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

Side by Side Diff: ash/root_window_controller.cc

Issue 2620913003: Removes WmRootWindowController subclasses (Closed)
Patch Set: WmLookupAura::GetRootWindowControllerWithDisplayId needs to handle null 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/root_window_controller.h" 5 #include "ash/root_window_controller.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_touch_exploration_manager_chromeos.h" 10 #include "ash/ash_touch_exploration_manager_chromeos.h"
11 #include "ash/aura/aura_layout_manager_adapter.h" 11 #include "ash/aura/aura_layout_manager_adapter.h"
12 #include "ash/aura/wm_root_window_controller_aura.h"
13 #include "ash/aura/wm_window_aura.h" 12 #include "ash/aura/wm_window_aura.h"
14 #include "ash/common/ash_constants.h" 13 #include "ash/common/ash_constants.h"
15 #include "ash/common/ash_switches.h" 14 #include "ash/common/ash_switches.h"
16 #include "ash/common/focus_cycler.h" 15 #include "ash/common/focus_cycler.h"
17 #include "ash/common/login_status.h" 16 #include "ash/common/login_status.h"
18 #include "ash/common/session/session_state_delegate.h" 17 #include "ash/common/session/session_state_delegate.h"
19 #include "ash/common/shelf/shelf_delegate.h" 18 #include "ash/common/shelf/shelf_delegate.h"
20 #include "ash/common/shelf/shelf_layout_manager.h" 19 #include "ash/common/shelf/shelf_layout_manager.h"
21 #include "ash/common/shelf/shelf_widget.h" 20 #include "ash/common/shelf/shelf_widget.h"
22 #include "ash/common/shelf/wm_shelf.h" 21 #include "ash/common/shelf/wm_shelf.h"
23 #include "ash/common/shell_delegate.h" 22 #include "ash/common/shell_delegate.h"
24 #include "ash/common/system/status_area_layout_manager.h" 23 #include "ash/common/system/status_area_layout_manager.h"
25 #include "ash/common/system/status_area_widget.h" 24 #include "ash/common/system/status_area_widget.h"
26 #include "ash/common/system/tray/system_tray_delegate.h" 25 #include "ash/common/system/tray/system_tray_delegate.h"
27 #include "ash/common/wallpaper/wallpaper_delegate.h" 26 #include "ash/common/wallpaper/wallpaper_delegate.h"
28 #include "ash/common/wallpaper/wallpaper_widget_controller.h" 27 #include "ash/common/wallpaper/wallpaper_widget_controller.h"
29 #include "ash/common/wm/always_on_top_controller.h" 28 #include "ash/common/wm/always_on_top_controller.h"
30 #include "ash/common/wm/container_finder.h" 29 #include "ash/common/wm/container_finder.h"
31 #include "ash/common/wm/dock/docked_window_layout_manager.h" 30 #include "ash/common/wm/dock/docked_window_layout_manager.h"
32 #include "ash/common/wm/fullscreen_window_finder.h" 31 #include "ash/common/wm/fullscreen_window_finder.h"
33 #include "ash/common/wm/panels/panel_layout_manager.h" 32 #include "ash/common/wm/panels/panel_layout_manager.h"
34 #include "ash/common/wm/root_window_layout_manager.h" 33 #include "ash/common/wm/root_window_layout_manager.h"
35 #include "ash/common/wm/switchable_windows.h" 34 #include "ash/common/wm/switchable_windows.h"
36 #include "ash/common/wm/system_modal_container_layout_manager.h" 35 #include "ash/common/wm/system_modal_container_layout_manager.h"
37 #include "ash/common/wm/window_state.h" 36 #include "ash/common/wm/window_state.h"
38 #include "ash/common/wm/workspace/workspace_layout_manager.h" 37 #include "ash/common/wm/workspace/workspace_layout_manager.h"
39 #include "ash/common/wm/workspace_controller.h" 38 #include "ash/common/wm/workspace_controller.h"
39 #include "ash/common/wm_root_window_controller.h"
40 #include "ash/common/wm_shell.h" 40 #include "ash/common/wm_shell.h"
41 #include "ash/common/wm_window.h" 41 #include "ash/common/wm_window.h"
42 #include "ash/high_contrast/high_contrast_controller.h" 42 #include "ash/high_contrast/high_contrast_controller.h"
43 #include "ash/host/ash_window_tree_host.h" 43 #include "ash/host/ash_window_tree_host.h"
44 #include "ash/public/cpp/shelf_types.h" 44 #include "ash/public/cpp/shelf_types.h"
45 #include "ash/public/cpp/shell_window_ids.h" 45 #include "ash/public/cpp/shell_window_ids.h"
46 #include "ash/root_window_settings.h" 46 #include "ash/root_window_settings.h"
47 #include "ash/shelf/shelf_window_targeter.h" 47 #include "ash/shelf/shelf_window_targeter.h"
48 #include "ash/shell.h" 48 #include "ash/shell.h"
49 #include "ash/touch/touch_hud_debug.h" 49 #include "ash/touch/touch_hud_debug.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 // If the target window is above blocking window, the window can handle 132 // If the target window is above blocking window, the window can handle
133 // events. 133 // events.
134 return std::find(blocking_iter, windows.end(), target) != windows.end(); 134 return std::find(blocking_iter, windows.end(), target) != windows.end();
135 } 135 }
136 136
137 return true; 137 return true;
138 } 138 }
139 139
140 } // namespace 140 } // namespace
141 141
142 RootWindowController::~RootWindowController() {
143 Shutdown();
144 ash_host_.reset();
145 owned_window_tree_host_.reset();
146 // The CaptureClient needs to be around for as long as the RootWindow is
147 // valid.
148 capture_client_.reset();
149 }
150
142 void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) { 151 void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
143 RootWindowController* controller = new RootWindowController(host); 152 RootWindowController* controller = new RootWindowController(host, nullptr);
144 controller->Init(RootWindowController::PRIMARY); 153 controller->Init(RootWindowType::PRIMARY);
145 } 154 }
146 155
147 void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) { 156 void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
148 RootWindowController* controller = new RootWindowController(host); 157 RootWindowController* controller = new RootWindowController(host, nullptr);
149 controller->Init(RootWindowController::SECONDARY); 158 controller->Init(RootWindowType::SECONDARY);
150 } 159 }
151 160
152 // static 161 // static
153 RootWindowController* RootWindowController::ForWindow( 162 RootWindowController* RootWindowController::ForWindow(
154 const aura::Window* window) { 163 const aura::Window* window) {
164 DCHECK(window);
155 CHECK(Shell::HasInstance()); 165 CHECK(Shell::HasInstance());
156 return GetRootWindowController(window->GetRootWindow()); 166 return GetRootWindowController(window->GetRootWindow());
157 } 167 }
158 168
159 // static 169 // static
160 RootWindowController* RootWindowController::ForTargetRootWindow() { 170 RootWindowController* RootWindowController::ForTargetRootWindow() {
161 CHECK(Shell::HasInstance()); 171 CHECK(Shell::HasInstance());
162 return GetRootWindowController(Shell::GetTargetRootWindow()); 172 return GetRootWindowController(Shell::GetTargetRootWindow());
163 } 173 }
164 174
165 RootWindowController::~RootWindowController() {
166 Shutdown();
167 ash_host_.reset();
168 // The CaptureClient needs to be around for as long as the RootWindow is
169 // valid.
170 capture_client_.reset();
171 }
172
173 aura::WindowTreeHost* RootWindowController::GetHost() { 175 aura::WindowTreeHost* RootWindowController::GetHost() {
174 return ash_host_->AsWindowTreeHost(); 176 return window_tree_host_;
175 } 177 }
176 178
177 const aura::WindowTreeHost* RootWindowController::GetHost() const { 179 const aura::WindowTreeHost* RootWindowController::GetHost() const {
178 return ash_host_->AsWindowTreeHost(); 180 return window_tree_host_;
179 } 181 }
180 182
181 aura::Window* RootWindowController::GetRootWindow() { 183 aura::Window* RootWindowController::GetRootWindow() {
182 return GetHost()->window(); 184 return GetHost()->window();
183 } 185 }
184 186
185 const aura::Window* RootWindowController::GetRootWindow() const { 187 const aura::Window* RootWindowController::GetRootWindow() const {
186 return GetHost()->window(); 188 return GetHost()->window();
187 } 189 }
188 190
189 WorkspaceController* RootWindowController::workspace_controller() { 191 WorkspaceController* RootWindowController::workspace_controller() {
190 return wm_root_window_controller_->workspace_controller(); 192 return wm_root_window_controller_->workspace_controller();
191 } 193 }
192 194
193 void RootWindowController::Shutdown() { 195 void RootWindowController::Shutdown() {
194 WmShell::Get()->RemoveShellObserver(this); 196 WmShell::Get()->RemoveShellObserver(this);
195 197
196 touch_exploration_manager_.reset(); 198 touch_exploration_manager_.reset();
197 199
198 wm_root_window_controller_->ResetRootForNewWindowsIfNecessary(); 200 wm_root_window_controller_->ResetRootForNewWindowsIfNecessary();
199 201
200 CloseChildWindows(); 202 CloseChildWindows();
201 aura::Window* root_window = GetRootWindow(); 203 aura::Window* root_window = GetRootWindow();
202 GetRootWindowSettings(root_window)->controller = NULL; 204 GetRootWindowSettings(root_window)->controller = NULL;
203 // Forget with the display ID so that display lookup 205 // Forget with the display ID so that display lookup
204 // ends up with invalid display. 206 // ends up with invalid display.
205 GetRootWindowSettings(root_window)->display_id = display::kInvalidDisplayId; 207 GetRootWindowSettings(root_window)->display_id = display::kInvalidDisplayId;
206 ash_host_->PrepareForShutdown(); 208 if (ash_host_)
209 ash_host_->PrepareForShutdown();
207 210
208 system_wallpaper_.reset(); 211 system_wallpaper_.reset();
209 aura::client::SetScreenPositionClient(root_window, NULL); 212 aura::client::SetScreenPositionClient(root_window, NULL);
210 } 213 }
211 214
212 bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) { 215 bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) {
213 if (GetRootWindow() != window->GetRootWindow()) 216 if (GetRootWindow() != window->GetRootWindow())
214 return false; 217 return false;
215 218
216 // Always allow events to fall through to the virtual keyboard even if 219 // Always allow events to fall through to the virtual keyboard even if
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 WmWindowAura::Get(window)); 255 WmWindowAura::Get(window));
253 256
254 return true; 257 return true;
255 } 258 }
256 259
257 aura::Window* RootWindowController::GetContainer(int container_id) { 260 aura::Window* RootWindowController::GetContainer(int container_id) {
258 return GetRootWindow()->GetChildById(container_id); 261 return GetRootWindow()->GetChildById(container_id);
259 } 262 }
260 263
261 const aura::Window* RootWindowController::GetContainer(int container_id) const { 264 const aura::Window* RootWindowController::GetContainer(int container_id) const {
262 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id); 265 return window_tree_host_->window()->GetChildById(container_id);
263 } 266 }
264 267
265 void RootWindowController::OnInitialWallpaperAnimationStarted() { 268 void RootWindowController::OnInitialWallpaperAnimationStarted() {
266 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 269 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
267 switches::kAshAnimateFromBootSplashScreen) && 270 switches::kAshAnimateFromBootSplashScreen) &&
268 boot_splash_screen_.get()) { 271 boot_splash_screen_.get()) {
269 // Make the splash screen fade out so it doesn't obscure the wallpaper's 272 // Make the splash screen fade out so it doesn't obscure the wallpaper's
270 // brightness/grayscale animation. 273 // brightness/grayscale animation.
271 boot_splash_screen_->StartHideAnimation( 274 boot_splash_screen_->StartHideAnimation(
272 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs)); 275 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 385
383 void RootWindowController::SetTouchAccessibilityAnchorPoint( 386 void RootWindowController::SetTouchAccessibilityAnchorPoint(
384 const gfx::Point& anchor_point) { 387 const gfx::Point& anchor_point) {
385 if (touch_exploration_manager_) 388 if (touch_exploration_manager_)
386 touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point); 389 touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point);
387 } 390 }
388 391
389 //////////////////////////////////////////////////////////////////////////////// 392 ////////////////////////////////////////////////////////////////////////////////
390 // RootWindowController, private: 393 // RootWindowController, private:
391 394
392 RootWindowController::RootWindowController(AshWindowTreeHost* ash_host) 395 RootWindowController::RootWindowController(
396 AshWindowTreeHost* ash_host,
397 aura::WindowTreeHost* window_tree_host)
393 : ash_host_(ash_host), 398 : ash_host_(ash_host),
399 owned_window_tree_host_(window_tree_host),
400 window_tree_host_(ash_host ? ash_host->AsWindowTreeHost()
401 : window_tree_host),
394 wm_shelf_(base::MakeUnique<WmShelf>()), 402 wm_shelf_(base::MakeUnique<WmShelf>()),
395 touch_hud_debug_(NULL), 403 touch_hud_debug_(NULL),
396 touch_hud_projection_(NULL) { 404 touch_hud_projection_(NULL) {
405 DCHECK((ash_host && !window_tree_host) || (!ash_host && window_tree_host));
James Cook 2017/01/10 22:41:13 Hooray for DCHECK!
397 aura::Window* root_window = GetRootWindow(); 406 aura::Window* root_window = GetRootWindow();
398 GetRootWindowSettings(root_window)->controller = this; 407 GetRootWindowSettings(root_window)->controller = this;
399 408
400 // Has to happen after this is set as |controller| of RootWindowSettings. 409 // Has to happen after this is set as |controller| of RootWindowSettings.
401 wm_root_window_controller_ = WmRootWindowControllerAura::Get(root_window); 410 wm_root_window_controller_ = base::MakeUnique<WmRootWindowController>(
411 this, WmWindowAura::Get(root_window));
402 412
403 stacking_controller_.reset(new StackingController); 413 stacking_controller_.reset(new StackingController);
404 aura::client::SetWindowParentingClient(root_window, 414 aura::client::SetWindowParentingClient(root_window,
405 stacking_controller_.get()); 415 stacking_controller_.get());
406 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window)); 416 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
407 } 417 }
408 418
409 void RootWindowController::Init(RootWindowType root_window_type) { 419 void RootWindowController::Init(RootWindowType root_window_type) {
410 aura::Window* root_window = GetRootWindow(); 420 aura::Window* root_window = GetRootWindow();
411 Shell* shell = Shell::GetInstance(); 421 WmShell* wm_shell = WmShell::Get();
412 shell->InitRootWindow(root_window); 422 Shell* shell = nullptr;
423 if (!wm_shell->IsRunningInMash()) {
424 shell = Shell::GetInstance();
425 shell->InitRootWindow(root_window);
426 }
413 427
414 wm_root_window_controller_->CreateContainers(); 428 wm_root_window_controller_->CreateContainers();
415 429
416 CreateSystemWallpaper(root_window_type); 430 CreateSystemWallpaper(root_window_type);
417 431
418 InitLayoutManagers(); 432 InitLayoutManagers();
419 InitTouchHuds(); 433 InitTouchHuds();
420 434
421 if (WmShell::Get() 435 if (wm_shell->GetPrimaryRootWindowController()
422 ->GetPrimaryRootWindowController()
423 ->GetSystemModalLayoutManager(nullptr) 436 ->GetSystemModalLayoutManager(nullptr)
424 ->has_window_dimmer()) { 437 ->has_window_dimmer()) {
425 wm_root_window_controller_->GetSystemModalLayoutManager(nullptr) 438 wm_root_window_controller_->GetSystemModalLayoutManager(nullptr)
426 ->CreateModalBackground(); 439 ->CreateModalBackground();
427 } 440 }
428 441
429 WmShell::Get()->AddShellObserver(this); 442 wm_shell->AddShellObserver(this);
430 443
431 wm_root_window_controller_->root_window_layout_manager()->OnWindowResized(); 444 wm_root_window_controller_->root_window_layout_manager()->OnWindowResized();
432 if (root_window_type == PRIMARY) { 445 if (root_window_type == RootWindowType::PRIMARY) {
433 shell->InitKeyboard(); 446 if (!wm_shell->IsRunningInMash())
447 shell->InitKeyboard();
434 } else { 448 } else {
435 ash_host_->AsWindowTreeHost()->Show(); 449 window_tree_host_->Show();
436 450
437 // Create a shelf if a user is already logged in. 451 // Create a shelf if a user is already logged in.
438 if (WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers()) 452 if (wm_shell->GetSessionStateDelegate()->NumberOfLoggedInUsers())
439 wm_root_window_controller_->CreateShelf(); 453 wm_root_window_controller_->CreateShelf();
440 454
441 // Notify shell observers about new root window. 455 // Notify shell observers about new root window.
442 shell->OnRootWindowAdded(WmWindowAura::Get(root_window)); 456 if (!wm_shell->IsRunningInMash())
457 shell->OnRootWindowAdded(WmWindowAura::Get(root_window));
443 } 458 }
444 459
460 // TODO: AshTouchExplorationManager doesn't work with mus.
461 // http://crbug.com/679782
445 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 462 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
446 switches::kAshDisableTouchExplorationMode)) { 463 switches::kAshDisableTouchExplorationMode) &&
464 !wm_shell->IsRunningInMash()) {
447 touch_exploration_manager_.reset(new AshTouchExplorationManager(this)); 465 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
448 } 466 }
449 } 467 }
450 468
451 void RootWindowController::InitLayoutManagers() { 469 void RootWindowController::InitLayoutManagers() {
452 // Create the shelf and status area widgets. 470 // Create the shelf and status area widgets.
453 DCHECK(!wm_shelf_->shelf_widget()); 471 DCHECK(!wm_shelf_->shelf_widget());
454 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer); 472 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
455 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer); 473 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
456 WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container); 474 WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container);
(...skipping 22 matching lines...) Expand all
479 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer); 497 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
480 panel_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>( 498 panel_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
481 new AttachedPanelWindowTargeter(panel_container, mouse_extend, 499 new AttachedPanelWindowTargeter(panel_container, mouse_extend,
482 touch_extend, panel_layout_manager()))); 500 touch_extend, panel_layout_manager())));
483 } 501 }
484 502
485 void RootWindowController::InitTouchHuds() { 503 void RootWindowController::InitTouchHuds() {
486 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 504 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
487 if (command_line->HasSwitch(switches::kAshTouchHud)) 505 if (command_line->HasSwitch(switches::kAshTouchHud))
488 set_touch_hud_debug(new TouchHudDebug(GetRootWindow())); 506 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
489 if (Shell::GetInstance()->is_touch_hud_projection_enabled()) 507 if (!WmShell::Get()->IsRunningInMash() &&
James Cook 2017/01/10 22:41:13 maybe this should go at the top of the function? o
sky 2017/01/10 23:06:56 Done.
508 Shell::GetInstance()->is_touch_hud_projection_enabled()) {
490 EnableTouchHudProjection(); 509 EnableTouchHudProjection();
510 }
491 } 511 }
492 512
493 void RootWindowController::CreateSystemWallpaper( 513 void RootWindowController::CreateSystemWallpaper(
494 RootWindowType root_window_type) { 514 RootWindowType root_window_type) {
495 SkColor color = SK_ColorBLACK; 515 SkColor color = SK_ColorBLACK;
496 // The splash screen appears on the primary display at boot. If this is a 516 // The splash screen appears on the primary display at boot. If this is a
497 // secondary monitor (either connected at boot or connected later) or if the 517 // secondary monitor (either connected at boot or connected later) or if the
498 // browser restarted for a second login then don't use the boot color. 518 // browser restarted for a second login then don't use the boot color.
499 const bool is_boot_splash_screen = 519 const bool is_boot_splash_screen =
500 root_window_type == PRIMARY && 520 root_window_type == RootWindowType::PRIMARY &&
501 base::CommandLine::ForCurrentProcess()->HasSwitch( 521 base::CommandLine::ForCurrentProcess()->HasSwitch(
502 chromeos::switches::kFirstExecAfterBoot); 522 chromeos::switches::kFirstExecAfterBoot);
503 if (is_boot_splash_screen) 523 if (is_boot_splash_screen)
504 color = kChromeOsBootColor; 524 color = kChromeOsBootColor;
505 system_wallpaper_.reset( 525 system_wallpaper_.reset(
506 new SystemWallpaperController(GetRootWindow(), color)); 526 new SystemWallpaperController(GetRootWindow(), color));
507 527
508 // Make a copy of the system's boot splash screen so we can composite it 528 // Make a copy of the system's boot splash screen so we can composite it
509 // onscreen until the wallpaper is ready. 529 // onscreen until the wallpaper is ready.
510 if (is_boot_splash_screen && 530 if (is_boot_splash_screen &&
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 EnableTouchHudProjection(); 565 EnableTouchHudProjection();
546 else 566 else
547 DisableTouchHudProjection(); 567 DisableTouchHudProjection();
548 } 568 }
549 569
550 RootWindowController* GetRootWindowController(const aura::Window* root_window) { 570 RootWindowController* GetRootWindowController(const aura::Window* root_window) {
551 return root_window ? GetRootWindowSettings(root_window)->controller : nullptr; 571 return root_window ? GetRootWindowSettings(root_window)->controller : nullptr;
552 } 572 }
553 573
554 } // namespace ash 574 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698