blob: 8b0e939093dca1c2cda49a725ab39cf8a3347f2d [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]878479482013-09-18 10:29:1913#include "ash/accelerators/nested_dispatcher_controller.h"
[email protected]b65bdda2011-12-23 23:35:3114#include "ash/ash_switches.h"
[email protected]02dbd1a2012-11-08 22:50:1315#include "ash/caps_lock_delegate.h"
[email protected]e70cf0ed2012-03-15 16:24:4716#include "ash/desktop_background/desktop_background_controller.h"
[email protected]e70cf0ed2012-03-15 16:24:4717#include "ash/desktop_background/desktop_background_view.h"
[email protected]81abb1032012-11-13 18:55:4118#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]2e236a52012-06-27 22:21:4719#include "ash/display/display_controller.h"
[email protected]6bdf7952012-11-14 10:10:5820#include "ash/display/display_manager.h"
[email protected]682990f2013-01-10 06:49:1121#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2722#include "ash/display/mouse_cursor_event_filter.h"
[email protected]6ef71d72013-08-10 18:13:4423#include "ash/display/resolution_notification_controller.h"
[email protected]8d625fb2012-07-18 16:40:0624#include "ash/display/screen_position_controller.h"
[email protected]f4c92b382012-08-28 00:59:5925#include "ash/drag_drop/drag_drop_controller.h"
26#include "ash/focus_cycler.h"
27#include "ash/high_contrast/high_contrast_controller.h"
[email protected]fca90ea2012-12-14 04:13:3028#include "ash/host/root_window_host_factory.h"
[email protected]7a80cdd2013-09-26 09:20:5329#include "ash/keyboard_uma_event_filter.h"
[email protected]b913a3a2012-12-11 13:07:1930#include "ash/launcher/launcher_delegate.h"
[email protected]cc29ba12013-08-28 05:22:3431#include "ash/launcher/launcher_item_delegate.h"
32#include "ash/launcher/launcher_item_delegate_manager.h"
[email protected]b913a3a2012-12-11 13:07:1933#include "ash/launcher/launcher_model.h"
[email protected]f4c92b382012-08-28 00:59:5934#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5435#include "ash/magnifier/partial_magnification_controller.h"
[email protected]d90b8392012-06-13 09:34:5636#include "ash/root_window_controller.h"
[email protected]1a2145b2012-03-13 21:09:1737#include "ash/screen_ash.h"
[email protected]fcb123d2013-04-17 15:58:4938#include "ash/session_state_delegate.h"
[email protected]976624f2013-09-19 21:58:4939#include "ash/shelf/app_list_shelf_item_delegate.h"
[email protected]478c6c32013-03-09 02:50:5840#include "ash/shelf/shelf_layout_manager.h"
41#include "ash/shelf/shelf_widget.h"
[email protected]b65bdda2011-12-23 23:35:3142#include "ash/shell_delegate.h"
43#include "ash/shell_factory.h"
44#include "ash/shell_window_ids.h"
[email protected]a9a40462013-07-31 06:22:5645#include "ash/system/locale/locale_notification_controller.h"
[email protected]6d6546e2012-05-30 23:12:0246#include "ash/system/status_area_widget.h"
[email protected]51ed5992012-11-07 10:14:3947#include "ash/system/tray/system_tray_delegate.h"
[email protected]83b2b84c2012-11-14 01:11:0048#include "ash/system/tray/system_tray_notifier.h"
[email protected]0039db92012-05-09 04:11:4549#include "ash/wm/app_list_controller.h"
[email protected]39718b52012-12-03 17:24:5650#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2951#include "ash/wm/ash_native_cursor_manager.h"
[email protected]8812588c2012-01-30 21:19:0352#include "ash/wm/base_layout_manager.h"
[email protected]88d71122012-10-18 07:11:0153#include "ash/wm/coordinate_conversion.h"
[email protected]9d4d1712012-03-06 06:55:2554#include "ash/wm/custom_frame_view_ash.h"
[email protected]262f8bd2012-03-23 19:30:2755#include "ash/wm/event_client_impl.h"
[email protected]b9d224c2012-07-13 01:09:0356#include "ash/wm/event_rewriter_event_filter.h"
[email protected]ab4f8c92013-05-30 19:07:4757#include "ash/wm/lock_state_controller.h"
[email protected]66c5c4112013-07-31 07:10:5958#include "ash/wm/mru_window_tracker.h"
[email protected]9ae32df2012-07-26 03:25:1859#include "ash/wm/overlay_event_filter.h"
[email protected]09f35d742013-08-23 00:39:3960#include "ash/wm/overview/window_selector_controller.h"
[email protected]e0d22e82012-01-04 00:46:5761#include "ash/wm/power_button_controller.h"
[email protected]e4a181cc2012-03-17 02:20:5762#include "ash/wm/resize_shadow_controller.h"
[email protected]a3301dc2011-12-23 16:34:5163#include "ash/wm/root_window_layout_manager.h"
[email protected]42993212012-04-30 23:42:0464#include "ash/wm/screen_dimmer.h"
[email protected]435b212e2012-04-05 19:43:3765#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2766#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3367#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]c16b9422012-06-06 21:51:1168#include "ash/wm/user_activity_detector.h"
[email protected]9633a9d22012-01-21 16:40:5869#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:0270#include "ash/wm/window_animations.h"
[email protected]40c4cbb2012-01-10 23:26:0771#include "ash/wm/window_cycle_controller.h"
[email protected]e9a71312013-10-04 03:20:0172#include "ash/wm/window_positioner.h"
[email protected]f059c6942012-07-21 14:27:5773#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5974#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3675#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0076#include "base/bind.h"
[email protected]46ca3632011-11-03 03:33:4277#include "base/command_line.h"
[email protected]b0a8faa2012-10-19 03:22:2278#include "base/debug/leak_annotations.h"
[email protected]89af4002013-09-06 07:47:0779#include "base/debug/trace_event.h"
[email protected]2c456102011-12-26 06:26:3480#include "ui/aura/client/aura_constants.h"
[email protected]c28853612012-05-31 22:43:4481#include "ui/aura/client/user_action_client.h"
[email protected]8a45c972012-03-14 18:22:4482#include "ui/aura/env.h"
[email protected]a857dbe2012-05-30 22:10:1483#include "ui/aura/focus_manager.h"
[email protected]4bb16502011-12-06 14:44:5884#include "ui/aura/layout_manager.h"
[email protected]2c456102011-12-26 06:26:3485#include "ui/aura/root_window.h"
[email protected]87b0d82e2011-10-07 21:02:5986#include "ui/aura/window.h"
[email protected]2d4817742012-12-17 20:16:1887#include "ui/base/ui_base_switches.h"
[email protected]116302fc2012-05-05 21:45:4188#include "ui/compositor/layer.h"
89#include "ui/compositor/layer_animator.h"
[email protected]7da9c4c2012-06-12 14:43:0190#include "ui/gfx/display.h"
[email protected]9ec0f452012-05-31 15:58:5391#include "ui/gfx/image/image_skia.h"
[email protected]b82c42c42012-04-25 20:03:4192#include "ui/gfx/screen.h"
[email protected]b0639282011-12-22 21:12:2793#include "ui/gfx/size.h"
[email protected]f1d5c3a2013-04-23 17:42:5694#include "ui/keyboard/keyboard.h"
[email protected]b6ba05d902013-10-04 21:38:4595#include "ui/keyboard/keyboard_controller.h"
[email protected]f1d5c3a2013-04-23 17:42:5696#include "ui/keyboard/keyboard_util.h"
[email protected]8393aa62013-01-23 19:40:1097#include "ui/message_center/message_center.h"
[email protected]4a59e4e2012-11-12 21:15:4098#include "ui/views/corewm/compound_event_filter.h"
[email protected]39718b52012-12-03 17:24:5699#include "ui/views/corewm/corewm_switches.h"
100#include "ui/views/corewm/focus_controller.h"
[email protected]4a59e4e2012-11-12 21:15:40101#include "ui/views/corewm/input_method_event_filter.h"
[email protected]86f2b5e2012-11-14 20:37:00102#include "ui/views/corewm/shadow_controller.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]b5756e22012-11-30 01:32:02105#include "ui/views/corewm/visibility_controller.h"
[email protected]0c2dc012012-12-02 00:00:23106#include "ui/views/corewm/window_modality_controller.h"
[email protected]e7293fa2012-05-17 04:42:33107#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:58108#include "ui/views/widget/native_widget_aura.h"
109#include "ui/views/widget/widget.h"
[email protected]87b0d82e2011-10-07 21:02:59110
[email protected]37ce571b2013-06-28 05:28:45111#if defined(OS_CHROMEOS)
112#if defined(USE_X11)
[email protected]44d444c2013-01-30 01:47:44113#include "ash/ash_constants.h"
[email protected]c1234a42013-08-20 09:35:40114#include "ash/display/display_change_observer_chromeos.h"
115#include "ash/display/display_error_observer_chromeos.h"
[email protected]196e9452012-08-01 06:42:51116#include "ash/display/output_configurator_animation.h"
[email protected]bb99d702013-09-07 03:21:04117#include "base/message_loop/message_pump_x11.h"
[email protected]49c4cf852013-09-27 19:28:24118#include "base/sys_info.h"
[email protected]2e236a52012-06-27 22:21:47119#include "chromeos/display/output_configurator.h"
[email protected]7158db12012-10-15 22:19:31120#include "content/public/browser/gpu_data_manager.h"
[email protected]d7b5cc72013-05-23 20:05:00121#include "gpu/config/gpu_feature_type.h"
[email protected]37ce571b2013-06-28 05:28:45122#endif // defined(USE_X11)
[email protected]25cae452013-09-26 10:15:03123#include "ash/system/chromeos/brightness/brightness_controller_chromeos.h"
[email protected]37ce571b2013-06-28 05:28:45124#include "ash/system/chromeos/power/power_status.h"
[email protected]ded58fd2013-10-09 07:56:55125#include "ash/system/chromeos/power/suspend_observer.h"
126#include "ash/system/chromeos/power/user_activity_notifier.h"
127#include "ash/system/chromeos/power/video_activity_notifier.h"
[email protected]70b3e7d52012-06-02 22:12:25128#endif // defined(OS_CHROMEOS)
129
[email protected]55f593352011-12-24 05:42:46130namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59131
132namespace {
[email protected]671a2ae2011-10-13 21:53:23133
[email protected]615922f2012-02-07 02:41:15134using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45135using views::Widget;
136
[email protected]b5756e22012-11-30 01:32:02137// A Corewm VisibilityController subclass that calls the Ash animation routine
138// so we can pick up our extended animations. See ash/wm/window_animations.h.
139class AshVisibilityController : public views::corewm::VisibilityController {
140 public:
141 AshVisibilityController() {}
142 virtual ~AshVisibilityController() {}
143
144 private:
145 // Overridden from views::corewm::VisibilityController:
146 virtual bool CallAnimateOnChildWindowVisibilityChanged(
147 aura::Window* window,
148 bool visible) OVERRIDE {
149 return AnimateOnChildWindowVisibilityChanged(window, visible);
150 }
151
152 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
153};
154
[email protected]87b0d82e2011-10-07 21:02:59155} // namespace
156
[email protected]cac10fc62011-10-07 23:22:56157// static
158Shell* Shell::instance_ = NULL;
[email protected]2b4cd302012-02-24 20:21:13159// static
[email protected]9488d4d2012-02-29 18:32:37160bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13161
162////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56163// Shell, public:
164
[email protected]cac10fc62011-10-07 23:22:56165// static
[email protected]3266c2b92011-11-14 00:06:08166Shell* Shell::CreateInstance(ShellDelegate* delegate) {
167 CHECK(!instance_);
168 instance_ = new Shell(delegate);
169 instance_->Init();
170 return instance_;
171}
172
173// static
[email protected]cac10fc62011-10-07 23:22:56174Shell* Shell::GetInstance() {
[email protected]3266c2b92011-11-14 00:06:08175 DCHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56176 return instance_;
177}
178
[email protected]6377a002011-11-10 20:26:47179// static
[email protected]b3b7bcd2012-03-06 19:35:45180bool Shell::HasInstance() {
181 return !!instance_;
182}
183
184// static
[email protected]ef589af2011-12-03 01:07:15185void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47186 delete instance_;
187 instance_ = NULL;
188}
189
[email protected]e73bd7802012-02-17 20:10:34190// static
[email protected]d90b8392012-06-13 09:34:56191internal::RootWindowController* Shell::GetPrimaryRootWindowController() {
[email protected]6b2d4a0b2013-09-06 06:29:54192 return internal::GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23193}
194
195// static
196Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
[email protected]2e236a52012-06-27 22:21:47197 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23198 GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56199}
200
201// static
[email protected]42713f72012-05-25 00:41:50202aura::RootWindow* Shell::GetPrimaryRootWindow() {
[email protected]2e236a52012-06-27 22:21:47203 return GetInstance()->display_controller()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34204}
205
[email protected]7b0f7502012-06-11 00:12:39206// static
[email protected]d17642d2013-09-12 23:44:38207aura::RootWindow* Shell::GetTargetRootWindow() {
[email protected]b42910f2013-08-01 11:45:29208 Shell* shell = GetInstance();
209 if (shell->scoped_target_root_window_)
210 return shell->scoped_target_root_window_;
211 return shell->target_root_window_;
[email protected]a857dbe2012-05-30 22:10:14212}
213
[email protected]7b0f7502012-06-11 00:12:39214// static
[email protected]ffabb1e2012-10-12 19:51:17215gfx::Screen* Shell::GetScreen() {
[email protected]5fdb45b2012-10-23 20:26:28216 return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
[email protected]ffabb1e2012-10-12 19:51:17217}
218
219// static
[email protected]be65be362012-06-15 07:38:23220Shell::RootWindowList Shell::GetAllRootWindows() {
[email protected]2e236a52012-06-27 22:21:47221 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23222 GetAllRootWindows();
223}
224
225// static
[email protected]7b0f7502012-06-11 00:12:39226aura::Window* Shell::GetContainer(aura::RootWindow* root_window,
227 int container_id) {
228 return root_window->GetChildById(container_id);
229}
230
231// static
[email protected]e67291f12012-10-10 05:52:38232const aura::Window* Shell::GetContainer(const aura::RootWindow* root_window,
233 int container_id) {
234 return root_window->GetChildById(container_id);
235}
236
237// static
[email protected]429433f2012-12-28 20:14:46238std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
239 int container_id,
240 aura::RootWindow* priority_root) {
[email protected]7b0f7502012-06-11 00:12:39241 std::vector<aura::Window*> containers;
[email protected]001272f2012-11-02 20:05:23242 RootWindowList root_windows = GetAllRootWindows();
243 for (RootWindowList::const_iterator it = root_windows.begin();
244 it != root_windows.end(); ++it) {
245 aura::Window* container = (*it)->GetChildById(container_id);
[email protected]429433f2012-12-28 20:14:46246 if (container) {
247 if (priority_root && priority_root->Contains(container))
248 containers.insert(containers.begin(), container);
249 else
250 containers.push_back(container);
251 }
[email protected]001272f2012-11-02 20:05:23252 }
[email protected]7b0f7502012-06-11 00:12:39253 return containers;
254}
255
[email protected]940fb1c2013-06-18 16:54:28256void Shell::ShowContextMenu(const gfx::Point& location_in_screen,
257 ui::MenuSourceType source_type) {
[email protected]fcb123d2013-04-17 15:58:49258 // No context menus if there is no session with an active user.
[email protected]c8d19f82013-05-18 09:09:41259 if (!session_state_delegate_->NumberOfLoggedInUsers())
[email protected]f60c6232012-08-24 18:55:03260 return;
261 // No context menus when screen is locked.
[email protected]fcb123d2013-04-17 15:58:49262 if (session_state_delegate_->IsScreenLocked())
[email protected]f60c6232012-08-24 18:55:03263 return;
[email protected]431552c2012-10-23 00:38:33264
[email protected]88d71122012-10-18 07:11:01265 aura::RootWindow* root =
[email protected]431552c2012-10-23 00:38:33266 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()));
[email protected]43dcd352012-12-18 02:28:46267 // TODO(oshima): The root and root window controller shouldn't be
268 // NULL even for the out-of-bounds |location_in_screen| (It should
269 // return the primary root). Investigate why/how this is
270 // happening. crbug.com/165214.
[email protected]6b2d4a0b2013-09-06 06:29:54271 internal::RootWindowController* rwc = internal::GetRootWindowController(root);
[email protected]bd4814b2012-12-27 01:16:00272 CHECK(rwc) << "root=" << root
273 << ", location:" << location_in_screen.ToString();
[email protected]43dcd352012-12-18 02:28:46274 if (rwc)
[email protected]940fb1c2013-06-18 16:54:28275 rwc->ShowContextMenu(location_in_screen, source_type);
[email protected]46ca3632011-11-03 03:33:42276}
277
[email protected]b913a3a2012-12-11 13:07:19278void Shell::ToggleAppList(aura::Window* window) {
[email protected]d17642d2013-09-12 23:44:38279 // If the context window is not given, show it on the target root window.
[email protected]ec67bc8a2013-05-06 17:44:42280 if (!window)
[email protected]d17642d2013-09-12 23:44:38281 window = GetTargetRootWindow();
[email protected]ec67bc8a2013-05-06 17:44:42282 if (!app_list_controller_)
283 app_list_controller_.reset(new internal::AppListController);
284 app_list_controller_->SetVisible(!app_list_controller_->IsVisible(), window);
[email protected]ae4987d2011-11-21 22:52:44285}
286
[email protected]7510d1082012-03-30 21:58:34287bool Shell::GetAppListTargetVisibility() const {
[email protected]ec67bc8a2013-05-06 17:44:42288 return app_list_controller_.get() &&
289 app_list_controller_->GetTargetVisibility();
[email protected]7510d1082012-03-30 21:58:34290}
291
[email protected]1e51a9d2012-04-09 23:31:11292aura::Window* Shell::GetAppListWindow() {
[email protected]ec67bc8a2013-05-06 17:44:42293 return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
[email protected]1e51a9d2012-04-09 23:31:11294}
295
[email protected]dc09739372012-11-15 20:17:39296bool Shell::IsSystemModalWindowOpen() const {
[email protected]852a55d2012-10-17 13:30:30297 if (simulate_modal_window_open_for_testing_)
298 return true;
[email protected]429433f2012-12-28 20:14:46299 const std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
300 internal::kShellWindowId_SystemModalContainer, NULL);
[email protected]001272f2012-11-02 20:05:23301 for (std::vector<aura::Window*>::const_iterator cit = containers.begin();
302 cit != containers.end(); ++cit) {
303 for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin();
304 wit != (*cit)->children().end(); ++wit) {
305 if ((*wit)->GetProperty(aura::client::kModalKey) ==
306 ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) {
307 return true;
308 }
309 }
310 }
311 return false;
[email protected]40c4cbb2012-01-10 23:26:07312}
313
[email protected]57b8bb352012-01-11 05:11:46314views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
315 views::Widget* widget) {
[email protected]c73d1332012-03-08 17:11:04316 // Use translucent-style window frames for dialogs.
[email protected]95c6cc42012-03-08 20:53:15317 CustomFrameViewAsh* frame_view = new CustomFrameViewAsh;
[email protected]c73d1332012-03-08 17:11:04318 frame_view->Init(widget);
319 return frame_view;
[email protected]57b8bb352012-01-11 05:11:46320}
321
[email protected]3d29912a2012-02-07 07:41:51322void Shell::RotateFocus(Direction direction) {
323 focus_cycler_->RotateFocus(
324 direction == FORWARD ? internal::FocusCycler::FORWARD :
325 internal::FocusCycler::BACKWARD);
326}
327
[email protected]2e236a52012-06-27 22:21:47328void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44329 const gfx::Insets& insets) {
[email protected]b8984242013-07-12 07:55:38330 if (!display_controller_->UpdateWorkAreaOfDisplayNearestWindow(
331 contains, insets)) {
[email protected]1a2145b2012-03-13 21:09:17332 return;
[email protected]b8984242013-07-12 07:55:38333 }
[email protected]1a2145b2012-03-13 21:09:17334 FOR_EACH_OBSERVER(ShellObserver, observers_,
[email protected]2e236a52012-06-27 22:21:47335 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17336}
337
[email protected]82d3954ae2012-04-20 09:02:22338void Shell::OnLoginStateChanged(user::LoginStatus status) {
[email protected]b6ba05d902013-10-04 21:38:45339 if (status != user::LOGGED_IN_NONE) {
340 // TODO(bshe): Primary root window controller may not be the controller to
341 // attach virtual keyboard. See http://crbug.com/303429
342 InitKeyboard(GetPrimaryRootWindowController());
343 }
[email protected]82d3954ae2012-04-20 09:02:22344 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
345}
346
[email protected]88d71122012-10-18 07:11:01347void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50348 RootWindowControllerList controllers = GetAllRootWindowControllers();
349 for (RootWindowControllerList::iterator iter = controllers.begin();
350 iter != controllers.end(); ++iter)
351 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01352}
353
[email protected]82d3954ae2012-04-20 09:02:22354void Shell::OnAppTerminating() {
355 FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
356}
357
358void Shell::OnLockStateChanged(bool locked) {
359 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
[email protected]ae298142013-08-10 15:30:29360#ifndef NDEBUG
361 // Make sure that there is no system modal in Lock layer when unlocked.
362 if (!locked) {
363 std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
364 internal::kShellWindowId_LockSystemModalContainer,
365 GetPrimaryRootWindow());
366 for (std::vector<aura::Window*>::const_iterator iter = containers.begin();
367 iter != containers.end(); ++iter) {
368 DCHECK_EQ(0u, (*iter)->children().size());
369 }
370 }
371#endif
[email protected]82d3954ae2012-04-20 09:02:22372}
373
[email protected]d9456cb2012-03-21 16:41:04374void Shell::CreateLauncher() {
[email protected]8c0ec432013-05-10 04:33:39375 RootWindowControllerList controllers = GetAllRootWindowControllers();
376 for (RootWindowControllerList::iterator iter = controllers.begin();
377 iter != controllers.end(); ++iter)
378 (*iter)->shelf()->CreateLauncher();
[email protected]d9456cb2012-03-21 16:41:04379}
380
[email protected]7e1df2f62012-07-19 19:17:18381void Shell::ShowLauncher() {
[email protected]8c0ec432013-05-10 04:33:39382 RootWindowControllerList controllers = GetAllRootWindowControllers();
383 for (RootWindowControllerList::iterator iter = controllers.begin();
384 iter != controllers.end(); ++iter)
385 (*iter)->ShowLauncher();
[email protected]7e1df2f62012-07-19 19:17:18386}
387
[email protected]1a2145b2012-03-13 21:09:17388void Shell::AddShellObserver(ShellObserver* observer) {
389 observers_.AddObserver(observer);
390}
391
392void Shell::RemoveShellObserver(ShellObserver* observer) {
393 observers_.RemoveObserver(observer);
394}
395
[email protected]c758fbf2012-03-25 22:53:59396void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33397 RootWindowControllerList controllers = GetAllRootWindowControllers();
398 for (RootWindowControllerList::iterator iter = controllers.begin();
399 iter != controllers.end(); ++iter)
400 if ((*iter)->shelf())
401 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59402}
403
[email protected]431552c2012-10-23 00:38:33404void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
405 aura::RootWindow* root_window) {
[email protected]478c6c32013-03-09 02:50:58406 ash::internal::ShelfLayoutManager::ForLauncher(root_window)->
407 SetAutoHideBehavior(behavior);
[email protected]c758fbf2012-03-25 22:53:59408}
409
[email protected]431552c2012-10-23 00:38:33410ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
411 aura::RootWindow* root_window) const {
[email protected]478c6c32013-03-09 02:50:58412 return ash::internal::ShelfLayoutManager::ForLauncher(root_window)->
413 auto_hide_behavior();
[email protected]c758fbf2012-03-25 22:53:59414}
415
[email protected]431552c2012-10-23 00:38:33416void Shell::SetShelfAlignment(ShelfAlignment alignment,
417 aura::RootWindow* root_window) {
[email protected]478c6c32013-03-09 02:50:58418 if (ash::internal::ShelfLayoutManager::ForLauncher(root_window)->
419 SetAlignment(alignment)) {
[email protected]f89f7512012-12-17 19:21:18420 FOR_EACH_OBSERVER(
421 ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
422 }
[email protected]55444502012-05-10 15:43:53423}
424
[email protected]431552c2012-10-23 00:38:33425ShelfAlignment Shell::GetShelfAlignment(aura::RootWindow* root_window) {
[email protected]6b2d4a0b2013-09-06 06:29:54426 return internal::GetRootWindowController(root_window)->
[email protected]478c6c32013-03-09 02:50:58427 GetShelfLayoutManager()->GetAlignment();
[email protected]55444502012-05-10 15:43:53428}
429
[email protected]d90b8392012-06-13 09:34:56430void Shell::SetDimming(bool should_dim) {
[email protected]be65be362012-06-15 07:38:23431 RootWindowControllerList controllers = GetAllRootWindowControllers();
432 for (RootWindowControllerList::iterator iter = controllers.begin();
433 iter != controllers.end(); ++iter)
434 (*iter)->screen_dimmer()->SetDimming(should_dim);
[email protected]d90b8392012-06-13 09:34:56435}
436
[email protected]375069e2013-10-04 13:54:31437void Shell::NotifyFullscreenStateChange(bool is_fullscreen,
438 aura::RootWindow* root_window) {
439 FOR_EACH_OBSERVER(ShellObserver, observers_, OnFullscreenStateChanged(
440 is_fullscreen, root_window));
441}
442
[email protected]090c4f12012-10-29 18:56:42443void Shell::CreateModalBackground(aura::Window* window) {
[email protected]7f7f65c2013-04-17 16:47:13444 if (!modality_filter_) {
[email protected]c0ce80e2012-10-05 23:28:27445 modality_filter_.reset(new internal::SystemModalContainerEventFilter(this));
[email protected]304594c2012-11-13 16:35:27446 AddPreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27447 }
448 RootWindowControllerList controllers = GetAllRootWindowControllers();
449 for (RootWindowControllerList::iterator iter = controllers.begin();
450 iter != controllers.end(); ++iter)
[email protected]090c4f12012-10-29 18:56:42451 (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27452}
453
454void Shell::OnModalWindowRemoved(aura::Window* removed) {
455 RootWindowControllerList controllers = GetAllRootWindowControllers();
456 bool activated = false;
457 for (RootWindowControllerList::iterator iter = controllers.begin();
458 iter != controllers.end() && !activated; ++iter) {
[email protected]8674b312012-10-12 19:02:44459 activated = (*iter)->GetSystemModalLayoutManager(removed)->
460 ActivateNextModalWindow();
[email protected]c0ce80e2012-10-05 23:28:27461 }
462 if (!activated) {
[email protected]304594c2012-11-13 16:35:27463 RemovePreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27464 modality_filter_.reset();
465 for (RootWindowControllerList::iterator iter = controllers.begin();
466 iter != controllers.end(); ++iter)
[email protected]8674b312012-10-12 19:02:44467 (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27468 }
469}
470
[email protected]88d71122012-10-18 07:11:01471WebNotificationTray* Shell::GetWebNotificationTray() {
[email protected]478c6c32013-03-09 02:50:58472 return GetPrimaryRootWindowController()->shelf()->
473 status_area_widget()->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28474}
475
[email protected]a0afeb12012-12-10 22:57:09476bool Shell::HasPrimaryStatusArea() {
[email protected]478c6c32013-03-09 02:50:58477 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf();
478 return shelf && shelf->status_area_widget();
[email protected]31f19e32012-10-30 22:31:23479}
480
[email protected]a0afeb12012-12-10 22:57:09481SystemTray* Shell::GetPrimarySystemTray() {
482 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42483}
484
[email protected]b913a3a2012-12-11 13:07:19485LauncherDelegate* Shell::GetLauncherDelegate() {
[email protected]7f7f65c2013-04-17 16:47:13486 if (!launcher_delegate_) {
[email protected]c72ed9802013-10-02 20:22:05487 // Creates LauncherItemDelegateManager before LauncherDelegate.
[email protected]f5316f1b2013-10-02 22:14:03488 launcher_item_delegate_manager_.reset(new LauncherItemDelegateManager);
489 launcher_model_.reset(new LauncherModel);
[email protected]b913a3a2012-12-11 13:07:19490 launcher_delegate_.reset(
491 delegate_->CreateLauncherDelegate(launcher_model_.get()));
[email protected]f5316f1b2013-10-02 22:14:03492 app_list_shelf_item_delegate_.reset(
[email protected]976624f2013-09-19 21:58:49493 new internal::AppListShelfItemDelegate);
[email protected]b913a3a2012-12-11 13:07:19494 }
495 return launcher_delegate_.get();
496}
497
[email protected]2b8a9bb2013-07-01 22:43:40498void Shell::SetTouchHudProjectionEnabled(bool enabled) {
499 if (is_touch_hud_projection_enabled_ == enabled)
500 return;
501
[email protected]2b8a9bb2013-07-01 22:43:40502 is_touch_hud_projection_enabled_ = enabled;
[email protected]d141b922013-07-09 08:13:17503 FOR_EACH_OBSERVER(ShellObserver, observers_,
504 OnTouchHudProjectionToggled(enabled));
[email protected]2b8a9bb2013-07-01 22:43:40505}
506
[email protected]2e236a52012-06-27 22:21:47507void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) {
[email protected]cf1c70e2012-08-30 01:13:02508 internal::RootWindowController* controller =
509 new internal::RootWindowController(root);
[email protected]bca9a7e2012-11-10 06:25:49510 // Pass false for the |is_first_run_after_boot| parameter so we'll show a
511 // black background on this display instead of trying to mimic the boot splash
512 // screen.
[email protected]756bda12013-07-03 08:17:06513 InitRootWindowController(controller, false);
514
[email protected]cf1c70e2012-08-30 01:13:02515 controller->root_window_layout()->OnWindowResized();
516 desktop_background_controller_->OnRootWindowAdded(root);
[email protected]6b37addd2012-09-28 03:08:09517 high_contrast_controller_->OnRootWindowAdded(root);
[email protected]cf1c70e2012-08-30 01:13:02518 root->ShowRootWindow();
519 // Activate new root for testing.
[email protected]b42910f2013-08-01 11:45:29520 // TODO(oshima): remove this.
521 target_root_window_ = root;
[email protected]ad2f5df2013-07-02 08:21:56522
523 // Create a launcher if a user is already logged.
524 if (Shell::GetInstance()->session_state_delegate()->NumberOfLoggedInUsers())
525 controller->shelf()->CreateLauncher();
[email protected]a857dbe2012-05-30 22:10:14526}
527
[email protected]f9466702012-09-17 16:35:27528void Shell::DoInitialWorkspaceAnimation() {
529 return GetPrimaryRootWindowController()->workspace_controller()->
530 DoInitialAnimation();
531}
532
[email protected]b6ba05d902013-10-04 21:38:45533////////////////////////////////////////////////////////////////////////////////
534// Shell, private:
535
536Shell::Shell(ShellDelegate* delegate)
537 : screen_(new ScreenAsh),
538 target_root_window_(NULL),
539 scoped_target_root_window_(NULL),
540 delegate_(delegate),
541 window_positioner_(new WindowPositioner),
542 activation_client_(NULL),
543#if defined(OS_CHROMEOS) && defined(USE_X11)
544 output_configurator_(new chromeos::OutputConfigurator()),
[email protected]ded58fd2013-10-09 07:56:55545#endif // defined(OS_CHROMEOS) && defined(USE_X11)
[email protected]b6ba05d902013-10-04 21:38:45546 native_cursor_manager_(new AshNativeCursorManager),
547 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>(
548 native_cursor_manager_)),
549 browser_context_(NULL),
550 simulate_modal_window_open_for_testing_(false),
551 is_touch_hud_projection_enabled_(false) {
552 DCHECK(delegate_.get());
553 display_manager_.reset(new internal::DisplayManager);
554
555 ANNOTATE_LEAKING_OBJECT_PTR(screen_); // see crbug.com/156466
556 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_);
557 if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE))
558 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_);
559 display_controller_.reset(new DisplayController);
560#if defined(OS_CHROMEOS) && defined(USE_X11)
561 bool is_panel_fitting_disabled =
562 content::GpuDataManager::GetInstance()->IsFeatureBlacklisted(
563 gpu::GPU_FEATURE_TYPE_PANEL_FITTING);
564
565 output_configurator_->Init(!is_panel_fitting_disabled);
566
567 base::MessagePumpX11::Current()->AddDispatcherForRootWindow(
568 output_configurator());
569 // We can't do this with a root window listener because XI_HierarchyChanged
570 // messages don't have a target window.
571 base::MessagePumpX11::Current()->AddObserver(output_configurator());
572#endif // defined(OS_CHROMEOS)
573
574#if defined(OS_CHROMEOS)
575 internal::PowerStatus::Initialize();
576#endif
577}
578
579Shell::~Shell() {
580 TRACE_EVENT0("shutdown", "ash::Shell::Destructor");
581
582 views::FocusManagerFactory::Install(NULL);
583
584 // Remove the focus from any window. This will prevent overhead and side
585 // effects (e.g. crashes) from changing focus during shutdown.
586 // See bug crbug.com/134502.
587 aura::client::GetFocusClient(GetPrimaryRootWindow())->FocusWindow(NULL);
588
589 // Please keep in same order as in Init() because it's easy to miss one.
590 if (window_modality_controller_)
591 window_modality_controller_.reset();
592 RemovePreTargetHandler(event_rewriter_filter_.get());
593 RemovePreTargetHandler(user_activity_detector_.get());
594 RemovePreTargetHandler(overlay_filter_.get());
595 RemovePreTargetHandler(input_method_filter_.get());
596 if (mouse_cursor_filter_)
597 RemovePreTargetHandler(mouse_cursor_filter_.get());
598 RemovePreTargetHandler(system_gesture_filter_.get());
599 RemovePreTargetHandler(keyboard_metrics_filter_.get());
600 RemovePreTargetHandler(event_transformation_handler_.get());
601 RemovePreTargetHandler(accelerator_filter_.get());
602
603 // TooltipController is deleted with the Shell so removing its references.
604 RemovePreTargetHandler(tooltip_controller_.get());
605
606 // AppList needs to be released before shelf layout manager, which is
607 // destroyed with launcher container in the loop below. However, app list
608 // container is now on top of launcher container and released after it.
609 // TODO(xiyuan): Move it back when app list container is no longer needed.
610 app_list_controller_.reset();
611
612 // Destroy SystemTrayDelegate before destroying the status area(s).
613 system_tray_delegate_->Shutdown();
614 system_tray_delegate_.reset();
615
616 locale_notification_controller_.reset();
617
618 // Drag-and-drop must be canceled prior to close all windows.
619 drag_drop_controller_.reset();
620
621 // Destroy all child windows including widgets.
622 display_controller_->CloseChildWindows();
623
624 // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
625 // needs to remove observers from it.
626 system_tray_notifier_.reset();
627
[email protected]ded58fd2013-10-09 07:56:55628#if defined(OS_CHROMEOS)
629 // Destroy VideoActivityNotifier before destroying VideoDetector.
630 video_activity_notifier_.reset();
631#endif // defined(OS_CHROMEOS)
632
[email protected]b6ba05d902013-10-04 21:38:45633 // These need a valid Shell instance to clean up properly, so explicitly
634 // delete them before invalidating the instance.
635 // Alphabetical. TODO(oshima): sort.
636 magnification_controller_.reset();
637 partial_magnification_controller_.reset();
638 resize_shadow_controller_.reset();
639 shadow_controller_.reset();
640 tooltip_controller_.reset();
641 event_client_.reset();
642 window_cycle_controller_.reset();
643 nested_dispatcher_controller_.reset();
644 user_action_client_.reset();
645 visibility_controller_.reset();
646 launcher_delegate_.reset();
647 launcher_model_.reset();
648 video_detector_.reset();
649
650 power_button_controller_.reset();
651 lock_state_controller_.reset();
652 mru_window_tracker_.reset();
653
654 resolution_notification_controller_.reset();
655 desktop_background_controller_.reset();
656
657 // This also deletes all RootWindows. Note that we invoke Shutdown() on
658 // DisplayController before resetting |display_controller_|, since destruction
659 // of its owned RootWindowControllers relies on the value.
660 display_controller_->Shutdown();
661 display_controller_.reset();
662 screen_position_controller_.reset();
663
664 keyboard_controller_.reset();
665
666#if defined(OS_CHROMEOS) && defined(USE_X11)
667 if (display_change_observer_)
668 output_configurator_->RemoveObserver(display_change_observer_.get());
669 if (output_configurator_animation_)
670 output_configurator_->RemoveObserver(output_configurator_animation_.get());
671 if (display_error_observer_)
672 output_configurator_->RemoveObserver(display_error_observer_.get());
673 base::MessagePumpX11::Current()->RemoveDispatcherForRootWindow(
674 output_configurator());
675 base::MessagePumpX11::Current()->RemoveObserver(output_configurator());
676 display_change_observer_.reset();
677#endif // defined(OS_CHROMEOS)
678
679#if defined(OS_CHROMEOS)
680 internal::PowerStatus::Shutdown();
681#endif
682
683 DCHECK(instance_ == this);
684 instance_ = NULL;
685}
686
687void Shell::Init() {
688 CommandLine* command_line = CommandLine::ForCurrentProcess();
689
690 delegate_->PreInit();
691 bool display_initialized = false;
692#if defined(OS_CHROMEOS) && defined(USE_X11)
693 output_configurator_animation_.reset(
694 new internal::OutputConfiguratorAnimation());
695 output_configurator_->AddObserver(output_configurator_animation_.get());
696 if (base::SysInfo::IsRunningOnChromeOS()) {
697 display_change_observer_.reset(new internal::DisplayChangeObserver);
698 // Register |display_change_observer_| first so that the rest of
699 // observer gets invoked after the root windows are configured.
700 output_configurator_->AddObserver(display_change_observer_.get());
701 display_error_observer_.reset(new internal::DisplayErrorObserver());
702 output_configurator_->AddObserver(display_error_observer_.get());
703 output_configurator_->set_state_controller(display_change_observer_.get());
704 if (!command_line->HasSwitch(ash::switches::kAshDisableSoftwareMirroring))
705 output_configurator_->set_mirroring_controller(display_manager_.get());
706 output_configurator_->Start(
707 delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
708 display_initialized = true;
709 }
710#endif // defined(OS_CHROMEOS) && defined(USE_X11)
711 if (!display_initialized)
712 display_manager_->InitFromCommandLine();
713
714 // Install the custom factory first so that views::FocusManagers for Tray,
715 // Launcher, and WallPaper could be created by the factory.
716 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
717
718 // The WindowModalityController needs to be at the front of the input event
719 // pretarget handler list to ensure that it processes input events when modal
720 // windows are active.
721 window_modality_controller_.reset(
722 new views::corewm::WindowModalityController(this));
723
724 AddPreTargetHandler(this);
725
726 env_filter_.reset(new views::corewm::CompoundEventFilter);
727 AddPreTargetHandler(env_filter_.get());
728
729 // Env creates the compositor. Historically it seems to have been implicitly
730 // initialized first by the ActivationController, but now that FocusController
731 // no longer does this we need to do it explicitly.
732 aura::Env::GetInstance();
733 views::corewm::FocusController* focus_controller =
734 new views::corewm::FocusController(new wm::AshFocusRules);
735 focus_client_.reset(focus_controller);
736 activation_client_ = focus_controller;
737 activation_client_->AddObserver(this);
738 focus_cycler_.reset(new internal::FocusCycler());
739
740 screen_position_controller_.reset(new internal::ScreenPositionController);
741 root_window_host_factory_.reset(delegate_->CreateRootWindowHostFactory());
742
743 display_controller_->Start();
744 display_controller_->InitPrimaryDisplay();
745 aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow();
746 target_root_window_ = root_window;
747
748 resolution_notification_controller_.reset(
749 new internal::ResolutionNotificationController);
750
751 cursor_manager_.SetDisplay(DisplayController::GetPrimaryDisplay());
752
753 nested_dispatcher_controller_.reset(new NestedDispatcherController);
754 accelerator_controller_.reset(new AcceleratorController);
755
756 // The order in which event filters are added is significant.
757 event_rewriter_filter_.reset(new internal::EventRewriterEventFilter);
758 AddPreTargetHandler(event_rewriter_filter_.get());
759
760 // UserActivityDetector passes events to observers, so let them get
761 // rewritten first.
762 user_activity_detector_.reset(new UserActivityDetector);
763 AddPreTargetHandler(user_activity_detector_.get());
764
765 overlay_filter_.reset(new internal::OverlayEventFilter);
766 AddPreTargetHandler(overlay_filter_.get());
767 AddShellObserver(overlay_filter_.get());
768
769 input_method_filter_.reset(new views::corewm::InputMethodEventFilter(
770 root_window->GetAcceleratedWidget()));
771 AddPreTargetHandler(input_method_filter_.get());
772
773 accelerator_filter_.reset(new internal::AcceleratorFilter);
774 AddPreTargetHandler(accelerator_filter_.get());
775
776 event_transformation_handler_.reset(new internal::EventTransformationHandler);
777 AddPreTargetHandler(event_transformation_handler_.get());
778
779 system_gesture_filter_.reset(new internal::SystemGestureEventFilter);
780 AddPreTargetHandler(system_gesture_filter_.get());
781
782 keyboard_metrics_filter_.reset(new internal::KeyboardUMAEventFilter);
783 AddPreTargetHandler(keyboard_metrics_filter_.get());
784
785 // The keyboard system must be initialized before the RootWindowController is
786 // created.
787 if (keyboard::IsKeyboardEnabled())
788 keyboard::InitializeKeyboard();
789
790 lock_state_controller_.reset(new LockStateController);
791 power_button_controller_.reset(new PowerButtonController(
792 lock_state_controller_.get()));
793 AddShellObserver(lock_state_controller_.get());
794
795 drag_drop_controller_.reset(new internal::DragDropController);
796 mouse_cursor_filter_.reset(new internal::MouseCursorEventFilter());
797 PrependPreTargetHandler(mouse_cursor_filter_.get());
798
799 // Create Controllers that may need root window.
800 // TODO(oshima): Move as many controllers before creating
801 // RootWindowController as possible.
802 visibility_controller_.reset(new AshVisibilityController);
803 user_action_client_.reset(delegate_->CreateUserActionClient());
804
805 magnification_controller_.reset(
806 MagnificationController::CreateInstance());
807 mru_window_tracker_.reset(new MruWindowTracker(activation_client_));
808
809 partial_magnification_controller_.reset(
810 new PartialMagnificationController());
811
812 high_contrast_controller_.reset(new HighContrastController);
813 video_detector_.reset(new VideoDetector);
814 window_cycle_controller_.reset(new WindowCycleController());
815 window_selector_controller_.reset(new WindowSelectorController());
816
[email protected]d7f30a72013-10-05 05:09:41817 tooltip_controller_.reset(
818 new views::corewm::TooltipController(
819 scoped_ptr<views::corewm::Tooltip>(
820 new views::corewm::TooltipAura(gfx::SCREEN_TYPE_ALTERNATE))));
[email protected]b6ba05d902013-10-04 21:38:45821 AddPreTargetHandler(tooltip_controller_.get());
822
823 event_client_.reset(new internal::EventClientImpl);
824
825 // This controller needs to be set before SetupManagedWindowMode.
826 desktop_background_controller_.reset(new DesktopBackgroundController());
827 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
828
829 // StatusAreaWidget uses Shell's CapsLockDelegate.
830 caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());
831
832 session_state_delegate_.reset(delegate_->CreateSessionStateDelegate());
833
834 if (!command_line->HasSwitch(views::corewm::switches::kNoDropShadows)) {
835 resize_shadow_controller_.reset(new internal::ResizeShadowController());
836 shadow_controller_.reset(
837 new views::corewm::ShadowController(activation_client_));
838 }
839
840 // Create system_tray_notifier_ before the delegate.
841 system_tray_notifier_.reset(new ash::SystemTrayNotifier());
842
843 // Initialize system_tray_delegate_ before initializing StatusAreaWidget.
844 system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate());
845 DCHECK(system_tray_delegate_.get());
846
847 internal::RootWindowController* root_window_controller =
848 new internal::RootWindowController(root_window);
849 InitRootWindowController(root_window_controller,
850 delegate_->IsFirstRunAfterBoot());
851 InitKeyboard(root_window_controller);
852
853 locale_notification_controller_.reset(
854 new internal::LocaleNotificationController);
855
856 // Initialize system_tray_delegate_ after StatusAreaWidget is created.
857 system_tray_delegate_->Initialize();
858
859 display_controller_->InitSecondaryDisplays();
860
861 // Force Layout
862 root_window_controller->root_window_layout()->OnWindowResized();
863
864 // It needs to be created after OnWindowResized has been called, otherwise the
865 // widget will not paint when restoring after a browser crash. Also it needs
866 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
867 // the correct size.
868 user_wallpaper_delegate_->InitializeWallpaper();
869
870 if (initially_hide_cursor_)
871 cursor_manager_.HideCursor();
872 cursor_manager_.SetCursor(ui::kCursorPointer);
873
874 if (!cursor_manager_.IsCursorVisible()) {
875 // Cursor might have been hidden by something other than chrome.
876 // Let the first mouse event show the cursor.
877 env_filter_->set_cursor_hidden_by_filter(true);
878 }
879
[email protected]5c04d3a92013-10-08 19:17:19880#if defined(OS_CHROMEOS)
[email protected]ded58fd2013-10-09 07:56:55881 // Set accelerator controller delegates.
[email protected]b6ba05d902013-10-04 21:38:45882 accelerator_controller_->SetBrightnessControlDelegate(
883 scoped_ptr<ash::BrightnessControlDelegate>(
884 new ash::system::BrightnessControllerChromeos).Pass());
[email protected]ded58fd2013-10-09 07:56:55885
886 suspend_observer_.reset(new internal::SuspendObserver());
887 user_activity_notifier_.reset(
888 new internal::UserActivityNotifier(user_activity_detector_.get()));
889 video_activity_notifier_.reset(
890 new internal::VideoActivityNotifier(video_detector_.get()));
[email protected]b6ba05d902013-10-04 21:38:45891#endif
892
893 // The compositor thread and main message loop have to be running in
894 // order to create mirror window. Run it after the main message loop
895 // is started.
896 base::MessageLoopForUI::current()->PostTask(
897 FROM_HERE,
898 base::Bind(&internal::DisplayManager::CreateMirrorWindowIfAny,
899 base::Unretained(display_manager_.get())));
900}
901
902void Shell::InitKeyboard(internal::RootWindowController* root) {
903 if (keyboard::IsKeyboardEnabled()) {
904 if (keyboard_controller_.get()) {
905 RootWindowControllerList controllers = GetAllRootWindowControllers();
906 for (RootWindowControllerList::iterator iter = controllers.begin();
907 iter != controllers.end(); ++iter) {
908 (*iter)->DeactivateKeyboard(keyboard_controller_.get());
909 }
910 }
911 keyboard::KeyboardControllerProxy* proxy =
912 delegate_->CreateKeyboardControllerProxy();
913 keyboard_controller_.reset(
914 new keyboard::KeyboardController(proxy));
915 root->ActivateKeyboard(keyboard_controller_.get());
916 }
917}
918
[email protected]be65be362012-06-15 07:38:23919void Shell::InitRootWindowController(
[email protected]756bda12013-07-03 08:17:06920 internal::RootWindowController* controller,
921 bool first_run_after_boot) {
922
[email protected]be65be362012-06-15 07:38:23923 aura::RootWindow* root_window = controller->root_window();
[email protected]39718b52012-12-03 17:24:56924 DCHECK(activation_client_);
[email protected]d90b8392012-06-13 09:34:56925 DCHECK(visibility_controller_.get());
926 DCHECK(drag_drop_controller_.get());
[email protected]8fef7432012-08-06 15:34:25927 DCHECK(window_cycle_controller_.get());
[email protected]d90b8392012-06-13 09:34:56928
[email protected]8cfb6722012-11-28 03:28:46929 aura::client::SetFocusClient(root_window, focus_client_.get());
[email protected]d90b8392012-06-13 09:34:56930 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
[email protected]39718b52012-12-03 17:24:56931 aura::client::SetActivationClient(root_window, activation_client_);
[email protected]375338212013-09-05 22:14:52932 views::corewm::FocusController* focus_controller =
933 static_cast<views::corewm::FocusController*>(activation_client_);
934 root_window->AddPreTargetHandler(focus_controller);
[email protected]d90b8392012-06-13 09:34:56935 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
936 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]8d625fb2012-07-18 16:40:06937 aura::client::SetScreenPositionClient(root_window,
938 screen_position_controller_.get());
[email protected]4b8003c2012-07-26 00:54:19939 aura::client::SetCursorClient(root_window, &cursor_manager_);
[email protected]54a37cdc2012-07-25 19:16:01940 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:38941 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:56942
[email protected]7f7f65c2013-04-17 16:47:13943 if (nested_dispatcher_controller_) {
[email protected]d90b8392012-06-13 09:34:56944 aura::client::SetDispatcherClient(root_window,
945 nested_dispatcher_controller_.get());
946 }
[email protected]7f7f65c2013-04-17 16:47:13947 if (user_action_client_)
[email protected]d90b8392012-06-13 09:34:56948 aura::client::SetUserActionClient(root_window, user_action_client_.get());
949
[email protected]756bda12013-07-03 08:17:06950 controller->Init(first_run_after_boot);
[email protected]d90b8392012-06-13 09:34:56951}
952
[email protected]c0ce80e2012-10-05 23:28:27953bool Shell::CanWindowReceiveEvents(aura::Window* window) {
954 RootWindowControllerList controllers = GetAllRootWindowControllers();
955 for (RootWindowControllerList::iterator iter = controllers.begin();
956 iter != controllers.end(); ++iter) {
[email protected]bb0c7cd42013-05-20 23:39:45957 internal::SystemModalContainerLayoutManager* layout_manager =
958 (*iter)->GetSystemModalLayoutManager(window);
959 if (layout_manager && layout_manager->CanWindowReceiveEvents(window))
[email protected]c0ce80e2012-10-05 23:28:27960 return true;
[email protected]c0ce80e2012-10-05 23:28:27961 }
962 return false;
963}
964
[email protected]049cf34b2012-12-07 17:15:48965////////////////////////////////////////////////////////////////////////////////
966// Shell, ui::EventTarget overrides:
967
[email protected]869f6352012-12-06 20:47:17968bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:41969 return true;
970}
971
972ui::EventTarget* Shell::GetParentTarget() {
973 return NULL;
974}
975
[email protected]049cf34b2012-12-07 17:15:48976void Shell::OnEvent(ui::Event* event) {
[email protected]1ae361652012-12-12 22:39:51977}
978
979////////////////////////////////////////////////////////////////////////////////
980// Shell, aura::client::ActivationChangeObserver implementation:
981
982void Shell::OnWindowActivated(aura::Window* gained_active,
983 aura::Window* lost_active) {
[email protected]d219a192012-12-14 00:08:18984 if (gained_active)
[email protected]b42910f2013-08-01 11:45:29985 target_root_window_ = gained_active->GetRootWindow();
[email protected]049cf34b2012-12-07 17:15:48986}
987
[email protected]55f593352011-12-24 05:42:46988} // namespace ash