OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/wm_root_window_controller.h" | 5 #include "ash/common/wm_root_window_controller.h" |
6 | 6 |
7 #include "ash/common/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
8 #include "ash/common/shelf/wm_shelf.h" | 8 #include "ash/common/shelf/wm_shelf.h" |
9 #include "ash/common/shell_delegate.h" | 9 #include "ash/common/shell_delegate.h" |
10 #include "ash/common/shell_window_ids.h" | 10 #include "ash/common/shell_window_ids.h" |
11 #include "ash/common/wallpaper/wallpaper_delegate.h" | 11 #include "ash/common/wallpaper/wallpaper_delegate.h" |
12 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 12 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
13 #include "ash/common/wm/container_finder.h" | 13 #include "ash/common/wm/container_finder.h" |
14 #include "ash/common/wm/root_window_layout_manager.h" | 14 #include "ash/common/wm/root_window_layout_manager.h" |
15 #include "ash/common/wm/system_modal_container_layout_manager.h" | 15 #include "ash/common/wm/system_modal_container_layout_manager.h" |
16 #include "ash/common/wm/window_state.h" | |
16 #include "ash/common/wm/workspace/workspace_layout_manager.h" | 17 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
17 #include "ash/common/wm/workspace_controller.h" | 18 #include "ash/common/wm/workspace_controller.h" |
18 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
19 #include "ash/common/wm_window.h" | 20 #include "ash/common/wm_window.h" |
20 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
21 #include "ui/base/models/menu_model.h" | 22 #include "ui/base/models/menu_model.h" |
22 #include "ui/views/controls/menu/menu_model_adapter.h" | 23 #include "ui/views/controls/menu/menu_model_adapter.h" |
23 #include "ui/views/controls/menu/menu_runner.h" | 24 #include "ui/views/controls/menu/menu_runner.h" |
24 | 25 |
25 namespace ash { | 26 namespace ash { |
26 namespace { | 27 namespace { |
27 | 28 |
29 // Scales |value| that is originally between 0 and |src_max| to be between | |
30 // 0 and |dst_max|. | |
31 float ToRelativeValue(int value, int src_max, int dst_max) { | |
32 return static_cast<float>(value) / static_cast<float>(src_max) * dst_max; | |
33 } | |
34 | |
35 // Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The | |
36 // width/height are not changed. | |
37 void MoveOriginRelativeToSize(const gfx::Size& src_size, | |
38 const gfx::Size& dst_size, | |
39 gfx::Rect* bounds_in_out) { | |
40 gfx::Point origin = bounds_in_out->origin(); | |
41 bounds_in_out->set_origin(gfx::Point( | |
42 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()), | |
43 ToRelativeValue(origin.y(), src_size.height(), dst_size.height()))); | |
44 } | |
45 | |
46 // Reparents |window| to |new_parent|. | |
47 void ReparentWindow(WmWindow* window, WmWindow* new_parent) { | |
48 const gfx::Size src_size = window->GetParent()->GetBounds().size(); | |
49 const gfx::Size dst_size = new_parent->GetBounds().size(); | |
50 // Update the restore bounds to make it relative to the display. | |
51 wm::WindowState* state = window->GetWindowState(); | |
52 gfx::Rect restore_bounds; | |
53 bool has_restore_bounds = state->HasRestoreBounds(); | |
54 | |
55 bool update_bounds = | |
56 (state->IsNormalOrSnapped() || state->IsMinimized()) && | |
57 new_parent->GetShellWindowId() != kShellWindowId_DockedContainer; | |
58 gfx::Rect local_bounds; | |
59 if (update_bounds) { | |
60 local_bounds = state->window()->GetBounds(); | |
61 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds); | |
62 } | |
63 | |
64 if (has_restore_bounds) { | |
65 restore_bounds = state->GetRestoreBoundsInParent(); | |
66 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds); | |
67 } | |
68 | |
69 new_parent->AddChild(window); | |
70 | |
71 // Docked windows have bounds handled by the layout manager in AddChild(). | |
72 if (update_bounds) | |
73 window->SetBounds(local_bounds); | |
74 | |
75 if (has_restore_bounds) | |
76 state->SetRestoreBoundsInParent(restore_bounds); | |
77 } | |
78 | |
79 // Reparents the appropriate set of windows from |src| to |dst|. | |
80 void ReparentAllWindows(WmWindow* src, WmWindow* dst) { | |
81 // Set of windows to move. | |
82 const int kContainerIdsToMove[] = { | |
83 kShellWindowId_DefaultContainer, | |
84 kShellWindowId_DockedContainer, | |
85 kShellWindowId_PanelContainer, | |
86 kShellWindowId_AlwaysOnTopContainer, | |
87 kShellWindowId_SystemModalContainer, | |
88 kShellWindowId_LockSystemModalContainer, | |
89 kShellWindowId_UnparentedControlContainer, | |
90 kShellWindowId_OverlayContainer, | |
91 }; | |
92 const int kExtraContainerIdsToMoveInUnifiedMode[] = { | |
93 kShellWindowId_LockScreenContainer, | |
94 kShellWindowId_LockScreenWallpaperContainer, | |
95 }; | |
96 std::vector<int> container_ids( | |
97 kContainerIdsToMove, | |
98 kContainerIdsToMove + arraysize(kContainerIdsToMove)); | |
99 // Check the display mode as this is also necessary when trasitioning between | |
100 // mirror and unified mode. | |
101 if (WmShell::Get()->IsInUnifiedModeIgnoreMirroring()) { | |
102 for (int id : kExtraContainerIdsToMoveInUnifiedMode) | |
103 container_ids.push_back(id); | |
104 } | |
105 | |
106 for (int id : container_ids) { | |
107 WmWindow* src_container = src->GetChildByShellWindowId(id); | |
108 WmWindow* dst_container = dst->GetChildByShellWindowId(id); | |
109 while (!src_container->GetChildren().empty()) { | |
110 // Restart iteration from the source container windows each time as they | |
111 // may change as a result of moving other windows. | |
112 WmWindow::Windows src_container_children = src_container->GetChildren(); | |
113 WmWindow::Windows::const_iterator iter = src_container_children.begin(); | |
114 while (iter != src_container_children.end() && | |
115 SystemModalContainerLayoutManager::IsModalBackground(*iter)) { | |
116 ++iter; | |
117 } | |
118 // If the entire window list is modal background windows then stop. | |
119 if (iter == src_container_children.end()) | |
120 break; | |
121 ReparentWindow(*iter, dst_container); | |
122 } | |
123 } | |
124 } | |
125 | |
28 // Creates a new window for use as a container. | 126 // Creates a new window for use as a container. |
29 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { | 127 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) { |
30 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, | 128 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, |
31 ui::LAYER_NOT_DRAWN); | 129 ui::LAYER_NOT_DRAWN); |
32 window->SetShellWindowId(window_id); | 130 window->SetShellWindowId(window_id); |
33 window->SetName(name); | 131 window->SetName(name); |
34 parent->AddChild(window); | 132 parent->AddChild(window); |
35 if (window_id != kShellWindowId_UnparentedControlContainer) | 133 if (window_id != kShellWindowId_UnparentedControlContainer) |
36 window->Show(); | 134 window->Show(); |
37 return window; | 135 return window; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 // be a white flash during the animation. | 231 // be a white flash during the animation. |
134 if (animating_wallpaper_widget_controller()) { | 232 if (animating_wallpaper_widget_controller()) { |
135 WallpaperWidgetController* controller = | 233 WallpaperWidgetController* controller = |
136 animating_wallpaper_widget_controller()->GetController(true); | 234 animating_wallpaper_widget_controller()->GetController(true); |
137 DCHECK_EQ(controller->widget(), widget); | 235 DCHECK_EQ(controller->widget(), widget); |
138 // Release the old controller and close its wallpaper widget. | 236 // Release the old controller and close its wallpaper widget. |
139 SetWallpaperWidgetController(controller); | 237 SetWallpaperWidgetController(controller); |
140 } | 238 } |
141 } | 239 } |
142 | 240 |
241 void WmRootWindowController::MoveWindowsTo(WmWindow* dest) { | |
sky
2016/09/15 03:27:14
This name is mildly confusing in that the function
msw
2016/09/15 17:29:36
Acknowledged.
| |
242 // Clear the workspace controller, so it doesn't incorrectly update the shelf. | |
243 DeleteWorkspaceController(); | |
244 ReparentAllWindows(GetWindow(), dest); | |
245 } | |
246 | |
143 void WmRootWindowController::CreateContainers() { | 247 void WmRootWindowController::CreateContainers() { |
144 // These containers are just used by PowerButtonController to animate groups | 248 // These containers are just used by PowerButtonController to animate groups |
145 // of containers simultaneously without messing up the current transformations | 249 // of containers simultaneously without messing up the current transformations |
146 // on those containers. These are direct children of the root window; all of | 250 // on those containers. These are direct children of the root window; all of |
147 // the other containers are their children. | 251 // the other containers are their children. |
148 | 252 |
149 // The wallpaper container is not part of the lock animation, so it is not | 253 // The wallpaper container is not part of the lock animation, so it is not |
150 // included in those animate groups. When the screen is locked, the wallpaper | 254 // included in those animate groups. When the screen is locked, the wallpaper |
151 // is moved to the lock screen wallpaper container (and moved back on unlock). | 255 // is moved to the lock screen wallpaper container (and moved back on unlock). |
152 // Ensure that there's an opaque layer occluding the non-lock-screen layers. | 256 // Ensure that there's an opaque layer occluding the non-lock-screen layers. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 } | 447 } |
344 | 448 |
345 void WmRootWindowController::OnMenuClosed() { | 449 void WmRootWindowController::OnMenuClosed() { |
346 menu_runner_.reset(); | 450 menu_runner_.reset(); |
347 menu_model_adapter_.reset(); | 451 menu_model_adapter_.reset(); |
348 menu_model_.reset(); | 452 menu_model_.reset(); |
349 GetShelf()->UpdateVisibilityState(); | 453 GetShelf()->UpdateVisibilityState(); |
350 } | 454 } |
351 | 455 |
352 } // namespace ash | 456 } // namespace ash |
OLD | NEW |