blob: 44f74894729ef389b59d5b4a66f85993ab35de73 [file] [log] [blame]
[email protected]e0d22e82012-01-04 00:46:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]87b0d82e2011-10-07 21:02:592// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]b65bdda2011-12-23 23:35:315#include "ash/shell.h"
[email protected]87b0d82e2011-10-07 21:02:596
[email protected]f7eb89c2011-12-13 09:48:547#include <algorithm>
[email protected]0039db92012-05-09 04:11:458#include <string>
dchengcbf0d9d2015-12-27 22:49:239#include <utility>
[email protected]f7eb89c2011-12-13 09:48:5410
[email protected]878479482013-09-18 10:29:1911#include "ash/accelerators/accelerator_controller.h"
[email protected]60d677d2014-05-30 13:07:0212#include "ash/accelerators/accelerator_delegate.h"
[email protected]e7293fa2012-05-17 04:42:3313#include "ash/accelerators/focus_manager_factory.h"
sky0702b272016-06-03 22:10:4114#include "ash/aura/wm_shell_aura.h"
15#include "ash/aura/wm_window_aura.h"
[email protected]55398d22013-10-10 19:49:2016#include "ash/autoclick/autoclick_controller.h"
mswd9b1b342016-06-17 20:19:5717#include "ash/common/ash_switches.h"
jamescook2b624c5a2016-06-08 01:34:0218#include "ash/common/session/session_state_delegate.h"
jamescookec04cc32016-06-07 00:52:4519#include "ash/common/shelf/shelf_item_delegate.h"
20#include "ash/common/shelf/shelf_item_delegate_manager.h"
21#include "ash/common/shelf/shelf_model.h"
skyc096d9f2016-06-02 13:46:2622#include "ash/common/shell_window_ids.h"
jamescook2a4d1eb2016-06-09 20:10:0723#include "ash/common/system/tray/system_tray_delegate.h"
sky629ab492016-06-07 18:04:1124#include "ash/common/wm/mru_window_tracker.h"
skyd6063772016-06-01 17:52:2125#include "ash/common/wm/root_window_finder.h"
26#include "ash/common/wm/window_positioner.h"
jamescook443e42d2016-06-10 21:44:4627#include "ash/common/wm_shell.h"
sky50a01122016-06-08 16:48:1928#include "ash/common/wm_shell_common.h"
jamescooke9f5f0c2016-05-09 18:22:1429#include "ash/container_delegate.h"
[email protected]e70cf0ed2012-03-15 16:24:4730#include "ash/desktop_background/desktop_background_controller.h"
[email protected]e70cf0ed2012-03-15 16:24:4731#include "ash/desktop_background/desktop_background_view.h"
[email protected]81abb1032012-11-13 18:55:4132#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]87ec2202014-02-06 06:24:2733#include "ash/display/cursor_window_controller.h"
stevenjb537c5c3f2016-01-20 23:38:1234#include "ash/display/display_configuration_controller.h"
[email protected]6bdf7952012-11-14 10:10:5835#include "ash/display/display_manager.h"
[email protected]682990f2013-01-10 06:49:1136#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2737#include "ash/display/mouse_cursor_event_filter.h"
[email protected]8d625fb2012-07-18 16:40:0638#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5239#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5940#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4041#include "ash/first_run/first_run_helper_impl.h"
[email protected]400a61c2014-03-13 19:40:2342#include "ash/frame/custom_frame_view_ash.h"
[email protected]1d2a7212014-01-16 06:09:4843#include "ash/gpu_support.h"
[email protected]f4c92b382012-08-28 00:59:5944#include "ash/high_contrast/high_contrast_controller.h"
[email protected]1b4c7472014-05-15 18:32:2345#include "ash/host/ash_window_tree_host_init_params.h"
oshima5e0fff82015-06-27 01:31:3046#include "ash/ime/input_method_event_handler.h"
skyfee520c2016-02-11 19:57:4647#include "ash/keyboard/keyboard_ui.h"
[email protected]7a80cdd2013-09-26 09:20:5348#include "ash/keyboard_uma_event_filter.h"
[email protected]f4c92b382012-08-28 00:59:5949#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5450#include "ash/magnifier/partial_magnification_controller.h"
[email protected]efc897f72013-11-01 11:43:0751#include "ash/media_delegate.h"
[email protected]47686c42013-10-25 01:49:1752#include "ash/new_window_delegate.h"
jamescook214fcbde2016-04-28 01:16:0653#include "ash/pointer_watcher_delegate.h"
[email protected]d90b8392012-06-13 09:34:5654#include "ash/root_window_controller.h"
[email protected]976624f2013-09-19 21:58:4955#include "ash/shelf/app_list_shelf_item_delegate.h"
msw174379b2016-04-05 00:25:1156#include "ash/shelf/shelf.h"
[email protected]8b57e942013-12-09 19:39:2057#include "ash/shelf/shelf_delegate.h"
[email protected]478c6c32013-03-09 02:50:5858#include "ash/shelf/shelf_widget.h"
[email protected]055a56d2013-12-06 12:13:3659#include "ash/shelf/shelf_window_watcher.h"
[email protected]b65bdda2011-12-23 23:35:3160#include "ash/shell_delegate.h"
61#include "ash/shell_factory.h"
[email protected]1b4c7472014-05-15 18:32:2362#include "ash/shell_init_params.h"
[email protected]a9a40462013-07-31 06:22:5663#include "ash/system/locale/locale_notification_controller.h"
[email protected]6d6546e2012-05-30 23:12:0264#include "ash/system/status_area_widget.h"
yoshiki32f51632016-03-24 01:24:4365#include "ash/system/toast/toast_manager.h"
[email protected]83b2b84c2012-11-14 01:11:0066#include "ash/system/tray/system_tray_notifier.h"
oshima5a296e82016-04-29 01:32:2767#include "ash/utility/screenshot_controller.h"
[email protected]39718b52012-12-03 17:24:5668#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2969#include "ash/wm/ash_native_cursor_manager.h"
[email protected]262f8bd2012-03-23 19:30:2770#include "ash/wm/event_client_impl.h"
[email protected]ab4f8c92013-05-30 19:07:4771#include "ash/wm/lock_state_controller.h"
[email protected]58fb353d2014-04-04 03:28:0572#include "ash/wm/maximize_mode/maximize_mode_controller.h"
[email protected]e55b73452014-02-20 13:18:0473#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
[email protected]9ae32df2012-07-26 03:25:1874#include "ash/wm/overlay_event_filter.h"
sky6624a7af2016-05-27 18:47:4975#include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h"
[email protected]09f35d742013-08-23 00:39:3976#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:5777#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:5778#include "ash/wm/resize_shadow_controller.h"
[email protected]435b212e2012-04-05 19:43:3779#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2780#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3381#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]3537d472014-01-15 05:45:3182#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:5883#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:0284#include "ash/wm/window_animations.h"
[email protected]dd1e1ac2014-05-13 03:44:0985#include "ash/wm/window_cycle_controller.h"
[email protected]f059c6942012-07-21 14:27:5786#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5987#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3688#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0089#include "base/bind.h"
dchenga94547472016-04-08 08:41:1190#include "base/memory/ptr_util.h"
primiano7182d7b2015-01-30 18:02:0391#include "base/trace_event/trace_event.h"
mfomitchevda899d82016-04-15 22:20:3792#include "ui/app_list/presenter/app_list_presenter.h"
[email protected]2c456102011-12-26 06:26:3493#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:4494#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:5895#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:5996#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2697#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:1898#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:1799#include "ui/base/user_activity/user_activity_detector.h"
[email protected]116302fc2012-05-05 21:45:41100#include "ui/compositor/layer.h"
101#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19102#include "ui/display/display.h"
103#include "ui/display/screen.h"
[email protected]3e670aa2013-12-02 19:04:32104#include "ui/events/event_target_iterator.h"
Avi Drissmanfefc2f82014-12-22 19:25:29105#include "ui/gfx/geometry/size.h"
[email protected]9ec0f452012-05-31 15:58:53106#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45107#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28108#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56109#include "ui/keyboard/keyboard_util.h"
[email protected]8393aa62013-01-23 19:40:10110#include "ui/message_center/message_center.h"
[email protected]d7f30a72013-10-05 05:09:41111#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04112#include "ui/views/corewm/tooltip_controller.h"
[email protected]e7293fa2012-05-17 04:42:33113#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58114#include "ui/views/widget/native_widget_aura.h"
115#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02116#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01117#include "ui/wm/core/compound_event_filter.h"
118#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01119#include "ui/wm/core/shadow_controller.h"
120#include "ui/wm/core/visibility_controller.h"
121#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59122
[email protected]37ce571b2013-06-28 05:28:45123#if defined(OS_CHROMEOS)
124#if defined(USE_X11)
kylechar4abed71f2016-04-06 14:46:42125#include "ui/gfx/x/x11_types.h" // nogncheck
[email protected]94545ca92014-03-29 01:17:59126#endif // defined(USE_X11)
spange9b51272014-12-11 01:20:10127#include "ash/accelerators/magnifier_key_scroller.h"
128#include "ash/accelerators/spoken_feedback_toggler.h"
jamescooke044e1c2016-06-13 20:56:18129#include "ash/common/ash_constants.h"
msw6a94e0492016-06-17 17:21:38130#include "ash/common/system/chromeos/power/power_status.h"
[email protected]c1234a42013-08-20 09:35:40131#include "ash/display/display_change_observer_chromeos.h"
benf6de9852015-10-06 21:29:28132#include "ash/display/display_color_manager_chromeos.h"
[email protected]c1234a42013-08-20 09:35:40133#include "ash/display/display_error_observer_chromeos.h"
[email protected]72bce522014-02-10 21:11:26134#include "ash/display/projecting_observer_chromeos.h"
[email protected]7bc49bd2014-01-22 09:30:34135#include "ash/display/resolution_notification_controller.h"
benf6de9852015-10-06 21:29:28136#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]08bdabed2013-12-20 07:52:28137#include "ash/sticky_keys/sticky_keys_controller.h"
[email protected]b3142722014-03-04 06:59:50138#include "ash/system/chromeos/bluetooth/bluetooth_notification_controller.h"
[email protected]25cae452013-09-26 10:15:03139#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
[email protected]51625052013-10-10 01:40:16140#include "ash/system/chromeos/power/power_event_observer.h"
[email protected]ded58fd2013-10-09 07:56:55141#include "ash/system/chromeos/power/video_activity_notifier.h"
[email protected]94545ca92014-03-29 01:17:59142#include "ash/system/chromeos/session/last_window_closed_logout_reminder.h"
[email protected]0dc85512014-03-13 13:26:41143#include "ash/system/chromeos/session/logout_confirmation_controller.h"
dnicoara8c3bd1e62014-10-30 19:53:39144#include "ash/touch/touch_transformer_controller.h"
rsadam9172bc8a2014-10-29 23:37:38145#include "ash/virtual_keyboard_controller.h"
[email protected]0dc85512014-03-13 13:26:41146#include "base/bind_helpers.h"
[email protected]94545ca92014-03-29 01:17:59147#include "base/sys_info.h"
warx533c8f62016-04-12 01:19:43148#include "chromeos/audio/audio_a11y_controller.h"
pneubeck8be1f5422014-10-09 16:46:18149#include "chromeos/dbus/dbus_thread_manager.h"
[email protected]b0fa7012014-04-16 12:50:57150#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]1e31cbd2014-04-07 20:06:11151#include "ui/display/chromeos/display_configurator.h"
oshimae001c8c2016-04-13 23:49:04152
153#if defined(USE_X11)
154#include "ui/display/chromeos/x11/native_display_delegate_x11.h"
155#endif
156
157#if defined(USE_OZONE)
158#include "ui/display/types/native_display_delegate.h"
159#include "ui/ozone/public/ozone_platform.h"
160#endif
[email protected]70b3e7d52012-06-02 22:12:25161#endif // defined(OS_CHROMEOS)
162
[email protected]55f593352011-12-24 05:42:46163namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59164
165namespace {
[email protected]671a2ae2011-10-13 21:53:23166
[email protected]615922f2012-02-07 02:41:15167using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45168using views::Widget;
169
mfomitcheva1a8aa62016-05-03 16:23:26170// Returns the display id corresponding to window, or |GetTargetDisplayId()|
171// if |window| is null.
172int64_t GetDisplayIdForWindow(aura::Window* window) {
173 if (!window)
174 return Shell::GetTargetDisplayId();
oshimafcb23252016-05-06 02:39:35175 return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id();
mfomitcheva1a8aa62016-05-03 16:23:26176}
177
[email protected]b5756e22012-11-30 01:32:02178// A Corewm VisibilityController subclass that calls the Ash animation routine
179// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14180class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02181 public:
182 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05183 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02184
185 private:
[email protected]e319c7e2014-03-14 19:56:14186 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05187 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
188 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02189 return AnimateOnChildWindowVisibilityChanged(window, visible);
190 }
191
192 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
193};
194
[email protected]1b4c7472014-05-15 18:32:23195AshWindowTreeHostInitParams ShellInitParamsToAshWindowTreeHostInitParams(
196 const ShellInitParams& shell_init_params) {
197 AshWindowTreeHostInitParams ash_init_params;
198#if defined(OS_WIN)
199 ash_init_params.remote_hwnd = shell_init_params.remote_hwnd;
200#endif
201 return ash_init_params;
202}
203
[email protected]87b0d82e2011-10-07 21:02:59204} // namespace
205
[email protected]cac10fc62011-10-07 23:22:56206// static
achuith287b26e2015-09-03 17:49:18207Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13208// static
[email protected]9488d4d2012-02-29 18:32:37209bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13210
211////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56212// Shell, public:
213
[email protected]cac10fc62011-10-07 23:22:56214// static
[email protected]1b4c7472014-05-15 18:32:23215Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08216 CHECK(!instance_);
ben0d6be2d42015-09-26 04:37:19217 instance_ = new Shell(init_params.delegate, init_params.blocking_pool);
[email protected]1b4c7472014-05-15 18:32:23218 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08219 return instance_;
220}
221
222// static
[email protected]cac10fc62011-10-07 23:22:56223Shell* Shell::GetInstance() {
oshima9eea82da2014-09-13 01:11:07224 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56225 return instance_;
226}
227
[email protected]6377a002011-11-10 20:26:47228// static
[email protected]b3b7bcd2012-03-06 19:35:45229bool Shell::HasInstance() {
230 return !!instance_;
231}
232
233// static
[email protected]ef589af2011-12-03 01:07:15234void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47235 delete instance_;
[email protected]6377a002011-11-10 20:26:47236}
237
[email protected]e73bd7802012-02-17 20:10:34238// static
[email protected]093b8d642014-04-03 20:59:28239RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07240 CHECK(HasInstance());
[email protected]093b8d642014-04-03 20:59:28241 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23242}
243
244// static
245Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07246 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52247 return Shell::GetInstance()
248 ->window_tree_host_manager()
249 ->GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56250}
251
252// static
[email protected]bf9cdb362013-10-25 19:22:45253aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07254 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52255 return GetInstance()->window_tree_host_manager()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34256}
257
[email protected]7b0f7502012-06-11 00:12:39258// static
[email protected]bf9cdb362013-10-25 19:22:45259aura::Window* Shell::GetTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07260 CHECK(HasInstance());
[email protected]b42910f2013-08-01 11:45:29261 Shell* shell = GetInstance();
262 if (shell->scoped_target_root_window_)
263 return shell->scoped_target_root_window_;
264 return shell->target_root_window_;
[email protected]a857dbe2012-05-30 22:10:14265}
266
[email protected]7b0f7502012-06-11 00:12:39267// static
mfomitcheva1a8aa62016-05-03 16:23:26268int64_t Shell::GetTargetDisplayId() {
oshimafcb23252016-05-06 02:39:35269 return display::Screen::GetScreen()
mfomitcheva1a8aa62016-05-03 16:23:26270 ->GetDisplayNearestWindow(GetTargetRootWindow())
271 .id();
272}
273
274// static
[email protected]c9390bd2013-11-08 20:33:13275aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07276 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52277 return Shell::GetInstance()->window_tree_host_manager()->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23278}
279
280// static
[email protected]bf9cdb362013-10-25 19:22:45281aura::Window* Shell::GetContainer(aura::Window* root_window,
[email protected]7b0f7502012-06-11 00:12:39282 int container_id) {
283 return root_window->GetChildById(container_id);
284}
285
286// static
[email protected]bf9cdb362013-10-25 19:22:45287const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38288 int container_id) {
289 return root_window->GetChildById(container_id);
290}
291
292// static
[email protected]429433f2012-12-28 20:14:46293std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
294 int container_id,
[email protected]bf9cdb362013-10-25 19:22:45295 aura::Window* priority_root) {
[email protected]7b0f7502012-06-11 00:12:39296 std::vector<aura::Window*> containers;
[email protected]c9390bd2013-11-08 20:33:13297 aura::Window::Windows root_windows = GetAllRootWindows();
298 for (aura::Window::Windows::const_iterator it = root_windows.begin();
[email protected]001272f2012-11-02 20:05:23299 it != root_windows.end(); ++it) {
300 aura::Window* container = (*it)->GetChildById(container_id);
[email protected]429433f2012-12-28 20:14:46301 if (container) {
302 if (priority_root && priority_root->Contains(container))
303 containers.insert(containers.begin(), container);
304 else
305 containers.push_back(container);
306 }
[email protected]001272f2012-11-02 20:05:23307 }
[email protected]7b0f7502012-06-11 00:12:39308 return containers;
309}
310
[email protected]940fb1c2013-06-18 16:54:28311void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
312 ui::MenuSourceType source_type) {
[email protected]fcb123d2013-04-17 15:58:49313 // No context menus if there is no session with an active user.
[email protected]c8d19f82013-05-18 09:09:41314 if (!session_state_delegate_->NumberOfLoggedInUsers())
[email protected]f60c6232012-08-24 18:55:03315 return;
316 // No context menus when screen is locked.
[email protected]fcb123d2013-04-17 15:58:49317 if (session_state_delegate_->IsScreenLocked())
[email protected]f60c6232012-08-24 18:55:03318 return;
[email protected]431552c2012-10-23 00:38:33319
sky0702b272016-06-03 22:10:41320 aura::Window* root = WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05321 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size())));
[email protected]093b8d642014-04-03 20:59:28322 GetRootWindowController(root)
323 ->ShowContextMenu(location_in_screen, source_type);
[email protected]46ca3632011-11-03 03:33:42324}
325
[email protected]1b467802014-08-15 16:03:06326void Shell::ShowAppList(aura::Window* window) {
[email protected]d17642d2013-09-12 23:44:38327 // If the context window is not given, show it on the target root window.
mfomitcheva1a8aa62016-05-03 16:23:26328 delegate_->GetAppListPresenter()->Show(GetDisplayIdForWindow(window));
[email protected]1b467802014-08-15 16:03:06329}
330
331void Shell::DismissAppList() {
mfomitchevda899d82016-04-15 22:20:37332 delegate_->GetAppListPresenter()->Dismiss();
[email protected]1b467802014-08-15 16:03:06333}
334
335void Shell::ToggleAppList(aura::Window* window) {
mfomitcheva1a8aa62016-05-03 16:23:26336 // If the context window is not given, show it on the target root window.
337 delegate_->GetAppListPresenter()->ToggleAppList(
338 GetDisplayIdForWindow(window));
[email protected]ae4987d2011-11-21 22:52:44339}
340
[email protected]7510d1082012-03-30 21:58:34341bool Shell::GetAppListTargetVisibility() const {
mfomitchevda899d82016-04-15 22:20:37342 return delegate_->GetAppListPresenter()->GetTargetVisibility();
[email protected]59ccade2013-10-17 17:56:40343}
344
[email protected]57b8bb352012-01-11 05:11:46345views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
346 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04347 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27348 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46349}
350
[email protected]2e236a52012-06-27 22:21:47351void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44352 const gfx::Insets& insets) {
oshimae2818922015-07-28 01:18:52353 if (!window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(
[email protected]b8984242013-07-12 07:55:38354 contains, insets)) {
[email protected]1a2145b2012-03-13 21:09:17355 return;
[email protected]b8984242013-07-12 07:55:38356 }
sky88bd4be62016-06-09 17:34:41357 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
[email protected]2e236a52012-06-27 22:21:47358 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17359}
360
skye79274a2016-06-08 05:39:02361void Shell::OnLoginStateChanged(LoginStatus status) {
sky88bd4be62016-06-09 17:34:41362 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
363 OnLoginStateChanged(status));
[email protected]82d3954ae2012-04-20 09:02:22364}
365
[email protected]51f438112013-11-18 19:32:50366void Shell::OnLoginUserProfilePrepared() {
[email protected]864b58552013-12-19 04:19:38367 CreateShelf();
[email protected]51f438112013-11-18 19:32:50368 CreateKeyboard();
369}
370
skye79274a2016-06-08 05:39:02371void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50372 RootWindowControllerList controllers = GetAllRootWindowControllers();
373 for (RootWindowControllerList::iterator iter = controllers.begin();
374 iter != controllers.end(); ++iter)
375 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01376}
377
[email protected]82d3954ae2012-04-20 09:02:22378void Shell::OnAppTerminating() {
sky88bd4be62016-06-09 17:34:41379 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
380 OnAppTerminating());
[email protected]82d3954ae2012-04-20 09:02:22381}
382
383void Shell::OnLockStateChanged(bool locked) {
sky88bd4be62016-06-09 17:34:41384 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
385 OnLockStateChanged(locked));
[email protected]ae298142013-08-10 15:30:29386#ifndef NDEBUG
387 // Make sure that there is no system modal in Lock layer when unlocked.
388 if (!locked) {
389 std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
[email protected]093b8d642014-04-03 20:59:28390 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
[email protected]ae298142013-08-10 15:30:29391 for (std::vector<aura::Window*>::const_iterator iter = containers.begin();
392 iter != containers.end(); ++iter) {
393 DCHECK_EQ(0u, (*iter)->children().size());
394 }
395 }
396#endif
[email protected]82d3954ae2012-04-20 09:02:22397}
398
[email protected]58868abf2014-01-17 23:45:33399void Shell::OnCastingSessionStartedOrStopped(bool started) {
spangb844ef02014-12-11 01:37:52400#if defined(OS_CHROMEOS)
sky88bd4be62016-06-09 17:34:41401 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
jdufault88fb76652015-04-30 22:36:43402 OnCastingSessionStartedOrStopped(started));
[email protected]58868abf2014-01-17 23:45:33403#endif
404}
405
[email protected]02a80052014-03-14 05:45:23406void Shell::OnMaximizeModeStarted() {
sky88bd4be62016-06-09 17:34:41407 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
408 OnMaximizeModeStarted());
[email protected]02a80052014-03-14 05:45:23409}
410
411void Shell::OnMaximizeModeEnded() {
sky88bd4be62016-06-09 17:34:41412 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
413 OnMaximizeModeEnded());
[email protected]02a80052014-03-14 05:45:23414}
415
sky80556bc42016-06-07 22:46:13416void Shell::OnRootWindowAdded(WmWindow* root_window) {
sky88bd4be62016-06-09 17:34:41417 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
418 OnRootWindowAdded(root_window));
[email protected]0e3e7cb2014-04-12 05:18:25419}
420
[email protected]864b58552013-12-19 04:19:38421void Shell::CreateShelf() {
[email protected]8c0ec432013-05-10 04:33:39422 RootWindowControllerList controllers = GetAllRootWindowControllers();
423 for (RootWindowControllerList::iterator iter = controllers.begin();
424 iter != controllers.end(); ++iter)
jamescook6500ad132016-05-27 06:15:54425 (*iter)->CreateShelf();
[email protected]d9456cb2012-03-21 16:41:04426}
427
sky80556bc42016-06-07 22:46:13428void Shell::OnShelfCreatedForRootWindow(WmWindow* root_window) {
sky88bd4be62016-06-09 17:34:41429 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
[email protected]b8642ec2014-04-17 05:20:39430 OnShelfCreatedForRootWindow(root_window));
431}
432
[email protected]51f438112013-11-18 19:32:50433void Shell::CreateKeyboard() {
skyfee520c2016-02-11 19:57:46434 if (in_mus_)
435 return;
[email protected]51f438112013-11-18 19:32:50436 // TODO(bshe): Primary root window controller may not be the controller to
437 // attach virtual keyboard. See http://crbug.com/303429
438 InitKeyboard();
bshe9858b4a2014-09-16 20:46:38439 GetPrimaryRootWindowController()->
440 ActivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50441}
442
[email protected]e1b299b2014-01-29 23:53:41443void Shell::DeactivateKeyboard() {
skyfee520c2016-02-11 19:57:46444 keyboard_ui_->Hide();
445 if (in_mus_)
446 return;
[email protected]a0b3fb882014-04-07 19:26:03447 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41448 RootWindowControllerList controllers = GetAllRootWindowControllers();
449 for (RootWindowControllerList::iterator iter = controllers.begin();
450 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03451 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41452 }
453 }
achuith287b26e2015-09-03 17:49:18454 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41455}
456
[email protected]864b58552013-12-19 04:19:38457void Shell::ShowShelf() {
[email protected]8c0ec432013-05-10 04:33:39458 RootWindowControllerList controllers = GetAllRootWindowControllers();
459 for (RootWindowControllerList::iterator iter = controllers.begin();
460 iter != controllers.end(); ++iter)
[email protected]864b58552013-12-19 04:19:38461 (*iter)->ShowShelf();
[email protected]7e1df2f62012-07-19 19:17:18462}
463
jamescookf17ee242016-05-25 21:22:00464void Shell::ShutdownShelf() {
jdufault551152e2016-01-27 19:48:43465 RootWindowControllerList controllers = GetAllRootWindowControllers();
466 for (RootWindowControllerList::iterator iter = controllers.begin();
467 iter != controllers.end(); ++iter) {
jamescook612205f2016-05-26 06:02:11468 if ((*iter)->shelf_widget())
469 (*iter)->shelf_widget()->Shutdown();
jdufault551152e2016-01-27 19:48:43470 }
471}
472
jamescook214fcbde2016-04-28 01:16:06473void Shell::AddPointerWatcher(views::PointerWatcher* watcher) {
474 pointer_watcher_delegate_->AddPointerWatcher(watcher);
475}
476
477void Shell::RemovePointerWatcher(views::PointerWatcher* watcher) {
478 pointer_watcher_delegate_->RemovePointerWatcher(watcher);
479}
480
[email protected]da285852014-05-27 19:53:43481#if defined(OS_CHROMEOS)
482bool Shell::ShouldSaveDisplaySettings() {
jonross0af45212015-01-13 18:55:46483 return !(screen_orientation_controller_
484 ->ignore_display_configuration_updates() ||
oshimabba2d992015-05-22 19:21:39485 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43486}
487#endif
488
[email protected]c758fbf2012-03-25 22:53:59489void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33490 RootWindowControllerList controllers = GetAllRootWindowControllers();
491 for (RootWindowControllerList::iterator iter = controllers.begin();
492 iter != controllers.end(); ++iter)
jamescook612205f2016-05-26 06:02:11493 if ((*iter)->shelf_widget())
[email protected]431552c2012-10-23 00:38:33494 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59495}
496
sky80556bc42016-06-07 22:46:13497void Shell::OnShelfAlignmentChanged(WmWindow* root_window) {
sky88bd4be62016-06-09 17:34:41498 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
msw953caf1f2016-03-18 00:33:29499 OnShelfAlignmentChanged(root_window));
500}
501
sky80556bc42016-06-07 22:46:13502void Shell::OnShelfAutoHideBehaviorChanged(WmWindow* root_window) {
sky88bd4be62016-06-09 17:34:41503 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
msw174379b2016-04-05 00:25:11504 OnShelfAutoHideBehaviorChanged(root_window));
505}
506
[email protected]375069e2013-10-04 13:54:31507void Shell::NotifyFullscreenStateChange(bool is_fullscreen,
sky80556bc42016-06-07 22:46:13508 WmWindow* root_window) {
sky88bd4be62016-06-09 17:34:41509 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
510 OnFullscreenStateChanged(is_fullscreen, root_window));
[email protected]375069e2013-10-04 13:54:31511}
512
[email protected]090c4f12012-10-29 18:56:42513void Shell::CreateModalBackground(aura::Window* window) {
[email protected]7f7f65c2013-04-17 16:47:13514 if (!modality_filter_) {
[email protected]093b8d642014-04-03 20:59:28515 modality_filter_.reset(new SystemModalContainerEventFilter(this));
[email protected]304594c2012-11-13 16:35:27516 AddPreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27517 }
518 RootWindowControllerList controllers = GetAllRootWindowControllers();
519 for (RootWindowControllerList::iterator iter = controllers.begin();
520 iter != controllers.end(); ++iter)
[email protected]090c4f12012-10-29 18:56:42521 (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27522}
523
524void Shell::OnModalWindowRemoved(aura::Window* removed) {
525 RootWindowControllerList controllers = GetAllRootWindowControllers();
526 bool activated = false;
527 for (RootWindowControllerList::iterator iter = controllers.begin();
528 iter != controllers.end() && !activated; ++iter) {
[email protected]8674b312012-10-12 19:02:44529 activated = (*iter)->GetSystemModalLayoutManager(removed)->
530 ActivateNextModalWindow();
[email protected]c0ce80e2012-10-05 23:28:27531 }
532 if (!activated) {
[email protected]304594c2012-11-13 16:35:27533 RemovePreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27534 modality_filter_.reset();
535 for (RootWindowControllerList::iterator iter = controllers.begin();
536 iter != controllers.end(); ++iter)
[email protected]8674b312012-10-12 19:02:44537 (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27538 }
539}
540
[email protected]88d71122012-10-18 07:11:01541WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11542 return GetPrimaryRootWindowController()
543 ->shelf_widget()
544 ->status_area_widget()
545 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28546}
547
[email protected]a0afeb12012-12-10 22:57:09548bool Shell::HasPrimaryStatusArea() {
jamescook612205f2016-05-26 06:02:11549 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf_widget();
[email protected]478c6c32013-03-09 02:50:58550 return shelf && shelf->status_area_widget();
[email protected]31f19e32012-10-30 22:31:23551}
552
[email protected]a0afeb12012-12-10 22:57:09553SystemTray* Shell::GetPrimarySystemTray() {
554 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42555}
556
[email protected]8b57e942013-12-09 19:39:20557ShelfDelegate* Shell::GetShelfDelegate() {
558 if (!shelf_delegate_) {
[email protected]8b57e942013-12-09 19:39:20559 // Creates ShelfItemDelegateManager before ShelfDelegate.
[email protected]c25ff502013-12-04 13:52:48560 shelf_item_delegate_manager_.reset(
561 new ShelfItemDelegateManager(shelf_model_.get()));
[email protected]6777f632013-10-15 02:38:41562
[email protected]8b57e942013-12-09 19:39:20563 shelf_delegate_.reset(delegate_->CreateShelfDelegate(shelf_model_.get()));
dchenga94547472016-04-08 08:41:11564 std::unique_ptr<ShelfItemDelegate> controller(new AppListShelfItemDelegate);
[email protected]6777f632013-10-15 02:38:41565
[email protected]64936bf2013-11-14 19:48:36566 // Finding the shelf model's location of the app list and setting its
[email protected]c25ff502013-12-04 13:52:48567 // ShelfItemDelegate.
[email protected]b7b4dec2013-11-18 06:16:12568 int app_list_index = shelf_model_->GetItemIndexForType(TYPE_APP_LIST);
[email protected]3fced99a2013-10-23 17:16:25569 DCHECK_GE(app_list_index, 0);
[email protected]eec0971422014-02-03 23:51:27570 ShelfID app_list_id = shelf_model_->items()[app_list_index].id;
[email protected]6777f632013-10-15 02:38:41571 DCHECK(app_list_id);
[email protected]c25ff502013-12-04 13:52:48572 shelf_item_delegate_manager_->SetShelfItemDelegate(app_list_id,
dchengcbf0d9d2015-12-27 22:49:23573 std::move(controller));
[email protected]093b8d642014-04-03 20:59:28574 shelf_window_watcher_.reset(new ShelfWindowWatcher(
575 shelf_model_.get(), shelf_item_delegate_manager_.get()));
[email protected]b913a3a2012-12-11 13:07:19576 }
[email protected]8b57e942013-12-09 19:39:20577 return shelf_delegate_.get();
[email protected]b913a3a2012-12-11 13:07:19578}
579
[email protected]2b8a9bb2013-07-01 22:43:40580void Shell::SetTouchHudProjectionEnabled(bool enabled) {
581 if (is_touch_hud_projection_enabled_ == enabled)
582 return;
583
[email protected]2b8a9bb2013-07-01 22:43:40584 is_touch_hud_projection_enabled_ = enabled;
sky88bd4be62016-06-09 17:34:41585 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
[email protected]d141b922013-07-09 08:13:17586 OnTouchHudProjectionToggled(enabled));
[email protected]2b8a9bb2013-07-01 22:43:40587}
588
[email protected]59ccade2013-10-17 17:56:40589#if defined(OS_CHROMEOS)
mswa7e8a5f2016-03-01 04:15:06590FirstRunHelper* Shell::CreateFirstRunHelper() {
591 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40592}
[email protected]87ec2202014-02-06 06:24:27593
594void Shell::SetCursorCompositingEnabled(bool enabled) {
oshimae2818922015-07-28 01:18:52595 window_tree_host_manager_->cursor_window_controller()
596 ->SetCursorCompositingEnabled(enabled);
[email protected]87ec2202014-02-06 06:24:27597 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
598}
[email protected]59ccade2013-10-17 17:56:40599#endif // defined(OS_CHROMEOS)
600
[email protected]f9466702012-09-17 16:35:27601void Shell::DoInitialWorkspaceAnimation() {
602 return GetPrimaryRootWindowController()->workspace_controller()->
603 DoInitialAnimation();
604}
605
[email protected]b6ba05d902013-10-04 21:38:45606////////////////////////////////////////////////////////////////////////////////
607// Shell, private:
608
ben0d6be2d42015-09-26 04:37:19609Shell::Shell(ShellDelegate* delegate, base::SequencedWorkerPool* blocking_pool)
achuith287b26e2015-09-03 17:49:18610 : target_root_window_(nullptr),
611 scoped_target_root_window_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45612 delegate_(delegate),
msw174379b2016-04-05 00:25:11613 shelf_model_(new ShelfModel),
yusukes1168eda2016-04-27 07:52:08614 link_handler_model_factory_(nullptr),
achuith287b26e2015-09-03 17:49:18615 activation_client_(nullptr),
[email protected]94545ca92014-03-29 01:17:59616#if defined(OS_CHROMEOS)
[email protected]1e31cbd2014-04-07 20:06:11617 display_configurator_(new ui::DisplayConfigurator()),
[email protected]94545ca92014-03-29 01:17:59618#endif // defined(OS_CHROMEOS)
sadrul7a8785e2016-02-12 21:54:35619 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45620 simulate_modal_window_open_for_testing_(false),
ben0d6be2d42015-09-26 04:37:19621 is_touch_hud_projection_enabled_(false),
622 blocking_pool_(blocking_pool) {
[email protected]b6ba05d902013-10-04 21:38:45623 DCHECK(delegate_.get());
sadrul679eb98f2015-08-07 05:25:10624 DCHECK(aura::Env::GetInstanceDontCreate());
[email protected]99edff3e2014-01-31 18:20:36625 gpu_support_.reset(delegate_->CreateGPUSupport());
[email protected]093b8d642014-04-03 20:59:28626 display_manager_.reset(new DisplayManager);
oshimae2818922015-07-28 01:18:52627 window_tree_host_manager_.reset(new WindowTreeHostManager);
[email protected]5d2ea362013-12-13 08:10:18628 user_metrics_recorder_.reset(new UserMetricsRecorder);
[email protected]b6ba05d902013-10-04 21:38:45629
630#if defined(OS_CHROMEOS)
[email protected]093b8d642014-04-03 20:59:28631 PowerStatus::Initialize();
[email protected]b6ba05d902013-10-04 21:38:45632#endif
633}
634
635Shell::~Shell() {
636 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
637
bruthigc24d11f2015-06-09 21:30:03638 user_metrics_recorder_->OnShellShuttingDown();
639
[email protected]050e77182014-03-25 15:29:16640 delegate_->PreShutdown();
641
achuith287b26e2015-09-03 17:49:18642 views::FocusManagerFactory::Install(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45643
644 // Remove the focus from any window. This will prevent overhead and side
645 // effects (e.g. crashes) from changing focus during shutdown.
646 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18647 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45648
649 // Please keep in same order as in Init() because it's easy to miss one.
650 if (window_modality_controller_)
651 window_modality_controller_.reset();
oshimae2818922015-07-28 01:18:52652 RemovePreTargetHandler(
653 window_tree_host_manager_->input_method_event_handler());
spange9b51272014-12-11 01:20:10654#if defined(OS_CHROMEOS)
[email protected]e4ea52362014-02-15 03:21:06655 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
656 magnifier_key_scroll_handler_.reset();
657
658 RemovePreTargetHandler(speech_feedback_handler_.get());
659 speech_feedback_handler_.reset();
[email protected]3dff2ef2014-02-09 22:50:39660#endif
[email protected]b6ba05d902013-10-04 21:38:45661 RemovePreTargetHandler(overlay_filter_.get());
[email protected]3537d472014-01-15 05:45:31662 RemovePreTargetHandler(accelerator_filter_.get());
663 RemovePreTargetHandler(event_transformation_handler_.get());
664 RemovePreTargetHandler(toplevel_window_event_handler_.get());
665 RemovePostTargetHandler(toplevel_window_event_handler_.get());
[email protected]342d56a2013-12-20 23:01:02666 RemovePreTargetHandler(system_gesture_filter_.get());
667 RemovePreTargetHandler(keyboard_metrics_filter_.get());
[email protected]8ab613cf2014-05-12 09:39:49668 RemovePreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45669
670 // TooltipController is deleted with the Shell so removing its references.
671 RemovePreTargetHandler(tooltip_controller_.get());
672
jonross0af45212015-01-13 18:55:46673#if defined(OS_CHROMEOS)
674 screen_orientation_controller_.reset();
675#endif
676
rsadambbaf2c82015-01-07 17:54:13677// Destroy the virtual keyboard controller before the maximize mode controller
678// since the latters destructor triggers events that the former is listening
679// to but no longer cares about.
680#if defined(OS_CHROMEOS)
681 virtual_keyboard_controller_.reset();
682#endif
jonross0af45212015-01-13 18:55:46683
[email protected]2a57beb52014-06-09 20:02:26684 // Destroy maximize mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57685 // need to be removed.
[email protected]58fb353d2014-04-04 03:28:05686 maximize_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57687
[email protected]0dc85512014-03-13 13:26:41688#if defined(OS_CHROMEOS)
[email protected]ded32492014-03-14 10:09:28689 // Destroy the LastWindowClosedLogoutReminder before the
690 // LogoutConfirmationController.
691 last_window_closed_logout_reminder_.reset();
692
[email protected]7b3f91ee2014-03-06 11:41:40693 // Destroy the LogoutConfirmationController before the SystemTrayDelegate.
694 logout_confirmation_controller_.reset();
[email protected]0dc85512014-03-13 13:26:41695#endif
[email protected]7b3f91ee2014-03-06 11:41:40696
jdufault551152e2016-01-27 19:48:43697 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
698 // layout.
699 DeactivateKeyboard();
700
yoshiki32f51632016-03-24 01:24:43701 // Destroy toasts
702 toast_manager_.reset();
703
jdufault551152e2016-01-27 19:48:43704 // Destroy SystemTrayDelegate before destroying the status area(s). Make sure
705 // to deinitialize the shelf first, as it is initialized after the delegate.
jamescookf17ee242016-05-25 21:22:00706 ShutdownShelf();
jamescook443e42d2016-06-10 21:44:46707 wm_shell_->system_tray_delegate()->Shutdown();
708 wm_shell_->SetSystemTrayDelegate(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45709
710 locale_notification_controller_.reset();
711
712 // Drag-and-drop must be canceled prior to close all windows.
713 drag_drop_controller_.reset();
714
[email protected]8c9d12a2013-12-06 18:39:03715 // Controllers who have WindowObserver added must be deleted
oshimae2818922015-07-28 01:18:52716 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03717
718#if defined(OS_CHROMEOS)
719 // VideoActivityNotifier must be deleted before |video_detector_| is
720 // deleted because it's observing video activity through
721 // VideoDetectorObserver interface.
722 video_activity_notifier_.reset();
723#endif // defined(OS_CHROMEOS)
724 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25725 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03726
727 shadow_controller_.reset();
728 resize_shadow_controller_.reset();
729
[email protected]dd1e1ac2014-05-13 03:44:09730 window_cycle_controller_.reset();
[email protected]3a472922013-12-16 18:00:54731 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03732
733 // |shelf_window_watcher_| has a weak pointer to |shelf_Model_|
734 // and has window observers.
735 shelf_window_watcher_.reset();
736
[email protected]b6ba05d902013-10-04 21:38:45737 // Destroy all child windows including widgets.
oshimae2818922015-07-28 01:18:52738 window_tree_host_manager_->CloseChildWindows();
afakhry58159392015-05-22 02:45:52739 // MruWindowTracker must be destroyed after all windows have been deleted to
740 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
741 // path. (crbug.com/485438).
sky50a01122016-06-08 16:48:19742 wm_shell_common_->DeleteMruWindowTracker();
[email protected]b6ba05d902013-10-04 21:38:45743
[email protected]8b57e942013-12-09 19:39:20744 // Chrome implementation of shelf delegate depends on FocusClient,
dtseng4ae0a882016-04-15 21:39:27745 // so must be deleted before |focus_client_| (below).
[email protected]8b57e942013-12-09 19:39:20746 shelf_delegate_.reset();
[email protected]8c9d12a2013-12-06 18:39:03747
[email protected]b6ba05d902013-10-04 21:38:45748 // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
749 // needs to remove observers from it.
750 system_tray_notifier_.reset();
751
752 // These need a valid Shell instance to clean up properly, so explicitly
753 // delete them before invalidating the instance.
754 // Alphabetical. TODO(oshima): sort.
755 magnification_controller_.reset();
756 partial_magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45757 tooltip_controller_.reset();
758 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31759 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45760 visibility_controller_.reset();
[email protected]c25ff502013-12-04 13:52:48761 // |shelf_item_delegate_manager_| observes |shelf_model_|. It must be
[email protected]64936bf2013-11-14 19:48:36762 // destroyed before |shelf_model_| is destroyed.
[email protected]c25ff502013-12-04 13:52:48763 shelf_item_delegate_manager_.reset();
[email protected]64936bf2013-11-14 19:48:36764 shelf_model_.reset();
[email protected]b6ba05d902013-10-04 21:38:45765
766 power_button_controller_.reset();
767 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45768
[email protected]7bc49bd2014-01-22 09:30:34769#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45770 resolution_notification_controller_.reset();
[email protected]7bc49bd2014-01-22 09:30:34771#endif
[email protected]b6ba05d902013-10-04 21:38:45772 desktop_background_controller_.reset();
oshima5a296e82016-04-29 01:32:27773 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49774 mouse_cursor_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45775
dnicoara8c3bd1e62014-10-30 19:53:39776#if defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:49777 touch_transformer_controller_.reset();
dnicoara8c3bd1e62014-10-30 19:53:39778#endif // defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:49779
warx533c8f62016-04-12 01:19:43780#if defined(OS_CHROMEOS)
781 audio_a11y_controller_.reset();
782#endif // defined(OS_CHROMEOS)
783
[email protected]b6ba05d902013-10-04 21:38:45784 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52785 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
786 // destruction
[email protected]b6ba05d902013-10-04 21:38:45787 // of its owned RootWindowControllers relies on the value.
[email protected]55ad8c12014-01-17 18:24:33788 display_manager_->CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12789 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27790
sky88bd4be62016-06-09 17:34:41791 wm_shell_->PrepareForShutdown();
dtseng4ae0a882016-04-15 21:39:27792 // Depends on |focus_client_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52793 window_tree_host_manager_->Shutdown();
794 window_tree_host_manager_.reset();
dtseng4ae0a882016-04-15 21:39:27795 focus_client_.reset();
[email protected]b6ba05d902013-10-04 21:38:45796 screen_position_controller_.reset();
[email protected]f3ab6eff52013-10-24 03:29:38797 accessibility_delegate_.reset();
[email protected]efc897f72013-11-01 11:43:07798 new_window_delegate_.reset();
799 media_delegate_.reset();
jamescooke9f5f0c2016-05-09 18:22:14800 container_delegate_.reset();
jamescook214fcbde2016-04-28 01:16:06801 pointer_watcher_delegate_.reset();
[email protected]b6ba05d902013-10-04 21:38:45802
shuchen29f3c7a2015-06-10 07:48:28803 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]a0b3fb882014-04-07 19:26:03804
[email protected]94545ca92014-03-29 01:17:59805#if defined(OS_CHROMEOS)
robert.bradfordab052492015-05-06 11:09:56806 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34807 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11808 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45809 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11810 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43811 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11812 display_configurator_->RemoveObserver(projecting_observer_.get());
sky88bd4be62016-06-09 17:34:41813 wm_shell_common_->RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43814 }
[email protected]b6ba05d902013-10-04 21:38:45815 display_change_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45816
[email protected]093b8d642014-04-03 20:59:28817 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18818
819 // Ensure that DBusThreadManager outlives this Shell.
820 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45821#endif
822
sky88bd4be62016-06-09 17:34:41823 // Needs to happen right before |instance_| is reset.
824 wm_shell_.reset();
825
826 // Must happen after |wm_shell_| is deleted.
827 wm_shell_common_.reset();
828
[email protected]b6ba05d902013-10-04 21:38:45829 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18830 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45831}
832
[email protected]1b4c7472014-05-15 18:32:23833void Shell::Init(const ShellInitParams& init_params) {
skyfee520c2016-02-11 19:57:46834 in_mus_ = init_params.in_mus;
sky984c1892016-04-20 00:00:34835
oshima3769b462016-04-25 16:49:18836#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
837 DCHECK(in_mus_) << "linux desktop does not support ash.";
838#endif
839
sky50a01122016-06-08 16:48:19840 wm_shell_common_.reset(new WmShellCommon);
841 wm_shell_.reset(new WmShellAura(wm_shell_common_.get()));
sky6624a7af2016-05-27 18:47:49842 scoped_overview_animation_settings_factory_.reset(
843 new ScopedOverviewAnimationSettingsFactoryAura);
sky0702b272016-06-03 22:10:41844 window_positioner_.reset(new WindowPositioner(wm_shell_.get()));
sky984c1892016-04-20 00:00:34845
sadrul7a8785e2016-02-12 21:54:35846 if (!in_mus_) {
847 native_cursor_manager_ = new AshNativeCursorManager;
848#if defined(OS_CHROMEOS)
849 cursor_manager_.reset(
dchenga94547472016-04-08 08:41:11850 new CursorManager(base::WrapUnique(native_cursor_manager_)));
sadrul7a8785e2016-02-12 21:54:35851#else
852 cursor_manager_.reset(
dchenga94547472016-04-08 08:41:11853 new ::wm::CursorManager(base::WrapUnique(native_cursor_manager_)));
sadrul7a8785e2016-02-12 21:54:35854#endif
855 }
skyfee520c2016-02-11 19:57:46856
[email protected]b6ba05d902013-10-04 21:38:45857 delegate_->PreInit();
[email protected]0249a6532013-10-31 06:53:34858 bool display_initialized = display_manager_->InitFromCommandLine();
stevenjb537c5c3f2016-01-20 23:38:12859
860 display_configuration_controller_.reset(new DisplayConfigurationController(
861 display_manager_.get(), window_tree_host_manager_.get()));
862
[email protected]94545ca92014-03-29 01:17:59863#if defined(OS_CHROMEOS)
kylecharde485eb2016-03-11 17:39:30864 // When running as part of mash, OzonePlatform is not initialized in the
865 // ash_sysui process. DisplayConfigurator will try to use OzonePlatform and
866 // crash. Instead, mash can manually set default display size using
867 // --ash-host-window-bounds flag.
868 if (in_mus_)
869 display_configurator_->set_configure_display(false);
oshimae001c8c2016-04-13 23:49:04870
871#if defined(USE_OZONE)
872 display_configurator_->Init(
sadrul6dbeef12016-04-14 07:09:34873 in_mus_ ? nullptr
874 : ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(),
oshimae001c8c2016-04-13 23:49:04875 !gpu_support_->IsPanelFittingDisabled());
876#elif defined(USE_X11)
877 display_configurator_->Init(
878 base::WrapUnique(new ui::NativeDisplayDelegateX11()),
879 !gpu_support_->IsPanelFittingDisabled());
880#endif
[email protected]0249a6532013-10-31 06:53:34881
pneubeck8be1f5422014-10-09 16:46:18882 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
883 chromeos::DBusThreadManager* dbus_thread_manager =
884 chromeos::DBusThreadManager::Get();
885 projecting_observer_.reset(
886 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11887 display_configurator_->AddObserver(projecting_observer_.get());
sky88bd4be62016-06-09 17:34:41888 wm_shell_common_->AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26889
[email protected]0249a6532013-10-31 06:53:34890 if (!display_initialized && base::SysInfo::IsRunningOnChromeOS()) {
[email protected]093b8d642014-04-03 20:59:28891 display_change_observer_.reset(new DisplayChangeObserver);
[email protected]b6ba05d902013-10-04 21:38:45892 // Register |display_change_observer_| first so that the rest of
893 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11894 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28895 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11896 display_configurator_->AddObserver(display_error_observer_.get());
897 display_configurator_->set_state_controller(display_change_observer_.get());
898 display_configurator_->set_mirroring_controller(display_manager_.get());
899 display_configurator_->ForceInitialConfigure(
[email protected]b6ba05d902013-10-04 21:38:45900 delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
901 display_initialized = true;
902 }
robert.bradfordab052492015-05-06 11:09:56903 display_color_manager_.reset(
ben0d6be2d42015-09-26 04:37:19904 new DisplayColorManager(display_configurator_.get(), blocking_pool_));
[email protected]94545ca92014-03-29 01:17:59905#endif // defined(OS_CHROMEOS)
stevenjb537c5c3f2016-01-20 23:38:12906
[email protected]b6ba05d902013-10-04 21:38:45907 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34908 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45909
mukai5dad2e72014-12-16 00:00:30910 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32911
[email protected]b6ba05d902013-10-04 21:38:45912 // Install the custom factory first so that views::FocusManagers for Tray,
[email protected]864b58552013-12-19 04:19:38913 // Shelf, and WallPaper could be created by the factory.
[email protected]b6ba05d902013-10-04 21:38:45914 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
915
[email protected]fa69f2b62014-05-22 21:47:58916 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
[email protected]ecca62b2013-10-09 16:18:53917
[email protected]b6ba05d902013-10-04 21:38:45918 // The WindowModalityController needs to be at the front of the input event
919 // pretarget handler list to ensure that it processes input events when modal
920 // windows are active.
921 window_modality_controller_.reset(
[email protected]e319c7e2014-03-14 19:56:14922 new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45923
[email protected]e319c7e2014-03-14 19:56:14924 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45925 AddPreTargetHandler(env_filter_.get());
926
afakhrycae0618f2015-01-12 17:57:43927 wm::AshFocusRules* focus_rules = new wm::AshFocusRules();
928
[email protected]e319c7e2014-03-14 19:56:14929 ::wm::FocusController* focus_controller =
afakhrycae0618f2015-01-12 17:57:43930 new ::wm::FocusController(focus_rules);
[email protected]b6ba05d902013-10-04 21:38:45931 focus_client_.reset(focus_controller);
932 activation_client_ = focus_controller;
933 activation_client_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45934
[email protected]093b8d642014-04-03 20:59:28935 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45936
oshimae2818922015-07-28 01:18:52937 window_tree_host_manager_->Start();
938 window_tree_host_manager_->CreatePrimaryHost(
[email protected]1b4c7472014-05-15 18:32:23939 ShellInitParamsToAshWindowTreeHostInitParams(init_params));
oshimae2818922015-07-28 01:18:52940 aura::Window* root_window = window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45941 target_root_window_ = root_window;
942
[email protected]7bc49bd2014-01-22 09:30:34943#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45944 resolution_notification_controller_.reset(
[email protected]093b8d642014-04-03 20:59:28945 new ResolutionNotificationController);
[email protected]7bc49bd2014-01-22 09:30:34946#endif
[email protected]b6ba05d902013-10-04 21:38:45947
sadrul7a8785e2016-02-12 21:54:35948 if (cursor_manager_)
oshimaf84b0da722016-04-27 19:47:19949 cursor_manager_->SetDisplay(
950 display::Screen::GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:45951
[email protected]b6ba05d902013-10-04 21:38:45952 accelerator_controller_.reset(new AcceleratorController);
[email protected]58fb353d2014-04-04 03:28:05953 maximize_mode_controller_.reset(new MaximizeModeController());
[email protected]b6ba05d902013-10-04 21:38:45954
oshimae2818922015-07-28 01:18:52955 AddPreTargetHandler(window_tree_host_manager_->input_method_event_handler());
oshima5e0fff82015-06-27 01:31:30956
spange9b51272014-12-11 01:20:10957#if defined(OS_CHROMEOS)
958 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06959 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10960 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06961 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39962#endif
963
[email protected]b6ba05d902013-10-04 21:38:45964 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45965
derat2d4e62d2015-01-09 16:09:17966 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45967 // rewritten first.
derat2d4e62d2015-01-09 16:09:17968 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45969
[email protected]093b8d642014-04-03 20:59:28970 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45971 AddPreTargetHandler(overlay_filter_.get());
sky88bd4be62016-06-09 17:34:41972 wm_shell_common_->AddShellObserver(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45973
[email protected]60d677d2014-05-30 13:07:02974 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11975 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
afakhry55463732014-11-21 21:06:16976 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45977 AddPreTargetHandler(accelerator_filter_.get());
978
[email protected]093b8d642014-04-03 20:59:28979 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45980 AddPreTargetHandler(event_transformation_handler_.get());
981
skycf67ed5a2016-05-23 19:38:39982 toplevel_window_event_handler_.reset(
sky0702b272016-06-03 22:10:41983 new ToplevelWindowEventHandler(wm_shell_.get()));
[email protected]3537d472014-01-15 05:45:31984
[email protected]093b8d642014-04-03 20:59:28985 system_gesture_filter_.reset(new SystemGestureEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45986 AddPreTargetHandler(system_gesture_filter_.get());
987
[email protected]093b8d642014-04-03 20:59:28988 keyboard_metrics_filter_.reset(new KeyboardUMAEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45989 AddPreTargetHandler(keyboard_metrics_filter_.get());
990
[email protected]354520b2014-06-21 04:31:01991#if defined(OS_CHROMEOS)
992 sticky_keys_controller_.reset(new StickyKeysController);
993#endif
994
[email protected]b6ba05d902013-10-04 21:38:45995 lock_state_controller_.reset(new LockStateController);
996 power_button_controller_.reset(new PowerButtonController(
997 lock_state_controller_.get()));
[email protected]94545ca92014-03-29 01:17:59998#if defined(OS_CHROMEOS)
[email protected]685442f32014-02-28 10:40:06999 // Pass the initial display state to PowerButtonController.
1000 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:091001 display_configurator_->cached_displays());
[email protected]685442f32014-02-28 10:40:061002#endif
sky88bd4be62016-06-09 17:34:411003 wm_shell_common_->AddShellObserver(lock_state_controller_.get());
[email protected]b6ba05d902013-10-04 21:38:451004
[email protected]093b8d642014-04-03 20:59:281005 drag_drop_controller_.reset(new DragDropController);
oshima5a296e82016-04-29 01:32:271006 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:481007 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:271008 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:481009 // See http://crbug.com/459214
oshima5a296e82016-04-29 01:32:271010 screenshot_controller_.reset(new ScreenshotController());
[email protected]093b8d642014-04-03 20:59:281011 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
[email protected]b6ba05d902013-10-04 21:38:451012 PrependPreTargetHandler(mouse_cursor_filter_.get());
1013
1014 // Create Controllers that may need root window.
1015 // TODO(oshima): Move as many controllers before creating
1016 // RootWindowController as possible.
1017 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:451018
1019 magnification_controller_.reset(
1020 MagnificationController::CreateInstance());
sky50a01122016-06-08 16:48:191021 wm_shell_common_->CreateMruWindowTracker();
[email protected]b6ba05d902013-10-04 21:38:451022
1023 partial_magnification_controller_.reset(
1024 new PartialMagnificationController());
1025
[email protected]55398d22013-10-10 19:49:201026 autoclick_controller_.reset(AutoclickController::CreateInstance());
1027
[email protected]b6ba05d902013-10-04 21:38:451028 high_contrast_controller_.reset(new HighContrastController);
1029 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:451030 window_selector_controller_.reset(new WindowSelectorController());
[email protected]dd1e1ac2014-05-13 03:44:091031 window_cycle_controller_.reset(new WindowCycleController());
[email protected]b6ba05d902013-10-04 21:38:451032
oshimaebbe63772015-02-19 18:41:321033 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111034 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451035 AddPreTargetHandler(tooltip_controller_.get());
1036
[email protected]093b8d642014-04-03 20:59:281037 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451038
1039 // This controller needs to be set before SetupManagedWindowMode.
ben0d6be2d42015-09-26 04:37:191040 desktop_background_controller_.reset(
1041 new DesktopBackgroundController(blocking_pool_));
[email protected]b6ba05d902013-10-04 21:38:451042 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
1043
[email protected]b6ba05d902013-10-04 21:38:451044 session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
[email protected]f3ab6eff52013-10-24 03:29:381045 accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate());
[email protected]47686c42013-10-25 01:49:171046 new_window_delegate_.reset(delegate_->CreateNewWindowDelegate());
[email protected]efc897f72013-11-01 11:43:071047 media_delegate_.reset(delegate_->CreateMediaDelegate());
jamescooke9f5f0c2016-05-09 18:22:141048 container_delegate_ = delegate_->CreateContainerDelegate();
jamescook214fcbde2016-04-28 01:16:061049 pointer_watcher_delegate_ = delegate_->CreatePointerWatcherDelegate();
[email protected]b6ba05d902013-10-04 21:38:451050
[email protected]093b8d642014-04-03 20:59:281051 resize_shadow_controller_.reset(new ResizeShadowController());
[email protected]d74caa82014-03-10 20:52:561052 shadow_controller_.reset(
[email protected]e319c7e2014-03-14 19:56:141053 new ::wm::ShadowController(activation_client_));
[email protected]b6ba05d902013-10-04 21:38:451054
1055 // Create system_tray_notifier_ before the delegate.
mswa7e8a5f2016-03-01 04:15:061056 system_tray_notifier_.reset(new SystemTrayNotifier());
[email protected]b6ba05d902013-10-04 21:38:451057
jamescook443e42d2016-06-10 21:44:461058 SystemTrayDelegate* system_tray_delegate =
1059 delegate()->CreateSystemTrayDelegate();
1060 DCHECK(system_tray_delegate);
1061 wm_shell_->SetSystemTrayDelegate(base::WrapUnique(system_tray_delegate));
[email protected]b6ba05d902013-10-04 21:38:451062
[email protected]093b8d642014-04-03 20:59:281063 locale_notification_controller_.reset(new LocaleNotificationController);
[email protected]b6ba05d902013-10-04 21:38:451064
yoshiki32f51632016-03-24 01:24:431065 // Initialize toast manager
1066 toast_manager_.reset(new ToastManager);
1067
[email protected]0dc85512014-03-13 13:26:411068#if defined(OS_CHROMEOS)
[email protected]7b3f91ee2014-03-06 11:41:401069 // Create the LogoutConfirmationController after the SystemTrayDelegate.
[email protected]093b8d642014-04-03 20:59:281070 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1071 base::Bind(&SystemTrayDelegate::SignOut,
jamescook443e42d2016-06-10 21:44:461072 base::Unretained(system_tray_delegate))));
[email protected]7b3f91ee2014-03-06 11:41:401073
oshimae2818922015-07-28 01:18:521074 // Create TouchTransformerController before
1075 // WindowTreeHostManager::InitDisplays()
[email protected]03122891a2014-05-13 23:56:491076 // since TouchTransformerController listens on
oshimae2818922015-07-28 01:18:521077 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
kylechard2fcd542016-06-07 17:19:541078 if (!in_mus_)
1079 touch_transformer_controller_.reset(new TouchTransformerController());
dnicoara8c3bd1e62014-10-30 19:53:391080#endif // defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:491081
skyfee520c2016-02-11 19:57:461082 keyboard_ui_ = init_params.keyboard_factory.is_null()
1083 ? KeyboardUI::Create()
1084 : init_params.keyboard_factory.Run();
1085
oshimae2818922015-07-28 01:18:521086 window_tree_host_manager_->InitHosts();
[email protected]b6ba05d902013-10-04 21:38:451087
rsadam9172bc8a2014-10-29 23:37:381088#if defined(OS_CHROMEOS)
1089 // Needs to be created after InitDisplays() since it may cause the virtual
1090 // keyboard to be deployed.
1091 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
1092#endif // defined(OS_CHROMEOS)
1093
warx533c8f62016-04-12 01:19:431094#if defined(OS_CHROMEOS)
1095 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
1096#endif // defined(OS_CHROMEOS)
1097
[email protected]a3565792013-10-18 12:52:371098 // It needs to be created after RootWindowController has been created
1099 // (which calls OnWindowResized has been called, otherwise the
[email protected]b6ba05d902013-10-04 21:38:451100 // widget will not paint when restoring after a browser crash. Also it needs
1101 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
1102 // the correct size.
1103 user_wallpaper_delegate_->InitializeWallpaper();
1104
sadrul7a8785e2016-02-12 21:54:351105 if (cursor_manager_) {
1106 if (initially_hide_cursor_)
1107 cursor_manager_->HideCursor();
1108 cursor_manager_->SetCursor(ui::kCursorPointer);
1109 }
[email protected]b6ba05d902013-10-04 21:38:451110
[email protected]5c04d3a92013-10-08 19:17:191111#if defined(OS_CHROMEOS)
[email protected]ded58fd2013-10-09 07:56:551112 // Set accelerator controller delegates.
[email protected]b6ba05d902013-10-04 21:38:451113 accelerator_controller_->SetBrightnessControlDelegate(
dchenga94547472016-04-08 08:41:111114 std::unique_ptr<BrightnessControlDelegate>(
mswa7e8a5f2016-03-01 04:15:061115 new system::BrightnessControllerChromeos));
[email protected]ded58fd2013-10-09 07:56:551116
[email protected]093b8d642014-04-03 20:59:281117 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551118 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571119 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551120 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281121 new VideoActivityNotifier(video_detector_.get()));
1122 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
1123 last_window_closed_logout_reminder_.reset(new LastWindowClosedLogoutReminder);
jonross0af45212015-01-13 18:55:461124 screen_orientation_controller_.reset(new ScreenOrientationController());
[email protected]b6ba05d902013-10-04 21:38:451125#endif
[email protected]b6ba05d902013-10-04 21:38:451126 // The compositor thread and main message loop have to be running in
1127 // order to create mirror window. Run it after the main message loop
1128 // is started.
oshimac8089b82014-11-12 21:43:501129 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031130
sky88bd4be62016-06-09 17:34:411131 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_common_->shell_observers(),
1132 OnShellInitialized());
phweiss0bf64c52015-11-17 12:56:181133
bruthigc24d11f2015-06-09 21:30:031134 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451135}
1136
[email protected]51f438112013-11-18 19:32:501137void Shell::InitKeyboard() {
skyfee520c2016-02-11 19:57:461138 if (in_mus_)
1139 return;
1140
[email protected]b6ba05d902013-10-04 21:38:451141 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031142 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451143 RootWindowControllerList controllers = GetAllRootWindowControllers();
1144 for (RootWindowControllerList::iterator iter = controllers.begin();
1145 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031146 (*iter)->DeactivateKeyboard(
1147 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451148 }
1149 }
[email protected]a0b3fb882014-04-07 19:26:031150 keyboard::KeyboardController::ResetInstance(
ben974286a2015-10-10 00:45:121151 new keyboard::KeyboardController(delegate_->CreateKeyboardUI()));
[email protected]b6ba05d902013-10-04 21:38:451152 }
1153}
1154
[email protected]41baaed2013-11-09 04:18:261155void Shell::InitRootWindow(aura::Window* root_window) {
[email protected]39718b52012-12-03 17:24:561156 DCHECK(activation_client_);
[email protected]d90b8392012-06-13 09:34:561157 DCHECK(visibility_controller_.get());
1158 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561159
[email protected]8cfb6722012-11-28 03:28:461160 aura::client::SetFocusClient(root_window, focus_client_.get());
[email protected]39718b52012-12-03 17:24:561161 aura::client::SetActivationClient(root_window, activation_client_);
[email protected]e319c7e2014-03-14 19:56:141162 ::wm::FocusController* focus_controller =
1163 static_cast< ::wm::FocusController*>(activation_client_);
[email protected]375338212013-09-05 22:14:521164 root_window->AddPreTargetHandler(focus_controller);
[email protected]d90b8392012-06-13 09:34:561165 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1166 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061167 aura::client::SetScreenPositionClient(root_window,
1168 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351169 aura::client::SetCursorClient(root_window, cursor_manager_.get());
[email protected]54a37cdc2012-07-25 19:16:011170 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381171 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561172
[email protected]3537d472014-01-15 05:45:311173 aura::client::SetWindowMoveClient(root_window,
1174 toplevel_window_event_handler_.get());
1175 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1176 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561177}
1178
[email protected]c0ce80e2012-10-05 23:28:271179bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1180 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051181 for (RootWindowController* controller : controllers) {
1182 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311183 return true;
[email protected]c0ce80e2012-10-05 23:28:271184 }
[email protected]c0ce80e2012-10-05 23:28:271185 return false;
1186}
1187
[email protected]049cf34b2012-12-07 17:15:481188////////////////////////////////////////////////////////////////////////////////
1189// Shell, ui::EventTarget overrides:
1190
[email protected]869f6352012-12-06 20:47:171191bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411192 return true;
1193}
1194
1195ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481196 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411197}
1198
dchenga94547472016-04-08 08:41:111199std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1200 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321201}
1202
1203ui::EventTargeter* Shell::GetEventTargeter() {
1204 NOTREACHED();
achuith287b26e2015-09-03 17:49:181205 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321206}
1207
[email protected]1ae361652012-12-12 22:39:511208////////////////////////////////////////////////////////////////////////////////
1209// Shell, aura::client::ActivationChangeObserver implementation:
1210
bruthig5681d882015-06-05 15:33:211211void Shell::OnWindowActivated(
1212 aura::client::ActivationChangeObserver::ActivationReason reason,
1213 aura::Window* gained_active,
1214 aura::Window* lost_active) {
[email protected]d219a192012-12-14 00:08:181215 if (gained_active)
[email protected]b42910f2013-08-01 11:45:291216 target_root_window_ = gained_active->GetRootWindow();
[email protected]049cf34b2012-12-07 17:15:481217}
1218
[email protected]55f593352011-12-24 05:42:461219} // namespace ash