blob: 558870688ef44829c67e2762a6d1440395d52f89 [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]e7293fa2012-05-17 04:42:3310#include "ash/accelerators/focus_manager_factory.h"
[email protected]b65bdda2011-12-23 23:35:3111#include "ash/ash_switches.h"
[email protected]02dbd1a2012-11-08 22:50:1312#include "ash/caps_lock_delegate.h"
[email protected]e70cf0ed2012-03-15 16:24:4713#include "ash/desktop_background/desktop_background_controller.h"
[email protected]e70cf0ed2012-03-15 16:24:4714#include "ash/desktop_background/desktop_background_view.h"
[email protected]81abb1032012-11-13 18:55:4115#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]2e236a52012-06-27 22:21:4716#include "ash/display/display_controller.h"
[email protected]6bdf7952012-11-14 10:10:5817#include "ash/display/display_manager.h"
[email protected]682990f2013-01-10 06:49:1118#include "ash/display/event_transformation_handler.h"
[email protected]91545872012-11-21 13:58:2719#include "ash/display/mouse_cursor_event_filter.h"
[email protected]8d625fb2012-07-18 16:40:0620#include "ash/display/screen_position_controller.h"
[email protected]f4c92b382012-08-28 00:59:5921#include "ash/drag_drop/drag_drop_controller.h"
22#include "ash/focus_cycler.h"
23#include "ash/high_contrast/high_contrast_controller.h"
[email protected]fca90ea2012-12-14 04:13:3024#include "ash/host/root_window_host_factory.h"
[email protected]b913a3a2012-12-11 13:07:1925#include "ash/launcher/launcher_delegate.h"
26#include "ash/launcher/launcher_model.h"
[email protected]f4c92b382012-08-28 00:59:5927#include "ash/magnifier/magnification_controller.h"
[email protected]77f7c132012-11-15 06:52:5428#include "ash/magnifier/partial_magnification_controller.h"
[email protected]d90b8392012-06-13 09:34:5629#include "ash/root_window_controller.h"
[email protected]1a2145b2012-03-13 21:09:1730#include "ash/screen_ash.h"
[email protected]478c6c32013-03-09 02:50:5831#include "ash/shelf/shelf_layout_manager.h"
32#include "ash/shelf/shelf_widget.h"
[email protected]b65bdda2011-12-23 23:35:3133#include "ash/shell_delegate.h"
34#include "ash/shell_factory.h"
35#include "ash/shell_window_ids.h"
[email protected]6d6546e2012-05-30 23:12:0236#include "ash/system/status_area_widget.h"
[email protected]51ed5992012-11-07 10:14:3937#include "ash/system/tray/system_tray_delegate.h"
[email protected]83b2b84c2012-11-14 01:11:0038#include "ash/system/tray/system_tray_notifier.h"
[email protected]73074742012-05-17 01:44:4139#include "ash/touch/touch_observer_hud.h"
[email protected]7634f962011-12-23 21:35:5240#include "ash/wm/activation_controller.h"
[email protected]f059c6942012-07-21 14:27:5741#include "ash/wm/always_on_top_controller.h"
[email protected]0039db92012-05-09 04:11:4542#include "ash/wm/app_list_controller.h"
[email protected]dc09739372012-11-15 20:17:3943#include "ash/wm/ash_activation_controller.h"
[email protected]39718b52012-12-03 17:24:5644#include "ash/wm/ash_focus_rules.h"
[email protected]c0ff0342013-02-27 00:41:2945#include "ash/wm/ash_native_cursor_manager.h"
[email protected]8812588c2012-01-30 21:19:0346#include "ash/wm/base_layout_manager.h"
[email protected]60a978b72012-06-08 00:29:1847#include "ash/wm/capture_controller.h"
[email protected]88d71122012-10-18 07:11:0148#include "ash/wm/coordinate_conversion.h"
[email protected]9d4d1712012-03-06 06:55:2549#include "ash/wm/custom_frame_view_ash.h"
[email protected]262f8bd2012-03-23 19:30:2750#include "ash/wm/event_client_impl.h"
[email protected]b9d224c2012-07-13 01:09:0351#include "ash/wm/event_rewriter_event_filter.h"
[email protected]9ae32df2012-07-26 03:25:1852#include "ash/wm/overlay_event_filter.h"
[email protected]e0d22e82012-01-04 00:46:5753#include "ash/wm/power_button_controller.h"
[email protected]7ae525002012-07-26 23:55:1054#include "ash/wm/property_util.h"
[email protected]e4a181cc2012-03-17 02:20:5755#include "ash/wm/resize_shadow_controller.h"
[email protected]a3301dc2011-12-23 16:34:5156#include "ash/wm/root_window_layout_manager.h"
[email protected]42993212012-04-30 23:42:0457#include "ash/wm/screen_dimmer.h"
[email protected]222f40c2012-10-18 08:58:1358#include "ash/wm/session_state_controller.h"
[email protected]839667d62012-10-23 19:38:5759#include "ash/wm/session_state_controller_impl.h"
60#include "ash/wm/session_state_controller_impl2.h"
[email protected]435b212e2012-04-05 19:43:3761#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2762#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3363#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]c16b9422012-06-06 21:51:1164#include "ash/wm/user_activity_detector.h"
[email protected]9633a9d22012-01-21 16:40:5865#include "ash/wm/video_detector.h"
[email protected]b5756e22012-11-30 01:32:0266#include "ash/wm/window_animations.h"
[email protected]40c4cbb2012-01-10 23:26:0767#include "ash/wm/window_cycle_controller.h"
[email protected]f059c6942012-07-21 14:27:5768#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5969#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3670#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0071#include "base/bind.h"
[email protected]46ca3632011-11-03 03:33:4272#include "base/command_line.h"
[email protected]b0a8faa2012-10-19 03:22:2273#include "base/debug/leak_annotations.h"
[email protected]2c456102011-12-26 06:26:3474#include "ui/aura/client/aura_constants.h"
[email protected]c28853612012-05-31 22:43:4475#include "ui/aura/client/user_action_client.h"
[email protected]8a45c972012-03-14 18:22:4476#include "ui/aura/env.h"
[email protected]a857dbe2012-05-30 22:10:1477#include "ui/aura/focus_manager.h"
[email protected]4bb16502011-12-06 14:44:5878#include "ui/aura/layout_manager.h"
[email protected]2c456102011-12-26 06:26:3479#include "ui/aura/root_window.h"
[email protected]87b0d82e2011-10-07 21:02:5980#include "ui/aura/window.h"
[email protected]2d4817742012-12-17 20:16:1881#include "ui/base/ui_base_switches.h"
[email protected]116302fc2012-05-05 21:45:4182#include "ui/compositor/layer.h"
83#include "ui/compositor/layer_animator.h"
[email protected]7da9c4c2012-06-12 14:43:0184#include "ui/gfx/display.h"
[email protected]9ec0f452012-05-31 15:58:5385#include "ui/gfx/image/image_skia.h"
[email protected]b82c42c42012-04-25 20:03:4186#include "ui/gfx/screen.h"
[email protected]b0639282011-12-22 21:12:2787#include "ui/gfx/size.h"
[email protected]8393aa62013-01-23 19:40:1088#include "ui/message_center/message_center.h"
[email protected]4a59e4e2012-11-12 21:15:4089#include "ui/views/corewm/compound_event_filter.h"
[email protected]39718b52012-12-03 17:24:5690#include "ui/views/corewm/corewm_switches.h"
91#include "ui/views/corewm/focus_controller.h"
[email protected]4a59e4e2012-11-12 21:15:4092#include "ui/views/corewm/input_method_event_filter.h"
[email protected]86f2b5e2012-11-14 20:37:0093#include "ui/views/corewm/shadow_controller.h"
[email protected]a1b7a822013-02-23 19:08:0494#include "ui/views/corewm/tooltip_controller.h"
[email protected]b5756e22012-11-30 01:32:0295#include "ui/views/corewm/visibility_controller.h"
[email protected]0c2dc012012-12-02 00:00:2396#include "ui/views/corewm/window_modality_controller.h"
[email protected]e7293fa2012-05-17 04:42:3397#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:5898#include "ui/views/widget/native_widget_aura.h"
99#include "ui/views/widget/widget.h"
[email protected]fef157d12013-02-04 20:43:23100#include "ui/views/window/dialog_delegate.h"
[email protected]87b0d82e2011-10-07 21:02:59101
[email protected]6e9f6aa2012-02-09 04:16:20102#if !defined(OS_MACOSX)
103#include "ash/accelerators/accelerator_controller.h"
104#include "ash/accelerators/accelerator_filter.h"
105#include "ash/accelerators/nested_dispatcher_controller.h"
106#endif
107
[email protected]70b3e7d52012-06-02 22:12:25108#if defined(OS_CHROMEOS)
[email protected]44d444c2013-01-30 01:47:44109#include "ash/ash_constants.h"
[email protected]6bdf7952012-11-14 10:10:58110#include "ash/display/display_change_observer_x11.h"
[email protected]18b21b2e2013-03-01 20:56:23111#include "ash/display/display_error_dialog.h"
[email protected]196e9452012-08-01 06:42:51112#include "ash/display/output_configurator_animation.h"
[email protected]6bdf7952012-11-14 10:10:58113#include "base/chromeos/chromeos_version.h"
[email protected]4168ad72012-08-30 16:57:21114#include "base/message_pump_aurax11.h"
[email protected]2e236a52012-06-27 22:21:47115#include "chromeos/display/output_configurator.h"
[email protected]7158db12012-10-15 22:19:31116#include "content/public/browser/gpu_data_manager.h"
[email protected]963dd662013-01-31 06:48:35117#include "content/public/common/content_switches.h"
[email protected]7158db12012-10-15 22:19:31118#include "content/public/common/gpu_feature_type.h"
[email protected]70b3e7d52012-06-02 22:12:25119#endif // defined(OS_CHROMEOS)
120
[email protected]55f593352011-12-24 05:42:46121namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59122
123namespace {
[email protected]671a2ae2011-10-13 21:53:23124
[email protected]615922f2012-02-07 02:41:15125using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45126using views::Widget;
127
[email protected]10b22612012-03-22 17:07:55128// This dummy class is used for shell unit tests. We dont have chrome delegate
129// in these tests.
[email protected]5c543242012-03-24 16:25:42130class DummyUserWallpaperDelegate : public UserWallpaperDelegate {
[email protected]10b22612012-03-22 17:07:55131 public:
132 DummyUserWallpaperDelegate() {}
133
134 virtual ~DummyUserWallpaperDelegate() {}
135
[email protected]d2177692012-11-29 16:19:04136 virtual int GetAnimationType() OVERRIDE {
137 return views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE;
[email protected]815d0c382012-07-21 08:13:44138 }
139
[email protected]bca9a7e2012-11-10 06:25:49140 virtual bool ShouldShowInitialAnimation() OVERRIDE {
141 return false;
142 }
143
[email protected]c10baf72012-11-01 18:24:32144 virtual void UpdateWallpaper() OVERRIDE {
145 }
146
[email protected]0c4f87d2012-06-12 02:00:35147 virtual void InitializeWallpaper() OVERRIDE {
[email protected]d50034732012-06-04 19:11:04148 ash::Shell::GetInstance()->desktop_background_controller()->
149 CreateEmptyWallpaper();
[email protected]10b22612012-03-22 17:07:55150 }
151
[email protected]5c543242012-03-24 16:25:42152 virtual void OpenSetWallpaperPage() OVERRIDE {
153 }
154
[email protected]0cfc18e2012-04-11 18:17:47155 virtual bool CanOpenSetWallpaperPage() OVERRIDE {
156 return false;
157 }
158
[email protected]07a2fa62012-06-26 10:39:38159 virtual void OnWallpaperAnimationFinished() OVERRIDE {
160 }
161
[email protected]8b04a1652012-08-04 02:59:49162 virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
163 }
164
[email protected]10b22612012-03-22 17:07:55165 private:
[email protected]0039db92012-05-09 04:11:45166 DISALLOW_COPY_AND_ASSIGN(DummyUserWallpaperDelegate);
[email protected]10b22612012-03-22 17:07:55167};
168
[email protected]b5756e22012-11-30 01:32:02169// A Corewm VisibilityController subclass that calls the Ash animation routine
170// so we can pick up our extended animations. See ash/wm/window_animations.h.
171class AshVisibilityController : public views::corewm::VisibilityController {
172 public:
173 AshVisibilityController() {}
174 virtual ~AshVisibilityController() {}
175
176 private:
177 // Overridden from views::corewm::VisibilityController:
178 virtual bool CallAnimateOnChildWindowVisibilityChanged(
179 aura::Window* window,
180 bool visible) OVERRIDE {
181 return AnimateOnChildWindowVisibilityChanged(window, visible);
182 }
183
184 DISALLOW_COPY_AND_ASSIGN(AshVisibilityController);
185};
186
[email protected]87b0d82e2011-10-07 21:02:59187} // namespace
188
[email protected]cac10fc62011-10-07 23:22:56189// static
190Shell* Shell::instance_ = NULL;
[email protected]2b4cd302012-02-24 20:21:13191// static
[email protected]9488d4d2012-02-29 18:32:37192bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13193
194////////////////////////////////////////////////////////////////////////////////
[email protected]cac10fc62011-10-07 23:22:56195// Shell, public:
196
[email protected]3266c2b92011-11-14 00:06:08197Shell::Shell(ShellDelegate* delegate)
[email protected]d90b8392012-06-13 09:34:56198 : screen_(new ScreenAsh),
[email protected]be65be362012-06-15 07:38:23199 active_root_window_(NULL),
[email protected]9c66adc2012-01-05 02:10:16200 delegate_(delegate),
[email protected]39718b52012-12-03 17:24:56201 activation_client_(NULL),
[email protected]70b3e7d52012-06-02 22:12:25202#if defined(OS_CHROMEOS)
[email protected]cf1c70e2012-08-30 01:13:02203 output_configurator_(new chromeos::OutputConfigurator()),
[email protected]70b3e7d52012-06-02 22:12:25204#endif // defined(OS_CHROMEOS)
[email protected]c0ff0342013-02-27 00:41:29205 native_cursor_manager_(new AshNativeCursorManager),
206 cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>(
207 native_cursor_manager_)),
[email protected]852a55d2012-10-17 13:30:30208 browser_context_(NULL),
209 simulate_modal_window_open_for_testing_(false) {
[email protected]02dbd1a2012-11-08 22:50:13210 DCHECK(delegate_.get());
[email protected]6bdf7952012-11-14 10:10:58211 display_manager_.reset(new internal::DisplayManager);
[email protected]b0a8faa2012-10-19 03:22:22212 ANNOTATE_LEAKING_OBJECT_PTR(screen_); // see crbug.com/156466
[email protected]b0a8faa2012-10-19 03:22:22213 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_);
[email protected]5fdb45b2012-10-23 20:26:28214 if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE))
215 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_);
[email protected]70b3e7d52012-06-02 22:12:25216#if defined(OS_CHROMEOS)
[email protected]7158db12012-10-15 22:19:31217 content::GpuFeatureType blacklisted_features =
218 content::GpuDataManager::GetInstance()->GetBlacklistedFeatures();
219 bool is_panel_fitting_disabled =
220 (blacklisted_features & content::GPU_FEATURE_TYPE_PANEL_FITTING) ||
221 CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]963dd662013-01-31 06:48:35222 ::switches::kDisablePanelFitting);
[email protected]44d444c2013-01-30 01:47:44223
224 output_configurator_->Init(
225 !is_panel_fitting_disabled,
226 delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0);
[email protected]7158db12012-10-15 22:19:31227
[email protected]4168ad72012-08-30 16:57:21228 base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow(
229 output_configurator());
[email protected]70b3e7d52012-06-02 22:12:25230#endif // defined(OS_CHROMEOS)
[email protected]049cf34b2012-12-07 17:15:48231 AddPreTargetHandler(this);
[email protected]87b0d82e2011-10-07 21:02:59232}
233
234Shell::~Shell() {
[email protected]e7293fa2012-05-17 04:42:33235 views::FocusManagerFactory::Install(NULL);
[email protected]cb3b8b22012-06-27 23:26:37236
237 // Remove the focus from any window. This will prevent overhead and side
238 // effects (e.g. crashes) from changing focus during shutdown.
239 // See bug crbug.com/134502.
240 if (active_root_window_)
[email protected]550543e2013-01-11 22:43:44241 aura::client::GetFocusClient(active_root_window_)->FocusWindow(NULL);
[email protected]cb3b8b22012-06-27 23:26:37242
[email protected]9861f1752012-06-01 07:16:14243 // Please keep in same order as in Init() because it's easy to miss one.
[email protected]304594c2012-11-13 16:35:27244 RemovePreTargetHandler(user_activity_detector_.get());
245 RemovePreTargetHandler(event_rewriter_filter_.get());
246 RemovePreTargetHandler(overlay_filter_.get());
247 RemovePreTargetHandler(input_method_filter_.get());
248 RemovePreTargetHandler(window_modality_controller_.get());
[email protected]78d96302012-06-22 00:58:07249 if (mouse_cursor_filter_.get())
[email protected]304594c2012-11-13 16:35:27250 RemovePreTargetHandler(mouse_cursor_filter_.get());
[email protected]f9f017c2012-11-12 19:05:17251 RemovePreTargetHandler(system_gesture_filter_.get());
[email protected]6e9f6aa2012-02-09 04:16:20252#if !defined(OS_MACOSX)
[email protected]f9f017c2012-11-12 19:05:17253 RemovePreTargetHandler(accelerator_filter_.get());
[email protected]6e9f6aa2012-02-09 04:16:20254#endif
[email protected]73074742012-05-17 01:44:41255 if (touch_observer_hud_.get())
[email protected]f9f017c2012-11-12 19:05:17256 RemovePreTargetHandler(touch_observer_hud_.get());
[email protected]745816be2011-11-22 05:08:30257
[email protected]931f4f42012-02-10 23:49:42258 // TooltipController is deleted with the Shell so removing its references.
[email protected]304594c2012-11-13 16:35:27259 RemovePreTargetHandler(tooltip_controller_.get());
[email protected]ef589af2011-12-03 01:07:15260
[email protected]f5f3c752012-06-07 05:16:02261 // AppList needs to be released before shelf layout manager, which is
262 // destroyed with launcher container in the loop below. However, app list
263 // container is now on top of launcher container and released after it.
264 // TODO(xiyuan): Move it back when app list container is no longer needed.
265 app_list_controller_.reset();
266
[email protected]51ed5992012-11-07 10:14:39267 // Destroy SystemTrayDelegate before destroying the status area(s).
268 system_tray_delegate_.reset();
269
[email protected]be65be362012-06-15 07:38:23270 // Destroy all child windows including widgets.
[email protected]2e236a52012-06-27 22:21:47271 display_controller_->CloseChildWindows();
[email protected]ef589af2011-12-03 01:07:15272
[email protected]45590a862012-12-11 01:55:31273 // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems
274 // needs to remove observers from it.
275 system_tray_notifier_.reset();
276
[email protected]40c4cbb2012-01-10 23:26:07277 // These need a valid Shell instance to clean up properly, so explicitly
278 // delete them before invalidating the instance.
[email protected]b913a3a2012-12-11 13:07:19279 // Alphabetical. TODO(oshima): sort.
[email protected]084b6bb2011-11-17 05:18:16280 drag_drop_controller_.reset();
[email protected]c1c670172012-04-26 04:20:26281 magnification_controller_.reset();
[email protected]77f7c132012-11-15 06:52:54282 partial_magnification_controller_.reset();
[email protected]e4a181cc2012-03-17 02:20:57283 resize_shadow_controller_.reset();
[email protected]58482fa2012-03-02 14:57:39284 shadow_controller_.reset();
[email protected]fd162f72012-04-14 03:24:53285 tooltip_controller_.reset();
[email protected]e67291f12012-10-10 05:52:38286 event_client_.reset();
[email protected]aa476502012-05-01 18:03:19287 window_cycle_controller_.reset();
[email protected]60a978b72012-06-08 00:29:18288 capture_controller_.reset();
[email protected]60a978b72012-06-08 00:29:18289 nested_dispatcher_controller_.reset();
[email protected]60a978b72012-06-08 00:29:18290 user_action_client_.reset();
[email protected]60a978b72012-06-08 00:29:18291 visibility_controller_.reset();
[email protected]b913a3a2012-12-11 13:07:19292 launcher_delegate_.reset();
293 launcher_model_.reset();
[email protected]084b6bb2011-11-17 05:18:16294
[email protected]83482fbf2012-11-21 14:02:09295 power_button_controller_.reset();
296 session_state_controller_.reset();
297
[email protected]28b55562013-02-20 11:37:34298 // This also deletes all RootWindows. Note that we invoke Shutdown() on
299 // DisplayController before resetting |display_controller_|, since destruction
300 // of its owned RootWindowControllers relies on the value.
301 display_controller_->Shutdown();
[email protected]2e236a52012-06-27 22:21:47302 display_controller_.reset();
[email protected]8d625fb2012-07-18 16:40:06303 screen_position_controller_.reset();
[email protected]d90b8392012-06-13 09:34:56304
[email protected]764864e2012-06-11 19:16:16305 // Delete the activation controller after other controllers and launcher
306 // because they might have registered ActivationChangeObserver.
[email protected]764864e2012-06-11 19:16:16307 activation_controller_.reset();
308
[email protected]70b3e7d52012-06-02 22:12:25309#if defined(OS_CHROMEOS)
[email protected]32c3e98e52013-01-30 19:20:09310 if (display_change_observer_.get())
311 output_configurator_->RemoveObserver(display_change_observer_.get());
312 if (output_configurator_animation_.get())
313 output_configurator_->RemoveObserver(output_configurator_animation_.get());
[email protected]18b21b2e2013-03-01 20:56:23314 if (display_error_observer_.get())
315 output_configurator_->RemoveObserver(display_error_observer_.get());
[email protected]4168ad72012-08-30 16:57:21316 base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow(
317 output_configurator());
[email protected]70b3e7d52012-06-02 22:12:25318#endif // defined(OS_CHROMEOS)
[email protected]18b21b2e2013-03-01 20:56:23319
320 DCHECK(instance_ == this);
321 instance_ = NULL;
[email protected]87b0d82e2011-10-07 21:02:59322}
323
[email protected]cac10fc62011-10-07 23:22:56324// static
[email protected]3266c2b92011-11-14 00:06:08325Shell* Shell::CreateInstance(ShellDelegate* delegate) {
326 CHECK(!instance_);
327 instance_ = new Shell(delegate);
328 instance_->Init();
329 return instance_;
330}
331
332// static
[email protected]cac10fc62011-10-07 23:22:56333Shell* Shell::GetInstance() {
[email protected]3266c2b92011-11-14 00:06:08334 DCHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56335 return instance_;
336}
337
[email protected]6377a002011-11-10 20:26:47338// static
[email protected]b3b7bcd2012-03-06 19:35:45339bool Shell::HasInstance() {
340 return !!instance_;
341}
342
343// static
[email protected]ef589af2011-12-03 01:07:15344void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47345 delete instance_;
346 instance_ = NULL;
347}
348
[email protected]e73bd7802012-02-17 20:10:34349// static
[email protected]d90b8392012-06-13 09:34:56350internal::RootWindowController* Shell::GetPrimaryRootWindowController() {
[email protected]7ae525002012-07-26 23:55:10351 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23352}
353
354// static
355Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
[email protected]2e236a52012-06-27 22:21:47356 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23357 GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56358}
359
360// static
[email protected]42713f72012-05-25 00:41:50361aura::RootWindow* Shell::GetPrimaryRootWindow() {
[email protected]2e236a52012-06-27 22:21:47362 return GetInstance()->display_controller()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34363}
364
[email protected]7b0f7502012-06-11 00:12:39365// static
[email protected]a857dbe2012-05-30 22:10:14366aura::RootWindow* Shell::GetActiveRootWindow() {
367 return GetInstance()->active_root_window_;
368}
369
[email protected]7b0f7502012-06-11 00:12:39370// static
[email protected]ffabb1e2012-10-12 19:51:17371gfx::Screen* Shell::GetScreen() {
[email protected]5fdb45b2012-10-23 20:26:28372 return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
[email protected]ffabb1e2012-10-12 19:51:17373}
374
375// static
[email protected]be65be362012-06-15 07:38:23376Shell::RootWindowList Shell::GetAllRootWindows() {
[email protected]2e236a52012-06-27 22:21:47377 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23378 GetAllRootWindows();
379}
380
381// static
[email protected]7b0f7502012-06-11 00:12:39382aura::Window* Shell::GetContainer(aura::RootWindow* root_window,
383 int container_id) {
384 return root_window->GetChildById(container_id);
385}
386
387// static
[email protected]e67291f12012-10-10 05:52:38388const aura::Window* Shell::GetContainer(const aura::RootWindow* root_window,
389 int container_id) {
390 return root_window->GetChildById(container_id);
391}
392
393// static
[email protected]429433f2012-12-28 20:14:46394std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows(
395 int container_id,
396 aura::RootWindow* priority_root) {
[email protected]7b0f7502012-06-11 00:12:39397 std::vector<aura::Window*> containers;
[email protected]001272f2012-11-02 20:05:23398 RootWindowList root_windows = GetAllRootWindows();
399 for (RootWindowList::const_iterator it = root_windows.begin();
400 it != root_windows.end(); ++it) {
401 aura::Window* container = (*it)->GetChildById(container_id);
[email protected]429433f2012-12-28 20:14:46402 if (container) {
403 if (priority_root && priority_root->Contains(container))
404 containers.insert(containers.begin(), container);
405 else
406 containers.push_back(container);
407 }
[email protected]001272f2012-11-02 20:05:23408 }
[email protected]7b0f7502012-06-11 00:12:39409 return containers;
410}
411
[email protected]e74aaf0a2012-10-12 18:42:28412// static
413bool Shell::IsLauncherPerDisplayEnabled() {
414 CommandLine* command_line = CommandLine::ForCurrentProcess();
[email protected]8039e06c2013-01-17 23:34:50415 return !command_line->HasSwitch(switches::kAshDisableLauncherPerDisplay);
[email protected]e74aaf0a2012-10-12 18:42:28416}
417
[email protected]87b0d82e2011-10-07 21:02:59418void Shell::Init() {
[email protected]6bdf7952012-11-14 10:10:58419#if defined(OS_CHROMEOS)
420 if (base::chromeos::IsRunningOnChromeOS()) {
421 display_change_observer_.reset(new internal::DisplayChangeObserverX11);
[email protected]32c3e98e52013-01-30 19:20:09422 // Register |display_change_observer_| first so that the rest of
423 // observer gets invoked after the root windows are configured.
424 output_configurator_->AddObserver(display_change_observer_.get());
425 output_configurator_animation_.reset(
[email protected]18b21b2e2013-03-01 20:56:23426 new internal::OutputConfiguratorAnimation());
427 display_error_observer_.reset(new internal::DisplayErrorObserver());
[email protected]32c3e98e52013-01-30 19:20:09428 output_configurator_->AddObserver(output_configurator_animation_.get());
[email protected]18b21b2e2013-03-01 20:56:23429 output_configurator_->AddObserver(display_error_observer_.get());
[email protected]32c3e98e52013-01-30 19:20:09430 display_change_observer_->OnDisplayModeChanged();
[email protected]6bdf7952012-11-14 10:10:58431 }
432#endif
433
[email protected]c9301e32012-05-23 08:34:58434 // Install the custom factory first so that views::FocusManagers for Tray,
435 // Launcher, and WallPaper could be created by the factory.
436 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
437
[email protected]4a59e4e2012-11-12 21:15:40438 env_filter_.reset(new views::corewm::CompoundEventFilter);
[email protected]304594c2012-11-13 16:35:27439 AddPreTargetHandler(env_filter_.get());
[email protected]1aad3322012-06-06 06:37:09440
[email protected]05ab8e12013-01-31 21:21:33441 // Env creates the compositor. Historically it seems to have been implicitly
442 // initialized first by the ActivationController, but now that FocusController
443 // no longer does this we need to do it explicitly.
444 aura::Env::GetInstance();
[email protected]052305f2012-12-05 18:53:04445 if (views::corewm::UseFocusController()) {
[email protected]39718b52012-12-03 17:24:56446 views::corewm::FocusController* focus_controller =
447 new views::corewm::FocusController(new wm::AshFocusRules);
448 focus_client_.reset(focus_controller);
449 activation_client_ = focus_controller;
[email protected]1ae361652012-12-12 22:39:51450 activation_client_->AddObserver(this);
[email protected]39718b52012-12-03 17:24:56451 } else {
452 focus_client_.reset(new aura::FocusManager);
453 activation_controller_.reset(
454 new internal::ActivationController(
455 focus_client_.get(),
456 new internal::AshActivationController));
457 activation_client_ = activation_controller_.get();
458 AddPreTargetHandler(activation_controller_.get());
459 }
[email protected]be65be362012-06-15 07:38:23460
[email protected]e74aaf0a2012-10-12 18:42:28461 focus_cycler_.reset(new internal::FocusCycler());
462
[email protected]8d625fb2012-07-18 16:40:06463 screen_position_controller_.reset(new internal::ScreenPositionController);
[email protected]fca90ea2012-12-14 04:13:30464 root_window_host_factory_.reset(delegate_->CreateRootWindowHostFactory());
[email protected]edbfb8d2012-09-03 08:33:43465 display_controller_.reset(new DisplayController);
[email protected]2e236a52012-06-27 22:21:47466 display_controller_->InitPrimaryDisplay();
467 aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow();
[email protected]be65be362012-06-15 07:38:23468 active_root_window_ = root_window;
[email protected]a857dbe2012-05-30 22:10:14469
[email protected]151ffdff2012-09-11 20:18:35470 cursor_manager_.SetDeviceScaleFactor(
471 root_window->AsRootWindowHostDelegate()->GetDeviceScaleFactor());
472
[email protected]58482fa2012-03-02 14:57:39473#if !defined(OS_MACOSX)
474 nested_dispatcher_controller_.reset(new NestedDispatcherController);
475 accelerator_controller_.reset(new AcceleratorController);
476#endif
[email protected]58482fa2012-03-02 14:57:39477
[email protected]c16b9422012-06-06 21:51:11478 // The order in which event filters are added is significant.
[email protected]c16b9422012-06-06 21:51:11479 user_activity_detector_.reset(new UserActivityDetector);
[email protected]304594c2012-11-13 16:35:27480 AddPreTargetHandler(user_activity_detector_.get());
[email protected]c16b9422012-06-06 21:51:11481
[email protected]b9d224c2012-07-13 01:09:03482 event_rewriter_filter_.reset(new internal::EventRewriterEventFilter);
[email protected]304594c2012-11-13 16:35:27483 AddPreTargetHandler(event_rewriter_filter_.get());
[email protected]0b0b0742012-02-16 13:23:45484
[email protected]9ae32df2012-07-26 03:25:18485 overlay_filter_.reset(new internal::OverlayEventFilter);
[email protected]304594c2012-11-13 16:35:27486 AddPreTargetHandler(overlay_filter_.get());
[email protected]9ae32df2012-07-26 03:25:18487 AddShellObserver(overlay_filter_.get());
[email protected]0b0b0742012-02-16 13:23:45488
[email protected]15a1b4e2012-12-06 23:03:10489 input_method_filter_.reset(new views::corewm::InputMethodEventFilter(
490 root_window->GetAcceleratedWidget()));
[email protected]304594c2012-11-13 16:35:27491 AddPreTargetHandler(input_method_filter_.get());
[email protected]c16b9422012-06-06 21:51:11492
[email protected]21472b12012-02-17 00:30:05493#if !defined(OS_MACOSX)
494 accelerator_filter_.reset(new internal::AcceleratorFilter);
[email protected]f9f017c2012-11-12 19:05:17495 AddPreTargetHandler(accelerator_filter_.get());
[email protected]21472b12012-02-17 00:30:05496#endif
[email protected]fcbbf082012-01-20 06:07:15497
[email protected]682990f2013-01-10 06:49:11498 event_transformation_handler_.reset(new internal::EventTransformationHandler);
499 AddPreTargetHandler(event_transformation_handler_.get());
500
[email protected]435b212e2012-04-05 19:43:37501 system_gesture_filter_.reset(new internal::SystemGestureEventFilter);
[email protected]f9f017c2012-11-12 19:05:17502 AddPreTargetHandler(system_gesture_filter_.get());
[email protected]435b212e2012-04-05 19:43:37503
[email protected]60a978b72012-06-08 00:29:18504 capture_controller_.reset(new internal::CaptureController);
[email protected]87b0d82e2011-10-07 21:02:59505
[email protected]871e9cc2012-06-17 22:41:55506 internal::RootWindowController* root_window_controller =
507 new internal::RootWindowController(root_window);
508 root_window_controller->CreateContainers();
[email protected]697f04c2012-10-03 01:15:10509 root_window_controller->CreateSystemBackground(
[email protected]02dbd1a2012-11-08 22:50:13510 delegate_->IsFirstRunAfterBoot());
[email protected]871e9cc2012-06-17 22:41:55511
[email protected]73074742012-05-17 01:44:41512 CommandLine* command_line = CommandLine::ForCurrentProcess();
513
[email protected]c11aa8f12012-12-18 18:43:14514 if (command_line->HasSwitch(ash::switches::kAshDisableNewLockAnimations))
[email protected]7ac6c5d2012-12-18 15:44:56515 session_state_controller_.reset(new SessionStateControllerImpl);
[email protected]c11aa8f12012-12-18 18:43:14516 else
517 session_state_controller_.reset(new SessionStateControllerImpl2);
[email protected]83482fbf2012-11-21 14:02:09518 power_button_controller_.reset(new PowerButtonController(
519 session_state_controller_.get()));
520 AddShellObserver(session_state_controller_.get());
521
[email protected]73074742012-05-17 01:44:41522 if (command_line->HasSwitch(switches::kAshTouchHud)) {
523 touch_observer_hud_.reset(new internal::TouchObserverHUD);
[email protected]f9f017c2012-11-12 19:05:17524 AddPreTargetHandler(touch_observer_hud_.get());
[email protected]73074742012-05-17 01:44:41525 }
[email protected]d90b8392012-06-13 09:34:56526
[email protected]8b7ba87b2012-09-01 00:40:40527 mouse_cursor_filter_.reset(new internal::MouseCursorEventFilter());
[email protected]304594c2012-11-13 16:35:27528 AddPreTargetHandler(mouse_cursor_filter_.get());
[email protected]0518d0d2012-08-26 11:59:04529
[email protected]d90b8392012-06-13 09:34:56530 // Create Controllers that may need root window.
531 // TODO(oshima): Move as many controllers before creating
532 // RootWindowController as possible.
[email protected]b5756e22012-11-30 01:32:02533 visibility_controller_.reset(new AshVisibilityController);
[email protected]d90b8392012-06-13 09:34:56534 drag_drop_controller_.reset(new internal::DragDropController);
[email protected]02dbd1a2012-11-08 22:50:13535 user_action_client_.reset(delegate_->CreateUserActionClient());
[email protected]0c2dc012012-12-02 00:00:23536 window_modality_controller_.reset(
537 new views::corewm::WindowModalityController);
[email protected]304594c2012-11-13 16:35:27538 AddPreTargetHandler(window_modality_controller_.get());
[email protected]488b42042011-11-15 00:20:18539
[email protected]9613eacf2012-06-22 02:18:05540 magnification_controller_.reset(
[email protected]77f7c132012-11-15 06:52:54541 MagnificationController::CreateInstance());
542
543 partial_magnification_controller_.reset(
544 new PartialMagnificationController());
[email protected]9613eacf2012-06-22 02:18:05545
[email protected]d90b8392012-06-13 09:34:56546 high_contrast_controller_.reset(new HighContrastController);
547 video_detector_.reset(new VideoDetector);
[email protected]39718b52012-12-03 17:24:56548 window_cycle_controller_.reset(new WindowCycleController(activation_client_));
[email protected]b0079a92012-01-25 20:13:38549
[email protected]a1b7a822013-02-23 19:08:04550 tooltip_controller_.reset(new views::corewm::TooltipController(
551 gfx::SCREEN_TYPE_ALTERNATE));
[email protected]304594c2012-11-13 16:35:27552 AddPreTargetHandler(tooltip_controller_.get());
[email protected]54a37cdc2012-07-25 19:16:01553
[email protected]e67291f12012-10-10 05:52:38554 event_client_.reset(new internal::EventClientImpl);
555
[email protected]be65be362012-06-15 07:38:23556 InitRootWindowController(root_window_controller);
[email protected]262f8bd2012-03-23 19:30:27557
[email protected]36f566532012-09-19 04:07:24558 // This controller needs to be set before SetupManagedWindowMode.
559 desktop_background_controller_.reset(new DesktopBackgroundController());
[email protected]02dbd1a2012-11-08 22:50:13560 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
[email protected]36f566532012-09-19 04:07:24561 if (!user_wallpaper_delegate_.get())
562 user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate());
563
[email protected]f4c92b382012-08-28 00:59:59564 // StatusAreaWidget uses Shell's CapsLockDelegate.
[email protected]02dbd1a2012-11-08 22:50:13565 caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());
[email protected]f4c92b382012-08-28 00:59:59566
[email protected]a1b7a822013-02-23 19:08:04567 if (!command_line->HasSwitch(views::corewm::switches::kNoDropShadows)) {
[email protected]e4a181cc2012-03-17 02:20:57568 resize_shadow_controller_.reset(new internal::ResizeShadowController());
[email protected]86f2b5e2012-11-14 20:37:00569 shadow_controller_.reset(
[email protected]7dd11db2013-02-27 01:29:13570 new views::corewm::ShadowController(activation_client_));
[email protected]e4a181cc2012-03-17 02:20:57571 }
[email protected]a54e65b2011-11-21 22:03:34572
[email protected]83b2b84c2012-11-14 01:11:00573 // Create system_tray_notifier_ before the delegate.
574 system_tray_notifier_.reset(new ash::SystemTrayNotifier());
575
[email protected]51ed5992012-11-07 10:14:39576 // Initialize system_tray_delegate_ before initializing StatusAreaWidget.
[email protected]02dbd1a2012-11-08 22:50:13577 system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate());
[email protected]51ed5992012-11-07 10:14:39578 if (!system_tray_delegate_.get())
579 system_tray_delegate_.reset(SystemTrayDelegate::CreateDummyDelegate());
580
581 // Creates StatusAreaWidget.
[email protected]e74aaf0a2012-10-12 18:42:28582 root_window_controller->InitForPrimaryDisplay();
[email protected]3d29912a2012-02-07 07:41:51583
[email protected]51ed5992012-11-07 10:14:39584 // Initialize system_tray_delegate_ after StatusAreaWidget is created.
585 system_tray_delegate_->Initialize();
586
[email protected]16059276d2012-10-22 18:59:50587 display_controller_->InitSecondaryDisplays();
588
[email protected]d90b8392012-06-13 09:34:56589 // Force Layout
[email protected]be65be362012-06-15 07:38:23590 root_window_controller->root_window_layout()->OnWindowResized();
[email protected]084b6bb2011-11-17 05:18:16591
[email protected]60b5b862012-04-27 18:56:34592 // It needs to be created after OnWindowResized has been called, otherwise the
[email protected]5f2391ea2012-09-12 23:46:49593 // widget will not paint when restoring after a browser crash. Also it needs
594 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
595 // the correct size.
[email protected]0c4f87d2012-06-12 02:00:35596 user_wallpaper_delegate_->InitializeWallpaper();
[email protected]60b5b862012-04-27 18:56:34597
[email protected]d90b8392012-06-13 09:34:56598 if (initially_hide_cursor_)
[email protected]4e721742013-02-04 21:39:30599 cursor_manager_.HideCursor();
[email protected]86e38e42012-11-20 17:53:26600 cursor_manager_.SetCursor(ui::kCursorPointer);
[email protected]0ad9b762012-09-28 04:22:09601
[email protected]4e721742013-02-04 21:39:30602 if (!cursor_manager_.IsCursorVisible()) {
603 // Cursor might have been hidden by something other than chrome.
604 // Let the first mouse event show the cursor.
605 env_filter_->set_cursor_hidden_by_filter(true);
606 }
[email protected]87b0d82e2011-10-07 21:02:59607}
608
[email protected]431552c2012-10-23 00:38:33609void Shell::ShowContextMenu(const gfx::Point& location_in_screen) {
[email protected]f60c6232012-08-24 18:55:03610 // No context menus if user have not logged in.
[email protected]02dbd1a2012-11-08 22:50:13611 if (!delegate_->IsUserLoggedIn())
[email protected]f60c6232012-08-24 18:55:03612 return;
613 // No context menus when screen is locked.
614 if (IsScreenLocked())
615 return;
[email protected]431552c2012-10-23 00:38:33616
[email protected]88d71122012-10-18 07:11:01617 aura::RootWindow* root =
[email protected]431552c2012-10-23 00:38:33618 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()));
[email protected]43dcd352012-12-18 02:28:46619 // TODO(oshima): The root and root window controller shouldn't be
620 // NULL even for the out-of-bounds |location_in_screen| (It should
621 // return the primary root). Investigate why/how this is
622 // happening. crbug.com/165214.
623 internal::RootWindowController* rwc = GetRootWindowController(root);
[email protected]bd4814b2012-12-27 01:16:00624 CHECK(rwc) << "root=" << root
625 << ", location:" << location_in_screen.ToString();
[email protected]43dcd352012-12-18 02:28:46626 if (rwc)
627 rwc->ShowContextMenu(location_in_screen);
[email protected]46ca3632011-11-03 03:33:42628}
629
[email protected]b913a3a2012-12-11 13:07:19630void Shell::ToggleAppList(aura::Window* window) {
631 // If the context window is not given, show it on the active root window.
632 if (!window)
633 window = GetActiveRootWindow();
[email protected]0039db92012-05-09 04:11:45634 if (!app_list_controller_.get())
635 app_list_controller_.reset(new internal::AppListController);
[email protected]b913a3a2012-12-11 13:07:19636 app_list_controller_->SetVisible(!app_list_controller_->IsVisible(), window);
[email protected]ae4987d2011-11-21 22:52:44637}
638
[email protected]7510d1082012-03-30 21:58:34639bool Shell::GetAppListTargetVisibility() const {
[email protected]0039db92012-05-09 04:11:45640 return app_list_controller_.get() &&
641 app_list_controller_->GetTargetVisibility();
[email protected]7510d1082012-03-30 21:58:34642}
643
[email protected]1e51a9d2012-04-09 23:31:11644aura::Window* Shell::GetAppListWindow() {
[email protected]0039db92012-05-09 04:11:45645 return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
[email protected]1e51a9d2012-04-09 23:31:11646}
647
[email protected]91545872012-11-21 13:58:27648bool Shell::CanLockScreen() {
649 return delegate_->CanLockScreen();
650}
651
[email protected]f7eb89c2011-12-13 09:48:54652bool Shell::IsScreenLocked() const {
[email protected]02dbd1a2012-11-08 22:50:13653 return delegate_->IsScreenLocked();
[email protected]f7eb89c2011-12-13 09:48:54654}
655
[email protected]dc09739372012-11-15 20:17:39656bool Shell::IsSystemModalWindowOpen() const {
[email protected]852a55d2012-10-17 13:30:30657 if (simulate_modal_window_open_for_testing_)
658 return true;
[email protected]429433f2012-12-28 20:14:46659 const std::vector<aura::Window*> containers = GetContainersFromAllRootWindows(
660 internal::kShellWindowId_SystemModalContainer, NULL);
[email protected]001272f2012-11-02 20:05:23661 for (std::vector<aura::Window*>::const_iterator cit = containers.begin();
662 cit != containers.end(); ++cit) {
663 for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin();
664 wit != (*cit)->children().end(); ++wit) {
665 if ((*wit)->GetProperty(aura::client::kModalKey) ==
666 ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) {
667 return true;
668 }
669 }
670 }
671 return false;
[email protected]40c4cbb2012-01-10 23:26:07672}
673
[email protected]57b8bb352012-01-11 05:11:46674views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
675 views::Widget* widget) {
[email protected]fef157d12013-02-04 20:43:23676 if (views::DialogDelegate::UseNewStyle())
677 return views::DialogDelegate::CreateNewStyleFrameView(widget);
[email protected]c73d1332012-03-08 17:11:04678 // Use translucent-style window frames for dialogs.
[email protected]95c6cc42012-03-08 20:53:15679 CustomFrameViewAsh* frame_view = new CustomFrameViewAsh;
[email protected]c73d1332012-03-08 17:11:04680 frame_view->Init(widget);
681 return frame_view;
[email protected]57b8bb352012-01-11 05:11:46682}
683
[email protected]3d29912a2012-02-07 07:41:51684void Shell::RotateFocus(Direction direction) {
685 focus_cycler_->RotateFocus(
686 direction == FORWARD ? internal::FocusCycler::FORWARD :
687 internal::FocusCycler::BACKWARD);
688}
689
[email protected]2e236a52012-06-27 22:21:47690void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44691 const gfx::Insets& insets) {
[email protected]6bdf7952012-11-14 10:10:58692 if (!display_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains, insets))
[email protected]1a2145b2012-03-13 21:09:17693 return;
[email protected]1a2145b2012-03-13 21:09:17694 FOR_EACH_OBSERVER(ShellObserver, observers_,
[email protected]2e236a52012-06-27 22:21:47695 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17696}
697
[email protected]82d3954ae2012-04-20 09:02:22698void Shell::OnLoginStateChanged(user::LoginStatus status) {
699 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
[email protected]16059276d2012-10-22 18:59:50700 RootWindowControllerList controllers = GetAllRootWindowControllers();
701 for (RootWindowControllerList::iterator iter = controllers.begin();
702 iter != controllers.end(); ++iter)
703 (*iter)->OnLoginStateChanged(status);
[email protected]82d3954ae2012-04-20 09:02:22704}
705
[email protected]88d71122012-10-18 07:11:01706void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50707 RootWindowControllerList controllers = GetAllRootWindowControllers();
708 for (RootWindowControllerList::iterator iter = controllers.begin();
709 iter != controllers.end(); ++iter)
710 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01711}
712
[email protected]82d3954ae2012-04-20 09:02:22713void Shell::OnAppTerminating() {
714 FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
715}
716
717void Shell::OnLockStateChanged(bool locked) {
718 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
719}
720
[email protected]d9456cb2012-03-21 16:41:04721void Shell::CreateLauncher() {
[email protected]a0afeb12012-12-10 22:57:09722 if (IsLauncherPerDisplayEnabled()) {
723 RootWindowControllerList controllers = GetAllRootWindowControllers();
724 for (RootWindowControllerList::iterator iter = controllers.begin();
725 iter != controllers.end(); ++iter)
[email protected]478c6c32013-03-09 02:50:58726 (*iter)->shelf()->CreateLauncher();
[email protected]a0afeb12012-12-10 22:57:09727 } else {
[email protected]478c6c32013-03-09 02:50:58728 GetPrimaryRootWindowController()->shelf()->CreateLauncher();
[email protected]a0afeb12012-12-10 22:57:09729 }
[email protected]d9456cb2012-03-21 16:41:04730}
731
[email protected]7e1df2f62012-07-19 19:17:18732void Shell::ShowLauncher() {
[email protected]bde8ae92012-12-15 17:08:18733 if (IsLauncherPerDisplayEnabled()) {
734 RootWindowControllerList controllers = GetAllRootWindowControllers();
735 for (RootWindowControllerList::iterator iter = controllers.begin();
736 iter != controllers.end(); ++iter)
737 (*iter)->ShowLauncher();
738 } else {
739 GetPrimaryRootWindowController()->ShowLauncher();
740 }
[email protected]7e1df2f62012-07-19 19:17:18741}
742
[email protected]1a2145b2012-03-13 21:09:17743void Shell::AddShellObserver(ShellObserver* observer) {
744 observers_.AddObserver(observer);
745}
746
747void Shell::RemoveShellObserver(ShellObserver* observer) {
748 observers_.RemoveObserver(observer);
749}
750
[email protected]c758fbf2012-03-25 22:53:59751void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33752 RootWindowControllerList controllers = GetAllRootWindowControllers();
753 for (RootWindowControllerList::iterator iter = controllers.begin();
754 iter != controllers.end(); ++iter)
755 if ((*iter)->shelf())
756 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59757}
758
[email protected]431552c2012-10-23 00:38:33759void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
760 aura::RootWindow* root_window) {
[email protected]478c6c32013-03-09 02:50:58761 ash::internal::ShelfLayoutManager::ForLauncher(root_window)->
762 SetAutoHideBehavior(behavior);
[email protected]c758fbf2012-03-25 22:53:59763}
764
[email protected]431552c2012-10-23 00:38:33765ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
766 aura::RootWindow* root_window) const {
[email protected]478c6c32013-03-09 02:50:58767 return ash::internal::ShelfLayoutManager::ForLauncher(root_window)->
768 auto_hide_behavior();
[email protected]c758fbf2012-03-25 22:53:59769}
770
[email protected]431552c2012-10-23 00:38:33771void Shell::SetShelfAlignment(ShelfAlignment alignment,
772 aura::RootWindow* root_window) {
[email protected]478c6c32013-03-09 02:50:58773 if (ash::internal::ShelfLayoutManager::ForLauncher(root_window)->
774 SetAlignment(alignment)) {
[email protected]f89f7512012-12-17 19:21:18775 FOR_EACH_OBSERVER(
776 ShellObserver, observers_, OnShelfAlignmentChanged(root_window));
777 }
[email protected]55444502012-05-10 15:43:53778}
779
[email protected]431552c2012-10-23 00:38:33780ShelfAlignment Shell::GetShelfAlignment(aura::RootWindow* root_window) {
[email protected]478c6c32013-03-09 02:50:58781 return GetRootWindowController(root_window)->
782 GetShelfLayoutManager()->GetAlignment();
[email protected]55444502012-05-10 15:43:53783}
784
[email protected]d90b8392012-06-13 09:34:56785void Shell::SetDimming(bool should_dim) {
[email protected]be65be362012-06-15 07:38:23786 RootWindowControllerList controllers = GetAllRootWindowControllers();
787 for (RootWindowControllerList::iterator iter = controllers.begin();
788 iter != controllers.end(); ++iter)
789 (*iter)->screen_dimmer()->SetDimming(should_dim);
[email protected]d90b8392012-06-13 09:34:56790}
791
[email protected]090c4f12012-10-29 18:56:42792void Shell::CreateModalBackground(aura::Window* window) {
[email protected]c0ce80e2012-10-05 23:28:27793 if (!modality_filter_.get()) {
794 modality_filter_.reset(new internal::SystemModalContainerEventFilter(this));
[email protected]304594c2012-11-13 16:35:27795 AddPreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27796 }
797 RootWindowControllerList controllers = GetAllRootWindowControllers();
798 for (RootWindowControllerList::iterator iter = controllers.begin();
799 iter != controllers.end(); ++iter)
[email protected]090c4f12012-10-29 18:56:42800 (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27801}
802
803void Shell::OnModalWindowRemoved(aura::Window* removed) {
804 RootWindowControllerList controllers = GetAllRootWindowControllers();
805 bool activated = false;
806 for (RootWindowControllerList::iterator iter = controllers.begin();
807 iter != controllers.end() && !activated; ++iter) {
[email protected]8674b312012-10-12 19:02:44808 activated = (*iter)->GetSystemModalLayoutManager(removed)->
809 ActivateNextModalWindow();
[email protected]c0ce80e2012-10-05 23:28:27810 }
811 if (!activated) {
[email protected]304594c2012-11-13 16:35:27812 RemovePreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27813 modality_filter_.reset();
814 for (RootWindowControllerList::iterator iter = controllers.begin();
815 iter != controllers.end(); ++iter)
[email protected]8674b312012-10-12 19:02:44816 (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27817 }
818}
819
[email protected]88d71122012-10-18 07:11:01820WebNotificationTray* Shell::GetWebNotificationTray() {
[email protected]478c6c32013-03-09 02:50:58821 return GetPrimaryRootWindowController()->shelf()->
822 status_area_widget()->web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28823}
824
[email protected]a0afeb12012-12-10 22:57:09825bool Shell::HasPrimaryStatusArea() {
[email protected]478c6c32013-03-09 02:50:58826 ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf();
827 return shelf && shelf->status_area_widget();
[email protected]31f19e32012-10-30 22:31:23828}
829
[email protected]a0afeb12012-12-10 22:57:09830SystemTray* Shell::GetPrimarySystemTray() {
831 return GetPrimaryRootWindowController()->GetSystemTray();
[email protected]aa54218b2012-06-12 16:51:42832}
833
[email protected]b913a3a2012-12-11 13:07:19834LauncherDelegate* Shell::GetLauncherDelegate() {
835 if (!launcher_delegate_.get()) {
836 launcher_model_.reset(new LauncherModel);
837 launcher_delegate_.reset(
838 delegate_->CreateLauncherDelegate(launcher_model_.get()));
839 }
840 return launcher_delegate_.get();
841}
842
[email protected]2e236a52012-06-27 22:21:47843void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) {
[email protected]8cfb6722012-11-28 03:28:46844 aura::client::SetFocusClient(root, focus_client_.get());
[email protected]cf1c70e2012-08-30 01:13:02845 internal::RootWindowController* controller =
846 new internal::RootWindowController(root);
847 controller->CreateContainers();
[email protected]bca9a7e2012-11-10 06:25:49848 // Pass false for the |is_first_run_after_boot| parameter so we'll show a
849 // black background on this display instead of trying to mimic the boot splash
850 // screen.
851 controller->CreateSystemBackground(false);
[email protected]cf1c70e2012-08-30 01:13:02852 InitRootWindowController(controller);
[email protected]16059276d2012-10-22 18:59:50853 if (IsLauncherPerDisplayEnabled())
854 controller->InitForPrimaryDisplay();
[email protected]cf1c70e2012-08-30 01:13:02855 controller->root_window_layout()->OnWindowResized();
856 desktop_background_controller_->OnRootWindowAdded(root);
[email protected]6b37addd2012-09-28 03:08:09857 high_contrast_controller_->OnRootWindowAdded(root);
[email protected]cf1c70e2012-08-30 01:13:02858 root->ShowRootWindow();
859 // Activate new root for testing.
860 active_root_window_ = root;
[email protected]a857dbe2012-05-30 22:10:14861}
862
[email protected]f9466702012-09-17 16:35:27863void Shell::DoInitialWorkspaceAnimation() {
864 return GetPrimaryRootWindowController()->workspace_controller()->
865 DoInitialAnimation();
866}
867
[email protected]be65be362012-06-15 07:38:23868void Shell::InitRootWindowController(
869 internal::RootWindowController* controller) {
870 aura::RootWindow* root_window = controller->root_window();
[email protected]39718b52012-12-03 17:24:56871 DCHECK(activation_client_);
[email protected]d90b8392012-06-13 09:34:56872 DCHECK(visibility_controller_.get());
873 DCHECK(drag_drop_controller_.get());
874 DCHECK(capture_controller_.get());
[email protected]8fef7432012-08-06 15:34:25875 DCHECK(window_cycle_controller_.get());
[email protected]d90b8392012-06-13 09:34:56876
[email protected]8cfb6722012-11-28 03:28:46877 aura::client::SetFocusClient(root_window, focus_client_.get());
[email protected]d90b8392012-06-13 09:34:56878 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
[email protected]39718b52012-12-03 17:24:56879 aura::client::SetActivationClient(root_window, activation_client_);
[email protected]052305f2012-12-05 18:53:04880 if (views::corewm::UseFocusController()) {
[email protected]39718b52012-12-03 17:24:56881 views::corewm::FocusController* controller =
882 static_cast<views::corewm::FocusController*>(activation_client_);
883 root_window->AddPreTargetHandler(controller);
884 }
[email protected]d90b8392012-06-13 09:34:56885 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
886 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:56887 aura::client::SetCaptureClient(root_window, capture_controller_.get());
[email protected]8d625fb2012-07-18 16:40:06888 aura::client::SetScreenPositionClient(root_window,
889 screen_position_controller_.get());
[email protected]4b8003c2012-07-26 00:54:19890 aura::client::SetCursorClient(root_window, &cursor_manager_);
[email protected]54a37cdc2012-07-25 19:16:01891 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:38892 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:56893
894 if (nested_dispatcher_controller_.get()) {
895 aura::client::SetDispatcherClient(root_window,
896 nested_dispatcher_controller_.get());
897 }
898 if (user_action_client_.get())
899 aura::client::SetUserActionClient(root_window, user_action_client_.get());
900
901 root_window->SetCursor(ui::kCursorPointer);
[email protected]be65be362012-06-15 07:38:23902 controller->InitLayoutManagers();
[email protected]f059c6942012-07-21 14:27:57903
904 // TODO(oshima): Move the instance to RootWindowController when
905 // the extended desktop is enabled by default.
906 internal::AlwaysOnTopController* always_on_top_controller =
907 new internal::AlwaysOnTopController;
[email protected]c96b9812012-10-17 16:04:04908 always_on_top_controller->SetAlwaysOnTopContainer(
[email protected]f059c6942012-07-21 14:27:57909 root_window->GetChildById(internal::kShellWindowId_AlwaysOnTopContainer));
910 root_window->SetProperty(internal::kAlwaysOnTopControllerKey,
911 always_on_top_controller);
[email protected]8674b312012-10-12 19:02:44912 if (GetPrimaryRootWindowController()->GetSystemModalLayoutManager(NULL)->
[email protected]c0ce80e2012-10-05 23:28:27913 has_modal_background()) {
[email protected]8674b312012-10-12 19:02:44914 controller->GetSystemModalLayoutManager(NULL)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27915 }
[email protected]8fef7432012-08-06 15:34:25916
917 window_cycle_controller_->OnRootWindowAdded(root_window);
[email protected]d90b8392012-06-13 09:34:56918}
919
[email protected]46ca3632011-11-03 03:33:42920////////////////////////////////////////////////////////////////////////////////
921// Shell, private:
922
[email protected]c0ce80e2012-10-05 23:28:27923bool Shell::CanWindowReceiveEvents(aura::Window* window) {
924 RootWindowControllerList controllers = GetAllRootWindowControllers();
925 for (RootWindowControllerList::iterator iter = controllers.begin();
926 iter != controllers.end(); ++iter) {
[email protected]8674b312012-10-12 19:02:44927 if ((*iter)->GetSystemModalLayoutManager(window)->
[email protected]c0ce80e2012-10-05 23:28:27928 CanWindowReceiveEvents(window)) {
929 return true;
930 }
931 }
932 return false;
933}
934
[email protected]049cf34b2012-12-07 17:15:48935////////////////////////////////////////////////////////////////////////////////
936// Shell, ui::EventTarget overrides:
937
[email protected]869f6352012-12-06 20:47:17938bool Shell::CanAcceptEvent(const ui::Event& event) {
[email protected]5097e692012-10-30 22:08:41939 return true;
940}
941
942ui::EventTarget* Shell::GetParentTarget() {
943 return NULL;
944}
945
[email protected]049cf34b2012-12-07 17:15:48946void Shell::OnEvent(ui::Event* event) {
[email protected]1ae361652012-12-12 22:39:51947}
948
949////////////////////////////////////////////////////////////////////////////////
950// Shell, aura::client::ActivationChangeObserver implementation:
951
952void Shell::OnWindowActivated(aura::Window* gained_active,
953 aura::Window* lost_active) {
[email protected]d219a192012-12-14 00:08:18954 if (gained_active)
955 active_root_window_ = gained_active->GetRootWindow();
[email protected]049cf34b2012-12-07 17:15:48956}
957
[email protected]55f593352011-12-24 05:42:46958} // namespace ash