Android: Remove unneeded Compositor::SetNeedsRedraw()
[chromium-blink-merge.git] / ash / root_window_controller.cc
blob066f06cd5d8c4057ba3ecca4eb8def828649c16a
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
3 // found in the LICENSE file.
5 #include "ash/root_window_controller.h"
7 #include <queue>
8 #include <vector>
10 #include "ash/ash_constants.h"
11 #include "ash/ash_switches.h"
12 #include "ash/desktop_background/desktop_background_widget_controller.h"
13 #include "ash/desktop_background/user_wallpaper_delegate.h"
14 #include "ash/display/display_manager.h"
15 #include "ash/focus_cycler.h"
16 #include "ash/root_window_settings.h"
17 #include "ash/session_state_delegate.h"
18 #include "ash/shelf/shelf_layout_manager.h"
19 #include "ash/shelf/shelf_types.h"
20 #include "ash/shelf/shelf_widget.h"
21 #include "ash/shell.h"
22 #include "ash/shell_delegate.h"
23 #include "ash/shell_factory.h"
24 #include "ash/shell_window_ids.h"
25 #include "ash/system/status_area_widget.h"
26 #include "ash/system/tray/system_tray_delegate.h"
27 #include "ash/touch/touch_hud_debug.h"
28 #include "ash/touch/touch_hud_projection.h"
29 #include "ash/touch/touch_observer_hud.h"
30 #include "ash/wm/always_on_top_controller.h"
31 #include "ash/wm/base_layout_manager.h"
32 #include "ash/wm/dock/docked_window_layout_manager.h"
33 #include "ash/wm/panels/panel_layout_manager.h"
34 #include "ash/wm/panels/panel_window_event_handler.h"
35 #include "ash/wm/root_window_layout_manager.h"
36 #include "ash/wm/screen_dimmer.h"
37 #include "ash/wm/stacking_controller.h"
38 #include "ash/wm/status_area_layout_manager.h"
39 #include "ash/wm/system_background_controller.h"
40 #include "ash/wm/system_modal_container_layout_manager.h"
41 #include "ash/wm/toplevel_window_event_handler.h"
42 #include "ash/wm/window_properties.h"
43 #include "ash/wm/window_state.h"
44 #include "ash/wm/window_util.h"
45 #include "ash/wm/workspace_controller.h"
46 #include "base/command_line.h"
47 #include "base/time/time.h"
48 #include "ui/aura/client/aura_constants.h"
49 #include "ui/aura/client/drag_drop_client.h"
50 #include "ui/aura/client/tooltip_client.h"
51 #include "ui/aura/root_window.h"
52 #include "ui/aura/window.h"
53 #include "ui/aura/window_delegate.h"
54 #include "ui/aura/window_observer.h"
55 #include "ui/aura/window_tracker.h"
56 #include "ui/base/hit_test.h"
57 #include "ui/base/models/menu_model.h"
58 #include "ui/gfx/display.h"
59 #include "ui/gfx/screen.h"
60 #include "ui/keyboard/keyboard_controller.h"
61 #include "ui/keyboard/keyboard_util.h"
62 #include "ui/views/controls/menu/menu_runner.h"
63 #include "ui/views/corewm/capture_controller.h"
64 #include "ui/views/corewm/visibility_controller.h"
65 #include "ui/views/view_model.h"
66 #include "ui/views/view_model_utils.h"
68 #if defined(OS_CHROMEOS)
69 #include "ash/wm/boot_splash_screen_chromeos.h"
70 #endif
72 namespace ash {
73 namespace {
75 #if defined(OS_CHROMEOS)
76 // Duration for the animation that hides the boot splash screen, in
77 // milliseconds. This should be short enough in relation to
78 // wm/window_animation.cc's brightness/grayscale fade animation that the login
79 // background image animation isn't hidden by the splash screen animation.
80 const int kBootSplashScreenHideDurationMs = 500;
81 #endif
83 // Creates a new window for use as a container.
84 aura::Window* CreateContainer(int window_id,
85 const char* name,
86 aura::Window* parent) {
87 aura::Window* container = new aura::Window(NULL);
88 container->set_id(window_id);
89 container->SetName(name);
90 container->Init(ui::LAYER_NOT_DRAWN);
91 parent->AddChild(container);
92 if (window_id != internal::kShellWindowId_UnparentedControlContainer)
93 container->Show();
94 return container;
97 // Reparents |window| to |new_parent|.
98 void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
99 // Update the restore bounds to make it relative to the display.
100 wm::WindowState* state = wm::GetWindowState(window);
101 gfx::Rect restore_bounds;
102 bool has_restore_bounds = state->HasRestoreBounds();
103 if (has_restore_bounds)
104 restore_bounds = state->GetRestoreBoundsInParent();
105 new_parent->AddChild(window);
106 if (has_restore_bounds)
107 state->SetRestoreBoundsInParent(restore_bounds);
110 // Reparents the appropriate set of windows from |src| to |dst|.
111 void ReparentAllWindows(aura::RootWindow* src, aura::RootWindow* dst) {
112 // Set of windows to move.
113 const int kContainerIdsToMove[] = {
114 internal::kShellWindowId_DefaultContainer,
115 internal::kShellWindowId_DockedContainer,
116 internal::kShellWindowId_PanelContainer,
117 internal::kShellWindowId_AlwaysOnTopContainer,
118 internal::kShellWindowId_SystemModalContainer,
119 internal::kShellWindowId_LockSystemModalContainer,
120 internal::kShellWindowId_InputMethodContainer,
121 internal::kShellWindowId_UnparentedControlContainer,
123 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
124 int id = kContainerIdsToMove[i];
125 aura::Window* src_container = Shell::GetContainer(src, id);
126 aura::Window* dst_container = Shell::GetContainer(dst, id);
127 while (!src_container->children().empty()) {
128 // Restart iteration from the source container windows each time as they
129 // may change as a result of moving other windows.
130 aura::Window::Windows::const_iterator iter =
131 src_container->children().begin();
132 while (iter != src_container->children().end() &&
133 internal::SystemModalContainerLayoutManager::IsModalBackground(
134 *iter)) {
135 ++iter;
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);
145 // Mark the container window so that a widget added to this container will
146 // use the virtual screeen coordinates instead of parent.
147 void SetUsesScreenCoordinates(aura::Window* container) {
148 container->SetProperty(internal::kUsesScreenCoordinatesKey, true);
151 // Mark the container window so that a widget added to this container will
152 // say in the same root window regardless of the bounds specified.
153 void DescendantShouldStayInSameRootWindow(aura::Window* container) {
154 container->SetProperty(internal::kStayInSameRootWindowKey, true);
157 // A window delegate which does nothing. Used to create a window that
158 // is a event target, but do nothing.
159 class EmptyWindowDelegate : public aura::WindowDelegate {
160 public:
161 EmptyWindowDelegate() {}
162 virtual ~EmptyWindowDelegate() {}
164 // aura::WindowDelegate overrides:
165 virtual gfx::Size GetMinimumSize() const OVERRIDE {
166 return gfx::Size();
168 virtual gfx::Size GetMaximumSize() const OVERRIDE {
169 return gfx::Size();
171 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
172 const gfx::Rect& new_bounds) OVERRIDE {
174 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
175 return gfx::kNullCursor;
177 virtual int GetNonClientComponent(
178 const gfx::Point& point) const OVERRIDE {
179 return HTNOWHERE;
181 virtual bool ShouldDescendIntoChildForEventHandling(
182 aura::Window* child,
183 const gfx::Point& location) OVERRIDE {
184 return false;
186 virtual bool CanFocus() OVERRIDE {
187 return false;
189 virtual void OnCaptureLost() OVERRIDE {
191 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
193 virtual void OnDeviceScaleFactorChanged(
194 float device_scale_factor) OVERRIDE {
196 virtual void OnWindowDestroying() OVERRIDE {}
197 virtual void OnWindowDestroyed() OVERRIDE {
198 delete this;
200 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
202 virtual bool HasHitTestMask() const OVERRIDE {
203 return false;
205 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
206 virtual void DidRecreateLayer(ui::Layer* old_layer,
207 ui::Layer* new_layer) OVERRIDE {}
209 private:
210 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
213 } // namespace
215 namespace internal {
217 RootWindowController::RootWindowController(aura::RootWindow* root_window)
218 : root_window_(root_window),
219 root_window_layout_(NULL),
220 docked_layout_manager_(NULL),
221 panel_layout_manager_(NULL),
222 touch_hud_debug_(NULL),
223 touch_hud_projection_(NULL) {
224 GetRootWindowSettings(root_window)->controller = this;
225 screen_dimmer_.reset(new ScreenDimmer(root_window));
227 stacking_controller_.reset(new StackingController);
228 aura::client::SetStackingClient(root_window, stacking_controller_.get());
229 capture_client_.reset(new views::corewm::ScopedCaptureClient(root_window));
232 RootWindowController::~RootWindowController() {
233 Shutdown();
234 root_window_.reset();
235 // The CaptureClient needs to be around for as long as the RootWindow is
236 // valid.
237 capture_client_.reset();
240 // static
241 RootWindowController* RootWindowController::ForLauncher(aura::Window* window) {
242 return GetRootWindowController(window->GetRootWindow());
245 // static
246 RootWindowController* RootWindowController::ForWindow(
247 const aura::Window* window) {
248 return GetRootWindowController(window->GetRootWindow());
251 // static
252 RootWindowController* RootWindowController::ForTargetRootWindow() {
253 return internal::GetRootWindowController(Shell::GetTargetRootWindow());
256 void RootWindowController::SetWallpaperController(
257 DesktopBackgroundWidgetController* controller) {
258 wallpaper_controller_.reset(controller);
261 void RootWindowController::SetAnimatingWallpaperController(
262 AnimatingDesktopController* controller) {
263 if (animating_wallpaper_controller_.get())
264 animating_wallpaper_controller_->StopAnimating();
265 animating_wallpaper_controller_.reset(controller);
268 void RootWindowController::Shutdown() {
269 Shell::GetInstance()->RemoveShellObserver(this);
271 if (animating_wallpaper_controller_.get())
272 animating_wallpaper_controller_->StopAnimating();
273 wallpaper_controller_.reset();
274 animating_wallpaper_controller_.reset();
276 // Change the target root window before closing child windows. If any child
277 // being removed triggers a relayout of the shelf it will try to build a
278 // window list adding windows from the target root window's containers which
279 // may have already gone away.
280 if (Shell::GetTargetRootWindow() == root_window_) {
281 Shell::GetInstance()->set_target_root_window(
282 Shell::GetPrimaryRootWindow() == root_window_.get() ?
283 NULL : Shell::GetPrimaryRootWindow());
286 CloseChildWindows();
287 GetRootWindowSettings(root_window_.get())->controller = NULL;
288 screen_dimmer_.reset();
289 workspace_controller_.reset();
290 // Forget with the display ID so that display lookup
291 // ends up with invalid display.
292 internal::GetRootWindowSettings(root_window_.get())->display_id =
293 gfx::Display::kInvalidDisplayID;
294 // And this root window should no longer process events.
295 root_window_->PrepareForShutdown();
297 system_background_.reset();
300 SystemModalContainerLayoutManager*
301 RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
302 aura::Window* container = NULL;
303 if (window) {
304 if (window->parent() &&
305 window->parent()->id() >= kShellWindowId_LockScreenContainer) {
306 container = GetContainer(kShellWindowId_LockSystemModalContainer);
307 } else {
308 container = GetContainer(kShellWindowId_SystemModalContainer);
310 } else {
311 int modal_window_id = Shell::GetInstance()->session_state_delegate()
312 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
313 kShellWindowId_SystemModalContainer;
314 container = GetContainer(modal_window_id);
316 return container ? static_cast<SystemModalContainerLayoutManager*>(
317 container->layout_manager()) : NULL;
320 aura::Window* RootWindowController::GetContainer(int container_id) {
321 return root_window_->GetChildById(container_id);
324 const aura::Window* RootWindowController::GetContainer(int container_id) const {
325 return root_window_->GetChildById(container_id);
328 void RootWindowController::Init(bool first_run_after_boot) {
329 root_window_->SetCursor(ui::kCursorPointer);
330 CreateContainersInRootWindow(root_window_.get());
331 CreateSystemBackground(first_run_after_boot);
333 InitLayoutManagers();
334 InitTouchHuds();
336 if (Shell::GetPrimaryRootWindowController()->
337 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
338 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
341 Shell::GetInstance()->AddShellObserver(this);
344 void RootWindowController::ShowLauncher() {
345 if (!shelf_->launcher())
346 return;
347 shelf_->launcher()->SetVisible(true);
348 shelf_->status_area_widget()->Show();
351 void RootWindowController::OnLauncherCreated() {
352 if (panel_layout_manager_)
353 panel_layout_manager_->SetLauncher(shelf_->launcher());
354 if (docked_layout_manager_) {
355 docked_layout_manager_->SetLauncher(shelf_->launcher());
356 if (shelf_->shelf_layout_manager())
357 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
361 void RootWindowController::UpdateAfterLoginStatusChange(
362 user::LoginStatus status) {
363 if (status != user::LOGGED_IN_NONE)
364 mouse_event_target_.reset();
365 if (shelf_->status_area_widget())
366 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
369 void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
370 #if defined(OS_CHROMEOS)
371 if (CommandLine::ForCurrentProcess()->HasSwitch(
372 switches::kAshAnimateFromBootSplashScreen) &&
373 boot_splash_screen_.get()) {
374 // Make the splash screen fade out so it doesn't obscure the desktop
375 // wallpaper's brightness/grayscale animation.
376 boot_splash_screen_->StartHideAnimation(
377 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
379 #endif
382 void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
383 // Make sure the wallpaper is visible.
384 system_background_->SetColor(SK_ColorBLACK);
385 #if defined(OS_CHROMEOS)
386 boot_splash_screen_.reset();
387 #endif
389 Shell::GetInstance()->user_wallpaper_delegate()->
390 OnWallpaperAnimationFinished();
391 // Only removes old component when wallpaper animation finished. If we
392 // remove the old one before the new wallpaper is done fading in there will
393 // be a white flash during the animation.
394 if (animating_wallpaper_controller()) {
395 DesktopBackgroundWidgetController* controller =
396 animating_wallpaper_controller()->GetController(true);
397 // |desktop_widget_| should be the same animating widget we try to move
398 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
399 // before move it to |kDesktopController|.
400 DCHECK_EQ(controller->widget(), widget);
401 // Release the old controller and close its background widget.
402 SetWallpaperController(controller);
406 void RootWindowController::CloseChildWindows() {
407 mouse_event_target_.reset();
409 // Deactivate keyboard container before closing child windows and shutting
410 // down associated layout managers.
411 DeactivateKeyboard(Shell::GetInstance()->keyboard_controller());
413 if (!shelf_.get())
414 return;
415 // panel_layout_manager_ needs to be shut down before windows are destroyed.
416 if (panel_layout_manager_) {
417 panel_layout_manager_->Shutdown();
418 panel_layout_manager_ = NULL;
420 // docked_layout_manager_ needs to be shut down before windows are destroyed.
421 if (docked_layout_manager_) {
422 if (shelf_->shelf_layout_manager())
423 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
424 docked_layout_manager_->Shutdown();
425 docked_layout_manager_ = NULL;
428 aura::client::SetDragDropClient(root_window_.get(), NULL);
430 // TODO(harrym): Remove when Status Area Widget is a child view.
431 shelf_->ShutdownStatusAreaWidget();
433 if (shelf_->shelf_layout_manager())
434 shelf_->shelf_layout_manager()->PrepareForShutdown();
436 // Close background widget first as it depends on tooltip.
437 wallpaper_controller_.reset();
438 animating_wallpaper_controller_.reset();
440 workspace_controller_.reset();
441 aura::client::SetTooltipClient(root_window_.get(), NULL);
443 // Explicitly destroy top level windows. We do this as during part of
444 // destruction such windows may query the RootWindow for state.
445 std::queue<aura::Window*> non_toplevel_windows;
446 non_toplevel_windows.push(root_window_.get());
447 while (!non_toplevel_windows.empty()) {
448 aura::Window* non_toplevel_window = non_toplevel_windows.front();
449 non_toplevel_windows.pop();
450 aura::WindowTracker toplevel_windows;
451 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
452 aura::Window* child = non_toplevel_window->children()[i];
453 if (!child->owned_by_parent())
454 continue;
455 if (child->delegate())
456 toplevel_windows.Add(child);
457 else
458 non_toplevel_windows.push(child);
460 while (!toplevel_windows.windows().empty())
461 delete *toplevel_windows.windows().begin();
463 // And then remove the containers.
464 while (!root_window_->children().empty()) {
465 aura::Window* window = root_window_->children()[0];
466 if (window->owned_by_parent()) {
467 delete window;
468 } else {
469 root_window_->RemoveChild(window);
473 shelf_.reset(NULL);
476 void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) {
477 // Forget the shelf early so that shelf don't update itself using wrong
478 // display info.
479 workspace_controller_->SetShelf(NULL);
480 ReparentAllWindows(root_window_.get(), dst);
483 ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
484 return shelf_->shelf_layout_manager();
487 SystemTray* RootWindowController::GetSystemTray() {
488 // We assume in throughout the code that this will not return NULL. If code
489 // triggers this for valid reasons, it should test status_area_widget first.
490 CHECK(shelf_->status_area_widget());
491 return shelf_->status_area_widget()->system_tray();
494 void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
495 ui::MenuSourceType source_type) {
496 DCHECK(Shell::GetInstance()->delegate());
497 scoped_ptr<ui::MenuModel> menu_model(
498 Shell::GetInstance()->delegate()->CreateContextMenu(root_window()));
499 if (!menu_model)
500 return;
502 // Background controller may not be set yet if user clicked on status are
503 // before initial animation completion. See crbug.com/222218
504 if (!wallpaper_controller_.get())
505 return;
507 views::MenuRunner menu_runner(menu_model.get());
508 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
509 NULL, gfx::Rect(location_in_screen, gfx::Size()),
510 views::MenuItemView::TOPLEFT, source_type,
511 views::MenuRunner::CONTEXT_MENU) ==
512 views::MenuRunner::MENU_DELETED) {
513 return;
516 Shell::GetInstance()->UpdateShelfVisibility();
519 void RootWindowController::UpdateShelfVisibility() {
520 shelf_->shelf_layout_manager()->UpdateVisibilityState();
523 const aura::Window* RootWindowController::GetTopmostFullscreenWindow() const {
524 const aura::Window::Windows& windows =
525 GetContainer(kShellWindowId_DefaultContainer)->children();
526 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
527 iter != windows.rend(); ++iter) {
528 if (wm::GetWindowState(*iter)->IsFullscreen())
529 return *iter;
531 return NULL;
534 void RootWindowController::ActivateKeyboard(
535 keyboard::KeyboardController* keyboard_controller) {
536 if (!keyboard::IsKeyboardEnabled() ||
537 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
538 return;
540 DCHECK(keyboard_controller);
541 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
542 keyboard_controller->AddObserver(panel_layout_manager_);
543 keyboard_controller->AddObserver(docked_layout_manager_);
544 aura::Window* parent = root_window();
545 aura::Window* keyboard_container =
546 keyboard_controller->GetContainerWindow();
547 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
548 parent->AddChild(keyboard_container);
549 // TODO(oshima): Bounds of keyboard container should be handled by
550 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
551 keyboard_container->SetBounds(parent->bounds());
554 void RootWindowController::DeactivateKeyboard(
555 keyboard::KeyboardController* keyboard_controller) {
556 if (!keyboard::IsKeyboardEnabled())
557 return;
559 DCHECK(keyboard_controller);
560 aura::Window* keyboard_container =
561 keyboard_controller->GetContainerWindow();
562 if (keyboard_container->GetRootWindow() == root_window()) {
563 root_window()->RemoveChild(keyboard_container);
564 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
565 keyboard_controller->RemoveObserver(panel_layout_manager_);
566 keyboard_controller->RemoveObserver(docked_layout_manager_);
571 ////////////////////////////////////////////////////////////////////////////////
572 // RootWindowController, private:
574 void RootWindowController::InitLayoutManagers() {
575 root_window_layout_ =
576 new RootWindowLayoutManager(root_window_.get());
577 root_window_->SetLayoutManager(root_window_layout_);
579 aura::Window* default_container =
580 GetContainer(kShellWindowId_DefaultContainer);
581 // Workspace manager has its own layout managers.
582 workspace_controller_.reset(
583 new WorkspaceController(default_container));
585 aura::Window* always_on_top_container =
586 GetContainer(kShellWindowId_AlwaysOnTopContainer);
587 always_on_top_container->SetLayoutManager(
588 new BaseLayoutManager(
589 always_on_top_container->GetRootWindow()));
590 always_on_top_controller_.reset(new internal::AlwaysOnTopController);
591 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
593 DCHECK(!shelf_.get());
594 aura::Window* shelf_container =
595 GetContainer(internal::kShellWindowId_ShelfContainer);
596 // TODO(harrym): Remove when status area is view.
597 aura::Window* status_container =
598 GetContainer(internal::kShellWindowId_StatusContainer);
599 shelf_.reset(new ShelfWidget(
600 shelf_container, status_container, workspace_controller()));
602 if (!Shell::GetInstance()->session_state_delegate()->
603 IsActiveUserSessionStarted()) {
604 // This window exists only to be a event target on login screen.
605 // It does not have to handle events, nor be visible.
606 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
607 mouse_event_target_->Init(ui::LAYER_NOT_DRAWN);
609 aura::Window* lock_background_container =
610 GetContainer(internal::kShellWindowId_LockScreenBackgroundContainer);
611 lock_background_container->AddChild(mouse_event_target_.get());
612 mouse_event_target_->Show();
615 // Create Docked windows layout manager
616 aura::Window* docked_container = GetContainer(
617 internal::kShellWindowId_DockedContainer);
618 docked_layout_manager_ =
619 new internal::DockedWindowLayoutManager(docked_container,
620 workspace_controller());
621 docked_container_handler_.reset(
622 new ToplevelWindowEventHandler(docked_container));
623 docked_container->SetLayoutManager(docked_layout_manager_);
625 // Create Panel layout manager
626 aura::Window* panel_container = GetContainer(
627 internal::kShellWindowId_PanelContainer);
628 panel_layout_manager_ =
629 new internal::PanelLayoutManager(panel_container);
630 panel_container_handler_.reset(
631 new PanelWindowEventHandler(panel_container));
632 panel_container->SetLayoutManager(panel_layout_manager_);
635 void RootWindowController::InitTouchHuds() {
636 CommandLine* command_line = CommandLine::ForCurrentProcess();
637 if (command_line->HasSwitch(switches::kAshTouchHud))
638 set_touch_hud_debug(new TouchHudDebug(root_window_.get()));
639 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
640 EnableTouchHudProjection();
643 void RootWindowController::CreateSystemBackground(
644 bool is_first_run_after_boot) {
645 SkColor color = SK_ColorBLACK;
646 #if defined(OS_CHROMEOS)
647 if (is_first_run_after_boot)
648 color = kChromeOsBootColor;
649 #endif
650 system_background_.reset(
651 new SystemBackgroundController(root_window_.get(), color));
653 #if defined(OS_CHROMEOS)
654 // Make a copy of the system's boot splash screen so we can composite it
655 // onscreen until the desktop background is ready.
656 if (is_first_run_after_boot &&
657 (CommandLine::ForCurrentProcess()->HasSwitch(
658 switches::kAshCopyHostBackgroundAtBoot) ||
659 CommandLine::ForCurrentProcess()->HasSwitch(
660 switches::kAshAnimateFromBootSplashScreen)))
661 boot_splash_screen_.reset(new BootSplashScreen(root_window_.get()));
662 #endif
665 void RootWindowController::CreateContainersInRootWindow(
666 aura::RootWindow* root_window) {
667 // These containers are just used by PowerButtonController to animate groups
668 // of containers simultaneously without messing up the current transformations
669 // on those containers. These are direct children of the root window; all of
670 // the other containers are their children.
672 // The desktop background container is not part of the lock animation, so it
673 // is not included in those animate groups.
674 // When screen is locked desktop background is moved to lock screen background
675 // container (moved back on unlock). We want to make sure that there's an
676 // opaque layer occluding the non-lock-screen layers.
677 aura::Window* desktop_background_container = CreateContainer(
678 kShellWindowId_DesktopBackgroundContainer,
679 "DesktopBackgroundContainer",
680 root_window);
681 views::corewm::SetChildWindowVisibilityChangesAnimated(
682 desktop_background_container);
684 aura::Window* non_lock_screen_containers = CreateContainer(
685 kShellWindowId_NonLockScreenContainersContainer,
686 "NonLockScreenContainersContainer",
687 root_window);
689 aura::Window* lock_background_containers = CreateContainer(
690 kShellWindowId_LockScreenBackgroundContainer,
691 "LockScreenBackgroundContainer",
692 root_window);
693 views::corewm::SetChildWindowVisibilityChangesAnimated(
694 lock_background_containers);
696 aura::Window* lock_screen_containers = CreateContainer(
697 kShellWindowId_LockScreenContainersContainer,
698 "LockScreenContainersContainer",
699 root_window);
700 aura::Window* lock_screen_related_containers = CreateContainer(
701 kShellWindowId_LockScreenRelatedContainersContainer,
702 "LockScreenRelatedContainersContainer",
703 root_window);
705 CreateContainer(kShellWindowId_UnparentedControlContainer,
706 "UnparentedControlContainer",
707 non_lock_screen_containers);
709 aura::Window* default_container = CreateContainer(
710 kShellWindowId_DefaultContainer,
711 "DefaultContainer",
712 non_lock_screen_containers);
713 views::corewm::SetChildWindowVisibilityChangesAnimated(default_container);
714 SetUsesScreenCoordinates(default_container);
716 aura::Window* always_on_top_container = CreateContainer(
717 kShellWindowId_AlwaysOnTopContainer,
718 "AlwaysOnTopContainer",
719 non_lock_screen_containers);
720 always_on_top_container_handler_.reset(
721 new ToplevelWindowEventHandler(always_on_top_container));
722 views::corewm::SetChildWindowVisibilityChangesAnimated(
723 always_on_top_container);
724 SetUsesScreenCoordinates(always_on_top_container);
726 aura::Window* docked_container = CreateContainer(
727 kShellWindowId_DockedContainer,
728 "DockedContainer",
729 non_lock_screen_containers);
730 views::corewm::SetChildWindowVisibilityChangesAnimated(docked_container);
731 SetUsesScreenCoordinates(docked_container);
733 aura::Window* panel_container = CreateContainer(
734 kShellWindowId_PanelContainer,
735 "PanelContainer",
736 non_lock_screen_containers);
737 SetUsesScreenCoordinates(panel_container);
739 aura::Window* shelf_container =
740 CreateContainer(kShellWindowId_ShelfContainer,
741 "ShelfContainer",
742 non_lock_screen_containers);
743 SetUsesScreenCoordinates(shelf_container);
744 DescendantShouldStayInSameRootWindow(shelf_container);
746 aura::Window* app_list_container =
747 CreateContainer(kShellWindowId_AppListContainer,
748 "AppListContainer",
749 non_lock_screen_containers);
750 SetUsesScreenCoordinates(app_list_container);
752 aura::Window* modal_container = CreateContainer(
753 kShellWindowId_SystemModalContainer,
754 "SystemModalContainer",
755 non_lock_screen_containers);
756 modal_container_handler_.reset(
757 new ToplevelWindowEventHandler(modal_container));
758 modal_container->SetLayoutManager(
759 new SystemModalContainerLayoutManager(modal_container));
760 views::corewm::SetChildWindowVisibilityChangesAnimated(modal_container);
761 SetUsesScreenCoordinates(modal_container);
763 aura::Window* input_method_container = CreateContainer(
764 kShellWindowId_InputMethodContainer,
765 "InputMethodContainer",
766 non_lock_screen_containers);
767 SetUsesScreenCoordinates(input_method_container);
769 // TODO(beng): Figure out if we can make this use
770 // SystemModalContainerEventFilter instead of stops_event_propagation.
771 aura::Window* lock_container = CreateContainer(
772 kShellWindowId_LockScreenContainer,
773 "LockScreenContainer",
774 lock_screen_containers);
775 lock_container->SetLayoutManager(
776 new BaseLayoutManager(root_window));
777 SetUsesScreenCoordinates(lock_container);
778 // TODO(beng): stopsevents
780 aura::Window* lock_modal_container = CreateContainer(
781 kShellWindowId_LockSystemModalContainer,
782 "LockSystemModalContainer",
783 lock_screen_containers);
784 lock_modal_container_handler_.reset(
785 new ToplevelWindowEventHandler(lock_modal_container));
786 lock_modal_container->SetLayoutManager(
787 new SystemModalContainerLayoutManager(lock_modal_container));
788 views::corewm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
789 SetUsesScreenCoordinates(lock_modal_container);
791 aura::Window* status_container =
792 CreateContainer(kShellWindowId_StatusContainer,
793 "StatusContainer",
794 lock_screen_related_containers);
795 SetUsesScreenCoordinates(status_container);
796 DescendantShouldStayInSameRootWindow(status_container);
798 aura::Window* settings_bubble_container = CreateContainer(
799 kShellWindowId_SettingBubbleContainer,
800 "SettingBubbleContainer",
801 lock_screen_related_containers);
802 views::corewm::SetChildWindowVisibilityChangesAnimated(
803 settings_bubble_container);
804 SetUsesScreenCoordinates(settings_bubble_container);
805 DescendantShouldStayInSameRootWindow(settings_bubble_container);
807 aura::Window* menu_container = CreateContainer(
808 kShellWindowId_MenuContainer,
809 "MenuContainer",
810 lock_screen_related_containers);
811 views::corewm::SetChildWindowVisibilityChangesAnimated(menu_container);
812 SetUsesScreenCoordinates(menu_container);
814 aura::Window* drag_drop_container = CreateContainer(
815 kShellWindowId_DragImageAndTooltipContainer,
816 "DragImageAndTooltipContainer",
817 lock_screen_related_containers);
818 views::corewm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
819 SetUsesScreenCoordinates(drag_drop_container);
821 aura::Window* overlay_container = CreateContainer(
822 kShellWindowId_OverlayContainer,
823 "OverlayContainer",
824 lock_screen_related_containers);
825 SetUsesScreenCoordinates(overlay_container);
827 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
828 "PowerButtonAnimationContainer", root_window) ;
831 void RootWindowController::EnableTouchHudProjection() {
832 if (touch_hud_projection_)
833 return;
834 set_touch_hud_projection(new TouchHudProjection(root_window_.get()));
837 void RootWindowController::DisableTouchHudProjection() {
838 if (!touch_hud_projection_)
839 return;
840 touch_hud_projection_->Remove();
843 void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
844 shelf_->shelf_layout_manager()->UpdateVisibilityState();
847 void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
848 if (enabled)
849 EnableTouchHudProjection();
850 else
851 DisableTouchHudProjection();
854 RootWindowController* GetRootWindowController(
855 const aura::RootWindow* root_window) {
856 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
859 } // namespace internal
860 } // namespace ash