blob: 6dd3b67491a6ca50cc7a7b5551df67dc252fe879 [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]fcb123d2013-04-17 15:58:4920#include "ash/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]2b8a9bb2013-07-01 22:43:4031#include "ash/touch/touch_hud_debug.h"
32#include "ash/touch/touch_hud_projection.h"
[email protected]80549c152013-07-02 01:42:4733#include "ash/touch/touch_observer_hud.h"
34#include "ash/wm/always_on_top_controller.h"
[email protected]beb4e5c2013-06-18 15:37:0735#include "ash/wm/dock/docked_window_layout_manager.h"
[email protected]b8642ec2014-04-17 05:20:3936#include "ash/wm/panels/attached_panel_window_targeter.h"
[email protected]7095a652013-03-07 19:41:4937#include "ash/wm/panels/panel_layout_manager.h"
[email protected]100659412013-06-21 22:59:5538#include "ash/wm/panels/panel_window_event_handler.h"
[email protected]d90b8392012-06-13 09:34:5639#include "ash/wm/root_window_layout_manager.h"
40#include "ash/wm/screen_dimmer.h"
[email protected]2a2caa02013-01-22 20:50:3641#include "ash/wm/stacking_controller.h"
[email protected]e74aaf0a2012-10-12 18:42:2842#include "ash/wm/status_area_layout_manager.h"
[email protected]e6e41d2f2012-10-29 19:22:1943#include "ash/wm/system_background_controller.h"
[email protected]d90b8392012-06-13 09:34:5644#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]8d625fb2012-07-18 16:40:0645#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3446#include "ash/wm/window_state.h"
[email protected]700849f2013-04-30 17:49:2047#include "ash/wm/window_util.h"
[email protected]1af71f72014-01-29 20:00:5548#include "ash/wm/workspace/workspace_layout_manager.h"
[email protected]d90b8392012-06-13 09:34:5649#include "ash/wm/workspace_controller.h"
[email protected]e6e41d2f2012-10-29 19:22:1950#include "base/command_line.h"
[email protected]1e84c632013-06-27 23:12:2151#include "base/time/time.h"
[email protected]f1853122012-06-27 16:21:2652#include "ui/aura/client/aura_constants.h"
[email protected]2374d1812014-03-04 03:42:2753#include "ui/aura/client/screen_position_client.h"
[email protected]f1853122012-06-27 16:21:2654#include "ui/aura/window.h"
[email protected]cf6fea22013-08-07 14:24:0155#include "ui/aura/window_delegate.h"
[email protected]fcc51c952014-02-21 21:31:2656#include "ui/aura/window_event_dispatcher.h"
[email protected]f1853122012-06-27 16:21:2657#include "ui/aura/window_observer.h"
[email protected]8b3e3d82013-08-20 14:36:3058#include "ui/aura/window_tracker.h"
[email protected]cf6fea22013-08-07 14:24:0159#include "ui/base/hit_test.h"
[email protected]431552c2012-10-23 00:38:3360#include "ui/base/models/menu_model.h"
[email protected]f8e6aad2013-08-30 21:49:1161#include "ui/gfx/display.h"
[email protected]8d625fb2012-07-18 16:40:0662#include "ui/gfx/screen.h"
[email protected]86459e2c2013-04-10 13:39:2463#include "ui/keyboard/keyboard_controller.h"
64#include "ui/keyboard/keyboard_util.h"
[email protected]431552c2012-10-23 00:38:3365#include "ui/views/controls/menu/menu_runner.h"
66#include "ui/views/view_model.h"
67#include "ui/views/view_model_utils.h"
[email protected]ee3ed10772014-03-11 22:02:0168#include "ui/wm/core/capture_controller.h"
[email protected]e319c7e2014-03-14 19:56:1469#include "ui/wm/core/easy_resize_window_targeter.h"
[email protected]ee3ed10772014-03-11 22:02:0170#include "ui/wm/core/visibility_controller.h"
71#include "ui/wm/core/window_util.h"
[email protected]af4552b22014-03-21 19:45:0172#include "ui/wm/public/drag_drop_client.h"
73#include "ui/wm/public/tooltip_client.h"
[email protected]5b251f12013-12-19 01:50:0574#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5675
[email protected]252eb232013-08-14 22:09:2776#if defined(OS_CHROMEOS)
77#include "ash/wm/boot_splash_screen_chromeos.h"
78#endif
79
[email protected]d90b8392012-06-13 09:34:5680namespace ash {
81namespace {
82
[email protected]252eb232013-08-14 22:09:2783#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:4984// Duration for the animation that hides the boot splash screen, in
85// milliseconds. This should be short enough in relation to
86// wm/window_animation.cc's brightness/grayscale fade animation that the login
87// background image animation isn't hidden by the splash screen animation.
88const int kBootSplashScreenHideDurationMs = 500;
[email protected]252eb232013-08-14 22:09:2789#endif
[email protected]bca9a7e2012-11-10 06:25:4990
[email protected]d90b8392012-06-13 09:34:5691// Creates a new window for use as a container.
92aura::Window* CreateContainer(int window_id,
93 const char* name,
94 aura::Window* parent) {
95 aura::Window* container = new aura::Window(NULL);
96 container->set_id(window_id);
97 container->SetName(name);
[email protected]52b02a72014-01-08 21:41:5098 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]d90b8392012-06-13 09:34:5699 parent->AddChild(container);
[email protected]093b8d642014-04-03 20:59:28100 if (window_id != kShellWindowId_UnparentedControlContainer)
[email protected]d90b8392012-06-13 09:34:56101 container->Show();
102 return container;
103}
104
[email protected]2816c2462013-12-17 02:22:25105float ToRelativeValue(int value, int src, int dst) {
106 return static_cast<float>(value) / static_cast<float>(src) * dst;
107}
108
109void MoveOriginRelativeToSize(const gfx::Size& src_size,
110 const gfx::Size& dst_size,
111 gfx::Rect* bounds_in_out) {
112 gfx::Point origin = bounds_in_out->origin();
113 bounds_in_out->set_origin(gfx::Point(
114 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
115 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
116}
117
[email protected]95058572012-08-20 14:57:29118// Reparents |window| to |new_parent|.
119void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
[email protected]2816c2462013-12-17 02:22:25120 const gfx::Size src_size = window->parent()->bounds().size();
121 const gfx::Size dst_size = new_parent->bounds().size();
[email protected]95058572012-08-20 14:57:29122 // Update the restore bounds to make it relative to the display.
[email protected]a41b4e12013-09-20 04:36:34123 wm::WindowState* state = wm::GetWindowState(window);
124 gfx::Rect restore_bounds;
125 bool has_restore_bounds = state->HasRestoreBounds();
[email protected]2816c2462013-12-17 02:22:25126
[email protected]9cfd3d12014-02-25 15:33:45127 bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) &&
[email protected]093b8d642014-04-03 20:59:28128 new_parent->id() != kShellWindowId_DockedContainer;
[email protected]2816c2462013-12-17 02:22:25129 gfx::Rect local_bounds;
130 if (update_bounds) {
131 local_bounds = state->window()->bounds();
132 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
133 }
134
135 if (has_restore_bounds) {
[email protected]a41b4e12013-09-20 04:36:34136 restore_bounds = state->GetRestoreBoundsInParent();
[email protected]2816c2462013-12-17 02:22:25137 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
138 }
139
[email protected]95058572012-08-20 14:57:29140 new_parent->AddChild(window);
[email protected]2816c2462013-12-17 02:22:25141
[email protected]8663b7a62014-01-18 01:24:21142 // Docked windows have bounds handled by the layout manager in AddChild().
[email protected]2816c2462013-12-17 02:22:25143 if (update_bounds)
144 window->SetBounds(local_bounds);
145
[email protected]a41b4e12013-09-20 04:36:34146 if (has_restore_bounds)
147 state->SetRestoreBoundsInParent(restore_bounds);
[email protected]95058572012-08-20 14:57:29148}
149
150// Reparents the appropriate set of windows from |src| to |dst|.
[email protected]bf9cdb362013-10-25 19:22:45151void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
[email protected]95058572012-08-20 14:57:29152 // Set of windows to move.
[email protected]f1853122012-06-27 16:21:26153 const int kContainerIdsToMove[] = {
[email protected]093b8d642014-04-03 20:59:28154 kShellWindowId_DefaultContainer,
155 kShellWindowId_DockedContainer,
156 kShellWindowId_PanelContainer,
157 kShellWindowId_AlwaysOnTopContainer,
158 kShellWindowId_SystemModalContainer,
159 kShellWindowId_LockSystemModalContainer,
160 kShellWindowId_InputMethodContainer,
161 kShellWindowId_UnparentedControlContainer, };
[email protected]f1853122012-06-27 16:21:26162 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
163 int id = kContainerIdsToMove[i];
164 aura::Window* src_container = Shell::GetContainer(src, id);
165 aura::Window* dst_container = Shell::GetContainer(dst, id);
[email protected]5b6021902013-02-26 05:33:29166 while (!src_container->children().empty()) {
167 // Restart iteration from the source container windows each time as they
168 // may change as a result of moving other windows.
169 aura::Window::Windows::const_iterator iter =
170 src_container->children().begin();
171 while (iter != src_container->children().end() &&
[email protected]093b8d642014-04-03 20:59:28172 SystemModalContainerLayoutManager::IsModalBackground(*iter)) {
[email protected]5b6021902013-02-26 05:33:29173 ++iter;
174 }
175 // If the entire window list is modal background windows then stop.
176 if (iter == src_container->children().end())
177 break;
178 ReparentWindow(*iter, dst_container);
[email protected]f1853122012-06-27 16:21:26179 }
180 }
181}
182
[email protected]8d625fb2012-07-18 16:40:06183// Mark the container window so that a widget added to this container will
184// use the virtual screeen coordinates instead of parent.
185void SetUsesScreenCoordinates(aura::Window* container) {
[email protected]093b8d642014-04-03 20:59:28186 container->SetProperty(kUsesScreenCoordinatesKey, true);
[email protected]8d625fb2012-07-18 16:40:06187}
188
[email protected]e887c6c2013-07-08 19:35:53189// Mark the container window so that a widget added to this container will
190// say in the same root window regardless of the bounds specified.
191void DescendantShouldStayInSameRootWindow(aura::Window* container) {
[email protected]093b8d642014-04-03 20:59:28192 container->SetProperty(kStayInSameRootWindowKey, true);
[email protected]e887c6c2013-07-08 19:35:53193}
194
[email protected]c5be8d672014-01-07 13:33:41195void SetUsesEasyResizeTargeter(aura::Window* container) {
196 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
197 -kResizeOutsideBoundsSize,
198 -kResizeOutsideBoundsSize,
199 -kResizeOutsideBoundsSize);
200 gfx::Insets touch_extend = mouse_extend.Scale(
201 kResizeOutsideBoundsScaleForTouch);
[email protected]95f642cb2014-01-31 01:35:41202 container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
[email protected]c5be8d672014-01-07 13:33:41203 new ::wm::EasyResizeWindowTargeter(container, mouse_extend,
204 touch_extend)));
205}
206
[email protected]cf6fea22013-08-07 14:24:01207// A window delegate which does nothing. Used to create a window that
208// is a event target, but do nothing.
209class EmptyWindowDelegate : public aura::WindowDelegate {
210 public:
211 EmptyWindowDelegate() {}
212 virtual ~EmptyWindowDelegate() {}
213
214 // aura::WindowDelegate overrides:
215 virtual gfx::Size GetMinimumSize() const OVERRIDE {
216 return gfx::Size();
217 }
218 virtual gfx::Size GetMaximumSize() const OVERRIDE {
219 return gfx::Size();
220 }
221 virtual void OnBoundsChanged(const gfx::Rect& old_bounds,
222 const gfx::Rect& new_bounds) OVERRIDE {
223 }
[email protected]62c9f102014-03-27 06:07:04224 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
225 return gfx::kNullCursor;
226 }
[email protected]cf6fea22013-08-07 14:24:01227 virtual int GetNonClientComponent(
228 const gfx::Point& point) const OVERRIDE {
229 return HTNOWHERE;
230 }
231 virtual bool ShouldDescendIntoChildForEventHandling(
232 aura::Window* child,
233 const gfx::Point& location) OVERRIDE {
234 return false;
235 }
236 virtual bool CanFocus() OVERRIDE {
237 return false;
238 }
239 virtual void OnCaptureLost() OVERRIDE {
240 }
241 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
242 }
243 virtual void OnDeviceScaleFactorChanged(
244 float device_scale_factor) OVERRIDE {
245 }
[email protected]48f36d92014-02-28 00:11:37246 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {}
247 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {
[email protected]febe1fd62013-08-07 16:07:24248 delete this;
249 }
[email protected]cf6fea22013-08-07 14:24:01250 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {
251 }
252 virtual bool HasHitTestMask() const OVERRIDE {
253 return false;
254 }
255 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {}
[email protected]cf6fea22013-08-07 14:24:01256
257 private:
258 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
259};
260
[email protected]d90b8392012-06-13 09:34:56261} // namespace
262
[email protected]f5c9dbc2014-04-11 08:13:45263void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38264 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28265 controller->Init(RootWindowController::PRIMARY,
[email protected]a273d33a2013-10-17 12:41:21266 Shell::GetInstance()->delegate()->IsFirstRunAfterBoot());
[email protected]d90b8392012-06-13 09:34:56267}
268
[email protected]f5c9dbc2014-04-11 08:13:45269void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38270 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28271 controller->Init(RootWindowController::SECONDARY, false /* first run */);
272}
273
274void RootWindowController::CreateForVirtualKeyboardDisplay(
[email protected]f5c9dbc2014-04-11 08:13:45275 AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38276 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28277 controller->Init(RootWindowController::VIRTUAL_KEYBOARD,
278 false /* first run */);
[email protected]6675e1c2012-09-11 09:15:45279}
280
[email protected]88d71122012-10-18 07:11:01281// static
[email protected]864b58552013-12-19 04:19:38282RootWindowController* RootWindowController::ForShelf(aura::Window* window) {
[email protected]8c0ec432013-05-10 04:33:39283 return GetRootWindowController(window->GetRootWindow());
[email protected]88d71122012-10-18 07:11:01284}
285
[email protected]a0afeb12012-12-10 22:57:09286// static
[email protected]ccff3d72013-02-06 04:26:28287RootWindowController* RootWindowController::ForWindow(
288 const aura::Window* window) {
[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() {
[email protected]093b8d642014-04-03 20:59:28294 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09295}
296
[email protected]a5c78802013-12-12 22:07:01297// static
298aura::Window* RootWindowController::GetContainerForWindow(
299 aura::Window* window) {
300 aura::Window* container = window->parent();
[email protected]5b251f12013-12-19 01:50:05301 while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN)
[email protected]a5c78802013-12-12 22:07:01302 container = container->parent();
303 return container;
304}
305
[email protected]a273d33a2013-10-17 12:41:21306RootWindowController::~RootWindowController() {
307 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45308 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21309 // The CaptureClient needs to be around for as long as the RootWindow is
310 // valid.
311 capture_client_.reset();
312}
313
[email protected]f5c9dbc2014-04-11 08:13:45314aura::WindowTreeHost* RootWindowController::GetHost() {
315 return ash_host_->AsWindowTreeHost();
316}
317
318const aura::WindowTreeHost* RootWindowController::GetHost() const {
319 return ash_host_->AsWindowTreeHost();
320}
321
322aura::Window* RootWindowController::GetRootWindow() {
323 return GetHost()->window();
324}
325
326const aura::Window* RootWindowController::GetRootWindow() const {
327 return GetHost()->window();
328}
329
[email protected]0bf61732013-07-02 04:35:10330void RootWindowController::SetWallpaperController(
331 DesktopBackgroundWidgetController* controller) {
332 wallpaper_controller_.reset(controller);
333}
334
335void RootWindowController::SetAnimatingWallpaperController(
336 AnimatingDesktopController* controller) {
337 if (animating_wallpaper_controller_.get())
338 animating_wallpaper_controller_->StopAnimating();
339 animating_wallpaper_controller_.reset(controller);
340}
341
[email protected]6675e1c2012-09-11 09:15:45342void RootWindowController::Shutdown() {
[email protected]d141b922013-07-09 08:13:17343 Shell::GetInstance()->RemoveShellObserver(this);
344
[email protected]0bf61732013-07-02 04:35:10345 if (animating_wallpaper_controller_.get())
346 animating_wallpaper_controller_->StopAnimating();
347 wallpaper_controller_.reset();
348 animating_wallpaper_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45349 aura::Window* root_window = GetRootWindow();
[email protected]d17642d2013-09-12 23:44:38350 // Change the target root window before closing child windows. If any child
[email protected]c98a4922013-09-05 20:01:42351 // being removed triggers a relayout of the shelf it will try to build a
[email protected]d17642d2013-09-12 23:44:38352 // window list adding windows from the target root window's containers which
[email protected]c98a4922013-09-05 20:01:42353 // may have already gone away.
[email protected]f5c9dbc2014-04-11 08:13:45354 if (Shell::GetTargetRootWindow() == root_window) {
[email protected]d17642d2013-09-12 23:44:38355 Shell::GetInstance()->set_target_root_window(
[email protected]f5c9dbc2014-04-11 08:13:45356 Shell::GetPrimaryRootWindow() == root_window
357 ? NULL
358 : Shell::GetPrimaryRootWindow());
[email protected]f634dd32012-07-23 22:49:07359 }
[email protected]c98a4922013-09-05 20:01:42360
361 CloseChildWindows();
[email protected]f5c9dbc2014-04-11 08:13:45362 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]d90b8392012-06-13 09:34:56363 screen_dimmer_.reset();
364 workspace_controller_.reset();
[email protected]6675e1c2012-09-11 09:15:45365 // Forget with the display ID so that display lookup
366 // ends up with invalid display.
[email protected]f5c9dbc2014-04-11 08:13:45367 GetRootWindowSettings(root_window)->display_id =
[email protected]f8e6aad2013-08-30 21:49:11368 gfx::Display::kInvalidDisplayID;
[email protected]f5c9dbc2014-04-11 08:13:45369 GetRootWindowSettings(root_window)->shutdown = true;
[email protected]e74aaf0a2012-10-12 18:42:28370
[email protected]956a6a42012-10-29 23:58:10371 system_background_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45372 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56373}
374
[email protected]c0ce80e2012-10-05 23:28:27375SystemModalContainerLayoutManager*
[email protected]8674b312012-10-12 19:02:44376RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
[email protected]a5c78802013-12-12 22:07:01377 aura::Window* modal_container = NULL;
[email protected]8674b312012-10-12 19:02:44378 if (window) {
[email protected]a5c78802013-12-12 22:07:01379 aura::Window* window_container = GetContainerForWindow(window);
380 if (window_container &&
381 window_container->id() >= kShellWindowId_LockScreenContainer) {
382 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35383 } else {
[email protected]a5c78802013-12-12 22:07:01384 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35385 }
[email protected]8674b312012-10-12 19:02:44386 } else {
[email protected]a44afbbd2013-07-24 21:49:35387 int modal_window_id = Shell::GetInstance()->session_state_delegate()
388 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
389 kShellWindowId_SystemModalContainer;
[email protected]a5c78802013-12-12 22:07:01390 modal_container = GetContainer(modal_window_id);
[email protected]8674b312012-10-12 19:02:44391 }
[email protected]a5c78802013-12-12 22:07:01392 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
393 modal_container->layout_manager()) : NULL;
[email protected]c0ce80e2012-10-05 23:28:27394}
395
[email protected]d90b8392012-06-13 09:34:56396aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45397 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56398}
399
[email protected]d8a24952013-08-05 20:05:05400const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45401 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05402}
403
[email protected]864b58552013-12-19 04:19:38404void RootWindowController::ShowShelf() {
405 if (!shelf_->shelf())
[email protected]e74aaf0a2012-10-12 18:42:28406 return;
[email protected]864b58552013-12-19 04:19:38407 shelf_->shelf()->SetVisible(true);
[email protected]478c6c32013-03-09 02:50:58408 shelf_->status_area_widget()->Show();
[email protected]e74aaf0a2012-10-12 18:42:28409}
410
[email protected]864b58552013-12-19 04:19:38411void RootWindowController::OnShelfCreated() {
[email protected]756bda12013-07-03 08:17:06412 if (panel_layout_manager_)
[email protected]864b58552013-12-19 04:19:38413 panel_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39414 if (docked_layout_manager_) {
[email protected]864b58552013-12-19 04:19:38415 docked_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39416 if (shelf_->shelf_layout_manager())
417 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
418 }
[email protected]b8642ec2014-04-17 05:20:39419
420 // Notify shell observers that the shelf has been created.
421 Shell::GetInstance()->OnShelfCreatedForRootWindow(GetRootWindow());
[email protected]756bda12013-07-03 08:17:06422}
423
[email protected]16059276d2012-10-22 18:59:50424void RootWindowController::UpdateAfterLoginStatusChange(
425 user::LoginStatus status) {
[email protected]cf6fea22013-08-07 14:24:01426 if (status != user::LOGGED_IN_NONE)
427 mouse_event_target_.reset();
[email protected]80549c152013-07-02 01:42:47428 if (shelf_->status_area_widget())
[email protected]478c6c32013-03-09 02:50:58429 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
[email protected]16059276d2012-10-22 18:59:50430}
431
[email protected]bca9a7e2012-11-10 06:25:49432void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27433#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49434 if (CommandLine::ForCurrentProcess()->HasSwitch(
435 switches::kAshAnimateFromBootSplashScreen) &&
436 boot_splash_screen_.get()) {
437 // Make the splash screen fade out so it doesn't obscure the desktop
438 // wallpaper's brightness/grayscale animation.
439 boot_splash_screen_->StartHideAnimation(
440 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
441 }
[email protected]252eb232013-08-14 22:09:27442#endif
[email protected]bca9a7e2012-11-10 06:25:49443}
444
[email protected]0bf61732013-07-02 04:35:10445void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
446 // Make sure the wallpaper is visible.
[email protected]bca9a7e2012-11-10 06:25:49447 system_background_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27448#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49449 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27450#endif
[email protected]0bf61732013-07-02 04:35:10451
452 Shell::GetInstance()->user_wallpaper_delegate()->
453 OnWallpaperAnimationFinished();
454 // Only removes old component when wallpaper animation finished. If we
455 // remove the old one before the new wallpaper is done fading in there will
456 // be a white flash during the animation.
457 if (animating_wallpaper_controller()) {
458 DesktopBackgroundWidgetController* controller =
459 animating_wallpaper_controller()->GetController(true);
460 // |desktop_widget_| should be the same animating widget we try to move
461 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
462 // before move it to |kDesktopController|.
463 DCHECK_EQ(controller->widget(), widget);
464 // Release the old controller and close its background widget.
465 SetWallpaperController(controller);
466 }
[email protected]697f04c2012-10-03 01:15:10467}
468
[email protected]d90b8392012-06-13 09:34:56469void RootWindowController::CloseChildWindows() {
[email protected]cf6fea22013-08-07 14:24:01470 mouse_event_target_.reset();
471
[email protected]b6ba05d902013-10-04 21:38:45472 // Deactivate keyboard container before closing child windows and shutting
473 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03474 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45475
[email protected]79a87b7e2013-01-25 05:08:22476 // panel_layout_manager_ needs to be shut down before windows are destroyed.
477 if (panel_layout_manager_) {
478 panel_layout_manager_->Shutdown();
479 panel_layout_manager_ = NULL;
480 }
[email protected]7115bd32013-07-19 08:25:39481 // docked_layout_manager_ needs to be shut down before windows are destroyed.
482 if (docked_layout_manager_) {
[email protected]bb42c932013-10-31 06:52:06483 if (shelf_ && shelf_->shelf_layout_manager())
[email protected]7115bd32013-07-19 08:25:39484 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
485 docked_layout_manager_->Shutdown();
486 docked_layout_manager_ = NULL;
487 }
[email protected]f5c9dbc2014-04-11 08:13:45488 aura::Window* root_window = GetRootWindow();
489 aura::client::SetDragDropClient(root_window, NULL);
[email protected]8b3e3d82013-08-20 14:36:30490
[email protected]478c6c32013-03-09 02:50:58491 // TODO(harrym): Remove when Status Area Widget is a child view.
[email protected]bb42c932013-10-31 06:52:06492 if (shelf_) {
493 shelf_->ShutdownStatusAreaWidget();
[email protected]478c6c32013-03-09 02:50:58494
[email protected]bb42c932013-10-31 06:52:06495 if (shelf_->shelf_layout_manager())
496 shelf_->shelf_layout_manager()->PrepareForShutdown();
497 }
[email protected]e74aaf0a2012-10-12 18:42:28498
[email protected]d90b8392012-06-13 09:34:56499 // Close background widget first as it depends on tooltip.
[email protected]0bf61732013-07-02 04:35:10500 wallpaper_controller_.reset();
501 animating_wallpaper_controller_.reset();
[email protected]b4ddc7a2012-08-07 04:17:32502
[email protected]d90b8392012-06-13 09:34:56503 workspace_controller_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45504 aura::client::SetTooltipClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56505
[email protected]0fbfa972013-10-02 19:23:33506 // Explicitly destroy top level windows. We do this as during part of
507 // destruction such windows may query the RootWindow for state.
[email protected]8b3e3d82013-08-20 14:36:30508 std::queue<aura::Window*> non_toplevel_windows;
[email protected]f5c9dbc2014-04-11 08:13:45509 non_toplevel_windows.push(root_window);
[email protected]8b3e3d82013-08-20 14:36:30510 while (!non_toplevel_windows.empty()) {
511 aura::Window* non_toplevel_window = non_toplevel_windows.front();
512 non_toplevel_windows.pop();
513 aura::WindowTracker toplevel_windows;
514 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
515 aura::Window* child = non_toplevel_window->children()[i];
[email protected]0fbfa972013-10-02 19:23:33516 if (!child->owned_by_parent())
517 continue;
[email protected]8b3e3d82013-08-20 14:36:30518 if (child->delegate())
519 toplevel_windows.Add(child);
520 else
521 non_toplevel_windows.push(child);
522 }
523 while (!toplevel_windows.windows().empty())
524 delete *toplevel_windows.windows().begin();
[email protected]d90b8392012-06-13 09:34:56525 }
[email protected]8b3e3d82013-08-20 14:36:30526 // And then remove the containers.
[email protected]f5c9dbc2014-04-11 08:13:45527 while (!root_window->children().empty()) {
528 aura::Window* window = root_window->children()[0];
[email protected]0fbfa972013-10-02 19:23:33529 if (window->owned_by_parent()) {
530 delete window;
531 } else {
[email protected]f5c9dbc2014-04-11 08:13:45532 root_window->RemoveChild(window);
[email protected]0fbfa972013-10-02 19:23:33533 }
534 }
[email protected]478c6c32013-03-09 02:50:58535
[email protected]bb42c932013-10-31 06:52:06536 shelf_.reset();
[email protected]d90b8392012-06-13 09:34:56537}
538
[email protected]bf9cdb362013-10-25 19:22:45539void RootWindowController::MoveWindowsTo(aura::Window* dst) {
[email protected]8039e06c2013-01-17 23:34:50540 // Forget the shelf early so that shelf don't update itself using wrong
541 // display info.
542 workspace_controller_->SetShelf(NULL);
[email protected]f5c9dbc2014-04-11 08:13:45543 ReparentAllWindows(GetRootWindow(), dst);
[email protected]f1853122012-06-27 16:21:26544}
545
[email protected]478c6c32013-03-09 02:50:58546ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
[email protected]80549c152013-07-02 01:42:47547 return shelf_->shelf_layout_manager();
[email protected]478c6c32013-03-09 02:50:58548}
549
[email protected]a0afeb12012-12-10 22:57:09550SystemTray* RootWindowController::GetSystemTray() {
551 // We assume in throughout the code that this will not return NULL. If code
552 // triggers this for valid reasons, it should test status_area_widget first.
[email protected]80549c152013-07-02 01:42:47553 CHECK(shelf_->status_area_widget());
[email protected]478c6c32013-03-09 02:50:58554 return shelf_->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09555}
556
[email protected]940fb1c2013-06-18 16:54:28557void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
558 ui::MenuSourceType source_type) {
[email protected]431552c2012-10-23 00:38:33559 DCHECK(Shell::GetInstance()->delegate());
560 scoped_ptr<ui::MenuModel> menu_model(
[email protected]f5c9dbc2014-04-11 08:13:45561 Shell::GetInstance()->delegate()->CreateContextMenu(
562 GetRootWindow(), NULL, NULL));
[email protected]7f7f65c2013-04-17 16:47:13563 if (!menu_model)
[email protected]8e837ec2013-01-31 01:48:33564 return;
[email protected]431552c2012-10-23 00:38:33565
[email protected]6175fc42013-04-05 05:58:58566 // Background controller may not be set yet if user clicked on status are
567 // before initial animation completion. See crbug.com/222218
[email protected]0bf61732013-07-02 04:35:10568 if (!wallpaper_controller_.get())
[email protected]431552c2012-10-23 00:38:33569 return;
570
[email protected]6175fc42013-04-05 05:58:58571 views::MenuRunner menu_runner(menu_model.get());
[email protected]0bf61732013-07-02 04:35:10572 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
[email protected]6175fc42013-04-05 05:58:58573 NULL, gfx::Rect(location_in_screen, gfx::Size()),
[email protected]940fb1c2013-06-18 16:54:28574 views::MenuItemView::TOPLEFT, source_type,
575 views::MenuRunner::CONTEXT_MENU) ==
[email protected]6175fc42013-04-05 05:58:58576 views::MenuRunner::MENU_DELETED) {
577 return;
578 }
579
[email protected]431552c2012-10-23 00:38:33580 Shell::GetInstance()->UpdateShelfVisibility();
581}
582
[email protected]e74aaf0a2012-10-12 18:42:28583void RootWindowController::UpdateShelfVisibility() {
[email protected]478c6c32013-03-09 02:50:58584 shelf_->shelf_layout_manager()->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28585}
586
[email protected]2c9171d22013-12-10 21:55:10587const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
[email protected]2c9171d22013-12-10 21:55:10588 const aura::Window* topmost_window = NULL;
[email protected]2c5db9e2014-02-27 13:58:14589 const aura::Window* active_window = wm::GetActiveWindow();
[email protected]f5c9dbc2014-04-11 08:13:45590 if (active_window && active_window->GetRootWindow() == GetRootWindow() &&
[email protected]2c5db9e2014-02-27 13:58:14591 IsSwitchableContainer(active_window->parent())) {
592 // Use the active window when it is on the current root window to determine
593 // the fullscreen state to allow temporarily using a panel or docked window
594 // (which are always above the default container) while a fullscreen
595 // window is open. We only use the active window when in a switchable
596 // container as the launcher should not exit fullscreen mode.
597 topmost_window = active_window;
598 } else {
599 // Otherwise, use the topmost window on the root window's default container
600 // when there is no active window on this root window.
601 const aura::Window::Windows& windows =
602 GetContainer(kShellWindowId_DefaultContainer)->children();
603 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
604 iter != windows.rend(); ++iter) {
605 if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL ||
606 (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) &&
607 (*iter)->layer()->GetTargetVisibility()) {
608 topmost_window = *iter;
609 break;
610 }
[email protected]2c9171d22013-12-10 21:55:10611 }
612 }
613 while (topmost_window) {
614 if (wm::GetWindowState(topmost_window)->IsFullscreen())
615 return topmost_window;
[email protected]e319c7e2014-03-14 19:56:14616 topmost_window = ::wm::GetTransientParent(topmost_window);
[email protected]2ee2f5d2013-01-10 23:37:16617 }
[email protected]700849f2013-04-30 17:49:20618 return NULL;
[email protected]2ee2f5d2013-01-10 23:37:16619}
620
[email protected]b6ba05d902013-10-04 21:38:45621void RootWindowController::ActivateKeyboard(
622 keyboard::KeyboardController* keyboard_controller) {
623 if (!keyboard::IsKeyboardEnabled() ||
624 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
625 return;
626 }
627 DCHECK(keyboard_controller);
[email protected]51f438112013-11-18 19:32:50628 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
629 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
630 keyboard_controller->AddObserver(panel_layout_manager_);
631 keyboard_controller->AddObserver(docked_layout_manager_);
[email protected]40db36e2014-04-04 14:08:18632 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(true);
[email protected]51f438112013-11-18 19:32:50633 }
[email protected]b2da9b602014-03-05 18:39:52634 aura::Window* parent = GetContainer(
635 kShellWindowId_VirtualKeyboardParentContainer);
636 DCHECK(parent);
[email protected]b6ba05d902013-10-04 21:38:45637 aura::Window* keyboard_container =
638 keyboard_controller->GetContainerWindow();
639 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
640 parent->AddChild(keyboard_container);
641 // TODO(oshima): Bounds of keyboard container should be handled by
642 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
643 keyboard_container->SetBounds(parent->bounds());
644}
[email protected]86459e2c2013-04-10 13:39:24645
[email protected]b6ba05d902013-10-04 21:38:45646void RootWindowController::DeactivateKeyboard(
647 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41648 if (!keyboard_controller ||
649 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45650 return;
[email protected]e1b299b2014-01-29 23:53:41651 }
[email protected]b6ba05d902013-10-04 21:38:45652 aura::Window* keyboard_container =
653 keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45654 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
[email protected]b2da9b602014-03-05 18:39:52655 aura::Window* parent = GetContainer(
656 kShellWindowId_VirtualKeyboardParentContainer);
657 DCHECK(parent);
658 parent->RemoveChild(keyboard_container);
[email protected]51f438112013-11-18 19:32:50659 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
[email protected]1025937e2014-02-13 01:25:50660 // Virtual keyboard may be deactivated while still showing, notify all
661 // observers that keyboard bounds changed to 0 before remove them.
662 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
[email protected]51f438112013-11-18 19:32:50663 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
664 keyboard_controller->RemoveObserver(panel_layout_manager_);
665 keyboard_controller->RemoveObserver(docked_layout_manager_);
[email protected]40db36e2014-04-04 14:08:18666 Shell::GetInstance()->delegate()->VirtualKeyboardActivated(false);
[email protected]51f438112013-11-18 19:32:50667 }
[email protected]86459e2c2013-04-10 13:39:24668 }
669}
670
[email protected]602022b2014-03-31 17:07:31671bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
672 aura::Window* parent = GetContainer(
673 kShellWindowId_VirtualKeyboardParentContainer);
674 return parent ? parent->Contains(window) : false;
675}
676
[email protected]a4cd6d32012-09-12 03:42:13677////////////////////////////////////////////////////////////////////////////////
678// RootWindowController, private:
679
[email protected]f5c9dbc2014-04-11 08:13:45680RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
681 : ash_host_(ash_host),
[email protected]a273d33a2013-10-17 12:41:21682 root_window_layout_(NULL),
683 docked_layout_manager_(NULL),
684 panel_layout_manager_(NULL),
685 touch_hud_debug_(NULL),
686 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45687 aura::Window* root_window = GetRootWindow();
688 GetRootWindowSettings(root_window)->controller = this;
689 screen_dimmer_.reset(new ScreenDimmer(root_window));
[email protected]a273d33a2013-10-17 12:41:21690
691 stacking_controller_.reset(new StackingController);
[email protected]f5c9dbc2014-04-11 08:13:45692 aura::client::SetWindowTreeClient(root_window, stacking_controller_.get());
693 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21694}
695
[email protected]608de6c2013-10-29 00:14:28696void RootWindowController::Init(RootWindowType root_window_type,
697 bool first_run_after_boot) {
[email protected]f5c9dbc2014-04-11 08:13:45698 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50699 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45700 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21701
[email protected]f5c9dbc2014-04-11 08:13:45702 ash_host_->AsWindowTreeHost()->SetCursor(ui::kCursorPointer);
703 CreateContainersInRootWindow(root_window);
[email protected]608de6c2013-10-29 00:14:28704
[email protected]51f438112013-11-18 19:32:50705 if (root_window_type == VIRTUAL_KEYBOARD) {
[email protected]0370e2e2014-04-14 19:49:06706 aura::Window* virtual_keyboard_parent_container = GetContainer(
707 kShellWindowId_VirtualKeyboardParentContainer);
708 virtual_keyboard_parent_container->SetBounds(root_window->bounds());
[email protected]51f438112013-11-18 19:32:50709 shell->InitKeyboard();
[email protected]608de6c2013-10-29 00:14:28710 return;
[email protected]51f438112013-11-18 19:32:50711 }
[email protected]608de6c2013-10-29 00:14:28712
[email protected]a273d33a2013-10-17 12:41:21713 CreateSystemBackground(first_run_after_boot);
714
715 InitLayoutManagers();
716 InitTouchHuds();
717
718 if (Shell::GetPrimaryRootWindowController()->
719 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
720 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
721 }
722
[email protected]a273d33a2013-10-17 12:41:21723 shell->AddShellObserver(this);
724
[email protected]608de6c2013-10-29 00:14:28725 if (root_window_type == PRIMARY) {
[email protected]a3565792013-10-18 12:52:37726 root_window_layout()->OnWindowResized();
[email protected]51f438112013-11-18 19:32:50727 if (!keyboard::IsKeyboardUsabilityExperimentEnabled())
728 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 }
740}
741
[email protected]756bda12013-07-03 08:17:06742void RootWindowController::InitLayoutManagers() {
[email protected]f5c9dbc2014-04-11 08:13:45743 aura::Window* root_window = GetRootWindow();
744 root_window_layout_ = new RootWindowLayoutManager(root_window);
745 root_window->SetLayoutManager(root_window_layout_);
[email protected]756bda12013-07-03 08:17:06746
747 aura::Window* default_container =
748 GetContainer(kShellWindowId_DefaultContainer);
749 // Workspace manager has its own layout managers.
750 workspace_controller_.reset(
751 new WorkspaceController(default_container));
752
753 aura::Window* always_on_top_container =
754 GetContainer(kShellWindowId_AlwaysOnTopContainer);
755 always_on_top_container->SetLayoutManager(
[email protected]093b8d642014-04-03 20:59:28756 new WorkspaceLayoutManager(always_on_top_container));
757 always_on_top_controller_.reset(new AlwaysOnTopController);
[email protected]756bda12013-07-03 08:17:06758 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
759
760 DCHECK(!shelf_.get());
[email protected]093b8d642014-04-03 20:59:28761 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
[email protected]756bda12013-07-03 08:17:06762 // TODO(harrym): Remove when status area is view.
[email protected]093b8d642014-04-03 20:59:28763 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
[email protected]756bda12013-07-03 08:17:06764 shelf_.reset(new ShelfWidget(
765 shelf_container, status_container, workspace_controller()));
766
[email protected]cf6fea22013-08-07 14:24:01767 if (!Shell::GetInstance()->session_state_delegate()->
768 IsActiveUserSessionStarted()) {
769 // This window exists only to be a event target on login screen.
770 // It does not have to handle events, nor be visible.
771 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
[email protected]52b02a72014-01-08 21:41:50772 mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]cf6fea22013-08-07 14:24:01773
774 aura::Window* lock_background_container =
[email protected]093b8d642014-04-03 20:59:28775 GetContainer(kShellWindowId_LockScreenBackgroundContainer);
[email protected]cf6fea22013-08-07 14:24:01776 lock_background_container->AddChild(mouse_event_target_.get());
777 mouse_event_target_->Show();
778 }
779
[email protected]756bda12013-07-03 08:17:06780 // Create Docked windows layout manager
[email protected]093b8d642014-04-03 20:59:28781 aura::Window* docked_container = GetContainer(kShellWindowId_DockedContainer);
[email protected]756bda12013-07-03 08:17:06782 docked_layout_manager_ =
[email protected]093b8d642014-04-03 20:59:28783 new DockedWindowLayoutManager(docked_container, workspace_controller());
[email protected]756bda12013-07-03 08:17:06784 docked_container->SetLayoutManager(docked_layout_manager_);
785
786 // Create Panel layout manager
[email protected]093b8d642014-04-03 20:59:28787 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
788 panel_layout_manager_ = new PanelLayoutManager(panel_container);
[email protected]756bda12013-07-03 08:17:06789 panel_container->SetLayoutManager(panel_layout_manager_);
[email protected]3537d472014-01-15 05:45:31790 panel_container_handler_.reset(new PanelWindowEventHandler);
791 panel_container->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39792
793 // Install an AttachedPanelWindowTargeter on the panel container to make it
794 // easier to correctly target shelf buttons with touch.
795 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize,
796 -kResizeOutsideBoundsSize,
797 -kResizeOutsideBoundsSize,
798 -kResizeOutsideBoundsSize);
799 gfx::Insets touch_extend = mouse_extend.Scale(
800 kResizeOutsideBoundsScaleForTouch);
801 panel_container->SetEventTargeter(scoped_ptr<ui::EventTargeter>(
802 new AttachedPanelWindowTargeter(panel_container,
803 mouse_extend,
804 touch_extend,
805 panel_layout_manager_)));
[email protected]756bda12013-07-03 08:17:06806}
807
808void RootWindowController::InitTouchHuds() {
809 CommandLine* command_line = CommandLine::ForCurrentProcess();
810 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45811 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06812 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
813 EnableTouchHudProjection();
814}
815
816void RootWindowController::CreateSystemBackground(
817 bool is_first_run_after_boot) {
818 SkColor color = SK_ColorBLACK;
819#if defined(OS_CHROMEOS)
820 if (is_first_run_after_boot)
821 color = kChromeOsBootColor;
822#endif
823 system_background_.reset(
[email protected]f5c9dbc2014-04-11 08:13:45824 new SystemBackgroundController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06825
826#if defined(OS_CHROMEOS)
827 // Make a copy of the system's boot splash screen so we can composite it
828 // onscreen until the desktop background is ready.
829 if (is_first_run_after_boot &&
830 (CommandLine::ForCurrentProcess()->HasSwitch(
831 switches::kAshCopyHostBackgroundAtBoot) ||
832 CommandLine::ForCurrentProcess()->HasSwitch(
833 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45834 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06835#endif
836}
837
[email protected]a4cd6d32012-09-12 03:42:13838void RootWindowController::CreateContainersInRootWindow(
[email protected]41baaed2013-11-09 04:18:26839 aura::Window* root_window) {
[email protected]a4cd6d32012-09-12 03:42:13840 // These containers are just used by PowerButtonController to animate groups
841 // of containers simultaneously without messing up the current transformations
842 // on those containers. These are direct children of the root window; all of
843 // the other containers are their children.
[email protected]e6e41d2f2012-10-29 19:22:19844
845 // The desktop background container is not part of the lock animation, so it
846 // is not included in those animate groups.
[email protected]a4cd6d32012-09-12 03:42:13847 // When screen is locked desktop background is moved to lock screen background
848 // container (moved back on unlock). We want to make sure that there's an
849 // opaque layer occluding the non-lock-screen layers.
[email protected]e6e41d2f2012-10-29 19:22:19850 aura::Window* desktop_background_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27851 kShellWindowId_DesktopBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13852 "DesktopBackgroundContainer",
853 root_window);
[email protected]e319c7e2014-03-14 19:56:14854 ::wm::SetChildWindowVisibilityChangesAnimated(desktop_background_container);
[email protected]a4cd6d32012-09-12 03:42:13855
856 aura::Window* non_lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27857 kShellWindowId_NonLockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13858 "NonLockScreenContainersContainer",
859 root_window);
860
861 aura::Window* lock_background_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27862 kShellWindowId_LockScreenBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13863 "LockScreenBackgroundContainer",
864 root_window);
[email protected]e319c7e2014-03-14 19:56:14865 ::wm::SetChildWindowVisibilityChangesAnimated(lock_background_containers);
[email protected]a4cd6d32012-09-12 03:42:13866
867 aura::Window* lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27868 kShellWindowId_LockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13869 "LockScreenContainersContainer",
870 root_window);
871 aura::Window* lock_screen_related_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27872 kShellWindowId_LockScreenRelatedContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13873 "LockScreenRelatedContainersContainer",
874 root_window);
875
[email protected]c0ce80e2012-10-05 23:28:27876 CreateContainer(kShellWindowId_UnparentedControlContainer,
[email protected]a4cd6d32012-09-12 03:42:13877 "UnparentedControlContainer",
878 non_lock_screen_containers);
879
880 aura::Window* default_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27881 kShellWindowId_DefaultContainer,
[email protected]a4cd6d32012-09-12 03:42:13882 "DefaultContainer",
883 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14884 ::wm::SetChildWindowVisibilityChangesAnimated(default_container);
[email protected]a4cd6d32012-09-12 03:42:13885 SetUsesScreenCoordinates(default_container);
[email protected]c5be8d672014-01-07 13:33:41886 SetUsesEasyResizeTargeter(default_container);
[email protected]a4cd6d32012-09-12 03:42:13887
888 aura::Window* always_on_top_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27889 kShellWindowId_AlwaysOnTopContainer,
[email protected]a4cd6d32012-09-12 03:42:13890 "AlwaysOnTopContainer",
891 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14892 ::wm::SetChildWindowVisibilityChangesAnimated(always_on_top_container);
[email protected]a4cd6d32012-09-12 03:42:13893 SetUsesScreenCoordinates(always_on_top_container);
894
[email protected]beb4e5c2013-06-18 15:37:07895 aura::Window* docked_container = CreateContainer(
896 kShellWindowId_DockedContainer,
897 "DockedContainer",
898 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14899 ::wm::SetChildWindowVisibilityChangesAnimated(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07900 SetUsesScreenCoordinates(docked_container);
[email protected]1ff0c492014-01-21 20:20:44901 SetUsesEasyResizeTargeter(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07902
[email protected]3f13cf12013-07-12 05:13:59903 aura::Window* shelf_container =
[email protected]478c6c32013-03-09 02:50:58904 CreateContainer(kShellWindowId_ShelfContainer,
[email protected]3f13cf12013-07-12 05:13:59905 "ShelfContainer",
[email protected]a4cd6d32012-09-12 03:42:13906 non_lock_screen_containers);
[email protected]3f13cf12013-07-12 05:13:59907 SetUsesScreenCoordinates(shelf_container);
908 DescendantShouldStayInSameRootWindow(shelf_container);
[email protected]a4cd6d32012-09-12 03:42:13909
[email protected]f2026eb2013-10-22 14:28:56910 aura::Window* panel_container = CreateContainer(
911 kShellWindowId_PanelContainer,
912 "PanelContainer",
913 non_lock_screen_containers);
914 SetUsesScreenCoordinates(panel_container);
915
916 aura::Window* shelf_bubble_container =
917 CreateContainer(kShellWindowId_ShelfBubbleContainer,
918 "ShelfBubbleContainer",
919 non_lock_screen_containers);
920 SetUsesScreenCoordinates(shelf_bubble_container);
921 DescendantShouldStayInSameRootWindow(shelf_bubble_container);
922
[email protected]dc851a4e52012-10-03 00:05:55923 aura::Window* app_list_container =
[email protected]c0ce80e2012-10-05 23:28:27924 CreateContainer(kShellWindowId_AppListContainer,
[email protected]dc851a4e52012-10-03 00:05:55925 "AppListContainer",
926 non_lock_screen_containers);
927 SetUsesScreenCoordinates(app_list_container);
[email protected]a4cd6d32012-09-12 03:42:13928
929 aura::Window* modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27930 kShellWindowId_SystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13931 "SystemModalContainer",
932 non_lock_screen_containers);
[email protected]a4cd6d32012-09-12 03:42:13933 modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27934 new SystemModalContainerLayoutManager(modal_container));
[email protected]e319c7e2014-03-14 19:56:14935 ::wm::SetChildWindowVisibilityChangesAnimated(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13936 SetUsesScreenCoordinates(modal_container);
[email protected]c5be8d672014-01-07 13:33:41937 SetUsesEasyResizeTargeter(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13938
939 aura::Window* input_method_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27940 kShellWindowId_InputMethodContainer,
[email protected]a4cd6d32012-09-12 03:42:13941 "InputMethodContainer",
942 non_lock_screen_containers);
[email protected]e319c7e2014-03-14 19:56:14943 ::wm::SetChildWindowVisibilityChangesAnimated(input_method_container);
[email protected]a4cd6d32012-09-12 03:42:13944 SetUsesScreenCoordinates(input_method_container);
945
946 // TODO(beng): Figure out if we can make this use
947 // SystemModalContainerEventFilter instead of stops_event_propagation.
948 aura::Window* lock_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27949 kShellWindowId_LockScreenContainer,
[email protected]a4cd6d32012-09-12 03:42:13950 "LockScreenContainer",
951 lock_screen_containers);
[email protected]093b8d642014-04-03 20:59:28952 lock_container->SetLayoutManager(new WorkspaceLayoutManager(lock_container));
[email protected]a4cd6d32012-09-12 03:42:13953 SetUsesScreenCoordinates(lock_container);
954 // TODO(beng): stopsevents
955
956 aura::Window* lock_modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27957 kShellWindowId_LockSystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13958 "LockSystemModalContainer",
959 lock_screen_containers);
[email protected]a4cd6d32012-09-12 03:42:13960 lock_modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27961 new SystemModalContainerLayoutManager(lock_modal_container));
[email protected]e319c7e2014-03-14 19:56:14962 ::wm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13963 SetUsesScreenCoordinates(lock_modal_container);
[email protected]c5be8d672014-01-07 13:33:41964 SetUsesEasyResizeTargeter(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13965
966 aura::Window* status_container =
[email protected]c0ce80e2012-10-05 23:28:27967 CreateContainer(kShellWindowId_StatusContainer,
[email protected]a4cd6d32012-09-12 03:42:13968 "StatusContainer",
969 lock_screen_related_containers);
970 SetUsesScreenCoordinates(status_container);
[email protected]e887c6c2013-07-08 19:35:53971 DescendantShouldStayInSameRootWindow(status_container);
[email protected]a4cd6d32012-09-12 03:42:13972
973 aura::Window* settings_bubble_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27974 kShellWindowId_SettingBubbleContainer,
[email protected]a4cd6d32012-09-12 03:42:13975 "SettingBubbleContainer",
976 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:14977 ::wm::SetChildWindowVisibilityChangesAnimated(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:13978 SetUsesScreenCoordinates(settings_bubble_container);
[email protected]e887c6c2013-07-08 19:35:53979 DescendantShouldStayInSameRootWindow(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:13980
981 aura::Window* menu_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27982 kShellWindowId_MenuContainer,
[email protected]a4cd6d32012-09-12 03:42:13983 "MenuContainer",
984 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:14985 ::wm::SetChildWindowVisibilityChangesAnimated(menu_container);
[email protected]a4cd6d32012-09-12 03:42:13986 SetUsesScreenCoordinates(menu_container);
987
988 aura::Window* drag_drop_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27989 kShellWindowId_DragImageAndTooltipContainer,
[email protected]a4cd6d32012-09-12 03:42:13990 "DragImageAndTooltipContainer",
991 lock_screen_related_containers);
[email protected]e319c7e2014-03-14 19:56:14992 ::wm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
[email protected]a4cd6d32012-09-12 03:42:13993 SetUsesScreenCoordinates(drag_drop_container);
994
995 aura::Window* overlay_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27996 kShellWindowId_OverlayContainer,
[email protected]a4cd6d32012-09-12 03:42:13997 "OverlayContainer",
998 lock_screen_related_containers);
999 SetUsesScreenCoordinates(overlay_container);
[email protected]a07615f2012-10-24 08:23:081000
[email protected]b2da9b602014-03-05 18:39:521001 aura::Window* virtual_keyboard_parent_container = CreateContainer(
1002 kShellWindowId_VirtualKeyboardParentContainer,
1003 "VirtualKeyboardParentContainer",
1004 root_window);
1005 SetUsesScreenCoordinates(virtual_keyboard_parent_container);
1006
1007#if defined(OS_CHROMEOS)
1008 aura::Window* mouse_cursor_container = CreateContainer(
1009 kShellWindowId_MouseCursorContainer,
1010 "MouseCursorContainer",
1011 root_window);
1012 SetUsesScreenCoordinates(mouse_cursor_container);
1013#endif
1014
[email protected]a07615f2012-10-24 08:23:081015 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
[email protected]b2da9b602014-03-05 18:39:521016 "PowerButtonAnimationContainer", root_window);
[email protected]a4cd6d32012-09-12 03:42:131017}
1018
[email protected]d141b922013-07-09 08:13:171019void RootWindowController::EnableTouchHudProjection() {
1020 if (touch_hud_projection_)
1021 return;
[email protected]f5c9dbc2014-04-11 08:13:451022 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:171023}
1024
1025void RootWindowController::DisableTouchHudProjection() {
1026 if (!touch_hud_projection_)
1027 return;
1028 touch_hud_projection_->Remove();
1029}
1030
1031void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
1032 shelf_->shelf_layout_manager()->UpdateVisibilityState();
1033}
1034
1035void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
1036 if (enabled)
1037 EnableTouchHudProjection();
1038 else
1039 DisableTouchHudProjection();
1040}
1041
[email protected]6b2d4a0b2013-09-06 06:29:541042RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:451043 const aura::Window* root_window) {
[email protected]6b2d4a0b2013-09-06 06:29:541044 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
1045}
1046
[email protected]d90b8392012-06-13 09:34:561047} // namespace ash