blob: 0ba6a202c9077ff7364114e2511527acbec5c777 [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]f8e6aad2013-08-30 21:49:1118#include "ash/root_window_settings.h"
[email protected]fcb123d2013-04-17 15:58:4919#include "ash/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:5820#include "ash/shelf/shelf_layout_manager.h"
21#include "ash/shelf/shelf_types.h"
22#include "ash/shelf/shelf_widget.h"
[email protected]d90b8392012-06-13 09:34:5623#include "ash/shell.h"
[email protected]e74aaf0a2012-10-12 18:42:2824#include "ash/shell_delegate.h"
[email protected]d90b8392012-06-13 09:34:5625#include "ash/shell_factory.h"
26#include "ash/shell_window_ids.h"
[email protected]2c5db9e2014-02-27 13:58:1427#include "ash/switchable_windows.h"
[email protected]e74aaf0a2012-10-12 18:42:2828#include "ash/system/status_area_widget.h"
[email protected]8674b312012-10-12 19:02:4429#include "ash/system/tray/system_tray_delegate.h"
[email protected]2b8a9bb2013-07-01 22:43:4030#include "ash/touch/touch_hud_debug.h"
31#include "ash/touch/touch_hud_projection.h"
[email protected]80549c152013-07-02 01:42:4732#include "ash/touch/touch_observer_hud.h"
33#include "ash/wm/always_on_top_controller.h"
[email protected]beb4e5c2013-06-18 15:37:0734#include "ash/wm/dock/docked_window_layout_manager.h"
[email protected]7095a652013-03-07 19:41:4935#include "ash/wm/panels/panel_layout_manager.h"
[email protected]100659412013-06-21 22:59:5536#include "ash/wm/panels/panel_window_event_handler.h"
[email protected]d90b8392012-06-13 09:34:5637#include "ash/wm/root_window_layout_manager.h"
38#include "ash/wm/screen_dimmer.h"
[email protected]2a2caa02013-01-22 20:50:3639#include "ash/wm/stacking_controller.h"
[email protected]e74aaf0a2012-10-12 18:42:2840#include "ash/wm/status_area_layout_manager.h"
[email protected]e6e41d2f2012-10-29 19:22:1941#include "ash/wm/system_background_controller.h"
[email protected]d90b8392012-06-13 09:34:5642#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]8d625fb2012-07-18 16:40:0643#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3444#include "ash/wm/window_state.h"
[email protected]700849f2013-04-30 17:49:2045#include "ash/wm/window_util.h"
[email protected]1af71f72014-01-29 20:00:5546#include "ash/wm/workspace/workspace_layout_manager.h"
[email protected]d90b8392012-06-13 09:34:5647#include "ash/wm/workspace_controller.h"
[email protected]e6e41d2f2012-10-29 19:22:1948#include "base/command_line.h"
[email protected]1e84c632013-06-27 23:12:2149#include "base/time/time.h"
[email protected]f1853122012-06-27 16:21:2650#include "ui/aura/client/aura_constants.h"
[email protected]8b3e3d82013-08-20 14:36:3051#include "ui/aura/client/drag_drop_client.h"
[email protected]2374d1812014-03-04 03:42:2752#include "ui/aura/client/screen_position_client.h"
[email protected]d90b8392012-06-13 09:34:5653#include "ui/aura/client/tooltip_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"
69#include "ui/wm/core/visibility_controller.h"
70#include "ui/wm/core/window_util.h"
[email protected]c5be8d672014-01-07 13:33:4171#include "ui/wm/public/easy_resize_window_targeter.h"
[email protected]5b251f12013-12-19 01:50:0572#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5673
[email protected]252eb232013-08-14 22:09:2774#if defined(OS_CHROMEOS)
75#include "ash/wm/boot_splash_screen_chromeos.h"
76#endif
77
[email protected]d90b8392012-06-13 09:34:5678namespace ash {
79namespace {
80
[email protected]252eb232013-08-14 22:09:2781#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:4982// Duration for the animation that hides the boot splash screen, in
83// milliseconds. This should be short enough in relation to
84// wm/window_animation.cc's brightness/grayscale fade animation that the login
85// background image animation isn't hidden by the splash screen animation.
86const int kBootSplashScreenHideDurationMs = 500;
[email protected]252eb232013-08-14 22:09:2787#endif
[email protected]bca9a7e2012-11-10 06:25:4988
[email protected]d90b8392012-06-13 09:34:5689// Creates a new window for use as a container.
90aura::Window* CreateContainer(int window_id,
91 const char* name,
92 aura::Window* parent) {
93 aura::Window* container = new aura::Window(NULL);
94 container->set_id(window_id);
95 container->SetName(name);
[email protected]52b02a72014-01-08 21:41:5096 container->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]d90b8392012-06-13 09:34:5697 parent->AddChild(container);
98 if (window_id != internal::kShellWindowId_UnparentedControlContainer)
99 container->Show();
100 return container;
101}
102
[email protected]2816c2462013-12-17 02:22:25103float ToRelativeValue(int value, int src, int dst) {
104 return static_cast<float>(value) / static_cast<float>(src) * dst;
105}
106
107void MoveOriginRelativeToSize(const gfx::Size& src_size,
108 const gfx::Size& dst_size,
109 gfx::Rect* bounds_in_out) {
110 gfx::Point origin = bounds_in_out->origin();
111 bounds_in_out->set_origin(gfx::Point(
112 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
113 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
114}
115
[email protected]95058572012-08-20 14:57:29116// Reparents |window| to |new_parent|.
117void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
[email protected]2816c2462013-12-17 02:22:25118 const gfx::Size src_size = window->parent()->bounds().size();
119 const gfx::Size dst_size = new_parent->bounds().size();
[email protected]95058572012-08-20 14:57:29120 // Update the restore bounds to make it relative to the display.
[email protected]a41b4e12013-09-20 04:36:34121 wm::WindowState* state = wm::GetWindowState(window);
122 gfx::Rect restore_bounds;
123 bool has_restore_bounds = state->HasRestoreBounds();
[email protected]2816c2462013-12-17 02:22:25124
[email protected]9cfd3d12014-02-25 15:33:45125 bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) &&
[email protected]8663b7a62014-01-18 01:24:21126 new_parent->id() != internal::kShellWindowId_DockedContainer;
[email protected]2816c2462013-12-17 02:22:25127 gfx::Rect local_bounds;
128 if (update_bounds) {
129 local_bounds = state->window()->bounds();
130 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
131 }
132
133 if (has_restore_bounds) {
[email protected]a41b4e12013-09-20 04:36:34134 restore_bounds = state->GetRestoreBoundsInParent();
[email protected]2816c2462013-12-17 02:22:25135 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
136 }
137
[email protected]95058572012-08-20 14:57:29138 new_parent->AddChild(window);
[email protected]2816c2462013-12-17 02:22:25139
[email protected]8663b7a62014-01-18 01:24:21140 // Docked windows have bounds handled by the layout manager in AddChild().
[email protected]2816c2462013-12-17 02:22:25141 if (update_bounds)
142 window->SetBounds(local_bounds);
143
[email protected]a41b4e12013-09-20 04:36:34144 if (has_restore_bounds)
145 state->SetRestoreBoundsInParent(restore_bounds);
[email protected]95058572012-08-20 14:57:29146}
147
148// Reparents the appropriate set of windows from |src| to |dst|.
[email protected]bf9cdb362013-10-25 19:22:45149void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
[email protected]95058572012-08-20 14:57:29150 // Set of windows to move.
[email protected]f1853122012-06-27 16:21:26151 const int kContainerIdsToMove[] = {
152 internal::kShellWindowId_DefaultContainer,
[email protected]beb4e5c2013-06-18 15:37:07153 internal::kShellWindowId_DockedContainer,
[email protected]95db9c12013-01-31 11:47:44154 internal::kShellWindowId_PanelContainer,
[email protected]f1853122012-06-27 16:21:26155 internal::kShellWindowId_AlwaysOnTopContainer,
156 internal::kShellWindowId_SystemModalContainer,
157 internal::kShellWindowId_LockSystemModalContainer,
[email protected]6274d312012-10-04 22:06:41158 internal::kShellWindowId_InputMethodContainer,
[email protected]a9754872013-01-25 07:44:00159 internal::kShellWindowId_UnparentedControlContainer,
[email protected]f1853122012-06-27 16:21:26160 };
[email protected]f1853122012-06-27 16:21:26161 for (size_t i = 0; i < arraysize(kContainerIdsToMove); i++) {
162 int id = kContainerIdsToMove[i];
163 aura::Window* src_container = Shell::GetContainer(src, id);
164 aura::Window* dst_container = Shell::GetContainer(dst, id);
[email protected]5b6021902013-02-26 05:33:29165 while (!src_container->children().empty()) {
166 // Restart iteration from the source container windows each time as they
167 // may change as a result of moving other windows.
168 aura::Window::Windows::const_iterator iter =
169 src_container->children().begin();
170 while (iter != src_container->children().end() &&
171 internal::SystemModalContainerLayoutManager::IsModalBackground(
172 *iter)) {
173 ++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) {
186 container->SetProperty(internal::kUsesScreenCoordinatesKey, true);
187}
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) {
192 container->SetProperty(internal::kStayInSameRootWindowKey, true);
193}
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 }
224 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE {
225 return gfx::kNullCursor;
226 }
227 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]1ddbe932013-09-12 06:23:16256 virtual void DidRecreateLayer(ui::Layer* old_layer,
257 ui::Layer* new_layer) OVERRIDE {}
[email protected]cf6fea22013-08-07 14:24:01258
259 private:
260 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
261};
262
[email protected]d90b8392012-06-13 09:34:56263} // namespace
264
265namespace internal {
266
[email protected]2f2620332014-02-28 10:07:38267void RootWindowController::CreateForPrimaryDisplay(aura::WindowTreeHost* host) {
268 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]056ce052014-02-21 05:19:32273void RootWindowController::CreateForSecondaryDisplay(
[email protected]2f2620332014-02-28 10:07:38274 aura::WindowTreeHost* host) {
275 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28276 controller->Init(RootWindowController::SECONDARY, false /* first run */);
277}
278
279void RootWindowController::CreateForVirtualKeyboardDisplay(
[email protected]2f2620332014-02-28 10:07:38280 aura::WindowTreeHost* host) {
281 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28282 controller->Init(RootWindowController::VIRTUAL_KEYBOARD,
283 false /* first run */);
[email protected]6675e1c2012-09-11 09:15:45284}
285
[email protected]88d71122012-10-18 07:11:01286// static
[email protected]864b58552013-12-19 04:19:38287RootWindowController* RootWindowController::ForShelf(aura::Window* window) {
[email protected]8c0ec432013-05-10 04:33:39288 return GetRootWindowController(window->GetRootWindow());
[email protected]88d71122012-10-18 07:11:01289}
290
[email protected]a0afeb12012-12-10 22:57:09291// static
[email protected]ccff3d72013-02-06 04:26:28292RootWindowController* RootWindowController::ForWindow(
293 const aura::Window* window) {
[email protected]a0afeb12012-12-10 22:57:09294 return GetRootWindowController(window->GetRootWindow());
295}
296
297// static
[email protected]d17642d2013-09-12 23:44:38298RootWindowController* RootWindowController::ForTargetRootWindow() {
299 return internal::GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09300}
301
[email protected]a5c78802013-12-12 22:07:01302// static
303aura::Window* RootWindowController::GetContainerForWindow(
304 aura::Window* window) {
305 aura::Window* container = window->parent();
[email protected]5b251f12013-12-19 01:50:05306 while (container && container->type() != ui::wm::WINDOW_TYPE_UNKNOWN)
[email protected]a5c78802013-12-12 22:07:01307 container = container->parent();
308 return container;
309}
310
[email protected]a273d33a2013-10-17 12:41:21311RootWindowController::~RootWindowController() {
312 Shutdown();
[email protected]2f2620332014-02-28 10:07:38313 host_.reset();
[email protected]a273d33a2013-10-17 12:41:21314 // The CaptureClient needs to be around for as long as the RootWindow is
315 // valid.
316 capture_client_.reset();
317}
318
[email protected]0bf61732013-07-02 04:35:10319void RootWindowController::SetWallpaperController(
320 DesktopBackgroundWidgetController* controller) {
321 wallpaper_controller_.reset(controller);
322}
323
324void RootWindowController::SetAnimatingWallpaperController(
325 AnimatingDesktopController* controller) {
326 if (animating_wallpaper_controller_.get())
327 animating_wallpaper_controller_->StopAnimating();
328 animating_wallpaper_controller_.reset(controller);
329}
330
[email protected]6675e1c2012-09-11 09:15:45331void RootWindowController::Shutdown() {
[email protected]d141b922013-07-09 08:13:17332 Shell::GetInstance()->RemoveShellObserver(this);
333
[email protected]0bf61732013-07-02 04:35:10334 if (animating_wallpaper_controller_.get())
335 animating_wallpaper_controller_->StopAnimating();
336 wallpaper_controller_.reset();
337 animating_wallpaper_controller_.reset();
338
[email protected]d17642d2013-09-12 23:44:38339 // Change the target root window before closing child windows. If any child
[email protected]c98a4922013-09-05 20:01:42340 // being removed triggers a relayout of the shelf it will try to build a
[email protected]d17642d2013-09-12 23:44:38341 // window list adding windows from the target root window's containers which
[email protected]c98a4922013-09-05 20:01:42342 // may have already gone away.
[email protected]41baaed2013-11-09 04:18:26343 if (Shell::GetTargetRootWindow() == root_window()) {
[email protected]d17642d2013-09-12 23:44:38344 Shell::GetInstance()->set_target_root_window(
[email protected]41baaed2013-11-09 04:18:26345 Shell::GetPrimaryRootWindow() == root_window() ?
[email protected]f634dd32012-07-23 22:49:07346 NULL : Shell::GetPrimaryRootWindow());
347 }
[email protected]c98a4922013-09-05 20:01:42348
349 CloseChildWindows();
[email protected]41baaed2013-11-09 04:18:26350 GetRootWindowSettings(root_window())->controller = NULL;
[email protected]d90b8392012-06-13 09:34:56351 screen_dimmer_.reset();
352 workspace_controller_.reset();
[email protected]6675e1c2012-09-11 09:15:45353 // Forget with the display ID so that display lookup
354 // ends up with invalid display.
[email protected]41baaed2013-11-09 04:18:26355 internal::GetRootWindowSettings(root_window())->display_id =
[email protected]f8e6aad2013-08-30 21:49:11356 gfx::Display::kInvalidDisplayID;
[email protected]6675e1c2012-09-11 09:15:45357 // And this root window should no longer process events.
[email protected]2d6eb742014-03-05 18:59:03358 host()->dispatcher()->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28359
[email protected]956a6a42012-10-29 23:58:10360 system_background_.reset();
[email protected]2374d1812014-03-04 03:42:27361 aura::client::SetScreenPositionClient(root_window(), NULL);
[email protected]d90b8392012-06-13 09:34:56362}
363
[email protected]c0ce80e2012-10-05 23:28:27364SystemModalContainerLayoutManager*
[email protected]8674b312012-10-12 19:02:44365RootWindowController::GetSystemModalLayoutManager(aura::Window* window) {
[email protected]a5c78802013-12-12 22:07:01366 aura::Window* modal_container = NULL;
[email protected]8674b312012-10-12 19:02:44367 if (window) {
[email protected]a5c78802013-12-12 22:07:01368 aura::Window* window_container = GetContainerForWindow(window);
369 if (window_container &&
370 window_container->id() >= kShellWindowId_LockScreenContainer) {
371 modal_container = GetContainer(kShellWindowId_LockSystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35372 } else {
[email protected]a5c78802013-12-12 22:07:01373 modal_container = GetContainer(kShellWindowId_SystemModalContainer);
[email protected]3b162e12012-11-09 11:52:35374 }
[email protected]8674b312012-10-12 19:02:44375 } else {
[email protected]a44afbbd2013-07-24 21:49:35376 int modal_window_id = Shell::GetInstance()->session_state_delegate()
377 ->IsUserSessionBlocked() ? kShellWindowId_LockSystemModalContainer :
378 kShellWindowId_SystemModalContainer;
[email protected]a5c78802013-12-12 22:07:01379 modal_container = GetContainer(modal_window_id);
[email protected]8674b312012-10-12 19:02:44380 }
[email protected]a5c78802013-12-12 22:07:01381 return modal_container ? static_cast<SystemModalContainerLayoutManager*>(
382 modal_container->layout_manager()) : NULL;
[email protected]c0ce80e2012-10-05 23:28:27383}
384
[email protected]d90b8392012-06-13 09:34:56385aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]41baaed2013-11-09 04:18:26386 return root_window()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56387}
388
[email protected]d8a24952013-08-05 20:05:05389const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]2f2620332014-02-28 10:07:38390 return host_->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05391}
392
[email protected]864b58552013-12-19 04:19:38393void RootWindowController::ShowShelf() {
394 if (!shelf_->shelf())
[email protected]e74aaf0a2012-10-12 18:42:28395 return;
[email protected]864b58552013-12-19 04:19:38396 shelf_->shelf()->SetVisible(true);
[email protected]478c6c32013-03-09 02:50:58397 shelf_->status_area_widget()->Show();
[email protected]e74aaf0a2012-10-12 18:42:28398}
399
[email protected]864b58552013-12-19 04:19:38400void RootWindowController::OnShelfCreated() {
[email protected]756bda12013-07-03 08:17:06401 if (panel_layout_manager_)
[email protected]864b58552013-12-19 04:19:38402 panel_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39403 if (docked_layout_manager_) {
[email protected]864b58552013-12-19 04:19:38404 docked_layout_manager_->SetShelf(shelf_->shelf());
[email protected]7115bd32013-07-19 08:25:39405 if (shelf_->shelf_layout_manager())
406 docked_layout_manager_->AddObserver(shelf_->shelf_layout_manager());
407 }
[email protected]756bda12013-07-03 08:17:06408}
409
[email protected]16059276d2012-10-22 18:59:50410void RootWindowController::UpdateAfterLoginStatusChange(
411 user::LoginStatus status) {
[email protected]cf6fea22013-08-07 14:24:01412 if (status != user::LOGGED_IN_NONE)
413 mouse_event_target_.reset();
[email protected]80549c152013-07-02 01:42:47414 if (shelf_->status_area_widget())
[email protected]478c6c32013-03-09 02:50:58415 shelf_->status_area_widget()->UpdateAfterLoginStatusChange(status);
[email protected]16059276d2012-10-22 18:59:50416}
417
[email protected]bca9a7e2012-11-10 06:25:49418void RootWindowController::HandleInitialDesktopBackgroundAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27419#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49420 if (CommandLine::ForCurrentProcess()->HasSwitch(
421 switches::kAshAnimateFromBootSplashScreen) &&
422 boot_splash_screen_.get()) {
423 // Make the splash screen fade out so it doesn't obscure the desktop
424 // wallpaper's brightness/grayscale animation.
425 boot_splash_screen_->StartHideAnimation(
426 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
427 }
[email protected]252eb232013-08-14 22:09:27428#endif
[email protected]bca9a7e2012-11-10 06:25:49429}
430
[email protected]0bf61732013-07-02 04:35:10431void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
432 // Make sure the wallpaper is visible.
[email protected]bca9a7e2012-11-10 06:25:49433 system_background_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27434#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49435 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27436#endif
[email protected]0bf61732013-07-02 04:35:10437
438 Shell::GetInstance()->user_wallpaper_delegate()->
439 OnWallpaperAnimationFinished();
440 // Only removes old component when wallpaper animation finished. If we
441 // remove the old one before the new wallpaper is done fading in there will
442 // be a white flash during the animation.
443 if (animating_wallpaper_controller()) {
444 DesktopBackgroundWidgetController* controller =
445 animating_wallpaper_controller()->GetController(true);
446 // |desktop_widget_| should be the same animating widget we try to move
447 // to |kDesktopController|. Otherwise, we may close |desktop_widget_|
448 // before move it to |kDesktopController|.
449 DCHECK_EQ(controller->widget(), widget);
450 // Release the old controller and close its background widget.
451 SetWallpaperController(controller);
452 }
[email protected]697f04c2012-10-03 01:15:10453}
454
[email protected]d90b8392012-06-13 09:34:56455void RootWindowController::CloseChildWindows() {
[email protected]cf6fea22013-08-07 14:24:01456 mouse_event_target_.reset();
457
[email protected]b6ba05d902013-10-04 21:38:45458 // Deactivate keyboard container before closing child windows and shutting
459 // down associated layout managers.
460 DeactivateKeyboard(Shell::GetInstance()->keyboard_controller());
461
[email protected]79a87b7e2013-01-25 05:08:22462 // panel_layout_manager_ needs to be shut down before windows are destroyed.
463 if (panel_layout_manager_) {
464 panel_layout_manager_->Shutdown();
465 panel_layout_manager_ = NULL;
466 }
[email protected]7115bd32013-07-19 08:25:39467 // docked_layout_manager_ needs to be shut down before windows are destroyed.
468 if (docked_layout_manager_) {
[email protected]bb42c932013-10-31 06:52:06469 if (shelf_ && shelf_->shelf_layout_manager())
[email protected]7115bd32013-07-19 08:25:39470 docked_layout_manager_->RemoveObserver(shelf_->shelf_layout_manager());
471 docked_layout_manager_->Shutdown();
472 docked_layout_manager_ = NULL;
473 }
[email protected]79a87b7e2013-01-25 05:08:22474
[email protected]41baaed2013-11-09 04:18:26475 aura::client::SetDragDropClient(root_window(), NULL);
[email protected]8b3e3d82013-08-20 14:36:30476
[email protected]478c6c32013-03-09 02:50:58477 // TODO(harrym): Remove when Status Area Widget is a child view.
[email protected]bb42c932013-10-31 06:52:06478 if (shelf_) {
479 shelf_->ShutdownStatusAreaWidget();
[email protected]478c6c32013-03-09 02:50:58480
[email protected]bb42c932013-10-31 06:52:06481 if (shelf_->shelf_layout_manager())
482 shelf_->shelf_layout_manager()->PrepareForShutdown();
483 }
[email protected]e74aaf0a2012-10-12 18:42:28484
[email protected]d90b8392012-06-13 09:34:56485 // Close background widget first as it depends on tooltip.
[email protected]0bf61732013-07-02 04:35:10486 wallpaper_controller_.reset();
487 animating_wallpaper_controller_.reset();
[email protected]b4ddc7a2012-08-07 04:17:32488
[email protected]d90b8392012-06-13 09:34:56489 workspace_controller_.reset();
[email protected]41baaed2013-11-09 04:18:26490 aura::client::SetTooltipClient(root_window(), NULL);
[email protected]d90b8392012-06-13 09:34:56491
[email protected]0fbfa972013-10-02 19:23:33492 // Explicitly destroy top level windows. We do this as during part of
493 // destruction such windows may query the RootWindow for state.
[email protected]8b3e3d82013-08-20 14:36:30494 std::queue<aura::Window*> non_toplevel_windows;
[email protected]41baaed2013-11-09 04:18:26495 non_toplevel_windows.push(root_window());
[email protected]8b3e3d82013-08-20 14:36:30496 while (!non_toplevel_windows.empty()) {
497 aura::Window* non_toplevel_window = non_toplevel_windows.front();
498 non_toplevel_windows.pop();
499 aura::WindowTracker toplevel_windows;
500 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
501 aura::Window* child = non_toplevel_window->children()[i];
[email protected]0fbfa972013-10-02 19:23:33502 if (!child->owned_by_parent())
503 continue;
[email protected]8b3e3d82013-08-20 14:36:30504 if (child->delegate())
505 toplevel_windows.Add(child);
506 else
507 non_toplevel_windows.push(child);
508 }
509 while (!toplevel_windows.windows().empty())
510 delete *toplevel_windows.windows().begin();
[email protected]d90b8392012-06-13 09:34:56511 }
[email protected]8b3e3d82013-08-20 14:36:30512 // And then remove the containers.
[email protected]41baaed2013-11-09 04:18:26513 while (!root_window()->children().empty()) {
514 aura::Window* window = root_window()->children()[0];
[email protected]0fbfa972013-10-02 19:23:33515 if (window->owned_by_parent()) {
516 delete window;
517 } else {
[email protected]41baaed2013-11-09 04:18:26518 root_window()->RemoveChild(window);
[email protected]0fbfa972013-10-02 19:23:33519 }
520 }
[email protected]478c6c32013-03-09 02:50:58521
[email protected]bb42c932013-10-31 06:52:06522 shelf_.reset();
[email protected]d90b8392012-06-13 09:34:56523}
524
[email protected]bf9cdb362013-10-25 19:22:45525void RootWindowController::MoveWindowsTo(aura::Window* dst) {
[email protected]8039e06c2013-01-17 23:34:50526 // Forget the shelf early so that shelf don't update itself using wrong
527 // display info.
528 workspace_controller_->SetShelf(NULL);
[email protected]41baaed2013-11-09 04:18:26529 ReparentAllWindows(root_window(), dst);
[email protected]f1853122012-06-27 16:21:26530}
531
[email protected]478c6c32013-03-09 02:50:58532ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
[email protected]80549c152013-07-02 01:42:47533 return shelf_->shelf_layout_manager();
[email protected]478c6c32013-03-09 02:50:58534}
535
[email protected]a0afeb12012-12-10 22:57:09536SystemTray* RootWindowController::GetSystemTray() {
537 // We assume in throughout the code that this will not return NULL. If code
538 // triggers this for valid reasons, it should test status_area_widget first.
[email protected]80549c152013-07-02 01:42:47539 CHECK(shelf_->status_area_widget());
[email protected]478c6c32013-03-09 02:50:58540 return shelf_->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09541}
542
[email protected]940fb1c2013-06-18 16:54:28543void RootWindowController::ShowContextMenu(const gfx::Point& location_in_screen,
544 ui::MenuSourceType source_type) {
[email protected]431552c2012-10-23 00:38:33545 DCHECK(Shell::GetInstance()->delegate());
546 scoped_ptr<ui::MenuModel> menu_model(
[email protected]e0cfc7f2014-01-09 20:25:42547 Shell::GetInstance()->delegate()->CreateContextMenu(root_window(),
548 NULL,
549 NULL));
[email protected]7f7f65c2013-04-17 16:47:13550 if (!menu_model)
[email protected]8e837ec2013-01-31 01:48:33551 return;
[email protected]431552c2012-10-23 00:38:33552
[email protected]6175fc42013-04-05 05:58:58553 // Background controller may not be set yet if user clicked on status are
554 // before initial animation completion. See crbug.com/222218
[email protected]0bf61732013-07-02 04:35:10555 if (!wallpaper_controller_.get())
[email protected]431552c2012-10-23 00:38:33556 return;
557
[email protected]6175fc42013-04-05 05:58:58558 views::MenuRunner menu_runner(menu_model.get());
[email protected]0bf61732013-07-02 04:35:10559 if (menu_runner.RunMenuAt(wallpaper_controller_->widget(),
[email protected]6175fc42013-04-05 05:58:58560 NULL, gfx::Rect(location_in_screen, gfx::Size()),
[email protected]940fb1c2013-06-18 16:54:28561 views::MenuItemView::TOPLEFT, source_type,
562 views::MenuRunner::CONTEXT_MENU) ==
[email protected]6175fc42013-04-05 05:58:58563 views::MenuRunner::MENU_DELETED) {
564 return;
565 }
566
[email protected]431552c2012-10-23 00:38:33567 Shell::GetInstance()->UpdateShelfVisibility();
568}
569
[email protected]e74aaf0a2012-10-12 18:42:28570void RootWindowController::UpdateShelfVisibility() {
[email protected]478c6c32013-03-09 02:50:58571 shelf_->shelf_layout_manager()->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28572}
573
[email protected]2c9171d22013-12-10 21:55:10574const aura::Window* RootWindowController::GetWindowForFullscreenMode() const {
[email protected]2c9171d22013-12-10 21:55:10575 const aura::Window* topmost_window = NULL;
[email protected]2c5db9e2014-02-27 13:58:14576 const aura::Window* active_window = wm::GetActiveWindow();
577 if (active_window && active_window->GetRootWindow() == root_window() &&
578 IsSwitchableContainer(active_window->parent())) {
579 // Use the active window when it is on the current root window to determine
580 // the fullscreen state to allow temporarily using a panel or docked window
581 // (which are always above the default container) while a fullscreen
582 // window is open. We only use the active window when in a switchable
583 // container as the launcher should not exit fullscreen mode.
584 topmost_window = active_window;
585 } else {
586 // Otherwise, use the topmost window on the root window's default container
587 // when there is no active window on this root window.
588 const aura::Window::Windows& windows =
589 GetContainer(kShellWindowId_DefaultContainer)->children();
590 for (aura::Window::Windows::const_reverse_iterator iter = windows.rbegin();
591 iter != windows.rend(); ++iter) {
592 if (((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL ||
593 (*iter)->type() == ui::wm::WINDOW_TYPE_PANEL) &&
594 (*iter)->layer()->GetTargetVisibility()) {
595 topmost_window = *iter;
596 break;
597 }
[email protected]2c9171d22013-12-10 21:55:10598 }
599 }
600 while (topmost_window) {
601 if (wm::GetWindowState(topmost_window)->IsFullscreen())
602 return topmost_window;
[email protected]751b13df2014-01-07 19:52:52603 topmost_window = views::corewm::GetTransientParent(topmost_window);
[email protected]2ee2f5d2013-01-10 23:37:16604 }
[email protected]700849f2013-04-30 17:49:20605 return NULL;
[email protected]2ee2f5d2013-01-10 23:37:16606}
607
[email protected]b6ba05d902013-10-04 21:38:45608void RootWindowController::ActivateKeyboard(
609 keyboard::KeyboardController* keyboard_controller) {
610 if (!keyboard::IsKeyboardEnabled() ||
611 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
612 return;
613 }
614 DCHECK(keyboard_controller);
[email protected]51f438112013-11-18 19:32:50615 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
616 keyboard_controller->AddObserver(shelf()->shelf_layout_manager());
617 keyboard_controller->AddObserver(panel_layout_manager_);
618 keyboard_controller->AddObserver(docked_layout_manager_);
619 }
[email protected]b2da9b602014-03-05 18:39:52620 aura::Window* parent = GetContainer(
621 kShellWindowId_VirtualKeyboardParentContainer);
622 DCHECK(parent);
[email protected]b6ba05d902013-10-04 21:38:45623 aura::Window* keyboard_container =
624 keyboard_controller->GetContainerWindow();
625 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
626 parent->AddChild(keyboard_container);
627 // TODO(oshima): Bounds of keyboard container should be handled by
628 // RootWindowLayoutManager. Remove this after fixed RootWindowLayoutManager.
629 keyboard_container->SetBounds(parent->bounds());
630}
[email protected]86459e2c2013-04-10 13:39:24631
[email protected]b6ba05d902013-10-04 21:38:45632void RootWindowController::DeactivateKeyboard(
633 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41634 if (!keyboard_controller ||
635 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45636 return;
[email protected]e1b299b2014-01-29 23:53:41637 }
[email protected]b6ba05d902013-10-04 21:38:45638 aura::Window* keyboard_container =
639 keyboard_controller->GetContainerWindow();
640 if (keyboard_container->GetRootWindow() == root_window()) {
[email protected]b2da9b602014-03-05 18:39:52641 aura::Window* parent = GetContainer(
642 kShellWindowId_VirtualKeyboardParentContainer);
643 DCHECK(parent);
644 parent->RemoveChild(keyboard_container);
[email protected]51f438112013-11-18 19:32:50645 if (!keyboard::IsKeyboardUsabilityExperimentEnabled()) {
[email protected]1025937e2014-02-13 01:25:50646 // Virtual keyboard may be deactivated while still showing, notify all
647 // observers that keyboard bounds changed to 0 before remove them.
648 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
[email protected]51f438112013-11-18 19:32:50649 keyboard_controller->RemoveObserver(shelf()->shelf_layout_manager());
650 keyboard_controller->RemoveObserver(panel_layout_manager_);
651 keyboard_controller->RemoveObserver(docked_layout_manager_);
652 }
[email protected]86459e2c2013-04-10 13:39:24653 }
654}
655
[email protected]a4cd6d32012-09-12 03:42:13656////////////////////////////////////////////////////////////////////////////////
657// RootWindowController, private:
658
[email protected]2f2620332014-02-28 10:07:38659RootWindowController::RootWindowController(aura::WindowTreeHost* host)
660 : host_(host),
[email protected]a273d33a2013-10-17 12:41:21661 root_window_layout_(NULL),
662 docked_layout_manager_(NULL),
663 panel_layout_manager_(NULL),
664 touch_hud_debug_(NULL),
665 touch_hud_projection_(NULL) {
[email protected]2f2620332014-02-28 10:07:38666 GetRootWindowSettings(root_window())->controller = this;
667 screen_dimmer_.reset(new ScreenDimmer(root_window()));
[email protected]a273d33a2013-10-17 12:41:21668
669 stacking_controller_.reset(new StackingController);
[email protected]2f2620332014-02-28 10:07:38670 aura::client::SetWindowTreeClient(root_window(), stacking_controller_.get());
[email protected]41baaed2013-11-09 04:18:26671 capture_client_.reset(
[email protected]2f2620332014-02-28 10:07:38672 new views::corewm::ScopedCaptureClient(root_window()));
[email protected]a273d33a2013-10-17 12:41:21673}
674
[email protected]608de6c2013-10-29 00:14:28675void RootWindowController::Init(RootWindowType root_window_type,
676 bool first_run_after_boot) {
[email protected]51f438112013-11-18 19:32:50677 Shell* shell = Shell::GetInstance();
678 shell->InitRootWindow(root_window());
[email protected]a273d33a2013-10-17 12:41:21679
[email protected]2f2620332014-02-28 10:07:38680 host_->SetCursor(ui::kCursorPointer);
681 CreateContainersInRootWindow(root_window());
[email protected]608de6c2013-10-29 00:14:28682
[email protected]51f438112013-11-18 19:32:50683 if (root_window_type == VIRTUAL_KEYBOARD) {
684 shell->InitKeyboard();
[email protected]608de6c2013-10-29 00:14:28685 return;
[email protected]51f438112013-11-18 19:32:50686 }
[email protected]608de6c2013-10-29 00:14:28687
[email protected]a273d33a2013-10-17 12:41:21688 CreateSystemBackground(first_run_after_boot);
689
690 InitLayoutManagers();
691 InitTouchHuds();
692
693 if (Shell::GetPrimaryRootWindowController()->
694 GetSystemModalLayoutManager(NULL)->has_modal_background()) {
695 GetSystemModalLayoutManager(NULL)->CreateModalBackground();
696 }
697
[email protected]a273d33a2013-10-17 12:41:21698 shell->AddShellObserver(this);
699
[email protected]608de6c2013-10-29 00:14:28700 if (root_window_type == PRIMARY) {
[email protected]a3565792013-10-18 12:52:37701 root_window_layout()->OnWindowResized();
[email protected]51f438112013-11-18 19:32:50702 if (!keyboard::IsKeyboardUsabilityExperimentEnabled())
703 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21704 } else {
705 root_window_layout()->OnWindowResized();
[email protected]41baaed2013-11-09 04:18:26706 shell->desktop_background_controller()->OnRootWindowAdded(root_window());
[email protected]2f2620332014-02-28 10:07:38707 shell->high_contrast_controller()->OnRootWindowAdded(root_window());
708 host_->Show();
[email protected]a273d33a2013-10-17 12:41:21709
[email protected]864b58552013-12-19 04:19:38710 // Create a shelf if a user is already logged in.
[email protected]a273d33a2013-10-17 12:41:21711 if (shell->session_state_delegate()->NumberOfLoggedInUsers())
[email protected]864b58552013-12-19 04:19:38712 shelf()->CreateShelf();
[email protected]a273d33a2013-10-17 12:41:21713 }
714}
715
[email protected]756bda12013-07-03 08:17:06716void RootWindowController::InitLayoutManagers() {
[email protected]41baaed2013-11-09 04:18:26717 root_window_layout_ = new RootWindowLayoutManager(root_window());
718 root_window()->SetLayoutManager(root_window_layout_);
[email protected]756bda12013-07-03 08:17:06719
720 aura::Window* default_container =
721 GetContainer(kShellWindowId_DefaultContainer);
722 // Workspace manager has its own layout managers.
723 workspace_controller_.reset(
724 new WorkspaceController(default_container));
725
726 aura::Window* always_on_top_container =
727 GetContainer(kShellWindowId_AlwaysOnTopContainer);
728 always_on_top_container->SetLayoutManager(
[email protected]1af71f72014-01-29 20:00:55729 new internal::WorkspaceLayoutManager(
730 always_on_top_container));
[email protected]756bda12013-07-03 08:17:06731 always_on_top_controller_.reset(new internal::AlwaysOnTopController);
732 always_on_top_controller_->SetAlwaysOnTopContainer(always_on_top_container);
733
734 DCHECK(!shelf_.get());
735 aura::Window* shelf_container =
736 GetContainer(internal::kShellWindowId_ShelfContainer);
737 // TODO(harrym): Remove when status area is view.
738 aura::Window* status_container =
739 GetContainer(internal::kShellWindowId_StatusContainer);
740 shelf_.reset(new ShelfWidget(
741 shelf_container, status_container, workspace_controller()));
742
[email protected]cf6fea22013-08-07 14:24:01743 if (!Shell::GetInstance()->session_state_delegate()->
744 IsActiveUserSessionStarted()) {
745 // This window exists only to be a event target on login screen.
746 // It does not have to handle events, nor be visible.
747 mouse_event_target_.reset(new aura::Window(new EmptyWindowDelegate));
[email protected]52b02a72014-01-08 21:41:50748 mouse_event_target_->Init(aura::WINDOW_LAYER_NOT_DRAWN);
[email protected]cf6fea22013-08-07 14:24:01749
750 aura::Window* lock_background_container =
751 GetContainer(internal::kShellWindowId_LockScreenBackgroundContainer);
752 lock_background_container->AddChild(mouse_event_target_.get());
753 mouse_event_target_->Show();
754 }
755
[email protected]756bda12013-07-03 08:17:06756 // Create Docked windows layout manager
757 aura::Window* docked_container = GetContainer(
758 internal::kShellWindowId_DockedContainer);
759 docked_layout_manager_ =
[email protected]375069e2013-10-04 13:54:31760 new internal::DockedWindowLayoutManager(docked_container,
761 workspace_controller());
[email protected]756bda12013-07-03 08:17:06762 docked_container->SetLayoutManager(docked_layout_manager_);
763
764 // Create Panel layout manager
765 aura::Window* panel_container = GetContainer(
766 internal::kShellWindowId_PanelContainer);
767 panel_layout_manager_ =
768 new internal::PanelLayoutManager(panel_container);
[email protected]756bda12013-07-03 08:17:06769 panel_container->SetLayoutManager(panel_layout_manager_);
[email protected]3537d472014-01-15 05:45:31770 panel_container_handler_.reset(new PanelWindowEventHandler);
771 panel_container->AddPreTargetHandler(panel_container_handler_.get());
[email protected]756bda12013-07-03 08:17:06772}
773
774void RootWindowController::InitTouchHuds() {
775 CommandLine* command_line = CommandLine::ForCurrentProcess();
776 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]41baaed2013-11-09 04:18:26777 set_touch_hud_debug(new TouchHudDebug(root_window()));
[email protected]756bda12013-07-03 08:17:06778 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
779 EnableTouchHudProjection();
780}
781
782void RootWindowController::CreateSystemBackground(
783 bool is_first_run_after_boot) {
784 SkColor color = SK_ColorBLACK;
785#if defined(OS_CHROMEOS)
786 if (is_first_run_after_boot)
787 color = kChromeOsBootColor;
788#endif
789 system_background_.reset(
[email protected]41baaed2013-11-09 04:18:26790 new SystemBackgroundController(root_window(), color));
[email protected]756bda12013-07-03 08:17:06791
792#if defined(OS_CHROMEOS)
793 // Make a copy of the system's boot splash screen so we can composite it
794 // onscreen until the desktop background is ready.
795 if (is_first_run_after_boot &&
796 (CommandLine::ForCurrentProcess()->HasSwitch(
797 switches::kAshCopyHostBackgroundAtBoot) ||
798 CommandLine::ForCurrentProcess()->HasSwitch(
799 switches::kAshAnimateFromBootSplashScreen)))
[email protected]2d6eb742014-03-05 18:59:03800 boot_splash_screen_.reset(new BootSplashScreen(host()));
[email protected]756bda12013-07-03 08:17:06801#endif
802}
803
[email protected]a4cd6d32012-09-12 03:42:13804void RootWindowController::CreateContainersInRootWindow(
[email protected]41baaed2013-11-09 04:18:26805 aura::Window* root_window) {
[email protected]a4cd6d32012-09-12 03:42:13806 // These containers are just used by PowerButtonController to animate groups
807 // of containers simultaneously without messing up the current transformations
808 // on those containers. These are direct children of the root window; all of
809 // the other containers are their children.
[email protected]e6e41d2f2012-10-29 19:22:19810
811 // The desktop background container is not part of the lock animation, so it
812 // is not included in those animate groups.
[email protected]a4cd6d32012-09-12 03:42:13813 // When screen is locked desktop background is moved to lock screen background
814 // container (moved back on unlock). We want to make sure that there's an
815 // opaque layer occluding the non-lock-screen layers.
[email protected]e6e41d2f2012-10-29 19:22:19816 aura::Window* desktop_background_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27817 kShellWindowId_DesktopBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13818 "DesktopBackgroundContainer",
819 root_window);
[email protected]b5756e22012-11-30 01:32:02820 views::corewm::SetChildWindowVisibilityChangesAnimated(
821 desktop_background_container);
[email protected]a4cd6d32012-09-12 03:42:13822
823 aura::Window* non_lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27824 kShellWindowId_NonLockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13825 "NonLockScreenContainersContainer",
826 root_window);
827
828 aura::Window* lock_background_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27829 kShellWindowId_LockScreenBackgroundContainer,
[email protected]a4cd6d32012-09-12 03:42:13830 "LockScreenBackgroundContainer",
831 root_window);
[email protected]b5756e22012-11-30 01:32:02832 views::corewm::SetChildWindowVisibilityChangesAnimated(
833 lock_background_containers);
[email protected]a4cd6d32012-09-12 03:42:13834
835 aura::Window* lock_screen_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27836 kShellWindowId_LockScreenContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13837 "LockScreenContainersContainer",
838 root_window);
839 aura::Window* lock_screen_related_containers = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27840 kShellWindowId_LockScreenRelatedContainersContainer,
[email protected]a4cd6d32012-09-12 03:42:13841 "LockScreenRelatedContainersContainer",
842 root_window);
843
[email protected]c0ce80e2012-10-05 23:28:27844 CreateContainer(kShellWindowId_UnparentedControlContainer,
[email protected]a4cd6d32012-09-12 03:42:13845 "UnparentedControlContainer",
846 non_lock_screen_containers);
847
848 aura::Window* default_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27849 kShellWindowId_DefaultContainer,
[email protected]a4cd6d32012-09-12 03:42:13850 "DefaultContainer",
851 non_lock_screen_containers);
[email protected]b5756e22012-11-30 01:32:02852 views::corewm::SetChildWindowVisibilityChangesAnimated(default_container);
[email protected]a4cd6d32012-09-12 03:42:13853 SetUsesScreenCoordinates(default_container);
[email protected]c5be8d672014-01-07 13:33:41854 SetUsesEasyResizeTargeter(default_container);
[email protected]a4cd6d32012-09-12 03:42:13855
856 aura::Window* always_on_top_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27857 kShellWindowId_AlwaysOnTopContainer,
[email protected]a4cd6d32012-09-12 03:42:13858 "AlwaysOnTopContainer",
859 non_lock_screen_containers);
[email protected]b5756e22012-11-30 01:32:02860 views::corewm::SetChildWindowVisibilityChangesAnimated(
861 always_on_top_container);
[email protected]a4cd6d32012-09-12 03:42:13862 SetUsesScreenCoordinates(always_on_top_container);
863
[email protected]beb4e5c2013-06-18 15:37:07864 aura::Window* docked_container = CreateContainer(
865 kShellWindowId_DockedContainer,
866 "DockedContainer",
867 non_lock_screen_containers);
[email protected]5eab6e92013-09-19 19:09:27868 views::corewm::SetChildWindowVisibilityChangesAnimated(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07869 SetUsesScreenCoordinates(docked_container);
[email protected]1ff0c492014-01-21 20:20:44870 SetUsesEasyResizeTargeter(docked_container);
[email protected]beb4e5c2013-06-18 15:37:07871
[email protected]3f13cf12013-07-12 05:13:59872 aura::Window* shelf_container =
[email protected]478c6c32013-03-09 02:50:58873 CreateContainer(kShellWindowId_ShelfContainer,
[email protected]3f13cf12013-07-12 05:13:59874 "ShelfContainer",
[email protected]a4cd6d32012-09-12 03:42:13875 non_lock_screen_containers);
[email protected]3f13cf12013-07-12 05:13:59876 SetUsesScreenCoordinates(shelf_container);
877 DescendantShouldStayInSameRootWindow(shelf_container);
[email protected]a4cd6d32012-09-12 03:42:13878
[email protected]f2026eb2013-10-22 14:28:56879 aura::Window* panel_container = CreateContainer(
880 kShellWindowId_PanelContainer,
881 "PanelContainer",
882 non_lock_screen_containers);
883 SetUsesScreenCoordinates(panel_container);
[email protected]c5be8d672014-01-07 13:33:41884 SetUsesEasyResizeTargeter(panel_container);
[email protected]f2026eb2013-10-22 14:28:56885
886 aura::Window* shelf_bubble_container =
887 CreateContainer(kShellWindowId_ShelfBubbleContainer,
888 "ShelfBubbleContainer",
889 non_lock_screen_containers);
890 SetUsesScreenCoordinates(shelf_bubble_container);
891 DescendantShouldStayInSameRootWindow(shelf_bubble_container);
892
[email protected]dc851a4e52012-10-03 00:05:55893 aura::Window* app_list_container =
[email protected]c0ce80e2012-10-05 23:28:27894 CreateContainer(kShellWindowId_AppListContainer,
[email protected]dc851a4e52012-10-03 00:05:55895 "AppListContainer",
896 non_lock_screen_containers);
897 SetUsesScreenCoordinates(app_list_container);
[email protected]a4cd6d32012-09-12 03:42:13898
899 aura::Window* modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27900 kShellWindowId_SystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13901 "SystemModalContainer",
902 non_lock_screen_containers);
[email protected]a4cd6d32012-09-12 03:42:13903 modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27904 new SystemModalContainerLayoutManager(modal_container));
[email protected]b5756e22012-11-30 01:32:02905 views::corewm::SetChildWindowVisibilityChangesAnimated(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13906 SetUsesScreenCoordinates(modal_container);
[email protected]c5be8d672014-01-07 13:33:41907 SetUsesEasyResizeTargeter(modal_container);
[email protected]a4cd6d32012-09-12 03:42:13908
909 aura::Window* input_method_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27910 kShellWindowId_InputMethodContainer,
[email protected]a4cd6d32012-09-12 03:42:13911 "InputMethodContainer",
912 non_lock_screen_containers);
[email protected]649eb7462013-10-24 07:52:01913 views::corewm::SetChildWindowVisibilityChangesAnimated(
914 input_method_container);
[email protected]a4cd6d32012-09-12 03:42:13915 SetUsesScreenCoordinates(input_method_container);
916
917 // TODO(beng): Figure out if we can make this use
918 // SystemModalContainerEventFilter instead of stops_event_propagation.
919 aura::Window* lock_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27920 kShellWindowId_LockScreenContainer,
[email protected]a4cd6d32012-09-12 03:42:13921 "LockScreenContainer",
922 lock_screen_containers);
923 lock_container->SetLayoutManager(
[email protected]1af71f72014-01-29 20:00:55924 new internal::WorkspaceLayoutManager(lock_container));
[email protected]a4cd6d32012-09-12 03:42:13925 SetUsesScreenCoordinates(lock_container);
926 // TODO(beng): stopsevents
927
928 aura::Window* lock_modal_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27929 kShellWindowId_LockSystemModalContainer,
[email protected]a4cd6d32012-09-12 03:42:13930 "LockSystemModalContainer",
931 lock_screen_containers);
[email protected]a4cd6d32012-09-12 03:42:13932 lock_modal_container->SetLayoutManager(
[email protected]c0ce80e2012-10-05 23:28:27933 new SystemModalContainerLayoutManager(lock_modal_container));
[email protected]b5756e22012-11-30 01:32:02934 views::corewm::SetChildWindowVisibilityChangesAnimated(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13935 SetUsesScreenCoordinates(lock_modal_container);
[email protected]c5be8d672014-01-07 13:33:41936 SetUsesEasyResizeTargeter(lock_modal_container);
[email protected]a4cd6d32012-09-12 03:42:13937
938 aura::Window* status_container =
[email protected]c0ce80e2012-10-05 23:28:27939 CreateContainer(kShellWindowId_StatusContainer,
[email protected]a4cd6d32012-09-12 03:42:13940 "StatusContainer",
941 lock_screen_related_containers);
942 SetUsesScreenCoordinates(status_container);
[email protected]e887c6c2013-07-08 19:35:53943 DescendantShouldStayInSameRootWindow(status_container);
[email protected]a4cd6d32012-09-12 03:42:13944
945 aura::Window* settings_bubble_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27946 kShellWindowId_SettingBubbleContainer,
[email protected]a4cd6d32012-09-12 03:42:13947 "SettingBubbleContainer",
948 lock_screen_related_containers);
[email protected]b5756e22012-11-30 01:32:02949 views::corewm::SetChildWindowVisibilityChangesAnimated(
950 settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:13951 SetUsesScreenCoordinates(settings_bubble_container);
[email protected]e887c6c2013-07-08 19:35:53952 DescendantShouldStayInSameRootWindow(settings_bubble_container);
[email protected]a4cd6d32012-09-12 03:42:13953
954 aura::Window* menu_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27955 kShellWindowId_MenuContainer,
[email protected]a4cd6d32012-09-12 03:42:13956 "MenuContainer",
957 lock_screen_related_containers);
[email protected]b5756e22012-11-30 01:32:02958 views::corewm::SetChildWindowVisibilityChangesAnimated(menu_container);
[email protected]a4cd6d32012-09-12 03:42:13959 SetUsesScreenCoordinates(menu_container);
960
961 aura::Window* drag_drop_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27962 kShellWindowId_DragImageAndTooltipContainer,
[email protected]a4cd6d32012-09-12 03:42:13963 "DragImageAndTooltipContainer",
964 lock_screen_related_containers);
[email protected]b5756e22012-11-30 01:32:02965 views::corewm::SetChildWindowVisibilityChangesAnimated(drag_drop_container);
[email protected]a4cd6d32012-09-12 03:42:13966 SetUsesScreenCoordinates(drag_drop_container);
967
968 aura::Window* overlay_container = CreateContainer(
[email protected]c0ce80e2012-10-05 23:28:27969 kShellWindowId_OverlayContainer,
[email protected]a4cd6d32012-09-12 03:42:13970 "OverlayContainer",
971 lock_screen_related_containers);
972 SetUsesScreenCoordinates(overlay_container);
[email protected]a07615f2012-10-24 08:23:08973
[email protected]b2da9b602014-03-05 18:39:52974 aura::Window* virtual_keyboard_parent_container = CreateContainer(
975 kShellWindowId_VirtualKeyboardParentContainer,
976 "VirtualKeyboardParentContainer",
977 root_window);
978 SetUsesScreenCoordinates(virtual_keyboard_parent_container);
979
980#if defined(OS_CHROMEOS)
981 aura::Window* mouse_cursor_container = CreateContainer(
982 kShellWindowId_MouseCursorContainer,
983 "MouseCursorContainer",
984 root_window);
985 SetUsesScreenCoordinates(mouse_cursor_container);
986#endif
987
[email protected]a07615f2012-10-24 08:23:08988 CreateContainer(kShellWindowId_PowerButtonAnimationContainer,
[email protected]b2da9b602014-03-05 18:39:52989 "PowerButtonAnimationContainer", root_window);
[email protected]a4cd6d32012-09-12 03:42:13990}
991
[email protected]d141b922013-07-09 08:13:17992void RootWindowController::EnableTouchHudProjection() {
993 if (touch_hud_projection_)
994 return;
[email protected]41baaed2013-11-09 04:18:26995 set_touch_hud_projection(new TouchHudProjection(root_window()));
[email protected]d141b922013-07-09 08:13:17996}
997
998void RootWindowController::DisableTouchHudProjection() {
999 if (!touch_hud_projection_)
1000 return;
1001 touch_hud_projection_->Remove();
1002}
1003
1004void RootWindowController::OnLoginStateChanged(user::LoginStatus status) {
1005 shelf_->shelf_layout_manager()->UpdateVisibilityState();
1006}
1007
1008void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
1009 if (enabled)
1010 EnableTouchHudProjection();
1011 else
1012 DisableTouchHudProjection();
1013}
1014
[email protected]6b2d4a0b2013-09-06 06:29:541015RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:451016 const aura::Window* root_window) {
[email protected]6b2d4a0b2013-09-06 06:29:541017 return root_window ? GetRootWindowSettings(root_window)->controller : NULL;
1018}
1019
[email protected]d90b8392012-06-13 09:34:561020} // namespace internal
1021} // namespace ash