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

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

Issue 2350953009: Centralizes more shared code between ash and mash (Closed)
Patch Set: feedback Created 4 years, 3 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
« no previous file with comments | « ash/common/wm_root_window_controller.h ('k') | ash/common/wm_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/always_on_top_controller.h"
13 #include "ash/common/wm/container_finder.h" 14 #include "ash/common/wm/container_finder.h"
15 #include "ash/common/wm/dock/docked_window_layout_manager.h"
14 #include "ash/common/wm/lock_layout_manager.h" 16 #include "ash/common/wm/lock_layout_manager.h"
17 #include "ash/common/wm/panels/panel_layout_manager.h"
15 #include "ash/common/wm/root_window_layout_manager.h" 18 #include "ash/common/wm/root_window_layout_manager.h"
16 #include "ash/common/wm/system_modal_container_layout_manager.h" 19 #include "ash/common/wm/system_modal_container_layout_manager.h"
17 #include "ash/common/wm/window_state.h" 20 #include "ash/common/wm/window_state.h"
21 #include "ash/common/wm/wm_snap_to_pixel_layout_manager.h"
18 #include "ash/common/wm/workspace/workspace_layout_manager.h" 22 #include "ash/common/wm/workspace/workspace_layout_manager.h"
19 #include "ash/common/wm/workspace_controller.h" 23 #include "ash/common/wm/workspace_controller.h"
20 #include "ash/common/wm_shell.h" 24 #include "ash/common/wm_shell.h"
21 #include "ash/common/wm_window.h" 25 #include "ash/common/wm_window.h"
22 #include "base/memory/ptr_util.h" 26 #include "base/memory/ptr_util.h"
23 #include "ui/base/models/menu_model.h" 27 #include "ui/base/models/menu_model.h"
24 #include "ui/views/controls/menu/menu_model_adapter.h" 28 #include "ui/views/controls/menu/menu_model_adapter.h"
25 #include "ui/views/controls/menu/menu_runner.h" 29 #include "ui/views/controls/menu/menu_runner.h"
26 30
27 namespace ash { 31 namespace ash {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 window->SetShellWindowId(window_id); 135 window->SetShellWindowId(window_id);
132 window->SetName(name); 136 window->SetName(name);
133 parent->AddChild(window); 137 parent->AddChild(window);
134 if (window_id != kShellWindowId_UnparentedControlContainer) 138 if (window_id != kShellWindowId_UnparentedControlContainer)
135 window->Show(); 139 window->Show();
136 return window; 140 return window;
137 } 141 }
138 142
139 } // namespace 143 } // namespace
140 144
141 WmRootWindowController::WmRootWindowController(WmWindow* root) 145 WmRootWindowController::WmRootWindowController(WmWindow* root) : root_(root) {}
142 : root_(root), root_window_layout_manager_(nullptr) {}
143 146
144 WmRootWindowController::~WmRootWindowController() { 147 WmRootWindowController::~WmRootWindowController() {
145 if (animating_wallpaper_widget_controller_.get()) 148 if (animating_wallpaper_widget_controller_.get())
146 animating_wallpaper_widget_controller_->StopAnimating(); 149 animating_wallpaper_widget_controller_->StopAnimating();
147 } 150 }
148 151
149 void WmRootWindowController::SetWallpaperWidgetController( 152 void WmRootWindowController::SetWallpaperWidgetController(
150 WallpaperWidgetController* controller) { 153 WallpaperWidgetController* controller) {
151 wallpaper_widget_controller_.reset(controller); 154 wallpaper_widget_controller_.reset(controller);
152 } 155 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 WallpaperWidgetController* controller = 237 WallpaperWidgetController* controller =
235 animating_wallpaper_widget_controller()->GetController(true); 238 animating_wallpaper_widget_controller()->GetController(true);
236 DCHECK_EQ(controller->widget(), widget); 239 DCHECK_EQ(controller->widget(), widget);
237 // Release the old controller and close its wallpaper widget. 240 // Release the old controller and close its wallpaper widget.
238 SetWallpaperWidgetController(controller); 241 SetWallpaperWidgetController(controller);
239 } 242 }
240 } 243 }
241 244
242 void WmRootWindowController::MoveWindowsTo(WmWindow* dest) { 245 void WmRootWindowController::MoveWindowsTo(WmWindow* dest) {
243 // Clear the workspace controller, so it doesn't incorrectly update the shelf. 246 // Clear the workspace controller, so it doesn't incorrectly update the shelf.
244 DeleteWorkspaceController(); 247 workspace_controller_.reset();
245 ReparentAllWindows(GetWindow(), dest); 248 ReparentAllWindows(GetWindow(), dest);
246 } 249 }
247 250
248 void WmRootWindowController::CreateContainers() { 251 void WmRootWindowController::CreateContainers() {
249 // These containers are just used by PowerButtonController to animate groups 252 // These containers are just used by PowerButtonController to animate groups
250 // of containers simultaneously without messing up the current transformations 253 // of containers simultaneously without messing up the current transformations
251 // on those containers. These are direct children of the root window; all of 254 // on those containers. These are direct children of the root window; all of
252 // the other containers are their children. 255 // the other containers are their children.
253 256
254 // The wallpaper container is not part of the lock animation, so it is not 257 // The wallpaper container is not part of the lock animation, so it is not
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 GetContainer(kShellWindowId_LockSystemModalContainer); 442 GetContainer(kShellWindowId_LockSystemModalContainer);
440 DCHECK(lock_modal_container); 443 DCHECK(lock_modal_container);
441 lock_modal_container->SetLayoutManager( 444 lock_modal_container->SetLayoutManager(
442 base::MakeUnique<SystemModalContainerLayoutManager>( 445 base::MakeUnique<SystemModalContainerLayoutManager>(
443 lock_modal_container)); 446 lock_modal_container));
444 447
445 WmWindow* lock_container = GetContainer(kShellWindowId_LockScreenContainer); 448 WmWindow* lock_container = GetContainer(kShellWindowId_LockScreenContainer);
446 DCHECK(lock_container); 449 DCHECK(lock_container);
447 lock_container->SetLayoutManager( 450 lock_container->SetLayoutManager(
448 base::MakeUnique<LockLayoutManager>(lock_container)); 451 base::MakeUnique<LockLayoutManager>(lock_container));
452
453 WmWindow* always_on_top_container =
454 GetContainer(kShellWindowId_AlwaysOnTopContainer);
455 DCHECK(always_on_top_container);
456 always_on_top_controller_ =
457 base::MakeUnique<AlwaysOnTopController>(always_on_top_container);
458
459 // Create Docked windows layout manager
460 WmWindow* docked_container = GetContainer(kShellWindowId_DockedContainer);
461 docked_window_layout_manager_ =
462 new DockedWindowLayoutManager(docked_container);
463 docked_container->SetLayoutManager(
464 base::WrapUnique(docked_window_layout_manager_));
465
466 // Create Panel layout manager
467 WmWindow* panel_container = GetContainer(kShellWindowId_PanelContainer);
468 panel_layout_manager_ = new PanelLayoutManager(panel_container);
469 panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_));
470
471 wm::WmSnapToPixelLayoutManager::InstallOnContainers(root_);
449 } 472 }
450 473
451 void WmRootWindowController::DeleteWorkspaceController() { 474 void WmRootWindowController::ResetRootForNewWindowsIfNecessary() {
475 WmShell* shell = WmShell::Get();
476 // Change the target root window before closing child windows. If any child
477 // being removed triggers a relayout of the shelf it will try to build a
478 // window list adding windows from the target root window's containers which
479 // may have already gone away.
480 if (shell->GetRootWindowForNewWindows() == GetWindow()) {
481 // The root window for new windows is being destroyed. Switch to the primary
482 // root window if possible.
483 WmWindow* primary_root = shell->GetPrimaryRootWindow();
484 shell->set_root_window_for_new_windows(
485 primary_root == GetWindow() ? nullptr : primary_root);
486 }
487 }
488
489 void WmRootWindowController::CloseChildWindows() {
490 // NOTE: this may be called multiple times.
491
492 // |panel_layout_manager_| needs to be shut down before windows are destroyed.
493 if (panel_layout_manager_) {
494 panel_layout_manager_->Shutdown();
495 panel_layout_manager_ = nullptr;
496 }
497
498 // |docked_window_layout_manager_| needs to be shut down before windows are
499 // destroyed.
500 if (docked_window_layout_manager_) {
501 docked_window_layout_manager_->Shutdown();
502 docked_window_layout_manager_ = nullptr;
503 }
504
505 WmShelf* shelf = GetShelf();
506 shelf->ShutdownShelfWidget();
507
452 workspace_controller_.reset(); 508 workspace_controller_.reset();
509
510 // Explicitly destroy top level windows. We do this because such windows may
511 // query the RootWindow for state.
512 WmWindowTracker non_toplevel_windows;
513 non_toplevel_windows.Add(root_);
514 while (!non_toplevel_windows.windows().empty()) {
515 WmWindow* non_toplevel_window = non_toplevel_windows.Pop();
516 WmWindowTracker toplevel_windows;
517 for (WmWindow* child : non_toplevel_window->GetChildren()) {
518 if (!ShouldDestroyWindowInCloseChildWindows(child))
519 continue;
520 if (child->HasNonClientArea())
521 toplevel_windows.Add(child);
522 else
523 non_toplevel_windows.Add(child);
524 }
525 while (!toplevel_windows.windows().empty())
526 toplevel_windows.Pop()->Destroy();
527 }
528 // And then remove the containers.
529 while (!root_->GetChildren().empty()) {
530 WmWindow* child = root_->GetChildren()[0];
531 if (ShouldDestroyWindowInCloseChildWindows(child))
532 child->Destroy();
533 else
534 root_->RemoveChild(child);
535 }
536
537 shelf->DestroyShelfWidget();
538
539 // CloseChildWindows() may be called twice during the shutdown of ash
540 // unittests. Avoid notifying WmShelf that the shelf has been destroyed twice.
541 if (shelf->IsShelfInitialized())
542 shelf->ShutdownShelf();
453 } 543 }
454 544
455 void WmRootWindowController::OnMenuClosed() { 545 void WmRootWindowController::OnMenuClosed() {
456 menu_runner_.reset(); 546 menu_runner_.reset();
457 menu_model_adapter_.reset(); 547 menu_model_adapter_.reset();
458 menu_model_.reset(); 548 menu_model_.reset();
459 GetShelf()->UpdateVisibilityState(); 549 GetShelf()->UpdateVisibilityState();
460 } 550 }
461 551
462 } // namespace ash 552 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm_root_window_controller.h ('k') | ash/common/wm_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698