blob: 89bb31eaa6f898e5c0ea48f112b24fd485dfc355 [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() {}
216 virtual ~EmptyWindowDelegate() {}
217
218 // aura::WindowDelegate overrides:
219 virtual gfx::Size GetMinimumSize() const OVERRIDE {
220 return gfx::Size();
221 }
222 virtual gfx::Size GetMaximumSize() const OVERRIDE {
223 return gfx::Size();
224 }
225 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
226 const gfx::Rect& new_bounds) OVERRIDE {
227 }
[email protected]62c9f102014-03-27 06:07:04228 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
229 return gfx::kNullCursor;
230 }
[email protected]cf6fea22013-08-07 14:24:01231 virtual int GetNonClientComponent(
232 const gfx::Point& point) const OVERRIDE {
233 return HTNOWHERE;
234 }
235 virtual bool ShouldDescendIntoChildForEventHandling(
236 aura::Window* child,
237 const gfx::Point& location) OVERRIDE {
238 return false;
239 }
240 virtual bool CanFocus() OVERRIDE {
241 return false;
242 }
243 virtual void OnCaptureLost() OVERRIDE {
244 }
245 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
246 }
247 virtual void OnDeviceScaleFactorChanged(
248 float device_scale_factor) OVERRIDE {
249 }
[email protected]48f36d92014-02-28 00:11:37250 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {}
251 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
[email protected]febe1fd62013-08-07 16:07:24252 delete this;
253 }
[email protected]cf6fea22013-08-07 14:24:01254 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
255 }
256 virtual bool HasHitTestMask() const OVERRIDE {
257 return false;
258 }
259 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
[email protected]cf6fea22013-08-07 14:24:01260
261 private:
262 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
263};
264
[email protected]d90b8392012-06-13 09:34:56265} // namespace
266
[email protected]f5c9dbc2014-04-11 08:13:45267void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38268 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28269 controller->Init(RootWindowController::PRIMARY,
[email protected]a273d33a2013-10-17 12:41:21270 Shell::GetInstance()->delegate()->IsFirstRunAfterBoot());
[email protected]d90b8392012-06-13 09:34:56271}
272
[email protected]f5c9dbc2014-04-11 08:13:45273void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38274 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28275 controller->Init(RootWindowController::SECONDARY, false /* first run */);
276}
277
[email protected]88d71122012-10-18 07:11:01278// static
[email protected]76bc4632014-06-16 19:07:46279RootWindowController* RootWindowController::ForShelf(
280 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07281 CHECK(Shell::HasInstance());
[email protected]8c0ec432013-05-10 04:33:39282 return GetRootWindowController(window->GetRootWindow());
[email protected]88d71122012-10-18 07:11:01283}
284
[email protected]a0afeb12012-12-10 22:57:09285// static
[email protected]ccff3d72013-02-06 04:26:28286RootWindowController* RootWindowController::ForWindow(
287 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07288 CHECK(Shell::HasInstance());
[email protected]a0afeb12012-12-10 22:57:09289 return GetRootWindowController(window->GetRootWindow());
290}
291
292// static
[email protected]d17642d2013-09-12 23:44:38293RootWindowController* RootWindowController::ForTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07294 CHECK(Shell::HasInstance());
[email protected]093b8d642014-04-03 20:59:28295 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09296}
297
[email protected]a5c78802013-12-12 22:07:01298// static
299aura::Window* RootWindowController::GetContainerForWindow(
300 aura::Window* window) {
301 aura::Window* container = window->parent();
[email protected]5b251f12013-12-19 01:50:05302 while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN)
[email protected]a5c78802013-12-12 22:07:01303 container = container->parent();
304 return container;
305}
306
[email protected]a273d33a2013-10-17 12:41:21307RootWindowController::~RootWindowController() {
308 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45309 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21310 // The CaptureClient needs to be around for as long as the RootWindow is
311 // valid.
312 capture_client_.reset();
313}
314
[email protected]f5c9dbc2014-04-11 08:13:45315aura::WindowTreeHost* RootWindowController::GetHost() {
316 return ash_host_->AsWindowTreeHost();
317}
318
319const aura::WindowTreeHost* RootWindowController::GetHost() const {
320 return ash_host_->AsWindowTreeHost();
321}
322
323aura::Window* RootWindowController::GetRootWindow() {
324 return GetHost()->window();
325}
326
327const aura::Window* RootWindowController::GetRootWindow() const {
328 return GetHost()->window();
329}
330
[email protected]0bf61732013-07-02 04:35:10331void RootWindowController::SetWallpaperController(
332 DesktopBackgroundWidgetController* controller) {
333 wallpaper_controller_.reset(controller);
334}
335
336void RootWindowController::SetAnimatingWallpaperController(
337 AnimatingDesktopController* controller) {
338 if (animating_wallpaper_controller_.get())
339 animating_wallpaper_controller_->StopAnimating();
340 animating_wallpaper_controller_.reset(controller);
341}
342
[email protected]6675e1c2012-09-11 09:15:45343void RootWindowController::Shutdown() {
[email protected]a825e8312014-05-05 22:05:01344 Shell* shell = Shell::GetInstance();
345 shell->RemoveShellObserver(this);
346
347#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:50348 if (touch_exploration_manager_) {
349 touch_exploration_manager_.reset();
[email protected]a825e8312014-05-05 22:05:01350 }
351#endif
[email protected]d141b922013-07-09 08:13:17352
[email protected]0bf61732013-07-02 04:35:10353 if (animating_wallpaper_controller_.get())
354 animating_wallpaper_controller_->StopAnimating();
355 wallpaper_controller_.reset();
356 animating_wallpaper_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45357 aura::Window* root_window = GetRootWindow();
[email protected]d17642d2013-09-12 23:44:38358 // Change the target root window before closing child windows. If any child
[email protected]c98a4922013-09-05 20:01:42359 // being removed triggers a relayout of the shelf it will try to build a
[email protected]d17642d2013-09-12 23:44:38360 // window list adding windows from the target root window's containers which
[email protected]c98a4922013-09-05 20:01:42361 // may have already gone away.
[email protected]f5c9dbc2014-04-11 08:13:45362 if (Shell::GetTargetRootWindow() == root_window) {
[email protected]a825e8312014-05-05 22:05:01363 shell->set_target_root_window(
[email protected]f5c9dbc2014-04-11 08:13:45364 Shell::GetPrimaryRootWindow() == root_window
365 ? NULL
366 : Shell::GetPrimaryRootWindow());
[email protected]f634dd32012-07-23 22:49:07367 }
[email protected]c98a4922013-09-05 20:01:42368
369 CloseChildWindows();
[email protected]f5c9dbc2014-04-11 08:13:45370 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]d90b8392012-06-13 09:34:56371 screen_dimmer_.reset();
372 workspace_controller_.reset();
[email protected]6675e1c2012-09-11 09:15:45373 // Forget with the display ID so that display lookup
374 // ends up with invalid display.
[email protected]f5c9dbc2014-04-11 08:13:45375 GetRootWindowSettings(root_window)->display_id =
[email protected]f8e6aad2013-08-30 21:49:11376 gfx::Display::kInvalidDisplayID;
[email protected]8f5209c2014-05-22 20:36:11377 ash_host_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28378
[email protected]956a6a42012-10-29 23:58:10379 system_background_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45380 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56381}
382
[email protected]c0ce80e2012-10-05 23:28:27383SystemModalContainerLayoutManager*
[email protected]8674b312012-10-12 19:02:44384RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
[email protected]a5c78802013-12-12 22:07:01385 aura::Window* modal_container = NULL;
[email protected]8674b312012-10-12 19:02:44386 if (window) {
[email protected]a5c78802013-12-12 22:07:01387 aura::Window* window_container = GetContainerForWindow(window);
388 if (window_container &&
389 window_container->id() >= kShellWindowId_LockScreenContainer) {
390 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35391 } else {
[email protected]a5c78802013-12-12 22:07:01392 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35393 }
[email protected]8674b312012-10-12 19:02:44394 } else {
[email protected]a44afbbd2013-07-24 21:49:35395 int modal_window_id = Shell::GetInstance()->session_state_delegate()
396 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
397 kShellWindowId_SystemModalContainer;
[email protected]a5c78802013-12-12 22:07:01398 modal_container = GetContainer(modal_window_id);
[email protected]8674b312012-10-12 19:02:44399 }
[email protected]a5c78802013-12-12 22:07:01400 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
401 modal_container->layout_manager()) : NULL;
[email protected]c0ce80e2012-10-05 23:28:27402}
403
[email protected]d90b8392012-06-13 09:34:56404aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45405 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56406}
407
[email protected]d8a24952013-08-05 20:05:05408const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45409 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05410}
411
[email protected]864b58552013-12-19 04:19:38412void RootWindowController::ShowShelf() {
413 if (!shelf_->shelf())
[email protected]e74aaf0a2012-10-12 18:42:28414 return;
[email protected]864b58552013-12-19 04:19:38415 shelf_->shelf()->SetVisible(true);
[email protected]478c6c32013-03-09 02:50:58416 shelf_->status_area_widget()->Show();
[email protected]e74aaf0a2012-10-12 18:42:28417}
418
[email protected]864b58552013-12-19 04:19:38419void RootWindowController::OnShelfCreated() {
[email protected]756bda12013-07-03 08:17:06420 if (panel_layout_manager_)
[email protected]864b58552013-12-19 04:19:38421 panel_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39422 if (docked_layout_manager_) {
[email protected]864b58552013-12-19 04:19:38423 docked_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39424 if (shelf_->shelf_layout_manager())
425 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
426 }
[email protected]b8642ec2014-04-17 05:20:39427
428 // Notify shell observers that the shelf has been created.
429 Shell::GetInstance()->OnShelfCreatedForRootWindow(GetRootWindow());
[email protected]756bda12013-07-03 08:17:06430}
431
[email protected]16059276d2012-10-22 18:59:50432void RootWindowController::UpdateAfterLoginStatusChange(
433 user::LoginStatus status) {
[email protected]cf6fea22013-08-07 14:24:01434 if (status != user::LOGGED_IN_NONE)
435 mouse_event_target_.reset();
[email protected]80549c152013-07-02 01:42:47436 if (shelf_->status_area_widget())
[email protected]478c6c32013-03-09 02:50:58437 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
[email protected]16059276d2012-10-22 18:59:50438}
439
[email protected]bca9a7e2012-11-10 06:25:49440void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27441#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49442 if (CommandLine::ForCurrentProcess()->HasSwitch(
443 switches::kAshAnimateFromBootSplashScreen) &&
444 boot_splash_screen_.get()) {
445 // Make the splash screen fade out so it doesn't obscure the desktop
446 // wallpaper's brightness/grayscale animation.
447 boot_splash_screen_->StartHideAnimation(
448 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
449 }
[email protected]252eb232013-08-14 22:09:27450#endif
[email protected]bca9a7e2012-11-10 06:25:49451}
452
[email protected]0bf61732013-07-02 04:35:10453void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
454 // Make sure the wallpaper is visible.
[email protected]bca9a7e2012-11-10 06:25:49455 system_background_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27456#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49457 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27458#endif
[email protected]0bf61732013-07-02 04:35:10459
460 Shell::GetInstance()->user_wallpaper_delegate()->
461 OnWallpaperAnimationFinished();
462 // Only removes old component when wallpaper animation finished. If we
463 // remove the old one before the new wallpaper is done fading in there will
464 // be a white flash during the animation.
465 if (animating_wallpaper_controller()) {
466 DesktopBackgroundWidgetController* controller =
467 animating_wallpaper_controller()->GetController(true);
468 // |desktop_widget_| should be the same animating widget we try to move
469 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
470 // before move it to |kDesktopController|.
471 DCHECK_EQ(controller->widget(), widget);
472 // Release the old controller and close its background widget.
473 SetWallpaperController(controller);
474 }
[email protected]697f04c2012-10-03 01:15:10475}
476
[email protected]d90b8392012-06-13 09:34:56477void RootWindowController::CloseChildWindows() {
[email protected]cf6fea22013-08-07 14:24:01478 mouse_event_target_.reset();
479
[email protected]2a57beb52014-06-09 20:02:26480 // Remove observer as deactivating keyboard causes |docked_layout_manager_|
481 // to fire notifications.
482 if (docked_layout_manager_ && shelf_ && shelf_->shelf_layout_manager())
483 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
484
[email protected]b6ba05d902013-10-04 21:38:45485 // Deactivate keyboard container before closing child windows and shutting
486 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03487 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45488
[email protected]79a87b7e2013-01-25 05:08:22489 // panel_layout_manager_ needs to be shut down before windows are destroyed.
490 if (panel_layout_manager_) {
491 panel_layout_manager_->Shutdown();
492 panel_layout_manager_ = NULL;
493 }
[email protected]7115bd32013-07-19 08:25:39494 // docked_layout_manager_ needs to be shut down before windows are destroyed.
495 if (docked_layout_manager_) {
[email protected]7115bd32013-07-19 08:25:39496 docked_layout_manager_->Shutdown();
497 docked_layout_manager_ = NULL;
498 }
[email protected]f5c9dbc2014-04-11 08:13:45499 aura::Window* root_window = GetRootWindow();
500 aura::client::SetDragDropClient(root_window, NULL);
[email protected]8b3e3d82013-08-20 14:36:30501
[email protected]478c6c32013-03-09 02:50:58502 // TODO(harrym): Remove when Status Area Widget is a child view.
[email protected]bb42c932013-10-31 06:52:06503 if (shelf_) {
504 shelf_->ShutdownStatusAreaWidget();
[email protected]478c6c32013-03-09 02:50:58505
[email protected]bb42c932013-10-31 06:52:06506 if (shelf_->shelf_layout_manager())
507 shelf_->shelf_layout_manager()->PrepareForShutdown();
508 }
[email protected]e74aaf0a2012-10-12 18:42:28509
[email protected]d90b8392012-06-13 09:34:56510 // Close background widget first as it depends on tooltip.
[email protected]0bf61732013-07-02 04:35:10511 wallpaper_controller_.reset();
512 animating_wallpaper_controller_.reset();
[email protected]b4ddc7a2012-08-07 04:17:32513
[email protected]d90b8392012-06-13 09:34:56514 workspace_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45515 aura::client::SetTooltipClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56516
[email protected]0fbfa972013-10-02 19:23:33517 // Explicitly destroy top level windows. We do this as during part of
518 // destruction such windows may query the RootWindow for state.
[email protected]8b3e3d82013-08-20 14:36:30519 std::queue<aura::Window*> non_toplevel_windows;
[email protected]f5c9dbc2014-04-11 08:13:45520 non_toplevel_windows.push(root_window);
[email protected]8b3e3d82013-08-20 14:36:30521 while (!non_toplevel_windows.empty()) {
522 aura::Window* non_toplevel_window = non_toplevel_windows.front();
523 non_toplevel_windows.pop();
524 aura::WindowTracker toplevel_windows;
525 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
526 aura::Window* child = non_toplevel_window->children()[i];
[email protected]0fbfa972013-10-02 19:23:33527 if (!child->owned_by_parent())
528 continue;
[email protected]8b3e3d82013-08-20 14:36:30529 if (child->delegate())
530 toplevel_windows.Add(child);
531 else
532 non_toplevel_windows.push(child);
533 }
534 while (!toplevel_windows.windows().empty())
535 delete *toplevel_windows.windows().begin();
[email protected]d90b8392012-06-13 09:34:56536 }
[email protected]8b3e3d82013-08-20 14:36:30537 // And then remove the containers.
[email protected]f5c9dbc2014-04-11 08:13:45538 while (!root_window->children().empty()) {
539 aura::Window* window = root_window->children()[0];
[email protected]0fbfa972013-10-02 19:23:33540 if (window->owned_by_parent()) {
541 delete window;
542 } else {
[email protected]f5c9dbc2014-04-11 08:13:45543 root_window->RemoveChild(window);
[email protected]0fbfa972013-10-02 19:23:33544 }
545 }
[email protected]478c6c32013-03-09 02:50:58546
[email protected]bb42c932013-10-31 06:52:06547 shelf_.reset();
[email protected]d90b8392012-06-13 09:34:56548}
549
[email protected]bf9cdb362013-10-25 19:22:45550void RootWindowController::MoveWindowsTo(aura::Window* dst) {
[email protected]8039e06c2013-01-17 23:34:50551 // Forget the shelf early so that shelf don't update itself using wrong
552 // display info.
553 workspace_controller_->SetShelf(NULL);
[email protected]f5c9dbc2014-04-11 08:13:45554 ReparentAllWindows(GetRootWindow(), dst);
[email protected]f1853122012-06-27 16:21:26555}
556
[email protected]478c6c32013-03-09 02:50:58557ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
[email protected]80549c152013-07-02 01:42:47558 return shelf_->shelf_layout_manager();
[email protected]478c6c32013-03-09 02:50:58559}
560
[email protected]a0afeb12012-12-10 22:57:09561SystemTray* RootWindowController::GetSystemTray() {
562 // We assume in throughout the code that this will not return NULL. If code
563 // triggers this for valid reasons, it should test status_area_widget first.
[email protected]80549c152013-07-02 01:42:47564 CHECK(shelf_->status_area_widget());
[email protected]478c6c32013-03-09 02:50:58565 return shelf_->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09566}
567
[email protected]940fb1c2013-06-18 16:54:28568void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
569 ui::MenuSourceType source_type) {
[email protected]431552c2012-10-23 00:38:33570 DCHECK(Shell::GetInstance()->delegate());
571 scoped_ptr<ui::MenuModel> menu_model(
[email protected]f5c9dbc2014-04-11 08:13:45572 Shell::GetInstance()->delegate()->CreateContextMenu(
573 GetRootWindow(), NULL, NULL));
[email protected]7f7f65c2013-04-17 16:47:13574 if (!menu_model)
[email protected]8e837ec2013-01-31 01:48:33575 return;
[email protected]431552c2012-10-23 00:38:33576
[email protected]6175fc42013-04-05 05:58:58577 // Background controller may not be set yet if user clicked on status are
578 // before initial animation completion. See crbug.com/222218
[email protected]0bf61732013-07-02 04:35:10579 if (!wallpaper_controller_.get())
[email protected]431552c2012-10-23 00:38:33580 return;
581
[email protected]0a37a5d2014-07-15 00:42:23582 views::MenuRunner menu_runner(menu_model.get(),
583 views::MenuRunner::CONTEXT_MENU);
[email protected]0bf61732013-07-02 04:35:10584 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
[email protected]fd6c0a62014-05-01 07:50:35585 NULL,
586 gfx::Rect(location_in_screen, gfx::Size()),
587 views::MENU_ANCHOR_TOPLEFT,
[email protected]0a37a5d2014-07-15 00:42:23588 source_type) == views::MenuRunner::MENU_DELETED) {
[email protected]6175fc42013-04-05 05:58:58589 return;
590 }
591
[email protected]431552c2012-10-23 00:38:33592 Shell::GetInstance()->UpdateShelfVisibility();
593}
594
[email protected]e74aaf0a2012-10-12 18:42:28595void RootWindowController::UpdateShelfVisibility() {
[email protected]478c6c32013-03-09 02:50:58596 shelf_->shelf_layout_manager()->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28597}
598
[email protected]2c9171d22013-12-10 21:55:10599const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
[email protected]2c9171d22013-12-10 21:55:10600 const aura::Window* topmost_window = NULL;
[email protected]2c5db9e2014-02-27 13:58:14601 const aura::Window* active_window = wm::GetActiveWindow();
[email protected]f5c9dbc2014-04-11 08:13:45602 if (active_window && active_window->GetRootWindow() == GetRootWindow() &&
[email protected]2c5db9e2014-02-27 13:58:14603 IsSwitchableContainer(active_window->parent())) {
604 // Use the active window when it is on the current root window to determine
605 // the fullscreen state to allow temporarily using a panel or docked window
606 // (which are always above the default container) while a fullscreen
607 // window is open. We only use the active window when in a switchable
608 // container as the launcher should not exit fullscreen mode.
609 topmost_window = active_window;
610 } else {
611 // Otherwise, use the topmost window on the root window's default container
612 // when there is no active window on this root window.
613 const aura::Window::Windows& windows =
614 GetContainer(kShellWindowId_DefaultContainer)->children();
615 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
616 iter != windows.rend(); ++iter) {
617 if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL ||
618 (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) &&
619 (*iter)->layer()->GetTargetVisibility()) {
620 topmost_window = *iter;
621 break;
622 }
[email protected]2c9171d22013-12-10 21:55:10623 }
624 }
625 while (topmost_window) {
626 if (wm::GetWindowState(topmost_window)->IsFullscreen())
627 return topmost_window;
[email protected]e319c7e2014-03-14 19:56:14628 topmost_window = ::wm::GetTransientParent(topmost_window);
[email protected]2ee2f5d2013-01-10 23:37:16629 }
[email protected]700849f2013-04-30 17:49:20630 return NULL;
[email protected]2ee2f5d2013-01-10 23:37:16631}
632
[email protected]b6ba05d902013-10-04 21:38:45633void RootWindowController::ActivateKeyboard(
634 keyboard::KeyboardController* keyboard_controller) {
635 if (!keyboard::IsKeyboardEnabled() ||
636 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
637 return;
638 }
639 DCHECK(keyboard_controller);
bshe9858b4a2014-09-16 20:46:38640 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
641 keyboard_controller->AddObserver(panel_layout_manager_);
642 keyboard_controller->AddObserver(docked_layout_manager_);
643 keyboard_controller->AddObserver(workspace_controller_->layout_manager());
644 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(true);
bshec3875422014-09-29 13:21:30645 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52646 DCHECK(parent);
[email protected]b6ba05d902013-10-04 21:38:45647 aura::Window* keyboard_container =
648 keyboard_controller->GetContainerWindow();
649 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
650 parent->AddChild(keyboard_container);
651 // TODO(oshima): Bounds of keyboard container should be handled by
652 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
653 keyboard_container->SetBounds(parent->bounds());
654}
[email protected]86459e2c2013-04-10 13:39:24655
[email protected]b6ba05d902013-10-04 21:38:45656void RootWindowController::DeactivateKeyboard(
657 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41658 if (!keyboard_controller ||
659 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45660 return;
[email protected]e1b299b2014-01-29 23:53:41661 }
[email protected]b6ba05d902013-10-04 21:38:45662 aura::Window* keyboard_container =
663 keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45664 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
bshec3875422014-09-29 13:21:30665 aura::Window* parent =
666 GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52667 DCHECK(parent);
668 parent->RemoveChild(keyboard_container);
bshe9858b4a2014-09-16 20:46:38669 // Virtual keyboard may be deactivated while still showing, notify all
670 // observers that keyboard bounds changed to 0 before remove them.
671 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
672 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
673 keyboard_controller->RemoveObserver(panel_layout_manager_);
674 keyboard_controller->RemoveObserver(docked_layout_manager_);
675 keyboard_controller->RemoveObserver(
676 workspace_controller_->layout_manager());
677 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(false);
[email protected]86459e2c2013-04-10 13:39:24678 }
679}
680
[email protected]602022b2014-03-31 17:07:31681bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
bshec3875422014-09-29 13:21:30682 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]602022b2014-03-31 17:07:31683 return parent ? parent->Contains(window) : false;
684}
685
[email protected]a4cd6d32012-09-12 03:42:13686////////////////////////////////////////////////////////////////////////////////
687// RootWindowController, private:
688
[email protected]f5c9dbc2014-04-11 08:13:45689RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
690 : ash_host_(ash_host),
[email protected]a273d33a2013-10-17 12:41:21691 root_window_layout_(NULL),
692 docked_layout_manager_(NULL),
693 panel_layout_manager_(NULL),
694 touch_hud_debug_(NULL),
695 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45696 aura::Window* root_window = GetRootWindow();
697 GetRootWindowSettings(root_window)->controller = this;
698 screen_dimmer_.reset(new ScreenDimmer(root_window));
[email protected]a273d33a2013-10-17 12:41:21699
700 stacking_controller_.reset(new StackingController);
[email protected]f5c9dbc2014-04-11 08:13:45701 aura::client::SetWindowTreeClient(root_window, stacking_controller_.get());
702 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21703}
704
[email protected]608de6c2013-10-29 00:14:28705void RootWindowController::Init(RootWindowType root_window_type,
706 bool first_run_after_boot) {
[email protected]f5c9dbc2014-04-11 08:13:45707 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50708 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45709 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21710
[email protected]f5c9dbc2014-04-11 08:13:45711 ash_host_->AsWindowTreeHost()->SetCursor(ui::kCursorPointer);
712 CreateContainersInRootWindow(root_window);
[email protected]608de6c2013-10-29 00:14:28713
[email protected]a273d33a2013-10-17 12:41:21714 CreateSystemBackground(first_run_after_boot);
715
716 InitLayoutManagers();
717 InitTouchHuds();
718
719 if (Shell::GetPrimaryRootWindowController()->
720 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
721 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
722 }
723
[email protected]a273d33a2013-10-17 12:41:21724 shell->AddShellObserver(this);
725
[email protected]608de6c2013-10-29 00:14:28726 if (root_window_type == PRIMARY) {
[email protected]a3565792013-10-18 12:52:37727 root_window_layout()->OnWindowResized();
bshe9858b4a2014-09-16 20:46:38728 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21729 } else {
730 root_window_layout()->OnWindowResized();
[email protected]f5c9dbc2014-04-11 08:13:45731 ash_host_->AsWindowTreeHost()->Show();
[email protected]a273d33a2013-10-17 12:41:21732
[email protected]864b58552013-12-19 04:19:38733 // Create a shelf if a user is already logged in.
[email protected]a273d33a2013-10-17 12:41:21734 if (shell->session_state_delegate()->NumberOfLoggedInUsers())
[email protected]864b58552013-12-19 04:19:38735 shelf()->CreateShelf();
[email protected]0e3e7cb2014-04-12 05:18:25736
737 // Notify shell observers about new root window.
738 shell->OnRootWindowAdded(root_window);
[email protected]a273d33a2013-10-17 12:41:21739 }
[email protected]a825e8312014-05-05 22:05:01740
741#if defined(OS_CHROMEOS)
[email protected]2e0b2352014-07-28 13:28:28742 if (!CommandLine::ForCurrentProcess()->HasSwitch(
743 switches::kAshDisableTouchExplorationMode)) {
[email protected]7d487592014-07-24 03:54:50744 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
[email protected]a825e8312014-05-05 22:05:01745 }
746#endif
[email protected]a273d33a2013-10-17 12:41:21747}
748
[email protected]756bda12013-07-03 08:17:06749void RootWindowController::InitLayoutManagers() {
[email protected]f5c9dbc2014-04-11 08:13:45750 aura::Window* root_window = GetRootWindow();
751 root_window_layout_ = new RootWindowLayoutManager(root_window);
752 root_window->SetLayoutManager(root_window_layout_);
[email protected]756bda12013-07-03 08:17:06753
754 aura::Window* default_container =
755 GetContainer(kShellWindowId_DefaultContainer);
756 // Workspace manager has its own layout managers.
757 workspace_controller_.reset(
758 new WorkspaceController(default_container));
759
760 aura::Window* always_on_top_container =
761 GetContainer(kShellWindowId_AlwaysOnTopContainer);
762 always_on_top_container->SetLayoutManager(
[email protected]093b8d642014-04-03 20:59:28763 new WorkspaceLayoutManager(always_on_top_container));
764 always_on_top_controller_.reset(new AlwaysOnTopController);
[email protected]756bda12013-07-03 08:17:06765 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
766
767 DCHECK(!shelf_.get());
[email protected]093b8d642014-04-03 20:59:28768 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
[email protected]756bda12013-07-03 08:17:06769 // TODO(harrym): Remove when status area is view.
[email protected]093b8d642014-04-03 20:59:28770 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
[email protected]756bda12013-07-03 08:17:06771 shelf_.reset(new ShelfWidget(
772 shelf_container, status_container, workspace_controller()));
773
[email protected]cf6fea22013-08-07 14:24:01774 if (!Shell::GetInstance()->session_state_delegate()->
775 IsActiveUserSessionStarted()) {
776 // This window exists only to be a event target on login screen.
777 // It does not have to handle events, nor be visible.
778 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
[email protected]52b02a72014-01-08 21:41:50779 mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]cf6fea22013-08-07 14:24:01780
781 aura::Window* lock_background_container =
[email protected]093b8d642014-04-03 20:59:28782 GetContainer(kShellWindowId_LockScreenBackgroundContainer);
[email protected]cf6fea22013-08-07 14:24:01783 lock_background_container->AddChild(mouse_event_target_.get());
784 mouse_event_target_->Show();
785 }
786
[email protected]756bda12013-07-03 08:17:06787 // Create Docked windows layout manager
[email protected]093b8d642014-04-03 20:59:28788 aura::Window* docked_container = GetContainer(kShellWindowId_DockedContainer);
[email protected]756bda12013-07-03 08:17:06789 docked_layout_manager_ =
[email protected]093b8d642014-04-03 20:59:28790 new DockedWindowLayoutManager(docked_container, workspace_controller());
[email protected]756bda12013-07-03 08:17:06791 docked_container->SetLayoutManager(docked_layout_manager_);
792
[email protected]1ca79d42014-07-18 16:26:10793 // Installs SnapLayoutManager to containers who set the
794 // |kSnapsChildrenToPhysicalPixelBoundary| property.
795 wm::InstallSnapLayoutManagerToContainers(root_window);
796
[email protected]756bda12013-07-03 08:17:06797 // Create Panel layout manager
[email protected]093b8d642014-04-03 20:59:28798 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
799 panel_layout_manager_ = new PanelLayoutManager(panel_container);
[email protected]756bda12013-07-03 08:17:06800 panel_container->SetLayoutManager(panel_layout_manager_);
[email protected]3537d472014-01-15 05:45:31801 panel_container_handler_.reset(new PanelWindowEventHandler);
802 panel_container->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39803
804 // Install an AttachedPanelWindowTargeter on the panel container to make it
805 // easier to correctly target shelf buttons with touch.
806 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
807 -kResizeOutsideBoundsSize,
808 -kResizeOutsideBoundsSize,
809 -kResizeOutsideBoundsSize);
810 gfx::Insets touch_extend = mouse_extend.Scale(
811 kResizeOutsideBoundsScaleForTouch);
812 panel_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
813 new AttachedPanelWindowTargeter(panel_container,
814 mouse_extend,
815 touch_extend,
816 panel_layout_manager_)));
[email protected]756bda12013-07-03 08:17:06817}
818
819void RootWindowController::InitTouchHuds() {
820 CommandLine* command_line = CommandLine::ForCurrentProcess();
821 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45822 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06823 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
824 EnableTouchHudProjection();
825}
826
827void RootWindowController::CreateSystemBackground(
828 bool is_first_run_after_boot) {
829 SkColor color = SK_ColorBLACK;
830#if defined(OS_CHROMEOS)
831 if (is_first_run_after_boot)
832 color = kChromeOsBootColor;
833#endif
834 system_background_.reset(
[email protected]f5c9dbc2014-04-11 08:13:45835 new SystemBackgroundController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06836
837#if defined(OS_CHROMEOS)
838 // Make a copy of the system's boot splash screen so we can composite it
839 // onscreen until the desktop background is ready.
840 if (is_first_run_after_boot &&
841 (CommandLine::ForCurrentProcess()->HasSwitch(
842 switches::kAshCopyHostBackgroundAtBoot) ||
843 CommandLine::ForCurrentProcess()->HasSwitch(
844 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45845 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06846#endif
847}
848
[email protected]a4cd6d32012-09-12 03:42:13849void RootWindowController::CreateContainersInRootWindow(
[email protected]41baaed2013-11-09 04:18:26850 aura::Window* root_window) {
[email protected]a4cd6d32012-09-12 03:42:13851 // These containers are just used by PowerButtonController to animate groups
852 // of containers simultaneously without messing up the current transformations
853 // on those containers. These are direct children of the root window; all of
854 // the other containers are their children.
[email protected]e6e41d2f2012-10-29 19:22:19855
856 // The desktop background container is not part of the lock animation, so it
857 // is not included in those animate groups.
[email protected]a4cd6d32012-09-12 03:42:13858 // When screen is locked desktop background is moved to lock screen background
859 // container (moved back on unlock). We want to make sure that there's an
860 // opaque layer occluding the non-lock-screen layers.
[email protected]e6e41d2f2012-10-29 19:22:19861 aura::Window* desktop_background_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27862 kShellWindowId_DesktopBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13863 "DesktopBackgroundContainer",
864 root_window);
[email protected]e319c7e2014-03-14 19:56:14865 ::wm::SetChildWindowVisibilityChangesAnimated(desktop_background_container);
[email protected]a4cd6d32012-09-12 03:42:13866
867 aura::Window* non_lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27868 kShellWindowId_NonLockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13869 "NonLockScreenContainersContainer",
870 root_window);
871
872 aura::Window* lock_background_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27873 kShellWindowId_LockScreenBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13874 "LockScreenBackgroundContainer",
875 root_window);
[email protected]e319c7e2014-03-14 19:56:14876 ::wm::SetChildWindowVisibilityChangesAnimated(lock_background_containers);
[email protected]a4cd6d32012-09-12 03:42:13877
878 aura::Window* lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27879 kShellWindowId_LockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13880 "LockScreenContainersContainer",
881 root_window);
882 aura::Window* lock_screen_related_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27883 kShellWindowId_LockScreenRelatedContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13884 "LockScreenRelatedContainersContainer",
885 root_window);
886
[email protected]c0ce80e2012-10-05 23:28:27887 CreateContainer(kShellWindowId_UnparentedControlContainer,
[email protected]a4cd6d32012-09-12 03:42:13888 "UnparentedControlContainer",
889 non_lock_screen_containers);
890
891 aura::Window* default_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27892 kShellWindowId_DefaultContainer,
[email protected]a4cd6d32012-09-12 03:42:13893 "DefaultContainer",
894 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14895 ::wm::SetChildWindowVisibilityChangesAnimated(default_container);
[email protected]1ca79d42014-07-18 16:26:10896 wm::SetSnapsChildrenToPhysicalPixelBoundary(default_container);
[email protected]a4cd6d32012-09-12 03:42:13897 SetUsesScreenCoordinates(default_container);
[email protected]c5be8d672014-01-07 13:33:41898 SetUsesEasyResizeTargeter(default_container);
[email protected]a4cd6d32012-09-12 03:42:13899
900 aura::Window* always_on_top_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27901 kShellWindowId_AlwaysOnTopContainer,
[email protected]a4cd6d32012-09-12 03:42:13902 "AlwaysOnTopContainer",
903 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14904 ::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container);
[email protected]1ca79d42014-07-18 16:26:10905 wm::SetSnapsChildrenToPhysicalPixelBoundary(always_on_top_container);
[email protected]a4cd6d32012-09-12 03:42:13906 SetUsesScreenCoordinates(always_on_top_container);
907
[email protected]beb4e5c2013-06-18 15:37:07908 aura::Window* docked_container = CreateContainer(
909 kShellWindowId_DockedContainer,
910 "DockedContainer",
911 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14912 ::wm::SetChildWindowVisibilityChangesAnimated(docked_container);
[email protected]1ca79d42014-07-18 16:26:10913 wm::SetSnapsChildrenToPhysicalPixelBoundary(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07914 SetUsesScreenCoordinates(docked_container);
[email protected]1ff0c492014-01-21 20:20:44915 SetUsesEasyResizeTargeter(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07916
[email protected]3f13cf12013-07-12 05:13:59917 aura::Window* shelf_container =
[email protected]478c6c32013-03-09 02:50:58918 CreateContainer(kShellWindowId_ShelfContainer,
[email protected]3f13cf12013-07-12 05:13:59919 "ShelfContainer",
[email protected]a4cd6d32012-09-12 03:42:13920 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10921 wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_container);
[email protected]3f13cf12013-07-12 05:13:59922 SetUsesScreenCoordinates(shelf_container);
923 DescendantShouldStayInSameRootWindow(shelf_container);
[email protected]a4cd6d32012-09-12 03:42:13924
[email protected]f2026eb2013-10-22 14:28:56925 aura::Window* panel_container = CreateContainer(
926 kShellWindowId_PanelContainer,
927 "PanelContainer",
928 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10929 wm::SetSnapsChildrenToPhysicalPixelBoundary(panel_container);
[email protected]f2026eb2013-10-22 14:28:56930 SetUsesScreenCoordinates(panel_container);
931
932 aura::Window* shelf_bubble_container =
933 CreateContainer(kShellWindowId_ShelfBubbleContainer,
934 "ShelfBubbleContainer",
935 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10936 wm::SetSnapsChildrenToPhysicalPixelBoundary(shelf_bubble_container);
[email protected]f2026eb2013-10-22 14:28:56937 SetUsesScreenCoordinates(shelf_bubble_container);
938 DescendantShouldStayInSameRootWindow(shelf_bubble_container);
939
[email protected]dc851a4e52012-10-03 00:05:55940 aura::Window* app_list_container =
[email protected]c0ce80e2012-10-05 23:28:27941 CreateContainer(kShellWindowId_AppListContainer,
[email protected]dc851a4e52012-10-03 00:05:55942 "AppListContainer",
943 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10944 wm::SetSnapsChildrenToPhysicalPixelBoundary(app_list_container);
[email protected]dc851a4e52012-10-03 00:05:55945 SetUsesScreenCoordinates(app_list_container);
[email protected]a4cd6d32012-09-12 03:42:13946
947 aura::Window* modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27948 kShellWindowId_SystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13949 "SystemModalContainer",
950 non_lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10951 wm::SetSnapsChildrenToPhysicalPixelBoundary(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13952 modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27953 new SystemModalContainerLayoutManager(modal_container));
[email protected]e319c7e2014-03-14 19:56:14954 ::wm::SetChildWindowVisibilityChangesAnimated(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13955 SetUsesScreenCoordinates(modal_container);
[email protected]c5be8d672014-01-07 13:33:41956 SetUsesEasyResizeTargeter(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13957
[email protected]a4cd6d32012-09-12 03:42:13958 // TODO(beng): Figure out if we can make this use
959 // SystemModalContainerEventFilter instead of stops_event_propagation.
960 aura::Window* lock_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27961 kShellWindowId_LockScreenContainer,
[email protected]a4cd6d32012-09-12 03:42:13962 "LockScreenContainer",
963 lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10964 wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_container);
[email protected]68d51332014-06-06 13:51:13965 if (CommandLine::ForCurrentProcess()->HasSwitch(
966 switches::kAshDisableLockLayoutManager)) {
967 lock_container->SetLayoutManager(
968 new WorkspaceLayoutManager(lock_container));
969 } else {
970 lock_container->SetLayoutManager(new LockLayoutManager(lock_container));
971 }
[email protected]a4cd6d32012-09-12 03:42:13972 SetUsesScreenCoordinates(lock_container);
973 // TODO(beng): stopsevents
974
975 aura::Window* lock_modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27976 kShellWindowId_LockSystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13977 "LockSystemModalContainer",
978 lock_screen_containers);
[email protected]1ca79d42014-07-18 16:26:10979 wm::SetSnapsChildrenToPhysicalPixelBoundary(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13980 lock_modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27981 new SystemModalContainerLayoutManager(lock_modal_container));
[email protected]e319c7e2014-03-14 19:56:14982 ::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13983 SetUsesScreenCoordinates(lock_modal_container);
[email protected]c5be8d672014-01-07 13:33:41984 SetUsesEasyResizeTargeter(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13985
986 aura::Window* status_container =
[email protected]c0ce80e2012-10-05 23:28:27987 CreateContainer(kShellWindowId_StatusContainer,
[email protected]a4cd6d32012-09-12 03:42:13988 "StatusContainer",
989 lock_screen_related_containers);
[email protected]1ca79d42014-07-18 16:26:10990 wm::SetSnapsChildrenToPhysicalPixelBoundary(status_container);
[email protected]a4cd6d32012-09-12 03:42:13991 SetUsesScreenCoordinates(status_container);
[email protected]e887c6c2013-07-08 19:35:53992 DescendantShouldStayInSameRootWindow(status_container);
[email protected]a4cd6d32012-09-12 03:42:13993
994 aura::Window* settings_bubble_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27995 kShellWindowId_SettingBubbleContainer,
[email protected]a4cd6d32012-09-12 03:42:13996 "SettingBubbleContainer",
997 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:14998 ::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
[email protected]1ca79d42014-07-18 16:26:10999 wm::SetSnapsChildrenToPhysicalPixelBoundary(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:131000 SetUsesScreenCoordinates(settings_bubble_container);
[email protected]e887c6c2013-07-08 19:35:531001 DescendantShouldStayInSameRootWindow(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:131002
kevers23f3987d2014-09-17 13:50:121003 aura::Window* virtual_keyboard_parent_container =
bshec3875422014-09-29 13:21:301004 CreateContainer(kShellWindowId_ImeWindowParentContainer,
kevers23f3987d2014-09-17 13:50:121005 "VirtualKeyboardParentContainer",
1006 lock_screen_related_containers);
1007 wm::SetSnapsChildrenToPhysicalPixelBoundary(
1008 virtual_keyboard_parent_container);
kevers0e450492014-09-30 16:02:311009 virtual_keyboard_parent_container->SetLayoutManager(
1010 new VirtualKeyboardContainerLayoutManager(
1011 virtual_keyboard_parent_container));
kevers23f3987d2014-09-17 13:50:121012 SetUsesScreenCoordinates(virtual_keyboard_parent_container);
1013
[email protected]a4cd6d32012-09-12 03:42:131014 aura::Window* menu_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271015 kShellWindowId_MenuContainer,
[email protected]a4cd6d32012-09-12 03:42:131016 "MenuContainer",
1017 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141018 ::wm::SetChildWindowVisibilityChangesAnimated(menu_container);
[email protected]1ca79d42014-07-18 16:26:101019 wm::SetSnapsChildrenToPhysicalPixelBoundary(menu_container);
[email protected]a4cd6d32012-09-12 03:42:131020 SetUsesScreenCoordinates(menu_container);
1021
1022 aura::Window* drag_drop_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271023 kShellWindowId_DragImageAndTooltipContainer,
[email protected]a4cd6d32012-09-12 03:42:131024 "DragImageAndTooltipContainer",
1025 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:141026 ::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
[email protected]1ca79d42014-07-18 16:26:101027 wm::SetSnapsChildrenToPhysicalPixelBoundary(drag_drop_container);
[email protected]a4cd6d32012-09-12 03:42:131028 SetUsesScreenCoordinates(drag_drop_container);
1029
1030 aura::Window* overlay_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:271031 kShellWindowId_OverlayContainer,
[email protected]a4cd6d32012-09-12 03:42:131032 "OverlayContainer",
1033 lock_screen_related_containers);
[email protected]1ca79d42014-07-18 16:26:101034 wm::SetSnapsChildrenToPhysicalPixelBoundary(overlay_container);
[email protected]a4cd6d32012-09-12 03:42:131035 SetUsesScreenCoordinates(overlay_container);
[email protected]a07615f2012-10-24 08:23:081036
[email protected]b2da9b602014-03-05 18:39:521037#if defined(OS_CHROMEOS)
1038 aura::Window* mouse_cursor_container = CreateContainer(
1039 kShellWindowId_MouseCursorContainer,
1040 "MouseCursorContainer",
1041 root_window);
1042 SetUsesScreenCoordinates(mouse_cursor_container);
1043#endif
1044
[email protected]a07615f2012-10-24 08:23:081045 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
[email protected]b2da9b602014-03-05 18:39:521046 "PowerButtonAnimationContainer", root_window);
[email protected]a4cd6d32012-09-12 03:42:131047}
1048
[email protected]d141b922013-07-09 08:13:171049void RootWindowController::EnableTouchHudProjection() {
1050 if (touch_hud_projection_)
1051 return;
[email protected]f5c9dbc2014-04-11 08:13:451052 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:171053}
1054
1055void RootWindowController::DisableTouchHudProjection() {
1056 if (!touch_hud_projection_)
1057 return;
1058 touch_hud_projection_->Remove();
1059}
1060
1061void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
1062 shelf_->shelf_layout_manager()->UpdateVisibilityState();
1063}
1064
1065void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
1066 if (enabled)
1067 EnableTouchHudProjection();
1068 else
1069 DisableTouchHudProjection();
1070}
1071
[email protected]6b2d4a0b2013-09-06 06:29:541072RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:451073 const aura::Window* root_window) {
[email protected]6b2d4a0b2013-09-06 06:29:541074 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
1075}
1076
[email protected]d90b8392012-06-13 09:34:561077} // namespace ash