blob: b8a69de6cc396d169978dac6e2a6a0f79cb2fb62 [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>
[email protected]f7eb89c2011-12-13 09:48:549
[email protected]878479482013-09-18 10:29:1910#include "ash/accelerators/accelerator_controller.h"
11#include "ash/accelerators/accelerator_filter.h"
[email protected]e7293fa2012-05-17 04:42:3312#include "ash/accelerators/focus_manager_factory.h"
[email protected]284145ef2014-05-27 19:04:0913#include "ash/accelerators/nested_dispatcher_controller.h"
[email protected]cc4fc3b2014-04-03 08:07:0914#include "ash/accelerometer/accelerometer_controller.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"
[email protected]2e236a52012-06-27 22:21:4721#include "ash/display/display_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"
[email protected]51f438112013-11-18 19:32:5026#include "ash/display/virtual_keyboard_window_controller.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"
[email protected]7a80cdd2013-09-26 09:20:5334#include "ash/keyboard_uma_event_filter.h"
[email protected]f4c92b382012-08-28 00:59:5935#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5436#include "ash/magnifier/partial_magnification_controller.h"
[email protected]efc897f72013-11-01 11:43:0737#include "ash/media_delegate.h"
[email protected]47686c42013-10-25 01:49:1738#include "ash/new_window_delegate.h"
[email protected]d90b8392012-06-13 09:34:5639#include "ash/root_window_controller.h"
[email protected]fdf74bf2014-04-30 21:24:0240#include "ash/session/session_state_delegate.h"
[email protected]976624f2013-09-19 21:58:4941#include "ash/shelf/app_list_shelf_item_delegate.h"
[email protected]8b57e942013-12-09 19:39:2042#include "ash/shelf/shelf_delegate.h"
[email protected]c25ff502013-12-04 13:52:4843#include "ash/shelf/shelf_item_delegate.h"
44#include "ash/shelf/shelf_item_delegate_manager.h"
[email protected]478c6c32013-03-09 02:50:5845#include "ash/shelf/shelf_layout_manager.h"
[email protected]64936bf2013-11-14 19:48:3646#include "ash/shelf/shelf_model.h"
[email protected]478c6c32013-03-09 02:50:5847#include "ash/shelf/shelf_widget.h"
[email protected]055a56d2013-12-06 12:13:3648#include "ash/shelf/shelf_window_watcher.h"
[email protected]b65bdda2011-12-23 23:35:3149#include "ash/shell_delegate.h"
50#include "ash/shell_factory.h"
[email protected]1b4c7472014-05-15 18:32:2351#include "ash/shell_init_params.h"
[email protected]b65bdda2011-12-23 23:35:3152#include "ash/shell_window_ids.h"
[email protected]a9a40462013-07-31 06:22:5653#include "ash/system/locale/locale_notification_controller.h"
[email protected]6d6546e2012-05-30 23:12:0254#include "ash/system/status_area_widget.h"
[email protected]51ed5992012-11-07 10:14:3955#include "ash/system/tray/system_tray_delegate.h"
[email protected]83b2b84c2012-11-14 01:11:0056#include "ash/system/tray/system_tray_notifier.h"
[email protected]0039db92012-05-09 04:11:4557#include "ash/wm/app_list_controller.h"
[email protected]39718b52012-12-03 17:24:5658#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2959#include "ash/wm/ash_native_cursor_manager.h"
[email protected]88d71122012-10-18 07:11:0160#include "ash/wm/coordinate_conversion.h"
[email protected]262f8bd2012-03-23 19:30:2761#include "ash/wm/event_client_impl.h"
[email protected]ab4f8c92013-05-30 19:07:4762#include "ash/wm/lock_state_controller.h"
[email protected]58fb353d2014-04-04 03:28:0563#include "ash/wm/maximize_mode/maximize_mode_controller.h"
[email protected]e55b73452014-02-20 13:18:0464#include "ash/wm/maximize_mode/maximize_mode_window_manager.h"
[email protected]66c5c4112013-07-31 07:10:5965#include "ash/wm/mru_window_tracker.h"
[email protected]9ae32df2012-07-26 03:25:1866#include "ash/wm/overlay_event_filter.h"
[email protected]09f35d742013-08-23 00:39:3967#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:5768#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:5769#include "ash/wm/resize_shadow_controller.h"
[email protected]a3301dc2011-12-23 16:34:5170#include "ash/wm/root_window_layout_manager.h"
[email protected]42993212012-04-30 23:42:0471#include "ash/wm/screen_dimmer.h"
[email protected]435b212e2012-04-05 19:43:3772#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2773#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3374#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]3537d472014-01-15 05:45:3175#include "ash/wm/toplevel_window_event_handler.h"
[email protected]9633a9d22012-01-21 16:40:5876#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:0277#include "ash/wm/window_animations.h"
[email protected]dd1e1ac2014-05-13 03:44:0978#include "ash/wm/window_cycle_controller.h"
[email protected]e9a71312013-10-04 03:20:0179#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:5780#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5981#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3682#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0083#include "base/bind.h"
[email protected]89af4002013-09-06 07:47:0784#include "base/debug/trace_event.h"
[email protected]2c456102011-12-26 06:26:3485#include "ui/aura/client/aura_constants.h"
[email protected]8a45c972012-03-14 18:22:4486#include "ui/aura/env.h"
[email protected]4bb16502011-12-06 14:44:5887#include "ui/aura/layout_manager.h"
[email protected]87b0d82e2011-10-07 21:02:5988#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2689#include "ui/aura/window_event_dispatcher.h"
[email protected]2d4817742012-12-17 20:16:1890#include "ui/base/ui_base_switches.h"
[email protected]116302fc2012-05-05 21:45:4191#include "ui/compositor/layer.h"
92#include "ui/compositor/layer_animator.h"
[email protected]3e670aa2013-12-02 19:04:3293#include "ui/events/event_target_iterator.h"
[email protected]7da9c4c2012-06-12 14:43:0194#include "ui/gfx/display.h"
[email protected]9ec0f452012-05-31 15:58:5395#include "ui/gfx/image/image_skia.h"
[email protected]b82c42c42012-04-25 20:03:4196#include "ui/gfx/screen.h"
[email protected]b0639282011-12-22 21:12:2797#include "ui/gfx/size.h"
[email protected]f1d5c3a2013-04-23 17:42:5698#include "ui/keyboard/keyboard.h"
[email protected]b6ba05d902013-10-04 21:38:4599#include "ui/keyboard/keyboard_controller.h"
[email protected]608de6c2013-10-29 00:14:28100#include "ui/keyboard/keyboard_switches.h"
[email protected]f1d5c3a2013-04-23 17:42:56101#include "ui/keyboard/keyboard_util.h"
[email protected]8393aa62013-01-23 19:40:10102#include "ui/message_center/message_center.h"
[email protected]d7f30a72013-10-05 05:09:41103#include "ui/views/corewm/tooltip_aura.h"
[email protected]a1b7a822013-02-23 19:08:04104#include "ui/views/corewm/tooltip_controller.h"
[email protected]e7293fa2012-05-17 04:42:33105#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58106#include "ui/views/widget/native_widget_aura.h"
107#include "ui/views/widget/widget.h"
[email protected]ee3ed10772014-03-11 22:02:01108#include "ui/wm/core/compound_event_filter.h"
109#include "ui/wm/core/focus_controller.h"
110#include "ui/wm/core/input_method_event_filter.h"
111#include "ui/wm/core/shadow_controller.h"
[email protected]f0f612382014-04-03 15:11:49112#include "ui/wm/core/user_activity_detector.h"
[email protected]ee3ed10772014-03-11 22:02:01113#include "ui/wm/core/visibility_controller.h"
114#include "ui/wm/core/window_modality_controller.h"
[email protected]87b0d82e2011-10-07 21:02:59115
[email protected]37ce571b2013-06-28 05:28:45116#if defined(OS_CHROMEOS)
117#if defined(USE_X11)
[email protected]e4ea52362014-02-15 03:21:06118#include "ash/accelerators/magnifier_key_scroller.h"
119#include "ash/accelerators/spoken_feedback_toggler.h"
[email protected]03122891a2014-05-13 23:56:49120#include "ash/touch/touch_transformer_controller.h"
[email protected]82f884d6ffb2014-04-15 03:34:54121#include "ui/gfx/x/x11_types.h"
[email protected]94545ca92014-03-29 01:17:59122#endif // defined(USE_X11)
[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"
[email protected]129aad82014-04-24 23:17:04125#include "ash/display/display_configurator_animation.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"
[email protected]08bdabed2013-12-20 07:52:28129#include "ash/sticky_keys/sticky_keys_controller.h"
[email protected]b3142722014-03-04 06:59:50130#include "ash/system/chromeos/bluetooth/bluetooth_notification_controller.h"
[email protected]25cae452013-09-26 10:15:03131#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
[email protected]51625052013-10-10 01:40:16132#include "ash/system/chromeos/power/power_event_observer.h"
[email protected]37ce571b2013-06-28 05:28:45133#include "ash/system/chromeos/power/power_status.h"
[email protected]ded58fd2013-10-09 07:56:55134#include "ash/system/chromeos/power/video_activity_notifier.h"
[email protected]94545ca92014-03-29 01:17:59135#include "ash/system/chromeos/session/last_window_closed_logout_reminder.h"
[email protected]0dc85512014-03-13 13:26:41136#include "ash/system/chromeos/session/logout_confirmation_controller.h"
137#include "base/bind_helpers.h"
[email protected]94545ca92014-03-29 01:17:59138#include "base/sys_info.h"
[email protected]b0fa7012014-04-16 12:50:57139#include "ui/chromeos/user_activity_power_manager_notifier.h"
[email protected]1e31cbd2014-04-07 20:06:11140#include "ui/display/chromeos/display_configurator.h"
[email protected]70b3e7d52012-06-02 22:12:25141#endif // defined(OS_CHROMEOS)
142
[email protected]55f593352011-12-24 05:42:46143namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59144
145namespace {
[email protected]671a2ae2011-10-13 21:53:23146
[email protected]615922f2012-02-07 02:41:15147using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45148using views::Widget;
149
[email protected]b5756e22012-11-30 01:32:02150// A Corewm VisibilityController subclass that calls the Ash animation routine
151// so we can pick up our extended animations. See ash/wm/window_animations.h.
[email protected]e319c7e2014-03-14 19:56:14152class AshVisibilityController : public ::wm::VisibilityController {
[email protected]b5756e22012-11-30 01:32:02153 public:
154 AshVisibilityController() {}
155 virtual ~AshVisibilityController() {}
156
157 private:
[email protected]e319c7e2014-03-14 19:56:14158 // Overridden from ::wm::VisibilityController:
[email protected]b5756e22012-11-30 01:32:02159 virtual bool CallAnimateOnChildWindowVisibilityChanged(
160 aura::Window* window,
161 bool visible) OVERRIDE {
162 return AnimateOnChildWindowVisibilityChanged(window, visible);
163 }
164
165 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
166};
167
[email protected]1b4c7472014-05-15 18:32:23168AshWindowTreeHostInitParams ShellInitParamsToAshWindowTreeHostInitParams(
169 const ShellInitParams& shell_init_params) {
170 AshWindowTreeHostInitParams ash_init_params;
171#if defined(OS_WIN)
172 ash_init_params.remote_hwnd = shell_init_params.remote_hwnd;
173#endif
174 return ash_init_params;
175}
176
[email protected]87b0d82e2011-10-07 21:02:59177} // namespace
178
[email protected]cac10fc62011-10-07 23:22:56179// static
180Shell* Shell::instance_ = NULL;
[email protected]2b4cd302012-02-24 20:21:13181// static
[email protected]9488d4d2012-02-29 18:32:37182bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13183
184////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56185// Shell, public:
186
[email protected]cac10fc62011-10-07 23:22:56187// static
[email protected]1b4c7472014-05-15 18:32:23188Shell* Shell::CreateInstance(const ShellInitParams& init_params) {
[email protected]3266c2b92011-11-14 00:06:08189 CHECK(!instance_);
[email protected]1b4c7472014-05-15 18:32:23190 instance_ = new Shell(init_params.delegate);
191 instance_->Init(init_params);
[email protected]3266c2b92011-11-14 00:06:08192 return instance_;
193}
194
195// static
[email protected]cac10fc62011-10-07 23:22:56196Shell* Shell::GetInstance() {
[email protected]3266c2b92011-11-14 00:06:08197 DCHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56198 return instance_;
199}
200
[email protected]6377a002011-11-10 20:26:47201// static
[email protected]b3b7bcd2012-03-06 19:35:45202bool Shell::HasInstance() {
203 return !!instance_;
204}
205
206// static
[email protected]ef589af2011-12-03 01:07:15207void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47208 delete instance_;
209 instance_ = NULL;
210}
211
[email protected]e73bd7802012-02-17 20:10:34212// static
[email protected]093b8d642014-04-03 20:59:28213RootWindowController* Shell::GetPrimaryRootWindowController() {
214 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23215}
216
217// static
218Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
[email protected]2e236a52012-06-27 22:21:47219 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23220 GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56221}
222
223// static
[email protected]bf9cdb362013-10-25 19:22:45224aura::Window* Shell::GetPrimaryRootWindow() {
[email protected]2e236a52012-06-27 22:21:47225 return GetInstance()->display_controller()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34226}
227
[email protected]7b0f7502012-06-11 00:12:39228// static
[email protected]bf9cdb362013-10-25 19:22:45229aura::Window* Shell::GetTargetRootWindow() {
[email protected]b42910f2013-08-01 11:45:29230 Shell* shell = GetInstance();
231 if (shell->scoped_target_root_window_)
232 return shell->scoped_target_root_window_;
233 return shell->target_root_window_;
[email protected]a857dbe2012-05-30 22:10:14234}
235
[email protected]7b0f7502012-06-11 00:12:39236// static
[email protected]ffabb1e2012-10-12 19:51:17237gfx::Screen* Shell::GetScreen() {
[email protected]5fdb45b2012-10-23 20:26:28238 return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
[email protected]ffabb1e2012-10-12 19:51:17239}
240
241// static
[email protected]c9390bd2013-11-08 20:33:13242aura::Window::Windows Shell::GetAllRootWindows() {
[email protected]2e236a52012-06-27 22:21:47243 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23244 GetAllRootWindows();
245}
246
247// static
[email protected]bf9cdb362013-10-25 19:22:45248aura::Window* Shell::GetContainer(aura::Window* root_window,
[email protected]7b0f7502012-06-11 00:12:39249 int container_id) {
250 return root_window->GetChildById(container_id);
251}
252
253// static
[email protected]bf9cdb362013-10-25 19:22:45254const aura::Window* Shell::GetContainer(const aura::Window* root_window,
[email protected]e67291f12012-10-10 05:52:38255 int container_id) {
256 return root_window->GetChildById(container_id);
257}
258
259// static
[email protected]429433f2012-12-28 20:14:46260std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
261 int container_id,
[email protected]bf9cdb362013-10-25 19:22:45262 aura::Window* priority_root) {
[email protected]7b0f7502012-06-11 00:12:39263 std::vector<aura::Window*> containers;
[email protected]c9390bd2013-11-08 20:33:13264 aura::Window::Windows root_windows = GetAllRootWindows();
265 for (aura::Window::Windows::const_iterator it = root_windows.begin();
[email protected]001272f2012-11-02 20:05:23266 it != root_windows.end(); ++it) {
267 aura::Window* container = (*it)->GetChildById(container_id);
[email protected]429433f2012-12-28 20:14:46268 if (container) {
269 if (priority_root && priority_root->Contains(container))
270 containers.insert(containers.begin(), container);
271 else
272 containers.push_back(container);
273 }
[email protected]001272f2012-11-02 20:05:23274 }
[email protected]7b0f7502012-06-11 00:12:39275 return containers;
276}
277
[email protected]940fb1c2013-06-18 16:54:28278void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
279 ui::MenuSourceType source_type) {
[email protected]fcb123d2013-04-17 15:58:49280 // No context menus if there is no session with an active user.
[email protected]c8d19f82013-05-18 09:09:41281 if (!session_state_delegate_->NumberOfLoggedInUsers())
[email protected]f60c6232012-08-24 18:55:03282 return;
283 // No context menus when screen is locked.
[email protected]fcb123d2013-04-17 15:58:49284 if (session_state_delegate_->IsScreenLocked())
[email protected]f60c6232012-08-24 18:55:03285 return;
[email protected]431552c2012-10-23 00:38:33286
[email protected]bf9cdb362013-10-25 19:22:45287 aura::Window* root =
[email protected]431552c2012-10-23 00:38:33288 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()));
[email protected]093b8d642014-04-03 20:59:28289 GetRootWindowController(root)
290 ->ShowContextMenu(location_in_screen, source_type);
[email protected]46ca3632011-11-03 03:33:42291}
292
[email protected]b913a3a2012-12-11 13:07:19293void Shell::ToggleAppList(aura::Window* window) {
[email protected]d17642d2013-09-12 23:44:38294 // If the context window is not given, show it on the target root window.
[email protected]ec67bc8a2013-05-06 17:44:42295 if (!window)
[email protected]d17642d2013-09-12 23:44:38296 window = GetTargetRootWindow();
[email protected]ec67bc8a2013-05-06 17:44:42297 if (!app_list_controller_)
[email protected]093b8d642014-04-03 20:59:28298 app_list_controller_.reset(new AppListController);
[email protected]ec67bc8a2013-05-06 17:44:42299 app_list_controller_->SetVisible(!app_list_controller_->IsVisible(), window);
[email protected]ae4987d2011-11-21 22:52:44300}
301
[email protected]7510d1082012-03-30 21:58:34302bool Shell::GetAppListTargetVisibility() const {
[email protected]ec67bc8a2013-05-06 17:44:42303 return app_list_controller_.get() &&
304 app_list_controller_->GetTargetVisibility();
[email protected]7510d1082012-03-30 21:58:34305}
306
[email protected]1e51a9d2012-04-09 23:31:11307aura::Window* Shell::GetAppListWindow() {
[email protected]ec67bc8a2013-05-06 17:44:42308 return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
[email protected]1e51a9d2012-04-09 23:31:11309}
310
[email protected]59ccade2013-10-17 17:56:40311app_list::AppListView* Shell::GetAppListView() {
312 return app_list_controller_.get() ? app_list_controller_->GetView() : NULL;
313}
314
[email protected]dc09739372012-11-15 20:17:39315bool Shell::IsSystemModalWindowOpen() const {
[email protected]852a55d2012-10-17 13:30:30316 if (simulate_modal_window_open_for_testing_)
317 return true;
[email protected]429433f2012-12-28 20:14:46318 const std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
[email protected]093b8d642014-04-03 20:59:28319 kShellWindowId_SystemModalContainer, NULL);
[email protected]001272f2012-11-02 20:05:23320 for (std::vector<aura::Window*>::const_iterator cit = containers.begin();
321 cit != containers.end(); ++cit) {
322 for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin();
323 wit != (*cit)->children().end(); ++wit) {
324 if ((*wit)->GetProperty(aura::client::kModalKey) ==
325 ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) {
326 return true;
327 }
328 }
329 }
330 return false;
[email protected]40c4cbb2012-01-10 23:26:07331}
332
[email protected]57b8bb352012-01-11 05:11:46333views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
334 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04335 // Use translucent-style window frames for dialogs.
[email protected]85501fe2013-10-18 10:15:27336 return new CustomFrameViewAsh(widget);
[email protected]57b8bb352012-01-11 05:11:46337}
338
[email protected]3d29912a2012-02-07 07:41:51339void Shell::RotateFocus(Direction direction) {
[email protected]093b8d642014-04-03 20:59:28340 focus_cycler_->RotateFocus(direction == FORWARD ? FocusCycler::FORWARD
341 : FocusCycler::BACKWARD);
[email protected]3d29912a2012-02-07 07:41:51342}
343
[email protected]2e236a52012-06-27 22:21:47344void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44345 const gfx::Insets& insets) {
[email protected]b8984242013-07-12 07:55:38346 if (!display_controller_->UpdateWorkAreaOfDisplayNearestWindow(
347 contains, insets)) {
[email protected]1a2145b2012-03-13 21:09:17348 return;
[email protected]b8984242013-07-12 07:55:38349 }
[email protected]1a2145b2012-03-13 21:09:17350 FOR_EACH_OBSERVER(ShellObserver, observers_,
[email protected]2e236a52012-06-27 22:21:47351 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17352}
353
[email protected]82d3954ae2012-04-20 09:02:22354void Shell::OnLoginStateChanged(user::LoginStatus status) {
355 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
356}
357
[email protected]51f438112013-11-18 19:32:50358void Shell::OnLoginUserProfilePrepared() {
[email protected]864b58552013-12-19 04:19:38359 CreateShelf();
[email protected]51f438112013-11-18 19:32:50360 CreateKeyboard();
361}
362
[email protected]88d71122012-10-18 07:11:01363void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50364 RootWindowControllerList controllers = GetAllRootWindowControllers();
365 for (RootWindowControllerList::iterator iter = controllers.begin();
366 iter != controllers.end(); ++iter)
367 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01368}
369
[email protected]82d3954ae2012-04-20 09:02:22370void Shell::OnAppTerminating() {
371 FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
372}
373
374void Shell::OnLockStateChanged(bool locked) {
375 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
[email protected]ae298142013-08-10 15:30:29376#ifndef NDEBUG
377 // Make sure that there is no system modal in Lock layer when unlocked.
378 if (!locked) {
379 std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
[email protected]093b8d642014-04-03 20:59:28380 kShellWindowId_LockSystemModalContainer, GetPrimaryRootWindow());
[email protected]ae298142013-08-10 15:30:29381 for (std::vector<aura::Window*>::const_iterator iter = containers.begin();
382 iter != containers.end(); ++iter) {
383 DCHECK_EQ(0u, (*iter)->children().size());
384 }
385 }
386#endif
[email protected]82d3954ae2012-04-20 09:02:22387}
388
[email protected]58868abf2014-01-17 23:45:33389void Shell::OnCastingSessionStartedOrStopped(bool started) {
390#if defined(OS_CHROMEOS) && defined(USE_X11)
[email protected]72bce522014-02-10 21:11:26391 if (projecting_observer_)
392 projecting_observer_->OnCastingSessionStartedOrStopped(started);
[email protected]58868abf2014-01-17 23:45:33393#endif
394}
395
[email protected]de42bcc2014-03-04 05:17:00396void Shell::OnOverviewModeStarting() {
397 FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeStarting());
398}
399
400void Shell::OnOverviewModeEnding() {
401 FOR_EACH_OBSERVER(ShellObserver, observers_, OnOverviewModeEnding());
402}
403
[email protected]02a80052014-03-14 05:45:23404void Shell::OnMaximizeModeStarted() {
405 FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeStarted());
406}
407
408void Shell::OnMaximizeModeEnded() {
409 FOR_EACH_OBSERVER(ShellObserver, observers_, OnMaximizeModeEnded());
410}
411
[email protected]0e3e7cb2014-04-12 05:18:25412void Shell::OnRootWindowAdded(aura::Window* root_window) {
413 FOR_EACH_OBSERVER(ShellObserver, observers_, OnRootWindowAdded(root_window));
414}
415
[email protected]864b58552013-12-19 04:19:38416void Shell::CreateShelf() {
[email protected]8c0ec432013-05-10 04:33:39417 RootWindowControllerList controllers = GetAllRootWindowControllers();
418 for (RootWindowControllerList::iterator iter = controllers.begin();
419 iter != controllers.end(); ++iter)
[email protected]864b58552013-12-19 04:19:38420 (*iter)->shelf()->CreateShelf();
[email protected]d9456cb2012-03-21 16:41:04421}
422
[email protected]b8642ec2014-04-17 05:20:39423void Shell::OnShelfCreatedForRootWindow(aura::Window* root_window) {
424 FOR_EACH_OBSERVER(ShellObserver,
425 observers_,
426 OnShelfCreatedForRootWindow(root_window));
427}
428
[email protected]51f438112013-11-18 19:32:50429void Shell::CreateKeyboard() {
430 // TODO(bshe): Primary root window controller may not be the controller to
431 // attach virtual keyboard. See http://crbug.com/303429
432 InitKeyboard();
433 if (keyboard::IsKeyboardUsabilityExperimentEnabled()) {
434 display_controller()->virtual_keyboard_window_controller()->
[email protected]a0b3fb882014-04-07 19:26:03435 ActivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50436 } else {
437 GetPrimaryRootWindowController()->
[email protected]a0b3fb882014-04-07 19:26:03438 ActivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]51f438112013-11-18 19:32:50439 }
440}
441
[email protected]e1b299b2014-01-29 23:53:41442void Shell::DeactivateKeyboard() {
[email protected]a0b3fb882014-04-07 19:26:03443 if (keyboard::KeyboardController::GetInstance()) {
[email protected]e1b299b2014-01-29 23:53:41444 RootWindowControllerList controllers = GetAllRootWindowControllers();
445 for (RootWindowControllerList::iterator iter = controllers.begin();
446 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:03447 (*iter)->DeactivateKeyboard(keyboard::KeyboardController::GetInstance());
[email protected]e1b299b2014-01-29 23:53:41448 }
449 }
[email protected]a0b3fb882014-04-07 19:26:03450 keyboard::KeyboardController::ResetInstance(NULL);
[email protected]e1b299b2014-01-29 23:53:41451}
452
[email protected]864b58552013-12-19 04:19:38453void Shell::ShowShelf() {
[email protected]8c0ec432013-05-10 04:33:39454 RootWindowControllerList controllers = GetAllRootWindowControllers();
455 for (RootWindowControllerList::iterator iter = controllers.begin();
456 iter != controllers.end(); ++iter)
[email protected]864b58552013-12-19 04:19:38457 (*iter)->ShowShelf();
[email protected]7e1df2f62012-07-19 19:17:18458}
459
[email protected]1a2145b2012-03-13 21:09:17460void Shell::AddShellObserver(ShellObserver* observer) {
461 observers_.AddObserver(observer);
462}
463
464void Shell::RemoveShellObserver(ShellObserver* observer) {
465 observers_.RemoveObserver(observer);
466}
467
[email protected]e55b73452014-02-20 13:18:04468void Shell::EnableMaximizeModeWindowManager(bool enable) {
469 if (enable && !maximize_mode_window_manager_.get()) {
[email protected]093b8d642014-04-03 20:59:28470 maximize_mode_window_manager_.reset(new MaximizeModeWindowManager());
[email protected]e55b73452014-02-20 13:18:04471 } else if (!enable && maximize_mode_window_manager_.get()) {
472 maximize_mode_window_manager_.reset();
473 }
474}
475
[email protected]b19b09a2014-02-26 05:34:34476bool Shell::IsMaximizeModeWindowManagerEnabled() {
477 return maximize_mode_window_manager_.get() != NULL;
478}
479
[email protected]da285852014-05-27 19:53:43480#if defined(OS_CHROMEOS)
481bool Shell::ShouldSaveDisplaySettings() {
482 return !((IsMaximizeModeWindowManagerEnabled() &&
483 maximize_mode_controller_->in_set_screen_rotation()) ||
484 resolution_notification_controller_->DoesNotificationTimeout());
485}
486#endif
487
[email protected]c758fbf2012-03-25 22:53:59488void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33489 RootWindowControllerList controllers = GetAllRootWindowControllers();
490 for (RootWindowControllerList::iterator iter = controllers.begin();
491 iter != controllers.end(); ++iter)
492 if ((*iter)->shelf())
493 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59494}
495
[email protected]431552c2012-10-23 00:38:33496void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
[email protected]bf9cdb362013-10-25 19:22:45497 aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28498 ash::ShelfLayoutManager::ForShelf(root_window)->SetAutoHideBehavior(behavior);
[email protected]c758fbf2012-03-25 22:53:59499}
500
[email protected]431552c2012-10-23 00:38:33501ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
[email protected]bf9cdb362013-10-25 19:22:45502 aura::Window* root_window) const {
[email protected]093b8d642014-04-03 20:59:28503 return ash::ShelfLayoutManager::ForShelf(root_window)->auto_hide_behavior();
[email protected]c758fbf2012-03-25 22:53:59504}
505
[email protected]431552c2012-10-23 00:38:33506void Shell::SetShelfAlignment(ShelfAlignment alignment,
[email protected]bf9cdb362013-10-25 19:22:45507 aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28508 if (ash::ShelfLayoutManager::ForShelf(root_window)->SetAlignment(alignment)) {
[email protected]f89f7512012-12-17 19:21:18509 FOR_EACH_OBSERVER(
510 ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
511 }
[email protected]55444502012-05-10 15:43:53512}
513
[email protected]bf9cdb362013-10-25 19:22:45514ShelfAlignment Shell::GetShelfAlignment(aura::Window* root_window) {
[email protected]093b8d642014-04-03 20:59:28515 return GetRootWindowController(root_window)
516 ->GetShelfLayoutManager()
517 ->GetAlignment();
[email protected]55444502012-05-10 15:43:53518}
519
[email protected]d90b8392012-06-13 09:34:56520void Shell::SetDimming(bool should_dim) {
[email protected]be65be362012-06-15 07:38:23521 RootWindowControllerList controllers = GetAllRootWindowControllers();
522 for (RootWindowControllerList::iterator iter = controllers.begin();
523 iter != controllers.end(); ++iter)
524 (*iter)->screen_dimmer()->SetDimming(should_dim);
[email protected]d90b8392012-06-13 09:34:56525}
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,
592 controller.Pass());
[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) {
614 display_controller_->cursor_window_controller()->SetCursorCompositingEnabled(
615 enabled);
616 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
628Shell::Shell(ShellDelegate* delegate)
[email protected]55ad8c12014-01-17 18:24:33629 : target_root_window_(NULL),
[email protected]b6ba05d902013-10-04 21:38:45630 scoped_target_root_window_(NULL),
631 delegate_(delegate),
632 window_positioner_(new WindowPositioner),
633 activation_client_(NULL),
[email protected]cc4fc3b2014-04-03 08:07:09634 accelerometer_controller_(new AccelerometerController()),
[email protected]94545ca92014-03-29 01:17:59635#if defined(OS_CHROMEOS)
[email protected]1e31cbd2014-04-07 20:06:11636 display_configurator_(new ui::DisplayConfigurator()),
[email protected]94545ca92014-03-29 01:17:59637#endif // defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45638 native_cursor_manager_(new AshNativeCursorManager),
[email protected]94545ca92014-03-29 01:17:59639 cursor_manager_(
640 scoped_ptr< ::wm::NativeCursorManager>(native_cursor_manager_)),
[email protected]b6ba05d902013-10-04 21:38:45641 simulate_modal_window_open_for_testing_(false),
[email protected]99edff3e2014-01-31 18:20:36642 is_touch_hud_projection_enabled_(false) {
[email protected]b6ba05d902013-10-04 21:38:45643 DCHECK(delegate_.get());
[email protected]99edff3e2014-01-31 18:20:36644 gpu_support_.reset(delegate_->CreateGPUSupport());
[email protected]093b8d642014-04-03 20:59:28645 display_manager_.reset(new DisplayManager);
[email protected]b6ba05d902013-10-04 21:38:45646 display_controller_.reset(new DisplayController);
647#if defined(OS_CHROMEOS) && defined(USE_X11)
[email protected]5d2ea362013-12-13 08:10:18648 user_metrics_recorder_.reset(new UserMetricsRecorder);
[email protected]b6ba05d902013-10-04 21:38:45649#endif // defined(OS_CHROMEOS)
650
651#if defined(OS_CHROMEOS)
[email protected]093b8d642014-04-03 20:59:28652 PowerStatus::Initialize();
[email protected]b6ba05d902013-10-04 21:38:45653#endif
654}
655
656Shell::~Shell() {
657 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
658
[email protected]050e77182014-03-25 15:29:16659 delegate_->PreShutdown();
660
[email protected]b6ba05d902013-10-04 21:38:45661 views::FocusManagerFactory::Install(NULL);
662
663 // Remove the focus from any window. This will prevent overhead and side
664 // effects (e.g. crashes) from changing focus during shutdown.
665 // See bug crbug.com/134502.
666 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(NULL);
667
668 // Please keep in same order as in Init() because it's easy to miss one.
669 if (window_modality_controller_)
670 window_modality_controller_.reset();
[email protected]3dff2ef2014-02-09 22:50:39671#if defined(OS_CHROMEOS) && defined(USE_X11)
[email protected]e4ea52362014-02-15 03:21:06672 RemovePreTargetHandler(magnifier_key_scroll_handler_.get());
673 magnifier_key_scroll_handler_.reset();
674
675 RemovePreTargetHandler(speech_feedback_handler_.get());
676 speech_feedback_handler_.reset();
[email protected]3dff2ef2014-02-09 22:50:39677#endif
[email protected]b6ba05d902013-10-04 21:38:45678 RemovePreTargetHandler(user_activity_detector_.get());
679 RemovePreTargetHandler(overlay_filter_.get());
680 RemovePreTargetHandler(input_method_filter_.get());
[email protected]3537d472014-01-15 05:45:31681 RemovePreTargetHandler(accelerator_filter_.get());
682 RemovePreTargetHandler(event_transformation_handler_.get());
683 RemovePreTargetHandler(toplevel_window_event_handler_.get());
684 RemovePostTargetHandler(toplevel_window_event_handler_.get());
[email protected]342d56a2013-12-20 23:01:02685 RemovePreTargetHandler(system_gesture_filter_.get());
686 RemovePreTargetHandler(keyboard_metrics_filter_.get());
[email protected]8ab613cf2014-05-12 09:39:49687 RemovePreTargetHandler(mouse_cursor_filter_.get());
[email protected]b6ba05d902013-10-04 21:38:45688
689 // TooltipController is deleted with the Shell so removing its references.
690 RemovePreTargetHandler(tooltip_controller_.get());
691
[email protected]5ed2b642014-03-04 00:06:57692 // Destroy maximize window manager early on since it has some observers which
693 // need to be removed.
[email protected]58fb353d2014-04-04 03:28:05694 maximize_mode_controller_.reset();
[email protected]5ed2b642014-03-04 00:06:57695 maximize_mode_window_manager_.reset();
696
[email protected]b6ba05d902013-10-04 21:38:45697 // AppList needs to be released before shelf layout manager, which is
[email protected]864b58552013-12-19 04:19:38698 // destroyed with shelf container in the loop below. However, app list
699 // container is now on top of shelf container and released after it.
[email protected]b6ba05d902013-10-04 21:38:45700 // TODO(xiyuan): Move it back when app list container is no longer needed.
701 app_list_controller_.reset();
702
[email protected]0dc85512014-03-13 13:26:41703#if defined(OS_CHROMEOS)
[email protected]ded32492014-03-14 10:09:28704 // Destroy the LastWindowClosedLogoutReminder before the
705 // LogoutConfirmationController.
706 last_window_closed_logout_reminder_.reset();
707
[email protected]7b3f91ee2014-03-06 11:41:40708 // Destroy the LogoutConfirmationController before the SystemTrayDelegate.
709 logout_confirmation_controller_.reset();
[email protected]0dc85512014-03-13 13:26:41710#endif
[email protected]7b3f91ee2014-03-06 11:41:40711
[email protected]b6ba05d902013-10-04 21:38:45712 // Destroy SystemTrayDelegate before destroying the status area(s).
713 system_tray_delegate_->Shutdown();
714 system_tray_delegate_.reset();
715
716 locale_notification_controller_.reset();
717
718 // Drag-and-drop must be canceled prior to close all windows.
719 drag_drop_controller_.reset();
720
[email protected]8c9d12a2013-12-06 18:39:03721 // Controllers who have WindowObserver added must be deleted
722 // before |display_controller_| is deleted.
723
724#if defined(OS_CHROMEOS)
725 // VideoActivityNotifier must be deleted before |video_detector_| is
726 // deleted because it's observing video activity through
727 // VideoDetectorObserver interface.
728 video_activity_notifier_.reset();
729#endif // defined(OS_CHROMEOS)
730 video_detector_.reset();
[email protected]0e3e7cb2014-04-12 05:18:25731 high_contrast_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03732
733 shadow_controller_.reset();
734 resize_shadow_controller_.reset();
735
[email protected]dd1e1ac2014-05-13 03:44:09736 window_cycle_controller_.reset();
[email protected]3a472922013-12-16 18:00:54737 window_selector_controller_.reset();
[email protected]8c9d12a2013-12-06 18:39:03738 mru_window_tracker_.reset();
739
740 // |shelf_window_watcher_| has a weak pointer to |shelf_Model_|
741 // and has window observers.
742 shelf_window_watcher_.reset();
743
[email protected]b6ba05d902013-10-04 21:38:45744 // Destroy all child windows including widgets.
745 display_controller_->CloseChildWindows();
[email protected]51f438112013-11-18 19:32:50746 display_controller_->CloseNonDesktopDisplay();
[email protected]b6ba05d902013-10-04 21:38:45747
[email protected]8b57e942013-12-09 19:39:20748 // Chrome implementation of shelf delegate depends on FocusClient,
[email protected]8c9d12a2013-12-06 18:39:03749 // so must be deleted before |focus_client_|.
[email protected]8b57e942013-12-09 19:39:20750 shelf_delegate_.reset();
[email protected]8c9d12a2013-12-06 18:39:03751 focus_client_.reset();
752
[email protected]b6ba05d902013-10-04 21:38:45753 // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
754 // needs to remove observers from it.
755 system_tray_notifier_.reset();
756
757 // These need a valid Shell instance to clean up properly, so explicitly
758 // delete them before invalidating the instance.
759 // Alphabetical. TODO(oshima): sort.
760 magnification_controller_.reset();
761 partial_magnification_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45762 tooltip_controller_.reset();
763 event_client_.reset();
[email protected]284145ef2014-05-27 19:04:09764 nested_dispatcher_controller_.reset();
[email protected]3537d472014-01-15 05:45:31765 toplevel_window_event_handler_.reset();
[email protected]b6ba05d902013-10-04 21:38:45766 visibility_controller_.reset();
[email protected]c25ff502013-12-04 13:52:48767 // |shelf_item_delegate_manager_| observes |shelf_model_|. It must be
[email protected]64936bf2013-11-14 19:48:36768 // destroyed before |shelf_model_| is destroyed.
[email protected]c25ff502013-12-04 13:52:48769 shelf_item_delegate_manager_.reset();
[email protected]64936bf2013-11-14 19:48:36770 shelf_model_.reset();
[email protected]b6ba05d902013-10-04 21:38:45771
772 power_button_controller_.reset();
773 lock_state_controller_.reset();
[email protected]b6ba05d902013-10-04 21:38:45774
[email protected]7bc49bd2014-01-22 09:30:34775#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45776 resolution_notification_controller_.reset();
[email protected]7bc49bd2014-01-22 09:30:34777#endif
[email protected]b6ba05d902013-10-04 21:38:45778 desktop_background_controller_.reset();
[email protected]8ab613cf2014-05-12 09:39:49779 mouse_cursor_filter_.reset();
[email protected]b6ba05d902013-10-04 21:38:45780
[email protected]03122891a2014-05-13 23:56:49781#if defined(OS_CHROMEOS) && defined(USE_X11)
782 touch_transformer_controller_.reset();
783#endif // defined(OS_CHROMEOS) && defined(USE_X11)
784
[email protected]b6ba05d902013-10-04 21:38:45785 // This also deletes all RootWindows. Note that we invoke Shutdown() on
786 // DisplayController before resetting |display_controller_|, since destruction
787 // of its owned RootWindowControllers relies on the value.
[email protected]55ad8c12014-01-17 18:24:33788 display_manager_->CreateScreenForShutdown();
[email protected]b6ba05d902013-10-04 21:38:45789 display_controller_->Shutdown();
790 display_controller_.reset();
791 screen_position_controller_.reset();
[email protected]f3ab6eff52013-10-24 03:29:38792 accessibility_delegate_.reset();
[email protected]efc897f72013-11-01 11:43:07793 new_window_delegate_.reset();
794 media_delegate_.reset();
[email protected]b6ba05d902013-10-04 21:38:45795
[email protected]a0b3fb882014-04-07 19:26:03796 keyboard::KeyboardController::ResetInstance(NULL);
797
[email protected]94545ca92014-03-29 01:17:59798#if defined(OS_CHROMEOS)
[email protected]7bc49bd2014-01-22 09:30:34799 if (display_change_observer_)
[email protected]1e31cbd2014-04-07 20:06:11800 display_configurator_->RemoveObserver(display_change_observer_.get());
[email protected]129aad82014-04-24 23:17:04801 if (display_configurator_animation_)
802 display_configurator_->RemoveObserver(
803 display_configurator_animation_.get());
[email protected]b6ba05d902013-10-04 21:38:45804 if (display_error_observer_)
[email protected]1e31cbd2014-04-07 20:06:11805 display_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]72bce522014-02-10 21:11:26806 if (projecting_observer_)
[email protected]1e31cbd2014-04-07 20:06:11807 display_configurator_->RemoveObserver(projecting_observer_.get());
[email protected]b6ba05d902013-10-04 21:38:45808 display_change_observer_.reset();
809#endif // defined(OS_CHROMEOS)
810
811#if defined(OS_CHROMEOS)
[email protected]093b8d642014-04-03 20:59:28812 PowerStatus::Shutdown();
[email protected]b6ba05d902013-10-04 21:38:45813#endif
814
815 DCHECK(instance_ == this);
816 instance_ = NULL;
817}
818
[email protected]1b4c7472014-05-15 18:32:23819void Shell::Init(const ShellInitParams& init_params) {
[email protected]b6ba05d902013-10-04 21:38:45820 delegate_->PreInit();
[email protected]51f438112013-11-18 19:32:50821 if (keyboard::IsKeyboardUsabilityExperimentEnabled()) {
[email protected]093b8d642014-04-03 20:59:28822 display_manager_->SetSecondDisplayMode(DisplayManager::VIRTUAL_KEYBOARD);
[email protected]608de6c2013-10-29 00:14:28823 }
[email protected]0249a6532013-10-31 06:53:34824 bool display_initialized = display_manager_->InitFromCommandLine();
[email protected]94545ca92014-03-29 01:17:59825#if defined(OS_CHROMEOS)
[email protected]1e31cbd2014-04-07 20:06:11826 display_configurator_->Init(!gpu_support_->IsPanelFittingDisabled());
[email protected]129aad82014-04-24 23:17:04827 display_configurator_animation_.reset(new DisplayConfiguratorAnimation());
828 display_configurator_->AddObserver(display_configurator_animation_.get());
[email protected]0249a6532013-10-31 06:53:34829
[email protected]093b8d642014-04-03 20:59:28830 projecting_observer_.reset(new ProjectingObserver());
[email protected]1e31cbd2014-04-07 20:06:11831 display_configurator_->AddObserver(projecting_observer_.get());
[email protected]72bce522014-02-10 21:11:26832
[email protected]0249a6532013-10-31 06:53:34833 if (!display_initialized && base::SysInfo::IsRunningOnChromeOS()) {
[email protected]093b8d642014-04-03 20:59:28834 display_change_observer_.reset(new DisplayChangeObserver);
[email protected]b6ba05d902013-10-04 21:38:45835 // Register |display_change_observer_| first so that the rest of
836 // observer gets invoked after the root windows are configured.
[email protected]1e31cbd2014-04-07 20:06:11837 display_configurator_->AddObserver(display_change_observer_.get());
[email protected]093b8d642014-04-03 20:59:28838 display_error_observer_.reset(new DisplayErrorObserver());
[email protected]1e31cbd2014-04-07 20:06:11839 display_configurator_->AddObserver(display_error_observer_.get());
840 display_configurator_->set_state_controller(display_change_observer_.get());
841 display_configurator_->set_mirroring_controller(display_manager_.get());
842 display_configurator_->ForceInitialConfigure(
[email protected]b6ba05d902013-10-04 21:38:45843 delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
844 display_initialized = true;
845 }
[email protected]94545ca92014-03-29 01:17:59846#endif // defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45847 if (!display_initialized)
[email protected]0249a6532013-10-31 06:53:34848 display_manager_->InitDefaultDisplay();
[email protected]b6ba05d902013-10-04 21:38:45849
850 // Install the custom factory first so that views::FocusManagers for Tray,
[email protected]864b58552013-12-19 04:19:38851 // Shelf, and WallPaper could be created by the factory.
[email protected]b6ba05d902013-10-04 21:38:45852 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
853
[email protected]5b883abb2014-05-05 06:44:10854 aura::Env::CreateInstance(true);
[email protected]fa69f2b62014-05-22 21:47:58855 aura::Env::GetInstance()->set_context_factory(init_params.context_factory);
[email protected]ecca62b2013-10-09 16:18:53856
[email protected]b6ba05d902013-10-04 21:38:45857 // The WindowModalityController needs to be at the front of the input event
858 // pretarget handler list to ensure that it processes input events when modal
859 // windows are active.
860 window_modality_controller_.reset(
[email protected]e319c7e2014-03-14 19:56:14861 new ::wm::WindowModalityController(this));
[email protected]b6ba05d902013-10-04 21:38:45862
863 AddPreTargetHandler(this);
864
[email protected]e319c7e2014-03-14 19:56:14865 env_filter_.reset(new ::wm::CompoundEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45866 AddPreTargetHandler(env_filter_.get());
867
[email protected]e319c7e2014-03-14 19:56:14868 ::wm::FocusController* focus_controller =
869 new ::wm::FocusController(new wm::AshFocusRules);
[email protected]b6ba05d902013-10-04 21:38:45870 focus_client_.reset(focus_controller);
871 activation_client_ = focus_controller;
872 activation_client_->AddObserver(this);
[email protected]093b8d642014-04-03 20:59:28873 focus_cycler_.reset(new FocusCycler());
[email protected]b6ba05d902013-10-04 21:38:45874
[email protected]093b8d642014-04-03 20:59:28875 screen_position_controller_.reset(new ScreenPositionController);
[email protected]b6ba05d902013-10-04 21:38:45876
877 display_controller_->Start();
[email protected]1b4c7472014-05-15 18:32:23878 display_controller_->CreatePrimaryHost(
879 ShellInitParamsToAshWindowTreeHostInitParams(init_params));
[email protected]bf9cdb362013-10-25 19:22:45880 aura::Window* root_window = display_controller_->GetPrimaryRootWindow();
[email protected]b6ba05d902013-10-04 21:38:45881 target_root_window_ = root_window;
882
[email protected]7bc49bd2014-01-22 09:30:34883#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45884 resolution_notification_controller_.reset(
[email protected]093b8d642014-04-03 20:59:28885 new ResolutionNotificationController);
[email protected]7bc49bd2014-01-22 09:30:34886#endif
[email protected]b6ba05d902013-10-04 21:38:45887
[email protected]55ad8c12014-01-17 18:24:33888 cursor_manager_.SetDisplay(GetScreen()->GetPrimaryDisplay());
[email protected]b6ba05d902013-10-04 21:38:45889
[email protected]284145ef2014-05-27 19:04:09890 nested_dispatcher_controller_.reset(new NestedDispatcherController);
[email protected]b6ba05d902013-10-04 21:38:45891 accelerator_controller_.reset(new AcceleratorController);
[email protected]58fb353d2014-04-04 03:28:05892 maximize_mode_controller_.reset(new MaximizeModeController());
[email protected]b6ba05d902013-10-04 21:38:45893
[email protected]3dff2ef2014-02-09 22:50:39894#if defined(OS_CHROMEOS) && defined(USE_X11)
[email protected]e4ea52362014-02-15 03:21:06895 magnifier_key_scroll_handler_ = MagnifierKeyScroller::CreateHandler().Pass();
896 AddPreTargetHandler(magnifier_key_scroll_handler_.get());
897 speech_feedback_handler_ = SpokenFeedbackToggler::CreateHandler().Pass();
898 AddPreTargetHandler(speech_feedback_handler_.get());
[email protected]3dff2ef2014-02-09 22:50:39899#endif
900
[email protected]b6ba05d902013-10-04 21:38:45901 // The order in which event filters are added is significant.
[email protected]b6ba05d902013-10-04 21:38:45902
[email protected]f94c6aa2013-11-08 01:18:54903#if defined(OS_CHROMEOS)
[email protected]08bdabed2013-12-20 07:52:28904 // The StickyKeysController also rewrites events and must be added
[email protected]f94c6aa2013-11-08 01:18:54905 // before observers, but after the EventRewriterEventFilter.
[email protected]08bdabed2013-12-20 07:52:28906 sticky_keys_controller_.reset(new StickyKeysController);
907 AddPreTargetHandler(sticky_keys_controller_.get());
[email protected]f94c6aa2013-11-08 01:18:54908#endif
909
[email protected]f0f612382014-04-03 15:11:49910 // wm::UserActivityDetector passes events to observers, so let them get
[email protected]b6ba05d902013-10-04 21:38:45911 // rewritten first.
[email protected]f0f612382014-04-03 15:11:49912 user_activity_detector_.reset(new ::wm::UserActivityDetector);
[email protected]b6ba05d902013-10-04 21:38:45913 AddPreTargetHandler(user_activity_detector_.get());
914
[email protected]093b8d642014-04-03 20:59:28915 overlay_filter_.reset(new OverlayEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45916 AddPreTargetHandler(overlay_filter_.get());
917 AddShellObserver(overlay_filter_.get());
918
[email protected]e319c7e2014-03-14 19:56:14919 input_method_filter_.reset(new ::wm::InputMethodEventFilter(
[email protected]2374d1812014-03-04 03:42:27920 root_window->GetHost()->GetAcceleratedWidget()));
[email protected]b6ba05d902013-10-04 21:38:45921 AddPreTargetHandler(input_method_filter_.get());
922
[email protected]093b8d642014-04-03 20:59:28923 accelerator_filter_.reset(new AcceleratorFilter);
[email protected]b6ba05d902013-10-04 21:38:45924 AddPreTargetHandler(accelerator_filter_.get());
925
[email protected]093b8d642014-04-03 20:59:28926 event_transformation_handler_.reset(new EventTransformationHandler);
[email protected]b6ba05d902013-10-04 21:38:45927 AddPreTargetHandler(event_transformation_handler_.get());
928
[email protected]3537d472014-01-15 05:45:31929 toplevel_window_event_handler_.reset(new ToplevelWindowEventHandler);
930
[email protected]093b8d642014-04-03 20:59:28931 system_gesture_filter_.reset(new SystemGestureEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45932 AddPreTargetHandler(system_gesture_filter_.get());
933
[email protected]093b8d642014-04-03 20:59:28934 keyboard_metrics_filter_.reset(new KeyboardUMAEventFilter);
[email protected]b6ba05d902013-10-04 21:38:45935 AddPreTargetHandler(keyboard_metrics_filter_.get());
936
937 // The keyboard system must be initialized before the RootWindowController is
938 // created.
[email protected]e1b299b2014-01-29 23:53:41939#if defined(OS_CHROMEOS)
[email protected]b6ba05d902013-10-04 21:38:45940 keyboard::InitializeKeyboard();
[email protected]e1b299b2014-01-29 23:53:41941#endif
[email protected]b6ba05d902013-10-04 21:38:45942
943 lock_state_controller_.reset(new LockStateController);
944 power_button_controller_.reset(new PowerButtonController(
945 lock_state_controller_.get()));
[email protected]94545ca92014-03-29 01:17:59946#if defined(OS_CHROMEOS)
[email protected]685442f32014-02-28 10:40:06947 // Pass the initial display state to PowerButtonController.
948 power_button_controller_->OnDisplayModeChanged(
[email protected]bcec7fb62014-04-08 20:59:09949 display_configurator_->cached_displays());
[email protected]685442f32014-02-28 10:40:06950#endif
[email protected]b6ba05d902013-10-04 21:38:45951 AddShellObserver(lock_state_controller_.get());
952
[email protected]093b8d642014-04-03 20:59:28953 drag_drop_controller_.reset(new DragDropController);
954 mouse_cursor_filter_.reset(new MouseCursorEventFilter());
[email protected]b6ba05d902013-10-04 21:38:45955 PrependPreTargetHandler(mouse_cursor_filter_.get());
956
957 // Create Controllers that may need root window.
958 // TODO(oshima): Move as many controllers before creating
959 // RootWindowController as possible.
960 visibility_controller_.reset(new AshVisibilityController);
[email protected]b6ba05d902013-10-04 21:38:45961
962 magnification_controller_.reset(
963 MagnificationController::CreateInstance());
964 mru_window_tracker_.reset(new MruWindowTracker(activation_client_));
965
966 partial_magnification_controller_.reset(
967 new PartialMagnificationController());
968
[email protected]55398d22013-10-10 19:49:20969 autoclick_controller_.reset(AutoclickController::CreateInstance());
970
[email protected]b6ba05d902013-10-04 21:38:45971 high_contrast_controller_.reset(new HighContrastController);
972 video_detector_.reset(new VideoDetector);
[email protected]b6ba05d902013-10-04 21:38:45973 window_selector_controller_.reset(new WindowSelectorController());
[email protected]dd1e1ac2014-05-13 03:44:09974 window_cycle_controller_.reset(new WindowCycleController());
[email protected]b6ba05d902013-10-04 21:38:45975
[email protected]d7f30a72013-10-05 05:09:41976 tooltip_controller_.reset(
977 new views::corewm::TooltipController(
978 scoped_ptr<views::corewm::Tooltip>(
979 new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE))));
[email protected]b6ba05d902013-10-04 21:38:45980 AddPreTargetHandler(tooltip_controller_.get());
981
[email protected]093b8d642014-04-03 20:59:28982 event_client_.reset(new EventClientImpl);
[email protected]b6ba05d902013-10-04 21:38:45983
984 // This controller needs to be set before SetupManagedWindowMode.
985 desktop_background_controller_.reset(new DesktopBackgroundController());
986 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
987
[email protected]b6ba05d902013-10-04 21:38:45988 session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
[email protected]f3ab6eff52013-10-24 03:29:38989 accessibility_delegate_.reset(delegate_->CreateAccessibilityDelegate());
[email protected]47686c42013-10-25 01:49:17990 new_window_delegate_.reset(delegate_->CreateNewWindowDelegate());
[email protected]efc897f72013-11-01 11:43:07991 media_delegate_.reset(delegate_->CreateMediaDelegate());
[email protected]b6ba05d902013-10-04 21:38:45992
[email protected]093b8d642014-04-03 20:59:28993 resize_shadow_controller_.reset(new ResizeShadowController());
[email protected]d74caa82014-03-10 20:52:56994 shadow_controller_.reset(
[email protected]e319c7e2014-03-14 19:56:14995 new ::wm::ShadowController(activation_client_));
[email protected]b6ba05d902013-10-04 21:38:45996
997 // Create system_tray_notifier_ before the delegate.
998 system_tray_notifier_.reset(new ash::SystemTrayNotifier());
999
1000 // Initialize system_tray_delegate_ before initializing StatusAreaWidget.
1001 system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate());
1002 DCHECK(system_tray_delegate_.get());
1003
[email protected]093b8d642014-04-03 20:59:281004 locale_notification_controller_.reset(new LocaleNotificationController);
[email protected]b6ba05d902013-10-04 21:38:451005
1006 // Initialize system_tray_delegate_ after StatusAreaWidget is created.
1007 system_tray_delegate_->Initialize();
1008
[email protected]0dc85512014-03-13 13:26:411009#if defined(OS_CHROMEOS)
[email protected]7b3f91ee2014-03-06 11:41:401010 // Create the LogoutConfirmationController after the SystemTrayDelegate.
[email protected]093b8d642014-04-03 20:59:281011 logout_confirmation_controller_.reset(new LogoutConfirmationController(
1012 base::Bind(&SystemTrayDelegate::SignOut,
1013 base::Unretained(system_tray_delegate_.get()))));
[email protected]0dc85512014-03-13 13:26:411014#endif
[email protected]7b3f91ee2014-03-06 11:41:401015
[email protected]03122891a2014-05-13 23:56:491016#if defined(OS_CHROMEOS) && defined(USE_X11)
1017 // Create TouchTransformerController before DisplayController::InitDisplays()
1018 // since TouchTransformerController listens on
1019 // DisplayController::Observer::OnDisplaysInitialized().
1020 touch_transformer_controller_.reset(new TouchTransformerController());
1021#endif // defined(OS_CHROMEOS) && defined(USE_X11)
1022
[email protected]f5c9dbc2014-04-11 08:13:451023 display_controller_->InitDisplays();
[email protected]b6ba05d902013-10-04 21:38:451024
[email protected]a3565792013-10-18 12:52:371025 // It needs to be created after RootWindowController has been created
1026 // (which calls OnWindowResized has been called, otherwise the
[email protected]b6ba05d902013-10-04 21:38:451027 // widget will not paint when restoring after a browser crash. Also it needs
1028 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
1029 // the correct size.
1030 user_wallpaper_delegate_->InitializeWallpaper();
1031
1032 if (initially_hide_cursor_)
1033 cursor_manager_.HideCursor();
1034 cursor_manager_.SetCursor(ui::kCursorPointer);
1035
[email protected]5c04d3a92013-10-08 19:17:191036#if defined(OS_CHROMEOS)
[email protected]ded58fd2013-10-09 07:56:551037 // Set accelerator controller delegates.
[email protected]b6ba05d902013-10-04 21:38:451038 accelerator_controller_->SetBrightnessControlDelegate(
1039 scoped_ptr<ash::BrightnessControlDelegate>(
1040 new ash::system::BrightnessControllerChromeos).Pass());
[email protected]ded58fd2013-10-09 07:56:551041
[email protected]093b8d642014-04-03 20:59:281042 power_event_observer_.reset(new PowerEventObserver());
[email protected]ded58fd2013-10-09 07:56:551043 user_activity_notifier_.reset(
[email protected]b0fa7012014-04-16 12:50:571044 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
[email protected]ded58fd2013-10-09 07:56:551045 video_activity_notifier_.reset(
[email protected]093b8d642014-04-03 20:59:281046 new VideoActivityNotifier(video_detector_.get()));
1047 bluetooth_notification_controller_.reset(new BluetoothNotificationController);
1048 last_window_closed_logout_reminder_.reset(new LastWindowClosedLogoutReminder);
[email protected]b6ba05d902013-10-04 21:38:451049#endif
1050
[email protected]6f67df52013-10-29 01:07:151051 weak_display_manager_factory_.reset(
[email protected]093b8d642014-04-03 20:59:281052 new base::WeakPtrFactory<DisplayManager>(display_manager_.get()));
[email protected]b6ba05d902013-10-04 21:38:451053 // The compositor thread and main message loop have to be running in
1054 // order to create mirror window. Run it after the main message loop
1055 // is started.
1056 base::MessageLoopForUI::current()->PostTask(
1057 FROM_HERE,
[email protected]093b8d642014-04-03 20:59:281058 base::Bind(&DisplayManager::CreateMirrorWindowIfAny,
[email protected]6f67df52013-10-29 01:07:151059 weak_display_manager_factory_->GetWeakPtr()));
[email protected]b6ba05d902013-10-04 21:38:451060}
1061
[email protected]51f438112013-11-18 19:32:501062void Shell::InitKeyboard() {
[email protected]b6ba05d902013-10-04 21:38:451063 if (keyboard::IsKeyboardEnabled()) {
[email protected]a0b3fb882014-04-07 19:26:031064 if (keyboard::KeyboardController::GetInstance()) {
[email protected]b6ba05d902013-10-04 21:38:451065 RootWindowControllerList controllers = GetAllRootWindowControllers();
1066 for (RootWindowControllerList::iterator iter = controllers.begin();
1067 iter != controllers.end(); ++iter) {
[email protected]a0b3fb882014-04-07 19:26:031068 (*iter)->DeactivateKeyboard(
1069 keyboard::KeyboardController::GetInstance());
[email protected]b6ba05d902013-10-04 21:38:451070 }
1071 }
1072 keyboard::KeyboardControllerProxy* proxy =
1073 delegate_->CreateKeyboardControllerProxy();
[email protected]a0b3fb882014-04-07 19:26:031074 keyboard::KeyboardController::ResetInstance(
[email protected]b6ba05d902013-10-04 21:38:451075 new keyboard::KeyboardController(proxy));
[email protected]b6ba05d902013-10-04 21:38:451076 }
1077}
1078
[email protected]41baaed2013-11-09 04:18:261079void Shell::InitRootWindow(aura::Window* root_window) {
[email protected]39718b52012-12-03 17:24:561080 DCHECK(activation_client_);
[email protected]d90b8392012-06-13 09:34:561081 DCHECK(visibility_controller_.get());
1082 DCHECK(drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:561083
[email protected]8cfb6722012-11-28 03:28:461084 aura::client::SetFocusClient(root_window, focus_client_.get());
[email protected]d90b8392012-06-13 09:34:561085 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
[email protected]39718b52012-12-03 17:24:561086 aura::client::SetActivationClient(root_window, activation_client_);
[email protected]e319c7e2014-03-14 19:56:141087 ::wm::FocusController* focus_controller =
1088 static_cast< ::wm::FocusController*>(activation_client_);
[email protected]375338212013-09-05 22:14:521089 root_window->AddPreTargetHandler(focus_controller);
[email protected]d90b8392012-06-13 09:34:561090 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
1091 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:061092 aura::client::SetScreenPositionClient(root_window,
1093 screen_position_controller_.get());
[email protected]4b8003c2012-07-26 00:54:191094 aura::client::SetCursorClient(root_window, &cursor_manager_);
[email protected]54a37cdc2012-07-25 19:16:011095 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:381096 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:561097
[email protected]3537d472014-01-15 05:45:311098 aura::client::SetWindowMoveClient(root_window,
1099 toplevel_window_event_handler_.get());
1100 root_window->AddPreTargetHandler(toplevel_window_event_handler_.get());
1101 root_window->AddPostTargetHandler(toplevel_window_event_handler_.get());
1102
[email protected]284145ef2014-05-27 19:04:091103 if (nested_dispatcher_controller_) {
[email protected]d90b8392012-06-13 09:34:561104 aura::client::SetDispatcherClient(root_window,
[email protected]284145ef2014-05-27 19:04:091105 nested_dispatcher_controller_.get());
[email protected]d90b8392012-06-13 09:34:561106 }
[email protected]d90b8392012-06-13 09:34:561107}
1108
[email protected]c0ce80e2012-10-05 23:28:271109bool Shell::CanWindowReceiveEvents(aura::Window* window) {
1110 RootWindowControllerList controllers = GetAllRootWindowControllers();
1111 for (RootWindowControllerList::iterator iter = controllers.begin();
1112 iter != controllers.end(); ++iter) {
[email protected]093b8d642014-04-03 20:59:281113 SystemModalContainerLayoutManager* layout_manager =
[email protected]bb0c7cd42013-05-20 23:39:451114 (*iter)->GetSystemModalLayoutManager(window);
1115 if (layout_manager && layout_manager->CanWindowReceiveEvents(window))
[email protected]c0ce80e2012-10-05 23:28:271116 return true;
[email protected]602022b2014-03-31 17:07:311117 // Allow events to fall through to the virtual keyboard even if displaying
1118 // a system modal dialog.
1119 if ((*iter)->IsVirtualKeyboardWindow(window))
1120 return true;
[email protected]c0ce80e2012-10-05 23:28:271121 }
[email protected]602022b2014-03-31 17:07:311122
[email protected]c0ce80e2012-10-05 23:28:271123 return false;
1124}
1125
[email protected]049cf34b2012-12-07 17:15:481126////////////////////////////////////////////////////////////////////////////////
1127// Shell, ui::EventTarget overrides:
1128
[email protected]869f6352012-12-06 20:47:171129bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:411130 return true;
1131}
1132
1133ui::EventTarget* Shell::GetParentTarget() {
[email protected]ff0278852013-11-05 22:35:481134 return aura::Env::GetInstance();
[email protected]5097e692012-10-30 22:08:411135}
1136
[email protected]3e670aa2013-12-02 19:04:321137scoped_ptr<ui::EventTargetIterator> Shell::GetChildIterator() const {
1138 return scoped_ptr<ui::EventTargetIterator>();
1139}
1140
1141ui::EventTargeter* Shell::GetEventTargeter() {
1142 NOTREACHED();
1143 return NULL;
1144}
1145
[email protected]049cf34b2012-12-07 17:15:481146void Shell::OnEvent(ui::Event* event) {
[email protected]1ae361652012-12-12 22:39:511147}
1148
1149////////////////////////////////////////////////////////////////////////////////
1150// Shell, aura::client::ActivationChangeObserver implementation:
1151
1152void Shell::OnWindowActivated(aura::Window* gained_active,
1153 aura::Window* lost_active) {
[email protected]d219a192012-12-14 00:08:181154 if (gained_active)
[email protected]b42910f2013-08-01 11:45:291155 target_root_window_ = gained_active->GetRootWindow();
[email protected]049cf34b2012-12-07 17:15:481156}
1157
[email protected]55f593352011-12-24 05:42:461158} // namespace ash