Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ash/shell.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | |
| 10 | #include "ash/accelerators/focus_manager_factory.h" |
| 11 | #include "ash/ash_switches.h" |
| 12 | #include "ash/caps_lock_delegate.h" |
| 13 | #include "ash/desktop_background/desktop_background_controller.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | #include "ash/desktop_background/desktop_background_view.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "ash/desktop_background/user_wallpaper_delegate.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 16 | #include "ash/display/display_controller.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | #include "ash/display/display_manager.h" |
| 18 | #include "ash/display/event_transformation_handler.h" |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 19 | #include "ash/display/mirror_window_controller.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | #include "ash/display/mouse_cursor_event_filter.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 21 | #include "ash/display/screen_position_controller.h" |
| 22 | #include "ash/drag_drop/drag_drop_controller.h" |
| 23 | #include "ash/focus_cycler.h" |
| 24 | #include "ash/high_contrast/high_contrast_controller.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | #include "ash/host/root_window_host_factory.h" |
| 26 | #include "ash/launcher/launcher_delegate.h" |
| 27 | #include "ash/launcher/launcher_model.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 28 | #include "ash/magnifier/magnification_controller.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 29 | #include "ash/magnifier/partial_magnification_controller.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 30 | #include "ash/root_window_controller.h" |
| 31 | #include "ash/screen_ash.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 32 | #include "ash/session_state_delegate.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 33 | #include "ash/shelf/shelf_layout_manager.h" |
| 34 | #include "ash/shelf/shelf_widget.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 35 | #include "ash/shell_delegate.h" |
| 36 | #include "ash/shell_factory.h" |
| 37 | #include "ash/shell_window_ids.h" |
| 38 | #include "ash/system/status_area_widget.h" |
| 39 | #include "ash/system/tray/system_tray_delegate.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 40 | #include "ash/system/tray/system_tray_notifier.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 41 | #include "ash/wm/activation_controller.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 42 | #include "ash/wm/app_list_controller.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 43 | #include "ash/wm/ash_activation_controller.h" |
| 44 | #include "ash/wm/ash_focus_rules.h" |
| 45 | #include "ash/wm/ash_native_cursor_manager.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 46 | #include "ash/wm/base_layout_manager.h" |
| 47 | #include "ash/wm/capture_controller.h" |
| 48 | #include "ash/wm/coordinate_conversion.h" |
| 49 | #include "ash/wm/custom_frame_view_ash.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 50 | #include "ash/wm/event_client_impl.h" |
| 51 | #include "ash/wm/event_rewriter_event_filter.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 52 | #include "ash/wm/lock_state_controller.h" |
| 53 | #include "ash/wm/lock_state_controller_impl2.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 54 | #include "ash/wm/overlay_event_filter.h" |
| 55 | #include "ash/wm/power_button_controller.h" |
| 56 | #include "ash/wm/property_util.h" |
| 57 | #include "ash/wm/resize_shadow_controller.h" |
| 58 | #include "ash/wm/root_window_layout_manager.h" |
| 59 | #include "ash/wm/screen_dimmer.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 60 | #include "ash/wm/session_state_controller_impl.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 61 | #include "ash/wm/system_gesture_event_filter.h" |
| 62 | #include "ash/wm/system_modal_container_event_filter.h" |
| 63 | #include "ash/wm/system_modal_container_layout_manager.h" |
| 64 | #include "ash/wm/user_activity_detector.h" |
| 65 | #include "ash/wm/video_detector.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 66 | #include "ash/wm/window_animations.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 67 | #include "ash/wm/window_cycle_controller.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 68 | #include "ash/wm/window_properties.h" |
| 69 | #include "ash/wm/window_util.h" |
| 70 | #include "ash/wm/workspace_controller.h" |
| 71 | #include "base/bind.h" |
| 72 | #include "base/command_line.h" |
| 73 | #include "base/debug/leak_annotations.h" |
| 74 | #include "ui/aura/client/aura_constants.h" |
| 75 | #include "ui/aura/client/user_action_client.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 76 | #include "ui/aura/env.h" |
| 77 | #include "ui/aura/focus_manager.h" |
| 78 | #include "ui/aura/layout_manager.h" |
| 79 | #include "ui/aura/root_window.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 80 | #include "ui/aura/window.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 81 | #include "ui/base/ui_base_switches.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 82 | #include "ui/compositor/layer.h" |
| 83 | #include "ui/compositor/layer_animator.h" |
| 84 | #include "ui/gfx/display.h" |
| 85 | #include "ui/gfx/image/image_skia.h" |
| 86 | #include "ui/gfx/screen.h" |
| 87 | #include "ui/gfx/size.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 88 | #include "ui/keyboard/keyboard.h" |
| 89 | #include "ui/keyboard/keyboard_util.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 90 | #include "ui/message_center/message_center.h" |
| 91 | #include "ui/views/corewm/compound_event_filter.h" |
| 92 | #include "ui/views/corewm/corewm_switches.h" |
| 93 | #include "ui/views/corewm/focus_controller.h" |
| 94 | #include "ui/views/corewm/input_method_event_filter.h" |
| 95 | #include "ui/views/corewm/shadow_controller.h" |
| 96 | #include "ui/views/corewm/tooltip_controller.h" |
| 97 | #include "ui/views/corewm/visibility_controller.h" |
| 98 | #include "ui/views/corewm/window_modality_controller.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 99 | #include "ui/views/focus/focus_manager_factory.h" |
| 100 | #include "ui/views/widget/native_widget_aura.h" |
| 101 | #include "ui/views/widget/widget.h" |
| 102 | |
| 103 | #if !defined(OS_MACOSX) |
| 104 | #include "ash/accelerators/accelerator_controller.h" |
| 105 | #include "ash/accelerators/accelerator_filter.h" |
| 106 | #include "ash/accelerators/nested_dispatcher_controller.h" |
| 107 | #endif |
| 108 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 109 | #if defined(OS_CHROMEOS) |
| 110 | #if defined(USE_X11) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 111 | #include "ash/ash_constants.h" |
| 112 | #include "ash/display/display_change_observer_x11.h" |
| 113 | #include "ash/display/display_error_dialog.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 114 | #include "ash/display/output_configurator_animation.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 115 | #include "base/chromeos/chromeos_version.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 116 | #include "base/message_loop/message_pump_aurax11.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 117 | #include "chromeos/display/output_configurator.h" |
| 118 | #include "content/public/browser/gpu_data_manager.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 119 | #include "content/public/common/content_switches.h" |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 120 | #include "gpu/config/gpu_feature_type.h" |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 121 | #endif // defined(USE_X11) |
| 122 | #include "ash/system/chromeos/power/power_status.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 123 | #endif // defined(OS_CHROMEOS) |
| 124 | |
| 125 | namespace ash { |
| 126 | |
| 127 | namespace { |
| 128 | |
| 129 | using aura::Window; |
| 130 | using views::Widget; |
| 131 | |
| 132 | // This dummy class is used for shell unit tests. We dont have chrome delegate |
| 133 | // in these tests. |
| 134 | class DummyUserWallpaperDelegate : public UserWallpaperDelegate { |
| 135 | public: |
| 136 | DummyUserWallpaperDelegate() {} |
| 137 | |
| 138 | virtual ~DummyUserWallpaperDelegate() {} |
| 139 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 140 | virtual int GetAnimationType() OVERRIDE { |
| 141 | return views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | virtual bool ShouldShowInitialAnimation() OVERRIDE { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | virtual void UpdateWallpaper() OVERRIDE { |
| 149 | } |
| 150 | |
| 151 | virtual void InitializeWallpaper() OVERRIDE { |
| 152 | ash::Shell::GetInstance()->desktop_background_controller()-> |
| 153 | CreateEmptyWallpaper(); |
| 154 | } |
| 155 | |
| 156 | virtual void OpenSetWallpaperPage() OVERRIDE { |
| 157 | } |
| 158 | |
| 159 | virtual bool CanOpenSetWallpaperPage() OVERRIDE { |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | virtual void OnWallpaperAnimationFinished() OVERRIDE { |
| 164 | } |
| 165 | |
| 166 | virtual void OnWallpaperBootAnimationFinished() OVERRIDE { |
| 167 | } |
| 168 | |
| 169 | private: |
| 170 | DISALLOW_COPY_AND_ASSIGN(DummyUserWallpaperDelegate); |
| 171 | }; |
| 172 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 173 | // A Corewm VisibilityController subclass that calls the Ash animation routine |
| 174 | // so we can pick up our extended animations. See ash/wm/window_animations.h. |
| 175 | class AshVisibilityController : public views::corewm::VisibilityController { |
| 176 | public: |
| 177 | AshVisibilityController() {} |
| 178 | virtual ~AshVisibilityController() {} |
| 179 | |
| 180 | private: |
| 181 | // Overridden from views::corewm::VisibilityController: |
| 182 | virtual bool CallAnimateOnChildWindowVisibilityChanged( |
| 183 | aura::Window* window, |
| 184 | bool visible) OVERRIDE { |
| 185 | return AnimateOnChildWindowVisibilityChanged(window, visible); |
| 186 | } |
| 187 | |
| 188 | DISALLOW_COPY_AND_ASSIGN(AshVisibilityController); |
| 189 | }; |
| 190 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 191 | } // namespace |
| 192 | |
| 193 | // static |
| 194 | Shell* Shell::instance_ = NULL; |
| 195 | // static |
| 196 | bool Shell::initially_hide_cursor_ = false; |
| 197 | |
| 198 | //////////////////////////////////////////////////////////////////////////////// |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 199 | // Shell, public: |
| 200 | |
| 201 | Shell::Shell(ShellDelegate* delegate) |
| 202 | : screen_(new ScreenAsh), |
| 203 | active_root_window_(NULL), |
| 204 | delegate_(delegate), |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 205 | activation_client_(NULL), |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 206 | #if defined(OS_CHROMEOS) && defined(USE_X11) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 207 | output_configurator_(new chromeos::OutputConfigurator()), |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 208 | #endif // defined(OS_CHROMEOS) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 209 | native_cursor_manager_(new AshNativeCursorManager), |
| 210 | cursor_manager_(scoped_ptr<views::corewm::NativeCursorManager>( |
| 211 | native_cursor_manager_)), |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 212 | browser_context_(NULL), |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 213 | simulate_modal_window_open_for_testing_(false), |
| 214 | is_touch_hud_projection_enabled_(false) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 215 | DCHECK(delegate_.get()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 216 | display_manager_.reset(new internal::DisplayManager); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 217 | mirror_window_controller_.reset(new internal::MirrorWindowController); |
| 218 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 219 | ANNOTATE_LEAKING_OBJECT_PTR(screen_); // see crbug.com/156466 |
| 220 | gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_ALTERNATE, screen_); |
| 221 | if (!gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_NATIVE)) |
| 222 | gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 223 | display_controller_.reset(new DisplayController); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 224 | #if defined(OS_CHROMEOS) && defined(USE_X11) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 225 | bool is_panel_fitting_disabled = |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 226 | content::GpuDataManager::GetInstance()->IsFeatureBlacklisted( |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 227 | gpu::GPU_FEATURE_TYPE_PANEL_FITTING) || |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 228 | CommandLine::ForCurrentProcess()->HasSwitch( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 229 | ::switches::kDisablePanelFitting); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 230 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 231 | output_configurator_->Init( |
| 232 | !is_panel_fitting_disabled, |
| 233 | delegate_->IsFirstRunAfterBoot() ? kChromeOsBootColor : 0); |
| 234 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 235 | base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow( |
| 236 | output_configurator()); |
| 237 | #endif // defined(OS_CHROMEOS) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 238 | AddPreTargetHandler(this); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 239 | |
| 240 | #if defined(OS_CHROMEOS) |
| 241 | internal::PowerStatus::Initialize(); |
| 242 | #endif |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | Shell::~Shell() { |
| 246 | views::FocusManagerFactory::Install(NULL); |
| 247 | |
| 248 | // Remove the focus from any window. This will prevent overhead and side |
| 249 | // effects (e.g. crashes) from changing focus during shutdown. |
| 250 | // See bug crbug.com/134502. |
| 251 | if (active_root_window_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 252 | aura::client::GetFocusClient(active_root_window_)->FocusWindow(NULL); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 253 | |
| 254 | // Please keep in same order as in Init() because it's easy to miss one. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 255 | RemovePreTargetHandler(user_activity_detector_.get()); |
| 256 | RemovePreTargetHandler(event_rewriter_filter_.get()); |
| 257 | RemovePreTargetHandler(overlay_filter_.get()); |
| 258 | RemovePreTargetHandler(input_method_filter_.get()); |
| 259 | RemovePreTargetHandler(window_modality_controller_.get()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 260 | if (mouse_cursor_filter_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 261 | RemovePreTargetHandler(mouse_cursor_filter_.get()); |
| 262 | RemovePreTargetHandler(system_gesture_filter_.get()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 263 | RemovePreTargetHandler(event_transformation_handler_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 264 | #if !defined(OS_MACOSX) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 265 | RemovePreTargetHandler(accelerator_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 266 | #endif |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 267 | |
| 268 | // TooltipController is deleted with the Shell so removing its references. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 269 | RemovePreTargetHandler(tooltip_controller_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 270 | |
| 271 | // AppList needs to be released before shelf layout manager, which is |
| 272 | // destroyed with launcher container in the loop below. However, app list |
| 273 | // container is now on top of launcher container and released after it. |
| 274 | // TODO(xiyuan): Move it back when app list container is no longer needed. |
| 275 | app_list_controller_.reset(); |
| 276 | |
| 277 | // Destroy SystemTrayDelegate before destroying the status area(s). |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 278 | system_tray_delegate_->Shutdown(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 279 | system_tray_delegate_.reset(); |
| 280 | |
| 281 | // Destroy all child windows including widgets. |
| 282 | display_controller_->CloseChildWindows(); |
| 283 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 284 | // Destroy SystemTrayNotifier after destroying SystemTray as TrayItems |
| 285 | // needs to remove observers from it. |
| 286 | system_tray_notifier_.reset(); |
| 287 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 288 | // These need a valid Shell instance to clean up properly, so explicitly |
| 289 | // delete them before invalidating the instance. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 290 | // Alphabetical. TODO(oshima): sort. |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 291 | drag_drop_controller_.reset(); |
| 292 | magnification_controller_.reset(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 293 | partial_magnification_controller_.reset(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 294 | resize_shadow_controller_.reset(); |
| 295 | shadow_controller_.reset(); |
| 296 | tooltip_controller_.reset(); |
| 297 | event_client_.reset(); |
| 298 | window_cycle_controller_.reset(); |
| 299 | capture_controller_.reset(); |
| 300 | nested_dispatcher_controller_.reset(); |
| 301 | user_action_client_.reset(); |
| 302 | visibility_controller_.reset(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 303 | launcher_delegate_.reset(); |
| 304 | launcher_model_.reset(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 305 | video_detector_.reset(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 306 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 307 | power_button_controller_.reset(); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 308 | lock_state_controller_.reset(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 309 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 310 | mirror_window_controller_.reset(); |
| 311 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 312 | // This also deletes all RootWindows. Note that we invoke Shutdown() on |
| 313 | // DisplayController before resetting |display_controller_|, since destruction |
| 314 | // of its owned RootWindowControllers relies on the value. |
| 315 | display_controller_->Shutdown(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 316 | display_controller_.reset(); |
| 317 | screen_position_controller_.reset(); |
| 318 | |
| 319 | // Delete the activation controller after other controllers and launcher |
| 320 | // because they might have registered ActivationChangeObserver. |
| 321 | activation_controller_.reset(); |
| 322 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 323 | #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 324 | if (display_change_observer_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 325 | output_configurator_->RemoveObserver(display_change_observer_.get()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 326 | if (output_configurator_animation_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 327 | output_configurator_->RemoveObserver(output_configurator_animation_.get()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 328 | if (display_error_observer_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 329 | output_configurator_->RemoveObserver(display_error_observer_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 330 | base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow( |
| 331 | output_configurator()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 332 | display_change_observer_.reset(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 333 | #endif // defined(OS_CHROMEOS) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 334 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 335 | #if defined(OS_CHROMEOS) |
| 336 | internal::PowerStatus::Shutdown(); |
| 337 | #endif |
| 338 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 339 | DCHECK(instance_ == this); |
| 340 | instance_ = NULL; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | // static |
| 344 | Shell* Shell::CreateInstance(ShellDelegate* delegate) { |
| 345 | CHECK(!instance_); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 346 | instance_ = new Shell(delegate); |
| 347 | instance_->Init(); |
| 348 | return instance_; |
| 349 | } |
| 350 | |
| 351 | // static |
| 352 | Shell* Shell::GetInstance() { |
| 353 | DCHECK(instance_); |
| 354 | return instance_; |
| 355 | } |
| 356 | |
| 357 | // static |
| 358 | bool Shell::HasInstance() { |
| 359 | return !!instance_; |
| 360 | } |
| 361 | |
| 362 | // static |
| 363 | void Shell::DeleteInstance() { |
| 364 | delete instance_; |
| 365 | instance_ = NULL; |
| 366 | } |
| 367 | |
| 368 | // static |
| 369 | internal::RootWindowController* Shell::GetPrimaryRootWindowController() { |
| 370 | return GetRootWindowController(GetPrimaryRootWindow()); |
| 371 | } |
| 372 | |
| 373 | // static |
| 374 | Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() { |
| 375 | return Shell::GetInstance()->display_controller()-> |
| 376 | GetAllRootWindowControllers(); |
| 377 | } |
| 378 | |
| 379 | // static |
| 380 | aura::RootWindow* Shell::GetPrimaryRootWindow() { |
| 381 | return GetInstance()->display_controller()->GetPrimaryRootWindow(); |
| 382 | } |
| 383 | |
| 384 | // static |
| 385 | aura::RootWindow* Shell::GetActiveRootWindow() { |
| 386 | return GetInstance()->active_root_window_; |
| 387 | } |
| 388 | |
| 389 | // static |
| 390 | gfx::Screen* Shell::GetScreen() { |
| 391 | return gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); |
| 392 | } |
| 393 | |
| 394 | // static |
| 395 | Shell::RootWindowList Shell::GetAllRootWindows() { |
| 396 | return Shell::GetInstance()->display_controller()-> |
| 397 | GetAllRootWindows(); |
| 398 | } |
| 399 | |
| 400 | // static |
| 401 | aura::Window* Shell::GetContainer(aura::RootWindow* root_window, |
| 402 | int container_id) { |
| 403 | return root_window->GetChildById(container_id); |
| 404 | } |
| 405 | |
| 406 | // static |
| 407 | const aura::Window* Shell::GetContainer(const aura::RootWindow* root_window, |
| 408 | int container_id) { |
| 409 | return root_window->GetChildById(container_id); |
| 410 | } |
| 411 | |
| 412 | // static |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 413 | std::vector<aura::Window*> Shell::GetContainersFromAllRootWindows( |
| 414 | int container_id, |
| 415 | aura::RootWindow* priority_root) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 416 | std::vector<aura::Window*> containers; |
| 417 | RootWindowList root_windows = GetAllRootWindows(); |
| 418 | for (RootWindowList::const_iterator it = root_windows.begin(); |
| 419 | it != root_windows.end(); ++it) { |
| 420 | aura::Window* container = (*it)->GetChildById(container_id); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 421 | if (container) { |
| 422 | if (priority_root && priority_root->Contains(container)) |
| 423 | containers.insert(containers.begin(), container); |
| 424 | else |
| 425 | containers.push_back(container); |
| 426 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 427 | } |
| 428 | return containers; |
| 429 | } |
| 430 | |
| 431 | // static |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 432 | bool Shell::IsForcedMaximizeMode() { |
| 433 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 434 | return command_line->HasSwitch(switches::kForcedMaximizeMode); |
| 435 | } |
| 436 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 437 | void Shell::Init() { |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 438 | CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 439 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 440 | delegate_->PreInit(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 441 | #if defined(OS_CHROMEOS) && defined(USE_X11) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 442 | output_configurator_animation_.reset( |
| 443 | new internal::OutputConfiguratorAnimation()); |
| 444 | output_configurator_->AddObserver(output_configurator_animation_.get()); |
| 445 | if (base::chromeos::IsRunningOnChromeOS()) { |
| 446 | display_change_observer_.reset(new internal::DisplayChangeObserverX11); |
| 447 | // Register |display_change_observer_| first so that the rest of |
| 448 | // observer gets invoked after the root windows are configured. |
| 449 | output_configurator_->AddObserver(display_change_observer_.get()); |
| 450 | display_error_observer_.reset(new internal::DisplayErrorObserver()); |
| 451 | output_configurator_->AddObserver(display_error_observer_.get()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 452 | output_configurator_->set_state_controller(display_change_observer_.get()); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 453 | if (!command_line->HasSwitch(ash::switches::kAshDisableSoftwareMirroring)) |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 454 | output_configurator_->set_mirroring_controller(display_manager_.get()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 455 | output_configurator_->Start(); |
| 456 | display_change_observer_->OnDisplayModeChanged(); |
| 457 | } |
| 458 | #endif |
| 459 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 460 | // Install the custom factory first so that views::FocusManagers for Tray, |
| 461 | // Launcher, and WallPaper could be created by the factory. |
| 462 | views::FocusManagerFactory::Install(new AshFocusManagerFactory); |
| 463 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 464 | env_filter_.reset(new views::corewm::CompoundEventFilter); |
| 465 | AddPreTargetHandler(env_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 466 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 467 | // Env creates the compositor. Historically it seems to have been implicitly |
| 468 | // initialized first by the ActivationController, but now that FocusController |
| 469 | // no longer does this we need to do it explicitly. |
| 470 | aura::Env::GetInstance(); |
| 471 | if (views::corewm::UseFocusController()) { |
| 472 | views::corewm::FocusController* focus_controller = |
| 473 | new views::corewm::FocusController(new wm::AshFocusRules); |
| 474 | focus_client_.reset(focus_controller); |
| 475 | activation_client_ = focus_controller; |
| 476 | activation_client_->AddObserver(this); |
| 477 | } else { |
| 478 | focus_client_.reset(new aura::FocusManager); |
| 479 | activation_controller_.reset( |
| 480 | new internal::ActivationController( |
| 481 | focus_client_.get(), |
| 482 | new internal::AshActivationController)); |
| 483 | activation_client_ = activation_controller_.get(); |
| 484 | AddPreTargetHandler(activation_controller_.get()); |
| 485 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 486 | |
| 487 | focus_cycler_.reset(new internal::FocusCycler()); |
| 488 | |
| 489 | screen_position_controller_.reset(new internal::ScreenPositionController); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 490 | root_window_host_factory_.reset(delegate_->CreateRootWindowHostFactory()); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 491 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 492 | display_controller_->Start(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 493 | display_controller_->InitPrimaryDisplay(); |
| 494 | aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow(); |
| 495 | active_root_window_ = root_window; |
| 496 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 497 | cursor_manager_.SetDisplay(DisplayController::GetPrimaryDisplay()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 498 | |
| 499 | #if !defined(OS_MACOSX) |
| 500 | nested_dispatcher_controller_.reset(new NestedDispatcherController); |
| 501 | accelerator_controller_.reset(new AcceleratorController); |
| 502 | #endif |
| 503 | |
| 504 | // The order in which event filters are added is significant. |
| 505 | user_activity_detector_.reset(new UserActivityDetector); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 506 | AddPreTargetHandler(user_activity_detector_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 507 | |
| 508 | event_rewriter_filter_.reset(new internal::EventRewriterEventFilter); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 509 | AddPreTargetHandler(event_rewriter_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 510 | |
| 511 | overlay_filter_.reset(new internal::OverlayEventFilter); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 512 | AddPreTargetHandler(overlay_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 513 | AddShellObserver(overlay_filter_.get()); |
| 514 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 515 | input_method_filter_.reset(new views::corewm::InputMethodEventFilter( |
| 516 | root_window->GetAcceleratedWidget())); |
| 517 | AddPreTargetHandler(input_method_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 518 | |
| 519 | #if !defined(OS_MACOSX) |
| 520 | accelerator_filter_.reset(new internal::AcceleratorFilter); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 521 | AddPreTargetHandler(accelerator_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 522 | #endif |
| 523 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 524 | event_transformation_handler_.reset(new internal::EventTransformationHandler); |
| 525 | AddPreTargetHandler(event_transformation_handler_.get()); |
| 526 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 527 | system_gesture_filter_.reset(new internal::SystemGestureEventFilter); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 528 | AddPreTargetHandler(system_gesture_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 529 | |
| 530 | capture_controller_.reset(new internal::CaptureController); |
| 531 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 532 | // The keyboard system must be initialized before the RootWindowController is |
| 533 | // created. |
| 534 | if (keyboard::IsKeyboardEnabled()) |
| 535 | keyboard::InitializeKeyboard(); |
| 536 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 537 | if (command_line->HasSwitch(ash::switches::kAshDisableNewLockAnimations)) |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 538 | lock_state_controller_.reset(new SessionStateControllerImpl); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 539 | else |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 540 | lock_state_controller_.reset(new LockStateControllerImpl2); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 541 | power_button_controller_.reset(new PowerButtonController( |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 542 | lock_state_controller_.get())); |
| 543 | AddShellObserver(lock_state_controller_.get()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 544 | |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 545 | drag_drop_controller_.reset(new internal::DragDropController); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 546 | mouse_cursor_filter_.reset(new internal::MouseCursorEventFilter()); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 547 | PrependPreTargetHandler(mouse_cursor_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 548 | |
| 549 | // Create Controllers that may need root window. |
| 550 | // TODO(oshima): Move as many controllers before creating |
| 551 | // RootWindowController as possible. |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 552 | visibility_controller_.reset(new AshVisibilityController); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 553 | user_action_client_.reset(delegate_->CreateUserActionClient()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 554 | window_modality_controller_.reset( |
| 555 | new views::corewm::WindowModalityController); |
| 556 | AddPreTargetHandler(window_modality_controller_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 557 | |
| 558 | magnification_controller_.reset( |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 559 | MagnificationController::CreateInstance()); |
| 560 | |
| 561 | partial_magnification_controller_.reset( |
| 562 | new PartialMagnificationController()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 563 | |
| 564 | high_contrast_controller_.reset(new HighContrastController); |
| 565 | video_detector_.reset(new VideoDetector); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 566 | window_cycle_controller_.reset(new WindowCycleController(activation_client_)); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 567 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 568 | tooltip_controller_.reset(new views::corewm::TooltipController( |
| 569 | gfx::SCREEN_TYPE_ALTERNATE)); |
| 570 | AddPreTargetHandler(tooltip_controller_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 571 | |
| 572 | event_client_.reset(new internal::EventClientImpl); |
| 573 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 574 | // This controller needs to be set before SetupManagedWindowMode. |
| 575 | desktop_background_controller_.reset(new DesktopBackgroundController()); |
| 576 | user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 577 | if (!user_wallpaper_delegate_) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 578 | user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate()); |
| 579 | |
| 580 | // StatusAreaWidget uses Shell's CapsLockDelegate. |
| 581 | caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate()); |
| 582 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 583 | session_state_delegate_.reset(delegate_->CreateSessionStateDelegate()); |
| 584 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 585 | if (!command_line->HasSwitch(views::corewm::switches::kNoDropShadows)) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 586 | resize_shadow_controller_.reset(new internal::ResizeShadowController()); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 587 | shadow_controller_.reset( |
| 588 | new views::corewm::ShadowController(activation_client_)); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 589 | } |
| 590 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 591 | // Create system_tray_notifier_ before the delegate. |
| 592 | system_tray_notifier_.reset(new ash::SystemTrayNotifier()); |
| 593 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 594 | // Initialize system_tray_delegate_ before initializing StatusAreaWidget. |
| 595 | system_tray_delegate_.reset(delegate()->CreateSystemTrayDelegate()); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 596 | if (!system_tray_delegate_) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 597 | system_tray_delegate_.reset(SystemTrayDelegate::CreateDummyDelegate()); |
| 598 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 599 | internal::RootWindowController* root_window_controller = |
| 600 | new internal::RootWindowController(root_window); |
| 601 | InitRootWindowController(root_window_controller, |
| 602 | delegate_->IsFirstRunAfterBoot()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 603 | |
| 604 | // Initialize system_tray_delegate_ after StatusAreaWidget is created. |
| 605 | system_tray_delegate_->Initialize(); |
| 606 | |
| 607 | display_controller_->InitSecondaryDisplays(); |
| 608 | |
| 609 | // Force Layout |
| 610 | root_window_controller->root_window_layout()->OnWindowResized(); |
| 611 | |
| 612 | // It needs to be created after OnWindowResized has been called, otherwise the |
| 613 | // widget will not paint when restoring after a browser crash. Also it needs |
| 614 | // to be created after InitSecondaryDisplays() to initialize the wallpapers in |
| 615 | // the correct size. |
| 616 | user_wallpaper_delegate_->InitializeWallpaper(); |
| 617 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 618 | if (initially_hide_cursor_) |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 619 | cursor_manager_.HideCursor(); |
| 620 | cursor_manager_.SetCursor(ui::kCursorPointer); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 621 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 622 | if (!cursor_manager_.IsCursorVisible()) { |
| 623 | // Cursor might have been hidden by something other than chrome. |
| 624 | // Let the first mouse event show the cursor. |
| 625 | env_filter_->set_cursor_hidden_by_filter(true); |
| 626 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 629 | void Shell::ShowContextMenu(const gfx::Point& location_in_screen, |
| 630 | ui::MenuSourceType source_type) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 631 | // No context menus if there is no session with an active user. |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 632 | if (!session_state_delegate_->NumberOfLoggedInUsers()) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 633 | return; |
| 634 | // No context menus when screen is locked. |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 635 | if (session_state_delegate_->IsScreenLocked()) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 636 | return; |
| 637 | |
| 638 | aura::RootWindow* root = |
| 639 | wm::GetRootWindowMatching(gfx::Rect(location_in_screen, gfx::Size())); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 640 | // TODO(oshima): The root and root window controller shouldn't be |
| 641 | // NULL even for the out-of-bounds |location_in_screen| (It should |
| 642 | // return the primary root). Investigate why/how this is |
| 643 | // happening. crbug.com/165214. |
| 644 | internal::RootWindowController* rwc = GetRootWindowController(root); |
| 645 | CHECK(rwc) << "root=" << root |
| 646 | << ", location:" << location_in_screen.ToString(); |
| 647 | if (rwc) |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 648 | rwc->ShowContextMenu(location_in_screen, source_type); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 651 | void Shell::ToggleAppList(aura::Window* window) { |
| 652 | // If the context window is not given, show it on the active root window. |
| 653 | if (!window) |
| 654 | window = GetActiveRootWindow(); |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 655 | if (!app_list_controller_) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 656 | app_list_controller_.reset(new internal::AppListController); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 657 | app_list_controller_->SetVisible(!app_list_controller_->IsVisible(), window); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 660 | void Shell::SetDragAndDropHostOfCurrentAppList( |
| 661 | app_list::ApplicationDragAndDropHost* drag_and_drop_host) { |
| 662 | if (app_list_controller_.get()) |
| 663 | app_list_controller_->SetDragAndDropHostOfCurrentAppList( |
| 664 | drag_and_drop_host); |
| 665 | } |
| 666 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 667 | bool Shell::GetAppListTargetVisibility() const { |
| 668 | return app_list_controller_.get() && |
| 669 | app_list_controller_->GetTargetVisibility(); |
| 670 | } |
| 671 | |
| 672 | aura::Window* Shell::GetAppListWindow() { |
| 673 | return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL; |
| 674 | } |
| 675 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 676 | bool Shell::IsSystemModalWindowOpen() const { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 677 | if (simulate_modal_window_open_for_testing_) |
| 678 | return true; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 679 | const std::vector<aura::Window*> containers = GetContainersFromAllRootWindows( |
| 680 | internal::kShellWindowId_SystemModalContainer, NULL); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 681 | for (std::vector<aura::Window*>::const_iterator cit = containers.begin(); |
| 682 | cit != containers.end(); ++cit) { |
| 683 | for (aura::Window::Windows::const_iterator wit = (*cit)->children().begin(); |
| 684 | wit != (*cit)->children().end(); ++wit) { |
| 685 | if ((*wit)->GetProperty(aura::client::kModalKey) == |
| 686 | ui::MODAL_TYPE_SYSTEM && (*wit)->TargetVisibility()) { |
| 687 | return true; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | return false; |
| 692 | } |
| 693 | |
| 694 | views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( |
| 695 | views::Widget* widget) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 696 | // Use translucent-style window frames for dialogs. |
| 697 | CustomFrameViewAsh* frame_view = new CustomFrameViewAsh; |
| 698 | frame_view->Init(widget); |
| 699 | return frame_view; |
| 700 | } |
| 701 | |
| 702 | void Shell::RotateFocus(Direction direction) { |
| 703 | focus_cycler_->RotateFocus( |
| 704 | direction == FORWARD ? internal::FocusCycler::FORWARD : |
| 705 | internal::FocusCycler::BACKWARD); |
| 706 | } |
| 707 | |
| 708 | void Shell::SetDisplayWorkAreaInsets(Window* contains, |
| 709 | const gfx::Insets& insets) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 710 | if (!display_manager_->UpdateWorkAreaOfDisplayNearestWindow(contains, insets)) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 711 | return; |
| 712 | FOR_EACH_OBSERVER(ShellObserver, observers_, |
| 713 | OnDisplayWorkAreaInsetsChanged()); |
| 714 | } |
| 715 | |
| 716 | void Shell::OnLoginStateChanged(user::LoginStatus status) { |
| 717 | FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status)); |
| 718 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 719 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 720 | iter != controllers.end(); ++iter) |
| 721 | (*iter)->OnLoginStateChanged(status); |
| 722 | } |
| 723 | |
| 724 | void Shell::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 725 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 726 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 727 | iter != controllers.end(); ++iter) |
| 728 | (*iter)->UpdateAfterLoginStatusChange(status); |
| 729 | } |
| 730 | |
| 731 | void Shell::OnAppTerminating() { |
| 732 | FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating()); |
| 733 | } |
| 734 | |
| 735 | void Shell::OnLockStateChanged(bool locked) { |
| 736 | FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked)); |
| 737 | } |
| 738 | |
| 739 | void Shell::CreateLauncher() { |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 740 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 741 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 742 | iter != controllers.end(); ++iter) |
| 743 | (*iter)->shelf()->CreateLauncher(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | void Shell::ShowLauncher() { |
Torne (Richard Coles) | b2df76e | 2013-05-13 16:52:09 +0100 | [diff] [blame] | 747 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 748 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 749 | iter != controllers.end(); ++iter) |
| 750 | (*iter)->ShowLauncher(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | void Shell::AddShellObserver(ShellObserver* observer) { |
| 754 | observers_.AddObserver(observer); |
| 755 | } |
| 756 | |
| 757 | void Shell::RemoveShellObserver(ShellObserver* observer) { |
| 758 | observers_.RemoveObserver(observer); |
| 759 | } |
| 760 | |
| 761 | void Shell::UpdateShelfVisibility() { |
| 762 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 763 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 764 | iter != controllers.end(); ++iter) |
| 765 | if ((*iter)->shelf()) |
| 766 | (*iter)->UpdateShelfVisibility(); |
| 767 | } |
| 768 | |
| 769 | void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior, |
| 770 | aura::RootWindow* root_window) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 771 | ash::internal::ShelfLayoutManager::ForLauncher(root_window)-> |
| 772 | SetAutoHideBehavior(behavior); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior( |
| 776 | aura::RootWindow* root_window) const { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 777 | return ash::internal::ShelfLayoutManager::ForLauncher(root_window)-> |
| 778 | auto_hide_behavior(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | void Shell::SetShelfAlignment(ShelfAlignment alignment, |
| 782 | aura::RootWindow* root_window) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 783 | if (ash::internal::ShelfLayoutManager::ForLauncher(root_window)-> |
| 784 | SetAlignment(alignment)) { |
| 785 | FOR_EACH_OBSERVER( |
| 786 | ShellObserver, observers_, OnShelfAlignmentChanged(root_window)); |
| 787 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | ShelfAlignment Shell::GetShelfAlignment(aura::RootWindow* root_window) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 791 | return GetRootWindowController(root_window)-> |
| 792 | GetShelfLayoutManager()->GetAlignment(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | void Shell::SetDimming(bool should_dim) { |
| 796 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 797 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 798 | iter != controllers.end(); ++iter) |
| 799 | (*iter)->screen_dimmer()->SetDimming(should_dim); |
| 800 | } |
| 801 | |
| 802 | void Shell::CreateModalBackground(aura::Window* window) { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 803 | if (!modality_filter_) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 804 | modality_filter_.reset(new internal::SystemModalContainerEventFilter(this)); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 805 | AddPreTargetHandler(modality_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 806 | } |
| 807 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 808 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 809 | iter != controllers.end(); ++iter) |
| 810 | (*iter)->GetSystemModalLayoutManager(window)->CreateModalBackground(); |
| 811 | } |
| 812 | |
| 813 | void Shell::OnModalWindowRemoved(aura::Window* removed) { |
| 814 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 815 | bool activated = false; |
| 816 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 817 | iter != controllers.end() && !activated; ++iter) { |
| 818 | activated = (*iter)->GetSystemModalLayoutManager(removed)-> |
| 819 | ActivateNextModalWindow(); |
| 820 | } |
| 821 | if (!activated) { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 822 | RemovePreTargetHandler(modality_filter_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 823 | modality_filter_.reset(); |
| 824 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 825 | iter != controllers.end(); ++iter) |
| 826 | (*iter)->GetSystemModalLayoutManager(removed)->DestroyModalBackground(); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | WebNotificationTray* Shell::GetWebNotificationTray() { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 831 | return GetPrimaryRootWindowController()->shelf()-> |
| 832 | status_area_widget()->web_notification_tray(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 835 | bool Shell::HasPrimaryStatusArea() { |
| 836 | ShelfWidget* shelf = GetPrimaryRootWindowController()->shelf(); |
| 837 | return shelf && shelf->status_area_widget(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 838 | } |
| 839 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 840 | SystemTray* Shell::GetPrimarySystemTray() { |
| 841 | return GetPrimaryRootWindowController()->GetSystemTray(); |
| 842 | } |
| 843 | |
| 844 | LauncherDelegate* Shell::GetLauncherDelegate() { |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 845 | if (!launcher_delegate_) { |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 846 | launcher_model_.reset(new LauncherModel); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 847 | launcher_delegate_.reset( |
| 848 | delegate_->CreateLauncherDelegate(launcher_model_.get())); |
| 849 | } |
| 850 | return launcher_delegate_.get(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 851 | } |
| 852 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 853 | void Shell::SetTouchHudProjectionEnabled(bool enabled) { |
| 854 | if (is_touch_hud_projection_enabled_ == enabled) |
| 855 | return; |
| 856 | |
| 857 | RootWindowList roots = GetInstance()->GetAllRootWindows(); |
| 858 | for (RootWindowList::iterator iter = roots.begin(); iter != roots.end(); |
| 859 | ++iter) { |
| 860 | internal::RootWindowController* controller = GetRootWindowController(*iter); |
| 861 | if (enabled) |
| 862 | controller->EnableTouchHudProjection(); |
| 863 | else |
| 864 | controller->DisableTouchHudProjection(); |
| 865 | } |
| 866 | is_touch_hud_projection_enabled_ = enabled; |
| 867 | } |
| 868 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 869 | void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 870 | internal::RootWindowController* controller = |
| 871 | new internal::RootWindowController(root); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 872 | // Pass false for the |is_first_run_after_boot| parameter so we'll show a |
| 873 | // black background on this display instead of trying to mimic the boot splash |
| 874 | // screen. |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 875 | InitRootWindowController(controller, false); |
| 876 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 877 | controller->root_window_layout()->OnWindowResized(); |
| 878 | desktop_background_controller_->OnRootWindowAdded(root); |
| 879 | high_contrast_controller_->OnRootWindowAdded(root); |
| 880 | root->ShowRootWindow(); |
| 881 | // Activate new root for testing. |
| 882 | active_root_window_ = root; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 883 | |
| 884 | // Create a launcher if a user is already logged. |
| 885 | if (Shell::GetInstance()->session_state_delegate()->NumberOfLoggedInUsers()) |
| 886 | controller->shelf()->CreateLauncher(); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | void Shell::DoInitialWorkspaceAnimation() { |
| 890 | return GetPrimaryRootWindowController()->workspace_controller()-> |
| 891 | DoInitialAnimation(); |
| 892 | } |
| 893 | |
| 894 | void Shell::InitRootWindowController( |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 895 | internal::RootWindowController* controller, |
| 896 | bool first_run_after_boot) { |
| 897 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 898 | aura::RootWindow* root_window = controller->root_window(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 899 | DCHECK(activation_client_); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 900 | DCHECK(visibility_controller_.get()); |
| 901 | DCHECK(drag_drop_controller_.get()); |
| 902 | DCHECK(capture_controller_.get()); |
| 903 | DCHECK(window_cycle_controller_.get()); |
| 904 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 905 | aura::client::SetFocusClient(root_window, focus_client_.get()); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 906 | input_method_filter_->SetInputMethodPropertyInRootWindow(root_window); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 907 | aura::client::SetActivationClient(root_window, activation_client_); |
| 908 | if (views::corewm::UseFocusController()) { |
| 909 | views::corewm::FocusController* controller = |
| 910 | static_cast<views::corewm::FocusController*>(activation_client_); |
| 911 | root_window->AddPreTargetHandler(controller); |
| 912 | } |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 913 | aura::client::SetVisibilityClient(root_window, visibility_controller_.get()); |
| 914 | aura::client::SetDragDropClient(root_window, drag_drop_controller_.get()); |
| 915 | aura::client::SetCaptureClient(root_window, capture_controller_.get()); |
| 916 | aura::client::SetScreenPositionClient(root_window, |
| 917 | screen_position_controller_.get()); |
| 918 | aura::client::SetCursorClient(root_window, &cursor_manager_); |
| 919 | aura::client::SetTooltipClient(root_window, tooltip_controller_.get()); |
| 920 | aura::client::SetEventClient(root_window, event_client_.get()); |
| 921 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 922 | if (nested_dispatcher_controller_) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 923 | aura::client::SetDispatcherClient(root_window, |
| 924 | nested_dispatcher_controller_.get()); |
| 925 | } |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 926 | if (user_action_client_) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 927 | aura::client::SetUserActionClient(root_window, user_action_client_.get()); |
| 928 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame^] | 929 | controller->Init(first_run_after_boot); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 930 | |
| 931 | window_cycle_controller_->OnRootWindowAdded(root_window); |
| 932 | } |
| 933 | |
| 934 | //////////////////////////////////////////////////////////////////////////////// |
| 935 | // Shell, private: |
| 936 | |
| 937 | bool Shell::CanWindowReceiveEvents(aura::Window* window) { |
| 938 | RootWindowControllerList controllers = GetAllRootWindowControllers(); |
| 939 | for (RootWindowControllerList::iterator iter = controllers.begin(); |
| 940 | iter != controllers.end(); ++iter) { |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 941 | internal::SystemModalContainerLayoutManager* layout_manager = |
| 942 | (*iter)->GetSystemModalLayoutManager(window); |
| 943 | if (layout_manager && layout_manager->CanWindowReceiveEvents(window)) |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 944 | return true; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 945 | } |
| 946 | return false; |
| 947 | } |
| 948 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 949 | //////////////////////////////////////////////////////////////////////////////// |
| 950 | // Shell, ui::EventTarget overrides: |
| 951 | |
| 952 | bool Shell::CanAcceptEvent(const ui::Event& event) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 953 | return true; |
| 954 | } |
| 955 | |
| 956 | ui::EventTarget* Shell::GetParentTarget() { |
| 957 | return NULL; |
| 958 | } |
| 959 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 960 | void Shell::OnEvent(ui::Event* event) { |
| 961 | } |
| 962 | |
| 963 | //////////////////////////////////////////////////////////////////////////////// |
| 964 | // Shell, aura::client::ActivationChangeObserver implementation: |
| 965 | |
| 966 | void Shell::OnWindowActivated(aura::Window* gained_active, |
| 967 | aura::Window* lost_active) { |
| 968 | if (gained_active) |
| 969 | active_root_window_ = gained_active->GetRootWindow(); |
| 970 | } |
| 971 | |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 972 | } // namespace ash |