Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: ash/common/wm_root_window_controller.cc

Issue 2625843002: Folds WmRootWindowController into RootWindowController (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ash/common/wm_root_window_controller.h"
6
7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/session/session_state_delegate.h"
9 #include "ash/common/shelf/shelf_layout_manager.h"
10 #include "ash/common/shelf/shelf_widget.h"
11 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shell_delegate.h"
13 #include "ash/common/system/status_area_widget.h"
14 #include "ash/common/wallpaper/wallpaper_delegate.h"
15 #include "ash/common/wallpaper/wallpaper_widget_controller.h"
16 #include "ash/common/wm/always_on_top_controller.h"
17 #include "ash/common/wm/container_finder.h"
18 #include "ash/common/wm/dock/docked_window_layout_manager.h"
19 #include "ash/common/wm/lock_layout_manager.h"
20 #include "ash/common/wm/panels/panel_layout_manager.h"
21 #include "ash/common/wm/root_window_layout_manager.h"
22 #include "ash/common/wm/system_modal_container_layout_manager.h"
23 #include "ash/common/wm/window_state.h"
24 #include "ash/common/wm/wm_snap_to_pixel_layout_manager.h"
25 #include "ash/common/wm/workspace/workspace_layout_manager.h"
26 #include "ash/common/wm/workspace_controller.h"
27 #include "ash/common/wm_shell.h"
28 #include "ash/common/wm_window.h"
29 #include "ash/public/cpp/shell_window_ids.h"
30 #include "ash/root_window_controller.h"
31 #include "ash/shell.h"
32 #include "base/memory/ptr_util.h"
33 #include "ui/aura/env.h"
34 #include "ui/aura/mus/window_mus.h"
35 #include "ui/aura/mus/window_tree_client.h"
36 #include "ui/aura/window.h"
37 #include "ui/aura/window_event_dispatcher.h"
38 #include "ui/aura/window_tree_host.h"
39 #include "ui/base/models/menu_model.h"
40 #include "ui/events/event_targeter.h"
41 #include "ui/events/event_utils.h"
42 #include "ui/views/controls/menu/menu_model_adapter.h"
43 #include "ui/views/controls/menu/menu_runner.h"
44
45 namespace ash {
46 namespace {
47
48 // Scales |value| that is originally between 0 and |src_max| to be between
49 // 0 and |dst_max|.
50 float ToRelativeValue(int value, int src_max, int dst_max) {
51 return static_cast<float>(value) / static_cast<float>(src_max) * dst_max;
52 }
53
54 // Uses ToRelativeValue() to scale the origin of |bounds_in_out|. The
55 // width/height are not changed.
56 void MoveOriginRelativeToSize(const gfx::Size& src_size,
57 const gfx::Size& dst_size,
58 gfx::Rect* bounds_in_out) {
59 gfx::Point origin = bounds_in_out->origin();
60 bounds_in_out->set_origin(gfx::Point(
61 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
62 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
63 }
64
65 // Reparents |window| to |new_parent|.
66 void ReparentWindow(WmWindow* window, WmWindow* new_parent) {
67 const gfx::Size src_size = window->GetParent()->GetBounds().size();
68 const gfx::Size dst_size = new_parent->GetBounds().size();
69 // Update the restore bounds to make it relative to the display.
70 wm::WindowState* state = window->GetWindowState();
71 gfx::Rect restore_bounds;
72 bool has_restore_bounds = state->HasRestoreBounds();
73
74 bool update_bounds =
75 (state->IsNormalOrSnapped() || state->IsMinimized()) &&
76 new_parent->GetShellWindowId() != kShellWindowId_DockedContainer;
77 gfx::Rect local_bounds;
78 if (update_bounds) {
79 local_bounds = state->window()->GetBounds();
80 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
81 }
82
83 if (has_restore_bounds) {
84 restore_bounds = state->GetRestoreBoundsInParent();
85 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
86 }
87
88 new_parent->AddChild(window);
89
90 // Docked windows have bounds handled by the layout manager in AddChild().
91 if (update_bounds)
92 window->SetBounds(local_bounds);
93
94 if (has_restore_bounds)
95 state->SetRestoreBoundsInParent(restore_bounds);
96 }
97
98 // Reparents the appropriate set of windows from |src| to |dst|.
99 void ReparentAllWindows(WmWindow* src, WmWindow* dst) {
100 // Set of windows to move.
101 const int kContainerIdsToMove[] = {
102 kShellWindowId_DefaultContainer,
103 kShellWindowId_DockedContainer,
104 kShellWindowId_PanelContainer,
105 kShellWindowId_AlwaysOnTopContainer,
106 kShellWindowId_SystemModalContainer,
107 kShellWindowId_LockSystemModalContainer,
108 kShellWindowId_UnparentedControlContainer,
109 kShellWindowId_OverlayContainer,
110 };
111 const int kExtraContainerIdsToMoveInUnifiedMode[] = {
112 kShellWindowId_LockScreenContainer,
113 kShellWindowId_LockScreenWallpaperContainer,
114 };
115 std::vector<int> container_ids(
116 kContainerIdsToMove,
117 kContainerIdsToMove + arraysize(kContainerIdsToMove));
118 // Check the display mode as this is also necessary when trasitioning between
119 // mirror and unified mode.
120 if (WmShell::Get()->IsInUnifiedModeIgnoreMirroring()) {
121 for (int id : kExtraContainerIdsToMoveInUnifiedMode)
122 container_ids.push_back(id);
123 }
124
125 for (int id : container_ids) {
126 WmWindow* src_container = src->GetChildByShellWindowId(id);
127 WmWindow* dst_container = dst->GetChildByShellWindowId(id);
128 while (!src_container->GetChildren().empty()) {
129 // Restart iteration from the source container windows each time as they
130 // may change as a result of moving other windows.
131 WmWindow::Windows src_container_children = src_container->GetChildren();
132 WmWindow::Windows::const_iterator iter = src_container_children.begin();
133 while (iter != src_container_children.end() &&
134 SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
135 ++iter;
136 }
137 // If the entire window list is modal background windows then stop.
138 if (iter == src_container_children.end())
139 break;
140 ReparentWindow(*iter, dst_container);
141 }
142 }
143 }
144
145 // Creates a new window for use as a container.
146 WmWindow* CreateContainer(int window_id, const char* name, WmWindow* parent) {
147 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
148 ui::LAYER_NOT_DRAWN);
149 window->SetShellWindowId(window_id);
150 window->SetName(name);
151 parent->AddChild(window);
152 if (window_id != kShellWindowId_UnparentedControlContainer)
153 window->Show();
154 return window;
155 }
156
157 } // namespace
158
159 WmRootWindowController::WmRootWindowController(
160 RootWindowController* root_window_controller,
161 WmWindow* root)
162 : root_window_controller_(root_window_controller), root_(root) {}
163
164 WmRootWindowController::~WmRootWindowController() {
165 if (animating_wallpaper_widget_controller_.get())
166 animating_wallpaper_widget_controller_->StopAnimating();
167 }
168
169 void WmRootWindowController::SetWallpaperWidgetController(
170 WallpaperWidgetController* controller) {
171 wallpaper_widget_controller_.reset(controller);
172 }
173
174 void WmRootWindowController::SetAnimatingWallpaperWidgetController(
175 AnimatingWallpaperWidgetController* controller) {
176 if (animating_wallpaper_widget_controller_.get())
177 animating_wallpaper_widget_controller_->StopAnimating();
178 animating_wallpaper_widget_controller_.reset(controller);
179 }
180
181 wm::WorkspaceWindowState WmRootWindowController::GetWorkspaceWindowState() {
182 return workspace_controller_ ? workspace_controller()->GetWindowState()
183 : wm::WORKSPACE_WINDOW_STATE_DEFAULT;
184 }
185
186 SystemModalContainerLayoutManager*
187 WmRootWindowController::GetSystemModalLayoutManager(WmWindow* window) {
188 WmWindow* modal_container = nullptr;
189 if (window) {
190 WmWindow* window_container = wm::GetContainerForWindow(window);
191 if (window_container &&
192 window_container->GetShellWindowId() >=
193 kShellWindowId_LockScreenContainer) {
194 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
195 } else {
196 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
197 }
198 } else {
199 int modal_window_id =
200 WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()
201 ? kShellWindowId_LockSystemModalContainer
202 : kShellWindowId_SystemModalContainer;
203 modal_container = GetContainer(modal_window_id);
204 }
205 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
206 modal_container->GetLayoutManager())
207 : nullptr;
208 }
209
210 bool WmRootWindowController::HasShelf() {
211 return GetShelf()->shelf_widget() != nullptr;
212 }
213
214 WmShelf* WmRootWindowController::GetShelf() {
215 return root_window_controller_->wm_shelf();
216 }
217
218 void WmRootWindowController::CreateShelf() {
219 WmShelf* shelf = GetShelf();
220 if (shelf->IsShelfInitialized())
221 return;
222 shelf->InitializeShelf();
223
224 if (panel_layout_manager_)
225 panel_layout_manager_->SetShelf(shelf);
226 if (docked_window_layout_manager_) {
227 docked_window_layout_manager_->SetShelf(shelf);
228 if (shelf->shelf_layout_manager())
229 docked_window_layout_manager_->AddObserver(shelf->shelf_layout_manager());
230 }
231
232 // Notify shell observers that the shelf has been created.
233 // TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will
234 // require changing AttachedPanelWidgetTargeter's access to WmShelf.
235 WmShell::Get()->NotifyShelfCreatedForRootWindow(GetWindow());
236
237 shelf->shelf_widget()->PostCreateShelf();
238 }
239
240 void WmRootWindowController::ShowShelf() {
241 WmShelf* shelf = GetShelf();
242 if (!shelf->IsShelfInitialized())
243 return;
244 // TODO(jamescook): Move this into WmShelf.
245 shelf->shelf_widget()->SetShelfVisibility(true);
246 shelf->shelf_widget()->status_area_widget()->Show();
247 }
248
249 SystemTray* WmRootWindowController::GetSystemTray() {
250 ShelfWidget* shelf_widget = GetShelf()->shelf_widget();
251 if (!shelf_widget || !shelf_widget->status_area_widget())
252 return nullptr;
253 return shelf_widget->status_area_widget()->system_tray();
254 }
255
256 WmWindow* WmRootWindowController::GetWindow() {
257 return root_;
258 }
259
260 WmWindow* WmRootWindowController::GetContainer(int container_id) {
261 return root_->GetChildByShellWindowId(container_id);
262 }
263
264 const WmWindow* WmRootWindowController::GetContainer(int container_id) const {
265 return root_->GetChildByShellWindowId(container_id);
266 }
267
268 void WmRootWindowController::ConfigureWidgetInitParamsForContainer(
269 views::Widget* widget,
270 int shell_container_id,
271 views::Widget::InitParams* init_params) {
272 init_params->parent = WmWindowAura::GetAuraWindow(
273 GetWindow()->GetChildByShellWindowId(shell_container_id));
274 }
275
276 WmWindow* WmRootWindowController::FindEventTarget(
277 const gfx::Point& location_in_screen) {
278 gfx::Point location_in_root =
279 GetWindow()->ConvertPointFromScreen(location_in_screen);
280 aura::Window* root = WmWindowAura::GetAuraWindow(GetWindow());
281 ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root,
282 location_in_root, ui::EventTimeForNow(),
283 ui::EF_NONE, ui::EF_NONE);
284 ui::EventTarget* event_handler = static_cast<ui::EventTarget*>(root)
285 ->GetEventTargeter()
286 ->FindTargetForEvent(root, &test_event);
287 return WmWindowAura::Get(static_cast<aura::Window*>(event_handler));
288 }
289
290 gfx::Point WmRootWindowController::GetLastMouseLocationInRoot() {
291 return WmWindowAura::GetAuraWindow(GetWindow())
292 ->GetHost()
293 ->dispatcher()
294 ->GetLastMouseLocationInRoot();
295 }
296
297 void WmRootWindowController::ShowContextMenu(
298 const gfx::Point& location_in_screen,
299 ui::MenuSourceType source_type) {
300 ShellDelegate* delegate = WmShell::Get()->delegate();
301 DCHECK(delegate);
302 menu_model_.reset(delegate->CreateContextMenu(GetShelf(), nullptr));
303 if (!menu_model_)
304 return;
305
306 menu_model_adapter_.reset(new views::MenuModelAdapter(
307 menu_model_.get(), base::Bind(&WmRootWindowController::OnMenuClosed,
308 base::Unretained(this))));
309
310 // The wallpaper controller may not be set yet if the user clicked on the
311 // status area before the initial animation completion. See crbug.com/222218
312 if (!wallpaper_widget_controller())
313 return;
314
315 menu_runner_.reset(new views::MenuRunner(
316 menu_model_adapter_->CreateMenu(),
317 views::MenuRunner::CONTEXT_MENU | views::MenuRunner::ASYNC));
318 ignore_result(
319 menu_runner_->RunMenuAt(wallpaper_widget_controller()->widget(), nullptr,
320 gfx::Rect(location_in_screen, gfx::Size()),
321 views::MENU_ANCHOR_TOPLEFT, source_type));
322 }
323
324 void WmRootWindowController::OnInitialWallpaperAnimationStarted() {
325 root_window_controller_->OnInitialWallpaperAnimationStarted();
326 }
327
328 void WmRootWindowController::OnWallpaperAnimationFinished(
329 views::Widget* widget) {
330 root_window_controller_->OnWallpaperAnimationFinished(widget);
331 WmShell::Get()->wallpaper_delegate()->OnWallpaperAnimationFinished();
332 // Only removes old component when wallpaper animation finished. If we
333 // remove the old one before the new wallpaper is done fading in there will
334 // be a white flash during the animation.
335 if (animating_wallpaper_widget_controller()) {
336 WallpaperWidgetController* controller =
337 animating_wallpaper_widget_controller()->GetController(true);
338 DCHECK_EQ(controller->widget(), widget);
339 // Release the old controller and close its wallpaper widget.
340 SetWallpaperWidgetController(controller);
341 }
342 }
343
344 void WmRootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) {
345 StatusAreaWidget* status_area_widget =
346 GetShelf()->shelf_widget()->status_area_widget();
347 if (status_area_widget)
348 status_area_widget->UpdateAfterLoginStatusChange(status);
349 }
350
351 void WmRootWindowController::MoveWindowsTo(WmWindow* dest) {
352 // Clear the workspace controller, so it doesn't incorrectly update the shelf.
353 workspace_controller_.reset();
354 ReparentAllWindows(GetWindow(), dest);
355 }
356
357 void WmRootWindowController::CreateContainers() {
358 // These containers are just used by PowerButtonController to animate groups
359 // of containers simultaneously without messing up the current transformations
360 // on those containers. These are direct children of the root window; all of
361 // the other containers are their children.
362
363 // The wallpaper container is not part of the lock animation, so it is not
364 // included in those animate groups. When the screen is locked, the wallpaper
365 // is moved to the lock screen wallpaper container (and moved back on unlock).
366 // Ensure that there's an opaque layer occluding the non-lock-screen layers.
367 WmWindow* wallpaper_container = CreateContainer(
368 kShellWindowId_WallpaperContainer, "WallpaperContainer", root_);
369 wallpaper_container->SetChildWindowVisibilityChangesAnimated();
370
371 WmWindow* non_lock_screen_containers =
372 CreateContainer(kShellWindowId_NonLockScreenContainersContainer,
373 "NonLockScreenContainersContainer", root_);
374 // Clip all windows inside this container, as half pixel of the window's
375 // texture may become visible when the screen is scaled. crbug.com/368591.
376 non_lock_screen_containers->SetMasksToBounds(true);
377
378 WmWindow* lock_wallpaper_containers =
379 CreateContainer(kShellWindowId_LockScreenWallpaperContainer,
380 "LockScreenWallpaperContainer", root_);
381 lock_wallpaper_containers->SetChildWindowVisibilityChangesAnimated();
382
383 WmWindow* lock_screen_containers =
384 CreateContainer(kShellWindowId_LockScreenContainersContainer,
385 "LockScreenContainersContainer", root_);
386 WmWindow* lock_screen_related_containers =
387 CreateContainer(kShellWindowId_LockScreenRelatedContainersContainer,
388 "LockScreenRelatedContainersContainer", root_);
389
390 CreateContainer(kShellWindowId_UnparentedControlContainer,
391 "UnparentedControlContainer", non_lock_screen_containers);
392
393 WmWindow* default_container =
394 CreateContainer(kShellWindowId_DefaultContainer, "DefaultContainer",
395 non_lock_screen_containers);
396 default_container->SetChildWindowVisibilityChangesAnimated();
397 default_container->SetSnapsChildrenToPhysicalPixelBoundary();
398 default_container->SetBoundsInScreenBehaviorForChildren(
399 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
400 default_container->SetChildrenUseExtendedHitRegion();
401
402 WmWindow* always_on_top_container =
403 CreateContainer(kShellWindowId_AlwaysOnTopContainer,
404 "AlwaysOnTopContainer", non_lock_screen_containers);
405 always_on_top_container->SetChildWindowVisibilityChangesAnimated();
406 always_on_top_container->SetSnapsChildrenToPhysicalPixelBoundary();
407 always_on_top_container->SetBoundsInScreenBehaviorForChildren(
408 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
409
410 WmWindow* docked_container =
411 CreateContainer(kShellWindowId_DockedContainer, "DockedContainer",
412 non_lock_screen_containers);
413 docked_container->SetChildWindowVisibilityChangesAnimated();
414 docked_container->SetSnapsChildrenToPhysicalPixelBoundary();
415 docked_container->SetBoundsInScreenBehaviorForChildren(
416 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
417 docked_container->SetChildrenUseExtendedHitRegion();
418
419 WmWindow* shelf_container =
420 CreateContainer(kShellWindowId_ShelfContainer, "ShelfContainer",
421 non_lock_screen_containers);
422 shelf_container->SetSnapsChildrenToPhysicalPixelBoundary();
423 shelf_container->SetBoundsInScreenBehaviorForChildren(
424 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
425 shelf_container->SetLockedToRoot(true);
426
427 WmWindow* panel_container =
428 CreateContainer(kShellWindowId_PanelContainer, "PanelContainer",
429 non_lock_screen_containers);
430 panel_container->SetSnapsChildrenToPhysicalPixelBoundary();
431 panel_container->SetBoundsInScreenBehaviorForChildren(
432 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
433
434 WmWindow* shelf_bubble_container =
435 CreateContainer(kShellWindowId_ShelfBubbleContainer,
436 "ShelfBubbleContainer", non_lock_screen_containers);
437 shelf_bubble_container->SetSnapsChildrenToPhysicalPixelBoundary();
438 shelf_bubble_container->SetBoundsInScreenBehaviorForChildren(
439 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
440 shelf_bubble_container->SetLockedToRoot(true);
441
442 WmWindow* app_list_container =
443 CreateContainer(kShellWindowId_AppListContainer, "AppListContainer",
444 non_lock_screen_containers);
445 app_list_container->SetSnapsChildrenToPhysicalPixelBoundary();
446 app_list_container->SetBoundsInScreenBehaviorForChildren(
447 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
448
449 WmWindow* modal_container =
450 CreateContainer(kShellWindowId_SystemModalContainer,
451 "SystemModalContainer", non_lock_screen_containers);
452 modal_container->SetSnapsChildrenToPhysicalPixelBoundary();
453 modal_container->SetChildWindowVisibilityChangesAnimated();
454 modal_container->SetBoundsInScreenBehaviorForChildren(
455 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
456 modal_container->SetChildrenUseExtendedHitRegion();
457
458 // TODO(beng): Figure out if we can make this use
459 // SystemModalContainerEventFilter instead of stops_event_propagation.
460 WmWindow* lock_container =
461 CreateContainer(kShellWindowId_LockScreenContainer, "LockScreenContainer",
462 lock_screen_containers);
463 lock_container->SetSnapsChildrenToPhysicalPixelBoundary();
464 lock_container->SetBoundsInScreenBehaviorForChildren(
465 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
466 // TODO(beng): stopsevents
467
468 WmWindow* lock_modal_container =
469 CreateContainer(kShellWindowId_LockSystemModalContainer,
470 "LockSystemModalContainer", lock_screen_containers);
471 lock_modal_container->SetSnapsChildrenToPhysicalPixelBoundary();
472 lock_modal_container->SetChildWindowVisibilityChangesAnimated();
473 lock_modal_container->SetBoundsInScreenBehaviorForChildren(
474 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
475 lock_modal_container->SetChildrenUseExtendedHitRegion();
476
477 WmWindow* status_container =
478 CreateContainer(kShellWindowId_StatusContainer, "StatusContainer",
479 lock_screen_related_containers);
480 status_container->SetSnapsChildrenToPhysicalPixelBoundary();
481 status_container->SetBoundsInScreenBehaviorForChildren(
482 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
483 status_container->SetLockedToRoot(true);
484
485 WmWindow* settings_bubble_container =
486 CreateContainer(kShellWindowId_SettingBubbleContainer,
487 "SettingBubbleContainer", lock_screen_related_containers);
488 settings_bubble_container->SetChildWindowVisibilityChangesAnimated();
489 settings_bubble_container->SetSnapsChildrenToPhysicalPixelBoundary();
490 settings_bubble_container->SetBoundsInScreenBehaviorForChildren(
491 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
492 settings_bubble_container->SetLockedToRoot(true);
493
494 WmWindow* virtual_keyboard_parent_container = CreateContainer(
495 kShellWindowId_ImeWindowParentContainer, "VirtualKeyboardParentContainer",
496 lock_screen_related_containers);
497 virtual_keyboard_parent_container->SetSnapsChildrenToPhysicalPixelBoundary();
498 virtual_keyboard_parent_container->SetBoundsInScreenBehaviorForChildren(
499 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
500
501 WmWindow* menu_container =
502 CreateContainer(kShellWindowId_MenuContainer, "MenuContainer",
503 lock_screen_related_containers);
504 menu_container->SetChildWindowVisibilityChangesAnimated();
505 menu_container->SetSnapsChildrenToPhysicalPixelBoundary();
506 menu_container->SetBoundsInScreenBehaviorForChildren(
507 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
508
509 WmWindow* drag_drop_container = CreateContainer(
510 kShellWindowId_DragImageAndTooltipContainer,
511 "DragImageAndTooltipContainer", lock_screen_related_containers);
512 drag_drop_container->SetChildWindowVisibilityChangesAnimated();
513 drag_drop_container->SetSnapsChildrenToPhysicalPixelBoundary();
514 drag_drop_container->SetBoundsInScreenBehaviorForChildren(
515 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
516
517 WmWindow* overlay_container =
518 CreateContainer(kShellWindowId_OverlayContainer, "OverlayContainer",
519 lock_screen_related_containers);
520 overlay_container->SetSnapsChildrenToPhysicalPixelBoundary();
521 overlay_container->SetBoundsInScreenBehaviorForChildren(
522 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
523
524 WmWindow* mouse_cursor_container = CreateContainer(
525 kShellWindowId_MouseCursorContainer, "MouseCursorContainer", root_);
526 mouse_cursor_container->SetBoundsInScreenBehaviorForChildren(
527 WmWindow::BoundsInScreenBehavior::USE_SCREEN_COORDINATES);
528
529 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
530 "PowerButtonAnimationContainer", root_);
531 }
532
533 void WmRootWindowController::CreateLayoutManagers() {
534 GetShelf()->CreateShelfWidget(GetWindow());
535
536 root_window_layout_manager_ = new wm::RootWindowLayoutManager(root_);
537 root_->SetLayoutManager(base::WrapUnique(root_window_layout_manager_));
538
539 WmWindow* default_container = GetContainer(kShellWindowId_DefaultContainer);
540 // Installs WorkspaceLayoutManager on |default_container|.
541 workspace_controller_.reset(new WorkspaceController(default_container));
542
543 WmWindow* modal_container = GetContainer(kShellWindowId_SystemModalContainer);
544 DCHECK(modal_container);
545 modal_container->SetLayoutManager(
546 base::MakeUnique<SystemModalContainerLayoutManager>(modal_container));
547
548 WmWindow* lock_modal_container =
549 GetContainer(kShellWindowId_LockSystemModalContainer);
550 DCHECK(lock_modal_container);
551 lock_modal_container->SetLayoutManager(
552 base::MakeUnique<SystemModalContainerLayoutManager>(
553 lock_modal_container));
554
555 WmWindow* lock_container = GetContainer(kShellWindowId_LockScreenContainer);
556 DCHECK(lock_container);
557 lock_container->SetLayoutManager(
558 base::MakeUnique<LockLayoutManager>(lock_container));
559
560 WmWindow* always_on_top_container =
561 GetContainer(kShellWindowId_AlwaysOnTopContainer);
562 DCHECK(always_on_top_container);
563 always_on_top_controller_ =
564 base::MakeUnique<AlwaysOnTopController>(always_on_top_container);
565
566 // Create Docked windows layout manager
567 WmWindow* docked_container = GetContainer(kShellWindowId_DockedContainer);
568 docked_window_layout_manager_ =
569 new DockedWindowLayoutManager(docked_container);
570 docked_container->SetLayoutManager(
571 base::WrapUnique(docked_window_layout_manager_));
572
573 // Create Panel layout manager
574 WmWindow* panel_container = GetContainer(kShellWindowId_PanelContainer);
575 panel_layout_manager_ = new PanelLayoutManager(panel_container);
576 panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_));
577
578 wm::WmSnapToPixelLayoutManager::InstallOnContainers(root_);
579 }
580
581 void WmRootWindowController::ResetRootForNewWindowsIfNecessary() {
582 WmShell* shell = WmShell::Get();
583 // Change the target root window before closing child windows. If any child
584 // being removed triggers a relayout of the shelf it will try to build a
585 // window list adding windows from the target root window's containers which
586 // may have already gone away.
587 if (shell->GetRootWindowForNewWindows() == GetWindow()) {
588 // The root window for new windows is being destroyed. Switch to the primary
589 // root window if possible.
590 WmWindow* primary_root = shell->GetPrimaryRootWindow();
591 shell->set_root_window_for_new_windows(
592 primary_root == GetWindow() ? nullptr : primary_root);
593 }
594 }
595
596 void WmRootWindowController::CloseChildWindows() {
597 // NOTE: this may be called multiple times.
598
599 // |panel_layout_manager_| needs to be shut down before windows are destroyed.
600 if (panel_layout_manager_) {
601 panel_layout_manager_->Shutdown();
602 panel_layout_manager_ = nullptr;
603 }
604
605 // |docked_window_layout_manager_| needs to be shut down before windows are
606 // destroyed.
607 if (docked_window_layout_manager_) {
608 docked_window_layout_manager_->Shutdown();
609 docked_window_layout_manager_ = nullptr;
610 }
611
612 WmShelf* shelf = GetShelf();
613 shelf->ShutdownShelfWidget();
614
615 workspace_controller_.reset();
616
617 // Explicitly destroy top level windows. We do this because such windows may
618 // query the RootWindow for state.
619 WmWindowTracker non_toplevel_windows;
620 non_toplevel_windows.Add(root_);
621 while (!non_toplevel_windows.windows().empty()) {
622 WmWindow* non_toplevel_window = non_toplevel_windows.Pop();
623 WmWindowTracker toplevel_windows;
624 for (WmWindow* child : non_toplevel_window->GetChildren()) {
625 if (!ShouldDestroyWindowInCloseChildWindows(child))
626 continue;
627 if (child->HasNonClientArea())
628 toplevel_windows.Add(child);
629 else
630 non_toplevel_windows.Add(child);
631 }
632 while (!toplevel_windows.windows().empty())
633 toplevel_windows.Pop()->Destroy();
634 }
635 // And then remove the containers.
636 while (!root_->GetChildren().empty()) {
637 WmWindow* child = root_->GetChildren()[0];
638 if (ShouldDestroyWindowInCloseChildWindows(child))
639 child->Destroy();
640 else
641 root_->RemoveChild(child);
642 }
643
644 shelf->DestroyShelfWidget();
645
646 // CloseChildWindows() may be called twice during the shutdown of ash
647 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice.
648 if (shelf->IsShelfInitialized())
649 shelf->ShutdownShelf();
650 }
651
652 bool WmRootWindowController::ShouldDestroyWindowInCloseChildWindows(
653 WmWindow* window) {
654 if (!WmWindowAura::GetAuraWindow(window)->owned_by_parent())
655 return false;
656
657 if (aura::Env::GetInstance()->mode() == aura::Env::Mode::LOCAL)
658 return true;
659
660 aura::WindowMus* window_mus =
661 aura::WindowMus::Get(WmWindowAura::GetAuraWindow(window));
662 return Shell::window_tree_client()->WasCreatedByThisClient(window_mus) ||
663 Shell::window_tree_client()->IsRoot(window_mus);
664 }
665
666 void WmRootWindowController::OnMenuClosed() {
667 menu_runner_.reset();
668 menu_model_adapter_.reset();
669 menu_model_.reset();
670 GetShelf()->UpdateVisibilityState();
671 }
672
673 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698