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