blob: 6ac85d4cc989838300835eb34d477dcb0c80e933 [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
sky0702b272016-06-03 22:10:4110#include "ash/aura/aura_layout_manager_adapter.h"
skyd053905c2016-08-30 22:37:3511#include "ash/aura/wm_root_window_controller_aura.h"
sky0702b272016-06-03 22:10:4112#include "ash/aura/wm_shelf_aura.h"
13#include "ash/aura/wm_window_aura.h"
jamescooke044e1c2016-06-13 20:56:1814#include "ash/common/ash_constants.h"
mswd9b1b342016-06-17 20:19:5715#include "ash/common/ash_switches.h"
jamescook26f32092016-06-17 04:26:5216#include "ash/common/focus_cycler.h"
mswb2416052016-06-24 21:23:4517#include "ash/common/login_status.h"
jamescook2b624c5a2016-06-08 01:34:0218#include "ash/common/session/session_state_delegate.h"
jamescook361185a22016-08-13 00:12:0919#include "ash/common/shelf/shelf_delegate.h"
mswdf64c66b2016-08-23 18:56:3720#include "ash/common/shelf/shelf_layout_manager.h"
jamescook1b474d6a2016-06-04 05:56:0021#include "ash/common/shelf/shelf_types.h"
mswdf64c66b2016-08-23 18:56:3722#include "ash/common/shelf/shelf_widget.h"
msw0414d4122016-07-06 22:58:4823#include "ash/common/shell_delegate.h"
skyc096d9f2016-06-02 13:46:2624#include "ash/common/shell_window_ids.h"
mswdf64c66b2016-08-23 18:56:3725#include "ash/common/system/status_area_layout_manager.h"
jamescook625f7912016-07-14 01:00:5226#include "ash/common/system/status_area_widget.h"
jamescook2a4d1eb2016-06-09 20:10:0727#include "ash/common/system/tray/system_tray_delegate.h"
msw0e91d932016-08-25 22:34:0928#include "ash/common/wallpaper/wallpaper_delegate.h"
msw3f439af2016-09-08 22:35:2629#include "ash/common/wallpaper/wallpaper_widget_controller.h"
skyd6063772016-06-01 17:52:2130#include "ash/common/wm/always_on_top_controller.h"
31#include "ash/common/wm/container_finder.h"
32#include "ash/common/wm/dock/docked_window_layout_manager.h"
33#include "ash/common/wm/fullscreen_window_finder.h"
34#include "ash/common/wm/panels/panel_layout_manager.h"
skyc096d9f2016-06-02 13:46:2635#include "ash/common/wm/root_window_layout_manager.h"
skyd6063772016-06-01 17:52:2136#include "ash/common/wm/switchable_windows.h"
skyea4ca942016-09-12 21:56:1937#include "ash/common/wm/system_modal_container_layout_manager.h"
skyd6063772016-06-01 17:52:2138#include "ash/common/wm/window_state.h"
skyd6063772016-06-01 17:52:2139#include "ash/common/wm/workspace/workspace_layout_manager.h"
skyf71e6c92016-08-30 18:49:1940#include "ash/common/wm/workspace_controller.h"
sky0702b272016-06-03 22:10:4141#include "ash/common/wm_shell.h"
42#include "ash/common/wm_window.h"
[email protected]6bdf7952012-11-14 10:10:5843#include "ash/display/display_manager.h"
[email protected]a273d33a2013-10-17 12:41:2144#include "ash/high_contrast/high_contrast_controller.h"
[email protected]f5c9dbc2014-04-11 08:13:4545#include "ash/host/ash_window_tree_host.h"
[email protected]f8e6aad2013-08-30 21:49:1146#include "ash/root_window_settings.h"
jamescook752e8df2016-08-09 19:54:3947#include "ash/shelf/shelf_window_targeter.h"
[email protected]d90b8392012-06-13 09:34:5648#include "ash/shell.h"
[email protected]2b8a9bb2013-07-01 22:43:4049#include "ash/touch/touch_hud_debug.h"
50#include "ash/touch/touch_hud_projection.h"
[email protected]80549c152013-07-02 01:42:4751#include "ash/touch/touch_observer_hud.h"
[email protected]68d51332014-06-06 13:51:1352#include "ash/wm/lock_layout_manager.h"
[email protected]b8642ec2014-04-17 05:20:3953#include "ash/wm/panels/attached_panel_window_targeter.h"
[email protected]100659412013-06-21 22:59:5554#include "ash/wm/panels/panel_window_event_handler.h"
[email protected]2a2caa02013-01-22 20:50:3655#include "ash/wm/stacking_controller.h"
msw607227f82016-08-30 17:22:3956#include "ash/wm/system_wallpaper_controller.h"
[email protected]8d625fb2012-07-18 16:40:0657#include "ash/wm/window_properties.h"
sky8d5646fe2016-04-15 17:03:4658#include "ash/wm/window_state_aura.h"
[email protected]700849f2013-04-30 17:49:2059#include "ash/wm/window_util.h"
[email protected]e6e41d2f2012-10-29 19:22:1960#include "base/command_line.h"
jonrossa90d8982016-05-16 18:14:2561#include "base/macros.h"
sky1e30f062016-04-14 21:19:1662#include "base/memory/ptr_util.h"
[email protected]1e84c632013-06-27 23:12:2163#include "base/time/time.h"
[email protected]f1853122012-06-27 16:21:2664#include "ui/aura/client/aura_constants.h"
[email protected]2374d1812014-03-04 03:42:2765#include "ui/aura/client/screen_position_client.h"
[email protected]f1853122012-06-27 16:21:2666#include "ui/aura/window.h"
[email protected]cf6fea22013-08-07 14:24:0167#include "ui/aura/window_delegate.h"
[email protected]fcc51c952014-02-21 21:31:2668#include "ui/aura/window_event_dispatcher.h"
[email protected]f1853122012-06-27 16:21:2669#include "ui/aura/window_observer.h"
[email protected]8b3e3d82013-08-20 14:36:3070#include "ui/aura/window_tracker.h"
[email protected]cf6fea22013-08-07 14:24:0171#include "ui/base/hit_test.h"
oshimaf84b0da722016-04-27 19:47:1972#include "ui/display/display.h"
73#include "ui/display/screen.h"
[email protected]86459e2c2013-04-10 13:39:2474#include "ui/keyboard/keyboard_controller.h"
75#include "ui/keyboard/keyboard_util.h"
[email protected]431552c2012-10-23 00:38:3376#include "ui/views/view_model.h"
77#include "ui/views/view_model_utils.h"
[email protected]ee3ed10772014-03-11 22:02:0178#include "ui/wm/core/capture_controller.h"
79#include "ui/wm/core/visibility_controller.h"
80#include "ui/wm/core/window_util.h"
[email protected]af4552b22014-03-21 19:45:0181#include "ui/wm/public/drag_drop_client.h"
82#include "ui/wm/public/tooltip_client.h"
[email protected]5b251f12013-12-19 01:50:0583#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5684
[email protected]252eb232013-08-14 22:09:2785#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:5086#include "ash/ash_touch_exploration_manager_chromeos.h"
[email protected]252eb232013-08-14 22:09:2787#include "ash/wm/boot_splash_screen_chromeos.h"
[email protected]a825e8312014-05-05 22:05:0188#include "ui/chromeos/touch_exploration_controller.h"
[email protected]252eb232013-08-14 22:09:2789#endif
90
[email protected]d90b8392012-06-13 09:34:5691namespace ash {
92namespace {
93
[email protected]252eb232013-08-14 22:09:2794#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:4995// Duration for the animation that hides the boot splash screen, in
96// milliseconds. This should be short enough in relation to
97// wm/window_animation.cc's brightness/grayscale fade animation that the login
msw607227f82016-08-30 17:22:3998// wallpaper image animation isn't hidden by the splash screen animation.
[email protected]bca9a7e2012-11-10 06:25:4999const int kBootSplashScreenHideDurationMs = 500;
[email protected]252eb232013-08-14 22:09:27100#endif
[email protected]bca9a7e2012-11-10 06:25:49101
[email protected]2816c2462013-12-17 02:22:25102float ToRelativeValue(int value, int src, int dst) {
103 return static_cast<float>(value) / static_cast<float>(src) * dst;
104}
105
106void MoveOriginRelativeToSize(const gfx::Size& src_size,
jamescookb8dcef522016-06-25 14:42:55107 const gfx::Size& dst_size,
108 gfx::Rect* bounds_in_out) {
[email protected]2816c2462013-12-17 02:22:25109 gfx::Point origin = bounds_in_out->origin();
110 bounds_in_out->set_origin(gfx::Point(
111 ToRelativeValue(origin.x(), src_size.width(), dst_size.width()),
112 ToRelativeValue(origin.y(), src_size.height(), dst_size.height())));
113}
114
[email protected]95058572012-08-20 14:57:29115// Reparents |window| to |new_parent|.
116void ReparentWindow(aura::Window* window, aura::Window* new_parent) {
[email protected]2816c2462013-12-17 02:22:25117 const gfx::Size src_size = window->parent()->bounds().size();
118 const gfx::Size dst_size = new_parent->bounds().size();
[email protected]95058572012-08-20 14:57:29119 // Update the restore bounds to make it relative to the display.
[email protected]a41b4e12013-09-20 04:36:34120 wm::WindowState* state = wm::GetWindowState(window);
121 gfx::Rect restore_bounds;
122 bool has_restore_bounds = state->HasRestoreBounds();
[email protected]2816c2462013-12-17 02:22:25123
[email protected]9cfd3d12014-02-25 15:33:45124 bool update_bounds = (state->IsNormalOrSnapped() || state->IsMinimized()) &&
[email protected]093b8d642014-04-03 20:59:28125 new_parent->id() != kShellWindowId_DockedContainer;
[email protected]2816c2462013-12-17 02:22:25126 gfx::Rect local_bounds;
127 if (update_bounds) {
sky0702b272016-06-03 22:10:41128 local_bounds = WmWindowAura::GetAuraWindow(state->window())->bounds();
[email protected]2816c2462013-12-17 02:22:25129 MoveOriginRelativeToSize(src_size, dst_size, &local_bounds);
130 }
131
132 if (has_restore_bounds) {
[email protected]a41b4e12013-09-20 04:36:34133 restore_bounds = state->GetRestoreBoundsInParent();
[email protected]2816c2462013-12-17 02:22:25134 MoveOriginRelativeToSize(src_size, dst_size, &restore_bounds);
135 }
136
[email protected]95058572012-08-20 14:57:29137 new_parent->AddChild(window);
[email protected]2816c2462013-12-17 02:22:25138
[email protected]8663b7a62014-01-18 01:24:21139 // Docked windows have bounds handled by the layout manager in AddChild().
[email protected]2816c2462013-12-17 02:22:25140 if (update_bounds)
141 window->SetBounds(local_bounds);
142
[email protected]a41b4e12013-09-20 04:36:34143 if (has_restore_bounds)
144 state->SetRestoreBoundsInParent(restore_bounds);
[email protected]95058572012-08-20 14:57:29145}
146
147// Reparents the appropriate set of windows from |src| to |dst|.
[email protected]bf9cdb362013-10-25 19:22:45148void ReparentAllWindows(aura::Window* src, aura::Window* dst) {
[email protected]95058572012-08-20 14:57:29149 // Set of windows to move.
[email protected]f1853122012-06-27 16:21:26150 const int kContainerIdsToMove[] = {
[email protected]093b8d642014-04-03 20:59:28151 kShellWindowId_DefaultContainer,
152 kShellWindowId_DockedContainer,
153 kShellWindowId_PanelContainer,
154 kShellWindowId_AlwaysOnTopContainer,
155 kShellWindowId_SystemModalContainer,
156 kShellWindowId_LockSystemModalContainer,
tengsf98986c2014-12-06 01:42:21157 kShellWindowId_UnparentedControlContainer,
oshima022a9542015-05-01 00:15:02158 kShellWindowId_OverlayContainer,
159 };
160 const int kExtraContainerIdsToMoveInUnifiedMode[] = {
161 kShellWindowId_LockScreenContainer,
msw607227f82016-08-30 17:22:39162 kShellWindowId_LockScreenWallpaperContainer,
oshima022a9542015-05-01 00:15:02163 };
164 std::vector<int> container_ids(
165 kContainerIdsToMove,
166 kContainerIdsToMove + arraysize(kContainerIdsToMove));
167 // Check the default_multi_display_mode because this is also necessary
168 // in trasition between mirror <-> unified mode.
oshima628a6172015-08-01 01:33:14169 if (Shell::GetInstance()
170 ->display_manager()
171 ->current_default_multi_display_mode() == DisplayManager::UNIFIED) {
oshima022a9542015-05-01 00:15:02172 for (int id : kExtraContainerIdsToMoveInUnifiedMode)
173 container_ids.push_back(id);
174 }
175
176 for (int id : container_ids) {
[email protected]f1853122012-06-27 16:21:26177 aura::Window* src_container = Shell::GetContainer(src, id);
178 aura::Window* dst_container = Shell::GetContainer(dst, id);
[email protected]5b6021902013-02-26 05:33:29179 while (!src_container->children().empty()) {
180 // Restart iteration from the source container windows each time as they
181 // may change as a result of moving other windows.
182 aura::Window::Windows::const_iterator iter =
183 src_container->children().begin();
184 while (iter != src_container->children().end() &&
skyea4ca942016-09-12 21:56:19185 SystemModalContainerLayoutManager::IsModalBackground(
186 WmWindowAura::Get(*iter))) {
[email protected]5b6021902013-02-26 05:33:29187 ++iter;
188 }
189 // If the entire window list is modal background windows then stop.
190 if (iter == src_container->children().end())
191 break;
192 ReparentWindow(*iter, dst_container);
[email protected]f1853122012-06-27 16:21:26193 }
194 }
195}
196
oshima9a61ecf2016-06-18 10:43:05197bool IsWindowAboveContainer(aura::Window* window,
198 aura::Window* blocking_container) {
199 std::vector<aura::Window*> target_path;
200 std::vector<aura::Window*> blocking_path;
201
202 while (window) {
203 target_path.push_back(window);
204 window = window->parent();
205 }
206
207 while (blocking_container) {
208 blocking_path.push_back(blocking_container);
209 blocking_container = blocking_container->parent();
210 }
211
212 // The root window is put at the end so that we compare windows at
213 // the same depth.
214 while (!blocking_path.empty()) {
215 if (target_path.empty())
216 return false;
217
218 aura::Window* target = target_path.back();
219 target_path.pop_back();
220 aura::Window* blocking = blocking_path.back();
221 blocking_path.pop_back();
222
223 // Still on the same path, continue.
224 if (target == blocking)
225 continue;
226
227 // This can happen only if unparented window is passed because
228 // first element must be the same root.
229 if (!target->parent() || !blocking->parent())
230 return false;
231
232 aura::Window* common_parent = target->parent();
233 DCHECK_EQ(common_parent, blocking->parent());
234 aura::Window::Windows windows = common_parent->children();
235 auto blocking_iter = std::find(windows.begin(), windows.end(), blocking);
236 // If the target window is above blocking window, the window can handle
237 // events.
238 return std::find(blocking_iter, windows.end(), target) != windows.end();
239 }
240
241 return true;
242}
243
[email protected]cf6fea22013-08-07 14:24:01244// A window delegate which does nothing. Used to create a window that
245// is a event target, but do nothing.
246class EmptyWindowDelegate : public aura::WindowDelegate {
247 public:
248 EmptyWindowDelegate() {}
dcheng1f4538e2014-10-27 23:57:05249 ~EmptyWindowDelegate() override {}
[email protected]cf6fea22013-08-07 14:24:01250
251 // aura::WindowDelegate overrides:
dcheng1f4538e2014-10-27 23:57:05252 gfx::Size GetMinimumSize() const override { return gfx::Size(); }
253 gfx::Size GetMaximumSize() const override { return gfx::Size(); }
254 void OnBoundsChanged(const gfx::Rect& old_bounds,
255 const gfx::Rect& new_bounds) override {}
256 gfx::NativeCursor GetCursor(const gfx::Point& point) override {
[email protected]62c9f102014-03-27 06:07:04257 return gfx::kNullCursor;
258 }
dcheng1f4538e2014-10-27 23:57:05259 int GetNonClientComponent(const gfx::Point& point) const override {
[email protected]cf6fea22013-08-07 14:24:01260 return HTNOWHERE;
261 }
dcheng1f4538e2014-10-27 23:57:05262 bool ShouldDescendIntoChildForEventHandling(
[email protected]cf6fea22013-08-07 14:24:01263 aura::Window* child,
mostynb10d6b382014-10-03 16:23:45264 const gfx::Point& location) override {
[email protected]cf6fea22013-08-07 14:24:01265 return false;
266 }
dcheng1f4538e2014-10-27 23:57:05267 bool CanFocus() override { return false; }
268 void OnCaptureLost() override {}
danakj85d970e2015-04-04 00:15:24269 void OnPaint(const ui::PaintContext& context) override {}
dcheng1f4538e2014-10-27 23:57:05270 void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
271 void OnWindowDestroying(aura::Window* window) override {}
272 void OnWindowDestroyed(aura::Window* window) override { delete this; }
273 void OnWindowTargetVisibilityChanged(bool visible) override {}
274 bool HasHitTestMask() const override { return false; }
275 void GetHitTestMask(gfx::Path* mask) const override {}
[email protected]cf6fea22013-08-07 14:24:01276
277 private:
278 DISALLOW_COPY_AND_ASSIGN(EmptyWindowDelegate);
279};
280
[email protected]d90b8392012-06-13 09:34:56281} // namespace
282
[email protected]f5c9dbc2014-04-11 08:13:45283void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38284 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28285 controller->Init(RootWindowController::PRIMARY,
msw0414d4122016-07-06 22:58:48286 WmShell::Get()->delegate()->IsFirstRunAfterBoot());
[email protected]d90b8392012-06-13 09:34:56287}
288
[email protected]f5c9dbc2014-04-11 08:13:45289void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38290 RootWindowController* controller = new RootWindowController(host);
[email protected]608de6c2013-10-29 00:14:28291 controller->Init(RootWindowController::SECONDARY, false /* first run */);
292}
293
[email protected]88d71122012-10-18 07:11:01294// static
[email protected]ccff3d72013-02-06 04:26:28295RootWindowController* RootWindowController::ForWindow(
296 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07297 CHECK(Shell::HasInstance());
[email protected]a0afeb12012-12-10 22:57:09298 return GetRootWindowController(window->GetRootWindow());
299}
300
301// static
[email protected]d17642d2013-09-12 23:44:38302RootWindowController* RootWindowController::ForTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07303 CHECK(Shell::HasInstance());
[email protected]093b8d642014-04-03 20:59:28304 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09305}
306
[email protected]a273d33a2013-10-17 12:41:21307RootWindowController::~RootWindowController() {
308 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45309 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21310 // The CaptureClient needs to be around for as long as the RootWindow is
311 // valid.
312 capture_client_.reset();
313}
314
[email protected]f5c9dbc2014-04-11 08:13:45315aura::WindowTreeHost* RootWindowController::GetHost() {
316 return ash_host_->AsWindowTreeHost();
317}
318
319const aura::WindowTreeHost* RootWindowController::GetHost() const {
320 return ash_host_->AsWindowTreeHost();
321}
322
323aura::Window* RootWindowController::GetRootWindow() {
324 return GetHost()->window();
325}
326
327const aura::Window* RootWindowController::GetRootWindow() const {
328 return GetHost()->window();
329}
330
skyf71e6c92016-08-30 18:49:19331WorkspaceController* RootWindowController::workspace_controller() {
skyd053905c2016-08-30 22:37:35332 return wm_root_window_controller_->workspace_controller();
skyf71e6c92016-08-30 18:49:19333}
334
[email protected]6675e1c2012-09-11 09:15:45335void RootWindowController::Shutdown() {
sky88bd4be62016-06-09 17:34:41336 WmShell::Get()->RemoveShellObserver(this);
[email protected]a825e8312014-05-05 22:05:01337
338#if defined(OS_CHROMEOS)
sky20686a4c52016-09-13 01:26:54339 touch_exploration_manager_.reset();
[email protected]a825e8312014-05-05 22:05:01340#endif
[email protected]d141b922013-07-09 08:13:17341
[email protected]f5c9dbc2014-04-11 08:13:45342 aura::Window* root_window = GetRootWindow();
jamescook4545062c2016-08-02 18:48:01343 WmWindow* root_shutting_down = WmWindowAura::Get(root_window);
344 WmShell* shell = WmShell::Get();
[email protected]d17642d2013-09-12 23:44:38345 // Change the target root window before closing child windows. If any child
[email protected]c98a4922013-09-05 20:01:42346 // being removed triggers a relayout of the shelf it will try to build a
[email protected]d17642d2013-09-12 23:44:38347 // window list adding windows from the target root window's containers which
[email protected]c98a4922013-09-05 20:01:42348 // may have already gone away.
jamescook4545062c2016-08-02 18:48:01349 if (shell->GetRootWindowForNewWindows() == root_shutting_down) {
350 // The root window for new windows is being destroyed. Switch to the primary
351 // root window if possible.
352 WmWindow* primary_root = shell->GetPrimaryRootWindow();
353 shell->set_root_window_for_new_windows(
354 primary_root == root_shutting_down ? nullptr : primary_root);
[email protected]f634dd32012-07-23 22:49:07355 }
[email protected]c98a4922013-09-05 20:01:42356
357 CloseChildWindows();
[email protected]f5c9dbc2014-04-11 08:13:45358 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]6675e1c2012-09-11 09:15:45359 // Forget with the display ID so that display lookup
360 // ends up with invalid display.
[email protected]f5c9dbc2014-04-11 08:13:45361 GetRootWindowSettings(root_window)->display_id =
oshimaf84b0da722016-04-27 19:47:19362 display::Display::kInvalidDisplayID;
[email protected]8f5209c2014-05-22 20:36:11363 ash_host_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28364
msw607227f82016-08-30 17:22:39365 system_wallpaper_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45366 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56367}
368
oshima9a61ecf2016-06-18 10:43:05369bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) {
370 if (GetRootWindow() != window->GetRootWindow())
371 return false;
372
373 // Always allow events to fall through to the virtual keyboard even if
374 // displaying a system modal dialog.
375 if (IsVirtualKeyboardWindow(window))
376 return true;
377
378 aura::Window* blocking_container = nullptr;
379
380 int modal_container_id = 0;
mswbc0a8b482016-06-30 02:21:14381 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()) {
oshima9a61ecf2016-06-18 10:43:05382 blocking_container =
383 GetContainer(kShellWindowId_LockScreenContainersContainer);
384 modal_container_id = kShellWindowId_LockSystemModalContainer;
385 } else {
386 modal_container_id = kShellWindowId_SystemModalContainer;
387 }
388 aura::Window* modal_container = GetContainer(modal_container_id);
389 SystemModalContainerLayoutManager* modal_layout_manager = nullptr;
390 modal_layout_manager = static_cast<SystemModalContainerLayoutManager*>(
skyea4ca942016-09-12 21:56:19391 WmWindowAura::Get(modal_container)->GetLayoutManager());
oshima9a61ecf2016-06-18 10:43:05392
skyb733d4182016-09-09 23:18:38393 if (modal_layout_manager->has_window_dimmer())
oshima9a61ecf2016-06-18 10:43:05394 blocking_container = modal_container;
395 else
396 modal_container = nullptr; // Don't check modal dialogs.
397
398 // In normal session.
399 if (!blocking_container)
400 return true;
401
402 if (!IsWindowAboveContainer(window, blocking_container))
403 return false;
404
405 // If the window is in the target modal container, only allow the top most
406 // one.
407 if (modal_container && modal_container->Contains(window))
skyea4ca942016-09-12 21:56:19408 return modal_layout_manager->IsPartOfActiveModalWindow(
409 WmWindowAura::Get(window));
oshima9a61ecf2016-06-18 10:43:05410
411 return true;
412}
413
[email protected]d90b8392012-06-13 09:34:56414aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45415 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56416}
417
[email protected]d8a24952013-08-05 20:05:05418const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45419 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05420}
421
[email protected]864b58552013-12-19 04:19:38422void RootWindowController::ShowShelf() {
jamescook1cad77e92016-08-31 00:02:26423 if (!wm_shelf_aura_->IsShelfInitialized())
[email protected]e74aaf0a2012-10-12 18:42:28424 return;
jamescook1cad77e92016-08-31 00:02:26425 // TODO(jamescook): Move this into WmShelf.
jamescookb551aba2016-09-01 01:00:16426 wm_shelf_aura_->shelf_widget()->SetShelfVisibility(true);
427 wm_shelf_aura_->shelf_widget()->status_area_widget()->Show();
[email protected]e74aaf0a2012-10-12 18:42:28428}
429
jamescook6500ad132016-05-27 06:15:54430void RootWindowController::CreateShelf() {
jamescook1cad77e92016-08-31 00:02:26431 if (wm_shelf_aura_->IsShelfInitialized())
jamescook6500ad132016-05-27 06:15:54432 return;
jamescook1cad77e92016-08-31 00:02:26433 wm_shelf_aura_->InitializeShelf();
jamescook6500ad132016-05-27 06:15:54434
[email protected]756bda12013-07-03 08:17:06435 if (panel_layout_manager_)
jamescookbe6ed822016-06-06 20:08:55436 panel_layout_manager_->SetShelf(wm_shelf_aura_.get());
[email protected]7115bd32013-07-19 08:25:39437 if (docked_layout_manager_) {
jamescookbe6ed822016-06-06 20:08:55438 docked_layout_manager_->SetShelf(wm_shelf_aura_.get());
jamescookb551aba2016-09-01 01:00:16439 if (wm_shelf_aura_->shelf_layout_manager()) {
jamescook612205f2016-05-26 06:02:11440 docked_layout_manager_->AddObserver(
jamescookb551aba2016-09-01 01:00:16441 wm_shelf_aura_->shelf_layout_manager());
442 }
[email protected]7115bd32013-07-19 08:25:39443 }
[email protected]b8642ec2014-04-17 05:20:39444
445 // Notify shell observers that the shelf has been created.
jamescook1cad77e92016-08-31 00:02:26446 // TODO(jamescook): Move this into WmShelf::InitializeShelf(). This will
447 // require changing AttachedPanelWidgetTargeter's access to WmShelf.
msw61e16672016-08-12 16:36:58448 WmShell::Get()->NotifyShelfCreatedForRootWindow(
sky80556bc42016-06-07 22:46:13449 WmWindowAura::Get(GetRootWindow()));
jamescook6500ad132016-05-27 06:15:54450
jamescookb551aba2016-09-01 01:00:16451 wm_shelf_aura_->shelf_widget()->PostCreateShelf();
[email protected]756bda12013-07-03 08:17:06452}
453
skye79274a2016-06-08 05:39:02454void RootWindowController::UpdateAfterLoginStatusChange(LoginStatus status) {
455 if (status != LoginStatus::NOT_LOGGED_IN)
[email protected]cf6fea22013-08-07 14:24:01456 mouse_event_target_.reset();
jamescookb551aba2016-09-01 01:00:16457 StatusAreaWidget* status_area_widget =
458 wm_shelf_aura_->shelf_widget()->status_area_widget();
459 if (status_area_widget)
460 status_area_widget->UpdateAfterLoginStatusChange(status);
[email protected]16059276d2012-10-22 18:59:50461}
462
msw3f439af2016-09-08 22:35:26463void RootWindowController::OnInitialWallpaperAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27464#if defined(OS_CHROMEOS)
pgal.u-szegedd84534d32014-10-29 12:34:30465 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]bca9a7e2012-11-10 06:25:49466 switches::kAshAnimateFromBootSplashScreen) &&
467 boot_splash_screen_.get()) {
msw607227f82016-08-30 17:22:39468 // Make the splash screen fade out so it doesn't obscure the wallpaper's
469 // brightness/grayscale animation.
[email protected]bca9a7e2012-11-10 06:25:49470 boot_splash_screen_->StartHideAnimation(
471 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
472 }
[email protected]252eb232013-08-14 22:09:27473#endif
[email protected]bca9a7e2012-11-10 06:25:49474}
475
[email protected]0bf61732013-07-02 04:35:10476void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
477 // Make sure the wallpaper is visible.
msw607227f82016-08-30 17:22:39478 system_wallpaper_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27479#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49480 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27481#endif
[email protected]697f04c2012-10-03 01:15:10482}
483
[email protected]d90b8392012-06-13 09:34:56484void RootWindowController::CloseChildWindows() {
[email protected]cf6fea22013-08-07 14:24:01485 mouse_event_target_.reset();
486
[email protected]2a57beb52014-06-09 20:02:26487 // Remove observer as deactivating keyboard causes |docked_layout_manager_|
488 // to fire notifications.
jamescookb551aba2016-09-01 01:00:16489 if (docked_layout_manager_ && wm_shelf_aura_->shelf_layout_manager()) {
jamescook612205f2016-05-26 06:02:11490 docked_layout_manager_->RemoveObserver(
jamescookb551aba2016-09-01 01:00:16491 wm_shelf_aura_->shelf_layout_manager());
492 }
[email protected]2a57beb52014-06-09 20:02:26493
[email protected]b6ba05d902013-10-04 21:38:45494 // Deactivate keyboard container before closing child windows and shutting
495 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03496 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45497
[email protected]79a87b7e2013-01-25 05:08:22498 // panel_layout_manager_ needs to be shut down before windows are destroyed.
499 if (panel_layout_manager_) {
500 panel_layout_manager_->Shutdown();
501 panel_layout_manager_ = NULL;
502 }
[email protected]7115bd32013-07-19 08:25:39503 // docked_layout_manager_ needs to be shut down before windows are destroyed.
504 if (docked_layout_manager_) {
[email protected]7115bd32013-07-19 08:25:39505 docked_layout_manager_->Shutdown();
506 docked_layout_manager_ = NULL;
507 }
jamescookb551aba2016-09-01 01:00:16508 wm_shelf_aura_->ShutdownShelfWidget();
[email protected]e74aaf0a2012-10-12 18:42:28509
skyd053905c2016-08-30 22:37:35510 wm_root_window_controller_->DeleteWorkspaceController();
[email protected]d90b8392012-06-13 09:34:56511
[email protected]0fbfa972013-10-02 19:23:33512 // Explicitly destroy top level windows. We do this as during part of
513 // destruction such windows may query the RootWindow for state.
sky29f31712016-09-07 22:50:38514 aura::Window* root_window = GetRootWindow();
oshimaf38efa92015-10-27 19:06:52515 aura::WindowTracker non_toplevel_windows;
516 non_toplevel_windows.Add(root_window);
517 while (!non_toplevel_windows.windows().empty()) {
518 const aura::Window* non_toplevel_window =
519 *non_toplevel_windows.windows().begin();
520 non_toplevel_windows.Remove(const_cast<aura::Window*>(non_toplevel_window));
[email protected]8b3e3d82013-08-20 14:36:30521 aura::WindowTracker toplevel_windows;
522 for (size_t i = 0; i < non_toplevel_window->children().size(); ++i) {
523 aura::Window* child = non_toplevel_window->children()[i];
[email protected]0fbfa972013-10-02 19:23:33524 if (!child->owned_by_parent())
525 continue;
[email protected]8b3e3d82013-08-20 14:36:30526 if (child->delegate())
527 toplevel_windows.Add(child);
528 else
oshimaf38efa92015-10-27 19:06:52529 non_toplevel_windows.Add(child);
[email protected]8b3e3d82013-08-20 14:36:30530 }
531 while (!toplevel_windows.windows().empty())
532 delete *toplevel_windows.windows().begin();
[email protected]d90b8392012-06-13 09:34:56533 }
[email protected]8b3e3d82013-08-20 14:36:30534 // And then remove the containers.
[email protected]f5c9dbc2014-04-11 08:13:45535 while (!root_window->children().empty()) {
536 aura::Window* window = root_window->children()[0];
[email protected]0fbfa972013-10-02 19:23:33537 if (window->owned_by_parent()) {
538 delete window;
539 } else {
[email protected]f5c9dbc2014-04-11 08:13:45540 root_window->RemoveChild(window);
[email protected]0fbfa972013-10-02 19:23:33541 }
542 }
[email protected]478c6c32013-03-09 02:50:58543
jamescookb551aba2016-09-01 01:00:16544 wm_shelf_aura_->DestroyShelfWidget();
545
mswccb5d692016-08-17 20:37:48546 // CloseChildWindows may be called twice during the shutdown of ash unittests.
jamescook1cad77e92016-08-31 00:02:26547 // Avoid notifying WmShelf that the shelf has been destroyed twice.
548 if (wm_shelf_aura_->IsShelfInitialized())
549 wm_shelf_aura_->ShutdownShelf();
sky29f31712016-09-07 22:50:38550
551 aura::client::SetDragDropClient(root_window, nullptr);
552 aura::client::SetTooltipClient(root_window, nullptr);
[email protected]d90b8392012-06-13 09:34:56553}
554
[email protected]bf9cdb362013-10-25 19:22:45555void RootWindowController::MoveWindowsTo(aura::Window* dst) {
msw6d9e0fd2016-08-12 04:06:02556 // Clear the workspace controller, so it doesn't incorrectly update the shelf.
skyd053905c2016-08-30 22:37:35557 wm_root_window_controller_->DeleteWorkspaceController();
[email protected]f5c9dbc2014-04-11 08:13:45558 ReparentAllWindows(GetRootWindow(), dst);
[email protected]f1853122012-06-27 16:21:26559}
560
[email protected]478c6c32013-03-09 02:50:58561ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
jamescookb551aba2016-09-01 01:00:16562 return wm_shelf_aura_->shelf_layout_manager();
563}
564
565StatusAreaWidget* RootWindowController::GetStatusAreaWidget() {
566 ShelfWidget* shelf_widget = wm_shelf_aura_->shelf_widget();
567 return shelf_widget ? shelf_widget->status_area_widget() : nullptr;
[email protected]478c6c32013-03-09 02:50:58568}
569
[email protected]a0afeb12012-12-10 22:57:09570SystemTray* RootWindowController::GetSystemTray() {
571 // We assume in throughout the code that this will not return NULL. If code
572 // triggers this for valid reasons, it should test status_area_widget first.
jamescookb551aba2016-09-01 01:00:16573 CHECK(wm_shelf_aura_->shelf_widget()->status_area_widget());
574 return wm_shelf_aura_->shelf_widget()->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09575}
576
[email protected]e74aaf0a2012-10-12 18:42:28577void RootWindowController::UpdateShelfVisibility() {
jamescookb551aba2016-09-01 01:00:16578 wm_shelf_aura_->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28579}
580
varkhad99fa94f2015-06-29 22:35:46581aura::Window* RootWindowController::GetWindowForFullscreenMode() {
sky0702b272016-06-03 22:10:41582 return WmWindowAura::GetAuraWindow(
583 wm::GetWindowForFullscreenMode(WmWindowAura::Get(GetRootWindow())));
[email protected]2ee2f5d2013-01-10 23:37:16584}
585
[email protected]b6ba05d902013-10-04 21:38:45586void RootWindowController::ActivateKeyboard(
587 keyboard::KeyboardController* keyboard_controller) {
588 if (!keyboard::IsKeyboardEnabled() ||
589 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
590 return;
591 }
592 DCHECK(keyboard_controller);
jamescookb551aba2016-09-01 01:00:16593 keyboard_controller->AddObserver(wm_shelf_aura_->shelf_layout_manager());
bshe9858b4a2014-09-16 20:46:38594 keyboard_controller->AddObserver(panel_layout_manager_);
595 keyboard_controller->AddObserver(docked_layout_manager_);
skyf71e6c92016-08-30 18:49:19596 keyboard_controller->AddObserver(workspace_controller()->layout_manager());
rsadam7bd510bb2014-12-09 20:10:56597 keyboard_controller->AddObserver(
598 always_on_top_controller_->GetLayoutManager());
msw61e16672016-08-12 16:36:58599 WmShell::Get()->NotifyVirtualKeyboardActivated(true);
bshec3875422014-09-29 13:21:30600 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52601 DCHECK(parent);
jamescookb8dcef522016-06-25 14:42:55602 aura::Window* keyboard_container = keyboard_controller->GetContainerWindow();
[email protected]b6ba05d902013-10-04 21:38:45603 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
604 parent->AddChild(keyboard_container);
[email protected]b6ba05d902013-10-04 21:38:45605}
[email protected]86459e2c2013-04-10 13:39:24606
[email protected]b6ba05d902013-10-04 21:38:45607void RootWindowController::DeactivateKeyboard(
608 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41609 if (!keyboard_controller ||
610 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45611 return;
[email protected]e1b299b2014-01-29 23:53:41612 }
jamescookb8dcef522016-06-25 14:42:55613 aura::Window* keyboard_container = keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45614 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
bshec3875422014-09-29 13:21:30615 aura::Window* parent =
616 GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52617 DCHECK(parent);
618 parent->RemoveChild(keyboard_container);
bshe9858b4a2014-09-16 20:46:38619 // Virtual keyboard may be deactivated while still showing, notify all
620 // observers that keyboard bounds changed to 0 before remove them.
621 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
jamescookb551aba2016-09-01 01:00:16622 keyboard_controller->RemoveObserver(wm_shelf_aura_->shelf_layout_manager());
bshe9858b4a2014-09-16 20:46:38623 keyboard_controller->RemoveObserver(panel_layout_manager_);
624 keyboard_controller->RemoveObserver(docked_layout_manager_);
625 keyboard_controller->RemoveObserver(
skyf71e6c92016-08-30 18:49:19626 workspace_controller()->layout_manager());
rsadam7bd510bb2014-12-09 20:10:56627 keyboard_controller->RemoveObserver(
628 always_on_top_controller_->GetLayoutManager());
msw61e16672016-08-12 16:36:58629 WmShell::Get()->NotifyVirtualKeyboardActivated(false);
[email protected]86459e2c2013-04-10 13:39:24630 }
631}
632
[email protected]602022b2014-03-31 17:07:31633bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
bshec3875422014-09-29 13:21:30634 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]602022b2014-03-31 17:07:31635 return parent ? parent->Contains(window) : false;
636}
637
dmazzoniff86e3472016-06-03 19:52:32638void RootWindowController::SetTouchAccessibilityAnchorPoint(
639 const gfx::Point& anchor_point) {
640#if defined(OS_CHROMEOS)
641 if (touch_exploration_manager_)
642 touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point);
643#endif // defined(OS_CHROMEOS)
644}
645
[email protected]a4cd6d32012-09-12 03:42:13646////////////////////////////////////////////////////////////////////////////////
647// RootWindowController, private:
648
[email protected]f5c9dbc2014-04-11 08:13:45649RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
650 : ash_host_(ash_host),
jamescookbe6ed822016-06-06 20:08:55651 wm_shelf_aura_(new WmShelfAura),
[email protected]a273d33a2013-10-17 12:41:21652 docked_layout_manager_(NULL),
653 panel_layout_manager_(NULL),
654 touch_hud_debug_(NULL),
655 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45656 aura::Window* root_window = GetRootWindow();
657 GetRootWindowSettings(root_window)->controller = this;
[email protected]a273d33a2013-10-17 12:41:21658
skyd053905c2016-08-30 22:37:35659 // Has to happen after this is set as |controller| of RootWindowSettings.
660 wm_root_window_controller_ = WmRootWindowControllerAura::Get(root_window);
661
[email protected]a273d33a2013-10-17 12:41:21662 stacking_controller_.reset(new StackingController);
[email protected]f5c9dbc2014-04-11 08:13:45663 aura::client::SetWindowTreeClient(root_window, stacking_controller_.get());
664 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21665}
666
[email protected]608de6c2013-10-29 00:14:28667void RootWindowController::Init(RootWindowType root_window_type,
668 bool first_run_after_boot) {
[email protected]f5c9dbc2014-04-11 08:13:45669 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50670 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45671 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21672
skyd053905c2016-08-30 22:37:35673 wm_root_window_controller_->CreateContainers();
[email protected]608de6c2013-10-29 00:14:28674
msw607227f82016-08-30 17:22:39675 CreateSystemWallpaper(first_run_after_boot);
[email protected]a273d33a2013-10-17 12:41:21676
677 InitLayoutManagers();
678 InitTouchHuds();
679
skyea4ca942016-09-12 21:56:19680 if (WmShell::Get()
681 ->GetPrimaryRootWindowController()
skyb733d4182016-09-09 23:18:38682 ->GetSystemModalLayoutManager(nullptr)
683 ->has_window_dimmer()) {
skyea4ca942016-09-12 21:56:19684 wm_root_window_controller_->GetSystemModalLayoutManager(nullptr)
685 ->CreateModalBackground();
[email protected]a273d33a2013-10-17 12:41:21686 }
687
sky88bd4be62016-06-09 17:34:41688 WmShell::Get()->AddShellObserver(this);
[email protected]a273d33a2013-10-17 12:41:21689
skyd053905c2016-08-30 22:37:35690 wm_root_window_controller_->root_window_layout_manager()->OnWindowResized();
[email protected]608de6c2013-10-29 00:14:28691 if (root_window_type == PRIMARY) {
bshe9858b4a2014-09-16 20:46:38692 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21693 } else {
[email protected]f5c9dbc2014-04-11 08:13:45694 ash_host_->AsWindowTreeHost()->Show();
[email protected]a273d33a2013-10-17 12:41:21695
[email protected]864b58552013-12-19 04:19:38696 // Create a shelf if a user is already logged in.
mswbc0a8b482016-06-30 02:21:14697 if (WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers())
jamescook6500ad132016-05-27 06:15:54698 CreateShelf();
[email protected]0e3e7cb2014-04-12 05:18:25699
700 // Notify shell observers about new root window.
sky80556bc42016-06-07 22:46:13701 shell->OnRootWindowAdded(WmWindowAura::Get(root_window));
[email protected]a273d33a2013-10-17 12:41:21702 }
[email protected]a825e8312014-05-05 22:05:01703
704#if defined(OS_CHROMEOS)
pgal.u-szegedd84534d32014-10-29 12:34:30705 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]2e0b2352014-07-28 13:28:28706 switches::kAshDisableTouchExplorationMode)) {
[email protected]7d487592014-07-24 03:54:50707 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
[email protected]a825e8312014-05-05 22:05:01708 }
709#endif
[email protected]a273d33a2013-10-17 12:41:21710}
711
[email protected]756bda12013-07-03 08:17:06712void RootWindowController::InitLayoutManagers() {
skyd053905c2016-08-30 22:37:35713 wm_root_window_controller_->CreateLayoutManagers();
sky7cd307042016-06-01 21:10:48714
[email protected]f5c9dbc2014-04-11 08:13:45715 aura::Window* root_window = GetRootWindow();
[email protected]756bda12013-07-03 08:17:06716
skye782a262016-05-31 20:28:57717 aura::Window* lock_container =
718 root_window->GetChildById(kShellWindowId_LockScreenContainer);
719 DCHECK(lock_container);
720 lock_container->SetLayoutManager(new LockLayoutManager(lock_container));
721
sky0702b272016-06-03 22:10:41722 WmWindow* always_on_top_container =
723 WmWindowAura::Get(GetContainer(kShellWindowId_AlwaysOnTopContainer));
rsadam7bd510bb2014-12-09 20:10:56724 always_on_top_controller_.reset(
725 new AlwaysOnTopController(always_on_top_container));
[email protected]756bda12013-07-03 08:17:06726
jamescook752e8df2016-08-09 19:54:39727 // Create the shelf and status area widgets.
jamescookb551aba2016-09-01 01:00:16728 DCHECK(!wm_shelf_aura_->shelf_widget());
jamescook752e8df2016-08-09 19:54:39729 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
730 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
731 WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container);
732 WmWindow* wm_status_container = WmWindowAura::Get(status_container);
jamescookb551aba2016-09-01 01:00:16733 wm_shelf_aura_->CreateShelfWidget(WmWindowAura::Get(root_window));
734
jamescook752e8df2016-08-09 19:54:39735 // Make it easier to resize windows that partially overlap the shelf. Must
736 // occur after the ShelfLayoutManager is constructed by ShelfWidget.
737 shelf_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
738 wm_shelf_container, wm_shelf_aura_.get()));
739 status_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
740 wm_status_container, wm_shelf_aura_.get()));
741
mswbc0a8b482016-06-30 02:21:14742 if (!WmShell::Get()
743 ->GetSessionStateDelegate()
jamescookb8dcef522016-06-25 14:42:55744 ->IsActiveUserSessionStarted()) {
[email protected]cf6fea22013-08-07 14:24:01745 // 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));
danakjb161836d2015-04-03 05:14:18748 mouse_event_target_->Init(ui::LAYER_NOT_DRAWN);
[email protected]cf6fea22013-08-07 14:24:01749
msw607227f82016-08-30 17:22:39750 aura::Window* lock_wallpaper_container =
751 GetContainer(kShellWindowId_LockScreenWallpaperContainer);
752 lock_wallpaper_container->AddChild(mouse_event_target_.get());
[email protected]cf6fea22013-08-07 14:24:01753 mouse_event_target_->Show();
754 }
755
[email protected]756bda12013-07-03 08:17:06756 // Create Docked windows layout manager
sky0702b272016-06-03 22:10:41757 WmWindow* docked_container =
758 WmWindowAura::Get(GetContainer(kShellWindowId_DockedContainer));
skyca4122692016-04-26 04:47:57759 docked_layout_manager_ = new DockedWindowLayoutManager(docked_container);
sky3f7af8812016-04-21 19:30:03760 docked_container->SetLayoutManager(base::WrapUnique(docked_layout_manager_));
[email protected]756bda12013-07-03 08:17:06761
[email protected]1ca79d42014-07-18 16:26:10762 // Installs SnapLayoutManager to containers who set the
763 // |kSnapsChildrenToPhysicalPixelBoundary| property.
764 wm::InstallSnapLayoutManagerToContainers(root_window);
765
[email protected]756bda12013-07-03 08:17:06766 // Create Panel layout manager
[email protected]093b8d642014-04-03 20:59:28767 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
sky0702b272016-06-03 22:10:41768 WmWindow* wm_panel_container = WmWindowAura::Get(panel_container);
skyad0315022016-04-25 19:40:31769 panel_layout_manager_ = new PanelLayoutManager(wm_panel_container);
770 wm_panel_container->SetLayoutManager(base::WrapUnique(panel_layout_manager_));
[email protected]3537d472014-01-15 05:45:31771 panel_container_handler_.reset(new PanelWindowEventHandler);
772 panel_container->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39773
774 // Install an AttachedPanelWindowTargeter on the panel container to make it
775 // easier to correctly target shelf buttons with touch.
jamescookb8dcef522016-06-25 14:42:55776 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize,
[email protected]b8642ec2014-04-17 05:20:39777 -kResizeOutsideBoundsSize,
778 -kResizeOutsideBoundsSize);
jamescookb8dcef522016-06-25 14:42:55779 gfx::Insets touch_extend =
780 mouse_extend.Scale(kResizeOutsideBoundsScaleForTouch);
dchenga94547472016-04-08 08:41:11781 panel_container->SetEventTargeter(
782 std::unique_ptr<ui::EventTargeter>(new AttachedPanelWindowTargeter(
783 panel_container, mouse_extend, touch_extend, panel_layout_manager_)));
[email protected]756bda12013-07-03 08:17:06784}
785
786void RootWindowController::InitTouchHuds() {
pgal.u-szegedd84534d32014-10-29 12:34:30787 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
[email protected]756bda12013-07-03 08:17:06788 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45789 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06790 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
791 EnableTouchHudProjection();
792}
793
msw607227f82016-08-30 17:22:39794void RootWindowController::CreateSystemWallpaper(bool is_first_run_after_boot) {
[email protected]756bda12013-07-03 08:17:06795 SkColor color = SK_ColorBLACK;
796#if defined(OS_CHROMEOS)
797 if (is_first_run_after_boot)
798 color = kChromeOsBootColor;
799#endif
msw607227f82016-08-30 17:22:39800 system_wallpaper_.reset(
801 new SystemWallpaperController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06802
803#if defined(OS_CHROMEOS)
804 // Make a copy of the system's boot splash screen so we can composite it
msw607227f82016-08-30 17:22:39805 // onscreen until the wallpaper is ready.
[email protected]756bda12013-07-03 08:17:06806 if (is_first_run_after_boot &&
pgal.u-szegedd84534d32014-10-29 12:34:30807 (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]756bda12013-07-03 08:17:06808 switches::kAshCopyHostBackgroundAtBoot) ||
pgal.u-szegedd84534d32014-10-29 12:34:30809 base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]756bda12013-07-03 08:17:06810 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45811 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06812#endif
813}
814
[email protected]d141b922013-07-09 08:13:17815void RootWindowController::EnableTouchHudProjection() {
816 if (touch_hud_projection_)
817 return;
[email protected]f5c9dbc2014-04-11 08:13:45818 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:17819}
820
821void RootWindowController::DisableTouchHudProjection() {
822 if (!touch_hud_projection_)
823 return;
824 touch_hud_projection_->Remove();
825}
826
skye79274a2016-06-08 05:39:02827void RootWindowController::OnLoginStateChanged(LoginStatus status) {
jamescookb551aba2016-09-01 01:00:16828 wm_shelf_aura_->UpdateVisibilityState();
[email protected]d141b922013-07-09 08:13:17829}
830
831void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
832 if (enabled)
833 EnableTouchHudProjection();
834 else
835 DisableTouchHudProjection();
836}
837
jamescookb8dcef522016-06-25 14:42:55838RootWindowController* GetRootWindowController(const aura::Window* root_window) {
msw15156bf2016-09-13 21:49:17839 return root_window ? GetRootWindowSettings(root_window)->controller : nullptr;
[email protected]6b2d4a0b2013-09-06 06:29:54840}
841
[email protected]d90b8392012-06-13 09:34:56842} // namespace ash