blob: c110af503c0263fb6d13a9403f4a55d7bb5425ad [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"
jamescook27417442016-06-20 21:37:0517#include "ash/common/accessibility_delegate.h"
mswd9b1b342016-06-17 20:19:5718#include "ash/common/ash_switches.h"
jamescook8cd6bf72016-06-21 16:31:1219#include "ash/common/keyboard/keyboard_ui.h"
mswb2416052016-06-24 21:23:4520#include "ash/common/login_status.h"
jamescook2b624c5a2016-06-08 01:34:0221#include "ash/common/session/session_state_delegate.h"
jamescookec04cc32016-06-07 00:52:4522#include "ash/common/shelf/shelf_item_delegate.h"
23#include "ash/common/shelf/shelf_item_delegate_manager.h"
24#include "ash/common/shelf/shelf_model.h"
msw0414d4122016-07-06 22:58:4825#include "ash/common/shell_delegate.h"
skyc096d9f2016-06-02 13:46:2626#include "ash/common/shell_window_ids.h"
msw67849632016-06-22 03:16:2527#include "ash/common/system/locale/locale_notification_controller.h"
jamescookb6870ff2016-07-13 16:25:5328#include "ash/common/system/toast/toast_manager.h"
jamescook2a4d1eb2016-06-09 20:10:0729#include "ash/common/system/tray/system_tray_delegate.h"
skye2bde2172016-07-01 18:27:0230#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
sky0be55e62016-06-29 19:07:4731#include "ash/common/wm/maximize_mode/maximize_mode_window_manager.h"
sky629ab492016-06-07 18:04:1132#include "ash/common/wm/mru_window_tracker.h"
skyd6063772016-06-01 17:52:2133#include "ash/common/wm/root_window_finder.h"
34#include "ash/common/wm/window_positioner.h"
jamescook443e42d2016-06-10 21:44:4635#include "ash/common/wm_shell.h"
[email protected]e70cf0ed2012-03-15 16:24:4736#include "ash/desktop_background/desktop_background_controller.h"
[email protected]e70cf0ed2012-03-15 16:24:4737#include "ash/desktop_background/desktop_background_view.h"
[email protected]81abb1032012-11-13 18:55:4138#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]87ec2202014-02-06 06:24:2739#include "ash/display/cursor_window_controller.h"
stevenjb537c5c3f2016-01-20 23:38:1240#include "ash/display/display_configuration_controller.h"
[email protected]6bdf7952012-11-14 10:10:5841#include "ash/display/display_manager.h"
[email protected]682990f2013-01-10 06:49:1142#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2743#include "ash/display/mouse_cursor_event_filter.h"
[email protected]8d625fb2012-07-18 16:40:0644#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5245#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5946#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4047#include "ash/first_run/first_run_helper_impl.h"
[email protected]400a61c2014-03-13 19:40:2348#include "ash/frame/custom_frame_view_ash.h"
[email protected]1d2a7212014-01-16 06:09:4849#include "ash/gpu_support.h"
[email protected]f4c92b382012-08-28 00:59:5950#include "ash/high_contrast/high_contrast_controller.h"
[email protected]1b4c7472014-05-15 18:32:2351#include "ash/host/ash_window_tree_host_init_params.h"
oshima5e0fff82015-06-27 01:31:3052#include "ash/ime/input_method_event_handler.h"
[email protected]7a80cdd2013-09-26 09:20:5353#include "ash/keyboard_uma_event_filter.h"
[email protected]f4c92b382012-08-28 00:59:5954#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5455#include "ash/magnifier/partial_magnification_controller.h"
[email protected]47686c42013-10-25 01:49:1756#include "ash/new_window_delegate.h"
jamescook214fcbde2016-04-28 01:16:0657#include "ash/pointer_watcher_delegate.h"
[email protected]d90b8392012-06-13 09:34:5658#include "ash/root_window_controller.h"
[email protected]976624f2013-09-19 21:58:4959#include "ash/shelf/app_list_shelf_item_delegate.h"
msw174379b2016-04-05 00:25:1160#include "ash/shelf/shelf.h"
[email protected]8b57e942013-12-09 19:39:2061#include "ash/shelf/shelf_delegate.h"
[email protected]478c6c32013-03-09 02:50:5862#include "ash/shelf/shelf_widget.h"
[email protected]055a56d2013-12-06 12:13:3663#include "ash/shelf/shelf_window_watcher.h"
[email protected]b65bdda2011-12-23 23:35:3164#include "ash/shell_factory.h"
[email protected]1b4c7472014-05-15 18:32:2365#include "ash/shell_init_params.h"
[email protected]6d6546e2012-05-30 23:12:0266#include "ash/system/status_area_widget.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]9ae32df2012-07-26 03:25:1872#include "ash/wm/overlay_event_filter.h"
sky6624a7af2016-05-27 18:47:4973#include "ash/wm/overview/scoped_overview_animation_settings_factory_aura.h"
[email protected]e0d22e82012-01-04 00:46:5774#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:5775#include "ash/wm/resize_shadow_controller.h"
hidehiko6821ca42016-06-18 11:12:2376#include "ash/wm/screen_pinning_controller.h"
[email protected]435b212e2012-04-05 19:43:3777#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2778#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3379#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]3537d472014-01-15 05:45:3180#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:5881#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:0282#include "ash/wm/window_animations.h"
[email protected]dd1e1ac2014-05-13 03:44:0983#include "ash/wm/window_cycle_controller.h"
[email protected]f059c6942012-07-21 14:27:5784#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5985#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3686#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0087#include "base/bind.h"
dchenga94547472016-04-08 08:41:1188#include "base/memory/ptr_util.h"
primiano7182d7b2015-01-30 18:02:0389#include "base/trace_event/trace_event.h"
mfomitchevda899d82016-04-15 22:20:3790#include "ui/app_list/presenter/app_list_presenter.h"
[email protected]2c456102011-12-26 06:26:3491#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:4492#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:5893#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:5994#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2695#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:1896#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:1797#include "ui/base/user_activity/user_activity_detector.h"
[email protected]116302fc2012-05-05 21:45:4198#include "ui/compositor/layer.h"
99#include "ui/compositor/layer_animator.h"
oshimaf84b0da722016-04-27 19:47:19100#include "ui/display/display.h"
101#include "ui/display/screen.h"
[email protected]3e670aa2013-12-02 19:04:32102#include "ui/events/event_target_iterator.h"
Avi Drissmanfefc2f82014-12-22 19:25:29103#include "ui/gfx/geometry/size.h"
[email protected]9ec0f452012-05-31 15:58:53104#include "ui/gfx/image/image_skia.h"
[email protected]b6ba05d902013-10-04 21:38:45105#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28106#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56107#include "ui/keyboard/keyboard_util.h"
[email protected]8393aa62013-01-23 19:40:10108#include "ui/message_center/message_center.h"
[email protected]d7f30a72013-10-05 05:09:41109#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04110#include "ui/views/corewm/tooltip_controller.h"
[email protected]e7293fa2012-05-17 04:42:33111#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58112#include "ui/views/widget/native_widget_aura.h"
113#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02114#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01115#include "ui/wm/core/compound_event_filter.h"
116#include "ui/wm/core/focus_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01117#include "ui/wm/core/shadow_controller.h"
118#include "ui/wm/core/visibility_controller.h"
119#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59120
[email protected]37ce571b2013-06-28 05:28:45121#if defined(OS_CHROMEOS)
122#if defined(USE_X11)
kylechar4abed71f2016-04-06 14:46:42123#include "ui/gfx/x/x11_types.h" // nogncheck
jamescookb8dcef522016-06-25 14:42:55124#endif // defined(USE_X11)
spange9b51272014-12-11 01:20:10125#include "ash/accelerators/magnifier_key_scroller.h"
126#include "ash/accelerators/spoken_feedback_toggler.h"
jamescooke044e1c2016-06-13 20:56:18127#include "ash/common/ash_constants.h"
jamescook2c9ef262016-07-01 01:54:19128#include "ash/common/system/chromeos/bluetooth/bluetooth_notification_controller.h"
msw6a94e0492016-06-17 17:21:38129#include "ash/common/system/chromeos/power/power_status.h"
[email protected]c1234a42013-08-20 09:35:40130#include "ash/display/display_change_observer_chromeos.h"
benf6de9852015-10-06 21:29:28131#include "ash/display/display_color_manager_chromeos.h"
[email protected]c1234a42013-08-20 09:35:40132#include "ash/display/display_error_observer_chromeos.h"
[email protected]72bce522014-02-10 21:11:26133#include "ash/display/projecting_observer_chromeos.h"
[email protected]7bc49bd2014-01-22 09:30:34134#include "ash/display/resolution_notification_controller.h"
benf6de9852015-10-06 21:29:28135#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]08bdabed2013-12-20 07:52:28136#include "ash/sticky_keys/sticky_keys_controller.h"
[email protected]51625052013-10-10 01:40:16137#include "ash/system/chromeos/power/power_event_observer.h"
[email protected]ded58fd2013-10-09 07:56:55138#include "ash/system/chromeos/power/video_activity_notifier.h"
dnicoara8c3bd1e62014-10-30 19:53:39139#include "ash/touch/touch_transformer_controller.h"
rsadam9172bc8a2014-10-29 23:37:38140#include "ash/virtual_keyboard_controller.h"
[email protected]0dc85512014-03-13 13:26:41141#include "base/bind_helpers.h"
[email protected]94545ca92014-03-29 01:17:59142#include "base/sys_info.h"
warx533c8f62016-04-12 01:19:43143#include "chromeos/audio/audio_a11y_controller.h"
pneubeck8be1f5422014-10-09 16:46:18144#include "chromeos/dbus/dbus_thread_manager.h"
[email protected]b0fa7012014-04-16 12:50:57145#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]1e31cbd2014-04-07 20:06:11146#include "ui/display/chromeos/display_configurator.h"
oshimae001c8c2016-04-13 23:49:04147
148#if defined(USE_X11)
149#include "ui/display/chromeos/x11/native_display_delegate_x11.h"
150#endif
151
152#if defined(USE_OZONE)
153#include "ui/display/types/native_display_delegate.h"
154#include "ui/ozone/public/ozone_platform.h"
155#endif
[email protected]70b3e7d52012-06-02 22:12:25156#endif // defined(OS_CHROMEOS)
157
[email protected]55f593352011-12-24 05:42:46158namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59159
160namespace {
[email protected]671a2ae2011-10-13 21:53:23161
[email protected]615922f2012-02-07 02:41:15162using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45163using views::Widget;
164
mfomitcheva1a8aa62016-05-03 16:23:26165// Returns the display id corresponding to window, or |GetTargetDisplayId()|
166// if |window| is null.
167int64_t GetDisplayIdForWindow(aura::Window* window) {
168 if (!window)
169 return Shell::GetTargetDisplayId();
oshimafcb23252016-05-06 02:39:35170 return display::Screen::GetScreen()->GetDisplayNearestWindow(window).id();
mfomitcheva1a8aa62016-05-03 16:23:26171}
172
[email protected]b5756e22012-11-30 01:32:02173// A Corewm VisibilityController subclass that calls the Ash animation routine
174// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14175class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02176 public:
177 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05178 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02179
180 private:
[email protected]e319c7e2014-03-14 19:56:14181 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05182 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
183 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02184 return AnimateOnChildWindowVisibilityChanged(window, visible);
185 }
186
187 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
188};
189
[email protected]1b4c7472014-05-15 18:32:23190AshWindowTreeHostInitParams ShellInitParamsToAshWindowTreeHostInitParams(
191 const ShellInitParams& shell_init_params) {
192 AshWindowTreeHostInitParams ash_init_params;
193#if defined(OS_WIN)
194 ash_init_params.remote_hwnd = shell_init_params.remote_hwnd;
195#endif
196 return ash_init_params;
197}
198
[email protected]87b0d82e2011-10-07 21:02:59199} // namespace
200
[email protected]cac10fc62011-10-07 23:22:56201// static
achuith287b26e2015-09-03 17:49:18202Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13203// static
[email protected]9488d4d2012-02-29 18:32:37204bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13205
206////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56207// Shell, public:
208
[email protected]cac10fc62011-10-07 23:22:56209// static
[email protected]1b4c7472014-05-15 18:32:23210Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08211 CHECK(!instance_);
ben0d6be2d42015-09-26 04:37:19212 instance_ = new Shell(init_params.delegate, init_params.blocking_pool);
[email protected]1b4c7472014-05-15 18:32:23213 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08214 return instance_;
215}
216
217// static
[email protected]cac10fc62011-10-07 23:22:56218Shell* Shell::GetInstance() {
oshima9eea82da2014-09-13 01:11:07219 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56220 return instance_;
221}
222
[email protected]6377a002011-11-10 20:26:47223// static
[email protected]b3b7bcd2012-03-06 19:35:45224bool Shell::HasInstance() {
225 return !!instance_;
226}
227
228// static
[email protected]ef589af2011-12-03 01:07:15229void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47230 delete instance_;
[email protected]6377a002011-11-10 20:26:47231}
232
[email protected]e73bd7802012-02-17 20:10:34233// static
[email protected]093b8d642014-04-03 20:59:28234RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07235 CHECK(HasInstance());
[email protected]093b8d642014-04-03 20:59:28236 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23237}
238
239// static
240Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07241 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52242 return Shell::GetInstance()
243 ->window_tree_host_manager()
244 ->GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56245}
246
247// static
[email protected]bf9cdb362013-10-25 19:22:45248aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07249 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52250 return GetInstance()->window_tree_host_manager()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34251}
252
[email protected]7b0f7502012-06-11 00:12:39253// static
[email protected]bf9cdb362013-10-25 19:22:45254aura::Window* Shell::GetTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07255 CHECK(HasInstance());
[email protected]b42910f2013-08-01 11:45:29256 Shell* shell = GetInstance();
257 if (shell->scoped_target_root_window_)
258 return shell->scoped_target_root_window_;
259 return shell->target_root_window_;
[email protected]a857dbe2012-05-30 22:10:14260}
261
[email protected]7b0f7502012-06-11 00:12:39262// static
mfomitcheva1a8aa62016-05-03 16:23:26263int64_t Shell::GetTargetDisplayId() {
oshimafcb23252016-05-06 02:39:35264 return display::Screen::GetScreen()
mfomitcheva1a8aa62016-05-03 16:23:26265 ->GetDisplayNearestWindow(GetTargetRootWindow())
266 .id();
267}
268
269// static
[email protected]c9390bd2013-11-08 20:33:13270aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07271 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52272 return Shell::GetInstance()->window_tree_host_manager()->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23273}
274
275// static
jamescookb8dcef522016-06-25 14:42:55276aura::Window* Shell::GetContainer(aura::Window* root_window, int container_id) {
[email protected]7b0f7502012-06-11 00:12:39277 return root_window->GetChildById(container_id);
278}
279
280// static
[email protected]bf9cdb362013-10-25 19:22:45281const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38282 int container_id) {
283 return root_window->GetChildById(container_id);
284}
285
286// static
[email protected]429433f2012-12-28 20:14:46287std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
288 int container_id,
[email protected]bf9cdb362013-10-25 19:22:45289 aura::Window* priority_root) {
[email protected]7b0f7502012-06-11 00:12:39290 std::vector<aura::Window*> containers;
[email protected]c9390bd2013-11-08 20:33:13291 aura::Window::Windows root_windows = GetAllRootWindows();
292 for (aura::Window::Windows::const_iterator it = root_windows.begin();
[email protected]001272f2012-11-02 20:05:23293 it != root_windows.end(); ++it) {
294 aura::Window* container = (*it)->GetChildById(container_id);
[email protected]429433f2012-12-28 20:14:46295 if (container) {
296 if (priority_root && priority_root->Contains(container))
297 containers.insert(containers.begin(), container);
298 else
299 containers.push_back(container);
300 }
[email protected]001272f2012-11-02 20:05:23301 }
[email protected]7b0f7502012-06-11 00:12:39302 return containers;
303}
304
[email protected]940fb1c2013-06-18 16:54:28305void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
306 ui::MenuSourceType source_type) {
[email protected]fcb123d2013-04-17 15:58:49307 // No context menus if there is no session with an active user.
[email protected]c8d19f82013-05-18 09:09:41308 if (!session_state_delegate_->NumberOfLoggedInUsers())
[email protected]f60c6232012-08-24 18:55:03309 return;
310 // No context menus when screen is locked.
[email protected]fcb123d2013-04-17 15:58:49311 if (session_state_delegate_->IsScreenLocked())
[email protected]f60c6232012-08-24 18:55:03312 return;
[email protected]431552c2012-10-23 00:38:33313
sky0702b272016-06-03 22:10:41314 aura::Window* root = WmWindowAura::GetAuraWindow(
skya6d587a62016-04-20 02:58:05315 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size())));
jamescookb8dcef522016-06-25 14:42:55316 GetRootWindowController(root)->ShowContextMenu(location_in_screen,
317 source_type);
[email protected]46ca3632011-11-03 03:33:42318}
319
[email protected]1b467802014-08-15 16:03:06320void Shell::ShowAppList(aura::Window* window) {
[email protected]d17642d2013-09-12 23:44:38321 // If the context window is not given, show it on the target root window.
msw0414d4122016-07-06 22:58:48322 wm_shell_->delegate()->GetAppListPresenter()->Show(
323 GetDisplayIdForWindow(window));
[email protected]1b467802014-08-15 16:03:06324}
325
326void Shell::DismissAppList() {
msw0414d4122016-07-06 22:58:48327 wm_shell_->delegate()->GetAppListPresenter()->Dismiss();
[email protected]1b467802014-08-15 16:03:06328}
329
330void Shell::ToggleAppList(aura::Window* window) {
mfomitcheva1a8aa62016-05-03 16:23:26331 // If the context window is not given, show it on the target root window.
msw0414d4122016-07-06 22:58:48332 wm_shell_->delegate()->GetAppListPresenter()->ToggleAppList(
mfomitcheva1a8aa62016-05-03 16:23:26333 GetDisplayIdForWindow(window));
[email protected]ae4987d2011-11-21 22:52:44334}
335
mohsen01e15ee2016-07-01 15:36:20336bool Shell::IsApplistVisible() const {
msw0414d4122016-07-06 22:58:48337 return wm_shell_->delegate()->GetAppListPresenter()->IsVisible();
mohsen01e15ee2016-07-01 15:36:20338}
339
[email protected]7510d1082012-03-30 21:58:34340bool Shell::GetAppListTargetVisibility() const {
msw0414d4122016-07-06 22:58:48341 return wm_shell_->delegate()->GetAppListPresenter()->GetTargetVisibility();
[email protected]59ccade2013-10-17 17:56:40342}
343
[email protected]57b8bb352012-01-11 05:11:46344views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
345 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04346 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27347 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46348}
349
[email protected]2e236a52012-06-27 22:21:47350void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44351 const gfx::Insets& insets) {
oshimae2818922015-07-28 01:18:52352 if (!window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(
[email protected]b8984242013-07-12 07:55:38353 contains, insets)) {
[email protected]1a2145b2012-03-13 21:09:17354 return;
[email protected]b8984242013-07-12 07:55:38355 }
skyd76167d2016-07-01 00:05:12356 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
[email protected]2e236a52012-06-27 22:21:47357 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17358}
359
skye79274a2016-06-08 05:39:02360void Shell::OnLoginStateChanged(LoginStatus status) {
skyd76167d2016-07-01 00:05:12361 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
sky88bd4be62016-06-09 17:34:41362 OnLoginStateChanged(status));
[email protected]82d3954ae2012-04-20 09:02:22363}
364
[email protected]51f438112013-11-18 19:32:50365void Shell::OnLoginUserProfilePrepared() {
[email protected]864b58552013-12-19 04:19:38366 CreateShelf();
[email protected]51f438112013-11-18 19:32:50367 CreateKeyboard();
368}
369
skye79274a2016-06-08 05:39:02370void Shell::UpdateAfterLoginStatusChange(LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50371 RootWindowControllerList controllers = GetAllRootWindowControllers();
372 for (RootWindowControllerList::iterator iter = controllers.begin();
373 iter != controllers.end(); ++iter)
374 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01375}
376
[email protected]82d3954ae2012-04-20 09:02:22377void Shell::OnAppTerminating() {
skyd76167d2016-07-01 00:05:12378 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
sky88bd4be62016-06-09 17:34:41379 OnAppTerminating());
[email protected]82d3954ae2012-04-20 09:02:22380}
381
382void Shell::OnLockStateChanged(bool locked) {
skyd76167d2016-07-01 00:05:12383 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
sky88bd4be62016-06-09 17:34:41384 OnLockStateChanged(locked));
[email protected]ae298142013-08-10 15:30:29385#ifndef NDEBUG
386 // Make sure that there is no system modal in Lock layer when unlocked.
387 if (!locked) {
388 std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
[email protected]093b8d642014-04-03 20:59:28389 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
[email protected]ae298142013-08-10 15:30:29390 for (std::vector<aura::Window*>::const_iterator iter = containers.begin();
391 iter != containers.end(); ++iter) {
392 DCHECK_EQ(0u, (*iter)->children().size());
393 }
394 }
395#endif
[email protected]82d3954ae2012-04-20 09:02:22396}
397
[email protected]58868abf2014-01-17 23:45:33398void Shell::OnCastingSessionStartedOrStopped(bool started) {
spangb844ef02014-12-11 01:37:52399#if defined(OS_CHROMEOS)
skyd76167d2016-07-01 00:05:12400 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
jdufault88fb76652015-04-30 22:36:43401 OnCastingSessionStartedOrStopped(started));
[email protected]58868abf2014-01-17 23:45:33402#endif
403}
404
sky80556bc42016-06-07 22:46:13405void Shell::OnRootWindowAdded(WmWindow* root_window) {
skyd76167d2016-07-01 00:05:12406 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
sky88bd4be62016-06-09 17:34:41407 OnRootWindowAdded(root_window));
[email protected]0e3e7cb2014-04-12 05:18:25408}
409
[email protected]864b58552013-12-19 04:19:38410void Shell::CreateShelf() {
[email protected]8c0ec432013-05-10 04:33:39411 RootWindowControllerList controllers = GetAllRootWindowControllers();
412 for (RootWindowControllerList::iterator iter = controllers.begin();
413 iter != controllers.end(); ++iter)
jamescook6500ad132016-05-27 06:15:54414 (*iter)->CreateShelf();
[email protected]d9456cb2012-03-21 16:41:04415}
416
sky80556bc42016-06-07 22:46:13417void Shell::OnShelfCreatedForRootWindow(WmWindow* root_window) {
skyd76167d2016-07-01 00:05:12418 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
[email protected]b8642ec2014-04-17 05:20:39419 OnShelfCreatedForRootWindow(root_window));
420}
421
[email protected]51f438112013-11-18 19:32:50422void Shell::CreateKeyboard() {
skyfee520c2016-02-11 19:57:46423 if (in_mus_)
424 return;
[email protected]51f438112013-11-18 19:32:50425 // TODO(bshe): Primary root window controller may not be the controller to
426 // attach virtual keyboard. See http://crbug.com/303429
427 InitKeyboard();
jamescookb8dcef522016-06-25 14:42:55428 GetPrimaryRootWindowController()->ActivateKeyboard(
429 keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50430}
431
[email protected]e1b299b2014-01-29 23:53:41432void Shell::DeactivateKeyboard() {
jamescookc3fbf0952016-06-29 06:48:31433 // TODO(jamescook): Move keyboard create and hide into WmShell.
434 wm_shell_->keyboard_ui()->Hide();
skyfee520c2016-02-11 19:57:46435 if (in_mus_)
436 return;
[email protected]a0b3fb882014-04-07 19:26:03437 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41438 RootWindowControllerList controllers = GetAllRootWindowControllers();
439 for (RootWindowControllerList::iterator iter = controllers.begin();
jamescookb8dcef522016-06-25 14:42:55440 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03441 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41442 }
443 }
achuith287b26e2015-09-03 17:49:18444 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41445}
446
[email protected]864b58552013-12-19 04:19:38447void Shell::ShowShelf() {
[email protected]8c0ec432013-05-10 04:33:39448 RootWindowControllerList controllers = GetAllRootWindowControllers();
449 for (RootWindowControllerList::iterator iter = controllers.begin();
450 iter != controllers.end(); ++iter)
[email protected]864b58552013-12-19 04:19:38451 (*iter)->ShowShelf();
[email protected]7e1df2f62012-07-19 19:17:18452}
453
jamescookf17ee242016-05-25 21:22:00454void Shell::ShutdownShelf() {
jdufault551152e2016-01-27 19:48:43455 RootWindowControllerList controllers = GetAllRootWindowControllers();
456 for (RootWindowControllerList::iterator iter = controllers.begin();
457 iter != controllers.end(); ++iter) {
jamescook612205f2016-05-26 06:02:11458 if ((*iter)->shelf_widget())
459 (*iter)->shelf_widget()->Shutdown();
jdufault551152e2016-01-27 19:48:43460 }
461}
462
jamescook214fcbde2016-04-28 01:16:06463void Shell::AddPointerWatcher(views::PointerWatcher* watcher) {
464 pointer_watcher_delegate_->AddPointerWatcher(watcher);
465}
466
467void Shell::RemovePointerWatcher(views::PointerWatcher* watcher) {
468 pointer_watcher_delegate_->RemovePointerWatcher(watcher);
469}
470
[email protected]da285852014-05-27 19:53:43471#if defined(OS_CHROMEOS)
472bool Shell::ShouldSaveDisplaySettings() {
jamescookb8dcef522016-06-25 14:42:55473 return !(
474 screen_orientation_controller_->ignore_display_configuration_updates() ||
475 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43476}
477#endif
478
[email protected]c758fbf2012-03-25 22:53:59479void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33480 RootWindowControllerList controllers = GetAllRootWindowControllers();
481 for (RootWindowControllerList::iterator iter = controllers.begin();
482 iter != controllers.end(); ++iter)
jamescook612205f2016-05-26 06:02:11483 if ((*iter)->shelf_widget())
[email protected]431552c2012-10-23 00:38:33484 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59485}
486
sky80556bc42016-06-07 22:46:13487void Shell::OnShelfAlignmentChanged(WmWindow* root_window) {
skyd76167d2016-07-01 00:05:12488 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
msw953caf1f2016-03-18 00:33:29489 OnShelfAlignmentChanged(root_window));
490}
491
sky80556bc42016-06-07 22:46:13492void Shell::OnShelfAutoHideBehaviorChanged(WmWindow* root_window) {
skyd76167d2016-07-01 00:05:12493 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
msw174379b2016-04-05 00:25:11494 OnShelfAutoHideBehaviorChanged(root_window));
495}
496
[email protected]375069e2013-10-04 13:54:31497void Shell::NotifyFullscreenStateChange(bool is_fullscreen,
sky80556bc42016-06-07 22:46:13498 WmWindow* root_window) {
skyd76167d2016-07-01 00:05:12499 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
sky88bd4be62016-06-09 17:34:41500 OnFullscreenStateChanged(is_fullscreen, root_window));
[email protected]375069e2013-10-04 13:54:31501}
502
[email protected]090c4f12012-10-29 18:56:42503void Shell::CreateModalBackground(aura::Window* window) {
[email protected]7f7f65c2013-04-17 16:47:13504 if (!modality_filter_) {
[email protected]093b8d642014-04-03 20:59:28505 modality_filter_.reset(new SystemModalContainerEventFilter(this));
[email protected]304594c2012-11-13 16:35:27506 AddPreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27507 }
508 RootWindowControllerList controllers = GetAllRootWindowControllers();
509 for (RootWindowControllerList::iterator iter = controllers.begin();
510 iter != controllers.end(); ++iter)
[email protected]090c4f12012-10-29 18:56:42511 (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27512}
513
514void Shell::OnModalWindowRemoved(aura::Window* removed) {
515 RootWindowControllerList controllers = GetAllRootWindowControllers();
516 bool activated = false;
517 for (RootWindowControllerList::iterator iter = controllers.begin();
518 iter != controllers.end() && !activated; ++iter) {
jamescookb8dcef522016-06-25 14:42:55519 activated = (*iter)
520 ->GetSystemModalLayoutManager(removed)
521 ->ActivateNextModalWindow();
[email protected]c0ce80e2012-10-05 23:28:27522 }
523 if (!activated) {
[email protected]304594c2012-11-13 16:35:27524 RemovePreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27525 modality_filter_.reset();
526 for (RootWindowControllerList::iterator iter = controllers.begin();
527 iter != controllers.end(); ++iter)
[email protected]8674b312012-10-12 19:02:44528 (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27529 }
530}
531
[email protected]88d71122012-10-18 07:11:01532WebNotificationTray* Shell::GetWebNotificationTray() {
jamescook612205f2016-05-26 06:02:11533 return GetPrimaryRootWindowController()
534 ->shelf_widget()
535 ->status_area_widget()
536 ->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28537}
538
[email protected]a0afeb12012-12-10 22:57:09539bool Shell::HasPrimaryStatusArea() {
jamescook612205f2016-05-26 06:02:11540 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf_widget();
[email protected]478c6c32013-03-09 02:50:58541 return shelf && shelf->status_area_widget();
[email protected]31f19e32012-10-30 22:31:23542}
543
[email protected]a0afeb12012-12-10 22:57:09544SystemTray* Shell::GetPrimarySystemTray() {
545 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42546}
547
[email protected]8b57e942013-12-09 19:39:20548ShelfDelegate* Shell::GetShelfDelegate() {
549 if (!shelf_delegate_) {
[email protected]8b57e942013-12-09 19:39:20550 // Creates ShelfItemDelegateManager before ShelfDelegate.
[email protected]c25ff502013-12-04 13:52:48551 shelf_item_delegate_manager_.reset(
552 new ShelfItemDelegateManager(shelf_model_.get()));
[email protected]6777f632013-10-15 02:38:41553
msw0414d4122016-07-06 22:58:48554 shelf_delegate_.reset(
555 wm_shell_->delegate()->CreateShelfDelegate(shelf_model_.get()));
dchenga94547472016-04-08 08:41:11556 std::unique_ptr<ShelfItemDelegate> controller(new AppListShelfItemDelegate);
[email protected]6777f632013-10-15 02:38:41557
[email protected]64936bf2013-11-14 19:48:36558 // Finding the shelf model's location of the app list and setting its
[email protected]c25ff502013-12-04 13:52:48559 // ShelfItemDelegate.
[email protected]b7b4dec2013-11-18 06:16:12560 int app_list_index = shelf_model_->GetItemIndexForType(TYPE_APP_LIST);
[email protected]3fced99a2013-10-23 17:16:25561 DCHECK_GE(app_list_index, 0);
[email protected]eec0971422014-02-03 23:51:27562 ShelfID app_list_id = shelf_model_->items()[app_list_index].id;
[email protected]6777f632013-10-15 02:38:41563 DCHECK(app_list_id);
[email protected]c25ff502013-12-04 13:52:48564 shelf_item_delegate_manager_->SetShelfItemDelegate(app_list_id,
dchengcbf0d9d2015-12-27 22:49:23565 std::move(controller));
[email protected]093b8d642014-04-03 20:59:28566 shelf_window_watcher_.reset(new ShelfWindowWatcher(
567 shelf_model_.get(), shelf_item_delegate_manager_.get()));
[email protected]b913a3a2012-12-11 13:07:19568 }
[email protected]8b57e942013-12-09 19:39:20569 return shelf_delegate_.get();
[email protected]b913a3a2012-12-11 13:07:19570}
571
[email protected]2b8a9bb2013-07-01 22:43:40572void Shell::SetTouchHudProjectionEnabled(bool enabled) {
573 if (is_touch_hud_projection_enabled_ == enabled)
574 return;
575
[email protected]2b8a9bb2013-07-01 22:43:40576 is_touch_hud_projection_enabled_ = enabled;
skyd76167d2016-07-01 00:05:12577 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
[email protected]d141b922013-07-09 08:13:17578 OnTouchHudProjectionToggled(enabled));
[email protected]2b8a9bb2013-07-01 22:43:40579}
580
[email protected]59ccade2013-10-17 17:56:40581#if defined(OS_CHROMEOS)
mswa7e8a5f2016-03-01 04:15:06582FirstRunHelper* Shell::CreateFirstRunHelper() {
583 return new FirstRunHelperImpl;
[email protected]59ccade2013-10-17 17:56:40584}
[email protected]87ec2202014-02-06 06:24:27585
586void Shell::SetCursorCompositingEnabled(bool enabled) {
oshimae2818922015-07-28 01:18:52587 window_tree_host_manager_->cursor_window_controller()
588 ->SetCursorCompositingEnabled(enabled);
[email protected]87ec2202014-02-06 06:24:27589 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
590}
[email protected]59ccade2013-10-17 17:56:40591#endif // defined(OS_CHROMEOS)
592
[email protected]f9466702012-09-17 16:35:27593void Shell::DoInitialWorkspaceAnimation() {
jamescookb8dcef522016-06-25 14:42:55594 return GetPrimaryRootWindowController()
595 ->workspace_controller()
596 ->DoInitialAnimation();
[email protected]f9466702012-09-17 16:35:27597}
598
[email protected]b6ba05d902013-10-04 21:38:45599////////////////////////////////////////////////////////////////////////////////
600// Shell, private:
601
ben0d6be2d42015-09-26 04:37:19602Shell::Shell(ShellDelegate* delegate, base::SequencedWorkerPool* blocking_pool)
msw0414d4122016-07-06 22:58:48603 : wm_shell_(new WmShellAura(delegate)),
604 target_root_window_(nullptr),
achuith287b26e2015-09-03 17:49:18605 scoped_target_root_window_(nullptr),
msw174379b2016-04-05 00:25:11606 shelf_model_(new ShelfModel),
yusukes1168eda2016-04-27 07:52:08607 link_handler_model_factory_(nullptr),
achuith287b26e2015-09-03 17:49:18608 activation_client_(nullptr),
[email protected]94545ca92014-03-29 01:17:59609#if defined(OS_CHROMEOS)
[email protected]1e31cbd2014-04-07 20:06:11610 display_configurator_(new ui::DisplayConfigurator()),
[email protected]94545ca92014-03-29 01:17:59611#endif // defined(OS_CHROMEOS)
sadrul7a8785e2016-02-12 21:54:35612 native_cursor_manager_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45613 simulate_modal_window_open_for_testing_(false),
ben0d6be2d42015-09-26 04:37:19614 is_touch_hud_projection_enabled_(false),
615 blocking_pool_(blocking_pool) {
sadrul679eb98f2015-08-07 05:25:10616 DCHECK(aura::Env::GetInstanceDontCreate());
msw0414d4122016-07-06 22:58:48617 gpu_support_.reset(wm_shell_->delegate()->CreateGPUSupport());
[email protected]093b8d642014-04-03 20:59:28618 display_manager_.reset(new DisplayManager);
oshimae2818922015-07-28 01:18:52619 window_tree_host_manager_.reset(new WindowTreeHostManager);
[email protected]5d2ea362013-12-13 08:10:18620 user_metrics_recorder_.reset(new UserMetricsRecorder);
[email protected]b6ba05d902013-10-04 21:38:45621
622#if defined(OS_CHROMEOS)
[email protected]093b8d642014-04-03 20:59:28623 PowerStatus::Initialize();
[email protected]b6ba05d902013-10-04 21:38:45624#endif
625}
626
627Shell::~Shell() {
628 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
629
bruthigc24d11f2015-06-09 21:30:03630 user_metrics_recorder_->OnShellShuttingDown();
631
msw0414d4122016-07-06 22:58:48632 wm_shell_->delegate()->PreShutdown();
[email protected]050e77182014-03-25 15:29:16633
achuith287b26e2015-09-03 17:49:18634 views::FocusManagerFactory::Install(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45635
636 // Remove the focus from any window. This will prevent overhead and side
637 // effects (e.g. crashes) from changing focus during shutdown.
638 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18639 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45640
641 // Please keep in same order as in Init() because it's easy to miss one.
642 if (window_modality_controller_)
643 window_modality_controller_.reset();
oshimae2818922015-07-28 01:18:52644 RemovePreTargetHandler(
645 window_tree_host_manager_->input_method_event_handler());
spange9b51272014-12-11 01:20:10646#if defined(OS_CHROMEOS)
[email protected]e4ea52362014-02-15 03:21:06647 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
648 magnifier_key_scroll_handler_.reset();
649
650 RemovePreTargetHandler(speech_feedback_handler_.get());
651 speech_feedback_handler_.reset();
[email protected]3dff2ef2014-02-09 22:50:39652#endif
[email protected]b6ba05d902013-10-04 21:38:45653 RemovePreTargetHandler(overlay_filter_.get());
[email protected]3537d472014-01-15 05:45:31654 RemovePreTargetHandler(accelerator_filter_.get());
655 RemovePreTargetHandler(event_transformation_handler_.get());
656 RemovePreTargetHandler(toplevel_window_event_handler_.get());
657 RemovePostTargetHandler(toplevel_window_event_handler_.get());
[email protected]342d56a2013-12-20 23:01:02658 RemovePreTargetHandler(system_gesture_filter_.get());
659 RemovePreTargetHandler(keyboard_metrics_filter_.get());
[email protected]8ab613cf2014-05-12 09:39:49660 RemovePreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45661
662 // TooltipController is deleted with the Shell so removing its references.
663 RemovePreTargetHandler(tooltip_controller_.get());
664
jonross0af45212015-01-13 18:55:46665#if defined(OS_CHROMEOS)
666 screen_orientation_controller_.reset();
667#endif
668
rsadambbaf2c82015-01-07 17:54:13669// Destroy the virtual keyboard controller before the maximize mode controller
670// since the latters destructor triggers events that the former is listening
671// to but no longer cares about.
672#if defined(OS_CHROMEOS)
673 virtual_keyboard_controller_.reset();
674#endif
jonross0af45212015-01-13 18:55:46675
[email protected]2a57beb52014-06-09 20:02:26676 // Destroy maximize mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57677 // need to be removed.
skyc68696c2016-07-01 21:06:02678 wm_shell_->DeleteMaximizeModeController();
[email protected]5ed2b642014-03-04 00:06:57679
jdufault551152e2016-01-27 19:48:43680 // Destroy the keyboard before closing the shelf, since it will invoke a shelf
681 // layout.
682 DeactivateKeyboard();
683
yoshiki32f51632016-03-24 01:24:43684 // Destroy toasts
685 toast_manager_.reset();
686
jdufault551152e2016-01-27 19:48:43687 // Destroy SystemTrayDelegate before destroying the status area(s). Make sure
688 // to deinitialize the shelf first, as it is initialized after the delegate.
jamescookf17ee242016-05-25 21:22:00689 ShutdownShelf();
jamescookb7381052016-06-28 23:43:43690 wm_shell_->DeleteSystemTrayDelegate();
[email protected]b6ba05d902013-10-04 21:38:45691
692 locale_notification_controller_.reset();
693
694 // Drag-and-drop must be canceled prior to close all windows.
695 drag_drop_controller_.reset();
696
jamescookb8dcef522016-06-25 14:42:55697// Controllers who have WindowObserver added must be deleted
698// before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03699
700#if defined(OS_CHROMEOS)
701 // VideoActivityNotifier must be deleted before |video_detector_| is
702 // deleted because it's observing video activity through
derat83b761392016-07-11 16:44:44703 // VideoDetector::Observer interface.
[email protected]8c9d12a2013-12-06 18:39:03704 video_activity_notifier_.reset();
705#endif // defined(OS_CHROMEOS)
706 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25707 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03708
709 shadow_controller_.reset();
710 resize_shadow_controller_.reset();
711
[email protected]dd1e1ac2014-05-13 03:44:09712 window_cycle_controller_.reset();
sky3be9c592016-06-23 01:08:33713 wm_shell_->DeleteWindowSelectorController();
[email protected]8c9d12a2013-12-06 18:39:03714
715 // |shelf_window_watcher_| has a weak pointer to |shelf_Model_|
716 // and has window observers.
717 shelf_window_watcher_.reset();
718
[email protected]b6ba05d902013-10-04 21:38:45719 // Destroy all child windows including widgets.
oshimae2818922015-07-28 01:18:52720 window_tree_host_manager_->CloseChildWindows();
afakhry58159392015-05-22 02:45:52721 // MruWindowTracker must be destroyed after all windows have been deleted to
722 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
723 // path. (crbug.com/485438).
skyd76167d2016-07-01 00:05:12724 wm_shell_->DeleteMruWindowTracker();
[email protected]b6ba05d902013-10-04 21:38:45725
[email protected]8b57e942013-12-09 19:39:20726 // Chrome implementation of shelf delegate depends on FocusClient,
dtseng4ae0a882016-04-15 21:39:27727 // so must be deleted before |focus_client_| (below).
[email protected]8b57e942013-12-09 19:39:20728 shelf_delegate_.reset();
[email protected]8c9d12a2013-12-06 18:39:03729
[email protected]b6ba05d902013-10-04 21:38:45730 // These need a valid Shell instance to clean up properly, so explicitly
731 // delete them before invalidating the instance.
732 // Alphabetical. TODO(oshima): sort.
733 magnification_controller_.reset();
734 partial_magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45735 tooltip_controller_.reset();
736 event_client_.reset();
[email protected]3537d472014-01-15 05:45:31737 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45738 visibility_controller_.reset();
[email protected]c25ff502013-12-04 13:52:48739 // |shelf_item_delegate_manager_| observes |shelf_model_|. It must be
[email protected]64936bf2013-11-14 19:48:36740 // destroyed before |shelf_model_| is destroyed.
[email protected]c25ff502013-12-04 13:52:48741 shelf_item_delegate_manager_.reset();
[email protected]64936bf2013-11-14 19:48:36742 shelf_model_.reset();
[email protected]b6ba05d902013-10-04 21:38:45743
744 power_button_controller_.reset();
745 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45746
hidehiko6821ca42016-06-18 11:12:23747 screen_pinning_controller_.reset();
748
[email protected]7bc49bd2014-01-22 09:30:34749#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45750 resolution_notification_controller_.reset();
[email protected]7bc49bd2014-01-22 09:30:34751#endif
[email protected]b6ba05d902013-10-04 21:38:45752 desktop_background_controller_.reset();
oshima5a296e82016-04-29 01:32:27753 screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49754 mouse_cursor_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45755
dnicoara8c3bd1e62014-10-30 19:53:39756#if defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:49757 touch_transformer_controller_.reset();
dnicoara8c3bd1e62014-10-30 19:53:39758#endif // defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:49759
warx533c8f62016-04-12 01:19:43760#if defined(OS_CHROMEOS)
761 audio_a11y_controller_.reset();
762#endif // defined(OS_CHROMEOS)
763
[email protected]b6ba05d902013-10-04 21:38:45764 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52765 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
766 // destruction
[email protected]b6ba05d902013-10-04 21:38:45767 // of its owned RootWindowControllers relies on the value.
[email protected]55ad8c12014-01-17 18:24:33768 display_manager_->CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12769 display_configuration_controller_.reset();
dtseng4ae0a882016-04-15 21:39:27770
sky88bd4be62016-06-09 17:34:41771 wm_shell_->PrepareForShutdown();
dtseng4ae0a882016-04-15 21:39:27772 // Depends on |focus_client_|, so must be destroyed before.
oshimae2818922015-07-28 01:18:52773 window_tree_host_manager_->Shutdown();
774 window_tree_host_manager_.reset();
dtseng4ae0a882016-04-15 21:39:27775 focus_client_.reset();
[email protected]b6ba05d902013-10-04 21:38:45776 screen_position_controller_.reset();
[email protected]f3ab6eff52013-10-24 03:29:38777 accessibility_delegate_.reset();
[email protected]efc897f72013-11-01 11:43:07778 new_window_delegate_.reset();
jamescook214fcbde2016-04-28 01:16:06779 pointer_watcher_delegate_.reset();
[email protected]b6ba05d902013-10-04 21:38:45780
shuchen29f3c7a2015-06-10 07:48:28781 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]a0b3fb882014-04-07 19:26:03782
[email protected]94545ca92014-03-29 01:17:59783#if defined(OS_CHROMEOS)
robert.bradfordab052492015-05-06 11:09:56784 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34785 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11786 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45787 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11788 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43789 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11790 display_configurator_->RemoveObserver(projecting_observer_.get());
skyd76167d2016-07-01 00:05:12791 wm_shell_->RemoveShellObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43792 }
[email protected]b6ba05d902013-10-04 21:38:45793 display_change_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45794
[email protected]093b8d642014-04-03 20:59:28795 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18796
797 // Ensure that DBusThreadManager outlives this Shell.
798 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45799#endif
800
sky88bd4be62016-06-09 17:34:41801 // Needs to happen right before |instance_| is reset.
802 wm_shell_.reset();
803
[email protected]b6ba05d902013-10-04 21:38:45804 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18805 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45806}
807
[email protected]1b4c7472014-05-15 18:32:23808void Shell::Init(const ShellInitParams& init_params) {
skyfee520c2016-02-11 19:57:46809 in_mus_ = init_params.in_mus;
sky984c1892016-04-20 00:00:34810
oshima3769b462016-04-25 16:49:18811#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
812 DCHECK(in_mus_) << "linux desktop does not support ash.";
813#endif
814
sky6624a7af2016-05-27 18:47:49815 scoped_overview_animation_settings_factory_.reset(
816 new ScopedOverviewAnimationSettingsFactoryAura);
sky0702b272016-06-03 22:10:41817 window_positioner_.reset(new WindowPositioner(wm_shell_.get()));
sky984c1892016-04-20 00:00:34818
sadrul7a8785e2016-02-12 21:54:35819 if (!in_mus_) {
820 native_cursor_manager_ = new AshNativeCursorManager;
821#if defined(OS_CHROMEOS)
822 cursor_manager_.reset(
dchenga94547472016-04-08 08:41:11823 new CursorManager(base::WrapUnique(native_cursor_manager_)));
sadrul7a8785e2016-02-12 21:54:35824#else
825 cursor_manager_.reset(
dchenga94547472016-04-08 08:41:11826 new ::wm::CursorManager(base::WrapUnique(native_cursor_manager_)));
sadrul7a8785e2016-02-12 21:54:35827#endif
828 }
skyfee520c2016-02-11 19:57:46829
msw0414d4122016-07-06 22:58:48830 wm_shell_->delegate()->PreInit();
[email protected]0249a6532013-10-31 06:53:34831 bool display_initialized = display_manager_->InitFromCommandLine();
stevenjb537c5c3f2016-01-20 23:38:12832
833 display_configuration_controller_.reset(new DisplayConfigurationController(
834 display_manager_.get(), window_tree_host_manager_.get()));
835
[email protected]94545ca92014-03-29 01:17:59836#if defined(OS_CHROMEOS)
kylecharfb5f6af2016-06-21 20:13:32837 // When running as part of mash display configuration is handled by the mus
838 // process, so we won't try to configure displays here.
839 if (in_mus_) {
kylecharde485eb2016-03-11 17:39:30840 display_configurator_->set_configure_display(false);
kylecharfb5f6af2016-06-21 20:13:32841 } else {
oshimae001c8c2016-04-13 23:49:04842#if defined(USE_OZONE)
kylecharfb5f6af2016-06-21 20:13:32843 display_configurator_->Init(
844 ui::OzonePlatform::GetInstance()->CreateNativeDisplayDelegate(),
845 !gpu_support_->IsPanelFittingDisabled());
oshimae001c8c2016-04-13 23:49:04846#elif defined(USE_X11)
kylecharfb5f6af2016-06-21 20:13:32847 display_configurator_->Init(
848 base::WrapUnique(new ui::NativeDisplayDelegateX11()),
849 !gpu_support_->IsPanelFittingDisabled());
oshimae001c8c2016-04-13 23:49:04850#endif
kylecharfb5f6af2016-06-21 20:13:32851 }
[email protected]0249a6532013-10-31 06:53:34852
pneubeck8be1f5422014-10-09 16:46:18853 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
854 chromeos::DBusThreadManager* dbus_thread_manager =
855 chromeos::DBusThreadManager::Get();
856 projecting_observer_.reset(
857 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11858 display_configurator_->AddObserver(projecting_observer_.get());
skyd76167d2016-07-01 00:05:12859 wm_shell_->AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26860
kylecharfb5f6af2016-06-21 20:13:32861 if (!in_mus_ && !display_initialized &&
862 base::SysInfo::IsRunningOnChromeOS()) {
[email protected]093b8d642014-04-03 20:59:28863 display_change_observer_.reset(new DisplayChangeObserver);
[email protected]b6ba05d902013-10-04 21:38:45864 // Register |display_change_observer_| first so that the rest of
865 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11866 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28867 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11868 display_configurator_->AddObserver(display_error_observer_.get());
869 display_configurator_->set_state_controller(display_change_observer_.get());
870 display_configurator_->set_mirroring_controller(display_manager_.get());
871 display_configurator_->ForceInitialConfigure(
msw0414d4122016-07-06 22:58:48872 wm_shell_->delegate()->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
[email protected]b6ba05d902013-10-04 21:38:45873 display_initialized = true;
874 }
robert.bradfordab052492015-05-06 11:09:56875 display_color_manager_.reset(
ben0d6be2d42015-09-26 04:37:19876 new DisplayColorManager(display_configurator_.get(), blocking_pool_));
[email protected]94545ca92014-03-29 01:17:59877#endif // defined(OS_CHROMEOS)
stevenjb537c5c3f2016-01-20 23:38:12878
[email protected]b6ba05d902013-10-04 21:38:45879 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34880 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45881
mukai5dad2e72014-12-16 00:00:30882 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32883
[email protected]b6ba05d902013-10-04 21:38:45884 // Install the custom factory first so that views::FocusManagers for Tray,
[email protected]864b58552013-12-19 04:19:38885 // Shelf, and WallPaper could be created by the factory.
[email protected]b6ba05d902013-10-04 21:38:45886 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
887
[email protected]fa69f2b62014-05-22 21:47:58888 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
[email protected]ecca62b2013-10-09 16:18:53889
[email protected]b6ba05d902013-10-04 21:38:45890 // The WindowModalityController needs to be at the front of the input event
891 // pretarget handler list to ensure that it processes input events when modal
892 // windows are active.
jamescookb8dcef522016-06-25 14:42:55893 window_modality_controller_.reset(new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45894
[email protected]e319c7e2014-03-14 19:56:14895 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45896 AddPreTargetHandler(env_filter_.get());
897
afakhrycae0618f2015-01-12 17:57:43898 wm::AshFocusRules* focus_rules = new wm::AshFocusRules();
899
[email protected]e319c7e2014-03-14 19:56:14900 ::wm::FocusController* focus_controller =
afakhrycae0618f2015-01-12 17:57:43901 new ::wm::FocusController(focus_rules);
[email protected]b6ba05d902013-10-04 21:38:45902 focus_client_.reset(focus_controller);
903 activation_client_ = focus_controller;
904 activation_client_->AddObserver(this);
[email protected]b6ba05d902013-10-04 21:38:45905
[email protected]093b8d642014-04-03 20:59:28906 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45907
oshimae2818922015-07-28 01:18:52908 window_tree_host_manager_->Start();
909 window_tree_host_manager_->CreatePrimaryHost(
[email protected]1b4c7472014-05-15 18:32:23910 ShellInitParamsToAshWindowTreeHostInitParams(init_params));
oshimae2818922015-07-28 01:18:52911 aura::Window* root_window = window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45912 target_root_window_ = root_window;
913
[email protected]7bc49bd2014-01-22 09:30:34914#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45915 resolution_notification_controller_.reset(
[email protected]093b8d642014-04-03 20:59:28916 new ResolutionNotificationController);
[email protected]7bc49bd2014-01-22 09:30:34917#endif
[email protected]b6ba05d902013-10-04 21:38:45918
sadrul7a8785e2016-02-12 21:54:35919 if (cursor_manager_)
oshimaf84b0da722016-04-27 19:47:19920 cursor_manager_->SetDisplay(
921 display::Screen::GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:45922
[email protected]b6ba05d902013-10-04 21:38:45923 accelerator_controller_.reset(new AcceleratorController);
skyc68696c2016-07-01 21:06:02924 wm_shell_->CreateMaximizeModeController();
[email protected]b6ba05d902013-10-04 21:38:45925
oshimae2818922015-07-28 01:18:52926 AddPreTargetHandler(window_tree_host_manager_->input_method_event_handler());
oshima5e0fff82015-06-27 01:31:30927
spange9b51272014-12-11 01:20:10928#if defined(OS_CHROMEOS)
929 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06930 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10931 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06932 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39933#endif
934
[email protected]b6ba05d902013-10-04 21:38:45935 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45936
derat2d4e62d2015-01-09 16:09:17937 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45938 // rewritten first.
derat2d4e62d2015-01-09 16:09:17939 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45940
[email protected]093b8d642014-04-03 20:59:28941 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45942 AddPreTargetHandler(overlay_filter_.get());
skyd76167d2016-07-01 00:05:12943 wm_shell_->AddShellObserver(overlay_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45944
[email protected]60d677d2014-05-30 13:07:02945 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchenga94547472016-04-08 08:41:11946 std::unique_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
afakhry55463732014-11-21 21:06:16947 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45948 AddPreTargetHandler(accelerator_filter_.get());
949
[email protected]093b8d642014-04-03 20:59:28950 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45951 AddPreTargetHandler(event_transformation_handler_.get());
952
skycf67ed5a2016-05-23 19:38:39953 toplevel_window_event_handler_.reset(
sky0702b272016-06-03 22:10:41954 new ToplevelWindowEventHandler(wm_shell_.get()));
[email protected]3537d472014-01-15 05:45:31955
[email protected]093b8d642014-04-03 20:59:28956 system_gesture_filter_.reset(new SystemGestureEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45957 AddPreTargetHandler(system_gesture_filter_.get());
958
[email protected]093b8d642014-04-03 20:59:28959 keyboard_metrics_filter_.reset(new KeyboardUMAEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45960 AddPreTargetHandler(keyboard_metrics_filter_.get());
961
[email protected]354520b2014-06-21 04:31:01962#if defined(OS_CHROMEOS)
963 sticky_keys_controller_.reset(new StickyKeysController);
964#endif
skyd76167d2016-07-01 00:05:12965 screen_pinning_controller_.reset(
966 new ScreenPinningController(window_tree_host_manager_.get()));
[email protected]354520b2014-06-21 04:31:01967
[email protected]b6ba05d902013-10-04 21:38:45968 lock_state_controller_.reset(new LockStateController);
jamescookb8dcef522016-06-25 14:42:55969 power_button_controller_.reset(
970 new PowerButtonController(lock_state_controller_.get()));
[email protected]94545ca92014-03-29 01:17:59971#if defined(OS_CHROMEOS)
[email protected]685442f32014-02-28 10:40:06972 // Pass the initial display state to PowerButtonController.
973 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:09974 display_configurator_->cached_displays());
[email protected]685442f32014-02-28 10:40:06975#endif
skyd76167d2016-07-01 00:05:12976 wm_shell_->AddShellObserver(lock_state_controller_.get());
[email protected]b6ba05d902013-10-04 21:38:45977
[email protected]093b8d642014-04-03 20:59:28978 drag_drop_controller_.reset(new DragDropController);
oshima5a296e82016-04-29 01:32:27979 // |screenshot_controller_| needs to be created (and prepended as a
mukai19274bdd2015-02-24 22:37:48980 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
oshima5a296e82016-04-29 01:32:27981 // process mouse events prior to screenshot session.
mukai19274bdd2015-02-24 22:37:48982 // See http://crbug.com/459214
oshima5a296e82016-04-29 01:32:27983 screenshot_controller_.reset(new ScreenshotController());
[email protected]093b8d642014-04-03 20:59:28984 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
[email protected]b6ba05d902013-10-04 21:38:45985 PrependPreTargetHandler(mouse_cursor_filter_.get());
986
987 // Create Controllers that may need root window.
988 // TODO(oshima): Move as many controllers before creating
989 // RootWindowController as possible.
990 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:45991
jamescookb8dcef522016-06-25 14:42:55992 magnification_controller_.reset(MagnificationController::CreateInstance());
skyd76167d2016-07-01 00:05:12993 wm_shell_->CreateMruWindowTracker();
[email protected]b6ba05d902013-10-04 21:38:45994
jamescookb8dcef522016-06-25 14:42:55995 partial_magnification_controller_.reset(new PartialMagnificationController());
[email protected]b6ba05d902013-10-04 21:38:45996
[email protected]55398d22013-10-10 19:49:20997 autoclick_controller_.reset(AutoclickController::CreateInstance());
998
[email protected]b6ba05d902013-10-04 21:38:45999 high_contrast_controller_.reset(new HighContrastController);
1000 video_detector_.reset(new VideoDetector);
[email protected]dd1e1ac2014-05-13 03:44:091001 window_cycle_controller_.reset(new WindowCycleController());
[email protected]b6ba05d902013-10-04 21:38:451002
oshimaebbe63772015-02-19 18:41:321003 tooltip_controller_.reset(new views::corewm::TooltipController(
dchenga94547472016-04-08 08:41:111004 std::unique_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451005 AddPreTargetHandler(tooltip_controller_.get());
1006
[email protected]093b8d642014-04-03 20:59:281007 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451008
1009 // This controller needs to be set before SetupManagedWindowMode.
ben0d6be2d42015-09-26 04:37:191010 desktop_background_controller_.reset(
1011 new DesktopBackgroundController(blocking_pool_));
msw0414d4122016-07-06 22:58:481012 user_wallpaper_delegate_.reset(
1013 wm_shell_->delegate()->CreateUserWallpaperDelegate());
[email protected]b6ba05d902013-10-04 21:38:451014
msw0414d4122016-07-06 22:58:481015 session_state_delegate_.reset(
1016 wm_shell_->delegate()->CreateSessionStateDelegate());
1017 accessibility_delegate_.reset(
1018 wm_shell_->delegate()->CreateAccessibilityDelegate());
1019 new_window_delegate_.reset(wm_shell_->delegate()->CreateNewWindowDelegate());
msw2e51cdd2016-06-30 22:18:321020 wm_shell_->SetMediaDelegate(
msw0414d4122016-07-06 22:58:481021 base::WrapUnique(wm_shell_->delegate()->CreateMediaDelegate()));
1022 pointer_watcher_delegate_ =
1023 wm_shell_->delegate()->CreatePointerWatcherDelegate();
[email protected]b6ba05d902013-10-04 21:38:451024
[email protected]093b8d642014-04-03 20:59:281025 resize_shadow_controller_.reset(new ResizeShadowController());
jamescookb8dcef522016-06-25 14:42:551026 shadow_controller_.reset(new ::wm::ShadowController(activation_client_));
[email protected]b6ba05d902013-10-04 21:38:451027
msw2e51cdd2016-06-30 22:18:321028 wm_shell_->SetSystemTrayDelegate(
msw0414d4122016-07-06 22:58:481029 base::WrapUnique(wm_shell_->delegate()->CreateSystemTrayDelegate()));
[email protected]b6ba05d902013-10-04 21:38:451030
[email protected]093b8d642014-04-03 20:59:281031 locale_notification_controller_.reset(new LocaleNotificationController);
[email protected]b6ba05d902013-10-04 21:38:451032
yoshiki32f51632016-03-24 01:24:431033 // Initialize toast manager
1034 toast_manager_.reset(new ToastManager);
1035
[email protected]0dc85512014-03-13 13:26:411036#if defined(OS_CHROMEOS)
oshimae2818922015-07-28 01:18:521037 // Create TouchTransformerController before
1038 // WindowTreeHostManager::InitDisplays()
[email protected]03122891a2014-05-13 23:56:491039 // since TouchTransformerController listens on
oshimae2818922015-07-28 01:18:521040 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
kylechard2fcd542016-06-07 17:19:541041 if (!in_mus_)
1042 touch_transformer_controller_.reset(new TouchTransformerController());
dnicoara8c3bd1e62014-10-30 19:53:391043#endif // defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:491044
jamescookc3fbf0952016-06-29 06:48:311045 wm_shell_->SetKeyboardUI(init_params.keyboard_factory.is_null()
1046 ? KeyboardUI::Create()
1047 : init_params.keyboard_factory.Run());
skyfee520c2016-02-11 19:57:461048
oshimae2818922015-07-28 01:18:521049 window_tree_host_manager_->InitHosts();
[email protected]b6ba05d902013-10-04 21:38:451050
rsadam9172bc8a2014-10-29 23:37:381051#if defined(OS_CHROMEOS)
1052 // Needs to be created after InitDisplays() since it may cause the virtual
1053 // keyboard to be deployed.
1054 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
1055#endif // defined(OS_CHROMEOS)
1056
warx533c8f62016-04-12 01:19:431057#if defined(OS_CHROMEOS)
1058 audio_a11y_controller_.reset(new chromeos::AudioA11yController);
1059#endif // defined(OS_CHROMEOS)
1060
[email protected]a3565792013-10-18 12:52:371061 // It needs to be created after RootWindowController has been created
1062 // (which calls OnWindowResized has been called, otherwise the
[email protected]b6ba05d902013-10-04 21:38:451063 // widget will not paint when restoring after a browser crash. Also it needs
1064 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
1065 // the correct size.
1066 user_wallpaper_delegate_->InitializeWallpaper();
1067
sadrul7a8785e2016-02-12 21:54:351068 if (cursor_manager_) {
1069 if (initially_hide_cursor_)
1070 cursor_manager_->HideCursor();
1071 cursor_manager_->SetCursor(ui::kCursorPointer);
1072 }
[email protected]b6ba05d902013-10-04 21:38:451073
[email protected]5c04d3a92013-10-08 19:17:191074#if defined(OS_CHROMEOS)
[email protected]093b8d642014-04-03 20:59:281075 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551076 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571077 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551078 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281079 new VideoActivityNotifier(video_detector_.get()));
1080 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
jonross0af45212015-01-13 18:55:461081 screen_orientation_controller_.reset(new ScreenOrientationController());
[email protected]b6ba05d902013-10-04 21:38:451082#endif
[email protected]b6ba05d902013-10-04 21:38:451083 // The compositor thread and main message loop have to be running in
1084 // order to create mirror window. Run it after the main message loop
1085 // is started.
oshimac8089b82014-11-12 21:43:501086 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031087
skyd76167d2016-07-01 00:05:121088 FOR_EACH_OBSERVER(ShellObserver, *wm_shell_->shell_observers(),
sky88bd4be62016-06-09 17:34:411089 OnShellInitialized());
phweiss0bf64c52015-11-17 12:56:181090
bruthigc24d11f2015-06-09 21:30:031091 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451092}
1093
[email protected]51f438112013-11-18 19:32:501094void Shell::InitKeyboard() {
skyfee520c2016-02-11 19:57:461095 if (in_mus_)
1096 return;
1097
[email protected]b6ba05d902013-10-04 21:38:451098 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031099 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451100 RootWindowControllerList controllers = GetAllRootWindowControllers();
1101 for (RootWindowControllerList::iterator iter = controllers.begin();
1102 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031103 (*iter)->DeactivateKeyboard(
1104 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451105 }
1106 }
[email protected]a0b3fb882014-04-07 19:26:031107 keyboard::KeyboardController::ResetInstance(
msw0414d4122016-07-06 22:58:481108 new keyboard::KeyboardController(
1109 wm_shell_->delegate()->CreateKeyboardUI()));
[email protected]b6ba05d902013-10-04 21:38:451110 }
1111}
1112
[email protected]41baaed2013-11-09 04:18:261113void Shell::InitRootWindow(aura::Window* root_window) {
[email protected]39718b52012-12-03 17:24:561114 DCHECK(activation_client_);
[email protected]d90b8392012-06-13 09:34:561115 DCHECK(visibility_controller_.get());
1116 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561117
[email protected]8cfb6722012-11-28 03:28:461118 aura::client::SetFocusClient(root_window, focus_client_.get());
[email protected]39718b52012-12-03 17:24:561119 aura::client::SetActivationClient(root_window, activation_client_);
[email protected]e319c7e2014-03-14 19:56:141120 ::wm::FocusController* focus_controller =
jamescookb8dcef522016-06-25 14:42:551121 static_cast<::wm::FocusController*>(activation_client_);
[email protected]375338212013-09-05 22:14:521122 root_window->AddPreTargetHandler(focus_controller);
[email protected]d90b8392012-06-13 09:34:561123 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1124 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061125 aura::client::SetScreenPositionClient(root_window,
1126 screen_position_controller_.get());
sadrul7a8785e2016-02-12 21:54:351127 aura::client::SetCursorClient(root_window, cursor_manager_.get());
[email protected]54a37cdc2012-07-25 19:16:011128 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381129 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561130
[email protected]3537d472014-01-15 05:45:311131 aura::client::SetWindowMoveClient(root_window,
jamescookb8dcef522016-06-25 14:42:551132 toplevel_window_event_handler_.get());
[email protected]3537d472014-01-15 05:45:311133 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1134 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
[email protected]d90b8392012-06-13 09:34:561135}
1136
[email protected]c0ce80e2012-10-05 23:28:271137bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1138 RootWindowControllerList controllers = GetAllRootWindowControllers();
oshima9a61ecf2016-06-18 10:43:051139 for (RootWindowController* controller : controllers) {
1140 if (controller->CanWindowReceiveEvents(window))
[email protected]602022b2014-03-31 17:07:311141 return true;
[email protected]c0ce80e2012-10-05 23:28:271142 }
1143 return false;
1144}
1145
[email protected]049cf34b2012-12-07 17:15:481146////////////////////////////////////////////////////////////////////////////////
1147// Shell, ui::EventTarget overrides:
1148
[email protected]869f6352012-12-06 20:47:171149bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411150 return true;
1151}
1152
1153ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481154 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411155}
1156
dchenga94547472016-04-08 08:41:111157std::unique_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1158 return std::unique_ptr<ui::EventTargetIterator>();
[email protected]3e670aa2013-12-02 19:04:321159}
1160
1161ui::EventTargeter* Shell::GetEventTargeter() {
1162 NOTREACHED();
achuith287b26e2015-09-03 17:49:181163 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321164}
1165
[email protected]1ae361652012-12-12 22:39:511166////////////////////////////////////////////////////////////////////////////////
1167// Shell, aura::client::ActivationChangeObserver implementation:
1168
bruthig5681d882015-06-05 15:33:211169void Shell::OnWindowActivated(
1170 aura::client::ActivationChangeObserver::ActivationReason reason,
1171 aura::Window* gained_active,
1172 aura::Window* lost_active) {
[email protected]d219a192012-12-14 00:08:181173 if (gained_active)
[email protected]b42910f2013-08-01 11:45:291174 target_root_window_ = gained_active->GetRootWindow();
[email protected]049cf34b2012-12-07 17:15:481175}
1176
[email protected]55f593352011-12-24 05:42:461177} // namespace ash