blob: d42c788367fc4b75a397f7a5db3912163d4d4967 [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"
[email protected]567c2692014-05-28 02:40:5514#include "ash/accelerators/nested_accelerator_delegate.h"
[email protected]b65bdda2011-12-23 23:35:3115#include "ash/ash_switches.h"
[email protected]55398d22013-10-10 19:49:2016#include "ash/autoclick/autoclick_controller.h"
[email protected]e70cf0ed2012-03-15 16:24:4717#include "ash/desktop_background/desktop_background_controller.h"
[email protected]e70cf0ed2012-03-15 16:24:4718#include "ash/desktop_background/desktop_background_view.h"
[email protected]81abb1032012-11-13 18:55:4119#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]87ec2202014-02-06 06:24:2720#include "ash/display/cursor_window_controller.h"
stevenjb537c5c3f2016-01-20 23:38:1221#include "ash/display/display_configuration_controller.h"
[email protected]6bdf7952012-11-14 10:10:5822#include "ash/display/display_manager.h"
[email protected]682990f2013-01-10 06:49:1123#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2724#include "ash/display/mouse_cursor_event_filter.h"
[email protected]8d625fb2012-07-18 16:40:0625#include "ash/display/screen_position_controller.h"
oshimae2818922015-07-28 01:18:5226#include "ash/display/window_tree_host_manager.h"
[email protected]f4c92b382012-08-28 00:59:5927#include "ash/drag_drop/drag_drop_controller.h"
[email protected]59ccade2013-10-17 17:56:4028#include "ash/first_run/first_run_helper_impl.h"
[email protected]f4c92b382012-08-28 00:59:5929#include "ash/focus_cycler.h"
[email protected]400a61c2014-03-13 19:40:2330#include "ash/frame/custom_frame_view_ash.h"
[email protected]1d2a7212014-01-16 06:09:4831#include "ash/gpu_support.h"
[email protected]f4c92b382012-08-28 00:59:5932#include "ash/high_contrast/high_contrast_controller.h"
[email protected]1b4c7472014-05-15 18:32:2333#include "ash/host/ash_window_tree_host_init_params.h"
oshima5e0fff82015-06-27 01:31:3034#include "ash/ime/input_method_event_handler.h"
[email protected]7a80cdd2013-09-26 09:20:5335#include "ash/keyboard_uma_event_filter.h"
[email protected]f4c92b382012-08-28 00:59:5936#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5437#include "ash/magnifier/partial_magnification_controller.h"
[email protected]efc897f72013-11-01 11:43:0738#include "ash/media_delegate.h"
[email protected]47686c42013-10-25 01:49:1739#include "ash/new_window_delegate.h"
[email protected]d90b8392012-06-13 09:34:5640#include "ash/root_window_controller.h"
[email protected]fdf74bf2014-04-30 21:24:0241#include "ash/session/session_state_delegate.h"
[email protected]976624f2013-09-19 21:58:4942#include "ash/shelf/app_list_shelf_item_delegate.h"
[email protected]8b57e942013-12-09 19:39:2043#include "ash/shelf/shelf_delegate.h"
[email protected]c25ff502013-12-04 13:52:4844#include "ash/shelf/shelf_item_delegate.h"
45#include "ash/shelf/shelf_item_delegate_manager.h"
[email protected]478c6c32013-03-09 02:50:5846#include "ash/shelf/shelf_layout_manager.h"
[email protected]64936bf2013-11-14 19:48:3647#include "ash/shelf/shelf_model.h"
[email protected]478c6c32013-03-09 02:50:5848#include "ash/shelf/shelf_widget.h"
[email protected]055a56d2013-12-06 12:13:3649#include "ash/shelf/shelf_window_watcher.h"
[email protected]b65bdda2011-12-23 23:35:3150#include "ash/shell_delegate.h"
51#include "ash/shell_factory.h"
[email protected]1b4c7472014-05-15 18:32:2352#include "ash/shell_init_params.h"
[email protected]b65bdda2011-12-23 23:35:3153#include "ash/shell_window_ids.h"
[email protected]a9a40462013-07-31 06:22:5654#include "ash/system/locale/locale_notification_controller.h"
[email protected]6d6546e2012-05-30 23:12:0255#include "ash/system/status_area_widget.h"
[email protected]51ed5992012-11-07 10:14:3956#include "ash/system/tray/system_tray_delegate.h"
[email protected]83b2b84c2012-11-14 01:11:0057#include "ash/system/tray/system_tray_notifier.h"
mukai19274bdd2015-02-24 22:37:4858#include "ash/utility/partial_screenshot_controller.h"
[email protected]0039db92012-05-09 04:11:4559#include "ash/wm/app_list_controller.h"
[email protected]39718b52012-12-03 17:24:5660#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2961#include "ash/wm/ash_native_cursor_manager.h"
[email protected]88d71122012-10-18 07:11:0162#include "ash/wm/coordinate_conversion.h"
[email protected]262f8bd2012-03-23 19:30:2763#include "ash/wm/event_client_impl.h"
[email protected]ab4f8c92013-05-30 19:07:4764#include "ash/wm/lock_state_controller.h"
[email protected]58fb353d2014-04-04 03:28:0565#include "ash/wm/maximize_mode/maximize_mode_controller.h"
[email protected]e55b73452014-02-20 13:18:0466#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
[email protected]66c5c4112013-07-31 07:10:5967#include "ash/wm/mru_window_tracker.h"
[email protected]9ae32df2012-07-26 03:25:1868#include "ash/wm/overlay_event_filter.h"
[email protected]09f35d742013-08-23 00:39:3969#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:5770#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:5771#include "ash/wm/resize_shadow_controller.h"
[email protected]a3301dc2011-12-23 16:34:5172#include "ash/wm/root_window_layout_manager.h"
[email protected]435b212e2012-04-05 19:43:3773#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2774#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3375#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]3537d472014-01-15 05:45:3176#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:5877#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:0278#include "ash/wm/window_animations.h"
[email protected]dd1e1ac2014-05-13 03:44:0979#include "ash/wm/window_cycle_controller.h"
[email protected]e9a71312013-10-04 03:20:0180#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:5781#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5982#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3683#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0084#include "base/bind.h"
primiano7182d7b2015-01-30 18:02:0385#include "base/trace_event/trace_event.h"
[email protected]2c456102011-12-26 06:26:3486#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:4487#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:5888#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:5989#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2690#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:1891#include "ui/base/ui_base_switches.h"
derat2d4e62d2015-01-09 16:09:1792#include "ui/base/user_activity/user_activity_detector.h"
[email protected]116302fc2012-05-05 21:45:4193#include "ui/compositor/layer.h"
94#include "ui/compositor/layer_animator.h"
[email protected]3e670aa2013-12-02 19:04:3295#include "ui/events/event_target_iterator.h"
[email protected]7da9c4c2012-06-12 14:43:0196#include "ui/gfx/display.h"
Avi Drissmanfefc2f82014-12-22 19:25:2997#include "ui/gfx/geometry/size.h"
[email protected]9ec0f452012-05-31 15:58:5398#include "ui/gfx/image/image_skia.h"
[email protected]b82c42c42012-04-25 20:03:4199#include "ui/gfx/screen.h"
[email protected]b6ba05d902013-10-04 21:38:45100#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28101#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56102#include "ui/keyboard/keyboard_util.h"
[email protected]8393aa62013-01-23 19:40:10103#include "ui/message_center/message_center.h"
[email protected]d7f30a72013-10-05 05:09:41104#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04105#include "ui/views/corewm/tooltip_controller.h"
[email protected]e7293fa2012-05-17 04:42:33106#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58107#include "ui/views/widget/native_widget_aura.h"
108#include "ui/views/widget/widget.h"
[email protected]60d677d2014-05-30 13:07:02109#include "ui/wm/core/accelerator_filter.h"
[email protected]ee3ed10772014-03-11 22:02:01110#include "ui/wm/core/compound_event_filter.h"
111#include "ui/wm/core/focus_controller.h"
[email protected]567c2692014-05-28 02:40:55112#include "ui/wm/core/nested_accelerator_controller.h"
[email protected]ee3ed10772014-03-11 22:02:01113#include "ui/wm/core/shadow_controller.h"
114#include "ui/wm/core/visibility_controller.h"
115#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59116
[email protected]37ce571b2013-06-28 05:28:45117#if defined(OS_CHROMEOS)
118#if defined(USE_X11)
[email protected]82f884d6ffb2014-04-15 03:34:54119#include "ui/gfx/x/x11_types.h"
[email protected]94545ca92014-03-29 01:17:59120#endif // defined(USE_X11)
spange9b51272014-12-11 01:20:10121#include "ash/accelerators/magnifier_key_scroller.h"
122#include "ash/accelerators/spoken_feedback_toggler.h"
[email protected]44d444c2013-01-30 01:47:44123#include "ash/ash_constants.h"
[email protected]c1234a42013-08-20 09:35:40124#include "ash/display/display_change_observer_chromeos.h"
benf6de9852015-10-06 21:29:28125#include "ash/display/display_color_manager_chromeos.h"
[email protected]c1234a42013-08-20 09:35:40126#include "ash/display/display_error_observer_chromeos.h"
[email protected]72bce522014-02-10 21:11:26127#include "ash/display/projecting_observer_chromeos.h"
[email protected]7bc49bd2014-01-22 09:30:34128#include "ash/display/resolution_notification_controller.h"
benf6de9852015-10-06 21:29:28129#include "ash/display/screen_orientation_controller_chromeos.h"
[email protected]08bdabed2013-12-20 07:52:28130#include "ash/sticky_keys/sticky_keys_controller.h"
[email protected]b3142722014-03-04 06:59:50131#include "ash/system/chromeos/bluetooth/bluetooth_notification_controller.h"
[email protected]25cae452013-09-26 10:15:03132#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
[email protected]51625052013-10-10 01:40:16133#include "ash/system/chromeos/power/power_event_observer.h"
[email protected]37ce571b2013-06-28 05:28:45134#include "ash/system/chromeos/power/power_status.h"
[email protected]ded58fd2013-10-09 07:56:55135#include "ash/system/chromeos/power/video_activity_notifier.h"
[email protected]94545ca92014-03-29 01:17:59136#include "ash/system/chromeos/session/last_window_closed_logout_reminder.h"
[email protected]0dc85512014-03-13 13:26:41137#include "ash/system/chromeos/session/logout_confirmation_controller.h"
dnicoara8c3bd1e62014-10-30 19:53:39138#include "ash/touch/touch_transformer_controller.h"
rsadam9172bc8a2014-10-29 23:37:38139#include "ash/virtual_keyboard_controller.h"
[email protected]0dc85512014-03-13 13:26:41140#include "base/bind_helpers.h"
[email protected]94545ca92014-03-29 01:17:59141#include "base/sys_info.h"
pneubeck8be1f5422014-10-09 16:46:18142#include "chromeos/dbus/dbus_thread_manager.h"
[email protected]b0fa7012014-04-16 12:50:57143#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]1e31cbd2014-04-07 20:06:11144#include "ui/display/chromeos/display_configurator.h"
[email protected]70b3e7d52012-06-02 22:12:25145#endif // defined(OS_CHROMEOS)
146
[email protected]55f593352011-12-24 05:42:46147namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59148
149namespace {
[email protected]671a2ae2011-10-13 21:53:23150
[email protected]615922f2012-02-07 02:41:15151using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45152using views::Widget;
153
[email protected]b5756e22012-11-30 01:32:02154// A Corewm VisibilityController subclass that calls the Ash animation routine
155// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14156class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02157 public:
158 AshVisibilityController() {}
dcheng1f4538e2014-10-27 23:57:05159 ~AshVisibilityController() override {}
[email protected]b5756e22012-11-30 01:32:02160
161 private:
[email protected]e319c7e2014-03-14 19:56:14162 // Overridden from ::wm::VisibilityController:
dcheng1f4538e2014-10-27 23:57:05163 bool CallAnimateOnChildWindowVisibilityChanged(aura::Window* window,
164 bool visible) override {
[email protected]b5756e22012-11-30 01:32:02165 return AnimateOnChildWindowVisibilityChanged(window, visible);
166 }
167
168 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
169};
170
[email protected]1b4c7472014-05-15 18:32:23171AshWindowTreeHostInitParams ShellInitParamsToAshWindowTreeHostInitParams(
172 const ShellInitParams& shell_init_params) {
173 AshWindowTreeHostInitParams ash_init_params;
174#if defined(OS_WIN)
175 ash_init_params.remote_hwnd = shell_init_params.remote_hwnd;
176#endif
177 return ash_init_params;
178}
179
[email protected]87b0d82e2011-10-07 21:02:59180} // namespace
181
[email protected]cac10fc62011-10-07 23:22:56182// static
achuith287b26e2015-09-03 17:49:18183Shell* Shell::instance_ = nullptr;
[email protected]2b4cd302012-02-24 20:21:13184// static
[email protected]9488d4d2012-02-29 18:32:37185bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13186
187////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56188// Shell, public:
189
[email protected]cac10fc62011-10-07 23:22:56190// static
[email protected]1b4c7472014-05-15 18:32:23191Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08192 CHECK(!instance_);
ben0d6be2d42015-09-26 04:37:19193 instance_ = new Shell(init_params.delegate, init_params.blocking_pool);
[email protected]1b4c7472014-05-15 18:32:23194 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08195 return instance_;
196}
197
198// static
[email protected]cac10fc62011-10-07 23:22:56199Shell* Shell::GetInstance() {
oshima9eea82da2014-09-13 01:11:07200 CHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56201 return instance_;
202}
203
[email protected]6377a002011-11-10 20:26:47204// static
[email protected]b3b7bcd2012-03-06 19:35:45205bool Shell::HasInstance() {
206 return !!instance_;
207}
208
209// static
[email protected]ef589af2011-12-03 01:07:15210void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47211 delete instance_;
achuith287b26e2015-09-03 17:49:18212 instance_ = nullptr;
[email protected]6377a002011-11-10 20:26:47213}
214
[email protected]e73bd7802012-02-17 20:10:34215// static
[email protected]093b8d642014-04-03 20:59:28216RootWindowController* Shell::GetPrimaryRootWindowController() {
oshima9eea82da2014-09-13 01:11:07217 CHECK(HasInstance());
[email protected]093b8d642014-04-03 20:59:28218 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23219}
220
221// static
222Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
oshima9eea82da2014-09-13 01:11:07223 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52224 return Shell::GetInstance()
225 ->window_tree_host_manager()
226 ->GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56227}
228
229// static
[email protected]bf9cdb362013-10-25 19:22:45230aura::Window* Shell::GetPrimaryRootWindow() {
oshima9eea82da2014-09-13 01:11:07231 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52232 return GetInstance()->window_tree_host_manager()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34233}
234
[email protected]7b0f7502012-06-11 00:12:39235// static
[email protected]bf9cdb362013-10-25 19:22:45236aura::Window* Shell::GetTargetRootWindow() {
oshima9eea82da2014-09-13 01:11:07237 CHECK(HasInstance());
[email protected]b42910f2013-08-01 11:45:29238 Shell* shell = GetInstance();
239 if (shell->scoped_target_root_window_)
240 return shell->scoped_target_root_window_;
241 return shell->target_root_window_;
[email protected]a857dbe2012-05-30 22:10:14242}
243
[email protected]7b0f7502012-06-11 00:12:39244// static
[email protected]ffabb1e2012-10-12 19:51:17245gfx::Screen* Shell::GetScreen() {
[email protected]5fdb45b2012-10-23 20:26:28246 return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
[email protected]ffabb1e2012-10-12 19:51:17247}
248
249// static
[email protected]c9390bd2013-11-08 20:33:13250aura::Window::Windows Shell::GetAllRootWindows() {
oshima9eea82da2014-09-13 01:11:07251 CHECK(HasInstance());
oshimae2818922015-07-28 01:18:52252 return Shell::GetInstance()->window_tree_host_manager()->GetAllRootWindows();
[email protected]be65be362012-06-15 07:38:23253}
254
255// static
[email protected]bf9cdb362013-10-25 19:22:45256aura::Window* Shell::GetContainer(aura::Window* root_window,
[email protected]7b0f7502012-06-11 00:12:39257 int container_id) {
258 return root_window->GetChildById(container_id);
259}
260
261// static
[email protected]bf9cdb362013-10-25 19:22:45262const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38263 int container_id) {
264 return root_window->GetChildById(container_id);
265}
266
267// static
[email protected]429433f2012-12-28 20:14:46268std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
269 int container_id,
[email protected]bf9cdb362013-10-25 19:22:45270 aura::Window* priority_root) {
[email protected]7b0f7502012-06-11 00:12:39271 std::vector<aura::Window*> containers;
[email protected]c9390bd2013-11-08 20:33:13272 aura::Window::Windows root_windows = GetAllRootWindows();
273 for (aura::Window::Windows::const_iterator it = root_windows.begin();
[email protected]001272f2012-11-02 20:05:23274 it != root_windows.end(); ++it) {
275 aura::Window* container = (*it)->GetChildById(container_id);
[email protected]429433f2012-12-28 20:14:46276 if (container) {
277 if (priority_root && priority_root->Contains(container))
278 containers.insert(containers.begin(), container);
279 else
280 containers.push_back(container);
281 }
[email protected]001272f2012-11-02 20:05:23282 }
[email protected]7b0f7502012-06-11 00:12:39283 return containers;
284}
285
[email protected]940fb1c2013-06-18 16:54:28286void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
287 ui::MenuSourceType source_type) {
[email protected]fcb123d2013-04-17 15:58:49288 // No context menus if there is no session with an active user.
[email protected]c8d19f82013-05-18 09:09:41289 if (!session_state_delegate_->NumberOfLoggedInUsers())
[email protected]f60c6232012-08-24 18:55:03290 return;
291 // No context menus when screen is locked.
[email protected]fcb123d2013-04-17 15:58:49292 if (session_state_delegate_->IsScreenLocked())
[email protected]f60c6232012-08-24 18:55:03293 return;
[email protected]431552c2012-10-23 00:38:33294
[email protected]bf9cdb362013-10-25 19:22:45295 aura::Window* root =
[email protected]431552c2012-10-23 00:38:33296 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()));
[email protected]093b8d642014-04-03 20:59:28297 GetRootWindowController(root)
298 ->ShowContextMenu(location_in_screen, source_type);
[email protected]46ca3632011-11-03 03:33:42299}
300
[email protected]1b467802014-08-15 16:03:06301void Shell::ShowAppList(aura::Window* window) {
[email protected]d17642d2013-09-12 23:44:38302 // If the context window is not given, show it on the target root window.
[email protected]ec67bc8a2013-05-06 17:44:42303 if (!window)
[email protected]d17642d2013-09-12 23:44:38304 window = GetTargetRootWindow();
[email protected]ec67bc8a2013-05-06 17:44:42305 if (!app_list_controller_)
[email protected]093b8d642014-04-03 20:59:28306 app_list_controller_.reset(new AppListController);
calamity51802a72014-08-27 02:11:28307 app_list_controller_->Show(window);
[email protected]1b467802014-08-15 16:03:06308}
309
310void Shell::DismissAppList() {
311 if (!app_list_controller_)
312 return;
calamity51802a72014-08-27 02:11:28313 app_list_controller_->Dismiss();
[email protected]1b467802014-08-15 16:03:06314}
315
316void Shell::ToggleAppList(aura::Window* window) {
[email protected]5fe76032014-08-19 02:20:58317 if (app_list_controller_ && app_list_controller_->IsVisible()) {
[email protected]1b467802014-08-15 16:03:06318 DismissAppList();
319 return;
320 }
321
322 ShowAppList(window);
[email protected]ae4987d2011-11-21 22:52:44323}
324
[email protected]7510d1082012-03-30 21:58:34325bool Shell::GetAppListTargetVisibility() const {
[email protected]ec67bc8a2013-05-06 17:44:42326 return app_list_controller_.get() &&
327 app_list_controller_->GetTargetVisibility();
[email protected]7510d1082012-03-30 21:58:34328}
329
[email protected]1e51a9d2012-04-09 23:31:11330aura::Window* Shell::GetAppListWindow() {
achuith287b26e2015-09-03 17:49:18331 return app_list_controller_.get() ? app_list_controller_->GetWindow()
332 : nullptr;
[email protected]1e51a9d2012-04-09 23:31:11333}
334
[email protected]59ccade2013-10-17 17:56:40335app_list::AppListView* Shell::GetAppListView() {
achuith287b26e2015-09-03 17:49:18336 return app_list_controller_.get() ? app_list_controller_->GetView() : nullptr;
[email protected]59ccade2013-10-17 17:56:40337}
338
[email protected]dc09739372012-11-15 20:17:39339bool Shell::IsSystemModalWindowOpen() const {
[email protected]852a55d2012-10-17 13:30:30340 if (simulate_modal_window_open_for_testing_)
341 return true;
[email protected]429433f2012-12-28 20:14:46342 const std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
achuith287b26e2015-09-03 17:49:18343 kShellWindowId_SystemModalContainer, nullptr);
[email protected]001272f2012-11-02 20:05:23344 for (std::vector<aura::Window*>::const_iterator cit = containers.begin();
345 cit != containers.end(); ++cit) {
346 for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin();
347 wit != (*cit)->children().end(); ++wit) {
348 if ((*wit)->GetProperty(aura::client::kModalKey) ==
349 ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) {
350 return true;
351 }
352 }
353 }
354 return false;
[email protected]40c4cbb2012-01-10 23:26:07355}
356
[email protected]57b8bb352012-01-11 05:11:46357views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
358 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04359 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27360 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46361}
362
[email protected]3d29912a2012-02-07 07:41:51363void Shell::RotateFocus(Direction direction) {
[email protected]093b8d642014-04-03 20:59:28364 focus_cycler_->RotateFocus(direction == FORWARD ? FocusCycler::FORWARD
365 : FocusCycler::BACKWARD);
[email protected]3d29912a2012-02-07 07:41:51366}
367
[email protected]2e236a52012-06-27 22:21:47368void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44369 const gfx::Insets& insets) {
oshimae2818922015-07-28 01:18:52370 if (!window_tree_host_manager_->UpdateWorkAreaOfDisplayNearestWindow(
[email protected]b8984242013-07-12 07:55:38371 contains, insets)) {
[email protected]1a2145b2012-03-13 21:09:17372 return;
[email protected]b8984242013-07-12 07:55:38373 }
[email protected]1a2145b2012-03-13 21:09:17374 FOR_EACH_OBSERVER(ShellObserver, observers_,
[email protected]2e236a52012-06-27 22:21:47375 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17376}
377
[email protected]82d3954ae2012-04-20 09:02:22378void Shell::OnLoginStateChanged(user::LoginStatus status) {
379 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
380}
381
[email protected]51f438112013-11-18 19:32:50382void Shell::OnLoginUserProfilePrepared() {
[email protected]864b58552013-12-19 04:19:38383 CreateShelf();
[email protected]51f438112013-11-18 19:32:50384 CreateKeyboard();
385}
386
[email protected]88d71122012-10-18 07:11:01387void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50388 RootWindowControllerList controllers = GetAllRootWindowControllers();
389 for (RootWindowControllerList::iterator iter = controllers.begin();
390 iter != controllers.end(); ++iter)
391 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01392}
393
[email protected]82d3954ae2012-04-20 09:02:22394void Shell::OnAppTerminating() {
395 FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
396}
397
398void Shell::OnLockStateChanged(bool locked) {
399 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
[email protected]ae298142013-08-10 15:30:29400#ifndef NDEBUG
401 // Make sure that there is no system modal in Lock layer when unlocked.
402 if (!locked) {
403 std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
[email protected]093b8d642014-04-03 20:59:28404 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
[email protected]ae298142013-08-10 15:30:29405 for (std::vector<aura::Window*>::const_iterator iter = containers.begin();
406 iter != containers.end(); ++iter) {
407 DCHECK_EQ(0u, (*iter)->children().size());
408 }
409 }
410#endif
[email protected]82d3954ae2012-04-20 09:02:22411}
412
[email protected]58868abf2014-01-17 23:45:33413void Shell::OnCastingSessionStartedOrStopped(bool started) {
spangb844ef02014-12-11 01:37:52414#if defined(OS_CHROMEOS)
jdufault88fb76652015-04-30 22:36:43415 FOR_EACH_OBSERVER(ShellObserver, observers_,
416 OnCastingSessionStartedOrStopped(started));
[email protected]58868abf2014-01-17 23:45:33417#endif
418}
419
[email protected]de42bcc2014-03-04 05:17:00420void Shell::OnOverviewModeStarting() {
421 FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeStarting());
422}
423
bruthigd7cf765b2015-01-20 19:32:27424void Shell::OnOverviewModeEnded() {
425 FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeEnded());
[email protected]de42bcc2014-03-04 05:17:00426}
427
[email protected]02a80052014-03-14 05:45:23428void Shell::OnMaximizeModeStarted() {
429 FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeStarted());
430}
431
432void Shell::OnMaximizeModeEnded() {
433 FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeEnded());
434}
435
[email protected]0e3e7cb2014-04-12 05:18:25436void Shell::OnRootWindowAdded(aura::Window* root_window) {
437 FOR_EACH_OBSERVER(ShellObserver, observers_, OnRootWindowAdded(root_window));
438}
439
[email protected]864b58552013-12-19 04:19:38440void Shell::CreateShelf() {
[email protected]8c0ec432013-05-10 04:33:39441 RootWindowControllerList controllers = GetAllRootWindowControllers();
442 for (RootWindowControllerList::iterator iter = controllers.begin();
443 iter != controllers.end(); ++iter)
[email protected]864b58552013-12-19 04:19:38444 (*iter)->shelf()->CreateShelf();
[email protected]d9456cb2012-03-21 16:41:04445}
446
[email protected]b8642ec2014-04-17 05:20:39447void Shell::OnShelfCreatedForRootWindow(aura::Window* root_window) {
448 FOR_EACH_OBSERVER(ShellObserver,
449 observers_,
450 OnShelfCreatedForRootWindow(root_window));
451}
452
[email protected]51f438112013-11-18 19:32:50453void Shell::CreateKeyboard() {
454 // TODO(bshe): Primary root window controller may not be the controller to
455 // attach virtual keyboard. See http://crbug.com/303429
456 InitKeyboard();
bshe9858b4a2014-09-16 20:46:38457 GetPrimaryRootWindowController()->
458 ActivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50459}
460
[email protected]e1b299b2014-01-29 23:53:41461void Shell::DeactivateKeyboard() {
[email protected]a0b3fb882014-04-07 19:26:03462 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41463 RootWindowControllerList controllers = GetAllRootWindowControllers();
464 for (RootWindowControllerList::iterator iter = controllers.begin();
465 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03466 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41467 }
468 }
achuith287b26e2015-09-03 17:49:18469 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]e1b299b2014-01-29 23:53:41470}
471
[email protected]864b58552013-12-19 04:19:38472void Shell::ShowShelf() {
[email protected]8c0ec432013-05-10 04:33:39473 RootWindowControllerList controllers = GetAllRootWindowControllers();
474 for (RootWindowControllerList::iterator iter = controllers.begin();
475 iter != controllers.end(); ++iter)
[email protected]864b58552013-12-19 04:19:38476 (*iter)->ShowShelf();
[email protected]7e1df2f62012-07-19 19:17:18477}
478
[email protected]1a2145b2012-03-13 21:09:17479void Shell::AddShellObserver(ShellObserver* observer) {
480 observers_.AddObserver(observer);
481}
482
483void Shell::RemoveShellObserver(ShellObserver* observer) {
484 observers_.RemoveObserver(observer);
485}
486
[email protected]da285852014-05-27 19:53:43487#if defined(OS_CHROMEOS)
488bool Shell::ShouldSaveDisplaySettings() {
jonross0af45212015-01-13 18:55:46489 return !(screen_orientation_controller_
490 ->ignore_display_configuration_updates() ||
oshimabba2d992015-05-22 19:21:39491 resolution_notification_controller_->DoesNotificationTimeout());
[email protected]da285852014-05-27 19:53:43492}
493#endif
494
[email protected]c758fbf2012-03-25 22:53:59495void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33496 RootWindowControllerList controllers = GetAllRootWindowControllers();
497 for (RootWindowControllerList::iterator iter = controllers.begin();
498 iter != controllers.end(); ++iter)
499 if ((*iter)->shelf())
500 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59501}
502
[email protected]431552c2012-10-23 00:38:33503void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
[email protected]bf9cdb362013-10-25 19:22:45504 aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28505 ash::ShelfLayoutManager::ForShelf(root_window)->SetAutoHideBehavior(behavior);
[email protected]c758fbf2012-03-25 22:53:59506}
507
[email protected]431552c2012-10-23 00:38:33508ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
[email protected]bf9cdb362013-10-25 19:22:45509 aura::Window* root_window) const {
[email protected]093b8d642014-04-03 20:59:28510 return ash::ShelfLayoutManager::ForShelf(root_window)->auto_hide_behavior();
[email protected]c758fbf2012-03-25 22:53:59511}
512
[email protected]431552c2012-10-23 00:38:33513void Shell::SetShelfAlignment(ShelfAlignment alignment,
[email protected]bf9cdb362013-10-25 19:22:45514 aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28515 if (ash::ShelfLayoutManager::ForShelf(root_window)->SetAlignment(alignment)) {
[email protected]f89f7512012-12-17 19:21:18516 FOR_EACH_OBSERVER(
517 ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
518 }
[email protected]55444502012-05-10 15:43:53519}
520
[email protected]76bc4632014-06-16 19:07:46521ShelfAlignment Shell::GetShelfAlignment(const aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28522 return GetRootWindowController(root_window)
523 ->GetShelfLayoutManager()
524 ->GetAlignment();
[email protected]55444502012-05-10 15:43:53525}
526
[email protected]375069e2013-10-04 13:54:31527void Shell::NotifyFullscreenStateChange(bool is_fullscreen,
[email protected]bf9cdb362013-10-25 19:22:45528 aura::Window* root_window) {
[email protected]375069e2013-10-04 13:54:31529 FOR_EACH_OBSERVER(ShellObserver, observers_, OnFullscreenStateChanged(
530 is_fullscreen, root_window));
531}
532
[email protected]090c4f12012-10-29 18:56:42533void Shell::CreateModalBackground(aura::Window* window) {
[email protected]7f7f65c2013-04-17 16:47:13534 if (!modality_filter_) {
[email protected]093b8d642014-04-03 20:59:28535 modality_filter_.reset(new SystemModalContainerEventFilter(this));
[email protected]304594c2012-11-13 16:35:27536 AddPreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27537 }
538 RootWindowControllerList controllers = GetAllRootWindowControllers();
539 for (RootWindowControllerList::iterator iter = controllers.begin();
540 iter != controllers.end(); ++iter)
[email protected]090c4f12012-10-29 18:56:42541 (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27542}
543
544void Shell::OnModalWindowRemoved(aura::Window* removed) {
545 RootWindowControllerList controllers = GetAllRootWindowControllers();
546 bool activated = false;
547 for (RootWindowControllerList::iterator iter = controllers.begin();
548 iter != controllers.end() && !activated; ++iter) {
[email protected]8674b312012-10-12 19:02:44549 activated = (*iter)->GetSystemModalLayoutManager(removed)->
550 ActivateNextModalWindow();
[email protected]c0ce80e2012-10-05 23:28:27551 }
552 if (!activated) {
[email protected]304594c2012-11-13 16:35:27553 RemovePreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27554 modality_filter_.reset();
555 for (RootWindowControllerList::iterator iter = controllers.begin();
556 iter != controllers.end(); ++iter)
[email protected]8674b312012-10-12 19:02:44557 (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27558 }
559}
560
[email protected]88d71122012-10-18 07:11:01561WebNotificationTray* Shell::GetWebNotificationTray() {
[email protected]478c6c32013-03-09 02:50:58562 return GetPrimaryRootWindowController()->shelf()->
563 status_area_widget()->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28564}
565
[email protected]a0afeb12012-12-10 22:57:09566bool Shell::HasPrimaryStatusArea() {
[email protected]478c6c32013-03-09 02:50:58567 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf();
568 return shelf && shelf->status_area_widget();
[email protected]31f19e32012-10-30 22:31:23569}
570
[email protected]a0afeb12012-12-10 22:57:09571SystemTray* Shell::GetPrimarySystemTray() {
572 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42573}
574
[email protected]8b57e942013-12-09 19:39:20575ShelfDelegate* Shell::GetShelfDelegate() {
576 if (!shelf_delegate_) {
[email protected]64936bf2013-11-14 19:48:36577 shelf_model_.reset(new ShelfModel);
[email protected]8b57e942013-12-09 19:39:20578 // Creates ShelfItemDelegateManager before ShelfDelegate.
[email protected]c25ff502013-12-04 13:52:48579 shelf_item_delegate_manager_.reset(
580 new ShelfItemDelegateManager(shelf_model_.get()));
[email protected]6777f632013-10-15 02:38:41581
[email protected]8b57e942013-12-09 19:39:20582 shelf_delegate_.reset(delegate_->CreateShelfDelegate(shelf_model_.get()));
[email protected]093b8d642014-04-03 20:59:28583 scoped_ptr<ShelfItemDelegate> controller(new AppListShelfItemDelegate);
[email protected]6777f632013-10-15 02:38:41584
[email protected]64936bf2013-11-14 19:48:36585 // Finding the shelf model's location of the app list and setting its
[email protected]c25ff502013-12-04 13:52:48586 // ShelfItemDelegate.
[email protected]b7b4dec2013-11-18 06:16:12587 int app_list_index = shelf_model_->GetItemIndexForType(TYPE_APP_LIST);
[email protected]3fced99a2013-10-23 17:16:25588 DCHECK_GE(app_list_index, 0);
[email protected]eec0971422014-02-03 23:51:27589 ShelfID app_list_id = shelf_model_->items()[app_list_index].id;
[email protected]6777f632013-10-15 02:38:41590 DCHECK(app_list_id);
[email protected]c25ff502013-12-04 13:52:48591 shelf_item_delegate_manager_->SetShelfItemDelegate(app_list_id,
dchengcbf0d9d2015-12-27 22:49:23592 std::move(controller));
[email protected]093b8d642014-04-03 20:59:28593 shelf_window_watcher_.reset(new ShelfWindowWatcher(
594 shelf_model_.get(), shelf_item_delegate_manager_.get()));
[email protected]b913a3a2012-12-11 13:07:19595 }
[email protected]8b57e942013-12-09 19:39:20596 return shelf_delegate_.get();
[email protected]b913a3a2012-12-11 13:07:19597}
598
[email protected]2b8a9bb2013-07-01 22:43:40599void Shell::SetTouchHudProjectionEnabled(bool enabled) {
600 if (is_touch_hud_projection_enabled_ == enabled)
601 return;
602
[email protected]2b8a9bb2013-07-01 22:43:40603 is_touch_hud_projection_enabled_ = enabled;
[email protected]d141b922013-07-09 08:13:17604 FOR_EACH_OBSERVER(ShellObserver, observers_,
605 OnTouchHudProjectionToggled(enabled));
[email protected]2b8a9bb2013-07-01 22:43:40606}
607
[email protected]59ccade2013-10-17 17:56:40608#if defined(OS_CHROMEOS)
609ash::FirstRunHelper* Shell::CreateFirstRunHelper() {
610 return new ash::FirstRunHelperImpl;
611}
[email protected]87ec2202014-02-06 06:24:27612
613void Shell::SetCursorCompositingEnabled(bool enabled) {
oshimae2818922015-07-28 01:18:52614 window_tree_host_manager_->cursor_window_controller()
615 ->SetCursorCompositingEnabled(enabled);
[email protected]87ec2202014-02-06 06:24:27616 native_cursor_manager_->SetNativeCursorEnabled(!enabled);
617}
[email protected]59ccade2013-10-17 17:56:40618#endif // defined(OS_CHROMEOS)
619
[email protected]f9466702012-09-17 16:35:27620void Shell::DoInitialWorkspaceAnimation() {
621 return GetPrimaryRootWindowController()->workspace_controller()->
622 DoInitialAnimation();
623}
624
[email protected]b6ba05d902013-10-04 21:38:45625////////////////////////////////////////////////////////////////////////////////
626// Shell, private:
627
ben0d6be2d42015-09-26 04:37:19628Shell::Shell(ShellDelegate* delegate, base::SequencedWorkerPool* blocking_pool)
achuith287b26e2015-09-03 17:49:18629 : target_root_window_(nullptr),
630 scoped_target_root_window_(nullptr),
[email protected]b6ba05d902013-10-04 21:38:45631 delegate_(delegate),
632 window_positioner_(new WindowPositioner),
achuith287b26e2015-09-03 17:49:18633 activation_client_(nullptr),
[email protected]94545ca92014-03-29 01:17:59634#if defined(OS_CHROMEOS)
[email protected]1e31cbd2014-04-07 20:06:11635 display_configurator_(new ui::DisplayConfigurator()),
[email protected]94545ca92014-03-29 01:17:59636#endif // defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45637 native_cursor_manager_(new AshNativeCursorManager),
[email protected]94545ca92014-03-29 01:17:59638 cursor_manager_(
jonross8834fc42014-12-19 17:29:19639 scoped_ptr<::wm::NativeCursorManager>(native_cursor_manager_)),
[email protected]b6ba05d902013-10-04 21:38:45640 simulate_modal_window_open_for_testing_(false),
ben0d6be2d42015-09-26 04:37:19641 is_touch_hud_projection_enabled_(false),
642 blocking_pool_(blocking_pool) {
[email protected]b6ba05d902013-10-04 21:38:45643 DCHECK(delegate_.get());
sadrul679eb98f2015-08-07 05:25:10644 DCHECK(aura::Env::GetInstanceDontCreate());
[email protected]99edff3e2014-01-31 18:20:36645 gpu_support_.reset(delegate_->CreateGPUSupport());
[email protected]093b8d642014-04-03 20:59:28646 display_manager_.reset(new DisplayManager);
oshimae2818922015-07-28 01:18:52647 window_tree_host_manager_.reset(new WindowTreeHostManager);
[email protected]5d2ea362013-12-13 08:10:18648 user_metrics_recorder_.reset(new UserMetricsRecorder);
[email protected]b6ba05d902013-10-04 21:38:45649
650#if defined(OS_CHROMEOS)
[email protected]093b8d642014-04-03 20:59:28651 PowerStatus::Initialize();
[email protected]b6ba05d902013-10-04 21:38:45652#endif
653}
654
655Shell::~Shell() {
656 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
657
bruthigc24d11f2015-06-09 21:30:03658 user_metrics_recorder_->OnShellShuttingDown();
659
[email protected]050e77182014-03-25 15:29:16660 delegate_->PreShutdown();
661
achuith287b26e2015-09-03 17:49:18662 views::FocusManagerFactory::Install(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45663
664 // Remove the focus from any window. This will prevent overhead and side
665 // effects (e.g. crashes) from changing focus during shutdown.
666 // See bug crbug.com/134502.
achuith287b26e2015-09-03 17:49:18667 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(nullptr);
[email protected]b6ba05d902013-10-04 21:38:45668
669 // Please keep in same order as in Init() because it's easy to miss one.
670 if (window_modality_controller_)
671 window_modality_controller_.reset();
oshimae2818922015-07-28 01:18:52672 RemovePreTargetHandler(
673 window_tree_host_manager_->input_method_event_handler());
spange9b51272014-12-11 01:20:10674#if defined(OS_CHROMEOS)
[email protected]e4ea52362014-02-15 03:21:06675 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
676 magnifier_key_scroll_handler_.reset();
677
678 RemovePreTargetHandler(speech_feedback_handler_.get());
679 speech_feedback_handler_.reset();
[email protected]3dff2ef2014-02-09 22:50:39680#endif
[email protected]b6ba05d902013-10-04 21:38:45681 RemovePreTargetHandler(overlay_filter_.get());
[email protected]3537d472014-01-15 05:45:31682 RemovePreTargetHandler(accelerator_filter_.get());
683 RemovePreTargetHandler(event_transformation_handler_.get());
684 RemovePreTargetHandler(toplevel_window_event_handler_.get());
685 RemovePostTargetHandler(toplevel_window_event_handler_.get());
[email protected]342d56a2013-12-20 23:01:02686 RemovePreTargetHandler(system_gesture_filter_.get());
687 RemovePreTargetHandler(keyboard_metrics_filter_.get());
[email protected]8ab613cf2014-05-12 09:39:49688 RemovePreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45689
690 // TooltipController is deleted with the Shell so removing its references.
691 RemovePreTargetHandler(tooltip_controller_.get());
692
jonross0af45212015-01-13 18:55:46693#if defined(OS_CHROMEOS)
694 screen_orientation_controller_.reset();
695#endif
696
rsadambbaf2c82015-01-07 17:54:13697// Destroy the virtual keyboard controller before the maximize mode controller
698// since the latters destructor triggers events that the former is listening
699// to but no longer cares about.
700#if defined(OS_CHROMEOS)
701 virtual_keyboard_controller_.reset();
702#endif
jonross0af45212015-01-13 18:55:46703
[email protected]2a57beb52014-06-09 20:02:26704 // Destroy maximize mode controller early on since it has some observers which
[email protected]5ed2b642014-03-04 00:06:57705 // need to be removed.
[email protected]58fb353d2014-04-04 03:28:05706 maximize_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57707
[email protected]b6ba05d902013-10-04 21:38:45708 // AppList needs to be released before shelf layout manager, which is
[email protected]864b58552013-12-19 04:19:38709 // destroyed with shelf container in the loop below. However, app list
710 // container is now on top of shelf container and released after it.
[email protected]b6ba05d902013-10-04 21:38:45711 // TODO(xiyuan): Move it back when app list container is no longer needed.
712 app_list_controller_.reset();
713
[email protected]0dc85512014-03-13 13:26:41714#if defined(OS_CHROMEOS)
[email protected]ded32492014-03-14 10:09:28715 // Destroy the LastWindowClosedLogoutReminder before the
716 // LogoutConfirmationController.
717 last_window_closed_logout_reminder_.reset();
718
[email protected]7b3f91ee2014-03-06 11:41:40719 // Destroy the LogoutConfirmationController before the SystemTrayDelegate.
720 logout_confirmation_controller_.reset();
[email protected]0dc85512014-03-13 13:26:41721#endif
[email protected]7b3f91ee2014-03-06 11:41:40722
[email protected]b6ba05d902013-10-04 21:38:45723 // Destroy SystemTrayDelegate before destroying the status area(s).
724 system_tray_delegate_->Shutdown();
725 system_tray_delegate_.reset();
726
727 locale_notification_controller_.reset();
728
729 // Drag-and-drop must be canceled prior to close all windows.
730 drag_drop_controller_.reset();
731
[email protected]8c9d12a2013-12-06 18:39:03732 // Controllers who have WindowObserver added must be deleted
oshimae2818922015-07-28 01:18:52733 // before |window_tree_host_manager_| is deleted.
[email protected]8c9d12a2013-12-06 18:39:03734
735#if defined(OS_CHROMEOS)
736 // VideoActivityNotifier must be deleted before |video_detector_| is
737 // deleted because it's observing video activity through
738 // VideoDetectorObserver interface.
739 video_activity_notifier_.reset();
740#endif // defined(OS_CHROMEOS)
741 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25742 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03743
744 shadow_controller_.reset();
745 resize_shadow_controller_.reset();
746
[email protected]dd1e1ac2014-05-13 03:44:09747 window_cycle_controller_.reset();
[email protected]3a472922013-12-16 18:00:54748 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03749
750 // |shelf_window_watcher_| has a weak pointer to |shelf_Model_|
751 // and has window observers.
752 shelf_window_watcher_.reset();
753
[email protected]b6ba05d902013-10-04 21:38:45754 // Destroy all child windows including widgets.
oshimae2818922015-07-28 01:18:52755 window_tree_host_manager_->CloseChildWindows();
afakhry58159392015-05-22 02:45:52756 // MruWindowTracker must be destroyed after all windows have been deleted to
757 // avoid a possible crash when Shell is destroyed from a non-normal shutdown
758 // path. (crbug.com/485438).
759 mru_window_tracker_.reset();
[email protected]b6ba05d902013-10-04 21:38:45760
[email protected]8b57e942013-12-09 19:39:20761 // Chrome implementation of shelf delegate depends on FocusClient,
[email protected]8c9d12a2013-12-06 18:39:03762 // so must be deleted before |focus_client_|.
[email protected]8b57e942013-12-09 19:39:20763 shelf_delegate_.reset();
[email protected]8c9d12a2013-12-06 18:39:03764 focus_client_.reset();
765
[email protected]b6ba05d902013-10-04 21:38:45766 // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
767 // needs to remove observers from it.
768 system_tray_notifier_.reset();
769
770 // These need a valid Shell instance to clean up properly, so explicitly
771 // delete them before invalidating the instance.
772 // Alphabetical. TODO(oshima): sort.
773 magnification_controller_.reset();
774 partial_magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45775 tooltip_controller_.reset();
776 event_client_.reset();
[email protected]567c2692014-05-28 02:40:55777 nested_accelerator_controller_.reset();
[email protected]3537d472014-01-15 05:45:31778 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45779 visibility_controller_.reset();
[email protected]c25ff502013-12-04 13:52:48780 // |shelf_item_delegate_manager_| observes |shelf_model_|. It must be
[email protected]64936bf2013-11-14 19:48:36781 // destroyed before |shelf_model_| is destroyed.
[email protected]c25ff502013-12-04 13:52:48782 shelf_item_delegate_manager_.reset();
[email protected]64936bf2013-11-14 19:48:36783 shelf_model_.reset();
[email protected]b6ba05d902013-10-04 21:38:45784
785 power_button_controller_.reset();
786 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45787
[email protected]7bc49bd2014-01-22 09:30:34788#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45789 resolution_notification_controller_.reset();
[email protected]7bc49bd2014-01-22 09:30:34790#endif
[email protected]b6ba05d902013-10-04 21:38:45791 desktop_background_controller_.reset();
mukai19274bdd2015-02-24 22:37:48792 partial_screenshot_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49793 mouse_cursor_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45794
dnicoara8c3bd1e62014-10-30 19:53:39795#if defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:49796 touch_transformer_controller_.reset();
dnicoara8c3bd1e62014-10-30 19:53:39797#endif // defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:49798
[email protected]b6ba05d902013-10-04 21:38:45799 // This also deletes all RootWindows. Note that we invoke Shutdown() on
oshimae2818922015-07-28 01:18:52800 // WindowTreeHostManager before resetting |window_tree_host_manager_|, since
801 // destruction
[email protected]b6ba05d902013-10-04 21:38:45802 // of its owned RootWindowControllers relies on the value.
[email protected]55ad8c12014-01-17 18:24:33803 display_manager_->CreateScreenForShutdown();
stevenjb537c5c3f2016-01-20 23:38:12804 display_configuration_controller_.reset();
oshimae2818922015-07-28 01:18:52805 window_tree_host_manager_->Shutdown();
806 window_tree_host_manager_.reset();
[email protected]b6ba05d902013-10-04 21:38:45807 screen_position_controller_.reset();
[email protected]f3ab6eff52013-10-24 03:29:38808 accessibility_delegate_.reset();
[email protected]efc897f72013-11-01 11:43:07809 new_window_delegate_.reset();
810 media_delegate_.reset();
[email protected]b6ba05d902013-10-04 21:38:45811
shuchen29f3c7a2015-06-10 07:48:28812 keyboard::KeyboardController::ResetInstance(nullptr);
[email protected]a0b3fb882014-04-07 19:26:03813
[email protected]94545ca92014-03-29 01:17:59814#if defined(OS_CHROMEOS)
robert.bradfordab052492015-05-06 11:09:56815 display_color_manager_.reset();
[email protected]7bc49bd2014-01-22 09:30:34816 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11817 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45818 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11819 display_configurator_->RemoveObserver(display_error_observer_.get());
jdufault88fb76652015-04-30 22:36:43820 if (projecting_observer_) {
[email protected]1e31cbd2014-04-07 20:06:11821 display_configurator_->RemoveObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43822 RemoveShellObserver(projecting_observer_.get());
823 }
[email protected]b6ba05d902013-10-04 21:38:45824 display_change_observer_.reset();
[email protected]b6ba05d902013-10-04 21:38:45825
[email protected]093b8d642014-04-03 20:59:28826 PowerStatus::Shutdown();
pneubeck8be1f5422014-10-09 16:46:18827
828 // Ensure that DBusThreadManager outlives this Shell.
829 DCHECK(chromeos::DBusThreadManager::IsInitialized());
[email protected]b6ba05d902013-10-04 21:38:45830#endif
831
832 DCHECK(instance_ == this);
achuith287b26e2015-09-03 17:49:18833 instance_ = nullptr;
[email protected]b6ba05d902013-10-04 21:38:45834}
835
[email protected]1b4c7472014-05-15 18:32:23836void Shell::Init(const ShellInitParams& init_params) {
[email protected]b6ba05d902013-10-04 21:38:45837 delegate_->PreInit();
[email protected]0249a6532013-10-31 06:53:34838 bool display_initialized = display_manager_->InitFromCommandLine();
stevenjb537c5c3f2016-01-20 23:38:12839
840 display_configuration_controller_.reset(new DisplayConfigurationController(
841 display_manager_.get(), window_tree_host_manager_.get()));
842
[email protected]94545ca92014-03-29 01:17:59843#if defined(OS_CHROMEOS)
[email protected]1e31cbd2014-04-07 20:06:11844 display_configurator_->Init(!gpu_support_->IsPanelFittingDisabled());
[email protected]0249a6532013-10-31 06:53:34845
pneubeck8be1f5422014-10-09 16:46:18846 // The DBusThreadManager must outlive this Shell. See the DCHECK in ~Shell.
847 chromeos::DBusThreadManager* dbus_thread_manager =
848 chromeos::DBusThreadManager::Get();
849 projecting_observer_.reset(
850 new ProjectingObserver(dbus_thread_manager->GetPowerManagerClient()));
[email protected]1e31cbd2014-04-07 20:06:11851 display_configurator_->AddObserver(projecting_observer_.get());
jdufault88fb76652015-04-30 22:36:43852 AddShellObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26853
[email protected]0249a6532013-10-31 06:53:34854 if (!display_initialized && base::SysInfo::IsRunningOnChromeOS()) {
[email protected]093b8d642014-04-03 20:59:28855 display_change_observer_.reset(new DisplayChangeObserver);
[email protected]b6ba05d902013-10-04 21:38:45856 // Register |display_change_observer_| first so that the rest of
857 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11858 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28859 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11860 display_configurator_->AddObserver(display_error_observer_.get());
861 display_configurator_->set_state_controller(display_change_observer_.get());
862 display_configurator_->set_mirroring_controller(display_manager_.get());
863 display_configurator_->ForceInitialConfigure(
[email protected]b6ba05d902013-10-04 21:38:45864 delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
865 display_initialized = true;
866 }
robert.bradfordab052492015-05-06 11:09:56867 display_color_manager_.reset(
ben0d6be2d42015-09-26 04:37:19868 new DisplayColorManager(display_configurator_.get(), blocking_pool_));
[email protected]94545ca92014-03-29 01:17:59869#endif // defined(OS_CHROMEOS)
stevenjb537c5c3f2016-01-20 23:38:12870
[email protected]b6ba05d902013-10-04 21:38:45871 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34872 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45873
mukai5dad2e72014-12-16 00:00:30874 display_manager_->RefreshFontParams();
[email protected]68d6080e2014-08-21 23:06:32875
[email protected]b6ba05d902013-10-04 21:38:45876 // Install the custom factory first so that views::FocusManagers for Tray,
[email protected]864b58552013-12-19 04:19:38877 // Shelf, and WallPaper could be created by the factory.
[email protected]b6ba05d902013-10-04 21:38:45878 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
879
[email protected]fa69f2b62014-05-22 21:47:58880 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
[email protected]ecca62b2013-10-09 16:18:53881
[email protected]b6ba05d902013-10-04 21:38:45882 // The WindowModalityController needs to be at the front of the input event
883 // pretarget handler list to ensure that it processes input events when modal
884 // windows are active.
885 window_modality_controller_.reset(
[email protected]e319c7e2014-03-14 19:56:14886 new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45887
[email protected]e319c7e2014-03-14 19:56:14888 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45889 AddPreTargetHandler(env_filter_.get());
890
afakhrycae0618f2015-01-12 17:57:43891 wm::AshFocusRules* focus_rules = new wm::AshFocusRules();
892
[email protected]e319c7e2014-03-14 19:56:14893 ::wm::FocusController* focus_controller =
afakhrycae0618f2015-01-12 17:57:43894 new ::wm::FocusController(focus_rules);
[email protected]b6ba05d902013-10-04 21:38:45895 focus_client_.reset(focus_controller);
896 activation_client_ = focus_controller;
897 activation_client_->AddObserver(this);
[email protected]093b8d642014-04-03 20:59:28898 focus_cycler_.reset(new FocusCycler());
[email protected]b6ba05d902013-10-04 21:38:45899
[email protected]093b8d642014-04-03 20:59:28900 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45901
oshimae2818922015-07-28 01:18:52902 window_tree_host_manager_->Start();
903 window_tree_host_manager_->CreatePrimaryHost(
[email protected]1b4c7472014-05-15 18:32:23904 ShellInitParamsToAshWindowTreeHostInitParams(init_params));
oshimae2818922015-07-28 01:18:52905 aura::Window* root_window = window_tree_host_manager_->GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45906 target_root_window_ = root_window;
907
[email protected]7bc49bd2014-01-22 09:30:34908#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45909 resolution_notification_controller_.reset(
[email protected]093b8d642014-04-03 20:59:28910 new ResolutionNotificationController);
[email protected]7bc49bd2014-01-22 09:30:34911#endif
[email protected]b6ba05d902013-10-04 21:38:45912
[email protected]55ad8c12014-01-17 18:24:33913 cursor_manager_.SetDisplay(GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:45914
[email protected]567c2692014-05-28 02:40:55915 nested_accelerator_controller_.reset(
916 new ::wm::NestedAcceleratorController(new NestedAcceleratorDelegate));
[email protected]b6ba05d902013-10-04 21:38:45917 accelerator_controller_.reset(new AcceleratorController);
[email protected]58fb353d2014-04-04 03:28:05918 maximize_mode_controller_.reset(new MaximizeModeController());
[email protected]b6ba05d902013-10-04 21:38:45919
oshimae2818922015-07-28 01:18:52920 AddPreTargetHandler(window_tree_host_manager_->input_method_event_handler());
oshima5e0fff82015-06-27 01:31:30921
spange9b51272014-12-11 01:20:10922#if defined(OS_CHROMEOS)
923 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06924 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
spange9b51272014-12-11 01:20:10925 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler();
[email protected]e4ea52362014-02-15 03:21:06926 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39927#endif
928
[email protected]b6ba05d902013-10-04 21:38:45929 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45930
derat2d4e62d2015-01-09 16:09:17931 // ui::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45932 // rewritten first.
derat2d4e62d2015-01-09 16:09:17933 user_activity_detector_.reset(new ui::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45934
[email protected]093b8d642014-04-03 20:59:28935 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45936 AddPreTargetHandler(overlay_filter_.get());
937 AddShellObserver(overlay_filter_.get());
938
[email protected]60d677d2014-05-30 13:07:02939 accelerator_filter_.reset(new ::wm::AcceleratorFilter(
dchengcbf0d9d2015-12-27 22:49:23940 scoped_ptr<::wm::AcceleratorDelegate>(new AcceleratorDelegate),
afakhry55463732014-11-21 21:06:16941 accelerator_controller_->accelerator_history()));
[email protected]b6ba05d902013-10-04 21:38:45942 AddPreTargetHandler(accelerator_filter_.get());
943
[email protected]093b8d642014-04-03 20:59:28944 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45945 AddPreTargetHandler(event_transformation_handler_.get());
946
[email protected]3537d472014-01-15 05:45:31947 toplevel_window_event_handler_.reset(new ToplevelWindowEventHandler);
948
[email protected]093b8d642014-04-03 20:59:28949 system_gesture_filter_.reset(new SystemGestureEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45950 AddPreTargetHandler(system_gesture_filter_.get());
951
[email protected]093b8d642014-04-03 20:59:28952 keyboard_metrics_filter_.reset(new KeyboardUMAEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45953 AddPreTargetHandler(keyboard_metrics_filter_.get());
954
[email protected]354520b2014-06-21 04:31:01955#if defined(OS_CHROMEOS)
956 sticky_keys_controller_.reset(new StickyKeysController);
957#endif
958
[email protected]b6ba05d902013-10-04 21:38:45959 lock_state_controller_.reset(new LockStateController);
960 power_button_controller_.reset(new PowerButtonController(
961 lock_state_controller_.get()));
[email protected]94545ca92014-03-29 01:17:59962#if defined(OS_CHROMEOS)
[email protected]685442f32014-02-28 10:40:06963 // Pass the initial display state to PowerButtonController.
964 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:09965 display_configurator_->cached_displays());
[email protected]685442f32014-02-28 10:40:06966#endif
[email protected]b6ba05d902013-10-04 21:38:45967 AddShellObserver(lock_state_controller_.get());
968
[email protected]093b8d642014-04-03 20:59:28969 drag_drop_controller_.reset(new DragDropController);
mukai19274bdd2015-02-24 22:37:48970 // |partial_screenshot_controller_| needs to be created (and prepended as a
971 // pre-target handler) at this point, because |mouse_cursor_filter_| needs to
972 // process mouse events prior to partial screenshot session.
973 // See http://crbug.com/459214
974 partial_screenshot_controller_.reset(new PartialScreenshotController());
[email protected]093b8d642014-04-03 20:59:28975 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
[email protected]b6ba05d902013-10-04 21:38:45976 PrependPreTargetHandler(mouse_cursor_filter_.get());
977
978 // Create Controllers that may need root window.
979 // TODO(oshima): Move as many controllers before creating
980 // RootWindowController as possible.
981 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:45982
983 magnification_controller_.reset(
984 MagnificationController::CreateInstance());
afakhrycae0618f2015-01-12 17:57:43985 mru_window_tracker_.reset(new MruWindowTracker(activation_client_,
986 focus_rules));
[email protected]b6ba05d902013-10-04 21:38:45987
988 partial_magnification_controller_.reset(
989 new PartialMagnificationController());
990
[email protected]55398d22013-10-10 19:49:20991 autoclick_controller_.reset(AutoclickController::CreateInstance());
992
[email protected]b6ba05d902013-10-04 21:38:45993 high_contrast_controller_.reset(new HighContrastController);
994 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:45995 window_selector_controller_.reset(new WindowSelectorController());
[email protected]dd1e1ac2014-05-13 03:44:09996 window_cycle_controller_.reset(new WindowCycleController());
[email protected]b6ba05d902013-10-04 21:38:45997
oshimaebbe63772015-02-19 18:41:32998 tooltip_controller_.reset(new views::corewm::TooltipController(
999 scoped_ptr<views::corewm::Tooltip>(new views::corewm::TooltipAura)));
[email protected]b6ba05d902013-10-04 21:38:451000 AddPreTargetHandler(tooltip_controller_.get());
1001
[email protected]093b8d642014-04-03 20:59:281002 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:451003
1004 // This controller needs to be set before SetupManagedWindowMode.
ben0d6be2d42015-09-26 04:37:191005 desktop_background_controller_.reset(
1006 new DesktopBackgroundController(blocking_pool_));
[email protected]b6ba05d902013-10-04 21:38:451007 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
1008
[email protected]b6ba05d902013-10-04 21:38:451009 session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
[email protected]f3ab6eff52013-10-24 03:29:381010 accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate());
[email protected]47686c42013-10-25 01:49:171011 new_window_delegate_.reset(delegate_->CreateNewWindowDelegate());
[email protected]efc897f72013-11-01 11:43:071012 media_delegate_.reset(delegate_->CreateMediaDelegate());
[email protected]b6ba05d902013-10-04 21:38:451013
[email protected]093b8d642014-04-03 20:59:281014 resize_shadow_controller_.reset(new ResizeShadowController());
[email protected]d74caa82014-03-10 20:52:561015 shadow_controller_.reset(
[email protected]e319c7e2014-03-14 19:56:141016 new ::wm::ShadowController(activation_client_));
[email protected]b6ba05d902013-10-04 21:38:451017
1018 // Create system_tray_notifier_ before the delegate.
1019 system_tray_notifier_.reset(new ash::SystemTrayNotifier());
1020
1021 // Initialize system_tray_delegate_ before initializing StatusAreaWidget.
1022 system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate());
1023 DCHECK(system_tray_delegate_.get());
1024
[email protected]093b8d642014-04-03 20:59:281025 locale_notification_controller_.reset(new LocaleNotificationController);
[email protected]b6ba05d902013-10-04 21:38:451026
1027 // Initialize system_tray_delegate_ after StatusAreaWidget is created.
1028 system_tray_delegate_->Initialize();
1029
[email protected]0dc85512014-03-13 13:26:411030#if defined(OS_CHROMEOS)
[email protected]7b3f91ee2014-03-06 11:41:401031 // Create the LogoutConfirmationController after the SystemTrayDelegate.
[email protected]093b8d642014-04-03 20:59:281032 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1033 base::Bind(&SystemTrayDelegate::SignOut,
1034 base::Unretained(system_tray_delegate_.get()))));
[email protected]7b3f91ee2014-03-06 11:41:401035
oshimae2818922015-07-28 01:18:521036 // Create TouchTransformerController before
1037 // WindowTreeHostManager::InitDisplays()
[email protected]03122891a2014-05-13 23:56:491038 // since TouchTransformerController listens on
oshimae2818922015-07-28 01:18:521039 // WindowTreeHostManager::Observer::OnDisplaysInitialized().
[email protected]03122891a2014-05-13 23:56:491040 touch_transformer_controller_.reset(new TouchTransformerController());
dnicoara8c3bd1e62014-10-30 19:53:391041#endif // defined(OS_CHROMEOS)
[email protected]03122891a2014-05-13 23:56:491042
oshimae2818922015-07-28 01:18:521043 window_tree_host_manager_->InitHosts();
[email protected]b6ba05d902013-10-04 21:38:451044
rsadam9172bc8a2014-10-29 23:37:381045#if defined(OS_CHROMEOS)
1046 // Needs to be created after InitDisplays() since it may cause the virtual
1047 // keyboard to be deployed.
1048 virtual_keyboard_controller_.reset(new VirtualKeyboardController);
1049#endif // defined(OS_CHROMEOS)
1050
[email protected]a3565792013-10-18 12:52:371051 // It needs to be created after RootWindowController has been created
1052 // (which calls OnWindowResized has been called, otherwise the
[email protected]b6ba05d902013-10-04 21:38:451053 // widget will not paint when restoring after a browser crash. Also it needs
1054 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
1055 // the correct size.
1056 user_wallpaper_delegate_->InitializeWallpaper();
1057
1058 if (initially_hide_cursor_)
1059 cursor_manager_.HideCursor();
1060 cursor_manager_.SetCursor(ui::kCursorPointer);
1061
[email protected]5c04d3a92013-10-08 19:17:191062#if defined(OS_CHROMEOS)
[email protected]ded58fd2013-10-09 07:56:551063 // Set accelerator controller delegates.
[email protected]b6ba05d902013-10-04 21:38:451064 accelerator_controller_->SetBrightnessControlDelegate(
1065 scoped_ptr<ash::BrightnessControlDelegate>(
dcheng22724952015-12-31 03:17:541066 new ash::system::BrightnessControllerChromeos));
[email protected]ded58fd2013-10-09 07:56:551067
[email protected]093b8d642014-04-03 20:59:281068 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551069 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571070 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551071 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281072 new VideoActivityNotifier(video_detector_.get()));
1073 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
1074 last_window_closed_logout_reminder_.reset(new LastWindowClosedLogoutReminder);
jonross0af45212015-01-13 18:55:461075 screen_orientation_controller_.reset(new ScreenOrientationController());
[email protected]b6ba05d902013-10-04 21:38:451076#endif
[email protected]b6ba05d902013-10-04 21:38:451077 // The compositor thread and main message loop have to be running in
1078 // order to create mirror window. Run it after the main message loop
1079 // is started.
oshimac8089b82014-11-12 21:43:501080 display_manager_->CreateMirrorWindowAsyncIfAny();
bruthigc24d11f2015-06-09 21:30:031081
phweiss0bf64c52015-11-17 12:56:181082 FOR_EACH_OBSERVER(ShellObserver, observers_, OnShellInitialized());
1083
bruthigc24d11f2015-06-09 21:30:031084 user_metrics_recorder_->OnShellInitialized();
[email protected]b6ba05d902013-10-04 21:38:451085}
1086
[email protected]51f438112013-11-18 19:32:501087void Shell::InitKeyboard() {
[email protected]b6ba05d902013-10-04 21:38:451088 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031089 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451090 RootWindowControllerList controllers = GetAllRootWindowControllers();
1091 for (RootWindowControllerList::iterator iter = controllers.begin();
1092 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031093 (*iter)->DeactivateKeyboard(
1094 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451095 }
1096 }
[email protected]a0b3fb882014-04-07 19:26:031097 keyboard::KeyboardController::ResetInstance(
ben974286a2015-10-10 00:45:121098 new keyboard::KeyboardController(delegate_->CreateKeyboardUI()));
[email protected]b6ba05d902013-10-04 21:38:451099 }
1100}
1101
[email protected]41baaed2013-11-09 04:18:261102void Shell::InitRootWindow(aura::Window* root_window) {
[email protected]39718b52012-12-03 17:24:561103 DCHECK(activation_client_);
[email protected]d90b8392012-06-13 09:34:561104 DCHECK(visibility_controller_.get());
1105 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561106
[email protected]8cfb6722012-11-28 03:28:461107 aura::client::SetFocusClient(root_window, focus_client_.get());
[email protected]39718b52012-12-03 17:24:561108 aura::client::SetActivationClient(root_window, activation_client_);
[email protected]e319c7e2014-03-14 19:56:141109 ::wm::FocusController* focus_controller =
1110 static_cast< ::wm::FocusController*>(activation_client_);
[email protected]375338212013-09-05 22:14:521111 root_window->AddPreTargetHandler(focus_controller);
[email protected]d90b8392012-06-13 09:34:561112 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1113 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061114 aura::client::SetScreenPositionClient(root_window,
1115 screen_position_controller_.get());
[email protected]4b8003c2012-07-26 00:54:191116 aura::client::SetCursorClient(root_window, &cursor_manager_);
[email protected]54a37cdc2012-07-25 19:16:011117 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381118 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561119
[email protected]3537d472014-01-15 05:45:311120 aura::client::SetWindowMoveClient(root_window,
1121 toplevel_window_event_handler_.get());
1122 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1123 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
1124
[email protected]567c2692014-05-28 02:40:551125 if (nested_accelerator_controller_) {
[email protected]d90b8392012-06-13 09:34:561126 aura::client::SetDispatcherClient(root_window,
[email protected]567c2692014-05-28 02:40:551127 nested_accelerator_controller_.get());
[email protected]d90b8392012-06-13 09:34:561128 }
[email protected]d90b8392012-06-13 09:34:561129}
1130
[email protected]c0ce80e2012-10-05 23:28:271131bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1132 RootWindowControllerList controllers = GetAllRootWindowControllers();
1133 for (RootWindowControllerList::iterator iter = controllers.begin();
1134 iter != controllers.end(); ++iter) {
[email protected]093b8d642014-04-03 20:59:281135 SystemModalContainerLayoutManager* layout_manager =
[email protected]bb0c7cd42013-05-20 23:39:451136 (*iter)->GetSystemModalLayoutManager(window);
1137 if (layout_manager && layout_manager->CanWindowReceiveEvents(window))
[email protected]c0ce80e2012-10-05 23:28:271138 return true;
[email protected]602022b2014-03-31 17:07:311139 // Allow events to fall through to the virtual keyboard even if displaying
1140 // a system modal dialog.
1141 if ((*iter)->IsVirtualKeyboardWindow(window))
1142 return true;
[email protected]c0ce80e2012-10-05 23:28:271143 }
[email protected]602022b2014-03-31 17:07:311144
[email protected]c0ce80e2012-10-05 23:28:271145 return false;
1146}
1147
[email protected]049cf34b2012-12-07 17:15:481148////////////////////////////////////////////////////////////////////////////////
1149// Shell, ui::EventTarget overrides:
1150
[email protected]869f6352012-12-06 20:47:171151bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411152 return true;
1153}
1154
1155ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481156 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411157}
1158
[email protected]3e670aa2013-12-02 19:04:321159scoped_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1160 return scoped_ptr<ui::EventTargetIterator>();
1161}
1162
1163ui::EventTargeter* Shell::GetEventTargeter() {
1164 NOTREACHED();
achuith287b26e2015-09-03 17:49:181165 return nullptr;
[email protected]3e670aa2013-12-02 19:04:321166}
1167
[email protected]1ae361652012-12-12 22:39:511168////////////////////////////////////////////////////////////////////////////////
1169// Shell, aura::client::ActivationChangeObserver implementation:
1170
bruthig5681d882015-06-05 15:33:211171void Shell::OnWindowActivated(
1172 aura::client::ActivationChangeObserver::ActivationReason reason,
1173 aura::Window* gained_active,
1174 aura::Window* lost_active) {
[email protected]d219a192012-12-14 00:08:181175 if (gained_active)
[email protected]b42910f2013-08-01 11:45:291176 target_root_window_ = gained_active->GetRootWindow();
[email protected]049cf34b2012-12-07 17:15:481177}
1178
[email protected]55f593352011-12-24 05:42:461179} // namespace ash