Replacing old devtools pillar page with newer one
[chromium-blink-merge.git] / ash / root_window_controller.cc
blob7c42ca72e5feeccb5c0ccefafceb2f4d469028c2
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_controller.h"
13 #include "ash/desktop_background/desktop_background_widget_controller.h"
14 #include "ash/desktop_background/user_wallpaper_delegate.h"
15 #include "ash/display/display_manager.h"
16 #include "ash/focus_cycler.h"
17 #include "ash/high_contrast/high_contrast_controller.h"
18 #include "ash/root_window_settings.h"
19 #include "ash/session_state_delegate.h"
20 #include "ash/shelf/shelf_layout_manager.h"
21 #include "ash/shelf/shelf_types.h"
22 #include "ash/shelf/shelf_widget.h"
23 #include "ash/shell.h"
24 #include "ash/shell_delegate.h"
25 #include "ash/shell_factory.h"
26 #include "ash/shell_window_ids.h"
27 #include "ash/system/status_area_widget.h"
28 #include "ash/system/tray/system_tray_delegate.h"
29 #include "ash/touch/touch_hud_debug.h"
30 #include "ash/touch/touch_hud_projection.h"
31 #include "ash/touch/touch_observer_hud.h"
32 #include "ash/wm/always_on_top_controller.h"
33 #include "ash/wm/dock/docked_window_layout_manager.h"
34 #include "ash/wm/panels/panel_layout_manager.h"
35 #include "ash/wm/panels/panel_window_event_handler.h"
36 #include "ash/wm/root_window_layout_manager.h"
37 #include "ash/wm/screen_dimmer.h"
38 #include "ash/wm/stacking_controller.h"
39 #include "ash/wm/status_area_layout_manager.h"
40 #include "ash/wm/system_background_controller.h"
41 #include "ash/wm/system_modal_container_layout_manager.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/workspace_layout_manager.h"
46 #include "ash/wm/workspace_controller.h"
47 #include "base/command_line.h"
48 #include "base/time/time.h"
49 #include "ui/aura/client/aura_constants.h"
50 #include "ui/aura/client/drag_drop_client.h"
51 #include "ui/aura/client/tooltip_client.h"
52 #include "ui/aura/root_window.h"
53 #include "ui/aura/window.h"
54 #include "ui/aura/window_delegate.h"
55 #include "ui/aura/window_observer.h"
56 #include "ui/aura/window_tracker.h"
57 #include "ui/base/hit_test.h"
58 #include "ui/base/models/menu_model.h"
59 #include "ui/gfx/display.h"
60 #include "ui/gfx/screen.h"
61 #include "ui/keyboard/keyboard_controller.h"
62 #include "ui/keyboard/keyboard_util.h"
63 #include "ui/views/controls/menu/menu_runner.h"
64 #include "ui/views/corewm/capture_controller.h"
65 #include "ui/views/corewm/visibility_controller.h"
66 #include "ui/views/corewm/window_util.h"
67 #include "ui/views/view_model.h"
68 #include "ui/views/view_model_utils.h"
69 #include "ui/wm/public/easy_resize_window_targeter.h"
70 #include "ui/wm/public/window_types.h"
72 #if defined(OS_CHROMEOS)
73 #include "ash/wm/boot_splash_screen_chromeos.h"
74 #endif
76 namespace ash {
77 namespace {
79 #if defined(OS_CHROMEOS)
80 // Duration for the animation that hides the boot splash screen, in
81 // milliseconds. This should be short enough in relation to
82 // wm/window_animation.cc's brightness/grayscale fade animation that the login
83 // background image animation isn't hidden by the splash screen animation.
84 const int kBootSplashScreenHideDurationMs = 500;
85 #endif
87 // Creates a new window for use as a container.
88 aura::Window* CreateContainer(int window_id,
89 const char* name,
90 aura::Window* parent) {
91 aura::Window* container = new aura::Window(NULL);
92 container->set_id(window_id);
93 container->SetName(name);
94 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
95 parent->AddChild(container);
96 if (window_id != internal::kShellWindowId_UnparentedControlContainer)
97 container->Show();
98 return container;
101 float ToRelativeValue(int value, int src, int dst) {
102 return static_cast<float>(value) / static_cast<float>(src) * dst;
105 void MoveOriginRelativeToSize(const gfx::Size& src_size,
106 const gfx::Size& dst_size,
107 gfx::Rect* bounds_in_out) {
108 gfx::Point origin = bounds_in_out->origin();
109 bounds_in_out->set_origin(gfx::Point(
110 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
111 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
114 // Reparents |window| to |new_parent|.
115 void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
116 const gfx::Size src_size = window->parent()->bounds().size();
117 const gfx::Size dst_size = new_parent->bounds().size();
118 // Update the restore bounds to make it relative to the display.
119 wm::WindowState* state = wm::GetWindowState(window);
120 gfx::Rect restore_bounds;
121 bool has_restore_bounds = state->HasRestoreBounds();
123 bool update_bounds = (state->IsNormalShowState() || state->IsMinimized()) &&
124 new_parent->id() != internal::kShellWindowId_DockedContainer;
125 gfx::Rect local_bounds;
126 if (update_bounds) {
127 local_bounds = state->window()->bounds();
128 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
131 if (has_restore_bounds) {
132 restore_bounds = state->GetRestoreBoundsInParent();
133 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
136 new_parent->AddChild(window);
138 // Docked windows have bounds handled by the layout manager in AddChild().
139 if (update_bounds)
140 window->SetBounds(local_bounds);
142 if (has_restore_bounds)
143 state->SetRestoreBoundsInParent(restore_bounds);
146 // Reparents the appropriate set of windows from |src| to |dst|.
147 void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
148 // Set of windows to move.
149 const int kContainerIdsToMove[] = {
150 internal::kShellWindowId_DefaultContainer,
151 internal::kShellWindowId_DockedContainer,
152 internal::kShellWindowId_PanelContainer,
153 internal::kShellWindowId_AlwaysOnTopContainer,
154 internal::kShellWindowId_SystemModalContainer,
155 internal::kShellWindowId_LockSystemModalContainer,
156 internal::kShellWindowId_InputMethodContainer,
157 internal::kShellWindowId_UnparentedControlContainer,
159 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
160 int id = kContainerIdsToMove[i];
161 aura::Window* src_container = Shell::GetContainer(src, id);
162 aura::Window* dst_container = Shell::GetContainer(dst, id);
163 while (!src_container->children().empty()) {
164 // Restart iteration from the source container windows each time as they
165 // may change as a result of moving other windows.
166 aura::Window::Windows::const_iterator iter =
167 src_container->children().begin();
168 while (iter != src_container->children().end() &&
169 internal::SystemModalContainerLayoutManager::IsModalBackground(
170 *iter)) {
171 ++iter;
173 // If the entire window list is modal background windows then stop.
174 if (iter == src_container->children().end())
175 break;
176 ReparentWindow(*iter, dst_container);
181 // Mark the container window so that a widget added to this container will
182 // use the virtual screeen coordinates instead of parent.
183 void SetUsesScreenCoordinates(aura::Window* container) {
184 container->SetProperty(internal::kUsesScreenCoordinatesKey, true);
187 // Mark the container window so that a widget added to this container will
188 // say in the same root window regardless of the bounds specified.
189 void DescendantShouldStayInSameRootWindow(aura::Window* container) {
190 container->SetProperty(internal::kStayInSameRootWindowKey, true);
193 void SetUsesEasyResizeTargeter(aura::Window* container) {
194 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
195 -kResizeOutsideBoundsSize,
196 -kResizeOutsideBoundsSize,
197 -kResizeOutsideBoundsSize);
198 gfx::Insets touch_extend = mouse_extend.Scale(
199 kResizeOutsideBoundsScaleForTouch);
200 container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
201 new ::wm::EasyResizeWindowTargeter(container, mouse_extend,
202 touch_extend)));
205 // A window delegate which does nothing. Used to create a window that
206 // is a event target, but do nothing.
207 class EmptyWindowDelegate : public aura::WindowDelegate {
208 public:
209 EmptyWindowDelegate() {}
210 virtual ~EmptyWindowDelegate() {}
212 // aura::WindowDelegate overrides:
213 virtual gfx::Size GetMinimumSize() const OVERRIDE {
214 return gfx::Size();
216 virtual gfx::Size GetMaximumSize() const OVERRIDE {
217 return gfx::Size();
219 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
220 const gfx::Rect& new_bounds) OVERRIDE {
222 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
223 return gfx::kNullCursor;
225 virtual int GetNonClientComponent(
226 const gfx::Point& point) const OVERRIDE {
227 return HTNOWHERE;
229 virtual bool ShouldDescendIntoChildForEventHandling(
230 aura::Window* child,
231 const gfx::Point& location) OVERRIDE {
232 return false;
234 virtual bool CanFocus() OVERRIDE {
235 return false;
237 virtual void OnCaptureLost() OVERRIDE {
239 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
241 virtual void OnDeviceScaleFactorChanged(
242 float device_scale_factor) OVERRIDE {
244 virtual void OnWindowDestroying() OVERRIDE {}
245 virtual void OnWindowDestroyed() OVERRIDE {
246 delete this;
248 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
250 virtual bool HasHitTestMask() const OVERRIDE {
251 return false;
253 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
254 virtual void DidRecreateLayer(ui::Layer* old_layer,
255 ui::Layer* new_layer) OVERRIDE {}
257 private:
258 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
261 } // namespace
263 namespace internal {
265 void RootWindowController::CreateForPrimaryDisplay(
266 aura::RootWindow* root) {
267 RootWindowController* controller = new RootWindowController(root);
268 controller->Init(RootWindowController::PRIMARY,
269 Shell::GetInstance()->delegate()->IsFirstRunAfterBoot());
272 void RootWindowController::CreateForSecondaryDisplay(aura::RootWindow * root) {
273 RootWindowController* controller = new RootWindowController(root);
274 controller->Init(RootWindowController::SECONDARY, false /* first run */);
277 void RootWindowController::CreateForVirtualKeyboardDisplay(
278 aura::RootWindow * root) {
279 RootWindowController* controller = new RootWindowController(root);
280 controller->Init(RootWindowController::VIRTUAL_KEYBOARD,
281 false /* first run */);
284 // static
285 RootWindowController* RootWindowController::ForShelf(aura::Window* window) {
286 return GetRootWindowController(window->GetRootWindow());
289 // static
290 RootWindowController* RootWindowController::ForWindow(
291 const aura::Window* window) {
292 return GetRootWindowController(window->GetRootWindow());
295 // static
296 RootWindowController* RootWindowController::ForTargetRootWindow() {
297 return internal::GetRootWindowController(Shell::GetTargetRootWindow());
300 // static
301 aura::Window* RootWindowController::GetContainerForWindow(
302 aura::Window* window) {
303 aura::Window* container = window->parent();
304 while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN)
305 container = container->parent();
306 return container;
309 RootWindowController::~RootWindowController() {
310 Shutdown();
311 root_window_.reset();
312 // The CaptureClient needs to be around for as long as the RootWindow is
313 // valid.
314 capture_client_.reset();
317 void RootWindowController::SetWallpaperController(
318 DesktopBackgroundWidgetController* controller) {
319 wallpaper_controller_.reset(controller);
322 void RootWindowController::SetAnimatingWallpaperController(
323 AnimatingDesktopController* controller) {
324 if (animating_wallpaper_controller_.get())
325 animating_wallpaper_controller_->StopAnimating();
326 animating_wallpaper_controller_.reset(controller);
329 void RootWindowController::Shutdown() {
330 Shell::GetInstance()->RemoveShellObserver(this);
332 if (animating_wallpaper_controller_.get())
333 animating_wallpaper_controller_->StopAnimating();
334 wallpaper_controller_.reset();
335 animating_wallpaper_controller_.reset();
337 // Change the target root window before closing child windows. If any child
338 // being removed triggers a relayout of the shelf it will try to build a
339 // window list adding windows from the target root window's containers which
340 // may have already gone away.
341 if (Shell::GetTargetRootWindow() == root_window()) {
342 Shell::GetInstance()->set_target_root_window(
343 Shell::GetPrimaryRootWindow() == root_window() ?
344 NULL : Shell::GetPrimaryRootWindow());
347 CloseChildWindows();
348 GetRootWindowSettings(root_window())->controller = NULL;
349 screen_dimmer_.reset();
350 workspace_controller_.reset();
351 // Forget with the display ID so that display lookup
352 // ends up with invalid display.
353 internal::GetRootWindowSettings(root_window())->display_id =
354 gfx::Display::kInvalidDisplayID;
355 // And this root window should no longer process events.
356 root_window_->PrepareForShutdown();
358 system_background_.reset();
361 SystemModalContainerLayoutManager*
362 RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
363 aura::Window* modal_container = NULL;
364 if (window) {
365 aura::Window* window_container = GetContainerForWindow(window);
366 if (window_container &&
367 window_container->id() >= kShellWindowId_LockScreenContainer) {
368 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
369 } else {
370 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
372 } else {
373 int modal_window_id = Shell::GetInstance()->session_state_delegate()
374 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
375 kShellWindowId_SystemModalContainer;
376 modal_container = GetContainer(modal_window_id);
378 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
379 modal_container->layout_manager()) : NULL;
382 aura::Window* RootWindowController::GetContainer(int container_id) {
383 return root_window()->GetChildById(container_id);
386 const aura::Window* RootWindowController::GetContainer(int container_id) const {
387 return root_window_->window()->GetChildById(container_id);
390 void RootWindowController::ShowShelf() {
391 if (!shelf_->shelf())
392 return;
393 shelf_->shelf()->SetVisible(true);
394 shelf_->status_area_widget()->Show();
397 void RootWindowController::OnShelfCreated() {
398 if (panel_layout_manager_)
399 panel_layout_manager_->SetShelf(shelf_->shelf());
400 if (docked_layout_manager_) {
401 docked_layout_manager_->SetShelf(shelf_->shelf());
402 if (shelf_->shelf_layout_manager())
403 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
407 void RootWindowController::UpdateAfterLoginStatusChange(
408 user::LoginStatus status) {
409 if (status != user::LOGGED_IN_NONE)
410 mouse_event_target_.reset();
411 if (shelf_->status_area_widget())
412 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
415 void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
416 #if defined(OS_CHROMEOS)
417 if (CommandLine::ForCurrentProcess()->HasSwitch(
418 switches::kAshAnimateFromBootSplashScreen) &&
419 boot_splash_screen_.get()) {
420 // Make the splash screen fade out so it doesn't obscure the desktop
421 // wallpaper's brightness/grayscale animation.
422 boot_splash_screen_->StartHideAnimation(
423 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
425 #endif
428 void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
429 // Make sure the wallpaper is visible.
430 system_background_->SetColor(SK_ColorBLACK);
431 #if defined(OS_CHROMEOS)
432 boot_splash_screen_.reset();
433 #endif
435 Shell::GetInstance()->user_wallpaper_delegate()->
436 OnWallpaperAnimationFinished();
437 // Only removes old component when wallpaper animation finished. If we
438 // remove the old one before the new wallpaper is done fading in there will
439 // be a white flash during the animation.
440 if (animating_wallpaper_controller()) {
441 DesktopBackgroundWidgetController* controller =
442 animating_wallpaper_controller()->GetController(true);
443 // |desktop_widget_| should be the same animating widget we try to move
444 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
445 // before move it to |kDesktopController|.
446 DCHECK_EQ(controller->widget(), widget);
447 // Release the old controller and close its background widget.
448 SetWallpaperController(controller);
452 void RootWindowController::CloseChildWindows() {
453 mouse_event_target_.reset();
455 // Deactivate keyboard container before closing child windows and shutting
456 // down associated layout managers.
457 DeactivateKeyboard(Shell::GetInstance()->keyboard_controller());
459 // panel_layout_manager_ needs to be shut down before windows are destroyed.
460 if (panel_layout_manager_) {
461 panel_layout_manager_->Shutdown();
462 panel_layout_manager_ = NULL;
464 // docked_layout_manager_ needs to be shut down before windows are destroyed.
465 if (docked_layout_manager_) {
466 if (shelf_ && shelf_->shelf_layout_manager())
467 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
468 docked_layout_manager_->Shutdown();
469 docked_layout_manager_ = NULL;
472 aura::client::SetDragDropClient(root_window(), NULL);
474 // TODO(harrym): Remove when Status Area Widget is a child view.
475 if (shelf_) {
476 shelf_->ShutdownStatusAreaWidget();
478 if (shelf_->shelf_layout_manager())
479 shelf_->shelf_layout_manager()->PrepareForShutdown();
482 // Close background widget first as it depends on tooltip.
483 wallpaper_controller_.reset();
484 animating_wallpaper_controller_.reset();
486 workspace_controller_.reset();
487 aura::client::SetTooltipClient(root_window(), NULL);
489 // Explicitly destroy top level windows. We do this as during part of
490 // destruction such windows may query the RootWindow for state.
491 std::queue<aura::Window*> non_toplevel_windows;
492 non_toplevel_windows.push(root_window());
493 while (!non_toplevel_windows.empty()) {
494 aura::Window* non_toplevel_window = non_toplevel_windows.front();
495 non_toplevel_windows.pop();
496 aura::WindowTracker toplevel_windows;
497 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
498 aura::Window* child = non_toplevel_window->children()[i];
499 if (!child->owned_by_parent())
500 continue;
501 if (child->delegate())
502 toplevel_windows.Add(child);
503 else
504 non_toplevel_windows.push(child);
506 while (!toplevel_windows.windows().empty())
507 delete *toplevel_windows.windows().begin();
509 // And then remove the containers.
510 while (!root_window()->children().empty()) {
511 aura::Window* window = root_window()->children()[0];
512 if (window->owned_by_parent()) {
513 delete window;
514 } else {
515 root_window()->RemoveChild(window);
519 shelf_.reset();
522 void RootWindowController::MoveWindowsTo(aura::Window* dst) {
523 // Forget the shelf early so that shelf don't update itself using wrong
524 // display info.
525 workspace_controller_->SetShelf(NULL);
526 ReparentAllWindows(root_window(), dst);
529 ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
530 return shelf_->shelf_layout_manager();
533 SystemTray* RootWindowController::GetSystemTray() {
534 // We assume in throughout the code that this will not return NULL. If code
535 // triggers this for valid reasons, it should test status_area_widget first.
536 CHECK(shelf_->status_area_widget());
537 return shelf_->status_area_widget()->system_tray();
540 void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
541 ui::MenuSourceType source_type) {
542 DCHECK(Shell::GetInstance()->delegate());
543 scoped_ptr<ui::MenuModel> menu_model(
544 Shell::GetInstance()->delegate()->CreateContextMenu(root_window(),
545 NULL,
546 NULL));
547 if (!menu_model)
548 return;
550 // Background controller may not be set yet if user clicked on status are
551 // before initial animation completion. See crbug.com/222218
552 if (!wallpaper_controller_.get())
553 return;
555 views::MenuRunner menu_runner(menu_model.get());
556 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
557 NULL, gfx::Rect(location_in_screen, gfx::Size()),
558 views::MenuItemView::TOPLEFT, source_type,
559 views::MenuRunner::CONTEXT_MENU) ==
560 views::MenuRunner::MENU_DELETED) {
561 return;
564 Shell::GetInstance()->UpdateShelfVisibility();
567 void RootWindowController::UpdateShelfVisibility() {
568 shelf_->shelf_layout_manager()->UpdateVisibilityState();
571 const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
572 const aura::Window::Windows& windows =
573 GetContainer(kShellWindowId_DefaultContainer)->children();
574 const aura::Window* topmost_window = NULL;
575 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
576 iter != windows.rend(); ++iter) {
577 if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL ||
578 (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) &&
579 (*iter)->layer()->GetTargetVisibility()) {
580 topmost_window = *iter;
581 break;
584 while (topmost_window) {
585 if (wm::GetWindowState(topmost_window)->IsFullscreen())
586 return topmost_window;
587 topmost_window = views::corewm::GetTransientParent(topmost_window);
589 return NULL;
592 void RootWindowController::ActivateKeyboard(
593 keyboard::KeyboardController* keyboard_controller) {
594 if (!keyboard::IsKeyboardEnabled() ||
595 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
596 return;
598 DCHECK(keyboard_controller);
599 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
600 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
601 keyboard_controller->AddObserver(panel_layout_manager_);
602 keyboard_controller->AddObserver(docked_layout_manager_);
604 aura::Window* parent = root_window();
605 aura::Window* keyboard_container =
606 keyboard_controller->GetContainerWindow();
607 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
608 parent->AddChild(keyboard_container);
609 // TODO(oshima): Bounds of keyboard container should be handled by
610 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
611 keyboard_container->SetBounds(parent->bounds());
614 void RootWindowController::DeactivateKeyboard(
615 keyboard::KeyboardController* keyboard_controller) {
616 if (!keyboard_controller ||
617 !keyboard_controller->keyboard_container_initialized()) {
618 return;
620 aura::Window* keyboard_container =
621 keyboard_controller->GetContainerWindow();
622 if (keyboard_container->GetRootWindow() == root_window()) {
623 root_window()->RemoveChild(keyboard_container);
624 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
625 // Virtual keyboard may be deactivated while still showing, notify all
626 // observers that keyboard bounds changed to 0 before remove them.
627 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
628 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
629 keyboard_controller->RemoveObserver(panel_layout_manager_);
630 keyboard_controller->RemoveObserver(docked_layout_manager_);
635 ////////////////////////////////////////////////////////////////////////////////
636 // RootWindowController, private:
638 RootWindowController::RootWindowController(aura::RootWindow* root_window)
639 : root_window_(root_window),
640 root_window_layout_(NULL),
641 docked_layout_manager_(NULL),
642 panel_layout_manager_(NULL),
643 touch_hud_debug_(NULL),
644 touch_hud_projection_(NULL) {
645 GetRootWindowSettings(root_window_->window())->controller = this;
646 screen_dimmer_.reset(new ScreenDimmer(root_window_->window()));
648 stacking_controller_.reset(new StackingController);
649 aura::client::SetWindowTreeClient(root_window_->window(),
650 stacking_controller_.get());
651 capture_client_.reset(
652 new views::corewm::ScopedCaptureClient(root_window_->window()));
655 void RootWindowController::Init(RootWindowType root_window_type,
656 bool first_run_after_boot) {
657 Shell* shell = Shell::GetInstance();
658 shell->InitRootWindow(root_window());
660 root_window_->SetCursor(ui::kCursorPointer);
661 CreateContainersInRootWindow(root_window_->window());
663 if (root_window_type == VIRTUAL_KEYBOARD) {
664 shell->InitKeyboard();
665 return;
668 CreateSystemBackground(first_run_after_boot);
670 InitLayoutManagers();
671 InitTouchHuds();
673 if (Shell::GetPrimaryRootWindowController()->
674 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
675 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
678 shell->AddShellObserver(this);
680 if (root_window_type == PRIMARY) {
681 root_window_layout()->OnWindowResized();
682 if (!keyboard::IsKeyboardUsabilityExperimentEnabled())
683 shell->InitKeyboard();
684 } else {
685 root_window_layout()->OnWindowResized();
686 shell->desktop_background_controller()->OnRootWindowAdded(root_window());
687 shell->high_contrast_controller()->OnRootWindowAdded(
688 root_window_->window());
689 root_window_->host()->Show();
691 // Create a shelf if a user is already logged in.
692 if (shell->session_state_delegate()->NumberOfLoggedInUsers())
693 shelf()->CreateShelf();
697 void RootWindowController::InitLayoutManagers() {
698 root_window_layout_ = new RootWindowLayoutManager(root_window());
699 root_window()->SetLayoutManager(root_window_layout_);
701 aura::Window* default_container =
702 GetContainer(kShellWindowId_DefaultContainer);
703 // Workspace manager has its own layout managers.
704 workspace_controller_.reset(
705 new WorkspaceController(default_container));
707 aura::Window* always_on_top_container =
708 GetContainer(kShellWindowId_AlwaysOnTopContainer);
709 always_on_top_container->SetLayoutManager(
710 new internal::WorkspaceLayoutManager(
711 always_on_top_container));
712 always_on_top_controller_.reset(new internal::AlwaysOnTopController);
713 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
715 DCHECK(!shelf_.get());
716 aura::Window* shelf_container =
717 GetContainer(internal::kShellWindowId_ShelfContainer);
718 // TODO(harrym): Remove when status area is view.
719 aura::Window* status_container =
720 GetContainer(internal::kShellWindowId_StatusContainer);
721 shelf_.reset(new ShelfWidget(
722 shelf_container, status_container, workspace_controller()));
724 if (!Shell::GetInstance()->session_state_delegate()->
725 IsActiveUserSessionStarted()) {
726 // This window exists only to be a event target on login screen.
727 // It does not have to handle events, nor be visible.
728 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
729 mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
731 aura::Window* lock_background_container =
732 GetContainer(internal::kShellWindowId_LockScreenBackgroundContainer);
733 lock_background_container->AddChild(mouse_event_target_.get());
734 mouse_event_target_->Show();
737 // Create Docked windows layout manager
738 aura::Window* docked_container = GetContainer(
739 internal::kShellWindowId_DockedContainer);
740 docked_layout_manager_ =
741 new internal::DockedWindowLayoutManager(docked_container,
742 workspace_controller());
743 docked_container->SetLayoutManager(docked_layout_manager_);
745 // Create Panel layout manager
746 aura::Window* panel_container = GetContainer(
747 internal::kShellWindowId_PanelContainer);
748 panel_layout_manager_ =
749 new internal::PanelLayoutManager(panel_container);
750 panel_container->SetLayoutManager(panel_layout_manager_);
751 panel_container_handler_.reset(new PanelWindowEventHandler);
752 panel_container->AddPreTargetHandler(panel_container_handler_.get());
755 void RootWindowController::InitTouchHuds() {
756 CommandLine* command_line = CommandLine::ForCurrentProcess();
757 if (command_line->HasSwitch(switches::kAshTouchHud))
758 set_touch_hud_debug(new TouchHudDebug(root_window()));
759 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
760 EnableTouchHudProjection();
763 void RootWindowController::CreateSystemBackground(
764 bool is_first_run_after_boot) {
765 SkColor color = SK_ColorBLACK;
766 #if defined(OS_CHROMEOS)
767 if (is_first_run_after_boot)
768 color = kChromeOsBootColor;
769 #endif
770 system_background_.reset(
771 new SystemBackgroundController(root_window(), color));
773 #if defined(OS_CHROMEOS)
774 // Make a copy of the system's boot splash screen so we can composite it
775 // onscreen until the desktop background is ready.
776 if (is_first_run_after_boot &&
777 (CommandLine::ForCurrentProcess()->HasSwitch(
778 switches::kAshCopyHostBackgroundAtBoot) ||
779 CommandLine::ForCurrentProcess()->HasSwitch(
780 switches::kAshAnimateFromBootSplashScreen)))
781 boot_splash_screen_.reset(new BootSplashScreen(root_window_.get()));
782 #endif
785 void RootWindowController::CreateContainersInRootWindow(
786 aura::Window* root_window) {
787 // These containers are just used by PowerButtonController to animate groups
788 // of containers simultaneously without messing up the current transformations
789 // on those containers. These are direct children of the root window; all of
790 // the other containers are their children.
792 // The desktop background container is not part of the lock animation, so it
793 // is not included in those animate groups.
794 // When screen is locked desktop background is moved to lock screen background
795 // container (moved back on unlock). We want to make sure that there's an
796 // opaque layer occluding the non-lock-screen layers.
797 aura::Window* desktop_background_container = CreateContainer(
798 kShellWindowId_DesktopBackgroundContainer,
799 "DesktopBackgroundContainer",
800 root_window);
801 views::corewm::SetChildWindowVisibilityChangesAnimated(
802 desktop_background_container);
804 aura::Window* non_lock_screen_containers = CreateContainer(
805 kShellWindowId_NonLockScreenContainersContainer,
806 "NonLockScreenContainersContainer",
807 root_window);
809 aura::Window* lock_background_containers = CreateContainer(
810 kShellWindowId_LockScreenBackgroundContainer,
811 "LockScreenBackgroundContainer",
812 root_window);
813 views::corewm::SetChildWindowVisibilityChangesAnimated(
814 lock_background_containers);
816 aura::Window* lock_screen_containers = CreateContainer(
817 kShellWindowId_LockScreenContainersContainer,
818 "LockScreenContainersContainer",
819 root_window);
820 aura::Window* lock_screen_related_containers = CreateContainer(
821 kShellWindowId_LockScreenRelatedContainersContainer,
822 "LockScreenRelatedContainersContainer",
823 root_window);
825 CreateContainer(kShellWindowId_UnparentedControlContainer,
826 "UnparentedControlContainer",
827 non_lock_screen_containers);
829 aura::Window* default_container = CreateContainer(
830 kShellWindowId_DefaultContainer,
831 "DefaultContainer",
832 non_lock_screen_containers);
833 views::corewm::SetChildWindowVisibilityChangesAnimated(default_container);
834 SetUsesScreenCoordinates(default_container);
835 SetUsesEasyResizeTargeter(default_container);
837 aura::Window* always_on_top_container = CreateContainer(
838 kShellWindowId_AlwaysOnTopContainer,
839 "AlwaysOnTopContainer",
840 non_lock_screen_containers);
841 views::corewm::SetChildWindowVisibilityChangesAnimated(
842 always_on_top_container);
843 SetUsesScreenCoordinates(always_on_top_container);
845 aura::Window* docked_container = CreateContainer(
846 kShellWindowId_DockedContainer,
847 "DockedContainer",
848 non_lock_screen_containers);
849 views::corewm::SetChildWindowVisibilityChangesAnimated(docked_container);
850 SetUsesScreenCoordinates(docked_container);
851 SetUsesEasyResizeTargeter(docked_container);
853 aura::Window* shelf_container =
854 CreateContainer(kShellWindowId_ShelfContainer,
855 "ShelfContainer",
856 non_lock_screen_containers);
857 SetUsesScreenCoordinates(shelf_container);
858 DescendantShouldStayInSameRootWindow(shelf_container);
860 aura::Window* panel_container = CreateContainer(
861 kShellWindowId_PanelContainer,
862 "PanelContainer",
863 non_lock_screen_containers);
864 SetUsesScreenCoordinates(panel_container);
865 SetUsesEasyResizeTargeter(panel_container);
867 aura::Window* shelf_bubble_container =
868 CreateContainer(kShellWindowId_ShelfBubbleContainer,
869 "ShelfBubbleContainer",
870 non_lock_screen_containers);
871 SetUsesScreenCoordinates(shelf_bubble_container);
872 DescendantShouldStayInSameRootWindow(shelf_bubble_container);
874 aura::Window* app_list_container =
875 CreateContainer(kShellWindowId_AppListContainer,
876 "AppListContainer",
877 non_lock_screen_containers);
878 SetUsesScreenCoordinates(app_list_container);
880 aura::Window* modal_container = CreateContainer(
881 kShellWindowId_SystemModalContainer,
882 "SystemModalContainer",
883 non_lock_screen_containers);
884 modal_container->SetLayoutManager(
885 new SystemModalContainerLayoutManager(modal_container));
886 views::corewm::SetChildWindowVisibilityChangesAnimated(modal_container);
887 SetUsesScreenCoordinates(modal_container);
888 SetUsesEasyResizeTargeter(modal_container);
890 aura::Window* input_method_container = CreateContainer(
891 kShellWindowId_InputMethodContainer,
892 "InputMethodContainer",
893 non_lock_screen_containers);
894 views::corewm::SetChildWindowVisibilityChangesAnimated(
895 input_method_container);
896 SetUsesScreenCoordinates(input_method_container);
898 // TODO(beng): Figure out if we can make this use
899 // SystemModalContainerEventFilter instead of stops_event_propagation.
900 aura::Window* lock_container = CreateContainer(
901 kShellWindowId_LockScreenContainer,
902 "LockScreenContainer",
903 lock_screen_containers);
904 lock_container->SetLayoutManager(
905 new internal::WorkspaceLayoutManager(lock_container));
906 SetUsesScreenCoordinates(lock_container);
907 // TODO(beng): stopsevents
909 aura::Window* lock_modal_container = CreateContainer(
910 kShellWindowId_LockSystemModalContainer,
911 "LockSystemModalContainer",
912 lock_screen_containers);
913 lock_modal_container->SetLayoutManager(
914 new SystemModalContainerLayoutManager(lock_modal_container));
915 views::corewm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
916 SetUsesScreenCoordinates(lock_modal_container);
917 SetUsesEasyResizeTargeter(lock_modal_container);
919 aura::Window* status_container =
920 CreateContainer(kShellWindowId_StatusContainer,
921 "StatusContainer",
922 lock_screen_related_containers);
923 SetUsesScreenCoordinates(status_container);
924 DescendantShouldStayInSameRootWindow(status_container);
926 aura::Window* settings_bubble_container = CreateContainer(
927 kShellWindowId_SettingBubbleContainer,
928 "SettingBubbleContainer",
929 lock_screen_related_containers);
930 views::corewm::SetChildWindowVisibilityChangesAnimated(
931 settings_bubble_container);
932 SetUsesScreenCoordinates(settings_bubble_container);
933 DescendantShouldStayInSameRootWindow(settings_bubble_container);
935 aura::Window* menu_container = CreateContainer(
936 kShellWindowId_MenuContainer,
937 "MenuContainer",
938 lock_screen_related_containers);
939 views::corewm::SetChildWindowVisibilityChangesAnimated(menu_container);
940 SetUsesScreenCoordinates(menu_container);
942 aura::Window* drag_drop_container = CreateContainer(
943 kShellWindowId_DragImageAndTooltipContainer,
944 "DragImageAndTooltipContainer",
945 lock_screen_related_containers);
946 views::corewm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
947 SetUsesScreenCoordinates(drag_drop_container);
949 aura::Window* overlay_container = CreateContainer(
950 kShellWindowId_OverlayContainer,
951 "OverlayContainer",
952 lock_screen_related_containers);
953 SetUsesScreenCoordinates(overlay_container);
955 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
956 "PowerButtonAnimationContainer", root_window) ;
959 void RootWindowController::EnableTouchHudProjection() {
960 if (touch_hud_projection_)
961 return;
962 set_touch_hud_projection(new TouchHudProjection(root_window()));
965 void RootWindowController::DisableTouchHudProjection() {
966 if (!touch_hud_projection_)
967 return;
968 touch_hud_projection_->Remove();
971 void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
972 shelf_->shelf_layout_manager()->UpdateVisibilityState();
975 void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
976 if (enabled)
977 EnableTouchHudProjection();
978 else
979 DisableTouchHudProjection();
982 RootWindowController* GetRootWindowController(
983 const aura::Window* root_window) {
984 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
987 } // namespace internal
988 } // namespace ash