blob: 960c5ccfb66b2943601b0e1aca7e1e80048baec7 [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"
mswdf64c66b2016-08-23 18:56:3721#include "ash/common/shelf/shelf_widget.h"
msw0414d4122016-07-06 22:58:4822#include "ash/common/shell_delegate.h"
mswdf64c66b2016-08-23 18:56:3723#include "ash/common/system/status_area_layout_manager.h"
jamescook625f7912016-07-14 01:00:5224#include "ash/common/system/status_area_widget.h"
jamescook2a4d1eb2016-06-09 20:10:0725#include "ash/common/system/tray/system_tray_delegate.h"
msw0e91d932016-08-25 22:34:0926#include "ash/common/wallpaper/wallpaper_delegate.h"
msw3f439af2016-09-08 22:35:2627#include "ash/common/wallpaper/wallpaper_widget_controller.h"
skyd6063772016-06-01 17:52:2128#include "ash/common/wm/always_on_top_controller.h"
29#include "ash/common/wm/container_finder.h"
30#include "ash/common/wm/dock/docked_window_layout_manager.h"
31#include "ash/common/wm/fullscreen_window_finder.h"
32#include "ash/common/wm/panels/panel_layout_manager.h"
skyc096d9f2016-06-02 13:46:2633#include "ash/common/wm/root_window_layout_manager.h"
skyd6063772016-06-01 17:52:2134#include "ash/common/wm/switchable_windows.h"
skyea4ca942016-09-12 21:56:1935#include "ash/common/wm/system_modal_container_layout_manager.h"
skyd6063772016-06-01 17:52:2136#include "ash/common/wm/window_state.h"
skyd6063772016-06-01 17:52:2137#include "ash/common/wm/workspace/workspace_layout_manager.h"
skyf71e6c92016-08-30 18:49:1938#include "ash/common/wm/workspace_controller.h"
sky0702b272016-06-03 22:10:4139#include "ash/common/wm_shell.h"
40#include "ash/common/wm_window.h"
[email protected]a273d33a2013-10-17 12:41:2141#include "ash/high_contrast/high_contrast_controller.h"
[email protected]f5c9dbc2014-04-11 08:13:4542#include "ash/host/ash_window_tree_host.h"
jamescookd4649fa2016-09-30 17:50:0943#include "ash/public/cpp/shelf_types.h"
jamescook8800b8232016-10-19 12:46:2744#include "ash/public/cpp/shell_window_ids.h"
[email protected]f8e6aad2013-08-30 21:49:1145#include "ash/root_window_settings.h"
jamescook752e8df2016-08-09 19:54:3946#include "ash/shelf/shelf_window_targeter.h"
[email protected]d90b8392012-06-13 09:34:5647#include "ash/shell.h"
[email protected]2b8a9bb2013-07-01 22:43:4048#include "ash/touch/touch_hud_debug.h"
49#include "ash/touch/touch_hud_projection.h"
[email protected]80549c152013-07-02 01:42:4750#include "ash/touch/touch_observer_hud.h"
[email protected]b8642ec2014-04-17 05:20:3951#include "ash/wm/panels/attached_panel_window_targeter.h"
[email protected]100659412013-06-21 22:59:5552#include "ash/wm/panels/panel_window_event_handler.h"
[email protected]2a2caa02013-01-22 20:50:3653#include "ash/wm/stacking_controller.h"
msw607227f82016-08-30 17:22:3954#include "ash/wm/system_wallpaper_controller.h"
[email protected]8d625fb2012-07-18 16:40:0655#include "ash/wm/window_properties.h"
sky8d5646fe2016-04-15 17:03:4656#include "ash/wm/window_state_aura.h"
[email protected]700849f2013-04-30 17:49:2057#include "ash/wm/window_util.h"
[email protected]e6e41d2f2012-10-29 19:22:1958#include "base/command_line.h"
jonrossa90d8982016-05-16 18:14:2559#include "base/macros.h"
sky1e30f062016-04-14 21:19:1660#include "base/memory/ptr_util.h"
[email protected]1e84c632013-06-27 23:12:2161#include "base/time/time.h"
[email protected]f1853122012-06-27 16:21:2662#include "ui/aura/client/aura_constants.h"
sky92d41b242016-10-27 20:10:1663#include "ui/aura/client/drag_drop_client.h"
[email protected]2374d1812014-03-04 03:42:2764#include "ui/aura/client/screen_position_client.h"
[email protected]f1853122012-06-27 16:21:2665#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2666#include "ui/aura/window_event_dispatcher.h"
[email protected]f1853122012-06-27 16:21:2667#include "ui/aura/window_observer.h"
[email protected]8b3e3d82013-08-20 14:36:3068#include "ui/aura/window_tracker.h"
oshimaf84b0da722016-04-27 19:47:1969#include "ui/display/display.h"
rjkroege72f8154f2016-10-29 00:49:0270#include "ui/display/manager/display_manager.h"
oshimaf84b0da722016-04-27 19:47:1971#include "ui/display/screen.h"
kylecharbc3192242016-11-23 00:51:2772#include "ui/display/types/display_constants.h"
[email protected]86459e2c2013-04-10 13:39:2473#include "ui/keyboard/keyboard_controller.h"
74#include "ui/keyboard/keyboard_util.h"
[email protected]431552c2012-10-23 00:38:3375#include "ui/views/view_model.h"
76#include "ui/views/view_model_utils.h"
[email protected]ee3ed10772014-03-11 22:02:0177#include "ui/wm/core/capture_controller.h"
78#include "ui/wm/core/visibility_controller.h"
79#include "ui/wm/core/window_util.h"
[email protected]af4552b22014-03-21 19:45:0180#include "ui/wm/public/tooltip_client.h"
[email protected]5b251f12013-12-19 01:50:0581#include "ui/wm/public/window_types.h"
[email protected]d90b8392012-06-13 09:34:5682
[email protected]252eb232013-08-14 22:09:2783#if defined(OS_CHROMEOS)
[email protected]7d487592014-07-24 03:54:5084#include "ash/ash_touch_exploration_manager_chromeos.h"
[email protected]252eb232013-08-14 22:09:2785#include "ash/wm/boot_splash_screen_chromeos.h"
jamescookfda159002016-10-21 18:48:5786#include "chromeos/chromeos_switches.h"
[email protected]a825e8312014-05-05 22:05:0187#include "ui/chromeos/touch_exploration_controller.h"
[email protected]252eb232013-08-14 22:09:2788#endif
89
[email protected]d90b8392012-06-13 09:34:5690namespace ash {
91namespace {
92
[email protected]252eb232013-08-14 22:09:2793#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:4994// Duration for the animation that hides the boot splash screen, in
95// milliseconds. This should be short enough in relation to
96// wm/window_animation.cc's brightness/grayscale fade animation that the login
msw607227f82016-08-30 17:22:3997// wallpaper image animation isn't hidden by the splash screen animation.
[email protected]bca9a7e2012-11-10 06:25:4998const int kBootSplashScreenHideDurationMs = 500;
[email protected]252eb232013-08-14 22:09:2799#endif
[email protected]bca9a7e2012-11-10 06:25:49100
oshima9a61ecf2016-06-18 10:43:05101bool IsWindowAboveContainer(aura::Window* window,
102 aura::Window* blocking_container) {
103 std::vector<aura::Window*> target_path;
104 std::vector<aura::Window*> blocking_path;
105
106 while (window) {
107 target_path.push_back(window);
108 window = window->parent();
109 }
110
111 while (blocking_container) {
112 blocking_path.push_back(blocking_container);
113 blocking_container = blocking_container->parent();
114 }
115
116 // The root window is put at the end so that we compare windows at
117 // the same depth.
118 while (!blocking_path.empty()) {
119 if (target_path.empty())
120 return false;
121
122 aura::Window* target = target_path.back();
123 target_path.pop_back();
124 aura::Window* blocking = blocking_path.back();
125 blocking_path.pop_back();
126
127 // Still on the same path, continue.
128 if (target == blocking)
129 continue;
130
131 // This can happen only if unparented window is passed because
132 // first element must be the same root.
133 if (!target->parent() || !blocking->parent())
134 return false;
135
136 aura::Window* common_parent = target->parent();
137 DCHECK_EQ(common_parent, blocking->parent());
138 aura::Window::Windows windows = common_parent->children();
139 auto blocking_iter = std::find(windows.begin(), windows.end(), blocking);
140 // If the target window is above blocking window, the window can handle
141 // events.
142 return std::find(blocking_iter, windows.end(), target) != windows.end();
143 }
144
145 return true;
146}
147
[email protected]d90b8392012-06-13 09:34:56148} // namespace
149
[email protected]f5c9dbc2014-04-11 08:13:45150void RootWindowController::CreateForPrimaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38151 RootWindowController* controller = new RootWindowController(host);
jamescookfda159002016-10-21 18:48:57152 controller->Init(RootWindowController::PRIMARY);
[email protected]d90b8392012-06-13 09:34:56153}
154
[email protected]f5c9dbc2014-04-11 08:13:45155void RootWindowController::CreateForSecondaryDisplay(AshWindowTreeHost* host) {
[email protected]2f2620332014-02-28 10:07:38156 RootWindowController* controller = new RootWindowController(host);
jamescookfda159002016-10-21 18:48:57157 controller->Init(RootWindowController::SECONDARY);
[email protected]608de6c2013-10-29 00:14:28158}
159
[email protected]88d71122012-10-18 07:11:01160// static
[email protected]ccff3d72013-02-06 04:26:28161RootWindowController* RootWindowController::ForWindow(
162 const aura::Window* window) {
oshima9eea82da2014-09-13 01:11:07163 CHECK(Shell::HasInstance());
[email protected]a0afeb12012-12-10 22:57:09164 return GetRootWindowController(window->GetRootWindow());
165}
166
167// static
[email protected]d17642d2013-09-12 23:44:38168RootWindowController* RootWindowController::ForTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07169 CHECK(Shell::HasInstance());
[email protected]093b8d642014-04-03 20:59:28170 return GetRootWindowController(Shell::GetTargetRootWindow());
[email protected]a0afeb12012-12-10 22:57:09171}
172
[email protected]a273d33a2013-10-17 12:41:21173RootWindowController::~RootWindowController() {
174 Shutdown();
[email protected]f5c9dbc2014-04-11 08:13:45175 ash_host_.reset();
[email protected]a273d33a2013-10-17 12:41:21176 // The CaptureClient needs to be around for as long as the RootWindow is
177 // valid.
178 capture_client_.reset();
179}
180
[email protected]f5c9dbc2014-04-11 08:13:45181aura::WindowTreeHost* RootWindowController::GetHost() {
182 return ash_host_->AsWindowTreeHost();
183}
184
185const aura::WindowTreeHost* RootWindowController::GetHost() const {
186 return ash_host_->AsWindowTreeHost();
187}
188
189aura::Window* RootWindowController::GetRootWindow() {
190 return GetHost()->window();
191}
192
193const aura::Window* RootWindowController::GetRootWindow() const {
194 return GetHost()->window();
195}
196
skyf71e6c92016-08-30 18:49:19197WorkspaceController* RootWindowController::workspace_controller() {
skyd053905c2016-08-30 22:37:35198 return wm_root_window_controller_->workspace_controller();
skyf71e6c92016-08-30 18:49:19199}
200
[email protected]6675e1c2012-09-11 09:15:45201void RootWindowController::Shutdown() {
sky88bd4be62016-06-09 17:34:41202 WmShell::Get()->RemoveShellObserver(this);
[email protected]a825e8312014-05-05 22:05:01203
204#if defined(OS_CHROMEOS)
sky20686a4c52016-09-13 01:26:54205 touch_exploration_manager_.reset();
[email protected]a825e8312014-05-05 22:05:01206#endif
[email protected]d141b922013-07-09 08:13:17207
sky8d971a0a2016-09-21 23:37:57208 wm_root_window_controller_->ResetRootForNewWindowsIfNecessary();
[email protected]c98a4922013-09-05 20:01:42209
210 CloseChildWindows();
sky8d971a0a2016-09-21 23:37:57211 aura::Window* root_window = GetRootWindow();
[email protected]f5c9dbc2014-04-11 08:13:45212 GetRootWindowSettings(root_window)->controller = NULL;
[email protected]6675e1c2012-09-11 09:15:45213 // Forget with the display ID so that display lookup
214 // ends up with invalid display.
kylecharbc3192242016-11-23 00:51:27215 GetRootWindowSettings(root_window)->display_id = display::kInvalidDisplayId;
[email protected]8f5209c2014-05-22 20:36:11216 ash_host_->PrepareForShutdown();
[email protected]e74aaf0a2012-10-12 18:42:28217
msw607227f82016-08-30 17:22:39218 system_wallpaper_.reset();
[email protected]f5c9dbc2014-04-11 08:13:45219 aura::client::SetScreenPositionClient(root_window, NULL);
[email protected]d90b8392012-06-13 09:34:56220}
221
oshima9a61ecf2016-06-18 10:43:05222bool RootWindowController::CanWindowReceiveEvents(aura::Window* window) {
223 if (GetRootWindow() != window->GetRootWindow())
224 return false;
225
226 // Always allow events to fall through to the virtual keyboard even if
227 // displaying a system modal dialog.
228 if (IsVirtualKeyboardWindow(window))
229 return true;
230
231 aura::Window* blocking_container = nullptr;
232
233 int modal_container_id = 0;
mswbc0a8b482016-06-30 02:21:14234 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked()) {
oshima9a61ecf2016-06-18 10:43:05235 blocking_container =
236 GetContainer(kShellWindowId_LockScreenContainersContainer);
237 modal_container_id = kShellWindowId_LockSystemModalContainer;
238 } else {
239 modal_container_id = kShellWindowId_SystemModalContainer;
240 }
241 aura::Window* modal_container = GetContainer(modal_container_id);
242 SystemModalContainerLayoutManager* modal_layout_manager = nullptr;
243 modal_layout_manager = static_cast<SystemModalContainerLayoutManager*>(
skyea4ca942016-09-12 21:56:19244 WmWindowAura::Get(modal_container)->GetLayoutManager());
oshima9a61ecf2016-06-18 10:43:05245
skyb733d4182016-09-09 23:18:38246 if (modal_layout_manager->has_window_dimmer())
oshima9a61ecf2016-06-18 10:43:05247 blocking_container = modal_container;
248 else
249 modal_container = nullptr; // Don't check modal dialogs.
250
251 // In normal session.
252 if (!blocking_container)
253 return true;
254
255 if (!IsWindowAboveContainer(window, blocking_container))
256 return false;
257
258 // If the window is in the target modal container, only allow the top most
259 // one.
260 if (modal_container && modal_container->Contains(window))
skyea4ca942016-09-12 21:56:19261 return modal_layout_manager->IsPartOfActiveModalWindow(
262 WmWindowAura::Get(window));
oshima9a61ecf2016-06-18 10:43:05263
264 return true;
265}
266
[email protected]d90b8392012-06-13 09:34:56267aura::Window* RootWindowController::GetContainer(int container_id) {
[email protected]f5c9dbc2014-04-11 08:13:45268 return GetRootWindow()->GetChildById(container_id);
[email protected]d90b8392012-06-13 09:34:56269}
270
[email protected]d8a24952013-08-05 20:05:05271const aura::Window* RootWindowController::GetContainer(int container_id) const {
[email protected]f5c9dbc2014-04-11 08:13:45272 return ash_host_->AsWindowTreeHost()->window()->GetChildById(container_id);
[email protected]d8a24952013-08-05 20:05:05273}
274
msw3f439af2016-09-08 22:35:26275void RootWindowController::OnInitialWallpaperAnimationStarted() {
[email protected]252eb232013-08-14 22:09:27276#if defined(OS_CHROMEOS)
pgal.u-szegedd84534d32014-10-29 12:34:30277 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]bca9a7e2012-11-10 06:25:49278 switches::kAshAnimateFromBootSplashScreen) &&
279 boot_splash_screen_.get()) {
msw607227f82016-08-30 17:22:39280 // Make the splash screen fade out so it doesn't obscure the wallpaper's
281 // brightness/grayscale animation.
[email protected]bca9a7e2012-11-10 06:25:49282 boot_splash_screen_->StartHideAnimation(
283 base::TimeDelta::FromMilliseconds(kBootSplashScreenHideDurationMs));
284 }
[email protected]252eb232013-08-14 22:09:27285#endif
[email protected]bca9a7e2012-11-10 06:25:49286}
287
[email protected]0bf61732013-07-02 04:35:10288void RootWindowController::OnWallpaperAnimationFinished(views::Widget* widget) {
289 // Make sure the wallpaper is visible.
msw607227f82016-08-30 17:22:39290 system_wallpaper_->SetColor(SK_ColorBLACK);
[email protected]252eb232013-08-14 22:09:27291#if defined(OS_CHROMEOS)
[email protected]bca9a7e2012-11-10 06:25:49292 boot_splash_screen_.reset();
[email protected]252eb232013-08-14 22:09:27293#endif
[email protected]697f04c2012-10-03 01:15:10294}
295
[email protected]d90b8392012-06-13 09:34:56296void RootWindowController::CloseChildWindows() {
sky8d971a0a2016-09-21 23:37:57297 // Remove observer as deactivating keyboard causes
298 // docked_window_layout_manager() to fire notifications.
299 if (docked_window_layout_manager() &&
300 wm_shelf_aura_->shelf_layout_manager()) {
301 docked_window_layout_manager()->RemoveObserver(
jamescookb551aba2016-09-01 01:00:16302 wm_shelf_aura_->shelf_layout_manager());
303 }
[email protected]2a57beb52014-06-09 20:02:26304
[email protected]b6ba05d902013-10-04 21:38:45305 // Deactivate keyboard container before closing child windows and shutting
306 // down associated layout managers.
[email protected]a0b3fb882014-04-07 19:26:03307 DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:45308
sky8d971a0a2016-09-21 23:37:57309 wm_root_window_controller_->CloseChildWindows();
[email protected]e74aaf0a2012-10-12 18:42:28310
sky8d971a0a2016-09-21 23:37:57311 aura::client::SetDragDropClient(GetRootWindow(), nullptr);
312 aura::client::SetTooltipClient(GetRootWindow(), nullptr);
[email protected]d90b8392012-06-13 09:34:56313}
314
[email protected]bf9cdb362013-10-25 19:22:45315void RootWindowController::MoveWindowsTo(aura::Window* dst) {
sky7aff7f8d2016-09-15 23:34:39316 wm_root_window_controller_->MoveWindowsTo(WmWindowAura::Get(dst));
[email protected]f1853122012-06-27 16:21:26317}
318
[email protected]478c6c32013-03-09 02:50:58319ShelfLayoutManager* RootWindowController::GetShelfLayoutManager() {
jamescookb551aba2016-09-01 01:00:16320 return wm_shelf_aura_->shelf_layout_manager();
321}
322
323StatusAreaWidget* RootWindowController::GetStatusAreaWidget() {
324 ShelfWidget* shelf_widget = wm_shelf_aura_->shelf_widget();
325 return shelf_widget ? shelf_widget->status_area_widget() : nullptr;
[email protected]478c6c32013-03-09 02:50:58326}
327
[email protected]a0afeb12012-12-10 22:57:09328SystemTray* RootWindowController::GetSystemTray() {
329 // We assume in throughout the code that this will not return NULL. If code
330 // triggers this for valid reasons, it should test status_area_widget first.
jamescookb551aba2016-09-01 01:00:16331 CHECK(wm_shelf_aura_->shelf_widget()->status_area_widget());
332 return wm_shelf_aura_->shelf_widget()->status_area_widget()->system_tray();
[email protected]a0afeb12012-12-10 22:57:09333}
334
[email protected]e74aaf0a2012-10-12 18:42:28335void RootWindowController::UpdateShelfVisibility() {
jamescookb551aba2016-09-01 01:00:16336 wm_shelf_aura_->UpdateVisibilityState();
[email protected]e74aaf0a2012-10-12 18:42:28337}
338
varkhad99fa94f2015-06-29 22:35:46339aura::Window* RootWindowController::GetWindowForFullscreenMode() {
sky0702b272016-06-03 22:10:41340 return WmWindowAura::GetAuraWindow(
341 wm::GetWindowForFullscreenMode(WmWindowAura::Get(GetRootWindow())));
[email protected]2ee2f5d2013-01-10 23:37:16342}
343
[email protected]b6ba05d902013-10-04 21:38:45344void RootWindowController::ActivateKeyboard(
345 keyboard::KeyboardController* keyboard_controller) {
346 if (!keyboard::IsKeyboardEnabled() ||
347 GetContainer(kShellWindowId_VirtualKeyboardContainer)) {
348 return;
349 }
350 DCHECK(keyboard_controller);
jamescookb551aba2016-09-01 01:00:16351 keyboard_controller->AddObserver(wm_shelf_aura_->shelf_layout_manager());
sky8d971a0a2016-09-21 23:37:57352 keyboard_controller->AddObserver(panel_layout_manager());
353 keyboard_controller->AddObserver(docked_window_layout_manager());
skyf71e6c92016-08-30 18:49:19354 keyboard_controller->AddObserver(workspace_controller()->layout_manager());
rsadam7bd510bb2014-12-09 20:10:56355 keyboard_controller->AddObserver(
sky8d971a0a2016-09-21 23:37:57356 wm_root_window_controller_->always_on_top_controller()
357 ->GetLayoutManager());
msw61e16672016-08-12 16:36:58358 WmShell::Get()->NotifyVirtualKeyboardActivated(true);
bshec3875422014-09-29 13:21:30359 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52360 DCHECK(parent);
jamescookb8dcef522016-06-25 14:42:55361 aura::Window* keyboard_container = keyboard_controller->GetContainerWindow();
[email protected]b6ba05d902013-10-04 21:38:45362 keyboard_container->set_id(kShellWindowId_VirtualKeyboardContainer);
363 parent->AddChild(keyboard_container);
[email protected]b6ba05d902013-10-04 21:38:45364}
[email protected]86459e2c2013-04-10 13:39:24365
[email protected]b6ba05d902013-10-04 21:38:45366void RootWindowController::DeactivateKeyboard(
367 keyboard::KeyboardController* keyboard_controller) {
[email protected]e1b299b2014-01-29 23:53:41368 if (!keyboard_controller ||
369 !keyboard_controller->keyboard_container_initialized()) {
[email protected]b6ba05d902013-10-04 21:38:45370 return;
[email protected]e1b299b2014-01-29 23:53:41371 }
jamescookb8dcef522016-06-25 14:42:55372 aura::Window* keyboard_container = keyboard_controller->GetContainerWindow();
[email protected]f5c9dbc2014-04-11 08:13:45373 if (keyboard_container->GetRootWindow() == GetRootWindow()) {
bshec3875422014-09-29 13:21:30374 aura::Window* parent =
375 GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]b2da9b602014-03-05 18:39:52376 DCHECK(parent);
377 parent->RemoveChild(keyboard_container);
bshe9858b4a2014-09-16 20:46:38378 // Virtual keyboard may be deactivated while still showing, notify all
379 // observers that keyboard bounds changed to 0 before remove them.
380 keyboard_controller->NotifyKeyboardBoundsChanging(gfx::Rect());
jamescookb551aba2016-09-01 01:00:16381 keyboard_controller->RemoveObserver(wm_shelf_aura_->shelf_layout_manager());
sky8d971a0a2016-09-21 23:37:57382 keyboard_controller->RemoveObserver(panel_layout_manager());
383 keyboard_controller->RemoveObserver(docked_window_layout_manager());
bshe9858b4a2014-09-16 20:46:38384 keyboard_controller->RemoveObserver(
skyf71e6c92016-08-30 18:49:19385 workspace_controller()->layout_manager());
rsadam7bd510bb2014-12-09 20:10:56386 keyboard_controller->RemoveObserver(
sky8d971a0a2016-09-21 23:37:57387 wm_root_window_controller_->always_on_top_controller()
388 ->GetLayoutManager());
msw61e16672016-08-12 16:36:58389 WmShell::Get()->NotifyVirtualKeyboardActivated(false);
[email protected]86459e2c2013-04-10 13:39:24390 }
391}
392
[email protected]602022b2014-03-31 17:07:31393bool RootWindowController::IsVirtualKeyboardWindow(aura::Window* window) {
bshec3875422014-09-29 13:21:30394 aura::Window* parent = GetContainer(kShellWindowId_ImeWindowParentContainer);
[email protected]602022b2014-03-31 17:07:31395 return parent ? parent->Contains(window) : false;
396}
397
dmazzoniff86e3472016-06-03 19:52:32398void RootWindowController::SetTouchAccessibilityAnchorPoint(
399 const gfx::Point& anchor_point) {
400#if defined(OS_CHROMEOS)
401 if (touch_exploration_manager_)
402 touch_exploration_manager_->SetTouchAccessibilityAnchorPoint(anchor_point);
403#endif // defined(OS_CHROMEOS)
404}
405
[email protected]a4cd6d32012-09-12 03:42:13406////////////////////////////////////////////////////////////////////////////////
407// RootWindowController, private:
408
[email protected]f5c9dbc2014-04-11 08:13:45409RootWindowController::RootWindowController(AshWindowTreeHost* ash_host)
410 : ash_host_(ash_host),
jamescookbe6ed822016-06-06 20:08:55411 wm_shelf_aura_(new WmShelfAura),
[email protected]a273d33a2013-10-17 12:41:21412 touch_hud_debug_(NULL),
413 touch_hud_projection_(NULL) {
[email protected]f5c9dbc2014-04-11 08:13:45414 aura::Window* root_window = GetRootWindow();
415 GetRootWindowSettings(root_window)->controller = this;
[email protected]a273d33a2013-10-17 12:41:21416
skyd053905c2016-08-30 22:37:35417 // Has to happen after this is set as |controller| of RootWindowSettings.
418 wm_root_window_controller_ = WmRootWindowControllerAura::Get(root_window);
419
[email protected]a273d33a2013-10-17 12:41:21420 stacking_controller_.reset(new StackingController);
sky28f20d62016-10-20 23:21:59421 aura::client::SetWindowParentingClient(root_window,
422 stacking_controller_.get());
[email protected]f5c9dbc2014-04-11 08:13:45423 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window));
[email protected]a273d33a2013-10-17 12:41:21424}
425
jamescookfda159002016-10-21 18:48:57426void RootWindowController::Init(RootWindowType root_window_type) {
[email protected]f5c9dbc2014-04-11 08:13:45427 aura::Window* root_window = GetRootWindow();
[email protected]51f438112013-11-18 19:32:50428 Shell* shell = Shell::GetInstance();
[email protected]f5c9dbc2014-04-11 08:13:45429 shell->InitRootWindow(root_window);
[email protected]a273d33a2013-10-17 12:41:21430
skyd053905c2016-08-30 22:37:35431 wm_root_window_controller_->CreateContainers();
[email protected]608de6c2013-10-29 00:14:28432
jamescookfda159002016-10-21 18:48:57433 CreateSystemWallpaper(root_window_type);
[email protected]a273d33a2013-10-17 12:41:21434
435 InitLayoutManagers();
436 InitTouchHuds();
437
skyea4ca942016-09-12 21:56:19438 if (WmShell::Get()
439 ->GetPrimaryRootWindowController()
skyb733d4182016-09-09 23:18:38440 ->GetSystemModalLayoutManager(nullptr)
441 ->has_window_dimmer()) {
skyea4ca942016-09-12 21:56:19442 wm_root_window_controller_->GetSystemModalLayoutManager(nullptr)
443 ->CreateModalBackground();
[email protected]a273d33a2013-10-17 12:41:21444 }
445
sky88bd4be62016-06-09 17:34:41446 WmShell::Get()->AddShellObserver(this);
[email protected]a273d33a2013-10-17 12:41:21447
skyd053905c2016-08-30 22:37:35448 wm_root_window_controller_->root_window_layout_manager()->OnWindowResized();
[email protected]608de6c2013-10-29 00:14:28449 if (root_window_type == PRIMARY) {
bshe9858b4a2014-09-16 20:46:38450 shell->InitKeyboard();
[email protected]a273d33a2013-10-17 12:41:21451 } else {
[email protected]f5c9dbc2014-04-11 08:13:45452 ash_host_->AsWindowTreeHost()->Show();
[email protected]a273d33a2013-10-17 12:41:21453
[email protected]864b58552013-12-19 04:19:38454 // Create a shelf if a user is already logged in.
mswbc0a8b482016-06-30 02:21:14455 if (WmShell::Get()->GetSessionStateDelegate()->NumberOfLoggedInUsers())
skyd52346b2016-10-07 15:43:50456 wm_root_window_controller_->CreateShelf();
[email protected]0e3e7cb2014-04-12 05:18:25457
458 // Notify shell observers about new root window.
sky80556bc42016-06-07 22:46:13459 shell->OnRootWindowAdded(WmWindowAura::Get(root_window));
[email protected]a273d33a2013-10-17 12:41:21460 }
[email protected]a825e8312014-05-05 22:05:01461
462#if defined(OS_CHROMEOS)
pgal.u-szegedd84534d32014-10-29 12:34:30463 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]2e0b2352014-07-28 13:28:28464 switches::kAshDisableTouchExplorationMode)) {
[email protected]7d487592014-07-24 03:54:50465 touch_exploration_manager_.reset(new AshTouchExplorationManager(this));
[email protected]a825e8312014-05-05 22:05:01466 }
467#endif
[email protected]a273d33a2013-10-17 12:41:21468}
469
[email protected]756bda12013-07-03 08:17:06470void RootWindowController::InitLayoutManagers() {
jamescook752e8df2016-08-09 19:54:39471 // Create the shelf and status area widgets.
jamescookb551aba2016-09-01 01:00:16472 DCHECK(!wm_shelf_aura_->shelf_widget());
jamescook752e8df2016-08-09 19:54:39473 aura::Window* shelf_container = GetContainer(kShellWindowId_ShelfContainer);
474 aura::Window* status_container = GetContainer(kShellWindowId_StatusContainer);
475 WmWindow* wm_shelf_container = WmWindowAura::Get(shelf_container);
476 WmWindow* wm_status_container = WmWindowAura::Get(status_container);
sky8d971a0a2016-09-21 23:37:57477
478 wm_root_window_controller_->CreateLayoutManagers();
jamescookb551aba2016-09-01 01:00:16479
jamescook752e8df2016-08-09 19:54:39480 // Make it easier to resize windows that partially overlap the shelf. Must
481 // occur after the ShelfLayoutManager is constructed by ShelfWidget.
482 shelf_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
483 wm_shelf_container, wm_shelf_aura_.get()));
484 status_container->SetEventTargeter(base::MakeUnique<ShelfWindowTargeter>(
485 wm_status_container, wm_shelf_aura_.get()));
486
sky8d971a0a2016-09-21 23:37:57487 panel_container_handler_ = base::MakeUnique<PanelWindowEventHandler>();
488 GetContainer(kShellWindowId_PanelContainer)
489 ->AddPreTargetHandler(panel_container_handler_.get());
[email protected]b8642ec2014-04-17 05:20:39490
491 // Install an AttachedPanelWindowTargeter on the panel container to make it
492 // easier to correctly target shelf buttons with touch.
jamescookb8dcef522016-06-25 14:42:55493 gfx::Insets mouse_extend(-kResizeOutsideBoundsSize, -kResizeOutsideBoundsSize,
[email protected]b8642ec2014-04-17 05:20:39494 -kResizeOutsideBoundsSize,
495 -kResizeOutsideBoundsSize);
jamescookb8dcef522016-06-25 14:42:55496 gfx::Insets touch_extend =
497 mouse_extend.Scale(kResizeOutsideBoundsScaleForTouch);
sky8d971a0a2016-09-21 23:37:57498 aura::Window* panel_container = GetContainer(kShellWindowId_PanelContainer);
499 panel_container->SetEventTargeter(std::unique_ptr<ui::EventTargeter>(
500 new AttachedPanelWindowTargeter(panel_container, mouse_extend,
501 touch_extend, panel_layout_manager())));
[email protected]756bda12013-07-03 08:17:06502}
503
504void RootWindowController::InitTouchHuds() {
pgal.u-szegedd84534d32014-10-29 12:34:30505 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
[email protected]756bda12013-07-03 08:17:06506 if (command_line->HasSwitch(switches::kAshTouchHud))
[email protected]f5c9dbc2014-04-11 08:13:45507 set_touch_hud_debug(new TouchHudDebug(GetRootWindow()));
[email protected]756bda12013-07-03 08:17:06508 if (Shell::GetInstance()->is_touch_hud_projection_enabled())
509 EnableTouchHudProjection();
510}
511
jamescookfda159002016-10-21 18:48:57512void RootWindowController::CreateSystemWallpaper(
513 RootWindowType root_window_type) {
[email protected]756bda12013-07-03 08:17:06514 SkColor color = SK_ColorBLACK;
515#if defined(OS_CHROMEOS)
jamescookfda159002016-10-21 18:48:57516 // The splash screen appears on the primary display at boot. If this is a
517 // secondary monitor (either connected at boot or connected later) or if the
518 // browser restarted for a second login then don't use the boot color.
519 const bool is_boot_splash_screen =
520 root_window_type == PRIMARY &&
521 base::CommandLine::ForCurrentProcess()->HasSwitch(
522 chromeos::switches::kFirstExecAfterBoot);
523 if (is_boot_splash_screen)
[email protected]756bda12013-07-03 08:17:06524 color = kChromeOsBootColor;
525#endif
msw607227f82016-08-30 17:22:39526 system_wallpaper_.reset(
527 new SystemWallpaperController(GetRootWindow(), color));
[email protected]756bda12013-07-03 08:17:06528
529#if defined(OS_CHROMEOS)
530 // Make a copy of the system's boot splash screen so we can composite it
msw607227f82016-08-30 17:22:39531 // onscreen until the wallpaper is ready.
jamescookfda159002016-10-21 18:48:57532 if (is_boot_splash_screen &&
pgal.u-szegedd84534d32014-10-29 12:34:30533 (base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]756bda12013-07-03 08:17:06534 switches::kAshCopyHostBackgroundAtBoot) ||
pgal.u-szegedd84534d32014-10-29 12:34:30535 base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]756bda12013-07-03 08:17:06536 switches::kAshAnimateFromBootSplashScreen)))
[email protected]f5c9dbc2014-04-11 08:13:45537 boot_splash_screen_.reset(new BootSplashScreen(GetHost()));
[email protected]756bda12013-07-03 08:17:06538#endif
539}
540
[email protected]d141b922013-07-09 08:13:17541void RootWindowController::EnableTouchHudProjection() {
542 if (touch_hud_projection_)
543 return;
[email protected]f5c9dbc2014-04-11 08:13:45544 set_touch_hud_projection(new TouchHudProjection(GetRootWindow()));
[email protected]d141b922013-07-09 08:13:17545}
546
547void RootWindowController::DisableTouchHudProjection() {
548 if (!touch_hud_projection_)
549 return;
550 touch_hud_projection_->Remove();
551}
552
sky8d971a0a2016-09-21 23:37:57553DockedWindowLayoutManager*
554RootWindowController::docked_window_layout_manager() {
555 return wm_root_window_controller_->docked_window_layout_manager();
556}
557
558PanelLayoutManager* RootWindowController::panel_layout_manager() {
559 return wm_root_window_controller_->panel_layout_manager();
560}
561
skye79274a2016-06-08 05:39:02562void RootWindowController::OnLoginStateChanged(LoginStatus status) {
jamescookb551aba2016-09-01 01:00:16563 wm_shelf_aura_->UpdateVisibilityState();
[email protected]d141b922013-07-09 08:13:17564}
565
566void RootWindowController::OnTouchHudProjectionToggled(bool enabled) {
567 if (enabled)
568 EnableTouchHudProjection();
569 else
570 DisableTouchHudProjection();
571}
572
jamescookb8dcef522016-06-25 14:42:55573RootWindowController* GetRootWindowController(const aura::Window* root_window) {
msw15156bf2016-09-13 21:49:17574 return root_window ? GetRootWindowSettings(root_window)->controller : nullptr;
[email protected]6b2d4a0b2013-09-06 06:29:54575}
576
[email protected]d90b8392012-06-13 09:34:56577} // namespace ash