blob: 68e15ab5882e0ad66c22bd1b885c83dda13f4abd [file] [log] [blame]
[email protected]d90b8392012-06-13 09:34:561// 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.
4
5#include "ash/root_window_controller.h"
6
[email protected]8b3e3d82013-08-20 14:36:307#include <queue>
[email protected]8d625fb2012-07-18 16:40:068#include <vector>
9
[email protected]44d444c2013-01-30 01:47:4410#include "ash/ash_constants.h"
[email protected]e6e41d2f2012-10-29 19:22:1911#include "ash/ash_switches.h"
[email protected]a273d33a2013-10-17 12:41:2112#include "ash/desktop_background/desktop_background_controller.h"
[email protected]b4ddc7a2012-08-07 04:17:3213#include "ash/desktop_background/desktop_background_widget_controller.h"
[email protected]0bf61732013-07-02 04:35:1014#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]6bdf7952012-11-14 10:10:5815#include "ash/display/display_manager.h"
[email protected]e74aaf0a2012-10-12 18:42:2816#include "ash/focus_cycler.h"
[email protected]a273d33a2013-10-17 12:41:2117#include "ash/high_contrast/high_contrast_controller.h"
[email protected]f5c9dbc2014-04-11 08:13:4518#include "ash/host/ash_window_tree_host.h"
[email protected]f8e6aad2013-08-30 21:49:1119#include "ash/root_window_settings.h"
[email protected]fdf74bf2014-04-30 21:24:0220#include "ash/session/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:5821#include "ash/shelf/shelf_layout_manager.h"
22#include "ash/shelf/shelf_types.h"
23#include "ash/shelf/shelf_widget.h"
[email protected]d90b8392012-06-13 09:34:5624#include "ash/shell.h"
[email protected]e74aaf0a2012-10-12 18:42:2825#include "ash/shell_delegate.h"
[email protected]d90b8392012-06-13 09:34:5626#include "ash/shell_factory.h"
27#include "ash/shell_window_ids.h"
[email protected]2c5db9e2014-02-27 13:58:1428#include "ash/switchable_windows.h"
[email protected]e74aaf0a2012-10-12 18:42:2829#include "ash/system/status_area_widget.h"
[email protected]8674b312012-10-12 19:02:4430#include "ash/system/tray/system_tray_delegate.h"
[email protected]a825e8312014-05-05 22:05:0131#include "ash/system/tray/system_tray_notifier.h"
[email protected]2b8a9bb2013-07-01 22:43:4032#include "ash/touch/touch_hud_debug.h"
33#include "ash/touch/touch_hud_projection.h"
[email protected]80549c152013-07-02 01:42:4734#include "ash/touch/touch_observer_hud.h"
35#include "ash/wm/always_on_top_controller.h"
[email protected]beb4e5c2013-06-18 15:37:0736#include "ash/wm/dock/docked_window_layout_manager.h"
[email protected]68d51332014-06-06 13:51:1337#include "ash/wm/lock_layout_manager.h"
[email protected]b8642ec2014-04-17 05:20:3938#include "ash/wm/panels/attached_panel_window_targeter.h"
[email protected]7095a652013-03-07 19:41:4939#include "ash/wm/panels/panel_layout_manager.h"
[email protected]100659412013-06-21 22:59:5540#include "ash/wm/panels/panel_window_event_handler.h"
[email protected]d90b8392012-06-13 09:34:5641#include "ash/wm/root_window_layout_manager.h"
42#include "ash/wm/screen_dimmer.h"
[email protected]2a2caa02013-01-22 20:50:3643#include "ash/wm/stacking_controller.h"
[email protected]e74aaf0a2012-10-12 18:42:2844#include "ash/wm/status_area_layout_manager.h"
[email protected]e6e41d2f2012-10-29 19:22:1945#include "ash/wm/system_background_controller.h"
[email protected]d90b8392012-06-13 09:34:5646#include "ash/wm/system_modal_container_layout_manager.h"
kevers0e450492014-09-30 16:02:3147#include "ash/wm/virtual_keyboard_container_layout_manager.h"
[email protected]8d625fb2012-07-18 16:40:0648#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3449#include "ash/wm/window_state.h"
[email protected]700849f2013-04-30 17:49:2050#include "ash/wm/window_util.h"
[email protected]1af71f72014-01-29 20:00:5551#include "ash/wm/workspace/workspace_layout_manager.h"
[email protected]d90b8392012-06-13 09:34:5652#include "ash/wm/workspace_controller.h"
[email protected]e6e41d2f2012-10-29 19:22:1953#include "base/command_line.h"
[email protected]1e84c632013-06-27 23:12:2154#include "base/time/time.h"
[email protected]f1853122012-06-27 16:21:2655#include "ui/aura/client/aura_constants.h"
[email protected]2374d1812014-03-04 03:42:2756#include "ui/aura/client/screen_position_client.h"
[email protected]f1853122012-06-27 16:21:2657#include "ui/aura/window.h"
[email protected]cf6fea22013-08-07 14:24:0158#include "ui/aura/window_delegate.h"
[email protected]fcc51c952014-02-21 21:31:2659#include "ui/aura/window_event_dispatcher.h"
[email protected]f1853122012-06-27 16:21:2660#include "ui/aura/window_observer.h"
[email protected]8b3e3d82013-08-20 14:36:3061#include "ui/aura/window_tracker.h"
[email protected]cf6fea22013-08-07 14:24:0162#include "ui/base/hit_test.h"
[email protected]431552c2012-10-23 00:38:3363#include "ui/base/models/menu_model.h"
[email protected]f8e6aad2013-08-30 21:49:1164#include "ui/gfx/display.h"
[email protected]8d625fb2012-07-18 16:40:0665#include "ui/gfx/screen.h"
[email protected]86459e2c2013-04-10 13:39:2466#include "ui/keyboard/keyboard_controller.h"
67#include "ui/keyboard/keyboard_util.h"
[email protected]431552c2012-10-23 00:38:3368#include "ui/views/controls/menu/menu_runner.h"
69#include "ui/views/view_model.h"
70#include "ui/views/view_model_utils.h"
[email protected]ee3ed10772014-03-11 22:02:0171#include "ui/wm/core/capture_controller.h"
[email protected]e319c7e2014-03-14 19:56:1472#include "ui/wm/core/easy_resize_window_targeter.h"
[email protected]ee3ed10772014-03-11 22:02:0173#include "ui/wm/core/visibility_controller.h"
74#include "ui/wm/core/window_util.h"
[email protected]af4552b22014-03-21 19:45:0175#include "ui/wm/public/drag_drop_client.h"
76#include "ui/wm/public/tooltip_client.h"
[email protected]5b251f12013-12-19 01:50:0577#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5678
[email protected]252eb232013-08-14 22:09:2779#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:5080#include "ash/ash_touch_exploration_manager_chromeos.h"
[email protected]252eb232013-08-14 22:09:2781#include "ash/wm/boot_splash_screen_chromeos.h"
[email protected]a825e8312014-05-05 22:05:0182#include "ui/chromeos/touch_exploration_controller.h"
[email protected]252eb232013-08-14 22:09:2783#endif
84
[email protected]d90b8392012-06-13 09:34:5685namespace ash {
86namespace {
87
[email protected]252eb232013-08-14 22:09:2788#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:4989// Duration for the animation that hides the boot splash screen, in
90// milliseconds. This should be short enough in relation to
91// wm/window_animation.cc's brightness/grayscale fade animation that the login
92// background image animation isn't hidden by the splash screen animation.
93const int kBootSplashScreenHideDurationMs = 500;
[email protected]252eb232013-08-14 22:09:2794#endif
[email protected]bca9a7e2012-11-10 06:25:4995
[email protected]d90b8392012-06-13 09:34:5696// Creates a new window for use as a container.
97aura::Window* CreateContainer(int window_id,
98 const char* name,
99 aura::Window* parent) {
100 aura::Window* container = new aura::Window(NULL);
101 container->set_id(window_id);
102 container->SetName(name);
[email protected]52b02a72014-01-08 21:41:50103 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]d90b8392012-06-13 09:34:56104 parent->AddChild(container);
[email protected]093b8d642014-04-03 20:59:28105 if (window_id != kShellWindowId_UnparentedControlContainer)
[email protected]d90b8392012-06-13 09:34:56106 container->Show();
107 return container;
108}
109
[email protected]2816c2462013-12-17 02:22:25110float ToRelativeValue(int value, int src, int dst) {
111 return static_cast<float>(value) / static_cast<float>(src) * dst;
112}
113
114void MoveOriginRelativeToSize(const gfx::Size& src_size,
115 const gfx::Size& dst_size,
116 gfx::Rect* bounds_in_out) {
117 gfx::Point origin = bounds_in_out->origin();
118 bounds_in_out->set_origin(gfx::Point(
119 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
120 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
121}
122
[email protected]95058572012-08-20 14:57:29123// Reparents |window| to |new_parent|.
124void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
[email protected]2816c2462013-12-17 02:22:25125 const gfx::Size src_size = window->parent()->bounds().size();
126 const gfx::Size dst_size = new_parent->bounds().size();
[email protected]95058572012-08-20 14:57:29127 // Update the restore bounds to make it relative to the display.
[email protected]a41b4e12013-09-20 04:36:34128 wm::WindowState* state = wm::GetWindowState(window);
129 gfx::Rect restore_bounds;
130 bool has_restore_bounds = state->HasRestoreBounds();
[email protected]2816c2462013-12-17 02:22:25131
[email protected]9cfd3d12014-02-25 15:33:45132 bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) &&
[email protected]093b8d642014-04-03 20:59:28133 new_parent->id() != kShellWindowId_DockedContainer;
[email protected]2816c2462013-12-17 02:22:25134 gfx::Rect local_bounds;
135 if (update_bounds) {
136 local_bounds = state->window()->bounds();
137 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
138 }
139
140 if (has_restore_bounds) {
[email protected]a41b4e12013-09-20 04:36:34141 restore_bounds = state->GetRestoreBoundsInParent();
[email protected]2816c2462013-12-17 02:22:25142 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
143 }
144
[email protected]95058572012-08-20 14:57:29145 new_parent->AddChild(window);
[email protected]2816c2462013-12-17 02:22:25146
[email protected]8663b7a62014-01-18 01:24:21147 // Docked windows have bounds handled by the layout manager in AddChild().
[email protected]2816c2462013-12-17 02:22:25148 if (update_bounds)
149 window->SetBounds(local_bounds);
150
[email protected]a41b4e12013-09-20 04:36:34151 if (has_restore_bounds)
152 state->SetRestoreBoundsInParent(restore_bounds);
[email protected]95058572012-08-20 14:57:29153}
154
155// Reparents the appropriate set of windows from |src| to |dst|.
[email protected]bf9cdb362013-10-25 19:22:45156void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
[email protected]95058572012-08-20 14:57:29157 // Set of windows to move.
[email protected]f1853122012-06-27 16:21:26158 const int kContainerIdsToMove[] = {
[email protected]093b8d642014-04-03 20:59:28159 kShellWindowId_DefaultContainer,
160 kShellWindowId_DockedContainer,
161 kShellWindowId_PanelContainer,
162 kShellWindowId_AlwaysOnTopContainer,
163 kShellWindowId_SystemModalContainer,
164 kShellWindowId_LockSystemModalContainer,
[email protected]093b8d642014-04-03 20:59:28165 kShellWindowId_UnparentedControlContainer, };
[email protected]f1853122012-06-27 16:21:26166 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
167 int id = kContainerIdsToMove[i];
168 aura::Window* src_container = Shell::GetContainer(src, id);
169 aura::Window* dst_container = Shell::GetContainer(dst, id);
[email protected]5b6021902013-02-26 05:33:29170 while (!src_container->children().empty()) {
171 // Restart iteration from the source container windows each time as they
172 // may change as a result of moving other windows.
173 aura::Window::Windows::const_iterator iter =
174 src_container->children().begin();
175 while (iter != src_container->children().end() &&
[email protected]093b8d642014-04-03 20:59:28176 SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
[email protected]5b6021902013-02-26 05:33:29177 ++iter;
178 }
179 // If the entire window list is modal background windows then stop.
180 if (iter == src_container->children().end())
181 break;
182 ReparentWindow(*iter, dst_container);
[email protected]f1853122012-06-27 16:21:26183 }
184 }
185}
186
[email protected]8d625fb2012-07-18 16:40:06187// Mark the container window so that a widget added to this container will
188// use the virtual screeen coordinates instead of parent.
189void SetUsesScreenCoordinates(aura::Window* container) {
[email protected]093b8d642014-04-03 20:59:28190 container->SetProperty(kUsesScreenCoordinatesKey, true);
[email protected]8d625fb2012-07-18 16:40:06191}
192
[email protected]e887c6c2013-07-08 19:35:53193// Mark the container window so that a widget added to this container will
194// say in the same root window regardless of the bounds specified.
195void DescendantShouldStayInSameRootWindow(aura::Window* container) {
[email protected]093b8d642014-04-03 20:59:28196 container->SetProperty(kStayInSameRootWindowKey, true);
[email protected]e887c6c2013-07-08 19:35:53197}
198
[email protected]c5be8d672014-01-07 13:33:41199void SetUsesEasyResizeTargeter(aura::Window* container) {
200 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
201 -kResizeOutsideBoundsSize,
202 -kResizeOutsideBoundsSize,
203 -kResizeOutsideBoundsSize);
204 gfx::Insets touch_extend = mouse_extend.Scale(
205 kResizeOutsideBoundsScaleForTouch);
[email protected]95f642cb2014-01-31 01:35:41206 container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
[email protected]c5be8d672014-01-07 13:33:41207 new ::wm::EasyResizeWindowTargeter(container, mouse_extend,
208 touch_extend)));
209}
210
[email protected]cf6fea22013-08-07 14:24:01211// A window delegate which does nothing. Used to create a window that
212// is a event target, but do nothing.
213class EmptyWindowDelegate : public aura::WindowDelegate {
214 public:
215 EmptyWindowDelegate() {}
dcheng1f4538e2014-10-27 23:57:05216 ~EmptyWindowDelegate() override {}
[email protected]cf6fea22013-08-07 14:24:01217
218 // aura::WindowDelegate overrides:
dcheng1f4538e2014-10-27 23:57:05219 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
220 gfx::Size GetMaximumSize() const override { return gfx::Size(); }
221 void OnBoundsChanged(const gfx::Rect& old_bounds,
222 const gfx::Rect& new_bounds) override {}
223 gfx::NativeCursor GetCursor(const gfx::Point& point) override {
[email protected]62c9f102014-03-27 06:07:04224 return gfx::kNullCursor;
225 }
dcheng1f4538e2014-10-27 23:57:05226 int GetNonClientComponent(const gfx::Point& point) const override {
[email protected]cf6fea22013-08-07 14:24:01227 return HTNOWHERE;
228 }
dcheng1f4538e2014-10-27 23:57:05229 bool ShouldDescendIntoChildForEventHandling(
[email protected]cf6fea22013-08-07 14:24:01230 aura::Window* child,
mostynb10d6b382014-10-03 16:23:45231 const gfx::Point& location) override {
[email protected]cf6fea22013-08-07 14:24:01232 return false;
233 }
dcheng1f4538e2014-10-27 23:57:05234 bool CanFocus() override { return false; }
235 void OnCaptureLost() override {}
236 void OnPaint(gfx::Canvas* canvas) override {}
237 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
238 void OnWindowDestroying(aura::Window* window) override {}
239 void OnWindowDestroyed(aura::Window* window) override { delete this; }
240 void OnWindowTargetVisibilityChanged(bool visible) override {}
241 bool HasHitTestMask() const override { return false; }
242 void GetHitTestMask(gfx::Path* mask) const override {}
[email protected]cf6fea22013-08-07 14:24:01243
244 private:
245 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
246};
247
[email protected]d90b8392012-06-13 09:34:56248} // namespace
249
[email protected]f5c9dbc2014-04-11 08:13:45250void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38251 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28252 controller->Init(RootWindowController::PRIMARY,
[email protected]a273d33a2013-10-17 12:41:21253 Shell::GetInstance()->delegate()->IsFirstRunAfterBoot());
[email protected]d90b8392012-06-13 09:34:56254}
255
[email protected]f5c9dbc2014-04-11 08:13:45256void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38257 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28258 controller->Init(RootWindowController::SECONDARY, false /* first run */);
259}
260
[email protected]88d71122012-10-18 07:11:01261// static
[email protected]76bc4632014-06-16 19:07:46262RootWindowController* RootWindowController::ForShelf(
263 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07264 CHECK(Shell::HasInstance());
[email protected]8c0ec432013-05-10 04:33:39265 return GetRootWindowController(window->GetRootWindow());
[email protected]88d71122012-10-18 07:11:01266}
267
[email protected]a0afeb12012-12-10 22:57:09268// static
[email protected]ccff3d72013-02-06 04:26:28269RootWindowController* RootWindowController::ForWindow(
270 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07271 CHECK(Shell::HasInstance());
[email protected]a0afeb12012-12-10 22:57:09272 return GetRootWindowController(window->GetRootWindow());
273}
274
275// static
[email protected]d17642d2013-09-12 23:44:38276RootWindowController* RootWindowController::ForTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07277 CHECK(Shell::HasInstance());
[email protected]093b8d642014-04-03 20:59:28278 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09279}
280
[email protected]a5c78802013-12-12 22:07:01281// static
282aura::Window* RootWindowController::GetContainerForWindow(
283 aura::Window* window) {
284 aura::Window* container = window->parent();
[email protected]5b251f12013-12-19 01:50:05285 while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN)
[email protected]a5c78802013-12-12 22:07:01286 container = container->parent();
287 return container;
288}
289
[email protected]a273d33a2013-10-17 12:41:21290RootWindowController::~RootWindowController() {
291 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45292 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21293 // The CaptureClient needs to be around for as long as the RootWindow is
294 // valid.
295 capture_client_.reset();
296}
297
[email protected]f5c9dbc2014-04-11 08:13:45298aura::WindowTreeHost* RootWindowController::GetHost() {
299 return ash_host_->AsWindowTreeHost();
300}
301
302const aura::WindowTreeHost* RootWindowController::GetHost() const {
303 return ash_host_->AsWindowTreeHost();
304}
305
306aura::Window* RootWindowController::GetRootWindow() {
307 return GetHost()->window();
308}
309
310const aura::Window* RootWindowController::GetRootWindow() const {
311 return GetHost()->window();
312}
313
[email protected]0bf61732013-07-02 04:35:10314void RootWindowController::SetWallpaperController(
315 DesktopBackgroundWidgetController* controller) {
316 wallpaper_controller_.reset(controller);
317}
318
319void RootWindowController::SetAnimatingWallpaperController(
320 AnimatingDesktopController* controller) {
321 if (animating_wallpaper_controller_.get())
322 animating_wallpaper_controller_->StopAnimating();
323 animating_wallpaper_controller_.reset(controller);
324}
325
[email protected]6675e1c2012-09-11 09:15:45326void RootWindowController::Shutdown() {
[email protected]a825e8312014-05-05 22:05:01327 Shell* shell = Shell::GetInstance();
328 shell->RemoveShellObserver(this);
329
330#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:50331 if (touch_exploration_manager_) {
332 touch_exploration_manager_.reset();
[email protected]a825e8312014-05-05 22:05:01333 }
334#endif
[email protected]d141b922013-07-09 08:13:17335
[email protected]0bf61732013-07-02 04:35:10336 if (animating_wallpaper_controller_.get())
337 animating_wallpaper_controller_->StopAnimating();
338 wallpaper_controller_.reset();
339 animating_wallpaper_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45340 aura::Window* root_window = GetRootWindow();
[email protected]d17642d2013-09-12 23:44:38341 // Change the target root window before closing child windows. If any child
[email protected]c98a4922013-09-05 20:01:42342 // being removed triggers a relayout of the shelf it will try to build a
[email protected]d17642d2013-09-12 23:44:38343 // window list adding windows from the target root window's containers which
[email protected]c98a4922013-09-05 20:01:42344 // may have already gone away.
[email protected]f5c9dbc2014-04-11 08:13:45345 if (Shell::GetTargetRootWindow() == root_window) {
[email protected]a825e8312014-05-05 22:05:01346 shell->set_target_root_window(
[email protected]f5c9dbc2014-04-11 08:13:45347 Shell::GetPrimaryRootWindow() == root_window
348 ? NULL
349 : Shell::GetPrimaryRootWindow());
[email protected]f634dd32012-07-23 22:49:07350 }
[email protected]c98a4922013-09-05 20:01:42351
352 CloseChildWindows();
[email protected]f5c9dbc2014-04-11 08:13:45353 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]d90b8392012-06-13 09:34:56354 screen_dimmer_.reset();
355 workspace_controller_.reset();
[email protected]6675e1c2012-09-11 09:15:45356 // Forget with the display ID so that display lookup
357 // ends up with invalid display.
[email protected]f5c9dbc2014-04-11 08:13:45358 GetRootWindowSettings(root_window)->display_id =
[email protected]f8e6aad2013-08-30 21:49:11359 gfx::Display::kInvalidDisplayID;
[email protected]8f5209c2014-05-22 20:36:11360 ash_host_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28361
[email protected]956a6a42012-10-29 23:58:10362 system_background_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45363 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56364}
365
[email protected]c0ce80e2012-10-05 23:28:27366SystemModalContainerLayoutManager*
[email protected]8674b312012-10-12 19:02:44367RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
[email protected]a5c78802013-12-12 22:07:01368 aura::Window* modal_container = NULL;
[email protected]8674b312012-10-12 19:02:44369 if (window) {
[email protected]a5c78802013-12-12 22:07:01370 aura::Window* window_container = GetContainerForWindow(window);
371 if (window_container &&
372 window_container->id() >= kShellWindowId_LockScreenContainer) {
373 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35374 } else {
[email protected]a5c78802013-12-12 22:07:01375 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35376 }
[email protected]8674b312012-10-12 19:02:44377 } else {
[email protected]a44afbbd2013-07-24 21:49:35378 int modal_window_id = Shell::GetInstance()->session_state_delegate()
379 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
380 kShellWindowId_SystemModalContainer;
[email protected]a5c78802013-12-12 22:07:01381 modal_container = GetContainer(modal_window_id);
[email protected]8674b312012-10-12 19:02:44382 }
[email protected]a5c78802013-12-12 22:07:01383 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
384 modal_container->layout_manager()) : NULL;
[email protected]c0ce80e2012-10-05 23:28:27385}
386
[email protected]d90b8392012-06-13 09:34:56387aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45388 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56389}
390
[email protected]d8a24952013-08-05 20:05:05391const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45392 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05393}
394
[email protected]864b58552013-12-19 04:19:38395void RootWindowController::ShowShelf() {
396 if (!shelf_->shelf())
[email protected]e74aaf0a2012-10-12 18:42:28397 return;
[email protected]864b58552013-12-19 04:19:38398 shelf_->shelf()->SetVisible(true);
[email protected]478c6c32013-03-09 02:50:58399 shelf_->status_area_widget()->Show();
[email protected]e74aaf0a2012-10-12 18:42:28400}
401
[email protected]864b58552013-12-19 04:19:38402void RootWindowController::OnShelfCreated() {
[email protected]756bda12013-07-03 08:17:06403 if (panel_layout_manager_)
[email protected]864b58552013-12-19 04:19:38404 panel_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39405 if (docked_layout_manager_) {
[email protected]864b58552013-12-19 04:19:38406 docked_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39407 if (shelf_->shelf_layout_manager())
408 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
409 }
[email protected]b8642ec2014-04-17 05:20:39410
411 // Notify shell observers that the shelf has been created.
412 Shell::GetInstance()->OnShelfCreatedForRootWindow(GetRootWindow());
[email protected]756bda12013-07-03 08:17:06413}
414
[email protected]16059276d2012-10-22 18:59:50415void RootWindowController::UpdateAfterLoginStatusChange(
416 user::LoginStatus status) {
[email protected]cf6fea22013-08-07 14:24:01417 if (status != user::LOGGED_IN_NONE)
418 mouse_event_target_.reset();
[email protected]80549c152013-07-02 01:42:47419 if (shelf_->status_area_widget())
[email protected]478c6c32013-03-09 02:50:58420 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
[email protected]16059276d2012-10-22 18:59:50421}
422
[email protected]bca9a7e2012-11-10 06:25:49423void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27424#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49425 if (CommandLine::ForCurrentProcess()->HasSwitch(
426 switches::kAshAnimateFromBootSplashScreen) &&
427 boot_splash_screen_.get()) {
428 // Make the splash screen fade out so it doesn't obscure the desktop
429 // wallpaper's brightness/grayscale animation.
430 boot_splash_screen_->StartHideAnimation(
431 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
432 }
[email protected]252eb232013-08-14 22:09:27433#endif
[email protected]bca9a7e2012-11-10 06:25:49434}
435
[email protected]0bf61732013-07-02 04:35:10436void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
437 // Make sure the wallpaper is visible.
[email protected]bca9a7e2012-11-10 06:25:49438 system_background_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27439#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49440 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27441#endif
[email protected]0bf61732013-07-02 04:35:10442
443 Shell::GetInstance()->user_wallpaper_delegate()->
444 OnWallpaperAnimationFinished();
445 // Only removes old component when wallpaper animation finished. If we
446 // remove the old one before the new wallpaper is done fading in there will
447 // be a white flash during the animation.
448 if (animating_wallpaper_controller()) {
449 DesktopBackgroundWidgetController* controller =
450 animating_wallpaper_controller()->GetController(true);
451 // |desktop_widget_| should be the same animating widget we try to move
452 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
453 // before move it to |kDesktopController|.
454 DCHECK_EQ(controller->widget(), widget);
455 // Release the old controller and close its background widget.
456 SetWallpaperController(controller);
457 }
[email protected]697f04c2012-10-03 01:15:10458}
459
[email protected]d90b8392012-06-13 09:34:56460void RootWindowController::CloseChildWindows() {
[email protected]cf6fea22013-08-07 14:24:01461 mouse_event_target_.reset();
462
[email protected]2a57beb52014-06-09 20:02:26463 // Remove observer as deactivating keyboard causes |docked_layout_manager_|
464 // to fire notifications.
465 if (docked_layout_manager_ && shelf_ && shelf_->shelf_layout_manager())
466 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
467
[email protected]b6ba05d902013-10-04 21:38:45468 // Deactivate keyboard container before closing child windows and shutting
469 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03470 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45471
[email protected]79a87b7e2013-01-25 05:08:22472 // panel_layout_manager_ needs to be shut down before windows are destroyed.
473 if (panel_layout_manager_) {
474 panel_layout_manager_->Shutdown();
475 panel_layout_manager_ = NULL;
476 }
[email protected]7115bd32013-07-19 08:25:39477 // docked_layout_manager_ needs to be shut down before windows are destroyed.
478 if (docked_layout_manager_) {
[email protected]7115bd32013-07-19 08:25:39479 docked_layout_manager_->Shutdown();
480 docked_layout_manager_ = NULL;
481 }
[email protected]f5c9dbc2014-04-11 08:13:45482 aura::Window* root_window = GetRootWindow();
483 aura::client::SetDragDropClient(root_window, NULL);
[email protected]8b3e3d82013-08-20 14:36:30484
[email protected]478c6c32013-03-09 02:50:58485 // TODO(harrym): Remove when Status Area Widget is a child view.
[email protected]bb42c932013-10-31 06:52:06486 if (shelf_) {
487 shelf_->ShutdownStatusAreaWidget();
[email protected]478c6c32013-03-09 02:50:58488
[email protected]bb42c932013-10-31 06:52:06489 if (shelf_->shelf_layout_manager())
490 shelf_->shelf_layout_manager()->PrepareForShutdown();
491 }
[email protected]e74aaf0a2012-10-12 18:42:28492
[email protected]d90b8392012-06-13 09:34:56493 // Close background widget first as it depends on tooltip.
[email protected]0bf61732013-07-02 04:35:10494 wallpaper_controller_.reset();
495 animating_wallpaper_controller_.reset();
[email protected]b4ddc7a2012-08-07 04:17:32496
[email protected]d90b8392012-06-13 09:34:56497 workspace_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45498 aura::client::SetTooltipClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56499
[email protected]0fbfa972013-10-02 19:23:33500 // Explicitly destroy top level windows. We do this as during part of
501 // destruction such windows may query the RootWindow for state.
[email protected]8b3e3d82013-08-20 14:36:30502 std::queue<aura::Window*> non_toplevel_windows;
[email protected]f5c9dbc2014-04-11 08:13:45503 non_toplevel_windows.push(root_window);
[email protected]8b3e3d82013-08-20 14:36:30504 while (!non_toplevel_windows.empty()) {
505 aura::Window* non_toplevel_window = non_toplevel_windows.front();
506 non_toplevel_windows.pop();
507 aura::WindowTracker toplevel_windows;
508 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
509 aura::Window* child = non_toplevel_window->children()[i];
[email protected]0fbfa972013-10-02 19:23:33510 if (!child->owned_by_parent())
511 continue;
[email protected]8b3e3d82013-08-20 14:36:30512 if (child->delegate())
513 toplevel_windows.Add(child);
514 else
515 non_toplevel_windows.push(child);
516 }
517 while (!toplevel_windows.windows().empty())
518 delete *toplevel_windows.windows().begin();
[email protected]d90b8392012-06-13 09:34:56519 }
[email protected]8b3e3d82013-08-20 14:36:30520 // And then remove the containers.
[email protected]f5c9dbc2014-04-11 08:13:45521 while (!root_window->children().empty()) {
522 aura::Window* window = root_window->children()[0];
[email protected]0fbfa972013-10-02 19:23:33523 if (window->owned_by_parent()) {
524 delete window;
525 } else {
[email protected]f5c9dbc2014-04-11 08:13:45526 root_window->RemoveChild(window);
[email protected]0fbfa972013-10-02 19:23:33527 }
528 }
[email protected]478c6c32013-03-09 02:50:58529
[email protected]bb42c932013-10-31 06:52:06530 shelf_.reset();
[email protected]d90b8392012-06-13 09:34:56531}
532
[email protected]bf9cdb362013-10-25 19:22:45533void RootWindowController::MoveWindowsTo(aura::Window* dst) {
[email protected]8039e06c2013-01-17 23:34:50534 // Forget the shelf early so that shelf don't update itself using wrong
535 // display info.
536 workspace_controller_->SetShelf(NULL);
[email protected]f5c9dbc2014-04-11 08:13:45537 ReparentAllWindows(GetRootWindow(), dst);
[email protected]f1853122012-06-27 16:21:26538}
539
[email protected]478c6c32013-03-09 02:50:58540ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
[email protected]80549c152013-07-02 01:42:47541 return shelf_->shelf_layout_manager();
[email protected]478c6c32013-03-09 02:50:58542}
543
[email protected]a0afeb12012-12-10 22:57:09544SystemTray* RootWindowController::GetSystemTray() {
545 // We assume in throughout the code that this will not return NULL. If code
546 // triggers this for valid reasons, it should test status_area_widget first.
[email protected]80549c152013-07-02 01:42:47547 CHECK(shelf_->status_area_widget());
[email protected]478c6c32013-03-09 02:50:58548 return shelf_->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09549}
550
[email protected]940fb1c2013-06-18 16:54:28551void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
552 ui::MenuSourceType source_type) {
[email protected]431552c2012-10-23 00:38:33553 DCHECK(Shell::GetInstance()->delegate());
554 scoped_ptr<ui::MenuModel> menu_model(
[email protected]f5c9dbc2014-04-11 08:13:45555 Shell::GetInstance()->delegate()->CreateContextMenu(
556 GetRootWindow(), NULL, NULL));
[email protected]7f7f65c2013-04-17 16:47:13557 if (!menu_model)
[email protected]8e837ec2013-01-31 01:48:33558 return;
[email protected]431552c2012-10-23 00:38:33559
[email protected]6175fc42013-04-05 05:58:58560 // Background controller may not be set yet if user clicked on status are
561 // before initial animation completion. See crbug.com/222218
[email protected]0bf61732013-07-02 04:35:10562 if (!wallpaper_controller_.get())
[email protected]431552c2012-10-23 00:38:33563 return;
564
[email protected]0a37a5d2014-07-15 00:42:23565 views::MenuRunner menu_runner(menu_model.get(),
566 views::MenuRunner::CONTEXT_MENU);
[email protected]0bf61732013-07-02 04:35:10567 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
[email protected]fd6c0a62014-05-01 07:50:35568 NULL,
569 gfx::Rect(location_in_screen, gfx::Size()),
570 views::MENU_ANCHOR_TOPLEFT,
[email protected]0a37a5d2014-07-15 00:42:23571 source_type) == views::MenuRunner::MENU_DELETED) {
[email protected]6175fc42013-04-05 05:58:58572 return;
573 }
574
[email protected]431552c2012-10-23 00:38:33575 Shell::GetInstance()->UpdateShelfVisibility();
576}
577
[email protected]e74aaf0a2012-10-12 18:42:28578void RootWindowController::UpdateShelfVisibility() {
[email protected]478c6c32013-03-09 02:50:58579 shelf_->shelf_layout_manager()->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28580}
581
[email protected]2c9171d22013-12-10 21:55:10582const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
[email protected]2c9171d22013-12-10 21:55:10583 const aura::Window* topmost_window = NULL;
[email protected]2c5db9e2014-02-27 13:58:14584 const aura::Window* active_window = wm::GetActiveWindow();
[email protected]f5c9dbc2014-04-11 08:13:45585 if (active_window && active_window->GetRootWindow() == GetRootWindow() &&
[email protected]2c5db9e2014-02-27 13:58:14586 IsSwitchableContainer(active_window->parent())) {
587 // Use the active window when it is on the current root window to determine
588 // the fullscreen state to allow temporarily using a panel or docked window
589 // (which are always above the default container) while a fullscreen
590 // window is open. We only use the active window when in a switchable
591 // container as the launcher should not exit fullscreen mode.
592 topmost_window = active_window;
593 } else {
594 // Otherwise, use the topmost window on the root window's default container
595 // when there is no active window on this root window.
596 const aura::Window::Windows& windows =
597 GetContainer(kShellWindowId_DefaultContainer)->children();
598 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
599 iter != windows.rend(); ++iter) {
600 if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL ||
601 (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) &&
602 (*iter)->layer()->GetTargetVisibility()) {
603 topmost_window = *iter;
604 break;
605 }
[email protected]2c9171d22013-12-10 21:55:10606 }
607 }
608 while (topmost_window) {
609 if (wm::GetWindowState(topmost_window)->IsFullscreen())
610 return topmost_window;
[email protected]e319c7e2014-03-14 19:56:14611 topmost_window = ::wm::GetTransientParent(topmost_window);
[email protected]2ee2f5d2013-01-10 23:37:16612 }
[email protected]700849f2013-04-30 17:49:20613 return NULL;
[email protected]2ee2f5d2013-01-10 23:37:16614}
615
[email protected]b6ba05d902013-10-04 21:38:45616void RootWindowController::ActivateKeyboard(
617 keyboard::KeyboardController* keyboard_controller) {
618 if (!keyboard::IsKeyboardEnabled() ||
619 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
620 return;
621 }
622 DCHECK(keyboard_controller);
bshe9858b4a2014-09-16 20:46:38623 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
624 keyboard_controller->AddObserver(panel_layout_manager_);
625 keyboard_controller->AddObserver(docked_layout_manager_);
626 keyboard_controller->AddObserver(workspace_controller_->layout_manager());
627 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(true);
bshec3875422014-09-29 13:21:30628 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52629 DCHECK(parent);
[email protected]b6ba05d902013-10-04 21:38:45630 aura::Window* keyboard_container =
631 keyboard_controller->GetContainerWindow();
632 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
633 parent->AddChild(keyboard_container);
634 // TODO(oshima): Bounds of keyboard container should be handled by
635 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
636 keyboard_container->SetBounds(parent->bounds());
637}
[email protected]86459e2c2013-04-10 13:39:24638
[email protected]b6ba05d902013-10-04 21:38:45639void RootWindowController::DeactivateKeyboard(
640 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41641 if (!keyboard_controller ||
642 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45643 return;
[email protected]e1b299b2014-01-29 23:53:41644 }
[email protected]b6ba05d902013-10-04 21:38:45645 aura::Window* keyboard_container =
646 keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45647 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
bshec3875422014-09-29 13:21:30648 aura::Window* parent =
649 GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52650 DCHECK(parent);
651 parent->RemoveChild(keyboard_container);
bshe9858b4a2014-09-16 20:46:38652 // Virtual keyboard may be deactivated while still showing, notify all
653 // observers that keyboard bounds changed to 0 before remove them.
654 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
655 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
656 keyboard_controller->RemoveObserver(panel_layout_manager_);
657 keyboard_controller->RemoveObserver(docked_layout_manager_);
658 keyboard_controller->RemoveObserver(
659 workspace_controller_->layout_manager());
660 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(false);
[email protected]86459e2c2013-04-10 13:39:24661 }
662}
663
[email protected]602022b2014-03-31 17:07:31664bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
bshec3875422014-09-29 13:21:30665 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]602022b2014-03-31 17:07:31666 return parent ? parent->Contains(window) : false;
667}
668
[email protected]a4cd6d32012-09-12 03:42:13669////////////////////////////////////////////////////////////////////////////////
670// RootWindowController, private:
671
[email protected]f5c9dbc2014-04-11 08:13:45672RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
673 : ash_host_(ash_host),
[email protected]a273d33a2013-10-17 12:41:21674 root_window_layout_(NULL),
675 docked_layout_manager_(NULL),
676 panel_layout_manager_(NULL),
677 touch_hud_debug_(NULL),
678 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45679 aura::Window* root_window = GetRootWindow();
680 GetRootWindowSettings(root_window)->controller = this;
681 screen_dimmer_.reset(new ScreenDimmer(root_window));
[email protected]a273d33a2013-10-17 12:41:21682
683 stacking_controller_.reset(new StackingController);
[email protected]f5c9dbc2014-04-11 08:13:45684 aura::client::SetWindowTreeClient(root_window, stacking_controller_.get());
685 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21686}
687
[email protected]608de6c2013-10-29 00:14:28688void RootWindowController::Init(RootWindowType root_window_type,
689 bool first_run_after_boot) {
[email protected]f5c9dbc2014-04-11 08:13:45690 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50691 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45692 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21693
[email protected]f5c9dbc2014-04-11 08:13:45694 ash_host_->AsWindowTreeHost()->SetCursor(ui::kCursorPointer);
695 CreateContainersInRootWindow(root_window);
[email protected]608de6c2013-10-29 00:14:28696
[email protected]a273d33a2013-10-17 12:41:21697 CreateSystemBackground(first_run_after_boot);
698
699 InitLayoutManagers();
700 InitTouchHuds();
701
702 if (Shell::GetPrimaryRootWindowController()->
703 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
704 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
705 }
706
[email protected]a273d33a2013-10-17 12:41:21707 shell->AddShellObserver(this);
708
[email protected]608de6c2013-10-29 00:14:28709 if (root_window_type == PRIMARY) {
[email protected]a3565792013-10-18 12:52:37710 root_window_layout()->OnWindowResized();
bshe9858b4a2014-09-16 20:46:38711 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21712 } else {
713 root_window_layout()->OnWindowResized();
[email protected]f5c9dbc2014-04-11 08:13:45714 ash_host_->AsWindowTreeHost()->Show();
[email protected]a273d33a2013-10-17 12:41:21715
[email protected]864b58552013-12-19 04:19:38716 // Create a shelf if a user is already logged in.
[email protected]a273d33a2013-10-17 12:41:21717 if (shell->session_state_delegate()->NumberOfLoggedInUsers())
[email protected]864b58552013-12-19 04:19:38718 shelf()->CreateShelf();
[email protected]0e3e7cb2014-04-12 05:18:25719
720 // Notify shell observers about new root window.
721 shell->OnRootWindowAdded(root_window);
[email protected]a273d33a2013-10-17 12:41:21722 }
[email protected]a825e8312014-05-05 22:05:01723
724#if defined(OS_CHROMEOS)
[email protected]2e0b2352014-07-28 13:28:28725 if (!CommandLine::ForCurrentProcess()->HasSwitch(
726 switches::kAshDisableTouchExplorationMode)) {
[email protected]7d487592014-07-24 03:54:50727 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
[email protected]a825e8312014-05-05 22:05:01728 }
729#endif
[email protected]a273d33a2013-10-17 12:41:21730}
731
[email protected]756bda12013-07-03 08:17:06732void RootWindowController::InitLayoutManagers() {
[email protected]f5c9dbc2014-04-11 08:13:45733 aura::Window* root_window = GetRootWindow();
734 root_window_layout_ = new RootWindowLayoutManager(root_window);
735 root_window->SetLayoutManager(root_window_layout_);
[email protected]756bda12013-07-03 08:17:06736
737 aura::Window* default_container =
738 GetContainer(kShellWindowId_DefaultContainer);
739 // Workspace manager has its own layout managers.
740 workspace_controller_.reset(
741 new WorkspaceController(default_container));
742
743 aura::Window* always_on_top_container =
744 GetContainer(kShellWindowId_AlwaysOnTopContainer);
745 always_on_top_container->SetLayoutManager(
[email protected]093b8d642014-04-03 20:59:28746 new WorkspaceLayoutManager(always_on_top_container));
747 always_on_top_controller_.reset(new AlwaysOnTopController);
[email protected]756bda12013-07-03 08:17:06748 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
749
750 DCHECK(!shelf_.get());
[email protected]093b8d642014-04-03 20:59:28751 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
[email protected]756bda12013-07-03 08:17:06752 // TODO(harrym): Remove when status area is view.
[email protected]093b8d642014-04-03 20:59:28753 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
[email protected]756bda12013-07-03 08:17:06754 shelf_.reset(new ShelfWidget(
755 shelf_container, status_container, workspace_controller()));
756
[email protected]cf6fea22013-08-07 14:24:01757 if (!Shell::GetInstance()->session_state_delegate()->
758 IsActiveUserSessionStarted()) {
759 // This window exists only to be a event target on login screen.
760 // It does not have to handle events, nor be visible.
761 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
[email protected]52b02a72014-01-08 21:41:50762 mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]cf6fea22013-08-07 14:24:01763
764 aura::Window* lock_background_container =
[email protected]093b8d642014-04-03 20:59:28765 GetContainer(kShellWindowId_LockScreenBackgroundContainer);
[email protected]cf6fea22013-08-07 14:24:01766 lock_background_container->AddChild(mouse_event_target_.get());
767 mouse_event_target_->Show();
768 }
769
[email protected]756bda12013-07-03 08:17:06770 // Create Docked windows layout manager
[email protected]093b8d642014-04-03 20:59:28771 aura::Window* docked_container = GetContainer(kShellWindowId_DockedContainer);
[email protected]756bda12013-07-03 08:17:06772 docked_layout_manager_ =
[email protected]093b8d642014-04-03 20:59:28773 new DockedWindowLayoutManager(docked_container, workspace_controller());
[email protected]756bda12013-07-03 08:17:06774 docked_container->SetLayoutManager(docked_layout_manager_);
775
[email protected]1ca79d42014-07-18 16:26:10776 // Installs SnapLayoutManager to containers who set the
777 // |kSnapsChildrenToPhysicalPixelBoundary| property.
778 wm::InstallSnapLayoutManagerToContainers(root_window);
779
[email protected]756bda12013-07-03 08:17:06780 // Create Panel layout manager
[email protected]093b8d642014-04-03 20:59:28781 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
782 panel_layout_manager_ = new PanelLayoutManager(panel_container);
[email protected]756bda12013-07-03 08:17:06783 panel_container->SetLayoutManager(panel_layout_manager_);
[email protected]3537d472014-01-15 05:45:31784 panel_container_handler_.reset(new PanelWindowEventHandler);
785 panel_container->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39786
787 // Install an AttachedPanelWindowTargeter on the panel container to make it
788 // easier to correctly target shelf buttons with touch.
789 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
790 -kResizeOutsideBoundsSize,
791 -kResizeOutsideBoundsSize,
792 -kResizeOutsideBoundsSize);
793 gfx::Insets touch_extend = mouse_extend.Scale(
794 kResizeOutsideBoundsScaleForTouch);
795 panel_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
796 new AttachedPanelWindowTargeter(panel_container,
797 mouse_extend,
798 touch_extend,
799 panel_layout_manager_)));
[email protected]756bda12013-07-03 08:17:06800}
801
802void RootWindowController::InitTouchHuds() {
803 CommandLine* command_line = CommandLine::ForCurrentProcess();
804 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45805 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06806 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
807 EnableTouchHudProjection();
808}
809
810void RootWindowController::CreateSystemBackground(
811 bool is_first_run_after_boot) {
812 SkColor color = SK_ColorBLACK;
813#if defined(OS_CHROMEOS)
814 if (is_first_run_after_boot)
815 color = kChromeOsBootColor;
816#endif
817 system_background_.reset(
[email protected]f5c9dbc2014-04-11 08:13:45818 new SystemBackgroundController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06819
820#if defined(OS_CHROMEOS)
821 // Make a copy of the system's boot splash screen so we can composite it
822 // onscreen until the desktop background is ready.
823 if (is_first_run_after_boot &&
824 (CommandLine::ForCurrentProcess()->HasSwitch(
825 switches::kAshCopyHostBackgroundAtBoot) ||
826 CommandLine::ForCurrentProcess()->HasSwitch(
827 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45828 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06829#endif
830}
831
[email protected]a4cd6d32012-09-12 03:42:13832void RootWindowController::CreateContainersInRootWindow(
[email protected]41baaed2013-11-09 04:18:26833 aura::Window* root_window) {
[email protected]a4cd6d32012-09-12 03:42:13834 // These containers are just used by PowerButtonController to animate groups
835 // of containers simultaneously without messing up the current transformations
836 // on those containers. These are direct children of the root window; all of
837 // the other containers are their children.
[email protected]e6e41d2f2012-10-29 19:22:19838
839 // The desktop background container is not part of the lock animation, so it
840 // is not included in those animate groups.
[email protected]a4cd6d32012-09-12 03:42:13841 // When screen is locked desktop background is moved to lock screen background
842 // container (moved back on unlock). We want to make sure that there's an
843 // opaque layer occluding the non-lock-screen layers.
[email protected]e6e41d2f2012-10-29 19:22:19844 aura::Window* desktop_background_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27845 kShellWindowId_DesktopBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13846 "DesktopBackgroundContainer",
847 root_window);
[email protected]e319c7e2014-03-14 19:56:14848 ::wm::SetChildWindowVisibilityChangesAnimated(desktop_background_container);
[email protected]a4cd6d32012-09-12 03:42:13849
850 aura::Window* non_lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27851 kShellWindowId_NonLockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13852 "NonLockScreenContainersContainer",
853 root_window);
854
855 aura::Window* lock_background_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27856 kShellWindowId_LockScreenBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13857 "LockScreenBackgroundContainer",
858 root_window);
[email protected]e319c7e2014-03-14 19:56:14859 ::wm::SetChildWindowVisibilityChangesAnimated(lock_background_containers);
[email protected]a4cd6d32012-09-12 03:42:13860
861 aura::Window* lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27862 kShellWindowId_LockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13863 "LockScreenContainersContainer",
864 root_window);
865 aura::Window* lock_screen_related_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27866 kShellWindowId_LockScreenRelatedContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13867 "LockScreenRelatedContainersContainer",
868 root_window);
869
[email protected]c0ce80e2012-10-05 23:28:27870 CreateContainer(kShellWindowId_UnparentedControlContainer,
[email protected]a4cd6d32012-09-12 03:42:13871 "UnparentedControlContainer",
872 non_lock_screen_containers);
873
874 aura::Window* default_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27875 kShellWindowId_DefaultContainer,
[email protected]a4cd6d32012-09-12 03:42:13876 "DefaultContainer",
877 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14878 ::wm::SetChildWindowVisibilityChangesAnimated(default_container);
[email protected]1ca79d42014-07-18 16:26:10879 wm::SetSnapsChildrenToPhysicalPixelBoundary(default_container);
[email protected]a4cd6d32012-09-12 03:42:13880 SetUsesScreenCoordinates(default_container);
[email protected]c5be8d672014-01-07 13:33:41881 SetUsesEasyResizeTargeter(default_container);
[email protected]a4cd6d32012-09-12 03:42:13882
883 aura::Window* always_on_top_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27884 kShellWindowId_AlwaysOnTopContainer,
[email protected]a4cd6d32012-09-12 03:42:13885 "AlwaysOnTopContainer",
886 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14887 ::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container);
[email protected]1ca79d42014-07-18 16:26:10888 wm::SetSnapsChildrenToPhysicalPixelBoundary(always_on_top_container);
[email protected]a4cd6d32012-09-12 03:42:13889 SetUsesScreenCoordinates(always_on_top_container);
890
[email protected]beb4e5c2013-06-18 15:37:07891 aura::Window* docked_container = CreateContainer(
892 kShellWindowId_DockedContainer,
893 "DockedContainer",
894 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14895 ::wm::SetChildWindowVisibilityChangesAnimated(docked_container);
[email protected]1ca79d42014-07-18 16:26:10896 wm::SetSnapsChildrenToPhysicalPixelBoundary(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07897 SetUsesScreenCoordinates(docked_container);
[email protected]1ff0c492014-01-21 20:20:44898 SetUsesEasyResizeTargeter(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07899
[email protected]3f13cf12013-07-12 05:13:59900 aura::Window* shelf_container =
[email protected]478c6c32013-03-09 02:50:58901 CreateContainer(kShellWindowId_ShelfContainer,
[email protected]3f13cf12013-07-12 05:13:59902 "ShelfContainer",
[email protected]a4cd6d32012-09-12 03:42:13903 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10904 wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_container);
[email protected]3f13cf12013-07-12 05:13:59905 SetUsesScreenCoordinates(shelf_container);
906 DescendantShouldStayInSameRootWindow(shelf_container);
[email protected]a4cd6d32012-09-12 03:42:13907
[email protected]f2026eb2013-10-22 14:28:56908 aura::Window* panel_container = CreateContainer(
909 kShellWindowId_PanelContainer,
910 "PanelContainer",
911 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10912 wm::SetSnapsChildrenToPhysicalPixelBoundary(panel_container);
[email protected]f2026eb2013-10-22 14:28:56913 SetUsesScreenCoordinates(panel_container);
914
915 aura::Window* shelf_bubble_container =
916 CreateContainer(kShellWindowId_ShelfBubbleContainer,
917 "ShelfBubbleContainer",
918 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10919 wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_bubble_container);
[email protected]f2026eb2013-10-22 14:28:56920 SetUsesScreenCoordinates(shelf_bubble_container);
921 DescendantShouldStayInSameRootWindow(shelf_bubble_container);
922
[email protected]dc851a4e52012-10-03 00:05:55923 aura::Window* app_list_container =
[email protected]c0ce80e2012-10-05 23:28:27924 CreateContainer(kShellWindowId_AppListContainer,
[email protected]dc851a4e52012-10-03 00:05:55925 "AppListContainer",
926 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10927 wm::SetSnapsChildrenToPhysicalPixelBoundary(app_list_container);
[email protected]dc851a4e52012-10-03 00:05:55928 SetUsesScreenCoordinates(app_list_container);
[email protected]a4cd6d32012-09-12 03:42:13929
930 aura::Window* modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27931 kShellWindowId_SystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13932 "SystemModalContainer",
933 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10934 wm::SetSnapsChildrenToPhysicalPixelBoundary(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13935 modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27936 new SystemModalContainerLayoutManager(modal_container));
[email protected]e319c7e2014-03-14 19:56:14937 ::wm::SetChildWindowVisibilityChangesAnimated(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13938 SetUsesScreenCoordinates(modal_container);
[email protected]c5be8d672014-01-07 13:33:41939 SetUsesEasyResizeTargeter(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13940
[email protected]a4cd6d32012-09-12 03:42:13941 // TODO(beng): Figure out if we can make this use
942 // SystemModalContainerEventFilter instead of stops_event_propagation.
943 aura::Window* lock_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27944 kShellWindowId_LockScreenContainer,
[email protected]a4cd6d32012-09-12 03:42:13945 "LockScreenContainer",
946 lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10947 wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_container);
[email protected]68d51332014-06-06 13:51:13948 if (CommandLine::ForCurrentProcess()->HasSwitch(
949 switches::kAshDisableLockLayoutManager)) {
950 lock_container->SetLayoutManager(
951 new WorkspaceLayoutManager(lock_container));
952 } else {
953 lock_container->SetLayoutManager(new LockLayoutManager(lock_container));
954 }
[email protected]a4cd6d32012-09-12 03:42:13955 SetUsesScreenCoordinates(lock_container);
956 // TODO(beng): stopsevents
957
958 aura::Window* lock_modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27959 kShellWindowId_LockSystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13960 "LockSystemModalContainer",
961 lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10962 wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13963 lock_modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27964 new SystemModalContainerLayoutManager(lock_modal_container));
[email protected]e319c7e2014-03-14 19:56:14965 ::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13966 SetUsesScreenCoordinates(lock_modal_container);
[email protected]c5be8d672014-01-07 13:33:41967 SetUsesEasyResizeTargeter(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13968
969 aura::Window* status_container =
[email protected]c0ce80e2012-10-05 23:28:27970 CreateContainer(kShellWindowId_StatusContainer,
[email protected]a4cd6d32012-09-12 03:42:13971 "StatusContainer",
972 lock_screen_related_containers);
[email protected]1ca79d42014-07-18 16:26:10973 wm::SetSnapsChildrenToPhysicalPixelBoundary(status_container);
[email protected]a4cd6d32012-09-12 03:42:13974 SetUsesScreenCoordinates(status_container);
[email protected]e887c6c2013-07-08 19:35:53975 DescendantShouldStayInSameRootWindow(status_container);
[email protected]a4cd6d32012-09-12 03:42:13976
977 aura::Window* settings_bubble_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27978 kShellWindowId_SettingBubbleContainer,
[email protected]a4cd6d32012-09-12 03:42:13979 "SettingBubbleContainer",
980 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:14981 ::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
[email protected]1ca79d42014-07-18 16:26:10982 wm::SetSnapsChildrenToPhysicalPixelBoundary(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:13983 SetUsesScreenCoordinates(settings_bubble_container);
[email protected]e887c6c2013-07-08 19:35:53984 DescendantShouldStayInSameRootWindow(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:13985
kevers23f3987d2014-09-17 13:50:12986 aura::Window* virtual_keyboard_parent_container =
bshec3875422014-09-29 13:21:30987 CreateContainer(kShellWindowId_ImeWindowParentContainer,
kevers23f3987d2014-09-17 13:50:12988 "VirtualKeyboardParentContainer",
989 lock_screen_related_containers);
990 wm::SetSnapsChildrenToPhysicalPixelBoundary(
991 virtual_keyboard_parent_container);
kevers0e450492014-09-30 16:02:31992 virtual_keyboard_parent_container->SetLayoutManager(
993 new VirtualKeyboardContainerLayoutManager(
994 virtual_keyboard_parent_container));
kevers23f3987d2014-09-17 13:50:12995 SetUsesScreenCoordinates(virtual_keyboard_parent_container);
996
[email protected]a4cd6d32012-09-12 03:42:13997 aura::Window* menu_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27998 kShellWindowId_MenuContainer,
[email protected]a4cd6d32012-09-12 03:42:13999 "MenuContainer",
1000 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141001 ::wm::SetChildWindowVisibilityChangesAnimated(menu_container);
[email protected]1ca79d42014-07-18 16:26:101002 wm::SetSnapsChildrenToPhysicalPixelBoundary(menu_container);
[email protected]a4cd6d32012-09-12 03:42:131003 SetUsesScreenCoordinates(menu_container);
1004
1005 aura::Window* drag_drop_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271006 kShellWindowId_DragImageAndTooltipContainer,
[email protected]a4cd6d32012-09-12 03:42:131007 "DragImageAndTooltipContainer",
1008 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141009 ::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
[email protected]1ca79d42014-07-18 16:26:101010 wm::SetSnapsChildrenToPhysicalPixelBoundary(drag_drop_container);
[email protected]a4cd6d32012-09-12 03:42:131011 SetUsesScreenCoordinates(drag_drop_container);
1012
1013 aura::Window* overlay_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271014 kShellWindowId_OverlayContainer,
[email protected]a4cd6d32012-09-12 03:42:131015 "OverlayContainer",
1016 lock_screen_related_containers);
[email protected]1ca79d42014-07-18 16:26:101017 wm::SetSnapsChildrenToPhysicalPixelBoundary(overlay_container);
[email protected]a4cd6d32012-09-12 03:42:131018 SetUsesScreenCoordinates(overlay_container);
[email protected]a07615f2012-10-24 08:23:081019
[email protected]b2da9b602014-03-05 18:39:521020#if defined(OS_CHROMEOS)
1021 aura::Window* mouse_cursor_container = CreateContainer(
1022 kShellWindowId_MouseCursorContainer,
1023 "MouseCursorContainer",
1024 root_window);
1025 SetUsesScreenCoordinates(mouse_cursor_container);
1026#endif
1027
[email protected]a07615f2012-10-24 08:23:081028 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
[email protected]b2da9b602014-03-05 18:39:521029 "PowerButtonAnimationContainer", root_window);
[email protected]a4cd6d32012-09-12 03:42:131030}
1031
[email protected]d141b922013-07-09 08:13:171032void RootWindowController::EnableTouchHudProjection() {
1033 if (touch_hud_projection_)
1034 return;
[email protected]f5c9dbc2014-04-11 08:13:451035 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:171036}
1037
1038void RootWindowController::DisableTouchHudProjection() {
1039 if (!touch_hud_projection_)
1040 return;
1041 touch_hud_projection_->Remove();
1042}
1043
1044void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
1045 shelf_->shelf_layout_manager()->UpdateVisibilityState();
1046}
1047
1048void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
1049 if (enabled)
1050 EnableTouchHudProjection();
1051 else
1052 DisableTouchHudProjection();
1053}
1054
[email protected]6b2d4a0b2013-09-06 06:29:541055RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:451056 const aura::Window* root_window) {
[email protected]6b2d4a0b2013-09-06 06:29:541057 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
1058}
1059
[email protected]d90b8392012-06-13 09:34:561060} // namespace ash