Commit 7aff7f8d authored by sky's avatar sky Committed by Commit bot

Moves RootWindowController::MoveWindowsTo to WmRootWindowController

This is part of getting shutdown of displays working correctly.

BUG=none
TEST=covered by tests
R=msw@chromium.org

Review-Url: https://codereview.chromium.org/2347493003
Cr-Commit-Position: refs/heads/master@{#419037}
parent 053dc146
...@@ -129,6 +129,12 @@ bool WmShellAura::IsInUnifiedMode() const { ...@@ -129,6 +129,12 @@ bool WmShellAura::IsInUnifiedMode() const {
return Shell::GetInstance()->display_manager()->IsInUnifiedMode(); return Shell::GetInstance()->display_manager()->IsInUnifiedMode();
} }
bool WmShellAura::IsInUnifiedModeIgnoreMirroring() const {
return Shell::GetInstance()
->display_manager()
->current_default_multi_display_mode() == DisplayManager::UNIFIED;
}
bool WmShellAura::IsForceMaximizeOnFirstRun() { bool WmShellAura::IsForceMaximizeOnFirstRun() {
return delegate()->IsForceMaximizeOnFirstRun(); return delegate()->IsForceMaximizeOnFirstRun();
} }
......
...@@ -44,6 +44,7 @@ class ASH_EXPORT WmShellAura : public WmShell, ...@@ -44,6 +44,7 @@ class ASH_EXPORT WmShellAura : public WmShell,
bool IsActiveDisplayId(int64_t display_id) const override; bool IsActiveDisplayId(int64_t display_id) const override;
display::Display GetFirstDisplay() const override; display::Display GetFirstDisplay() const override;
bool IsInUnifiedMode() const override; bool IsInUnifiedMode() const override;
bool IsInUnifiedModeIgnoreMirroring() const override;
bool IsForceMaximizeOnFirstRun() override; bool IsForceMaximizeOnFirstRun() override;
void SetDisplayWorkAreaInsets(WmWindow* window, void SetDisplayWorkAreaInsets(WmWindow* window,
const gfx::Insets& insets) override; const gfx::Insets& insets) override;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "ash/common/wm/container_finder.h" #include "ash/common/wm/container_finder.h"
#include "ash/common/wm/root_window_layout_manager.h" #include "ash/common/wm/root_window_layout_manager.h"
#include "ash/common/wm/system_modal_container_layout_manager.h" #include "ash/common/wm/system_modal_container_layout_manager.h"
#include "ash/common/wm/window_state.h"
#include "ash/common/wm/workspace/workspace_layout_manager.h" #include "ash/common/wm/workspace/workspace_layout_manager.h"
#include "ash/common/wm/workspace_controller.h" #include "ash/common/wm/workspace_controller.h"
#include "ash/common/wm_shell.h" #include "ash/common/wm_shell.h"
...@@ -25,6 +26,103 @@ ...@@ -25,6 +26,103 @@
namespace ash { namespace ash {
namespace { namespace {
// Scales |value| that is originally between 0 and |src_max| to be between
// 0 and |dst_max|.
float ToRelativeValue(int value, int src_max, int dst_max) {
return static_cast<float>(value) / static_cast<float>(src_max) * dst_max;
}
// Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The
// width/height are not changed.
void MoveOriginRelativeToSize(const gfx::Size& src_size,
const gfx::Size& dst_size,
gfx::Rect* bounds_in_out) {
gfx::Point origin = bounds_in_out->origin();
bounds_in_out->set_origin(gfx::Point(
ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
}
// Reparents |window| to |new_parent|.
void ReparentWindow(WmWindow* window, WmWindow* new_parent) {
const gfx::Size src_size = window->GetParent()->GetBounds().size();
const gfx::Size dst_size = new_parent->GetBounds().size();
// Update the restore bounds to make it relative to the display.
wm::WindowState* state = window->GetWindowState();
gfx::Rect restore_bounds;
bool has_restore_bounds = state->HasRestoreBounds();
bool update_bounds =
(state->IsNormalOrSnapped() || state->IsMinimized()) &&
new_parent->GetShellWindowId() != kShellWindowId_DockedContainer;
gfx::Rect local_bounds;
if (update_bounds) {
local_bounds = state->window()->GetBounds();
MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
}
if (has_restore_bounds) {
restore_bounds = state->GetRestoreBoundsInParent();
MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
}
new_parent->AddChild(window);
// Docked windows have bounds handled by the layout manager in AddChild().
if (update_bounds)
window->SetBounds(local_bounds);
if (has_restore_bounds)
state->SetRestoreBoundsInParent(restore_bounds);
}
// Reparents the appropriate set of windows from |src| to |dst|.
void ReparentAllWindows(WmWindow* src, WmWindow* dst) {
// Set of windows to move.
const int kContainerIdsToMove[] = {
kShellWindowId_DefaultContainer,
kShellWindowId_DockedContainer,
kShellWindowId_PanelContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_SystemModalContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_UnparentedControlContainer,
kShellWindowId_OverlayContainer,
};
const int kExtraContainerIdsToMoveInUnifiedMode[] = {
kShellWindowId_LockScreenContainer,
kShellWindowId_LockScreenWallpaperContainer,
};
std::vector<int> container_ids(
kContainerIdsToMove,
kContainerIdsToMove + arraysize(kContainerIdsToMove));
// Check the display mode as this is also necessary when trasitioning between
// mirror and unified mode.
if (WmShell::Get()->IsInUnifiedModeIgnoreMirroring()) {
for (int id : kExtraContainerIdsToMoveInUnifiedMode)
container_ids.push_back(id);
}
for (int id : container_ids) {
WmWindow* src_container = src->GetChildByShellWindowId(id);
WmWindow* dst_container = dst->GetChildByShellWindowId(id);
while (!src_container->GetChildren().empty()) {
// Restart iteration from the source container windows each time as they
// may change as a result of moving other windows.
WmWindow::Windows src_container_children = src_container->GetChildren();
WmWindow::Windows::const_iterator iter = src_container_children.begin();
while (iter != src_container_children.end() &&
SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
++iter;
}
// If the entire window list is modal background windows then stop.
if (iter == src_container_children.end())
break;
ReparentWindow(*iter, dst_container);
}
}
}
// Creates a new window for use as a container. // Creates a new window for use as a container.
WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) {
WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
...@@ -140,6 +238,12 @@ void WmRootWindowController::OnWallpaperAnimationFinished( ...@@ -140,6 +238,12 @@ void WmRootWindowController::OnWallpaperAnimationFinished(
} }
} }
void WmRootWindowController::MoveWindowsTo(WmWindow* dest) {
// Clear the workspace controller, so it doesn't incorrectly update the shelf.
DeleteWorkspaceController();
ReparentAllWindows(GetWindow(), dest);
}
void WmRootWindowController::CreateContainers() { void WmRootWindowController::CreateContainers() {
// These containers are just used by PowerButtonController to animate groups // These containers are just used by PowerButtonController to animate groups
// of containers simultaneously without messing up the current transformations // of containers simultaneously without messing up the current transformations
......
...@@ -119,6 +119,9 @@ class ASH_EXPORT WmRootWindowController { ...@@ -119,6 +119,9 @@ class ASH_EXPORT WmRootWindowController {
virtual void OnWallpaperAnimationFinished(views::Widget* widget); virtual void OnWallpaperAnimationFinished(views::Widget* widget);
protected: protected:
// Moves child windows to |dest|.
void MoveWindowsTo(WmWindow* dest);
// Creates the containers (WmWindows) used by the shell. // Creates the containers (WmWindows) used by the shell.
void CreateContainers(); void CreateContainers();
......
...@@ -198,10 +198,15 @@ class ASH_EXPORT WmShell { ...@@ -198,10 +198,15 @@ class ASH_EXPORT WmShell {
// TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480 // TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480
virtual bool IsActiveDisplayId(int64_t display_id) const = 0; virtual bool IsActiveDisplayId(int64_t display_id) const = 0;
// Returns true if the desktop is in unified mode. // Returns true if the desktop is in unified mode and there are no mirroring
// displays.
// TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480 // TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480
virtual bool IsInUnifiedMode() const = 0; virtual bool IsInUnifiedMode() const = 0;
// Returns true if the desktop is in unified mode.
// TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480
virtual bool IsInUnifiedModeIgnoreMirroring() const = 0;
// Returns the first display; this is the first display listed by hardware, // Returns the first display; this is the first display listed by hardware,
// which corresponds to internal displays on devices with integrated displays. // which corresponds to internal displays on devices with integrated displays.
// TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480 // TODO(mash): Remove when DisplayManager has been moved. crbug.com/622480
......
...@@ -252,6 +252,13 @@ display::Display WmShellMus::GetFirstDisplay() const { ...@@ -252,6 +252,13 @@ display::Display WmShellMus::GetFirstDisplay() const {
bool WmShellMus::IsInUnifiedMode() const { bool WmShellMus::IsInUnifiedMode() const {
// TODO(mash): implement http://crbug.com/622480. // TODO(mash): implement http://crbug.com/622480.
NOTIMPLEMENTED();
return false;
}
bool WmShellMus::IsInUnifiedModeIgnoreMirroring() const {
// TODO(mash): implement http://crbug.com/622480.
NOTIMPLEMENTED();
return false; return false;
} }
......
...@@ -74,6 +74,7 @@ class WmShellMus : public WmShell, public ui::WindowTreeClientObserver { ...@@ -74,6 +74,7 @@ class WmShellMus : public WmShell, public ui::WindowTreeClientObserver {
bool IsActiveDisplayId(int64_t display_id) const override; bool IsActiveDisplayId(int64_t display_id) const override;
display::Display GetFirstDisplay() const override; display::Display GetFirstDisplay() const override;
bool IsInUnifiedMode() const override; bool IsInUnifiedMode() const override;
bool IsInUnifiedModeIgnoreMirroring() const override;
bool IsForceMaximizeOnFirstRun() override; bool IsForceMaximizeOnFirstRun() override;
void SetDisplayWorkAreaInsets(WmWindow* window, void SetDisplayWorkAreaInsets(WmWindow* window,
const gfx::Insets& insets) override; const gfx::Insets& insets) override;
......
...@@ -99,101 +99,6 @@ namespace { ...@@ -99,101 +99,6 @@ namespace {
const int kBootSplashScreenHideDurationMs = 500; const int kBootSplashScreenHideDurationMs = 500;
#endif #endif
float ToRelativeValue(int value, int src, int dst) {
return static_cast<float>(value) / static_cast<float>(src) * dst;
}
void MoveOriginRelativeToSize(const gfx::Size& src_size,
const gfx::Size& dst_size,
gfx::Rect* bounds_in_out) {
gfx::Point origin = bounds_in_out->origin();
bounds_in_out->set_origin(gfx::Point(
ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
}
// Reparents |window| to |new_parent|.
void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
const gfx::Size src_size = window->parent()->bounds().size();
const gfx::Size dst_size = new_parent->bounds().size();
// Update the restore bounds to make it relative to the display.
wm::WindowState* state = wm::GetWindowState(window);
gfx::Rect restore_bounds;
bool has_restore_bounds = state->HasRestoreBounds();
bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) &&
new_parent->id() != kShellWindowId_DockedContainer;
gfx::Rect local_bounds;
if (update_bounds) {
local_bounds = WmWindowAura::GetAuraWindow(state->window())->bounds();
MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
}
if (has_restore_bounds) {
restore_bounds = state->GetRestoreBoundsInParent();
MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
}
new_parent->AddChild(window);
// Docked windows have bounds handled by the layout manager in AddChild().
if (update_bounds)
window->SetBounds(local_bounds);
if (has_restore_bounds)
state->SetRestoreBoundsInParent(restore_bounds);
}
// Reparents the appropriate set of windows from |src| to |dst|.
void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
// Set of windows to move.
const int kContainerIdsToMove[] = {
kShellWindowId_DefaultContainer,
kShellWindowId_DockedContainer,
kShellWindowId_PanelContainer,
kShellWindowId_AlwaysOnTopContainer,
kShellWindowId_SystemModalContainer,
kShellWindowId_LockSystemModalContainer,
kShellWindowId_UnparentedControlContainer,
kShellWindowId_OverlayContainer,
};
const int kExtraContainerIdsToMoveInUnifiedMode[] = {
kShellWindowId_LockScreenContainer,
kShellWindowId_LockScreenWallpaperContainer,
};
std::vector<int> container_ids(
kContainerIdsToMove,
kContainerIdsToMove + arraysize(kContainerIdsToMove));
// Check the default_multi_display_mode because this is also necessary
// in trasition between mirror <-> unified mode.
if (Shell::GetInstance()
->display_manager()
->current_default_multi_display_mode() == DisplayManager::UNIFIED) {
for (int id : kExtraContainerIdsToMoveInUnifiedMode)
container_ids.push_back(id);
}
for (int id : container_ids) {
aura::Window* src_container = Shell::GetContainer(src, id);
aura::Window* dst_container = Shell::GetContainer(dst, id);
while (!src_container->children().empty()) {
// Restart iteration from the source container windows each time as they
// may change as a result of moving other windows.
aura::Window::Windows::const_iterator iter =
src_container->children().begin();
while (iter != src_container->children().end() &&
SystemModalContainerLayoutManager::IsModalBackground(
WmWindowAura::Get(*iter))) {
++iter;
}
// If the entire window list is modal background windows then stop.
if (iter == src_container->children().end())
break;
ReparentWindow(*iter, dst_container);
}
}
}
bool IsWindowAboveContainer(aura::Window* window, bool IsWindowAboveContainer(aura::Window* window,
aura::Window* blocking_container) { aura::Window* blocking_container) {
std::vector<aura::Window*> target_path; std::vector<aura::Window*> target_path;
...@@ -553,9 +458,7 @@ void RootWindowController::CloseChildWindows() { ...@@ -553,9 +458,7 @@ void RootWindowController::CloseChildWindows() {
} }
void RootWindowController::MoveWindowsTo(aura::Window* dst) { void RootWindowController::MoveWindowsTo(aura::Window* dst) {
// Clear the workspace controller, so it doesn't incorrectly update the shelf. wm_root_window_controller_->MoveWindowsTo(WmWindowAura::Get(dst));
wm_root_window_controller_->DeleteWorkspaceController();
ReparentAllWindows(GetRootWindow(), dst);
} }
ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() { ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment