blob: 791e4dc0de4a714914a2a78d698f0e1d653e4213 [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
jamescook01bf23e72017-01-09 19:58:1510#include "ash/ash_touch_exploration_manager_chromeos.h"
sky0702b272016-06-03 22:10:4111#include "ash/aura/aura_layout_manager_adapter.h"
skyd053905c2016-08-30 22:37:3512#include "ash/aura/wm_root_window_controller_aura.h"
sky0702b272016-06-03 22:10:4113#include "ash/aura/wm_shelf_aura.h"
14#include "ash/aura/wm_window_aura.h"
jamescooke044e1c2016-06-13 20:56:1815#include "ash/common/ash_constants.h"
mswd9b1b342016-06-17 20:19:5716#include "ash/common/ash_switches.h"
jamescook26f32092016-06-17 04:26:5217#include "ash/common/focus_cycler.h"
mswb2416052016-06-24 21:23:4518#include "ash/common/login_status.h"
jamescook2b624c5a2016-06-08 01:34:0219#include "ash/common/session/session_state_delegate.h"
jamescook361185a22016-08-13 00:12:0920#include "ash/common/shelf/shelf_delegate.h"
mswdf64c66b2016-08-23 18:56:3721#include "ash/common/shelf/shelf_layout_manager.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"
mswdf64c66b2016-08-23 18:56:3724#include "ash/common/system/status_area_layout_manager.h"
jamescook625f7912016-07-14 01:00:5225#include "ash/common/system/status_area_widget.h"
jamescook2a4d1eb2016-06-09 20:10:0726#include "ash/common/system/tray/system_tray_delegate.h"
msw0e91d932016-08-25 22:34:0927#include "ash/common/wallpaper/wallpaper_delegate.h"
msw3f439af2016-09-08 22:35:2628#include "ash/common/wallpaper/wallpaper_widget_controller.h"
skyd6063772016-06-01 17:52:2129#include "ash/common/wm/always_on_top_controller.h"
30#include "ash/common/wm/container_finder.h"
31#include "ash/common/wm/dock/docked_window_layout_manager.h"
32#include "ash/common/wm/fullscreen_window_finder.h"
33#include "ash/common/wm/panels/panel_layout_manager.h"
skyc096d9f2016-06-02 13:46:2634#include "ash/common/wm/root_window_layout_manager.h"
skyd6063772016-06-01 17:52:2135#include "ash/common/wm/switchable_windows.h"
skyea4ca942016-09-12 21:56:1936#include "ash/common/wm/system_modal_container_layout_manager.h"
skyd6063772016-06-01 17:52:2137#include "ash/common/wm/window_state.h"
skyd6063772016-06-01 17:52:2138#include "ash/common/wm/workspace/workspace_layout_manager.h"
skyf71e6c92016-08-30 18:49:1939#include "ash/common/wm/workspace_controller.h"
sky0702b272016-06-03 22:10:4140#include "ash/common/wm_shell.h"
41#include "ash/common/wm_window.h"
[email protected]a273d33a2013-10-17 12:41:2142#include "ash/high_contrast/high_contrast_controller.h"
[email protected]f5c9dbc2014-04-11 08:13:4543#include "ash/host/ash_window_tree_host.h"
jamescookd4649fa2016-09-30 17:50:0944#include "ash/public/cpp/shelf_types.h"
jamescook8800b8232016-10-19 12:46:2745#include "ash/public/cpp/shell_window_ids.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"
jamescook01bf23e72017-01-09 19:58:1552#include "ash/wm/boot_splash_screen_chromeos.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"
jamescook01bf23e72017-01-09 19:58:1564#include "chromeos/chromeos_switches.h"
[email protected]f1853122012-06-27 16:21:2665#include "ui/aura/client/aura_constants.h"
sky92d41b242016-10-27 20:10:1666#include "ui/aura/client/drag_drop_client.h"
[email protected]2374d1812014-03-04 03:42:2767#include "ui/aura/client/screen_position_client.h"
[email protected]f1853122012-06-27 16:21:2668#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2669#include "ui/aura/window_event_dispatcher.h"
[email protected]f1853122012-06-27 16:21:2670#include "ui/aura/window_observer.h"
[email protected]8b3e3d82013-08-20 14:36:3071#include "ui/aura/window_tracker.h"
jamescook01bf23e72017-01-09 19:58:1572#include "ui/chromeos/touch_exploration_controller.h"
kylecharbc3192242016-11-23 00:51:2773#include "ui/display/types/display_constants.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/tooltip_client.h"
[email protected]5b251f12013-12-19 01:50:0582#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5683
[email protected]d90b8392012-06-13 09:34:5684namespace ash {
85namespace {
86
[email protected]bca9a7e2012-11-10 06:25:4987// Duration for the animation that hides the boot splash screen, in
88// milliseconds. This should be short enough in relation to
89// wm/window_animation.cc's brightness/grayscale fade animation that the login
msw607227f82016-08-30 17:22:3990// wallpaper image animation isn't hidden by the splash screen animation.
[email protected]bca9a7e2012-11-10 06:25:4991const int kBootSplashScreenHideDurationMs = 500;
[email protected]bca9a7e2012-11-10 06:25:4992
oshima9a61ecf2016-06-18 10:43:0593bool IsWindowAboveContainer(aura::Window* window,
94 aura::Window* blocking_container) {
95 std::vector<aura::Window*> target_path;
96 std::vector<aura::Window*> blocking_path;
97
98 while (window) {
99 target_path.push_back(window);
100 window = window->parent();
101 }
102
103 while (blocking_container) {
104 blocking_path.push_back(blocking_container);
105 blocking_container = blocking_container->parent();
106 }
107
108 // The root window is put at the end so that we compare windows at
109 // the same depth.
110 while (!blocking_path.empty()) {
111 if (target_path.empty())
112 return false;
113
114 aura::Window* target = target_path.back();
115 target_path.pop_back();
116 aura::Window* blocking = blocking_path.back();
117 blocking_path.pop_back();
118
119 // Still on the same path, continue.
120 if (target == blocking)
121 continue;
122
123 // This can happen only if unparented window is passed because
124 // first element must be the same root.
125 if (!target->parent() || !blocking->parent())
126 return false;
127
128 aura::Window* common_parent = target->parent();
129 DCHECK_EQ(common_parent, blocking->parent());
130 aura::Window::Windows windows = common_parent->children();
131 auto blocking_iter = std::find(windows.begin(), windows.end(), blocking);
132 // If the target window is above blocking window, the window can handle
133 // events.
134 return std::find(blocking_iter, windows.end(), target) != windows.end();
135 }
136
137 return true;
138}
139
[email protected]d90b8392012-06-13 09:34:56140} // namespace
141
[email protected]f5c9dbc2014-04-11 08:13:45142void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38143 RootWindowController* controller = new RootWindowController(host);
jamescookfda159002016-10-21 18:48:57144 controller->Init(RootWindowController::PRIMARY);
[email protected]d90b8392012-06-13 09:34:56145}
146
[email protected]f5c9dbc2014-04-11 08:13:45147void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38148 RootWindowController* controller = new RootWindowController(host);
jamescookfda159002016-10-21 18:48:57149 controller->Init(RootWindowController::SECONDARY);
[email protected]608de6c2013-10-29 00:14:28150}
151
[email protected]88d71122012-10-18 07:11:01152// static
[email protected]ccff3d72013-02-06 04:26:28153RootWindowController* RootWindowController::ForWindow(
154 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07155 CHECK(Shell::HasInstance());
[email protected]a0afeb12012-12-10 22:57:09156 return GetRootWindowController(window->GetRootWindow());
157}
158
159// static
[email protected]d17642d2013-09-12 23:44:38160RootWindowController* RootWindowController::ForTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07161 CHECK(Shell::HasInstance());
[email protected]093b8d642014-04-03 20:59:28162 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09163}
164
[email protected]a273d33a2013-10-17 12:41:21165RootWindowController::~RootWindowController() {
166 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45167 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21168 // The CaptureClient needs to be around for as long as the RootWindow is
169 // valid.
170 capture_client_.reset();
171}
172
[email protected]f5c9dbc2014-04-11 08:13:45173aura::WindowTreeHost* RootWindowController::GetHost() {
174 return ash_host_->AsWindowTreeHost();
175}
176
177const aura::WindowTreeHost* RootWindowController::GetHost() const {
178 return ash_host_->AsWindowTreeHost();
179}
180
181aura::Window* RootWindowController::GetRootWindow() {
182 return GetHost()->window();
183}
184
185const aura::Window* RootWindowController::GetRootWindow() const {
186 return GetHost()->window();
187}
188
skyf71e6c92016-08-30 18:49:19189WorkspaceController* RootWindowController::workspace_controller() {
skyd053905c2016-08-30 22:37:35190 return wm_root_window_controller_->workspace_controller();
skyf71e6c92016-08-30 18:49:19191}
192
[email protected]6675e1c2012-09-11 09:15:45193void RootWindowController::Shutdown() {
sky88bd4be62016-06-09 17:34:41194 WmShell::Get()->RemoveShellObserver(this);
[email protected]a825e8312014-05-05 22:05:01195
sky20686a4c52016-09-13 01:26:54196 touch_exploration_manager_.reset();
[email protected]d141b922013-07-09 08:13:17197
sky8d971a0a2016-09-21 23:37:57198 wm_root_window_controller_->ResetRootForNewWindowsIfNecessary();
[email protected]c98a4922013-09-05 20:01:42199
200 CloseChildWindows();
sky8d971a0a2016-09-21 23:37:57201 aura::Window* root_window = GetRootWindow();
[email protected]f5c9dbc2014-04-11 08:13:45202 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]6675e1c2012-09-11 09:15:45203 // Forget with the display ID so that display lookup
204 // ends up with invalid display.
kylecharbc3192242016-11-23 00:51:27205 GetRootWindowSettings(root_window)->display_id = display::kInvalidDisplayId;
[email protected]8f5209c2014-05-22 20:36:11206 ash_host_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28207
msw607227f82016-08-30 17:22:39208 system_wallpaper_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45209 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56210}
211
oshima9a61ecf2016-06-18 10:43:05212bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) {
213 if (GetRootWindow() != window->GetRootWindow())
214 return false;
215
216 // Always allow events to fall through to the virtual keyboard even if
217 // displaying a system modal dialog.
218 if (IsVirtualKeyboardWindow(window))
219 return true;
220
221 aura::Window* blocking_container = nullptr;
222
223 int modal_container_id = 0;
mswbc0a8b482016-06-30 02:21:14224 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()) {
oshima9a61ecf2016-06-18 10:43:05225 blocking_container =
226 GetContainer(kShellWindowId_LockScreenContainersContainer);
227 modal_container_id = kShellWindowId_LockSystemModalContainer;
228 } else {
229 modal_container_id = kShellWindowId_SystemModalContainer;
230 }
231 aura::Window* modal_container = GetContainer(modal_container_id);
232 SystemModalContainerLayoutManager* modal_layout_manager = nullptr;
233 modal_layout_manager = static_cast<SystemModalContainerLayoutManager*>(
skyea4ca942016-09-12 21:56:19234 WmWindowAura::Get(modal_container)->GetLayoutManager());
oshima9a61ecf2016-06-18 10:43:05235
skyb733d4182016-09-09 23:18:38236 if (modal_layout_manager->has_window_dimmer())
oshima9a61ecf2016-06-18 10:43:05237 blocking_container = modal_container;
238 else
239 modal_container = nullptr; // Don't check modal dialogs.
240
241 // In normal session.
242 if (!blocking_container)
243 return true;
244
245 if (!IsWindowAboveContainer(window, blocking_container))
246 return false;
247
248 // If the window is in the target modal container, only allow the top most
249 // one.
250 if (modal_container && modal_container->Contains(window))
skyea4ca942016-09-12 21:56:19251 return modal_layout_manager->IsPartOfActiveModalWindow(
252 WmWindowAura::Get(window));
oshima9a61ecf2016-06-18 10:43:05253
254 return true;
255}
256
[email protected]d90b8392012-06-13 09:34:56257aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45258 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56259}
260
[email protected]d8a24952013-08-05 20:05:05261const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45262 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05263}
264
msw3f439af2016-09-08 22:35:26265void RootWindowController::OnInitialWallpaperAnimationStarted() {
pgal.u-szegedd84534d32014-10-29 12:34:30266 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]bca9a7e2012-11-10 06:25:49267 switches::kAshAnimateFromBootSplashScreen) &&
268 boot_splash_screen_.get()) {
msw607227f82016-08-30 17:22:39269 // Make the splash screen fade out so it doesn't obscure the wallpaper's
270 // brightness/grayscale animation.
[email protected]bca9a7e2012-11-10 06:25:49271 boot_splash_screen_->StartHideAnimation(
272 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
273 }
[email protected]bca9a7e2012-11-10 06:25:49274}
275
[email protected]0bf61732013-07-02 04:35:10276void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
277 // Make sure the wallpaper is visible.
msw607227f82016-08-30 17:22:39278 system_wallpaper_->SetColor(SK_ColorBLACK);
[email protected]bca9a7e2012-11-10 06:25:49279 boot_splash_screen_.reset();
[email protected]697f04c2012-10-03 01:15:10280}
281
[email protected]d90b8392012-06-13 09:34:56282void RootWindowController::CloseChildWindows() {
sky8d971a0a2016-09-21 23:37:57283 // Remove observer as deactivating keyboard causes
284 // docked_window_layout_manager() to fire notifications.
285 if (docked_window_layout_manager() &&
286 wm_shelf_aura_->shelf_layout_manager()) {
287 docked_window_layout_manager()->RemoveObserver(
jamescookb551aba2016-09-01 01:00:16288 wm_shelf_aura_->shelf_layout_manager());
289 }
[email protected]2a57beb52014-06-09 20:02:26290
[email protected]b6ba05d902013-10-04 21:38:45291 // Deactivate keyboard container before closing child windows and shutting
292 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03293 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45294
sky8d971a0a2016-09-21 23:37:57295 wm_root_window_controller_->CloseChildWindows();
[email protected]e74aaf0a2012-10-12 18:42:28296
sky8d971a0a2016-09-21 23:37:57297 aura::client::SetDragDropClient(GetRootWindow(), nullptr);
298 aura::client::SetTooltipClient(GetRootWindow(), nullptr);
[email protected]d90b8392012-06-13 09:34:56299}
300
[email protected]bf9cdb362013-10-25 19:22:45301void RootWindowController::MoveWindowsTo(aura::Window* dst) {
sky7aff7f8d2016-09-15 23:34:39302 wm_root_window_controller_->MoveWindowsTo(WmWindowAura::Get(dst));
[email protected]f1853122012-06-27 16:21:26303}
304
[email protected]478c6c32013-03-09 02:50:58305ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
jamescookb551aba2016-09-01 01:00:16306 return wm_shelf_aura_->shelf_layout_manager();
307}
308
309StatusAreaWidget* RootWindowController::GetStatusAreaWidget() {
310 ShelfWidget* shelf_widget = wm_shelf_aura_->shelf_widget();
311 return shelf_widget ? shelf_widget->status_area_widget() : nullptr;
[email protected]478c6c32013-03-09 02:50:58312}
313
[email protected]a0afeb12012-12-10 22:57:09314SystemTray* RootWindowController::GetSystemTray() {
315 // We assume in throughout the code that this will not return NULL. If code
316 // triggers this for valid reasons, it should test status_area_widget first.
jamescookb551aba2016-09-01 01:00:16317 CHECK(wm_shelf_aura_->shelf_widget()->status_area_widget());
318 return wm_shelf_aura_->shelf_widget()->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09319}
320
[email protected]e74aaf0a2012-10-12 18:42:28321void RootWindowController::UpdateShelfVisibility() {
jamescookb551aba2016-09-01 01:00:16322 wm_shelf_aura_->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28323}
324
varkhad99fa94f2015-06-29 22:35:46325aura::Window* RootWindowController::GetWindowForFullscreenMode() {
sky0702b272016-06-03 22:10:41326 return WmWindowAura::GetAuraWindow(
327 wm::GetWindowForFullscreenMode(WmWindowAura::Get(GetRootWindow())));
[email protected]2ee2f5d2013-01-10 23:37:16328}
329
[email protected]b6ba05d902013-10-04 21:38:45330void RootWindowController::ActivateKeyboard(
331 keyboard::KeyboardController* keyboard_controller) {
332 if (!keyboard::IsKeyboardEnabled() ||
333 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
334 return;
335 }
336 DCHECK(keyboard_controller);
jamescookb551aba2016-09-01 01:00:16337 keyboard_controller->AddObserver(wm_shelf_aura_->shelf_layout_manager());
sky8d971a0a2016-09-21 23:37:57338 keyboard_controller->AddObserver(panel_layout_manager());
339 keyboard_controller->AddObserver(docked_window_layout_manager());
skyf71e6c92016-08-30 18:49:19340 keyboard_controller->AddObserver(workspace_controller()->layout_manager());
rsadam7bd510bb2014-12-09 20:10:56341 keyboard_controller->AddObserver(
sky8d971a0a2016-09-21 23:37:57342 wm_root_window_controller_->always_on_top_controller()
343 ->GetLayoutManager());
msw61e16672016-08-12 16:36:58344 WmShell::Get()->NotifyVirtualKeyboardActivated(true);
bshec3875422014-09-29 13:21:30345 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52346 DCHECK(parent);
jamescookb8dcef522016-06-25 14:42:55347 aura::Window* keyboard_container = keyboard_controller->GetContainerWindow();
[email protected]b6ba05d902013-10-04 21:38:45348 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
349 parent->AddChild(keyboard_container);
[email protected]b6ba05d902013-10-04 21:38:45350}
[email protected]86459e2c2013-04-10 13:39:24351
[email protected]b6ba05d902013-10-04 21:38:45352void RootWindowController::DeactivateKeyboard(
353 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41354 if (!keyboard_controller ||
355 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45356 return;
[email protected]e1b299b2014-01-29 23:53:41357 }
jamescookb8dcef522016-06-25 14:42:55358 aura::Window* keyboard_container = keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45359 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
bshec3875422014-09-29 13:21:30360 aura::Window* parent =
361 GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52362 DCHECK(parent);
363 parent->RemoveChild(keyboard_container);
bshe9858b4a2014-09-16 20:46:38364 // Virtual keyboard may be deactivated while still showing, notify all
365 // observers that keyboard bounds changed to 0 before remove them.
366 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
jamescookb551aba2016-09-01 01:00:16367 keyboard_controller->RemoveObserver(wm_shelf_aura_->shelf_layout_manager());
sky8d971a0a2016-09-21 23:37:57368 keyboard_controller->RemoveObserver(panel_layout_manager());
369 keyboard_controller->RemoveObserver(docked_window_layout_manager());
bshe9858b4a2014-09-16 20:46:38370 keyboard_controller->RemoveObserver(
skyf71e6c92016-08-30 18:49:19371 workspace_controller()->layout_manager());
rsadam7bd510bb2014-12-09 20:10:56372 keyboard_controller->RemoveObserver(
sky8d971a0a2016-09-21 23:37:57373 wm_root_window_controller_->always_on_top_controller()
374 ->GetLayoutManager());
msw61e16672016-08-12 16:36:58375 WmShell::Get()->NotifyVirtualKeyboardActivated(false);
[email protected]86459e2c2013-04-10 13:39:24376 }
377}
378
[email protected]602022b2014-03-31 17:07:31379bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
bshec3875422014-09-29 13:21:30380 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]602022b2014-03-31 17:07:31381 return parent ? parent->Contains(window) : false;
382}
383
dmazzoniff86e3472016-06-03 19:52:32384void RootWindowController::SetTouchAccessibilityAnchorPoint(
385 const gfx::Point& anchor_point) {
dmazzoniff86e3472016-06-03 19:52:32386 if (touch_exploration_manager_)
387 touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point);
dmazzoniff86e3472016-06-03 19:52:32388}
389
[email protected]a4cd6d32012-09-12 03:42:13390////////////////////////////////////////////////////////////////////////////////
391// RootWindowController, private:
392
[email protected]f5c9dbc2014-04-11 08:13:45393RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
394 : ash_host_(ash_host),
jamescookbe6ed822016-06-06 20:08:55395 wm_shelf_aura_(new WmShelfAura),
[email protected]a273d33a2013-10-17 12:41:21396 touch_hud_debug_(NULL),
397 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45398 aura::Window* root_window = GetRootWindow();
399 GetRootWindowSettings(root_window)->controller = this;
[email protected]a273d33a2013-10-17 12:41:21400
skyd053905c2016-08-30 22:37:35401 // Has to happen after this is set as |controller| of RootWindowSettings.
402 wm_root_window_controller_ = WmRootWindowControllerAura::Get(root_window);
403
[email protected]a273d33a2013-10-17 12:41:21404 stacking_controller_.reset(new StackingController);
sky28f20d62016-10-20 23:21:59405 aura::client::SetWindowParentingClient(root_window,
406 stacking_controller_.get());
[email protected]f5c9dbc2014-04-11 08:13:45407 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21408}
409
jamescookfda159002016-10-21 18:48:57410void RootWindowController::Init(RootWindowType root_window_type) {
[email protected]f5c9dbc2014-04-11 08:13:45411 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50412 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45413 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21414
skyd053905c2016-08-30 22:37:35415 wm_root_window_controller_->CreateContainers();
[email protected]608de6c2013-10-29 00:14:28416
jamescookfda159002016-10-21 18:48:57417 CreateSystemWallpaper(root_window_type);
[email protected]a273d33a2013-10-17 12:41:21418
419 InitLayoutManagers();
420 InitTouchHuds();
421
skyea4ca942016-09-12 21:56:19422 if (WmShell::Get()
423 ->GetPrimaryRootWindowController()
skyb733d4182016-09-09 23:18:38424 ->GetSystemModalLayoutManager(nullptr)
425 ->has_window_dimmer()) {
skyea4ca942016-09-12 21:56:19426 wm_root_window_controller_->GetSystemModalLayoutManager(nullptr)
427 ->CreateModalBackground();
[email protected]a273d33a2013-10-17 12:41:21428 }
429
sky88bd4be62016-06-09 17:34:41430 WmShell::Get()->AddShellObserver(this);
[email protected]a273d33a2013-10-17 12:41:21431
skyd053905c2016-08-30 22:37:35432 wm_root_window_controller_->root_window_layout_manager()->OnWindowResized();
[email protected]608de6c2013-10-29 00:14:28433 if (root_window_type == PRIMARY) {
bshe9858b4a2014-09-16 20:46:38434 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21435 } else {
[email protected]f5c9dbc2014-04-11 08:13:45436 ash_host_->AsWindowTreeHost()->Show();
[email protected]a273d33a2013-10-17 12:41:21437
[email protected]864b58552013-12-19 04:19:38438 // Create a shelf if a user is already logged in.
mswbc0a8b482016-06-30 02:21:14439 if (WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers())
skyd52346b2016-10-07 15:43:50440 wm_root_window_controller_->CreateShelf();
[email protected]0e3e7cb2014-04-12 05:18:25441
442 // Notify shell observers about new root window.
sky80556bc42016-06-07 22:46:13443 shell->OnRootWindowAdded(WmWindowAura::Get(root_window));
[email protected]a273d33a2013-10-17 12:41:21444 }
[email protected]a825e8312014-05-05 22:05:01445
pgal.u-szegedd84534d32014-10-29 12:34:30446 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]2e0b2352014-07-28 13:28:28447 switches::kAshDisableTouchExplorationMode)) {
[email protected]7d487592014-07-24 03:54:50448 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
[email protected]a825e8312014-05-05 22:05:01449 }
[email protected]a273d33a2013-10-17 12:41:21450}
451
[email protected]756bda12013-07-03 08:17:06452void RootWindowController::InitLayoutManagers() {
jamescook752e8df2016-08-09 19:54:39453 // Create the shelf and status area widgets.
jamescookb551aba2016-09-01 01:00:16454 DCHECK(!wm_shelf_aura_->shelf_widget());
jamescook752e8df2016-08-09 19:54:39455 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
456 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
457 WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container);
458 WmWindow* wm_status_container = WmWindowAura::Get(status_container);
sky8d971a0a2016-09-21 23:37:57459
460 wm_root_window_controller_->CreateLayoutManagers();
jamescookb551aba2016-09-01 01:00:16461
jamescook752e8df2016-08-09 19:54:39462 // Make it easier to resize windows that partially overlap the shelf. Must
463 // occur after the ShelfLayoutManager is constructed by ShelfWidget.
464 shelf_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
465 wm_shelf_container, wm_shelf_aura_.get()));
466 status_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
467 wm_status_container, wm_shelf_aura_.get()));
468
sky8d971a0a2016-09-21 23:37:57469 panel_container_handler_ = base::MakeUnique<PanelWindowEventHandler>();
470 GetContainer(kShellWindowId_PanelContainer)
471 ->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39472
473 // Install an AttachedPanelWindowTargeter on the panel container to make it
474 // easier to correctly target shelf buttons with touch.
jamescookb8dcef522016-06-25 14:42:55475 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize,
[email protected]b8642ec2014-04-17 05:20:39476 -kResizeOutsideBoundsSize,
477 -kResizeOutsideBoundsSize);
jamescookb8dcef522016-06-25 14:42:55478 gfx::Insets touch_extend =
479 mouse_extend.Scale(kResizeOutsideBoundsScaleForTouch);
sky8d971a0a2016-09-21 23:37:57480 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
481 panel_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
482 new AttachedPanelWindowTargeter(panel_container, mouse_extend,
483 touch_extend, panel_layout_manager())));
[email protected]756bda12013-07-03 08:17:06484}
485
486void RootWindowController::InitTouchHuds() {
pgal.u-szegedd84534d32014-10-29 12:34:30487 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
[email protected]756bda12013-07-03 08:17:06488 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45489 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06490 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
491 EnableTouchHudProjection();
492}
493
jamescookfda159002016-10-21 18:48:57494void RootWindowController::CreateSystemWallpaper(
495 RootWindowType root_window_type) {
[email protected]756bda12013-07-03 08:17:06496 SkColor color = SK_ColorBLACK;
jamescookfda159002016-10-21 18:48:57497 // The splash screen appears on the primary display at boot. If this is a
498 // secondary monitor (either connected at boot or connected later) or if the
499 // browser restarted for a second login then don't use the boot color.
500 const bool is_boot_splash_screen =
501 root_window_type == PRIMARY &&
502 base::CommandLine::ForCurrentProcess()->HasSwitch(
503 chromeos::switches::kFirstExecAfterBoot);
504 if (is_boot_splash_screen)
[email protected]756bda12013-07-03 08:17:06505 color = kChromeOsBootColor;
msw607227f82016-08-30 17:22:39506 system_wallpaper_.reset(
507 new SystemWallpaperController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06508
[email protected]756bda12013-07-03 08:17:06509 // Make a copy of the system's boot splash screen so we can composite it
msw607227f82016-08-30 17:22:39510 // onscreen until the wallpaper is ready.
jamescookfda159002016-10-21 18:48:57511 if (is_boot_splash_screen &&
pgal.u-szegedd84534d32014-10-29 12:34:30512 (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]756bda12013-07-03 08:17:06513 switches::kAshCopyHostBackgroundAtBoot) ||
pgal.u-szegedd84534d32014-10-29 12:34:30514 base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]756bda12013-07-03 08:17:06515 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45516 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06517}
518
[email protected]d141b922013-07-09 08:13:17519void RootWindowController::EnableTouchHudProjection() {
520 if (touch_hud_projection_)
521 return;
[email protected]f5c9dbc2014-04-11 08:13:45522 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:17523}
524
525void RootWindowController::DisableTouchHudProjection() {
526 if (!touch_hud_projection_)
527 return;
528 touch_hud_projection_->Remove();
529}
530
sky8d971a0a2016-09-21 23:37:57531DockedWindowLayoutManager*
532RootWindowController::docked_window_layout_manager() {
533 return wm_root_window_controller_->docked_window_layout_manager();
534}
535
536PanelLayoutManager* RootWindowController::panel_layout_manager() {
537 return wm_root_window_controller_->panel_layout_manager();
538}
539
skye79274a2016-06-08 05:39:02540void RootWindowController::OnLoginStateChanged(LoginStatus status) {
jamescookb551aba2016-09-01 01:00:16541 wm_shelf_aura_->UpdateVisibilityState();
[email protected]d141b922013-07-09 08:13:17542}
543
544void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
545 if (enabled)
546 EnableTouchHudProjection();
547 else
548 DisableTouchHudProjection();
549}
550
jamescookb8dcef522016-06-25 14:42:55551RootWindowController* GetRootWindowController(const aura::Window* root_window) {
msw15156bf2016-09-13 21:49:17552 return root_window ? GetRootWindowSettings(root_window)->controller : nullptr;
[email protected]6b2d4a0b2013-09-06 06:29:54553}
554
[email protected]d90b8392012-06-13 09:34:56555} // namespace ash