blob: 078305c1aa975002e71d86a51d845b9946b73918 [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"
14#include "ash/desktop_background/desktop_background_resources.h"
15#include "ash/desktop_background/desktop_background_view.h"
[email protected]81abb1032012-11-13 18:55:4116#include "ash/desktop_background/user_wallpaper_delegate.h"
[email protected]2e236a52012-06-27 22:21:4717#include "ash/display/display_controller.h"
18#include "ash/display/mouse_cursor_event_filter.h"
[email protected]6bdf7952012-11-14 10:10:5819#include "ash/display/display_manager.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]f4c92b382012-08-28 00:59:5924#include "ash/magnifier/magnification_controller.h"
[email protected]d90b8392012-06-13 09:34:5625#include "ash/root_window_controller.h"
[email protected]1a2145b2012-03-13 21:09:1726#include "ash/screen_ash.h"
[email protected]b65bdda2011-12-23 23:35:3127#include "ash/shell_delegate.h"
28#include "ash/shell_factory.h"
29#include "ash/shell_window_ids.h"
[email protected]6d6546e2012-05-30 23:12:0230#include "ash/system/status_area_widget.h"
[email protected]51ed5992012-11-07 10:14:3931#include "ash/system/tray/system_tray_delegate.h"
[email protected]83b2b84c2012-11-14 01:11:0032#include "ash/system/tray/system_tray_notifier.h"
[email protected]2f744282011-12-23 22:40:5233#include "ash/tooltips/tooltip_controller.h"
[email protected]73074742012-05-17 01:44:4134#include "ash/touch/touch_observer_hud.h"
[email protected]7634f962011-12-23 21:35:5235#include "ash/wm/activation_controller.h"
[email protected]f059c6942012-07-21 14:27:5736#include "ash/wm/always_on_top_controller.h"
[email protected]0039db92012-05-09 04:11:4537#include "ash/wm/app_list_controller.h"
[email protected]8812588c2012-01-30 21:19:0338#include "ash/wm/base_layout_manager.h"
[email protected]60a978b72012-06-08 00:29:1839#include "ash/wm/capture_controller.h"
[email protected]88d71122012-10-18 07:11:0140#include "ash/wm/coordinate_conversion.h"
[email protected]9d4d1712012-03-06 06:55:2541#include "ash/wm/custom_frame_view_ash.h"
[email protected]57b8bb352012-01-11 05:11:4642#include "ash/wm/dialog_frame_view.h"
[email protected]262f8bd2012-03-23 19:30:2743#include "ash/wm/event_client_impl.h"
[email protected]b9d224c2012-07-13 01:09:0344#include "ash/wm/event_rewriter_event_filter.h"
[email protected]9ae32df2012-07-26 03:25:1845#include "ash/wm/overlay_event_filter.h"
[email protected]e0d22e82012-01-04 00:46:5746#include "ash/wm/power_button_controller.h"
[email protected]7ae525002012-07-26 23:55:1047#include "ash/wm/property_util.h"
[email protected]e4a181cc2012-03-17 02:20:5748#include "ash/wm/resize_shadow_controller.h"
[email protected]a3301dc2011-12-23 16:34:5149#include "ash/wm/root_window_layout_manager.h"
[email protected]42993212012-04-30 23:42:0450#include "ash/wm/screen_dimmer.h"
[email protected]222f40c2012-10-18 08:58:1351#include "ash/wm/session_state_controller.h"
[email protected]839667d62012-10-23 19:38:5752#include "ash/wm/session_state_controller_impl.h"
53#include "ash/wm/session_state_controller_impl2.h"
[email protected]75859672011-12-23 01:04:5654#include "ash/wm/stacking_controller.h"
[email protected]435b212e2012-04-05 19:43:3755#include "ash/wm/system_gesture_event_filter.h"
[email protected]c0ce80e2012-10-05 23:28:2756#include "ash/wm/system_modal_container_event_filter.h"
[email protected]4244d6992012-01-23 17:14:3357#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]c16b9422012-06-06 21:51:1158#include "ash/wm/user_activity_detector.h"
[email protected]9633a9d22012-01-21 16:40:5859#include "ash/wm/video_detector.h"
[email protected]ddd91e92012-01-27 16:03:4860#include "ash/wm/visibility_controller.h"
[email protected]40c4cbb2012-01-10 23:26:0761#include "ash/wm/window_cycle_controller.h"
[email protected]80373572012-01-06 23:14:3062#include "ash/wm/window_modality_controller.h"
[email protected]f059c6942012-07-21 14:27:5763#include "ash/wm/window_properties.h"
[email protected]f4c92b382012-08-28 00:59:5964#include "ash/wm/window_util.h"
[email protected]c7839552012-04-03 21:14:3665#include "ash/wm/workspace_controller.h"
[email protected]f296be72011-10-11 15:40:0066#include "base/bind.h"
[email protected]46ca3632011-11-03 03:33:4267#include "base/command_line.h"
[email protected]b0a8faa2012-10-19 03:22:2268#include "base/debug/leak_annotations.h"
[email protected]2c456102011-12-26 06:26:3469#include "ui/aura/client/aura_constants.h"
[email protected]d8f10042012-11-14 01:10:4670#include "ui/aura/client/stacking_client.h"
[email protected]c28853612012-05-31 22:43:4471#include "ui/aura/client/user_action_client.h"
[email protected]8a45c972012-03-14 18:22:4472#include "ui/aura/env.h"
[email protected]a857dbe2012-05-30 22:10:1473#include "ui/aura/focus_manager.h"
[email protected]4bb16502011-12-06 14:44:5874#include "ui/aura/layout_manager.h"
[email protected]2c456102011-12-26 06:26:3475#include "ui/aura/root_window.h"
[email protected]536f8082012-03-16 09:30:3376#include "ui/aura/ui_controls_aura.h"
[email protected]87b0d82e2011-10-07 21:02:5977#include "ui/aura/window.h"
[email protected]116302fc2012-05-05 21:45:4178#include "ui/compositor/layer.h"
79#include "ui/compositor/layer_animator.h"
[email protected]7da9c4c2012-06-12 14:43:0180#include "ui/gfx/display.h"
[email protected]9ec0f452012-05-31 15:58:5381#include "ui/gfx/image/image_skia.h"
[email protected]b82c42c42012-04-25 20:03:4182#include "ui/gfx/screen.h"
[email protected]b0639282011-12-22 21:12:2783#include "ui/gfx/size.h"
[email protected]536f8082012-03-16 09:30:3384#include "ui/ui_controls/ui_controls.h"
[email protected]4a59e4e2012-11-12 21:15:4085#include "ui/views/corewm/compound_event_filter.h"
86#include "ui/views/corewm/input_method_event_filter.h"
[email protected]86f2b5e2012-11-14 20:37:0087#include "ui/views/corewm/shadow_controller.h"
[email protected]e7293fa2012-05-17 04:42:3388#include "ui/views/focus/focus_manager_factory.h"
[email protected]c13be0d2011-11-22 02:09:5889#include "ui/views/widget/native_widget_aura.h"
90#include "ui/views/widget/widget.h"
[email protected]87b0d82e2011-10-07 21:02:5991
[email protected]6e9f6aa2012-02-09 04:16:2092#if !defined(OS_MACOSX)
93#include "ash/accelerators/accelerator_controller.h"
94#include "ash/accelerators/accelerator_filter.h"
95#include "ash/accelerators/nested_dispatcher_controller.h"
96#endif
97
[email protected]70b3e7d52012-06-02 22:12:2598#if defined(OS_CHROMEOS)
[email protected]6bdf7952012-11-14 10:10:5899#include "ash/display/display_change_observer_x11.h"
[email protected]196e9452012-08-01 06:42:51100#include "ash/display/output_configurator_animation.h"
[email protected]6bdf7952012-11-14 10:10:58101#include "base/chromeos/chromeos_version.h"
[email protected]4168ad72012-08-30 16:57:21102#include "base/message_pump_aurax11.h"
[email protected]2e236a52012-06-27 22:21:47103#include "chromeos/display/output_configurator.h"
[email protected]7158db12012-10-15 22:19:31104#include "content/public/browser/gpu_data_manager.h"
105#include "content/public/common/gpu_feature_type.h"
[email protected]70b3e7d52012-06-02 22:12:25106#endif // defined(OS_CHROMEOS)
107
[email protected]55f593352011-12-24 05:42:46108namespace ash {
[email protected]87b0d82e2011-10-07 21:02:59109
110namespace {
[email protected]671a2ae2011-10-13 21:53:23111
[email protected]615922f2012-02-07 02:41:15112using aura::Window;
[email protected]3f02dc52011-10-21 19:36:45113using views::Widget;
114
[email protected]10b22612012-03-22 17:07:55115// This dummy class is used for shell unit tests. We dont have chrome delegate
116// in these tests.
[email protected]5c543242012-03-24 16:25:42117class DummyUserWallpaperDelegate : public UserWallpaperDelegate {
[email protected]10b22612012-03-22 17:07:55118 public:
119 DummyUserWallpaperDelegate() {}
120
121 virtual ~DummyUserWallpaperDelegate() {}
122
[email protected]815d0c382012-07-21 08:13:44123 virtual ash::WindowVisibilityAnimationType GetAnimationType() OVERRIDE {
124 return WINDOW_VISIBILITY_ANIMATION_TYPE_FADE;
125 }
126
[email protected]bca9a7e2012-11-10 06:25:49127 virtual bool ShouldShowInitialAnimation() OVERRIDE {
128 return false;
129 }
130
[email protected]c10baf72012-11-01 18:24:32131 virtual void UpdateWallpaper() OVERRIDE {
132 }
133
[email protected]0c4f87d2012-06-12 02:00:35134 virtual void InitializeWallpaper() OVERRIDE {
[email protected]d50034732012-06-04 19:11:04135 ash::Shell::GetInstance()->desktop_background_controller()->
136 CreateEmptyWallpaper();
[email protected]10b22612012-03-22 17:07:55137 }
138
[email protected]5c543242012-03-24 16:25:42139 virtual void OpenSetWallpaperPage() OVERRIDE {
140 }
141
[email protected]0cfc18e2012-04-11 18:17:47142 virtual bool CanOpenSetWallpaperPage() OVERRIDE {
143 return false;
144 }
145
[email protected]07a2fa62012-06-26 10:39:38146 virtual void OnWallpaperAnimationFinished() OVERRIDE {
147 }
148
[email protected]8b04a1652012-08-04 02:59:49149 virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
150 }
151
[email protected]10b22612012-03-22 17:07:55152 private:
[email protected]0039db92012-05-09 04:11:45153 DISALLOW_COPY_AND_ASSIGN(DummyUserWallpaperDelegate);
[email protected]10b22612012-03-22 17:07:55154};
155
[email protected]87b0d82e2011-10-07 21:02:59156} // namespace
157
[email protected]cac10fc62011-10-07 23:22:56158// static
159Shell* Shell::instance_ = NULL;
[email protected]2b4cd302012-02-24 20:21:13160// static
[email protected]9488d4d2012-02-29 18:32:37161bool Shell::initially_hide_cursor_ = false;
[email protected]2b4cd302012-02-24 20:21:13162
163////////////////////////////////////////////////////////////////////////////////
164// Shell::TestApi
165
166Shell::TestApi::TestApi(Shell* shell) : shell_(shell) {}
167
[email protected]2b4cd302012-02-24 20:21:13168internal::RootWindowLayoutManager* Shell::TestApi::root_window_layout() {
[email protected]d90b8392012-06-13 09:34:56169 return shell_->GetPrimaryRootWindowController()->root_window_layout();
[email protected]2b4cd302012-02-24 20:21:13170}
[email protected]cac10fc62011-10-07 23:22:56171
[email protected]4a59e4e2012-11-12 21:15:40172views::corewm::InputMethodEventFilter*
[email protected]0e46c272012-05-15 18:15:23173 Shell::TestApi::input_method_event_filter() {
[email protected]db9131602012-02-29 19:06:32174 return shell_->input_method_filter_.get();
175}
176
[email protected]435b212e2012-04-05 19:43:37177internal::SystemGestureEventFilter*
178 Shell::TestApi::system_gesture_event_filter() {
179 return shell_->system_gesture_filter_.get();
180}
181
[email protected]db9131602012-02-29 19:06:32182internal::WorkspaceController* Shell::TestApi::workspace_controller() {
[email protected]d90b8392012-06-13 09:34:56183 return shell_->GetPrimaryRootWindowController()->workspace_controller();
[email protected]db9131602012-02-29 19:06:32184}
185
[email protected]9737f8f2012-09-20 03:38:38186internal::ScreenPositionController*
187 Shell::TestApi::screen_position_controller() {
188 return shell_->screen_position_controller_.get();
189}
190
[email protected]cac10fc62011-10-07 23:22:56191////////////////////////////////////////////////////////////////////////////////
192// Shell, public:
193
[email protected]3266c2b92011-11-14 00:06:08194Shell::Shell(ShellDelegate* delegate)
[email protected]d90b8392012-06-13 09:34:56195 : screen_(new ScreenAsh),
[email protected]be65be362012-06-15 07:38:23196 active_root_window_(NULL),
[email protected]9c66adc2012-01-05 02:10:16197 delegate_(delegate),
[email protected]70b3e7d52012-06-02 22:12:25198#if defined(OS_CHROMEOS)
[email protected]cf1c70e2012-08-30 01:13:02199 output_configurator_(new chromeos::OutputConfigurator()),
[email protected]196e9452012-08-01 06:42:51200 output_configurator_animation_(
201 new internal::OutputConfiguratorAnimation()),
[email protected]70b3e7d52012-06-02 22:12:25202#endif // defined(OS_CHROMEOS)
[email protected]852a55d2012-10-17 13:30:30203 browser_context_(NULL),
204 simulate_modal_window_open_for_testing_(false) {
[email protected]02dbd1a2012-11-08 22:50:13205 DCHECK(delegate_.get());
[email protected]6bdf7952012-11-14 10:10:58206 display_manager_.reset(new internal::DisplayManager);
[email protected]b0a8faa2012-10-19 03:22:22207 ANNOTATE_LEAKING_OBJECT_PTR(screen_); // see crbug.com/156466
[email protected]b0a8faa2012-10-19 03:22:22208 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_);
[email protected]5fdb45b2012-10-23 20:26:28209 if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE))
210 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_);
[email protected]054b2d72012-06-08 04:52:25211 ui_controls::InstallUIControlsAura(internal::CreateUIControls());
[email protected]70b3e7d52012-06-02 22:12:25212#if defined(OS_CHROMEOS)
[email protected]7158db12012-10-15 22:19:31213 content::GpuFeatureType blacklisted_features =
214 content::GpuDataManager::GetInstance()->GetBlacklistedFeatures();
215 bool is_panel_fitting_disabled =
216 (blacklisted_features & content::GPU_FEATURE_TYPE_PANEL_FITTING) ||
217 CommandLine::ForCurrentProcess()->HasSwitch(
218 switches::kAshDisablePanelFitting);
219 output_configurator_->Init(!is_panel_fitting_disabled);
220
[email protected]196e9452012-08-01 06:42:51221 output_configurator_->AddObserver(output_configurator_animation_.get());
[email protected]4168ad72012-08-30 16:57:21222 base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow(
223 output_configurator());
[email protected]70b3e7d52012-06-02 22:12:25224#endif // defined(OS_CHROMEOS)
[email protected]87b0d82e2011-10-07 21:02:59225}
226
227Shell::~Shell() {
[email protected]e7293fa2012-05-17 04:42:33228 views::FocusManagerFactory::Install(NULL);
[email protected]cb3b8b22012-06-27 23:26:37229
230 // Remove the focus from any window. This will prevent overhead and side
231 // effects (e.g. crashes) from changing focus during shutdown.
232 // See bug crbug.com/134502.
233 if (active_root_window_)
234 active_root_window_->GetFocusManager()->SetFocusedWindow(NULL, NULL);
235
[email protected]9861f1752012-06-01 07:16:14236 // Please keep in same order as in Init() because it's easy to miss one.
[email protected]304594c2012-11-13 16:35:27237 RemovePreTargetHandler(user_activity_detector_.get());
238 RemovePreTargetHandler(event_rewriter_filter_.get());
239 RemovePreTargetHandler(overlay_filter_.get());
240 RemovePreTargetHandler(input_method_filter_.get());
241 RemovePreTargetHandler(window_modality_controller_.get());
[email protected]78d96302012-06-22 00:58:07242 if (mouse_cursor_filter_.get())
[email protected]304594c2012-11-13 16:35:27243 RemovePreTargetHandler(mouse_cursor_filter_.get());
[email protected]f9f017c2012-11-12 19:05:17244 RemovePreTargetHandler(system_gesture_filter_.get());
[email protected]6e9f6aa2012-02-09 04:16:20245#if !defined(OS_MACOSX)
[email protected]f9f017c2012-11-12 19:05:17246 RemovePreTargetHandler(accelerator_filter_.get());
[email protected]6e9f6aa2012-02-09 04:16:20247#endif
[email protected]73074742012-05-17 01:44:41248 if (touch_observer_hud_.get())
[email protected]f9f017c2012-11-12 19:05:17249 RemovePreTargetHandler(touch_observer_hud_.get());
[email protected]745816be2011-11-22 05:08:30250
[email protected]931f4f42012-02-10 23:49:42251 // TooltipController is deleted with the Shell so removing its references.
[email protected]304594c2012-11-13 16:35:27252 RemovePreTargetHandler(tooltip_controller_.get());
[email protected]ef589af2011-12-03 01:07:15253
[email protected]f5f3c752012-06-07 05:16:02254 // AppList needs to be released before shelf layout manager, which is
255 // destroyed with launcher container in the loop below. However, app list
256 // container is now on top of launcher container and released after it.
257 // TODO(xiyuan): Move it back when app list container is no longer needed.
258 app_list_controller_.reset();
259
[email protected]51ed5992012-11-07 10:14:39260 // Destroy SystemTrayDelegate before destroying the status area(s).
261 system_tray_delegate_.reset();
262
[email protected]83b2b84c2012-11-14 01:11:00263 // Destroy SystemTrayNotifier immediately after destroying SystemTrayDelegate
264 // so that it is still available when shutting down the UI, but not after
265 // the notifier observers have been destroyed.
266 system_tray_notifier_.reset();
267
[email protected]be65be362012-06-15 07:38:23268 // Destroy all child windows including widgets.
[email protected]2e236a52012-06-27 22:21:47269 display_controller_->CloseChildWindows();
[email protected]ef589af2011-12-03 01:07:15270
[email protected]40c4cbb2012-01-10 23:26:07271 // These need a valid Shell instance to clean up properly, so explicitly
272 // delete them before invalidating the instance.
[email protected]58482fa2012-03-02 14:57:39273 // Alphabetical.
[email protected]084b6bb2011-11-17 05:18:16274 drag_drop_controller_.reset();
[email protected]c1c670172012-04-26 04:20:26275 magnification_controller_.reset();
[email protected]aa476502012-05-01 18:03:19276 power_button_controller_.reset();
[email protected]222f40c2012-10-18 08:58:13277 session_state_controller_.reset();
[email protected]e4a181cc2012-03-17 02:20:57278 resize_shadow_controller_.reset();
[email protected]58482fa2012-03-02 14:57:39279 shadow_controller_.reset();
[email protected]fd162f72012-04-14 03:24:53280 tooltip_controller_.reset();
[email protected]e67291f12012-10-10 05:52:38281 event_client_.reset();
[email protected]aa476502012-05-01 18:03:19282 window_cycle_controller_.reset();
[email protected]60a978b72012-06-08 00:29:18283 capture_controller_.reset();
[email protected]60a978b72012-06-08 00:29:18284 nested_dispatcher_controller_.reset();
[email protected]60a978b72012-06-08 00:29:18285 user_action_client_.reset();
[email protected]60a978b72012-06-08 00:29:18286 visibility_controller_.reset();
[email protected]084b6bb2011-11-17 05:18:16287
[email protected]be65be362012-06-15 07:38:23288 // This also deletes all RootWindows.
[email protected]2e236a52012-06-27 22:21:47289 display_controller_.reset();
[email protected]8d625fb2012-07-18 16:40:06290 screen_position_controller_.reset();
[email protected]d90b8392012-06-13 09:34:56291
[email protected]764864e2012-06-11 19:16:16292 // Delete the activation controller after other controllers and launcher
293 // because they might have registered ActivationChangeObserver.
[email protected]764864e2012-06-11 19:16:16294 activation_controller_.reset();
295
[email protected]488b42042011-11-15 00:20:18296 DCHECK(instance_ == this);
297 instance_ = NULL;
[email protected]70b3e7d52012-06-02 22:12:25298
299#if defined(OS_CHROMEOS)
[email protected]196e9452012-08-01 06:42:51300 output_configurator_->RemoveObserver(output_configurator_animation_.get());
[email protected]4168ad72012-08-30 16:57:21301 base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow(
302 output_configurator());
[email protected]70b3e7d52012-06-02 22:12:25303#endif // defined(OS_CHROMEOS)
[email protected]87b0d82e2011-10-07 21:02:59304}
305
[email protected]cac10fc62011-10-07 23:22:56306// static
[email protected]3266c2b92011-11-14 00:06:08307Shell* Shell::CreateInstance(ShellDelegate* delegate) {
308 CHECK(!instance_);
309 instance_ = new Shell(delegate);
310 instance_->Init();
311 return instance_;
312}
313
314// static
[email protected]cac10fc62011-10-07 23:22:56315Shell* Shell::GetInstance() {
[email protected]3266c2b92011-11-14 00:06:08316 DCHECK(instance_);
[email protected]cac10fc62011-10-07 23:22:56317 return instance_;
318}
319
[email protected]6377a002011-11-10 20:26:47320// static
[email protected]b3b7bcd2012-03-06 19:35:45321bool Shell::HasInstance() {
322 return !!instance_;
323}
324
325// static
[email protected]ef589af2011-12-03 01:07:15326void Shell::DeleteInstance() {
[email protected]6377a002011-11-10 20:26:47327 delete instance_;
328 instance_ = NULL;
329}
330
[email protected]e73bd7802012-02-17 20:10:34331// static
[email protected]d90b8392012-06-13 09:34:56332internal::RootWindowController* Shell::GetPrimaryRootWindowController() {
[email protected]7ae525002012-07-26 23:55:10333 return GetRootWindowController(GetPrimaryRootWindow());
[email protected]be65be362012-06-15 07:38:23334}
335
336// static
337Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
[email protected]2e236a52012-06-27 22:21:47338 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23339 GetAllRootWindowControllers();
[email protected]d90b8392012-06-13 09:34:56340}
341
342// static
[email protected]42713f72012-05-25 00:41:50343aura::RootWindow* Shell::GetPrimaryRootWindow() {
[email protected]2e236a52012-06-27 22:21:47344 return GetInstance()->display_controller()->GetPrimaryRootWindow();
[email protected]e73bd7802012-02-17 20:10:34345}
346
[email protected]7b0f7502012-06-11 00:12:39347// static
[email protected]a857dbe2012-05-30 22:10:14348aura::RootWindow* Shell::GetActiveRootWindow() {
349 return GetInstance()->active_root_window_;
350}
351
[email protected]7b0f7502012-06-11 00:12:39352// static
[email protected]ffabb1e2012-10-12 19:51:17353gfx::Screen* Shell::GetScreen() {
[email protected]5fdb45b2012-10-23 20:26:28354 return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE);
[email protected]ffabb1e2012-10-12 19:51:17355}
356
357// static
[email protected]be65be362012-06-15 07:38:23358Shell::RootWindowList Shell::GetAllRootWindows() {
[email protected]2e236a52012-06-27 22:21:47359 return Shell::GetInstance()->display_controller()->
[email protected]be65be362012-06-15 07:38:23360 GetAllRootWindows();
361}
362
363// static
[email protected]7b0f7502012-06-11 00:12:39364aura::Window* Shell::GetContainer(aura::RootWindow* root_window,
365 int container_id) {
366 return root_window->GetChildById(container_id);
367}
368
369// static
[email protected]e67291f12012-10-10 05:52:38370const aura::Window* Shell::GetContainer(const aura::RootWindow* root_window,
371 int container_id) {
372 return root_window->GetChildById(container_id);
373}
374
375// static
[email protected]7b0f7502012-06-11 00:12:39376std::vector<aura::Window*> Shell::GetAllContainers(int container_id) {
[email protected]7b0f7502012-06-11 00:12:39377 std::vector<aura::Window*> containers;
[email protected]001272f2012-11-02 20:05:23378 RootWindowList root_windows = GetAllRootWindows();
379 for (RootWindowList::const_iterator it = root_windows.begin();
380 it != root_windows.end(); ++it) {
381 aura::Window* container = (*it)->GetChildById(container_id);
382 if (container)
383 containers.push_back(container);
384 }
[email protected]7b0f7502012-06-11 00:12:39385 return containers;
386}
387
[email protected]e74aaf0a2012-10-12 18:42:28388// static
389bool Shell::IsLauncherPerDisplayEnabled() {
390 CommandLine* command_line = CommandLine::ForCurrentProcess();
391 return command_line->HasSwitch(switches::kAshLauncherPerDisplay);
392}
393
[email protected]87b0d82e2011-10-07 21:02:59394void Shell::Init() {
[email protected]6bdf7952012-11-14 10:10:58395#if defined(OS_CHROMEOS)
396 if (base::chromeos::IsRunningOnChromeOS()) {
397 display_change_observer_.reset(new internal::DisplayChangeObserverX11);
398 display_change_observer_->NotifyDisplayChange();
399 }
400#endif
401
[email protected]c9301e32012-05-23 08:34:58402 // Install the custom factory first so that views::FocusManagers for Tray,
403 // Launcher, and WallPaper could be created by the factory.
404 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
405
[email protected]4a59e4e2012-11-12 21:15:40406 env_filter_.reset(new views::corewm::CompoundEventFilter);
[email protected]304594c2012-11-13 16:35:27407 AddPreTargetHandler(env_filter_.get());
[email protected]1aad3322012-06-06 06:37:09408
[email protected]a857dbe2012-05-30 22:10:14409 focus_manager_.reset(new aura::FocusManager);
[email protected]be65be362012-06-15 07:38:23410 activation_controller_.reset(
411 new internal::ActivationController(focus_manager_.get()));
412
[email protected]e74aaf0a2012-10-12 18:42:28413 focus_cycler_.reset(new internal::FocusCycler());
414
[email protected]8d625fb2012-07-18 16:40:06415 screen_position_controller_.reset(new internal::ScreenPositionController);
[email protected]edbfb8d2012-09-03 08:33:43416 display_controller_.reset(new DisplayController);
[email protected]2e236a52012-06-27 22:21:47417 display_controller_->InitPrimaryDisplay();
418 aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow();
[email protected]be65be362012-06-15 07:38:23419 active_root_window_ = root_window;
[email protected]a857dbe2012-05-30 22:10:14420
[email protected]151ffdff2012-09-11 20:18:35421 cursor_manager_.SetDeviceScaleFactor(
422 root_window->AsRootWindowHostDelegate()->GetDeviceScaleFactor());
423
[email protected]58482fa2012-03-02 14:57:39424#if !defined(OS_MACOSX)
425 nested_dispatcher_controller_.reset(new NestedDispatcherController);
426 accelerator_controller_.reset(new AcceleratorController);
427#endif
[email protected]58482fa2012-03-02 14:57:39428
[email protected]c16b9422012-06-06 21:51:11429 // The order in which event filters are added is significant.
[email protected]c16b9422012-06-06 21:51:11430 user_activity_detector_.reset(new UserActivityDetector);
[email protected]304594c2012-11-13 16:35:27431 AddPreTargetHandler(user_activity_detector_.get());
[email protected]c16b9422012-06-06 21:51:11432
[email protected]b9d224c2012-07-13 01:09:03433 event_rewriter_filter_.reset(new internal::EventRewriterEventFilter);
[email protected]304594c2012-11-13 16:35:27434 AddPreTargetHandler(event_rewriter_filter_.get());
[email protected]0b0b0742012-02-16 13:23:45435
[email protected]9ae32df2012-07-26 03:25:18436 overlay_filter_.reset(new internal::OverlayEventFilter);
[email protected]304594c2012-11-13 16:35:27437 AddPreTargetHandler(overlay_filter_.get());
[email protected]9ae32df2012-07-26 03:25:18438 AddShellObserver(overlay_filter_.get());
[email protected]0b0b0742012-02-16 13:23:45439
[email protected]4a59e4e2012-11-12 21:15:40440 input_method_filter_.reset(new views::corewm::InputMethodEventFilter);
[email protected]304594c2012-11-13 16:35:27441 AddPreTargetHandler(input_method_filter_.get());
[email protected]c16b9422012-06-06 21:51:11442
[email protected]21472b12012-02-17 00:30:05443#if !defined(OS_MACOSX)
444 accelerator_filter_.reset(new internal::AcceleratorFilter);
[email protected]f9f017c2012-11-12 19:05:17445 AddPreTargetHandler(accelerator_filter_.get());
[email protected]21472b12012-02-17 00:30:05446#endif
[email protected]fcbbf082012-01-20 06:07:15447
[email protected]435b212e2012-04-05 19:43:37448 system_gesture_filter_.reset(new internal::SystemGestureEventFilter);
[email protected]f9f017c2012-11-12 19:05:17449 AddPreTargetHandler(system_gesture_filter_.get());
[email protected]435b212e2012-04-05 19:43:37450
[email protected]60a978b72012-06-08 00:29:18451 capture_controller_.reset(new internal::CaptureController);
[email protected]87b0d82e2011-10-07 21:02:59452
[email protected]871e9cc2012-06-17 22:41:55453 internal::RootWindowController* root_window_controller =
454 new internal::RootWindowController(root_window);
455 root_window_controller->CreateContainers();
[email protected]697f04c2012-10-03 01:15:10456 root_window_controller->CreateSystemBackground(
[email protected]02dbd1a2012-11-08 22:50:13457 delegate_->IsFirstRunAfterBoot());
[email protected]871e9cc2012-06-17 22:41:55458
[email protected]73074742012-05-17 01:44:41459 CommandLine* command_line = CommandLine::ForCurrentProcess();
460
461 if (command_line->HasSwitch(switches::kAshTouchHud)) {
462 touch_observer_hud_.reset(new internal::TouchObserverHUD);
[email protected]f9f017c2012-11-12 19:05:17463 AddPreTargetHandler(touch_observer_hud_.get());
[email protected]73074742012-05-17 01:44:41464 }
[email protected]d90b8392012-06-13 09:34:56465
[email protected]8b7ba87b2012-09-01 00:40:40466 mouse_cursor_filter_.reset(new internal::MouseCursorEventFilter());
[email protected]304594c2012-11-13 16:35:27467 AddPreTargetHandler(mouse_cursor_filter_.get());
[email protected]0518d0d2012-08-26 11:59:04468
[email protected]d90b8392012-06-13 09:34:56469 // Create Controllers that may need root window.
470 // TODO(oshima): Move as many controllers before creating
471 // RootWindowController as possible.
[email protected]d8f10042012-11-14 01:10:46472 stacking_client_.reset(delegate_->CreateStackingClient());
473 if (stacking_client_.get())
474 aura::client::SetStackingClient(stacking_client_.get());
[email protected]d90b8392012-06-13 09:34:56475 visibility_controller_.reset(new internal::VisibilityController);
476 drag_drop_controller_.reset(new internal::DragDropController);
[email protected]02dbd1a2012-11-08 22:50:13477 user_action_client_.reset(delegate_->CreateUserActionClient());
[email protected]d90b8392012-06-13 09:34:56478 window_modality_controller_.reset(new internal::WindowModalityController);
[email protected]304594c2012-11-13 16:35:27479 AddPreTargetHandler(window_modality_controller_.get());
[email protected]488b42042011-11-15 00:20:18480
[email protected]9613eacf2012-06-22 02:18:05481 magnification_controller_.reset(
482 internal::MagnificationController::CreateInstance());
483
[email protected]d90b8392012-06-13 09:34:56484 high_contrast_controller_.reset(new HighContrastController);
485 video_detector_.reset(new VideoDetector);
[email protected]8fef7432012-08-06 15:34:25486 window_cycle_controller_.reset(
487 new WindowCycleController(activation_controller_.get()));
[email protected]b0079a92012-01-25 20:13:38488
[email protected]54a37cdc2012-07-25 19:16:01489 tooltip_controller_.reset(new internal::TooltipController(
490 drag_drop_controller_.get()));
[email protected]304594c2012-11-13 16:35:27491 AddPreTargetHandler(tooltip_controller_.get());
[email protected]54a37cdc2012-07-25 19:16:01492
[email protected]e67291f12012-10-10 05:52:38493 event_client_.reset(new internal::EventClientImpl);
494
[email protected]be65be362012-06-15 07:38:23495 InitRootWindowController(root_window_controller);
[email protected]262f8bd2012-03-23 19:30:27496
[email protected]36f566532012-09-19 04:07:24497 // This controller needs to be set before SetupManagedWindowMode.
498 desktop_background_controller_.reset(new DesktopBackgroundController());
[email protected]02dbd1a2012-11-08 22:50:13499 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
[email protected]36f566532012-09-19 04:07:24500 if (!user_wallpaper_delegate_.get())
501 user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate());
502
[email protected]f4c92b382012-08-28 00:59:59503 // StatusAreaWidget uses Shell's CapsLockDelegate.
[email protected]02dbd1a2012-11-08 22:50:13504 caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());
[email protected]f4c92b382012-08-28 00:59:59505
[email protected]e4a181cc2012-03-17 02:20:57506 if (!command_line->HasSwitch(switches::kAuraNoShadows)) {
507 resize_shadow_controller_.reset(new internal::ResizeShadowController());
[email protected]86f2b5e2012-11-14 20:37:00508 shadow_controller_.reset(
509 new views::corewm::ShadowController(GetPrimaryRootWindow()));
[email protected]e4a181cc2012-03-17 02:20:57510 }
[email protected]a54e65b2011-11-21 22:03:34511
[email protected]83b2b84c2012-11-14 01:11:00512 // Create system_tray_notifier_ before the delegate.
513 system_tray_notifier_.reset(new ash::SystemTrayNotifier());
514
[email protected]51ed5992012-11-07 10:14:39515 // Initialize system_tray_delegate_ before initializing StatusAreaWidget.
[email protected]02dbd1a2012-11-08 22:50:13516 system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate());
[email protected]51ed5992012-11-07 10:14:39517 if (!system_tray_delegate_.get())
518 system_tray_delegate_.reset(SystemTrayDelegate::CreateDummyDelegate());
519
520 // Creates StatusAreaWidget.
[email protected]e74aaf0a2012-10-12 18:42:28521 root_window_controller->InitForPrimaryDisplay();
[email protected]3d29912a2012-02-07 07:41:51522
[email protected]51ed5992012-11-07 10:14:39523 // Initialize system_tray_delegate_ after StatusAreaWidget is created.
524 system_tray_delegate_->Initialize();
525
[email protected]16059276d2012-10-22 18:59:50526 display_controller_->InitSecondaryDisplays();
527
[email protected]d90b8392012-06-13 09:34:56528 // Force Layout
[email protected]be65be362012-06-15 07:38:23529 root_window_controller->root_window_layout()->OnWindowResized();
[email protected]084b6bb2011-11-17 05:18:16530
[email protected]60b5b862012-04-27 18:56:34531 // It needs to be created after OnWindowResized has been called, otherwise the
[email protected]5f2391ea2012-09-12 23:46:49532 // widget will not paint when restoring after a browser crash. Also it needs
533 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
534 // the correct size.
[email protected]0c4f87d2012-06-12 02:00:35535 user_wallpaper_delegate_->InitializeWallpaper();
[email protected]60b5b862012-04-27 18:56:34536
[email protected]839667d62012-10-23 19:38:57537 if (command_line->HasSwitch(ash::switches::kAshNewLockAnimationsEnabled))
538 session_state_controller_.reset(new SessionStateControllerImpl2);
539 else
540 session_state_controller_.reset(new SessionStateControllerImpl);
[email protected]222f40c2012-10-18 08:58:13541 power_button_controller_.reset(new PowerButtonController(
542 session_state_controller_.get()));
543 AddShellObserver(session_state_controller_.get());
[email protected]d90b8392012-06-13 09:34:56544
545 if (initially_hide_cursor_)
[email protected]4b8003c2012-07-26 00:54:19546 cursor_manager_.ShowCursor(false);
[email protected]0ad9b762012-09-28 04:22:09547
548 // Cursor might have been hidden by somethign other than chrome.
549 // Let the first mouse event show the cursor.
550 env_filter_->set_cursor_hidden_by_filter(true);
[email protected]87b0d82e2011-10-07 21:02:59551}
552
[email protected]431552c2012-10-23 00:38:33553void Shell::ShowContextMenu(const gfx::Point& location_in_screen) {
[email protected]f60c6232012-08-24 18:55:03554 // No context menus if user have not logged in.
[email protected]02dbd1a2012-11-08 22:50:13555 if (!delegate_->IsUserLoggedIn())
[email protected]f60c6232012-08-24 18:55:03556 return;
557 // No context menus when screen is locked.
558 if (IsScreenLocked())
559 return;
[email protected]431552c2012-10-23 00:38:33560
[email protected]88d71122012-10-18 07:11:01561 aura::RootWindow* root =
[email protected]431552c2012-10-23 00:38:33562 wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size()));
563 GetRootWindowController(root)->ShowContextMenu(location_in_screen);
[email protected]46ca3632011-11-03 03:33:42564}
565
[email protected]ae4987d2011-11-21 22:52:44566void Shell::ToggleAppList() {
[email protected]0039db92012-05-09 04:11:45567 if (!app_list_controller_.get())
568 app_list_controller_.reset(new internal::AppListController);
569 app_list_controller_->SetVisible(!app_list_controller_->IsVisible());
[email protected]ae4987d2011-11-21 22:52:44570}
571
[email protected]7510d1082012-03-30 21:58:34572bool Shell::GetAppListTargetVisibility() const {
[email protected]0039db92012-05-09 04:11:45573 return app_list_controller_.get() &&
574 app_list_controller_->GetTargetVisibility();
[email protected]7510d1082012-03-30 21:58:34575}
576
[email protected]1e51a9d2012-04-09 23:31:11577aura::Window* Shell::GetAppListWindow() {
[email protected]0039db92012-05-09 04:11:45578 return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
[email protected]1e51a9d2012-04-09 23:31:11579}
580
[email protected]f7eb89c2011-12-13 09:48:54581bool Shell::IsScreenLocked() const {
[email protected]02dbd1a2012-11-08 22:50:13582 return delegate_->IsScreenLocked();
[email protected]f7eb89c2011-12-13 09:48:54583}
584
[email protected]40c4cbb2012-01-10 23:26:07585bool Shell::IsModalWindowOpen() const {
[email protected]852a55d2012-10-17 13:30:30586 if (simulate_modal_window_open_for_testing_)
587 return true;
[email protected]001272f2012-11-02 20:05:23588 const std::vector<aura::Window*> containers = GetAllContainers(
[email protected]e73bd7802012-02-17 20:10:34589 internal::kShellWindowId_SystemModalContainer);
[email protected]001272f2012-11-02 20:05:23590 for (std::vector<aura::Window*>::const_iterator cit = containers.begin();
591 cit != containers.end(); ++cit) {
592 for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin();
593 wit != (*cit)->children().end(); ++wit) {
594 if ((*wit)->GetProperty(aura::client::kModalKey) ==
595 ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) {
596 return true;
597 }
598 }
599 }
600 return false;
[email protected]40c4cbb2012-01-10 23:26:07601}
602
[email protected]57b8bb352012-01-11 05:11:46603views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
604 views::Widget* widget) {
605 if (CommandLine::ForCurrentProcess()->HasSwitch(
606 switches::kAuraGoogleDialogFrames)) {
607 return new internal::DialogFrameView;
608 }
[email protected]c73d1332012-03-08 17:11:04609 // Use translucent-style window frames for dialogs.
[email protected]95c6cc42012-03-08 20:53:15610 CustomFrameViewAsh* frame_view = new CustomFrameViewAsh;
[email protected]c73d1332012-03-08 17:11:04611 frame_view->Init(widget);
612 return frame_view;
[email protected]57b8bb352012-01-11 05:11:46613}
614
[email protected]3d29912a2012-02-07 07:41:51615void Shell::RotateFocus(Direction direction) {
616 focus_cycler_->RotateFocus(
617 direction == FORWARD ? internal::FocusCycler::FORWARD :
618 internal::FocusCycler::BACKWARD);
619}
620
[email protected]2e236a52012-06-27 22:21:47621void Shell::SetDisplayWorkAreaInsets(Window* contains,
[email protected]8a45c972012-03-14 18:22:44622 const gfx::Insets& insets) {
[email protected]6bdf7952012-11-14 10:10:58623 if (!display_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains, insets))
[email protected]1a2145b2012-03-13 21:09:17624 return;
[email protected]1a2145b2012-03-13 21:09:17625 FOR_EACH_OBSERVER(ShellObserver, observers_,
[email protected]2e236a52012-06-27 22:21:47626 OnDisplayWorkAreaInsetsChanged());
[email protected]1a2145b2012-03-13 21:09:17627}
628
[email protected]82d3954ae2012-04-20 09:02:22629void Shell::OnLoginStateChanged(user::LoginStatus status) {
630 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
[email protected]16059276d2012-10-22 18:59:50631 RootWindowControllerList controllers = GetAllRootWindowControllers();
632 for (RootWindowControllerList::iterator iter = controllers.begin();
633 iter != controllers.end(); ++iter)
634 (*iter)->OnLoginStateChanged(status);
[email protected]82d3954ae2012-04-20 09:02:22635}
636
[email protected]88d71122012-10-18 07:11:01637void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) {
[email protected]16059276d2012-10-22 18:59:50638 RootWindowControllerList controllers = GetAllRootWindowControllers();
639 for (RootWindowControllerList::iterator iter = controllers.begin();
640 iter != controllers.end(); ++iter)
641 (*iter)->UpdateAfterLoginStatusChange(status);
[email protected]88d71122012-10-18 07:11:01642}
643
[email protected]82d3954ae2012-04-20 09:02:22644void Shell::OnAppTerminating() {
645 FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
646}
647
648void Shell::OnLockStateChanged(bool locked) {
649 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
650}
651
[email protected]d9456cb2012-03-21 16:41:04652void Shell::CreateLauncher() {
[email protected]e74aaf0a2012-10-12 18:42:28653 GetPrimaryRootWindowController()->CreateLauncher();
[email protected]d9456cb2012-03-21 16:41:04654}
655
[email protected]7e1df2f62012-07-19 19:17:18656void Shell::ShowLauncher() {
[email protected]e74aaf0a2012-10-12 18:42:28657 GetPrimaryRootWindowController()->ShowLauncher();
[email protected]7e1df2f62012-07-19 19:17:18658}
659
[email protected]1a2145b2012-03-13 21:09:17660void Shell::AddShellObserver(ShellObserver* observer) {
661 observers_.AddObserver(observer);
662}
663
664void Shell::RemoveShellObserver(ShellObserver* observer) {
665 observers_.RemoveObserver(observer);
666}
667
[email protected]c758fbf2012-03-25 22:53:59668void Shell::UpdateShelfVisibility() {
[email protected]431552c2012-10-23 00:38:33669 RootWindowControllerList controllers = GetAllRootWindowControllers();
670 for (RootWindowControllerList::iterator iter = controllers.begin();
671 iter != controllers.end(); ++iter)
672 if ((*iter)->shelf())
673 (*iter)->UpdateShelfVisibility();
[email protected]c758fbf2012-03-25 22:53:59674}
675
[email protected]431552c2012-10-23 00:38:33676void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
677 aura::RootWindow* root_window) {
678 GetRootWindowController(root_window)->SetShelfAutoHideBehavior(behavior);
[email protected]c758fbf2012-03-25 22:53:59679}
680
[email protected]431552c2012-10-23 00:38:33681ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior(
682 aura::RootWindow* root_window) const {
683 return GetRootWindowController(root_window)->GetShelfAutoHideBehavior();
[email protected]c758fbf2012-03-25 22:53:59684}
685
[email protected]431552c2012-10-23 00:38:33686bool Shell::IsShelfAutoHideMenuHideChecked(aura::RootWindow* root_window) {
687 return GetRootWindowController(root_window)->GetShelfAutoHideBehavior() ==
688 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
689}
690
691ShelfAutoHideBehavior Shell::GetToggledShelfAutoHideBehavior(
692 aura::RootWindow* root_window) {
693 return GetRootWindowController(root_window)->
694 GetToggledShelfAutoHideBehavior();
695}
696
697void Shell::SetShelfAlignment(ShelfAlignment alignment,
698 aura::RootWindow* root_window) {
699 if (GetRootWindowController(root_window)->SetShelfAlignment(alignment))
[email protected]e74aaf0a2012-10-12 18:42:28700 FOR_EACH_OBSERVER(ShellObserver, observers_, OnShelfAlignmentChanged());
[email protected]55444502012-05-10 15:43:53701}
702
[email protected]431552c2012-10-23 00:38:33703ShelfAlignment Shell::GetShelfAlignment(aura::RootWindow* root_window) {
704 return GetRootWindowController(root_window)->GetShelfAlignment();
[email protected]55444502012-05-10 15:43:53705}
706
[email protected]d90b8392012-06-13 09:34:56707void Shell::SetDimming(bool should_dim) {
[email protected]be65be362012-06-15 07:38:23708 RootWindowControllerList controllers = GetAllRootWindowControllers();
709 for (RootWindowControllerList::iterator iter = controllers.begin();
710 iter != controllers.end(); ++iter)
711 (*iter)->screen_dimmer()->SetDimming(should_dim);
[email protected]d90b8392012-06-13 09:34:56712}
713
[email protected]090c4f12012-10-29 18:56:42714void Shell::CreateModalBackground(aura::Window* window) {
[email protected]c0ce80e2012-10-05 23:28:27715 if (!modality_filter_.get()) {
716 modality_filter_.reset(new internal::SystemModalContainerEventFilter(this));
[email protected]304594c2012-11-13 16:35:27717 AddPreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27718 }
719 RootWindowControllerList controllers = GetAllRootWindowControllers();
720 for (RootWindowControllerList::iterator iter = controllers.begin();
721 iter != controllers.end(); ++iter)
[email protected]090c4f12012-10-29 18:56:42722 (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27723}
724
725void Shell::OnModalWindowRemoved(aura::Window* removed) {
726 RootWindowControllerList controllers = GetAllRootWindowControllers();
727 bool activated = false;
728 for (RootWindowControllerList::iterator iter = controllers.begin();
729 iter != controllers.end() && !activated; ++iter) {
[email protected]8674b312012-10-12 19:02:44730 activated = (*iter)->GetSystemModalLayoutManager(removed)->
731 ActivateNextModalWindow();
[email protected]c0ce80e2012-10-05 23:28:27732 }
733 if (!activated) {
[email protected]304594c2012-11-13 16:35:27734 RemovePreTargetHandler(modality_filter_.get());
[email protected]c0ce80e2012-10-05 23:28:27735 modality_filter_.reset();
736 for (RootWindowControllerList::iterator iter = controllers.begin();
737 iter != controllers.end(); ++iter)
[email protected]8674b312012-10-12 19:02:44738 (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27739 }
740}
741
[email protected]88d71122012-10-18 07:11:01742WebNotificationTray* Shell::GetWebNotificationTray() {
743 return GetPrimaryRootWindowController()->status_area_widget()->
744 web_notification_tray();
[email protected]e74aaf0a2012-10-12 18:42:28745}
746
[email protected]31f19e32012-10-30 22:31:23747internal::StatusAreaWidget* Shell::status_area_widget() {
748 return GetPrimaryRootWindowController()->status_area_widget();
749}
750
[email protected]aa54218b2012-06-12 16:51:42751SystemTray* Shell::system_tray() {
[email protected]31f19e32012-10-30 22:31:23752 // We assume in throughout the code that this will not return NULL. If code
753 // triggers this for valid reasons, it should test status_area_widget first.
754 internal::StatusAreaWidget* status_area = status_area_widget();
755 CHECK(status_area);
756 return status_area->system_tray();
[email protected]aa54218b2012-06-12 16:51:42757}
758
[email protected]2e236a52012-06-27 22:21:47759void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) {
[email protected]a857dbe2012-05-30 22:10:14760 root->set_focus_manager(focus_manager_.get());
[email protected]cf1c70e2012-08-30 01:13:02761 internal::RootWindowController* controller =
762 new internal::RootWindowController(root);
763 controller->CreateContainers();
[email protected]bca9a7e2012-11-10 06:25:49764 // Pass false for the |is_first_run_after_boot| parameter so we'll show a
765 // black background on this display instead of trying to mimic the boot splash
766 // screen.
767 controller->CreateSystemBackground(false);
[email protected]cf1c70e2012-08-30 01:13:02768 InitRootWindowController(controller);
[email protected]16059276d2012-10-22 18:59:50769 if (IsLauncherPerDisplayEnabled())
770 controller->InitForPrimaryDisplay();
[email protected]cf1c70e2012-08-30 01:13:02771 controller->root_window_layout()->OnWindowResized();
772 desktop_background_controller_->OnRootWindowAdded(root);
[email protected]6b37addd2012-09-28 03:08:09773 high_contrast_controller_->OnRootWindowAdded(root);
[email protected]cf1c70e2012-08-30 01:13:02774 root->ShowRootWindow();
775 // Activate new root for testing.
776 active_root_window_ = root;
[email protected]a857dbe2012-05-30 22:10:14777}
778
[email protected]f9466702012-09-17 16:35:27779void Shell::DoInitialWorkspaceAnimation() {
780 return GetPrimaryRootWindowController()->workspace_controller()->
781 DoInitialAnimation();
782}
783
[email protected]d8f10042012-11-14 01:10:46784aura::client::StackingClient* Shell::stacking_client() {
785 return stacking_client_.get();
786}
787
[email protected]be65be362012-06-15 07:38:23788void Shell::InitRootWindowController(
789 internal::RootWindowController* controller) {
790 aura::RootWindow* root_window = controller->root_window();
[email protected]d90b8392012-06-13 09:34:56791 DCHECK(activation_controller_.get());
792 DCHECK(visibility_controller_.get());
793 DCHECK(drag_drop_controller_.get());
794 DCHECK(capture_controller_.get());
[email protected]8fef7432012-08-06 15:34:25795 DCHECK(window_cycle_controller_.get());
[email protected]d90b8392012-06-13 09:34:56796
797 root_window->set_focus_manager(focus_manager_.get());
798 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
799 aura::client::SetActivationClient(root_window, activation_controller_.get());
800 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
801 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
[email protected]d90b8392012-06-13 09:34:56802 aura::client::SetCaptureClient(root_window, capture_controller_.get());
[email protected]8d625fb2012-07-18 16:40:06803 aura::client::SetScreenPositionClient(root_window,
804 screen_position_controller_.get());
[email protected]4b8003c2012-07-26 00:54:19805 aura::client::SetCursorClient(root_window, &cursor_manager_);
[email protected]54a37cdc2012-07-25 19:16:01806 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
[email protected]e67291f12012-10-10 05:52:38807 aura::client::SetEventClient(root_window, event_client_.get());
[email protected]d90b8392012-06-13 09:34:56808
809 if (nested_dispatcher_controller_.get()) {
810 aura::client::SetDispatcherClient(root_window,
811 nested_dispatcher_controller_.get());
812 }
813 if (user_action_client_.get())
814 aura::client::SetUserActionClient(root_window, user_action_client_.get());
815
816 root_window->SetCursor(ui::kCursorPointer);
[email protected]be65be362012-06-15 07:38:23817 controller->InitLayoutManagers();
[email protected]f059c6942012-07-21 14:27:57818
819 // TODO(oshima): Move the instance to RootWindowController when
820 // the extended desktop is enabled by default.
821 internal::AlwaysOnTopController* always_on_top_controller =
822 new internal::AlwaysOnTopController;
[email protected]c96b9812012-10-17 16:04:04823 always_on_top_controller->SetAlwaysOnTopContainer(
[email protected]f059c6942012-07-21 14:27:57824 root_window->GetChildById(internal::kShellWindowId_AlwaysOnTopContainer));
825 root_window->SetProperty(internal::kAlwaysOnTopControllerKey,
826 always_on_top_controller);
[email protected]8674b312012-10-12 19:02:44827 if (GetPrimaryRootWindowController()->GetSystemModalLayoutManager(NULL)->
[email protected]c0ce80e2012-10-05 23:28:27828 has_modal_background()) {
[email protected]8674b312012-10-12 19:02:44829 controller->GetSystemModalLayoutManager(NULL)->CreateModalBackground();
[email protected]c0ce80e2012-10-05 23:28:27830 }
[email protected]8fef7432012-08-06 15:34:25831
832 window_cycle_controller_->OnRootWindowAdded(root_window);
[email protected]d90b8392012-06-13 09:34:56833}
834
[email protected]46ca3632011-11-03 03:33:42835////////////////////////////////////////////////////////////////////////////////
836// Shell, private:
837
[email protected]c0ce80e2012-10-05 23:28:27838bool Shell::CanWindowReceiveEvents(aura::Window* window) {
839 RootWindowControllerList controllers = GetAllRootWindowControllers();
840 for (RootWindowControllerList::iterator iter = controllers.begin();
841 iter != controllers.end(); ++iter) {
[email protected]8674b312012-10-12 19:02:44842 if ((*iter)->GetSystemModalLayoutManager(window)->
[email protected]c0ce80e2012-10-05 23:28:27843 CanWindowReceiveEvents(window)) {
844 return true;
845 }
846 }
847 return false;
848}
849
[email protected]5097e692012-10-30 22:08:41850bool Shell::CanAcceptEvents() {
851 return true;
852}
853
854ui::EventTarget* Shell::GetParentTarget() {
855 return NULL;
856}
857
[email protected]55f593352011-12-24 05:42:46858} // namespace ash