OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/shell.h" | 5 #include "ash/shell.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ash/accelerators/focus_manager_factory.h" | 10 #include "ash/accelerators/focus_manager_factory.h" |
11 #include "ash/ash_switches.h" | 11 #include "ash/ash_switches.h" |
12 #include "ash/desktop_background/desktop_background_controller.h" | 12 #include "ash/desktop_background/desktop_background_controller.h" |
13 #include "ash/desktop_background/desktop_background_resources.h" | 13 #include "ash/desktop_background/desktop_background_resources.h" |
14 #include "ash/desktop_background/desktop_background_view.h" | 14 #include "ash/desktop_background/desktop_background_view.h" |
15 #include "ash/drag_drop/drag_drop_controller.h" | 15 #include "ash/drag_drop/drag_drop_controller.h" |
16 #include "ash/focus_cycler.h" | 16 #include "ash/focus_cycler.h" |
17 #include "ash/high_contrast/high_contrast_controller.h" | 17 #include "ash/high_contrast/high_contrast_controller.h" |
18 #include "ash/launcher/launcher.h" | 18 #include "ash/launcher/launcher.h" |
19 #include "ash/magnifier/magnification_controller.h" | 19 #include "ash/magnifier/magnification_controller.h" |
20 #include "ash/monitor/monitor_controller.h" | 20 #include "ash/monitor/monitor_controller.h" |
21 #include "ash/monitor/multi_monitor_manager.h" | 21 #include "ash/monitor/multi_monitor_manager.h" |
22 #include "ash/monitor/secondary_monitor_view.h" | 22 #include "ash/monitor/secondary_monitor_view.h" |
| 23 #include "ash/root_window_controller.h" |
23 #include "ash/screen_ash.h" | 24 #include "ash/screen_ash.h" |
24 #include "ash/shell_context_menu.h" | 25 #include "ash/shell_context_menu.h" |
25 #include "ash/shell_delegate.h" | 26 #include "ash/shell_delegate.h" |
26 #include "ash/shell_factory.h" | 27 #include "ash/shell_factory.h" |
27 #include "ash/shell_window_ids.h" | 28 #include "ash/shell_window_ids.h" |
28 #include "ash/system/status_area_widget.h" | 29 #include "ash/system/status_area_widget.h" |
29 #include "ash/system/tray/system_tray.h" | 30 #include "ash/system/tray/system_tray.h" |
30 #include "ash/tooltips/tooltip_controller.h" | 31 #include "ash/tooltips/tooltip_controller.h" |
31 #include "ash/touch/touch_observer_hud.h" | 32 #include "ash/touch/touch_observer_hud.h" |
32 #include "ash/wm/activation_controller.h" | 33 #include "ash/wm/activation_controller.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 #include "ui/aura/dispatcher_linux.h" | 100 #include "ui/aura/dispatcher_linux.h" |
100 #endif // defined(OS_CHROMEOS) | 101 #endif // defined(OS_CHROMEOS) |
101 | 102 |
102 namespace ash { | 103 namespace ash { |
103 | 104 |
104 namespace { | 105 namespace { |
105 | 106 |
106 using aura::Window; | 107 using aura::Window; |
107 using views::Widget; | 108 using views::Widget; |
108 | 109 |
109 // Creates a new window for use as a container. | |
110 aura::Window* CreateContainer(int window_id, | |
111 const char* name, | |
112 aura::Window* parent) { | |
113 aura::Window* container = new aura::Window(NULL); | |
114 container->set_id(window_id); | |
115 container->SetName(name); | |
116 container->Init(ui::LAYER_NOT_DRAWN); | |
117 parent->AddChild(container); | |
118 if (window_id != internal::kShellWindowId_UnparentedControlContainer) | |
119 container->Show(); | |
120 return container; | |
121 } | |
122 | |
123 // Creates each of the special window containers that holds windows of various | |
124 // types in the shell UI. | |
125 void CreateSpecialContainers(aura::RootWindow* root_window) { | |
126 // These containers are just used by PowerButtonController to animate groups | |
127 // of containers simultaneously without messing up the current transformations | |
128 // on those containers. These are direct children of the root window; all of | |
129 // the other containers are their children. | |
130 aura::Window* non_lock_screen_containers = CreateContainer( | |
131 internal::kShellWindowId_NonLockScreenContainersContainer, | |
132 "NonLockScreenContainersContainer", | |
133 root_window); | |
134 aura::Window* lock_screen_containers = CreateContainer( | |
135 internal::kShellWindowId_LockScreenContainersContainer, | |
136 "LockScreenContainersContainer", | |
137 root_window); | |
138 aura::Window* lock_screen_related_containers = CreateContainer( | |
139 internal::kShellWindowId_LockScreenRelatedContainersContainer, | |
140 "LockScreenRelatedContainersContainer", | |
141 root_window); | |
142 | |
143 CreateContainer(internal::kShellWindowId_UnparentedControlContainer, | |
144 "UnparentedControlContainer", | |
145 non_lock_screen_containers); | |
146 | |
147 aura::Window* desktop_background_containers = CreateContainer( | |
148 internal::kShellWindowId_DesktopBackgroundContainer, | |
149 "DesktopBackgroundContainer", | |
150 non_lock_screen_containers); | |
151 SetChildWindowVisibilityChangesAnimated(desktop_background_containers); | |
152 | |
153 aura::Window* default_container = CreateContainer( | |
154 internal::kShellWindowId_DefaultContainer, | |
155 "DefaultContainer", | |
156 non_lock_screen_containers); | |
157 default_container->SetEventFilter( | |
158 new ToplevelWindowEventFilter(default_container)); | |
159 SetChildWindowVisibilityChangesAnimated(default_container); | |
160 | |
161 aura::Window* always_on_top_container = CreateContainer( | |
162 internal::kShellWindowId_AlwaysOnTopContainer, | |
163 "AlwaysOnTopContainer", | |
164 non_lock_screen_containers); | |
165 always_on_top_container->SetEventFilter( | |
166 new ToplevelWindowEventFilter(always_on_top_container)); | |
167 SetChildWindowVisibilityChangesAnimated(always_on_top_container); | |
168 | |
169 CreateContainer(internal::kShellWindowId_PanelContainer, | |
170 "PanelContainer", | |
171 non_lock_screen_containers); | |
172 | |
173 CreateContainer(internal::kShellWindowId_LauncherContainer, | |
174 "LauncherContainer", | |
175 non_lock_screen_containers); | |
176 | |
177 CreateContainer(internal::kShellWindowId_AppListContainer, | |
178 "AppListContainer", | |
179 non_lock_screen_containers); | |
180 | |
181 aura::Window* modal_container = CreateContainer( | |
182 internal::kShellWindowId_SystemModalContainer, | |
183 "SystemModalContainer", | |
184 non_lock_screen_containers); | |
185 modal_container->SetEventFilter( | |
186 new ToplevelWindowEventFilter(modal_container)); | |
187 modal_container->SetLayoutManager( | |
188 new internal::SystemModalContainerLayoutManager(modal_container)); | |
189 SetChildWindowVisibilityChangesAnimated(modal_container); | |
190 | |
191 // TODO(beng): Figure out if we can make this use | |
192 // SystemModalContainerEventFilter instead of stops_event_propagation. | |
193 aura::Window* lock_container = CreateContainer( | |
194 internal::kShellWindowId_LockScreenContainer, | |
195 "LockScreenContainer", | |
196 lock_screen_containers); | |
197 lock_container->SetLayoutManager( | |
198 new internal::BaseLayoutManager(root_window)); | |
199 // TODO(beng): stopsevents | |
200 | |
201 aura::Window* lock_modal_container = CreateContainer( | |
202 internal::kShellWindowId_LockSystemModalContainer, | |
203 "LockSystemModalContainer", | |
204 lock_screen_containers); | |
205 lock_modal_container->SetEventFilter( | |
206 new ToplevelWindowEventFilter(lock_modal_container)); | |
207 lock_modal_container->SetLayoutManager( | |
208 new internal::SystemModalContainerLayoutManager(lock_modal_container)); | |
209 SetChildWindowVisibilityChangesAnimated(lock_modal_container); | |
210 | |
211 CreateContainer(internal::kShellWindowId_StatusContainer, | |
212 "StatusContainer", | |
213 lock_screen_related_containers); | |
214 | |
215 aura::Window* settings_bubble_container = CreateContainer( | |
216 internal::kShellWindowId_SettingBubbleContainer, | |
217 "SettingBubbleContainer", | |
218 lock_screen_related_containers); | |
219 SetChildWindowVisibilityChangesAnimated(settings_bubble_container); | |
220 | |
221 aura::Window* menu_container = CreateContainer( | |
222 internal::kShellWindowId_MenuContainer, | |
223 "MenuContainer", | |
224 lock_screen_related_containers); | |
225 SetChildWindowVisibilityChangesAnimated(menu_container); | |
226 | |
227 aura::Window* drag_drop_container = CreateContainer( | |
228 internal::kShellWindowId_DragImageAndTooltipContainer, | |
229 "DragImageAndTooltipContainer", | |
230 lock_screen_related_containers); | |
231 SetChildWindowVisibilityChangesAnimated(drag_drop_container); | |
232 | |
233 CreateContainer(internal::kShellWindowId_OverlayContainer, | |
234 "OverlayContainer", | |
235 lock_screen_related_containers); | |
236 } | |
237 | |
238 // This dummy class is used for shell unit tests. We dont have chrome delegate | 110 // This dummy class is used for shell unit tests. We dont have chrome delegate |
239 // in these tests. | 111 // in these tests. |
240 class DummyUserWallpaperDelegate : public UserWallpaperDelegate { | 112 class DummyUserWallpaperDelegate : public UserWallpaperDelegate { |
241 public: | 113 public: |
242 DummyUserWallpaperDelegate() {} | 114 DummyUserWallpaperDelegate() {} |
243 | 115 |
244 virtual ~DummyUserWallpaperDelegate() {} | 116 virtual ~DummyUserWallpaperDelegate() {} |
245 | 117 |
246 virtual void InitializeWallpaper() OVERRIDE { | 118 virtual void InitializeWallpaper() OVERRIDE { |
247 ash::Shell::GetInstance()->desktop_background_controller()-> | 119 ash::Shell::GetInstance()->desktop_background_controller()-> |
(...skipping 17 matching lines...) Expand all Loading... |
265 Shell* Shell::instance_ = NULL; | 137 Shell* Shell::instance_ = NULL; |
266 // static | 138 // static |
267 bool Shell::initially_hide_cursor_ = false; | 139 bool Shell::initially_hide_cursor_ = false; |
268 | 140 |
269 //////////////////////////////////////////////////////////////////////////////// | 141 //////////////////////////////////////////////////////////////////////////////// |
270 // Shell::TestApi | 142 // Shell::TestApi |
271 | 143 |
272 Shell::TestApi::TestApi(Shell* shell) : shell_(shell) {} | 144 Shell::TestApi::TestApi(Shell* shell) : shell_(shell) {} |
273 | 145 |
274 internal::RootWindowLayoutManager* Shell::TestApi::root_window_layout() { | 146 internal::RootWindowLayoutManager* Shell::TestApi::root_window_layout() { |
275 return shell_->root_window_layout_; | 147 return shell_->GetPrimaryRootWindowController()->root_window_layout(); |
276 } | 148 } |
277 | 149 |
278 aura::shared::InputMethodEventFilter* | 150 aura::shared::InputMethodEventFilter* |
279 Shell::TestApi::input_method_event_filter() { | 151 Shell::TestApi::input_method_event_filter() { |
280 return shell_->input_method_filter_.get(); | 152 return shell_->input_method_filter_.get(); |
281 } | 153 } |
282 | 154 |
283 internal::SystemGestureEventFilter* | 155 internal::SystemGestureEventFilter* |
284 Shell::TestApi::system_gesture_event_filter() { | 156 Shell::TestApi::system_gesture_event_filter() { |
285 return shell_->system_gesture_filter_.get(); | 157 return shell_->system_gesture_filter_.get(); |
286 } | 158 } |
287 | 159 |
288 internal::WorkspaceController* Shell::TestApi::workspace_controller() { | 160 internal::WorkspaceController* Shell::TestApi::workspace_controller() { |
289 return shell_->workspace_controller_.get(); | 161 return shell_->GetPrimaryRootWindowController()->workspace_controller(); |
290 } | 162 } |
291 | 163 |
292 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
293 // Shell, public: | 165 // Shell, public: |
294 | 166 |
295 Shell::Shell(ShellDelegate* delegate) | 167 Shell::Shell(ShellDelegate* delegate) |
296 : root_window_(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()), | 168 : screen_(new ScreenAsh), |
297 screen_(new ScreenAsh), | |
298 env_filter_(NULL), | 169 env_filter_(NULL), |
299 delegate_(delegate), | 170 delegate_(delegate), |
300 #if defined(OS_CHROMEOS) | 171 #if defined(OS_CHROMEOS) |
301 output_configurator_(new chromeos::OutputConfigurator()), | 172 output_configurator_(new chromeos::OutputConfigurator()), |
302 #endif // defined(OS_CHROMEOS) | 173 #endif // defined(OS_CHROMEOS) |
303 shelf_(NULL), | 174 shelf_(NULL), |
304 panel_layout_manager_(NULL), | 175 panel_layout_manager_(NULL), |
305 root_window_layout_(NULL), | |
306 status_area_widget_(NULL), | 176 status_area_widget_(NULL), |
307 browser_context_(NULL) { | 177 browser_context_(NULL) { |
308 gfx::Screen::SetInstance(screen_); | 178 gfx::Screen::SetInstance(screen_); |
309 ui_controls::InstallUIControlsAura(internal::CreateUIControls()); | 179 ui_controls::InstallUIControlsAura(internal::CreateUIControls()); |
310 #if defined(OS_CHROMEOS) | 180 #if defined(OS_CHROMEOS) |
311 // OutputConfigurator needs to get events regarding added/removed outputs. | 181 // OutputConfigurator needs to get events regarding added/removed outputs. |
312 static_cast<aura::DispatcherLinux*>( | 182 static_cast<aura::DispatcherLinux*>( |
313 aura::Env::GetInstance()->GetDispatcher())->AddDispatcherForRootWindow( | 183 aura::Env::GetInstance()->GetDispatcher())->AddDispatcherForRootWindow( |
314 output_configurator()); | 184 output_configurator()); |
315 #endif // defined(OS_CHROMEOS) | 185 #endif // defined(OS_CHROMEOS) |
(...skipping 10 matching lines...) Expand all Loading... |
326 RemoveEnvEventFilter(input_method_filter_.get()); | 196 RemoveEnvEventFilter(input_method_filter_.get()); |
327 RemoveEnvEventFilter(window_modality_controller_.get()); | 197 RemoveEnvEventFilter(window_modality_controller_.get()); |
328 RemoveEnvEventFilter(system_gesture_filter_.get()); | 198 RemoveEnvEventFilter(system_gesture_filter_.get()); |
329 RemoveEnvEventFilter(slow_animation_filter_.get()); | 199 RemoveEnvEventFilter(slow_animation_filter_.get()); |
330 #if !defined(OS_MACOSX) | 200 #if !defined(OS_MACOSX) |
331 RemoveEnvEventFilter(accelerator_filter_.get()); | 201 RemoveEnvEventFilter(accelerator_filter_.get()); |
332 #endif | 202 #endif |
333 if (touch_observer_hud_.get()) | 203 if (touch_observer_hud_.get()) |
334 RemoveEnvEventFilter(touch_observer_hud_.get()); | 204 RemoveEnvEventFilter(touch_observer_hud_.get()); |
335 | 205 |
336 // Close background widget now so that the focus manager of the | |
337 // widget gets deleted in the final message loop run. | |
338 root_window_layout_->SetBackgroundWidget(NULL); | |
339 | |
340 aura::RootWindow* root_window = GetPrimaryRootWindow(); | |
341 | |
342 // TooltipController is deleted with the Shell so removing its references. | 206 // TooltipController is deleted with the Shell so removing its references. |
343 RemoveEnvEventFilter(tooltip_controller_.get()); | 207 RemoveEnvEventFilter(tooltip_controller_.get()); |
344 aura::client::SetTooltipClient(root_window, NULL); | |
345 tooltip_controller_.reset(); | |
346 | |
347 // Make sure we delete WorkspaceController before launcher is | |
348 // deleted as it has a reference to launcher model. | |
349 workspace_controller_.reset(); | |
350 | 208 |
351 // The status area needs to be shut down before the windows are destroyed. | 209 // The status area needs to be shut down before the windows are destroyed. |
352 status_area_widget_->Shutdown(); | 210 status_area_widget_->Shutdown(); |
353 | 211 |
354 // AppList needs to be released before shelf layout manager, which is | 212 // AppList needs to be released before shelf layout manager, which is |
355 // destroyed with launcher container in the loop below. However, app list | 213 // destroyed with launcher container in the loop below. However, app list |
356 // container is now on top of launcher container and released after it. | 214 // container is now on top of launcher container and released after it. |
357 // TODO(xiyuan): Move it back when app list container is no longer needed. | 215 // TODO(xiyuan): Move it back when app list container is no longer needed. |
358 app_list_controller_.reset(); | 216 app_list_controller_.reset(); |
359 | 217 |
360 // Destroy secondary monitor's widgets before all the windows are destroyed. | 218 // Destroy secondary monitor's widgets before all the windows are destroyed. |
361 monitor_controller_.reset(); | 219 monitor_controller_.reset(); |
362 | 220 |
363 // Delete containers now so that child windows does not access | 221 root_window_controller_->CloseChildWindows(); |
364 // observers when they are destructed. | |
365 while (!root_window->children().empty()) { | |
366 aura::Window* child = root_window->children()[0]; | |
367 delete child; | |
368 } | |
369 | 222 |
370 // These need a valid Shell instance to clean up properly, so explicitly | 223 // These need a valid Shell instance to clean up properly, so explicitly |
371 // delete them before invalidating the instance. | 224 // delete them before invalidating the instance. |
372 // Alphabetical. | 225 // Alphabetical. |
373 drag_drop_controller_.reset(); | 226 drag_drop_controller_.reset(); |
374 event_client_.reset(); | |
375 magnification_controller_.reset(); | 227 magnification_controller_.reset(); |
376 monitor_controller_.reset(); | 228 monitor_controller_.reset(); |
377 power_button_controller_.reset(); | 229 power_button_controller_.reset(); |
378 resize_shadow_controller_.reset(); | 230 resize_shadow_controller_.reset(); |
379 screen_dimmer_.reset(); | |
380 shadow_controller_.reset(); | 231 shadow_controller_.reset(); |
381 tooltip_controller_.reset(); | 232 tooltip_controller_.reset(); |
382 window_cycle_controller_.reset(); | 233 window_cycle_controller_.reset(); |
383 aura::client::SetCaptureClient(root_window, NULL); | |
384 capture_controller_.reset(); | 234 capture_controller_.reset(); |
385 aura::client::SetDispatcherClient(root_window, NULL); | |
386 nested_dispatcher_controller_.reset(); | 235 nested_dispatcher_controller_.reset(); |
387 aura::client::SetUserActionClient(root_window, NULL); | |
388 user_action_client_.reset(); | 236 user_action_client_.reset(); |
389 aura::client::SetVisibilityClient(root_window, NULL); | |
390 visibility_controller_.reset(); | 237 visibility_controller_.reset(); |
391 | 238 |
| 239 root_window_controller_.reset(); |
| 240 |
392 // Launcher widget has a InputMethodBridge that references to | 241 // Launcher widget has a InputMethodBridge that references to |
393 // input_method_filter_'s input_method_. So explicitly release launcher_ | 242 // input_method_filter_'s input_method_. So explicitly release launcher_ |
394 // before input_method_filter_. And this needs to be after we delete all | 243 // before input_method_filter_. And this needs to be after we delete all |
395 // containers in case there are still live browser windows which access | 244 // containers in case there are still live browser windows which access |
396 // LauncherModel during close. | 245 // LauncherModel during close. |
397 launcher_.reset(); | 246 launcher_.reset(); |
398 | 247 |
399 // Delete the activation controller after other controllers and launcher | 248 // Delete the activation controller after other controllers and launcher |
400 // because they might have registered ActivationChangeObserver. | 249 // because they might have registered ActivationChangeObserver. |
401 aura::client::SetActivationClient(root_window, NULL); | |
402 activation_controller_.reset(); | 250 activation_controller_.reset(); |
403 | 251 |
404 DCHECK(instance_ == this); | 252 DCHECK(instance_ == this); |
405 instance_ = NULL; | 253 instance_ = NULL; |
406 | 254 |
407 #if defined(OS_CHROMEOS) | 255 #if defined(OS_CHROMEOS) |
408 // Remove OutputConfigurator from Dispatcher. | 256 // Remove OutputConfigurator from Dispatcher. |
409 static_cast<aura::DispatcherLinux*>( | 257 static_cast<aura::DispatcherLinux*>( |
410 aura::Env::GetInstance()->GetDispatcher())->RemoveDispatcherForRootWindow( | 258 aura::Env::GetInstance()->GetDispatcher())->RemoveDispatcherForRootWindow( |
411 output_configurator()); | 259 output_configurator()); |
(...skipping 21 matching lines...) Expand all Loading... |
433 return !!instance_; | 281 return !!instance_; |
434 } | 282 } |
435 | 283 |
436 // static | 284 // static |
437 void Shell::DeleteInstance() { | 285 void Shell::DeleteInstance() { |
438 delete instance_; | 286 delete instance_; |
439 instance_ = NULL; | 287 instance_ = NULL; |
440 } | 288 } |
441 | 289 |
442 // static | 290 // static |
| 291 internal::RootWindowController* Shell::GetPrimaryRootWindowController() { |
| 292 return GetInstance()->root_window_controller_.get(); |
| 293 } |
| 294 |
| 295 // static |
443 aura::RootWindow* Shell::GetPrimaryRootWindow() { | 296 aura::RootWindow* Shell::GetPrimaryRootWindow() { |
444 return GetInstance()->root_window_.get(); | 297 return GetPrimaryRootWindowController()->root_window(); |
445 } | 298 } |
446 | 299 |
447 // static | 300 // static |
448 aura::RootWindow* Shell::GetActiveRootWindow() { | 301 aura::RootWindow* Shell::GetActiveRootWindow() { |
449 return GetInstance()->active_root_window_; | 302 return GetInstance()->active_root_window_; |
450 } | 303 } |
451 | 304 |
452 // static | 305 // static |
453 aura::RootWindow* Shell::GetRootWindowAt(const gfx::Point& point) { | 306 aura::RootWindow* Shell::GetRootWindowAt(const gfx::Point& point) { |
454 // TODO(oshima): Support multiple root windows. | 307 // TODO(oshima): Support multiple root windows. |
(...skipping 19 matching lines...) Expand all Loading... |
474 void Shell::Init() { | 327 void Shell::Init() { |
475 // Install the custom factory first so that views::FocusManagers for Tray, | 328 // Install the custom factory first so that views::FocusManagers for Tray, |
476 // Launcher, and WallPaper could be created by the factory. | 329 // Launcher, and WallPaper could be created by the factory. |
477 views::FocusManagerFactory::Install(new AshFocusManagerFactory); | 330 views::FocusManagerFactory::Install(new AshFocusManagerFactory); |
478 | 331 |
479 env_filter_ = new aura::shared::CompoundEventFilter; | 332 env_filter_ = new aura::shared::CompoundEventFilter; |
480 // Pass ownership of the filter to the Env. | 333 // Pass ownership of the filter to the Env. |
481 aura::Env::GetInstance()->SetEventFilter(env_filter_); | 334 aura::Env::GetInstance()->SetEventFilter(env_filter_); |
482 | 335 |
483 aura::Env::GetInstance()->cursor_manager()->set_delegate(this); | 336 aura::Env::GetInstance()->cursor_manager()->set_delegate(this); |
484 | 337 aura::RootWindow* root_window = |
485 aura::RootWindow* root_window = GetPrimaryRootWindow(); | 338 aura::MonitorManager::CreateRootWindowForPrimaryMonitor(); |
486 active_root_window_ = root_window; | 339 active_root_window_ = root_window; |
487 | 340 |
488 focus_manager_.reset(new aura::FocusManager); | 341 focus_manager_.reset(new aura::FocusManager); |
489 root_window_->set_focus_manager(focus_manager_.get()); | |
490 | 342 |
491 #if !defined(OS_MACOSX) | 343 #if !defined(OS_MACOSX) |
492 nested_dispatcher_controller_.reset(new NestedDispatcherController); | 344 nested_dispatcher_controller_.reset(new NestedDispatcherController); |
493 aura::client::SetDispatcherClient(root_window, | |
494 nested_dispatcher_controller_.get()); | |
495 accelerator_controller_.reset(new AcceleratorController); | 345 accelerator_controller_.reset(new AcceleratorController); |
496 #endif | 346 #endif |
497 shell_context_menu_.reset(new internal::ShellContextMenu); | 347 shell_context_menu_.reset(new internal::ShellContextMenu); |
498 | 348 |
499 // The order in which event filters are added is significant. | 349 // The order in which event filters are added is significant. |
500 DCHECK(!GetEnvEventFilterCount()); | 350 DCHECK(!GetEnvEventFilterCount()); |
501 user_activity_detector_.reset(new UserActivityDetector); | 351 user_activity_detector_.reset(new UserActivityDetector); |
502 AddEnvEventFilter(user_activity_detector_.get()); | 352 AddEnvEventFilter(user_activity_detector_.get()); |
503 | 353 |
504 DCHECK_EQ(1U, GetEnvEventFilterCount()); | 354 DCHECK_EQ(1U, GetEnvEventFilterCount()); |
505 key_rewriter_filter_.reset(new internal::KeyRewriterEventFilter); | 355 key_rewriter_filter_.reset(new internal::KeyRewriterEventFilter); |
506 AddEnvEventFilter(key_rewriter_filter_.get()); | 356 AddEnvEventFilter(key_rewriter_filter_.get()); |
507 | 357 |
508 DCHECK_EQ(2U, GetEnvEventFilterCount()); | 358 DCHECK_EQ(2U, GetEnvEventFilterCount()); |
509 partial_screenshot_filter_.reset(new internal::PartialScreenshotEventFilter); | 359 partial_screenshot_filter_.reset(new internal::PartialScreenshotEventFilter); |
510 AddEnvEventFilter(partial_screenshot_filter_.get()); | 360 AddEnvEventFilter(partial_screenshot_filter_.get()); |
511 AddShellObserver(partial_screenshot_filter_.get()); | 361 AddShellObserver(partial_screenshot_filter_.get()); |
512 | 362 |
513 DCHECK_EQ(3U, GetEnvEventFilterCount()); | 363 DCHECK_EQ(3U, GetEnvEventFilterCount()); |
514 input_method_filter_.reset(new aura::shared::InputMethodEventFilter()); | 364 input_method_filter_.reset(new aura::shared::InputMethodEventFilter()); |
515 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window); | |
516 AddEnvEventFilter(input_method_filter_.get()); | 365 AddEnvEventFilter(input_method_filter_.get()); |
517 | 366 |
518 #if !defined(OS_MACOSX) | 367 #if !defined(OS_MACOSX) |
519 accelerator_filter_.reset(new internal::AcceleratorFilter); | 368 accelerator_filter_.reset(new internal::AcceleratorFilter); |
520 AddEnvEventFilter(accelerator_filter_.get()); | 369 AddEnvEventFilter(accelerator_filter_.get()); |
521 #endif | 370 #endif |
522 | 371 |
523 system_gesture_filter_.reset(new internal::SystemGestureEventFilter); | 372 system_gesture_filter_.reset(new internal::SystemGestureEventFilter); |
524 AddEnvEventFilter(system_gesture_filter_.get()); | 373 AddEnvEventFilter(system_gesture_filter_.get()); |
525 | 374 |
526 slow_animation_filter_.reset(new internal::SlowAnimationEventFilter); | 375 slow_animation_filter_.reset(new internal::SlowAnimationEventFilter); |
527 AddEnvEventFilter(slow_animation_filter_.get()); | 376 AddEnvEventFilter(slow_animation_filter_.get()); |
528 | 377 |
529 root_window->SetCursor(ui::kCursorPointer); | |
530 if (initially_hide_cursor_) | |
531 aura::Env::GetInstance()->cursor_manager()->ShowCursor(false); | |
532 | |
533 activation_controller_.reset( | 378 activation_controller_.reset( |
534 new internal::ActivationController(focus_manager_.get())); | 379 new internal::ActivationController(focus_manager_.get())); |
535 aura::client::SetActivationClient(root_window, activation_controller_.get()); | |
536 | 380 |
537 capture_controller_.reset(new internal::CaptureController); | 381 capture_controller_.reset(new internal::CaptureController); |
538 aura::client::SetCaptureClient(root_window, capture_controller_.get()); | |
539 | |
540 CreateSpecialContainers(root_window); | |
541 | 382 |
542 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 383 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
543 | 384 |
544 if (command_line->HasSwitch(switches::kAshTouchHud)) { | 385 if (command_line->HasSwitch(switches::kAshTouchHud)) { |
545 touch_observer_hud_.reset(new internal::TouchObserverHUD); | 386 touch_observer_hud_.reset(new internal::TouchObserverHUD); |
546 AddEnvEventFilter(touch_observer_hud_.get()); | 387 AddEnvEventFilter(touch_observer_hud_.get()); |
547 } | 388 } |
548 | 389 |
| 390 root_window_controller_.reset( |
| 391 new internal::RootWindowController(root_window)); |
| 392 root_window_controller_->CreateContainers(); |
| 393 |
| 394 // Create Controllers that may need root window. |
| 395 // TODO(oshima): Move as many controllers before creating |
| 396 // RootWindowController as possible. |
549 stacking_controller_.reset(new internal::StackingController); | 397 stacking_controller_.reset(new internal::StackingController); |
| 398 visibility_controller_.reset(new internal::VisibilityController); |
| 399 drag_drop_controller_.reset(new internal::DragDropController); |
| 400 tooltip_controller_.reset(new internal::TooltipController( |
| 401 drag_drop_controller_.get())); |
| 402 if (delegate_.get()) |
| 403 user_action_client_.reset(delegate_->CreateUserActionClient()); |
| 404 window_modality_controller_.reset(new internal::WindowModalityController); |
| 405 AddEnvEventFilter(window_modality_controller_.get()); |
| 406 AddEnvEventFilter(tooltip_controller_.get()); |
550 | 407 |
551 root_window_layout_ = new internal::RootWindowLayoutManager(root_window); | 408 magnification_controller_.reset(new internal::MagnificationController); |
552 root_window->SetLayoutManager(root_window_layout_); | 409 high_contrast_controller_.reset(new HighContrastController); |
| 410 video_detector_.reset(new VideoDetector); |
| 411 window_cycle_controller_.reset(new WindowCycleController); |
| 412 monitor_controller_.reset(new internal::MonitorController); |
553 | 413 |
554 event_client_.reset(new internal::EventClientImpl(root_window)); | 414 InitRootWindow(root_window); |
555 | 415 |
| 416 // Initialize Primary RootWindow specific items. |
556 status_area_widget_ = new internal::StatusAreaWidget(); | 417 status_area_widget_ = new internal::StatusAreaWidget(); |
557 status_area_widget_->CreateTrayViews(delegate_.get()); | 418 status_area_widget_->CreateTrayViews(delegate_.get()); |
558 status_area_widget_->Show(); | 419 status_area_widget_->Show(); |
559 | 420 |
| 421 focus_cycler_.reset(new internal::FocusCycler()); |
| 422 focus_cycler_->AddWidget(status_area_widget_); |
| 423 |
560 // This controller needs to be set before SetupManagedWindowMode. | 424 // This controller needs to be set before SetupManagedWindowMode. |
561 desktop_background_controller_.reset(new DesktopBackgroundController()); | 425 desktop_background_controller_.reset(new DesktopBackgroundController()); |
562 if (delegate_.get()) | 426 if (delegate_.get()) |
563 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate()); | 427 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate()); |
564 if (!user_wallpaper_delegate_.get()) | 428 if (!user_wallpaper_delegate_.get()) |
565 user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate()); | 429 user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate()); |
566 | 430 |
567 if (delegate_.get()) | 431 InitLayoutManagersForPrimaryDisplay(root_window_controller_.get()); |
568 user_action_client_.reset(delegate_->CreateUserActionClient()); | |
569 if (user_action_client_.get()) | |
570 aura::client::SetUserActionClient(root_window, user_action_client_.get()); | |
571 | |
572 InitLayoutManagers(); | |
573 | 432 |
574 if (!command_line->HasSwitch(switches::kAuraNoShadows)) { | 433 if (!command_line->HasSwitch(switches::kAuraNoShadows)) { |
575 resize_shadow_controller_.reset(new internal::ResizeShadowController()); | 434 resize_shadow_controller_.reset(new internal::ResizeShadowController()); |
576 shadow_controller_.reset(new internal::ShadowController()); | 435 shadow_controller_.reset(new internal::ShadowController()); |
577 } | 436 } |
578 | 437 |
579 focus_cycler_.reset(new internal::FocusCycler()); | |
580 focus_cycler_->AddWidget(status_area_widget_); | |
581 | |
582 if (!delegate_.get() || delegate_->IsUserLoggedIn()) | 438 if (!delegate_.get() || delegate_->IsUserLoggedIn()) |
583 CreateLauncher(); | 439 CreateLauncher(); |
584 | 440 |
585 // Force a layout. | 441 // Force Layout |
586 root_window->layout_manager()->OnWindowResized(); | 442 root_window_controller_->root_window_layout()->OnWindowResized(); |
587 | 443 |
588 // It needs to be created after OnWindowResized has been called, otherwise the | 444 // It needs to be created after OnWindowResized has been called, otherwise the |
589 // widget will not paint when restoring after a browser crash. | 445 // widget will not paint when restoring after a browser crash. |
590 user_wallpaper_delegate_->InitializeWallpaper(); | 446 user_wallpaper_delegate_->InitializeWallpaper(); |
591 | 447 |
592 window_modality_controller_.reset(new internal::WindowModalityController); | |
593 AddEnvEventFilter(window_modality_controller_.get()); | |
594 | |
595 visibility_controller_.reset(new internal::VisibilityController); | |
596 aura::client::SetVisibilityClient(root_window, visibility_controller_.get()); | |
597 | |
598 drag_drop_controller_.reset(new internal::DragDropController); | |
599 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get()); | |
600 | |
601 tooltip_controller_.reset( | |
602 new internal::TooltipController(drag_drop_controller_.get())); | |
603 aura::client::SetTooltipClient(root_window, tooltip_controller_.get()); | |
604 | |
605 AddEnvEventFilter(tooltip_controller_.get()); | |
606 | |
607 magnification_controller_.reset(new internal::MagnificationController); | |
608 high_contrast_controller_.reset(new HighContrastController); | |
609 power_button_controller_.reset(new PowerButtonController); | 448 power_button_controller_.reset(new PowerButtonController); |
610 AddShellObserver(power_button_controller_.get()); | 449 AddShellObserver(power_button_controller_.get()); |
611 video_detector_.reset(new VideoDetector); | 450 |
612 window_cycle_controller_.reset(new WindowCycleController); | 451 if (initially_hide_cursor_) |
613 monitor_controller_.reset(new internal::MonitorController); | 452 aura::Env::GetInstance()->cursor_manager()->ShowCursor(false); |
614 screen_dimmer_.reset(new internal::ScreenDimmer(root_window)); | |
615 } | 453 } |
616 | 454 |
617 void Shell::AddEnvEventFilter(aura::EventFilter* filter) { | 455 void Shell::AddEnvEventFilter(aura::EventFilter* filter) { |
618 env_filter_->AddFilter(filter); | 456 env_filter_->AddFilter(filter); |
619 } | 457 } |
620 | 458 |
621 void Shell::RemoveEnvEventFilter(aura::EventFilter* filter) { | 459 void Shell::RemoveEnvEventFilter(aura::EventFilter* filter) { |
622 env_filter_->RemoveFilter(filter); | 460 env_filter_->RemoveFilter(filter); |
623 } | 461 } |
624 | 462 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 } | 535 } |
698 | 536 |
699 void Shell::OnLockStateChanged(bool locked) { | 537 void Shell::OnLockStateChanged(bool locked) { |
700 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked)); | 538 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked)); |
701 } | 539 } |
702 | 540 |
703 void Shell::CreateLauncher() { | 541 void Shell::CreateLauncher() { |
704 if (launcher_.get()) | 542 if (launcher_.get()) |
705 return; | 543 return; |
706 | 544 |
707 aura::Window* default_container = GetContainer( | 545 aura::Window* default_container = |
708 GetPrimaryRootWindow(), | 546 GetPrimaryRootWindowController()-> |
709 internal::kShellWindowId_DefaultContainer); | 547 GetContainer(internal::kShellWindowId_DefaultContainer); |
710 launcher_.reset(new Launcher(default_container)); | 548 launcher_.reset(new Launcher(default_container)); |
711 | 549 |
712 launcher_->SetFocusCycler(focus_cycler_.get()); | 550 launcher_->SetFocusCycler(focus_cycler_.get()); |
713 shelf_->SetLauncher(launcher_.get()); | 551 shelf_->SetLauncher(launcher_.get()); |
714 if (panel_layout_manager_) | 552 if (panel_layout_manager_) |
715 panel_layout_manager_->SetLauncher(launcher_.get()); | 553 panel_layout_manager_->SetLauncher(launcher_.get()); |
716 | 554 |
717 launcher_->widget()->Show(); | 555 launcher_->widget()->Show(); |
718 } | 556 } |
719 | 557 |
(...skipping 21 matching lines...) Expand all Loading... |
741 if (!shelf_->SetAlignment(alignment)) | 579 if (!shelf_->SetAlignment(alignment)) |
742 return; | 580 return; |
743 FOR_EACH_OBSERVER(ShellObserver, observers_, | 581 FOR_EACH_OBSERVER(ShellObserver, observers_, |
744 OnShelfAlignmentChanged()); | 582 OnShelfAlignmentChanged()); |
745 } | 583 } |
746 | 584 |
747 ShelfAlignment Shell::GetShelfAlignment() { | 585 ShelfAlignment Shell::GetShelfAlignment() { |
748 return shelf_->alignment(); | 586 return shelf_->alignment(); |
749 } | 587 } |
750 | 588 |
| 589 void Shell::SetDimming(bool should_dim) { |
| 590 GetPrimaryRootWindowController()->screen_dimmer()->SetDimming(should_dim); |
| 591 } |
| 592 |
751 SystemTrayDelegate* Shell::tray_delegate() { | 593 SystemTrayDelegate* Shell::tray_delegate() { |
752 return status_area_widget_->system_tray_delegate(); | 594 return status_area_widget_->system_tray_delegate(); |
753 } | 595 } |
754 | 596 |
755 SystemTray* Shell::system_tray() { | 597 SystemTray* Shell::system_tray() { |
756 return status_area_widget_->system_tray(); | 598 return status_area_widget_->system_tray(); |
757 } | 599 } |
758 | 600 |
759 int Shell::GetGridSize() const { | 601 int Shell::GetGridSize() const { |
760 return workspace_controller_->workspace_manager()->grid_size(); | 602 return GetPrimaryRootWindowController()->workspace_controller()-> |
761 } | 603 workspace_manager()->grid_size(); |
762 | |
763 bool Shell::IsInMaximizedMode() const { | |
764 return workspace_controller_->workspace_manager()->IsInMaximizedMode(); | |
765 } | 604 } |
766 | 605 |
767 void Shell::InitRootWindowForSecondaryMonitor(aura::RootWindow* root) { | 606 void Shell::InitRootWindowForSecondaryMonitor(aura::RootWindow* root) { |
768 root->set_focus_manager(focus_manager_.get()); | 607 root->set_focus_manager(focus_manager_.get()); |
769 root->SetFocusWhenShown(false); | 608 root->SetFocusWhenShown(false); |
770 root->SetLayoutManager(new internal::RootWindowLayoutManager(root)); | 609 root->SetLayoutManager(new internal::RootWindowLayoutManager(root)); |
771 aura::Window* container = new aura::Window(NULL); | 610 aura::Window* container = new aura::Window(NULL); |
772 container->SetName("SecondaryMonitorContainer"); | 611 container->SetName("SecondaryMonitorContainer"); |
773 container->Init(ui::LAYER_NOT_DRAWN); | 612 container->Init(ui::LAYER_NOT_DRAWN); |
774 root->AddChild(container); | 613 root->AddChild(container); |
775 container->SetLayoutManager(new internal::BaseLayoutManager(root)); | 614 container->SetLayoutManager(new internal::BaseLayoutManager(root)); |
776 CreateSecondaryMonitorWidget(container); | 615 CreateSecondaryMonitorWidget(container); |
777 container->Show(); | 616 container->Show(); |
778 root->layout_manager()->OnWindowResized(); | 617 root->layout_manager()->OnWindowResized(); |
779 root->ShowRootWindow(); | 618 root->ShowRootWindow(); |
780 | 619 |
781 aura::client::SetCaptureClient(root, capture_controller_.get()); | 620 aura::client::SetCaptureClient(root, capture_controller_.get()); |
782 } | 621 } |
783 | 622 |
| 623 void Shell::InitRootWindow(aura::RootWindow* root_window) { |
| 624 DCHECK(activation_controller_.get()); |
| 625 DCHECK(visibility_controller_.get()); |
| 626 DCHECK(drag_drop_controller_.get()); |
| 627 DCHECK(capture_controller_.get()); |
| 628 |
| 629 root_window->set_focus_manager(focus_manager_.get()); |
| 630 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window); |
| 631 aura::client::SetActivationClient(root_window, activation_controller_.get()); |
| 632 aura::client::SetVisibilityClient(root_window, visibility_controller_.get()); |
| 633 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get()); |
| 634 aura::client::SetTooltipClient(root_window, tooltip_controller_.get()); |
| 635 aura::client::SetCaptureClient(root_window, capture_controller_.get()); |
| 636 |
| 637 if (nested_dispatcher_controller_.get()) { |
| 638 aura::client::SetDispatcherClient(root_window, |
| 639 nested_dispatcher_controller_.get()); |
| 640 } |
| 641 if (user_action_client_.get()) |
| 642 aura::client::SetUserActionClient(root_window, user_action_client_.get()); |
| 643 |
| 644 root_window->SetCursor(ui::kCursorPointer); |
| 645 root_window_controller_->InitLayoutManagers(); |
| 646 } |
| 647 |
784 //////////////////////////////////////////////////////////////////////////////// | 648 //////////////////////////////////////////////////////////////////////////////// |
785 // Shell, private: | 649 // Shell, private: |
786 | 650 |
787 void Shell::InitLayoutManagers() { | 651 void Shell::InitLayoutManagersForPrimaryDisplay( |
788 DCHECK(root_window_layout_); | 652 internal::RootWindowController* controller) { |
789 DCHECK(status_area_widget_); | 653 DCHECK(status_area_widget_); |
790 | 654 |
791 internal::ShelfLayoutManager* shelf_layout_manager = | 655 internal::ShelfLayoutManager* shelf_layout_manager = |
792 new internal::ShelfLayoutManager(status_area_widget_); | 656 new internal::ShelfLayoutManager(status_area_widget_); |
793 GetContainer( | 657 controller->GetContainer(internal::kShellWindowId_LauncherContainer)-> |
794 GetPrimaryRootWindow(), | |
795 internal::kShellWindowId_LauncherContainer)-> | |
796 SetLayoutManager(shelf_layout_manager); | 658 SetLayoutManager(shelf_layout_manager); |
797 shelf_ = shelf_layout_manager; | 659 shelf_ = shelf_layout_manager; |
798 | 660 |
799 internal::StatusAreaLayoutManager* status_area_layout_manager = | 661 internal::StatusAreaLayoutManager* status_area_layout_manager = |
800 new internal::StatusAreaLayoutManager(shelf_layout_manager); | 662 new internal::StatusAreaLayoutManager(shelf_layout_manager); |
801 GetContainer(GetPrimaryRootWindow(), | 663 controller->GetContainer(internal::kShellWindowId_StatusContainer)-> |
802 internal::kShellWindowId_StatusContainer)-> | |
803 SetLayoutManager(status_area_layout_manager); | 664 SetLayoutManager(status_area_layout_manager); |
804 | 665 |
805 aura::Window* default_container = GetContainer( | |
806 GetPrimaryRootWindow(), internal::kShellWindowId_DefaultContainer); | |
807 // Workspace manager has its own layout managers. | |
808 workspace_controller_.reset( | |
809 new internal::WorkspaceController(default_container)); | |
810 workspace_controller_->workspace_manager()->set_shelf(shelf_layout_manager); | |
811 shelf_layout_manager->set_workspace_manager( | 666 shelf_layout_manager->set_workspace_manager( |
812 workspace_controller_->workspace_manager()); | 667 controller->workspace_controller()->workspace_manager()); |
813 | 668 |
814 aura::Window* always_on_top_container = GetContainer( | 669 // TODO(oshima): Support multiple displays. |
815 GetPrimaryRootWindow(), internal::kShellWindowId_AlwaysOnTopContainer); | 670 controller->workspace_controller()->workspace_manager()-> |
816 always_on_top_container->SetLayoutManager( | 671 set_shelf(shelf()); |
817 new internal::BaseLayoutManager( | |
818 always_on_top_container->GetRootWindow())); | |
819 | 672 |
820 // Create Panel layout manager | 673 // Create Panel layout manager |
821 if (CommandLine::ForCurrentProcess()-> | 674 if (CommandLine::ForCurrentProcess()-> |
822 HasSwitch(switches::kAuraPanelManager)) { | 675 HasSwitch(switches::kAuraPanelManager)) { |
823 aura::Window* panel_container = GetContainer( | 676 aura::Window* panel_container = GetContainer( |
824 GetPrimaryRootWindow(), | 677 GetPrimaryRootWindow(), |
825 internal::kShellWindowId_PanelContainer); | 678 internal::kShellWindowId_PanelContainer); |
826 panel_layout_manager_ = | 679 panel_layout_manager_ = |
827 new internal::PanelLayoutManager(panel_container); | 680 new internal::PanelLayoutManager(panel_container); |
828 panel_container->SetEventFilter( | 681 panel_container->SetEventFilter( |
829 new internal::PanelWindowEventFilter( | 682 new internal::PanelWindowEventFilter( |
830 panel_container, panel_layout_manager_)); | 683 panel_container, panel_layout_manager_)); |
831 panel_container->SetLayoutManager(panel_layout_manager_); | 684 panel_container->SetLayoutManager(panel_layout_manager_); |
832 } | 685 } |
833 } | 686 } |
834 | 687 |
835 void Shell::DisableWorkspaceGridLayout() { | 688 void Shell::DisableWorkspaceGridLayout() { |
836 if (workspace_controller_.get()) | 689 GetPrimaryRootWindowController()-> |
837 workspace_controller_->workspace_manager()->set_grid_size(0); | 690 workspace_controller()->workspace_manager()->set_grid_size(0); |
838 } | 691 } |
839 | 692 |
840 void Shell::SetCursor(gfx::NativeCursor cursor) { | 693 void Shell::SetCursor(gfx::NativeCursor cursor) { |
841 // TODO(oshima): set cursor to all root windows. | 694 // TODO(oshima): set cursor to all root windows. |
842 GetPrimaryRootWindow()->SetCursor(cursor); | 695 GetPrimaryRootWindow()->SetCursor(cursor); |
843 } | 696 } |
844 | 697 |
845 void Shell::ShowCursor(bool visible) { | 698 void Shell::ShowCursor(bool visible) { |
846 GetPrimaryRootWindow()->ShowCursor(visible); | 699 GetPrimaryRootWindow()->ShowCursor(visible); |
847 } | 700 } |
848 | 701 |
849 } // namespace ash | 702 } // namespace ash |
OLD | NEW |