blob: eb97d251e9c807a27bc719f7913657b2691a61c8 [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"
[email protected]8d625fb2012-07-18 16:40:0647#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3448#include "ash/wm/window_state.h"
[email protected]700849f2013-04-30 17:49:2049#include "ash/wm/window_util.h"
[email protected]1af71f72014-01-29 20:00:5550#include "ash/wm/workspace/workspace_layout_manager.h"
[email protected]d90b8392012-06-13 09:34:5651#include "ash/wm/workspace_controller.h"
[email protected]e6e41d2f2012-10-29 19:22:1952#include "base/command_line.h"
[email protected]1e84c632013-06-27 23:12:2153#include "base/time/time.h"
[email protected]f1853122012-06-27 16:21:2654#include "ui/aura/client/aura_constants.h"
[email protected]2374d1812014-03-04 03:42:2755#include "ui/aura/client/screen_position_client.h"
[email protected]f1853122012-06-27 16:21:2656#include "ui/aura/window.h"
[email protected]cf6fea22013-08-07 14:24:0157#include "ui/aura/window_delegate.h"
[email protected]fcc51c952014-02-21 21:31:2658#include "ui/aura/window_event_dispatcher.h"
[email protected]f1853122012-06-27 16:21:2659#include "ui/aura/window_observer.h"
[email protected]8b3e3d82013-08-20 14:36:3060#include "ui/aura/window_tracker.h"
[email protected]cf6fea22013-08-07 14:24:0161#include "ui/base/hit_test.h"
[email protected]431552c2012-10-23 00:38:3362#include "ui/base/models/menu_model.h"
[email protected]f8e6aad2013-08-30 21:49:1163#include "ui/gfx/display.h"
[email protected]8d625fb2012-07-18 16:40:0664#include "ui/gfx/screen.h"
[email protected]86459e2c2013-04-10 13:39:2465#include "ui/keyboard/keyboard_controller.h"
66#include "ui/keyboard/keyboard_util.h"
[email protected]431552c2012-10-23 00:38:3367#include "ui/views/controls/menu/menu_runner.h"
68#include "ui/views/view_model.h"
69#include "ui/views/view_model_utils.h"
[email protected]ee3ed10772014-03-11 22:02:0170#include "ui/wm/core/capture_controller.h"
[email protected]e319c7e2014-03-14 19:56:1471#include "ui/wm/core/easy_resize_window_targeter.h"
[email protected]ee3ed10772014-03-11 22:02:0172#include "ui/wm/core/visibility_controller.h"
73#include "ui/wm/core/window_util.h"
[email protected]af4552b22014-03-21 19:45:0174#include "ui/wm/public/drag_drop_client.h"
75#include "ui/wm/public/tooltip_client.h"
[email protected]5b251f12013-12-19 01:50:0576#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5677
[email protected]252eb232013-08-14 22:09:2778#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:5079#include "ash/ash_touch_exploration_manager_chromeos.h"
[email protected]252eb232013-08-14 22:09:2780#include "ash/wm/boot_splash_screen_chromeos.h"
[email protected]a825e8312014-05-05 22:05:0181#include "ui/chromeos/touch_exploration_controller.h"
[email protected]252eb232013-08-14 22:09:2782#endif
83
[email protected]d90b8392012-06-13 09:34:5684namespace ash {
85namespace {
86
[email protected]252eb232013-08-14 22:09:2787#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:4988// Duration for the animation that hides the boot splash screen, in
89// milliseconds. This should be short enough in relation to
90// wm/window_animation.cc's brightness/grayscale fade animation that the login
91// background image animation isn't hidden by the splash screen animation.
92const int kBootSplashScreenHideDurationMs = 500;
[email protected]252eb232013-08-14 22:09:2793#endif
[email protected]bca9a7e2012-11-10 06:25:4994
[email protected]d90b8392012-06-13 09:34:5695// Creates a new window for use as a container.
96aura::Window* CreateContainer(int window_id,
97 const char* name,
98 aura::Window* parent) {
99 aura::Window* container = new aura::Window(NULL);
100 container->set_id(window_id);
101 container->SetName(name);
[email protected]52b02a72014-01-08 21:41:50102 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]d90b8392012-06-13 09:34:56103 parent->AddChild(container);
[email protected]093b8d642014-04-03 20:59:28104 if (window_id != kShellWindowId_UnparentedControlContainer)
[email protected]d90b8392012-06-13 09:34:56105 container->Show();
106 return container;
107}
108
[email protected]2816c2462013-12-17 02:22:25109float ToRelativeValue(int value, int src, int dst) {
110 return static_cast<float>(value) / static_cast<float>(src) * dst;
111}
112
113void MoveOriginRelativeToSize(const gfx::Size& src_size,
114 const gfx::Size& dst_size,
115 gfx::Rect* bounds_in_out) {
116 gfx::Point origin = bounds_in_out->origin();
117 bounds_in_out->set_origin(gfx::Point(
118 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
119 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
120}
121
[email protected]95058572012-08-20 14:57:29122// Reparents |window| to |new_parent|.
123void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
[email protected]2816c2462013-12-17 02:22:25124 const gfx::Size src_size = window->parent()->bounds().size();
125 const gfx::Size dst_size = new_parent->bounds().size();
[email protected]95058572012-08-20 14:57:29126 // Update the restore bounds to make it relative to the display.
[email protected]a41b4e12013-09-20 04:36:34127 wm::WindowState* state = wm::GetWindowState(window);
128 gfx::Rect restore_bounds;
129 bool has_restore_bounds = state->HasRestoreBounds();
[email protected]2816c2462013-12-17 02:22:25130
[email protected]9cfd3d12014-02-25 15:33:45131 bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) &&
[email protected]093b8d642014-04-03 20:59:28132 new_parent->id() != kShellWindowId_DockedContainer;
[email protected]2816c2462013-12-17 02:22:25133 gfx::Rect local_bounds;
134 if (update_bounds) {
135 local_bounds = state->window()->bounds();
136 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
137 }
138
139 if (has_restore_bounds) {
[email protected]a41b4e12013-09-20 04:36:34140 restore_bounds = state->GetRestoreBoundsInParent();
[email protected]2816c2462013-12-17 02:22:25141 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
142 }
143
[email protected]95058572012-08-20 14:57:29144 new_parent->AddChild(window);
[email protected]2816c2462013-12-17 02:22:25145
[email protected]8663b7a62014-01-18 01:24:21146 // Docked windows have bounds handled by the layout manager in AddChild().
[email protected]2816c2462013-12-17 02:22:25147 if (update_bounds)
148 window->SetBounds(local_bounds);
149
[email protected]a41b4e12013-09-20 04:36:34150 if (has_restore_bounds)
151 state->SetRestoreBoundsInParent(restore_bounds);
[email protected]95058572012-08-20 14:57:29152}
153
154// Reparents the appropriate set of windows from |src| to |dst|.
[email protected]bf9cdb362013-10-25 19:22:45155void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
[email protected]95058572012-08-20 14:57:29156 // Set of windows to move.
[email protected]f1853122012-06-27 16:21:26157 const int kContainerIdsToMove[] = {
[email protected]093b8d642014-04-03 20:59:28158 kShellWindowId_DefaultContainer,
159 kShellWindowId_DockedContainer,
160 kShellWindowId_PanelContainer,
161 kShellWindowId_AlwaysOnTopContainer,
162 kShellWindowId_SystemModalContainer,
163 kShellWindowId_LockSystemModalContainer,
[email protected]093b8d642014-04-03 20:59:28164 kShellWindowId_UnparentedControlContainer, };
[email protected]f1853122012-06-27 16:21:26165 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
166 int id = kContainerIdsToMove[i];
167 aura::Window* src_container = Shell::GetContainer(src, id);
168 aura::Window* dst_container = Shell::GetContainer(dst, id);
[email protected]5b6021902013-02-26 05:33:29169 while (!src_container->children().empty()) {
170 // Restart iteration from the source container windows each time as they
171 // may change as a result of moving other windows.
172 aura::Window::Windows::const_iterator iter =
173 src_container->children().begin();
174 while (iter != src_container->children().end() &&
[email protected]093b8d642014-04-03 20:59:28175 SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
[email protected]5b6021902013-02-26 05:33:29176 ++iter;
177 }
178 // If the entire window list is modal background windows then stop.
179 if (iter == src_container->children().end())
180 break;
181 ReparentWindow(*iter, dst_container);
[email protected]f1853122012-06-27 16:21:26182 }
183 }
184}
185
[email protected]8d625fb2012-07-18 16:40:06186// Mark the container window so that a widget added to this container will
187// use the virtual screeen coordinates instead of parent.
188void SetUsesScreenCoordinates(aura::Window* container) {
[email protected]093b8d642014-04-03 20:59:28189 container->SetProperty(kUsesScreenCoordinatesKey, true);
[email protected]8d625fb2012-07-18 16:40:06190}
191
[email protected]e887c6c2013-07-08 19:35:53192// Mark the container window so that a widget added to this container will
193// say in the same root window regardless of the bounds specified.
194void DescendantShouldStayInSameRootWindow(aura::Window* container) {
[email protected]093b8d642014-04-03 20:59:28195 container->SetProperty(kStayInSameRootWindowKey, true);
[email protected]e887c6c2013-07-08 19:35:53196}
197
[email protected]c5be8d672014-01-07 13:33:41198void SetUsesEasyResizeTargeter(aura::Window* container) {
199 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
200 -kResizeOutsideBoundsSize,
201 -kResizeOutsideBoundsSize,
202 -kResizeOutsideBoundsSize);
203 gfx::Insets touch_extend = mouse_extend.Scale(
204 kResizeOutsideBoundsScaleForTouch);
[email protected]95f642cb2014-01-31 01:35:41205 container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
[email protected]c5be8d672014-01-07 13:33:41206 new ::wm::EasyResizeWindowTargeter(container, mouse_extend,
207 touch_extend)));
208}
209
[email protected]cf6fea22013-08-07 14:24:01210// A window delegate which does nothing. Used to create a window that
211// is a event target, but do nothing.
212class EmptyWindowDelegate : public aura::WindowDelegate {
213 public:
214 EmptyWindowDelegate() {}
215 virtual ~EmptyWindowDelegate() {}
216
217 // aura::WindowDelegate overrides:
218 virtual gfx::Size GetMinimumSize() const OVERRIDE {
219 return gfx::Size();
220 }
221 virtual gfx::Size GetMaximumSize() const OVERRIDE {
222 return gfx::Size();
223 }
224 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
225 const gfx::Rect& new_bounds) OVERRIDE {
226 }
[email protected]62c9f102014-03-27 06:07:04227 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
228 return gfx::kNullCursor;
229 }
[email protected]cf6fea22013-08-07 14:24:01230 virtual int GetNonClientComponent(
231 const gfx::Point& point) const OVERRIDE {
232 return HTNOWHERE;
233 }
234 virtual bool ShouldDescendIntoChildForEventHandling(
235 aura::Window* child,
236 const gfx::Point& location) OVERRIDE {
237 return false;
238 }
239 virtual bool CanFocus() OVERRIDE {
240 return false;
241 }
242 virtual void OnCaptureLost() OVERRIDE {
243 }
244 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
245 }
246 virtual void OnDeviceScaleFactorChanged(
247 float device_scale_factor) OVERRIDE {
248 }
[email protected]48f36d92014-02-28 00:11:37249 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {}
250 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
[email protected]febe1fd62013-08-07 16:07:24251 delete this;
252 }
[email protected]cf6fea22013-08-07 14:24:01253 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
254 }
255 virtual bool HasHitTestMask() const OVERRIDE {
256 return false;
257 }
258 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
[email protected]cf6fea22013-08-07 14:24:01259
260 private:
261 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
262};
263
[email protected]d90b8392012-06-13 09:34:56264} // namespace
265
[email protected]f5c9dbc2014-04-11 08:13:45266void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38267 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28268 controller->Init(RootWindowController::PRIMARY,
[email protected]a273d33a2013-10-17 12:41:21269 Shell::GetInstance()->delegate()->IsFirstRunAfterBoot());
[email protected]d90b8392012-06-13 09:34:56270}
271
[email protected]f5c9dbc2014-04-11 08:13:45272void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38273 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28274 controller->Init(RootWindowController::SECONDARY, false /* first run */);
275}
276
277void RootWindowController::CreateForVirtualKeyboardDisplay(
[email protected]f5c9dbc2014-04-11 08:13:45278 AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38279 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28280 controller->Init(RootWindowController::VIRTUAL_KEYBOARD,
281 false /* first run */);
[email protected]6675e1c2012-09-11 09:15:45282}
283
[email protected]88d71122012-10-18 07:11:01284// static
[email protected]76bc4632014-06-16 19:07:46285RootWindowController* RootWindowController::ForShelf(
286 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07287 CHECK(Shell::HasInstance());
[email protected]8c0ec432013-05-10 04:33:39288 return GetRootWindowController(window->GetRootWindow());
[email protected]88d71122012-10-18 07:11:01289}
290
[email protected]a0afeb12012-12-10 22:57:09291// static
[email protected]ccff3d72013-02-06 04:26:28292RootWindowController* RootWindowController::ForWindow(
293 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07294 CHECK(Shell::HasInstance());
[email protected]a0afeb12012-12-10 22:57:09295 return GetRootWindowController(window->GetRootWindow());
296}
297
298// static
[email protected]d17642d2013-09-12 23:44:38299RootWindowController* RootWindowController::ForTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07300 CHECK(Shell::HasInstance());
[email protected]093b8d642014-04-03 20:59:28301 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09302}
303
[email protected]a5c78802013-12-12 22:07:01304// static
305aura::Window* RootWindowController::GetContainerForWindow(
306 aura::Window* window) {
307 aura::Window* container = window->parent();
[email protected]5b251f12013-12-19 01:50:05308 while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN)
[email protected]a5c78802013-12-12 22:07:01309 container = container->parent();
310 return container;
311}
312
[email protected]a273d33a2013-10-17 12:41:21313RootWindowController::~RootWindowController() {
314 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45315 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21316 // The CaptureClient needs to be around for as long as the RootWindow is
317 // valid.
318 capture_client_.reset();
319}
320
[email protected]f5c9dbc2014-04-11 08:13:45321aura::WindowTreeHost* RootWindowController::GetHost() {
322 return ash_host_->AsWindowTreeHost();
323}
324
325const aura::WindowTreeHost* RootWindowController::GetHost() const {
326 return ash_host_->AsWindowTreeHost();
327}
328
329aura::Window* RootWindowController::GetRootWindow() {
330 return GetHost()->window();
331}
332
333const aura::Window* RootWindowController::GetRootWindow() const {
334 return GetHost()->window();
335}
336
[email protected]0bf61732013-07-02 04:35:10337void RootWindowController::SetWallpaperController(
338 DesktopBackgroundWidgetController* controller) {
339 wallpaper_controller_.reset(controller);
340}
341
342void RootWindowController::SetAnimatingWallpaperController(
343 AnimatingDesktopController* controller) {
344 if (animating_wallpaper_controller_.get())
345 animating_wallpaper_controller_->StopAnimating();
346 animating_wallpaper_controller_.reset(controller);
347}
348
[email protected]6675e1c2012-09-11 09:15:45349void RootWindowController::Shutdown() {
[email protected]a825e8312014-05-05 22:05:01350 Shell* shell = Shell::GetInstance();
351 shell->RemoveShellObserver(this);
352
353#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:50354 if (touch_exploration_manager_) {
355 touch_exploration_manager_.reset();
[email protected]a825e8312014-05-05 22:05:01356 }
357#endif
[email protected]d141b922013-07-09 08:13:17358
[email protected]0bf61732013-07-02 04:35:10359 if (animating_wallpaper_controller_.get())
360 animating_wallpaper_controller_->StopAnimating();
361 wallpaper_controller_.reset();
362 animating_wallpaper_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45363 aura::Window* root_window = GetRootWindow();
[email protected]d17642d2013-09-12 23:44:38364 // Change the target root window before closing child windows. If any child
[email protected]c98a4922013-09-05 20:01:42365 // being removed triggers a relayout of the shelf it will try to build a
[email protected]d17642d2013-09-12 23:44:38366 // window list adding windows from the target root window's containers which
[email protected]c98a4922013-09-05 20:01:42367 // may have already gone away.
[email protected]f5c9dbc2014-04-11 08:13:45368 if (Shell::GetTargetRootWindow() == root_window) {
[email protected]a825e8312014-05-05 22:05:01369 shell->set_target_root_window(
[email protected]f5c9dbc2014-04-11 08:13:45370 Shell::GetPrimaryRootWindow() == root_window
371 ? NULL
372 : Shell::GetPrimaryRootWindow());
[email protected]f634dd32012-07-23 22:49:07373 }
[email protected]c98a4922013-09-05 20:01:42374
375 CloseChildWindows();
[email protected]f5c9dbc2014-04-11 08:13:45376 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]d90b8392012-06-13 09:34:56377 screen_dimmer_.reset();
378 workspace_controller_.reset();
[email protected]6675e1c2012-09-11 09:15:45379 // Forget with the display ID so that display lookup
380 // ends up with invalid display.
[email protected]f5c9dbc2014-04-11 08:13:45381 GetRootWindowSettings(root_window)->display_id =
[email protected]f8e6aad2013-08-30 21:49:11382 gfx::Display::kInvalidDisplayID;
[email protected]8f5209c2014-05-22 20:36:11383 ash_host_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28384
[email protected]956a6a42012-10-29 23:58:10385 system_background_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45386 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56387}
388
[email protected]c0ce80e2012-10-05 23:28:27389SystemModalContainerLayoutManager*
[email protected]8674b312012-10-12 19:02:44390RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
[email protected]a5c78802013-12-12 22:07:01391 aura::Window* modal_container = NULL;
[email protected]8674b312012-10-12 19:02:44392 if (window) {
[email protected]a5c78802013-12-12 22:07:01393 aura::Window* window_container = GetContainerForWindow(window);
394 if (window_container &&
395 window_container->id() >= kShellWindowId_LockScreenContainer) {
396 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35397 } else {
[email protected]a5c78802013-12-12 22:07:01398 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35399 }
[email protected]8674b312012-10-12 19:02:44400 } else {
[email protected]a44afbbd2013-07-24 21:49:35401 int modal_window_id = Shell::GetInstance()->session_state_delegate()
402 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
403 kShellWindowId_SystemModalContainer;
[email protected]a5c78802013-12-12 22:07:01404 modal_container = GetContainer(modal_window_id);
[email protected]8674b312012-10-12 19:02:44405 }
[email protected]a5c78802013-12-12 22:07:01406 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
407 modal_container->layout_manager()) : NULL;
[email protected]c0ce80e2012-10-05 23:28:27408}
409
[email protected]d90b8392012-06-13 09:34:56410aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45411 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56412}
413
[email protected]d8a24952013-08-05 20:05:05414const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45415 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05416}
417
[email protected]864b58552013-12-19 04:19:38418void RootWindowController::ShowShelf() {
419 if (!shelf_->shelf())
[email protected]e74aaf0a2012-10-12 18:42:28420 return;
[email protected]864b58552013-12-19 04:19:38421 shelf_->shelf()->SetVisible(true);
[email protected]478c6c32013-03-09 02:50:58422 shelf_->status_area_widget()->Show();
[email protected]e74aaf0a2012-10-12 18:42:28423}
424
[email protected]864b58552013-12-19 04:19:38425void RootWindowController::OnShelfCreated() {
[email protected]756bda12013-07-03 08:17:06426 if (panel_layout_manager_)
[email protected]864b58552013-12-19 04:19:38427 panel_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39428 if (docked_layout_manager_) {
[email protected]864b58552013-12-19 04:19:38429 docked_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39430 if (shelf_->shelf_layout_manager())
431 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
432 }
[email protected]b8642ec2014-04-17 05:20:39433
434 // Notify shell observers that the shelf has been created.
435 Shell::GetInstance()->OnShelfCreatedForRootWindow(GetRootWindow());
[email protected]756bda12013-07-03 08:17:06436}
437
[email protected]16059276d2012-10-22 18:59:50438void RootWindowController::UpdateAfterLoginStatusChange(
439 user::LoginStatus status) {
[email protected]cf6fea22013-08-07 14:24:01440 if (status != user::LOGGED_IN_NONE)
441 mouse_event_target_.reset();
[email protected]80549c152013-07-02 01:42:47442 if (shelf_->status_area_widget())
[email protected]478c6c32013-03-09 02:50:58443 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
[email protected]16059276d2012-10-22 18:59:50444}
445
[email protected]bca9a7e2012-11-10 06:25:49446void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27447#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49448 if (CommandLine::ForCurrentProcess()->HasSwitch(
449 switches::kAshAnimateFromBootSplashScreen) &&
450 boot_splash_screen_.get()) {
451 // Make the splash screen fade out so it doesn't obscure the desktop
452 // wallpaper's brightness/grayscale animation.
453 boot_splash_screen_->StartHideAnimation(
454 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
455 }
[email protected]252eb232013-08-14 22:09:27456#endif
[email protected]bca9a7e2012-11-10 06:25:49457}
458
[email protected]0bf61732013-07-02 04:35:10459void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
460 // Make sure the wallpaper is visible.
[email protected]bca9a7e2012-11-10 06:25:49461 system_background_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27462#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49463 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27464#endif
[email protected]0bf61732013-07-02 04:35:10465
466 Shell::GetInstance()->user_wallpaper_delegate()->
467 OnWallpaperAnimationFinished();
468 // Only removes old component when wallpaper animation finished. If we
469 // remove the old one before the new wallpaper is done fading in there will
470 // be a white flash during the animation.
471 if (animating_wallpaper_controller()) {
472 DesktopBackgroundWidgetController* controller =
473 animating_wallpaper_controller()->GetController(true);
474 // |desktop_widget_| should be the same animating widget we try to move
475 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
476 // before move it to |kDesktopController|.
477 DCHECK_EQ(controller->widget(), widget);
478 // Release the old controller and close its background widget.
479 SetWallpaperController(controller);
480 }
[email protected]697f04c2012-10-03 01:15:10481}
482
[email protected]d90b8392012-06-13 09:34:56483void RootWindowController::CloseChildWindows() {
[email protected]cf6fea22013-08-07 14:24:01484 mouse_event_target_.reset();
485
[email protected]2a57beb52014-06-09 20:02:26486 // Remove observer as deactivating keyboard causes |docked_layout_manager_|
487 // to fire notifications.
488 if (docked_layout_manager_ && shelf_ && shelf_->shelf_layout_manager())
489 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
490
[email protected]b6ba05d902013-10-04 21:38:45491 // Deactivate keyboard container before closing child windows and shutting
492 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03493 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45494
[email protected]79a87b7e2013-01-25 05:08:22495 // panel_layout_manager_ needs to be shut down before windows are destroyed.
496 if (panel_layout_manager_) {
497 panel_layout_manager_->Shutdown();
498 panel_layout_manager_ = NULL;
499 }
[email protected]7115bd32013-07-19 08:25:39500 // docked_layout_manager_ needs to be shut down before windows are destroyed.
501 if (docked_layout_manager_) {
[email protected]7115bd32013-07-19 08:25:39502 docked_layout_manager_->Shutdown();
503 docked_layout_manager_ = NULL;
504 }
[email protected]f5c9dbc2014-04-11 08:13:45505 aura::Window* root_window = GetRootWindow();
506 aura::client::SetDragDropClient(root_window, NULL);
[email protected]8b3e3d82013-08-20 14:36:30507
[email protected]478c6c32013-03-09 02:50:58508 // TODO(harrym): Remove when Status Area Widget is a child view.
[email protected]bb42c932013-10-31 06:52:06509 if (shelf_) {
510 shelf_->ShutdownStatusAreaWidget();
[email protected]478c6c32013-03-09 02:50:58511
[email protected]bb42c932013-10-31 06:52:06512 if (shelf_->shelf_layout_manager())
513 shelf_->shelf_layout_manager()->PrepareForShutdown();
514 }
[email protected]e74aaf0a2012-10-12 18:42:28515
[email protected]d90b8392012-06-13 09:34:56516 // Close background widget first as it depends on tooltip.
[email protected]0bf61732013-07-02 04:35:10517 wallpaper_controller_.reset();
518 animating_wallpaper_controller_.reset();
[email protected]b4ddc7a2012-08-07 04:17:32519
[email protected]d90b8392012-06-13 09:34:56520 workspace_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45521 aura::client::SetTooltipClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56522
[email protected]0fbfa972013-10-02 19:23:33523 // Explicitly destroy top level windows. We do this as during part of
524 // destruction such windows may query the RootWindow for state.
[email protected]8b3e3d82013-08-20 14:36:30525 std::queue<aura::Window*> non_toplevel_windows;
[email protected]f5c9dbc2014-04-11 08:13:45526 non_toplevel_windows.push(root_window);
[email protected]8b3e3d82013-08-20 14:36:30527 while (!non_toplevel_windows.empty()) {
528 aura::Window* non_toplevel_window = non_toplevel_windows.front();
529 non_toplevel_windows.pop();
530 aura::WindowTracker toplevel_windows;
531 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
532 aura::Window* child = non_toplevel_window->children()[i];
[email protected]0fbfa972013-10-02 19:23:33533 if (!child->owned_by_parent())
534 continue;
[email protected]8b3e3d82013-08-20 14:36:30535 if (child->delegate())
536 toplevel_windows.Add(child);
537 else
538 non_toplevel_windows.push(child);
539 }
540 while (!toplevel_windows.windows().empty())
541 delete *toplevel_windows.windows().begin();
[email protected]d90b8392012-06-13 09:34:56542 }
[email protected]8b3e3d82013-08-20 14:36:30543 // And then remove the containers.
[email protected]f5c9dbc2014-04-11 08:13:45544 while (!root_window->children().empty()) {
545 aura::Window* window = root_window->children()[0];
[email protected]0fbfa972013-10-02 19:23:33546 if (window->owned_by_parent()) {
547 delete window;
548 } else {
[email protected]f5c9dbc2014-04-11 08:13:45549 root_window->RemoveChild(window);
[email protected]0fbfa972013-10-02 19:23:33550 }
551 }
[email protected]478c6c32013-03-09 02:50:58552
[email protected]bb42c932013-10-31 06:52:06553 shelf_.reset();
[email protected]d90b8392012-06-13 09:34:56554}
555
[email protected]bf9cdb362013-10-25 19:22:45556void RootWindowController::MoveWindowsTo(aura::Window* dst) {
[email protected]8039e06c2013-01-17 23:34:50557 // Forget the shelf early so that shelf don't update itself using wrong
558 // display info.
559 workspace_controller_->SetShelf(NULL);
[email protected]f5c9dbc2014-04-11 08:13:45560 ReparentAllWindows(GetRootWindow(), dst);
[email protected]f1853122012-06-27 16:21:26561}
562
[email protected]478c6c32013-03-09 02:50:58563ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
[email protected]80549c152013-07-02 01:42:47564 return shelf_->shelf_layout_manager();
[email protected]478c6c32013-03-09 02:50:58565}
566
[email protected]a0afeb12012-12-10 22:57:09567SystemTray* RootWindowController::GetSystemTray() {
568 // We assume in throughout the code that this will not return NULL. If code
569 // triggers this for valid reasons, it should test status_area_widget first.
[email protected]80549c152013-07-02 01:42:47570 CHECK(shelf_->status_area_widget());
[email protected]478c6c32013-03-09 02:50:58571 return shelf_->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09572}
573
[email protected]940fb1c2013-06-18 16:54:28574void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
575 ui::MenuSourceType source_type) {
[email protected]431552c2012-10-23 00:38:33576 DCHECK(Shell::GetInstance()->delegate());
577 scoped_ptr<ui::MenuModel> menu_model(
[email protected]f5c9dbc2014-04-11 08:13:45578 Shell::GetInstance()->delegate()->CreateContextMenu(
579 GetRootWindow(), NULL, NULL));
[email protected]7f7f65c2013-04-17 16:47:13580 if (!menu_model)
[email protected]8e837ec2013-01-31 01:48:33581 return;
[email protected]431552c2012-10-23 00:38:33582
[email protected]6175fc42013-04-05 05:58:58583 // Background controller may not be set yet if user clicked on status are
584 // before initial animation completion. See crbug.com/222218
[email protected]0bf61732013-07-02 04:35:10585 if (!wallpaper_controller_.get())
[email protected]431552c2012-10-23 00:38:33586 return;
587
[email protected]0a37a5d2014-07-15 00:42:23588 views::MenuRunner menu_runner(menu_model.get(),
589 views::MenuRunner::CONTEXT_MENU);
[email protected]0bf61732013-07-02 04:35:10590 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
[email protected]fd6c0a62014-05-01 07:50:35591 NULL,
592 gfx::Rect(location_in_screen, gfx::Size()),
593 views::MENU_ANCHOR_TOPLEFT,
[email protected]0a37a5d2014-07-15 00:42:23594 source_type) == views::MenuRunner::MENU_DELETED) {
[email protected]6175fc42013-04-05 05:58:58595 return;
596 }
597
[email protected]431552c2012-10-23 00:38:33598 Shell::GetInstance()->UpdateShelfVisibility();
599}
600
[email protected]e74aaf0a2012-10-12 18:42:28601void RootWindowController::UpdateShelfVisibility() {
[email protected]478c6c32013-03-09 02:50:58602 shelf_->shelf_layout_manager()->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28603}
604
[email protected]2c9171d22013-12-10 21:55:10605const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
[email protected]2c9171d22013-12-10 21:55:10606 const aura::Window* topmost_window = NULL;
[email protected]2c5db9e2014-02-27 13:58:14607 const aura::Window* active_window = wm::GetActiveWindow();
[email protected]f5c9dbc2014-04-11 08:13:45608 if (active_window && active_window->GetRootWindow() == GetRootWindow() &&
[email protected]2c5db9e2014-02-27 13:58:14609 IsSwitchableContainer(active_window->parent())) {
610 // Use the active window when it is on the current root window to determine
611 // the fullscreen state to allow temporarily using a panel or docked window
612 // (which are always above the default container) while a fullscreen
613 // window is open. We only use the active window when in a switchable
614 // container as the launcher should not exit fullscreen mode.
615 topmost_window = active_window;
616 } else {
617 // Otherwise, use the topmost window on the root window's default container
618 // when there is no active window on this root window.
619 const aura::Window::Windows& windows =
620 GetContainer(kShellWindowId_DefaultContainer)->children();
621 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
622 iter != windows.rend(); ++iter) {
623 if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL ||
624 (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) &&
625 (*iter)->layer()->GetTargetVisibility()) {
626 topmost_window = *iter;
627 break;
628 }
[email protected]2c9171d22013-12-10 21:55:10629 }
630 }
631 while (topmost_window) {
632 if (wm::GetWindowState(topmost_window)->IsFullscreen())
633 return topmost_window;
[email protected]e319c7e2014-03-14 19:56:14634 topmost_window = ::wm::GetTransientParent(topmost_window);
[email protected]2ee2f5d2013-01-10 23:37:16635 }
[email protected]700849f2013-04-30 17:49:20636 return NULL;
[email protected]2ee2f5d2013-01-10 23:37:16637}
638
[email protected]b6ba05d902013-10-04 21:38:45639void RootWindowController::ActivateKeyboard(
640 keyboard::KeyboardController* keyboard_controller) {
641 if (!keyboard::IsKeyboardEnabled() ||
642 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
643 return;
644 }
645 DCHECK(keyboard_controller);
[email protected]51f438112013-11-18 19:32:50646 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
647 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
648 keyboard_controller->AddObserver(panel_layout_manager_);
649 keyboard_controller->AddObserver(docked_layout_manager_);
[email protected]ee4d1a62014-06-04 15:55:49650 keyboard_controller->AddObserver(workspace_controller_->layout_manager());
[email protected]40db36e2014-04-04 14:08:18651 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(true);
[email protected]51f438112013-11-18 19:32:50652 }
[email protected]b2da9b602014-03-05 18:39:52653 aura::Window* parent = GetContainer(
654 kShellWindowId_VirtualKeyboardParentContainer);
655 DCHECK(parent);
[email protected]b6ba05d902013-10-04 21:38:45656 aura::Window* keyboard_container =
657 keyboard_controller->GetContainerWindow();
658 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
659 parent->AddChild(keyboard_container);
660 // TODO(oshima): Bounds of keyboard container should be handled by
661 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
662 keyboard_container->SetBounds(parent->bounds());
663}
[email protected]86459e2c2013-04-10 13:39:24664
[email protected]b6ba05d902013-10-04 21:38:45665void RootWindowController::DeactivateKeyboard(
666 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41667 if (!keyboard_controller ||
668 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45669 return;
[email protected]e1b299b2014-01-29 23:53:41670 }
[email protected]b6ba05d902013-10-04 21:38:45671 aura::Window* keyboard_container =
672 keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45673 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
[email protected]b2da9b602014-03-05 18:39:52674 aura::Window* parent = GetContainer(
675 kShellWindowId_VirtualKeyboardParentContainer);
676 DCHECK(parent);
677 parent->RemoveChild(keyboard_container);
[email protected]51f438112013-11-18 19:32:50678 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
[email protected]1025937e2014-02-13 01:25:50679 // Virtual keyboard may be deactivated while still showing, notify all
680 // observers that keyboard bounds changed to 0 before remove them.
681 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
[email protected]51f438112013-11-18 19:32:50682 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
683 keyboard_controller->RemoveObserver(panel_layout_manager_);
684 keyboard_controller->RemoveObserver(docked_layout_manager_);
[email protected]ee4d1a62014-06-04 15:55:49685 keyboard_controller->RemoveObserver(
686 workspace_controller_->layout_manager());
[email protected]40db36e2014-04-04 14:08:18687 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(false);
[email protected]51f438112013-11-18 19:32:50688 }
[email protected]86459e2c2013-04-10 13:39:24689 }
690}
691
[email protected]602022b2014-03-31 17:07:31692bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
693 aura::Window* parent = GetContainer(
694 kShellWindowId_VirtualKeyboardParentContainer);
695 return parent ? parent->Contains(window) : false;
696}
697
[email protected]a4cd6d32012-09-12 03:42:13698////////////////////////////////////////////////////////////////////////////////
699// RootWindowController, private:
700
[email protected]f5c9dbc2014-04-11 08:13:45701RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
702 : ash_host_(ash_host),
[email protected]a273d33a2013-10-17 12:41:21703 root_window_layout_(NULL),
704 docked_layout_manager_(NULL),
705 panel_layout_manager_(NULL),
706 touch_hud_debug_(NULL),
707 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45708 aura::Window* root_window = GetRootWindow();
709 GetRootWindowSettings(root_window)->controller = this;
710 screen_dimmer_.reset(new ScreenDimmer(root_window));
[email protected]a273d33a2013-10-17 12:41:21711
712 stacking_controller_.reset(new StackingController);
[email protected]f5c9dbc2014-04-11 08:13:45713 aura::client::SetWindowTreeClient(root_window, stacking_controller_.get());
714 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21715}
716
[email protected]608de6c2013-10-29 00:14:28717void RootWindowController::Init(RootWindowType root_window_type,
718 bool first_run_after_boot) {
[email protected]f5c9dbc2014-04-11 08:13:45719 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50720 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45721 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21722
[email protected]f5c9dbc2014-04-11 08:13:45723 ash_host_->AsWindowTreeHost()->SetCursor(ui::kCursorPointer);
724 CreateContainersInRootWindow(root_window);
[email protected]608de6c2013-10-29 00:14:28725
[email protected]51f438112013-11-18 19:32:50726 if (root_window_type == VIRTUAL_KEYBOARD) {
[email protected]0370e2e2014-04-14 19:49:06727 aura::Window* virtual_keyboard_parent_container = GetContainer(
728 kShellWindowId_VirtualKeyboardParentContainer);
729 virtual_keyboard_parent_container->SetBounds(root_window->bounds());
[email protected]51f438112013-11-18 19:32:50730 shell->InitKeyboard();
[email protected]608de6c2013-10-29 00:14:28731 return;
[email protected]51f438112013-11-18 19:32:50732 }
[email protected]608de6c2013-10-29 00:14:28733
[email protected]a273d33a2013-10-17 12:41:21734 CreateSystemBackground(first_run_after_boot);
735
736 InitLayoutManagers();
737 InitTouchHuds();
738
739 if (Shell::GetPrimaryRootWindowController()->
740 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
741 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
742 }
743
[email protected]a273d33a2013-10-17 12:41:21744 shell->AddShellObserver(this);
745
[email protected]608de6c2013-10-29 00:14:28746 if (root_window_type == PRIMARY) {
[email protected]a3565792013-10-18 12:52:37747 root_window_layout()->OnWindowResized();
[email protected]51f438112013-11-18 19:32:50748 if (!keyboard::IsKeyboardUsabilityExperimentEnabled())
749 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21750 } else {
751 root_window_layout()->OnWindowResized();
[email protected]f5c9dbc2014-04-11 08:13:45752 ash_host_->AsWindowTreeHost()->Show();
[email protected]a273d33a2013-10-17 12:41:21753
[email protected]864b58552013-12-19 04:19:38754 // Create a shelf if a user is already logged in.
[email protected]a273d33a2013-10-17 12:41:21755 if (shell->session_state_delegate()->NumberOfLoggedInUsers())
[email protected]864b58552013-12-19 04:19:38756 shelf()->CreateShelf();
[email protected]0e3e7cb2014-04-12 05:18:25757
758 // Notify shell observers about new root window.
759 shell->OnRootWindowAdded(root_window);
[email protected]a273d33a2013-10-17 12:41:21760 }
[email protected]a825e8312014-05-05 22:05:01761
762#if defined(OS_CHROMEOS)
[email protected]2e0b2352014-07-28 13:28:28763 if (!CommandLine::ForCurrentProcess()->HasSwitch(
764 switches::kAshDisableTouchExplorationMode)) {
[email protected]7d487592014-07-24 03:54:50765 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
[email protected]a825e8312014-05-05 22:05:01766 }
767#endif
[email protected]a273d33a2013-10-17 12:41:21768}
769
[email protected]756bda12013-07-03 08:17:06770void RootWindowController::InitLayoutManagers() {
[email protected]f5c9dbc2014-04-11 08:13:45771 aura::Window* root_window = GetRootWindow();
772 root_window_layout_ = new RootWindowLayoutManager(root_window);
773 root_window->SetLayoutManager(root_window_layout_);
[email protected]756bda12013-07-03 08:17:06774
775 aura::Window* default_container =
776 GetContainer(kShellWindowId_DefaultContainer);
777 // Workspace manager has its own layout managers.
778 workspace_controller_.reset(
779 new WorkspaceController(default_container));
780
781 aura::Window* always_on_top_container =
782 GetContainer(kShellWindowId_AlwaysOnTopContainer);
783 always_on_top_container->SetLayoutManager(
[email protected]093b8d642014-04-03 20:59:28784 new WorkspaceLayoutManager(always_on_top_container));
785 always_on_top_controller_.reset(new AlwaysOnTopController);
[email protected]756bda12013-07-03 08:17:06786 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
787
788 DCHECK(!shelf_.get());
[email protected]093b8d642014-04-03 20:59:28789 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
[email protected]756bda12013-07-03 08:17:06790 // TODO(harrym): Remove when status area is view.
[email protected]093b8d642014-04-03 20:59:28791 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
[email protected]756bda12013-07-03 08:17:06792 shelf_.reset(new ShelfWidget(
793 shelf_container, status_container, workspace_controller()));
794
[email protected]cf6fea22013-08-07 14:24:01795 if (!Shell::GetInstance()->session_state_delegate()->
796 IsActiveUserSessionStarted()) {
797 // This window exists only to be a event target on login screen.
798 // It does not have to handle events, nor be visible.
799 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
[email protected]52b02a72014-01-08 21:41:50800 mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]cf6fea22013-08-07 14:24:01801
802 aura::Window* lock_background_container =
[email protected]093b8d642014-04-03 20:59:28803 GetContainer(kShellWindowId_LockScreenBackgroundContainer);
[email protected]cf6fea22013-08-07 14:24:01804 lock_background_container->AddChild(mouse_event_target_.get());
805 mouse_event_target_->Show();
806 }
807
[email protected]756bda12013-07-03 08:17:06808 // Create Docked windows layout manager
[email protected]093b8d642014-04-03 20:59:28809 aura::Window* docked_container = GetContainer(kShellWindowId_DockedContainer);
[email protected]756bda12013-07-03 08:17:06810 docked_layout_manager_ =
[email protected]093b8d642014-04-03 20:59:28811 new DockedWindowLayoutManager(docked_container, workspace_controller());
[email protected]756bda12013-07-03 08:17:06812 docked_container->SetLayoutManager(docked_layout_manager_);
813
[email protected]1ca79d42014-07-18 16:26:10814 // Installs SnapLayoutManager to containers who set the
815 // |kSnapsChildrenToPhysicalPixelBoundary| property.
816 wm::InstallSnapLayoutManagerToContainers(root_window);
817
[email protected]756bda12013-07-03 08:17:06818 // Create Panel layout manager
[email protected]093b8d642014-04-03 20:59:28819 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
820 panel_layout_manager_ = new PanelLayoutManager(panel_container);
[email protected]756bda12013-07-03 08:17:06821 panel_container->SetLayoutManager(panel_layout_manager_);
[email protected]3537d472014-01-15 05:45:31822 panel_container_handler_.reset(new PanelWindowEventHandler);
823 panel_container->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39824
825 // Install an AttachedPanelWindowTargeter on the panel container to make it
826 // easier to correctly target shelf buttons with touch.
827 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
828 -kResizeOutsideBoundsSize,
829 -kResizeOutsideBoundsSize,
830 -kResizeOutsideBoundsSize);
831 gfx::Insets touch_extend = mouse_extend.Scale(
832 kResizeOutsideBoundsScaleForTouch);
833 panel_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
834 new AttachedPanelWindowTargeter(panel_container,
835 mouse_extend,
836 touch_extend,
837 panel_layout_manager_)));
[email protected]756bda12013-07-03 08:17:06838}
839
840void RootWindowController::InitTouchHuds() {
841 CommandLine* command_line = CommandLine::ForCurrentProcess();
842 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45843 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06844 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
845 EnableTouchHudProjection();
846}
847
848void RootWindowController::CreateSystemBackground(
849 bool is_first_run_after_boot) {
850 SkColor color = SK_ColorBLACK;
851#if defined(OS_CHROMEOS)
852 if (is_first_run_after_boot)
853 color = kChromeOsBootColor;
854#endif
855 system_background_.reset(
[email protected]f5c9dbc2014-04-11 08:13:45856 new SystemBackgroundController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06857
858#if defined(OS_CHROMEOS)
859 // Make a copy of the system's boot splash screen so we can composite it
860 // onscreen until the desktop background is ready.
861 if (is_first_run_after_boot &&
862 (CommandLine::ForCurrentProcess()->HasSwitch(
863 switches::kAshCopyHostBackgroundAtBoot) ||
864 CommandLine::ForCurrentProcess()->HasSwitch(
865 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45866 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06867#endif
868}
869
[email protected]a4cd6d32012-09-12 03:42:13870void RootWindowController::CreateContainersInRootWindow(
[email protected]41baaed2013-11-09 04:18:26871 aura::Window* root_window) {
[email protected]a4cd6d32012-09-12 03:42:13872 // These containers are just used by PowerButtonController to animate groups
873 // of containers simultaneously without messing up the current transformations
874 // on those containers. These are direct children of the root window; all of
875 // the other containers are their children.
[email protected]e6e41d2f2012-10-29 19:22:19876
877 // The desktop background container is not part of the lock animation, so it
878 // is not included in those animate groups.
[email protected]a4cd6d32012-09-12 03:42:13879 // When screen is locked desktop background is moved to lock screen background
880 // container (moved back on unlock). We want to make sure that there's an
881 // opaque layer occluding the non-lock-screen layers.
[email protected]e6e41d2f2012-10-29 19:22:19882 aura::Window* desktop_background_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27883 kShellWindowId_DesktopBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13884 "DesktopBackgroundContainer",
885 root_window);
[email protected]e319c7e2014-03-14 19:56:14886 ::wm::SetChildWindowVisibilityChangesAnimated(desktop_background_container);
[email protected]a4cd6d32012-09-12 03:42:13887
888 aura::Window* non_lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27889 kShellWindowId_NonLockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13890 "NonLockScreenContainersContainer",
891 root_window);
892
893 aura::Window* lock_background_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27894 kShellWindowId_LockScreenBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13895 "LockScreenBackgroundContainer",
896 root_window);
[email protected]e319c7e2014-03-14 19:56:14897 ::wm::SetChildWindowVisibilityChangesAnimated(lock_background_containers);
[email protected]a4cd6d32012-09-12 03:42:13898
899 aura::Window* lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27900 kShellWindowId_LockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13901 "LockScreenContainersContainer",
902 root_window);
903 aura::Window* lock_screen_related_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27904 kShellWindowId_LockScreenRelatedContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13905 "LockScreenRelatedContainersContainer",
906 root_window);
907
[email protected]c0ce80e2012-10-05 23:28:27908 CreateContainer(kShellWindowId_UnparentedControlContainer,
[email protected]a4cd6d32012-09-12 03:42:13909 "UnparentedControlContainer",
910 non_lock_screen_containers);
911
912 aura::Window* default_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27913 kShellWindowId_DefaultContainer,
[email protected]a4cd6d32012-09-12 03:42:13914 "DefaultContainer",
915 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14916 ::wm::SetChildWindowVisibilityChangesAnimated(default_container);
[email protected]1ca79d42014-07-18 16:26:10917 wm::SetSnapsChildrenToPhysicalPixelBoundary(default_container);
[email protected]a4cd6d32012-09-12 03:42:13918 SetUsesScreenCoordinates(default_container);
[email protected]c5be8d672014-01-07 13:33:41919 SetUsesEasyResizeTargeter(default_container);
[email protected]a4cd6d32012-09-12 03:42:13920
921 aura::Window* always_on_top_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27922 kShellWindowId_AlwaysOnTopContainer,
[email protected]a4cd6d32012-09-12 03:42:13923 "AlwaysOnTopContainer",
924 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14925 ::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container);
[email protected]1ca79d42014-07-18 16:26:10926 wm::SetSnapsChildrenToPhysicalPixelBoundary(always_on_top_container);
[email protected]a4cd6d32012-09-12 03:42:13927 SetUsesScreenCoordinates(always_on_top_container);
928
[email protected]beb4e5c2013-06-18 15:37:07929 aura::Window* docked_container = CreateContainer(
930 kShellWindowId_DockedContainer,
931 "DockedContainer",
932 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14933 ::wm::SetChildWindowVisibilityChangesAnimated(docked_container);
[email protected]1ca79d42014-07-18 16:26:10934 wm::SetSnapsChildrenToPhysicalPixelBoundary(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07935 SetUsesScreenCoordinates(docked_container);
[email protected]1ff0c492014-01-21 20:20:44936 SetUsesEasyResizeTargeter(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07937
[email protected]3f13cf12013-07-12 05:13:59938 aura::Window* shelf_container =
[email protected]478c6c32013-03-09 02:50:58939 CreateContainer(kShellWindowId_ShelfContainer,
[email protected]3f13cf12013-07-12 05:13:59940 "ShelfContainer",
[email protected]a4cd6d32012-09-12 03:42:13941 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10942 wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_container);
[email protected]3f13cf12013-07-12 05:13:59943 SetUsesScreenCoordinates(shelf_container);
944 DescendantShouldStayInSameRootWindow(shelf_container);
[email protected]a4cd6d32012-09-12 03:42:13945
[email protected]f2026eb2013-10-22 14:28:56946 aura::Window* panel_container = CreateContainer(
947 kShellWindowId_PanelContainer,
948 "PanelContainer",
949 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10950 wm::SetSnapsChildrenToPhysicalPixelBoundary(panel_container);
[email protected]f2026eb2013-10-22 14:28:56951 SetUsesScreenCoordinates(panel_container);
952
953 aura::Window* shelf_bubble_container =
954 CreateContainer(kShellWindowId_ShelfBubbleContainer,
955 "ShelfBubbleContainer",
956 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10957 wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_bubble_container);
[email protected]f2026eb2013-10-22 14:28:56958 SetUsesScreenCoordinates(shelf_bubble_container);
959 DescendantShouldStayInSameRootWindow(shelf_bubble_container);
960
[email protected]dc851a4e52012-10-03 00:05:55961 aura::Window* app_list_container =
[email protected]c0ce80e2012-10-05 23:28:27962 CreateContainer(kShellWindowId_AppListContainer,
[email protected]dc851a4e52012-10-03 00:05:55963 "AppListContainer",
964 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10965 wm::SetSnapsChildrenToPhysicalPixelBoundary(app_list_container);
[email protected]dc851a4e52012-10-03 00:05:55966 SetUsesScreenCoordinates(app_list_container);
[email protected]a4cd6d32012-09-12 03:42:13967
968 aura::Window* modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27969 kShellWindowId_SystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13970 "SystemModalContainer",
971 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10972 wm::SetSnapsChildrenToPhysicalPixelBoundary(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13973 modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27974 new SystemModalContainerLayoutManager(modal_container));
[email protected]e319c7e2014-03-14 19:56:14975 ::wm::SetChildWindowVisibilityChangesAnimated(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13976 SetUsesScreenCoordinates(modal_container);
[email protected]c5be8d672014-01-07 13:33:41977 SetUsesEasyResizeTargeter(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13978
[email protected]a4cd6d32012-09-12 03:42:13979 // TODO(beng): Figure out if we can make this use
980 // SystemModalContainerEventFilter instead of stops_event_propagation.
981 aura::Window* lock_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27982 kShellWindowId_LockScreenContainer,
[email protected]a4cd6d32012-09-12 03:42:13983 "LockScreenContainer",
984 lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10985 wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_container);
[email protected]68d51332014-06-06 13:51:13986 if (CommandLine::ForCurrentProcess()->HasSwitch(
987 switches::kAshDisableLockLayoutManager)) {
988 lock_container->SetLayoutManager(
989 new WorkspaceLayoutManager(lock_container));
990 } else {
991 lock_container->SetLayoutManager(new LockLayoutManager(lock_container));
992 }
[email protected]a4cd6d32012-09-12 03:42:13993 SetUsesScreenCoordinates(lock_container);
994 // TODO(beng): stopsevents
995
996 aura::Window* lock_modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27997 kShellWindowId_LockSystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13998 "LockSystemModalContainer",
999 lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:101000 wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:131001 lock_modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:271002 new SystemModalContainerLayoutManager(lock_modal_container));
[email protected]e319c7e2014-03-14 19:56:141003 ::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:131004 SetUsesScreenCoordinates(lock_modal_container);
[email protected]c5be8d672014-01-07 13:33:411005 SetUsesEasyResizeTargeter(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:131006
1007 aura::Window* status_container =
[email protected]c0ce80e2012-10-05 23:28:271008 CreateContainer(kShellWindowId_StatusContainer,
[email protected]a4cd6d32012-09-12 03:42:131009 "StatusContainer",
1010 lock_screen_related_containers);
[email protected]1ca79d42014-07-18 16:26:101011 wm::SetSnapsChildrenToPhysicalPixelBoundary(status_container);
[email protected]a4cd6d32012-09-12 03:42:131012 SetUsesScreenCoordinates(status_container);
[email protected]e887c6c2013-07-08 19:35:531013 DescendantShouldStayInSameRootWindow(status_container);
[email protected]a4cd6d32012-09-12 03:42:131014
1015 aura::Window* settings_bubble_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271016 kShellWindowId_SettingBubbleContainer,
[email protected]a4cd6d32012-09-12 03:42:131017 "SettingBubbleContainer",
1018 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141019 ::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
[email protected]1ca79d42014-07-18 16:26:101020 wm::SetSnapsChildrenToPhysicalPixelBoundary(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:131021 SetUsesScreenCoordinates(settings_bubble_container);
[email protected]e887c6c2013-07-08 19:35:531022 DescendantShouldStayInSameRootWindow(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:131023
1024 aura::Window* menu_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271025 kShellWindowId_MenuContainer,
[email protected]a4cd6d32012-09-12 03:42:131026 "MenuContainer",
1027 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141028 ::wm::SetChildWindowVisibilityChangesAnimated(menu_container);
[email protected]1ca79d42014-07-18 16:26:101029 wm::SetSnapsChildrenToPhysicalPixelBoundary(menu_container);
[email protected]a4cd6d32012-09-12 03:42:131030 SetUsesScreenCoordinates(menu_container);
1031
1032 aura::Window* drag_drop_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271033 kShellWindowId_DragImageAndTooltipContainer,
[email protected]a4cd6d32012-09-12 03:42:131034 "DragImageAndTooltipContainer",
1035 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141036 ::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
[email protected]1ca79d42014-07-18 16:26:101037 wm::SetSnapsChildrenToPhysicalPixelBoundary(drag_drop_container);
[email protected]a4cd6d32012-09-12 03:42:131038 SetUsesScreenCoordinates(drag_drop_container);
1039
1040 aura::Window* overlay_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271041 kShellWindowId_OverlayContainer,
[email protected]a4cd6d32012-09-12 03:42:131042 "OverlayContainer",
1043 lock_screen_related_containers);
[email protected]1ca79d42014-07-18 16:26:101044 wm::SetSnapsChildrenToPhysicalPixelBoundary(overlay_container);
[email protected]a4cd6d32012-09-12 03:42:131045 SetUsesScreenCoordinates(overlay_container);
[email protected]a07615f2012-10-24 08:23:081046
[email protected]b2da9b602014-03-05 18:39:521047 aura::Window* virtual_keyboard_parent_container = CreateContainer(
1048 kShellWindowId_VirtualKeyboardParentContainer,
1049 "VirtualKeyboardParentContainer",
1050 root_window);
[email protected]1ca79d42014-07-18 16:26:101051 wm::SetSnapsChildrenToPhysicalPixelBoundary(
1052 virtual_keyboard_parent_container);
[email protected]b2da9b602014-03-05 18:39:521053 SetUsesScreenCoordinates(virtual_keyboard_parent_container);
1054
1055#if defined(OS_CHROMEOS)
1056 aura::Window* mouse_cursor_container = CreateContainer(
1057 kShellWindowId_MouseCursorContainer,
1058 "MouseCursorContainer",
1059 root_window);
1060 SetUsesScreenCoordinates(mouse_cursor_container);
1061#endif
1062
[email protected]a07615f2012-10-24 08:23:081063 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
[email protected]b2da9b602014-03-05 18:39:521064 "PowerButtonAnimationContainer", root_window);
[email protected]a4cd6d32012-09-12 03:42:131065}
1066
[email protected]d141b922013-07-09 08:13:171067void RootWindowController::EnableTouchHudProjection() {
1068 if (touch_hud_projection_)
1069 return;
[email protected]f5c9dbc2014-04-11 08:13:451070 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:171071}
1072
1073void RootWindowController::DisableTouchHudProjection() {
1074 if (!touch_hud_projection_)
1075 return;
1076 touch_hud_projection_->Remove();
1077}
1078
1079void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
1080 shelf_->shelf_layout_manager()->UpdateVisibilityState();
1081}
1082
1083void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
1084 if (enabled)
1085 EnableTouchHudProjection();
1086 else
1087 DisableTouchHudProjection();
1088}
1089
[email protected]6b2d4a0b2013-09-06 06:29:541090RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:451091 const aura::Window* root_window) {
[email protected]6b2d4a0b2013-09-06 06:29:541092 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
1093}
1094
[email protected]d90b8392012-06-13 09:34:561095} // namespace ash