Add ScreenPositionClient::ConvertNativePointToScreen.
[chromium-blink-merge.git] / ash / shell.cc
blob894961ce87c272a0a36f37a797295c2274415d84
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.
5 #include "ash/shell.h"
7 #include <algorithm>
8 #include <string>
10 #include "ash/accelerators/focus_manager_factory.h"
11 #include "ash/ash_switches.h"
12 #include "ash/caps_lock_delegate_stub.h"
13 #include "ash/desktop_background/desktop_background_controller.h"
14 #include "ash/desktop_background/desktop_background_resources.h"
15 #include "ash/desktop_background/desktop_background_view.h"
16 #include "ash/display/display_controller.h"
17 #include "ash/display/mouse_cursor_event_filter.h"
18 #include "ash/display/multi_display_manager.h"
19 #include "ash/display/screen_position_controller.h"
20 #include "ash/display/secondary_display_view.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"
24 #include "ash/launcher/launcher.h"
25 #include "ash/magnifier/magnification_controller.h"
26 #include "ash/root_window_controller.h"
27 #include "ash/screen_ash.h"
28 #include "ash/shell_context_menu.h"
29 #include "ash/shell_delegate.h"
30 #include "ash/shell_factory.h"
31 #include "ash/shell_window_ids.h"
32 #include "ash/system/status_area_widget.h"
33 #include "ash/system/tray/system_tray.h"
34 #include "ash/tooltips/tooltip_controller.h"
35 #include "ash/touch/touch_observer_hud.h"
36 #include "ash/wm/activation_controller.h"
37 #include "ash/wm/always_on_top_controller.h"
38 #include "ash/wm/app_list_controller.h"
39 #include "ash/wm/base_layout_manager.h"
40 #include "ash/wm/capture_controller.h"
41 #include "ash/wm/custom_frame_view_ash.h"
42 #include "ash/wm/dialog_frame_view.h"
43 #include "ash/wm/event_client_impl.h"
44 #include "ash/wm/event_rewriter_event_filter.h"
45 #include "ash/wm/overlay_event_filter.h"
46 #include "ash/wm/panel_layout_manager.h"
47 #include "ash/wm/panel_window_event_filter.h"
48 #include "ash/wm/power_button_controller.h"
49 #include "ash/wm/property_util.h"
50 #include "ash/wm/resize_shadow_controller.h"
51 #include "ash/wm/root_window_layout_manager.h"
52 #include "ash/wm/screen_dimmer.h"
53 #include "ash/wm/shadow_controller.h"
54 #include "ash/wm/shelf_layout_manager.h"
55 #include "ash/wm/stacking_controller.h"
56 #include "ash/wm/status_area_layout_manager.h"
57 #include "ash/wm/system_gesture_event_filter.h"
58 #include "ash/wm/system_modal_container_layout_manager.h"
59 #include "ash/wm/user_activity_detector.h"
60 #include "ash/wm/video_detector.h"
61 #include "ash/wm/visibility_controller.h"
62 #include "ash/wm/window_cycle_controller.h"
63 #include "ash/wm/window_modality_controller.h"
64 #include "ash/wm/window_properties.h"
65 #include "ash/wm/window_util.h"
66 #include "ash/wm/workspace/workspace_layout_manager.h"
67 #include "ash/wm/workspace_controller.h"
68 #include "base/bind.h"
69 #include "base/command_line.h"
70 #include "ui/aura/client/aura_constants.h"
71 #include "ui/aura/client/user_action_client.h"
72 #include "ui/aura/display_manager.h"
73 #include "ui/aura/env.h"
74 #include "ui/aura/focus_manager.h"
75 #include "ui/aura/layout_manager.h"
76 #include "ui/aura/root_window.h"
77 #include "ui/aura/shared/compound_event_filter.h"
78 #include "ui/aura/shared/input_method_event_filter.h"
79 #include "ui/aura/ui_controls_aura.h"
80 #include "ui/aura/window.h"
81 #include "ui/compositor/layer.h"
82 #include "ui/compositor/layer_animator.h"
83 #include "ui/gfx/display.h"
84 #include "ui/gfx/image/image_skia.h"
85 #include "ui/gfx/screen.h"
86 #include "ui/gfx/size.h"
87 #include "ui/ui_controls/ui_controls.h"
88 #include "ui/views/focus/focus_manager_factory.h"
89 #include "ui/views/widget/native_widget_aura.h"
90 #include "ui/views/widget/widget.h"
92 #if !defined(OS_MACOSX)
93 #include "ash/accelerators/accelerator_controller.h"
94 #include "ash/accelerators/accelerator_filter.h"
95 #include "ash/accelerators/nested_dispatcher_controller.h"
96 #endif
98 #if defined(OS_CHROMEOS)
99 #include "ash/display/output_configurator_animation.h"
100 #include "base/message_pump_aurax11.h"
101 #include "chromeos/display/output_configurator.h"
102 #endif // defined(OS_CHROMEOS)
104 namespace ash {
106 namespace {
108 using aura::Window;
109 using views::Widget;
111 // This dummy class is used for shell unit tests. We dont have chrome delegate
112 // in these tests.
113 class DummyUserWallpaperDelegate : public UserWallpaperDelegate {
114 public:
115 DummyUserWallpaperDelegate() {}
117 virtual ~DummyUserWallpaperDelegate() {}
119 virtual ash::WindowVisibilityAnimationType GetAnimationType() OVERRIDE {
120 return WINDOW_VISIBILITY_ANIMATION_TYPE_FADE;
123 virtual void InitializeWallpaper() OVERRIDE {
124 ash::Shell::GetInstance()->desktop_background_controller()->
125 CreateEmptyWallpaper();
128 virtual void OpenSetWallpaperPage() OVERRIDE {
131 virtual bool CanOpenSetWallpaperPage() OVERRIDE {
132 return false;
135 virtual void OnWallpaperAnimationFinished() OVERRIDE {
138 virtual void OnWallpaperBootAnimationFinished() OVERRIDE {
141 private:
142 DISALLOW_COPY_AND_ASSIGN(DummyUserWallpaperDelegate);
145 } // namespace
147 // static
148 Shell* Shell::instance_ = NULL;
149 // static
150 bool Shell::initially_hide_cursor_ = false;
152 ////////////////////////////////////////////////////////////////////////////////
153 // Shell::TestApi
155 Shell::TestApi::TestApi(Shell* shell) : shell_(shell) {}
157 internal::RootWindowLayoutManager* Shell::TestApi::root_window_layout() {
158 return shell_->GetPrimaryRootWindowController()->root_window_layout();
161 aura::shared::InputMethodEventFilter*
162 Shell::TestApi::input_method_event_filter() {
163 return shell_->input_method_filter_.get();
166 internal::SystemGestureEventFilter*
167 Shell::TestApi::system_gesture_event_filter() {
168 return shell_->system_gesture_filter_.get();
171 internal::WorkspaceController* Shell::TestApi::workspace_controller() {
172 return shell_->GetPrimaryRootWindowController()->workspace_controller();
175 internal::ScreenPositionController*
176 Shell::TestApi::screen_position_controller() {
177 return shell_->screen_position_controller_.get();
180 ////////////////////////////////////////////////////////////////////////////////
181 // Shell, public:
183 Shell::Shell(ShellDelegate* delegate)
184 : screen_(new ScreenAsh),
185 active_root_window_(NULL),
186 env_filter_(NULL),
187 delegate_(delegate),
188 #if defined(OS_CHROMEOS)
189 output_configurator_(new chromeos::OutputConfigurator()),
190 output_configurator_animation_(
191 new internal::OutputConfiguratorAnimation()),
192 #endif // defined(OS_CHROMEOS)
193 shelf_(NULL),
194 panel_layout_manager_(NULL),
195 status_area_widget_(NULL),
196 browser_context_(NULL) {
197 gfx::Screen::SetInstance(screen_);
198 ui_controls::InstallUIControlsAura(internal::CreateUIControls());
199 #if defined(OS_CHROMEOS)
200 output_configurator_->AddObserver(output_configurator_animation_.get());
201 base::MessagePumpAuraX11::Current()->AddDispatcherForRootWindow(
202 output_configurator());
203 #endif // defined(OS_CHROMEOS)
206 Shell::~Shell() {
207 views::FocusManagerFactory::Install(NULL);
209 // Remove the focus from any window. This will prevent overhead and side
210 // effects (e.g. crashes) from changing focus during shutdown.
211 // See bug crbug.com/134502.
212 if (active_root_window_)
213 active_root_window_->GetFocusManager()->SetFocusedWindow(NULL, NULL);
215 cursor_manager_.set_delegate(NULL);
217 // Please keep in same order as in Init() because it's easy to miss one.
218 RemoveEnvEventFilter(user_activity_detector_.get());
219 RemoveEnvEventFilter(event_rewriter_filter_.get());
220 RemoveEnvEventFilter(overlay_filter_.get());
221 RemoveEnvEventFilter(input_method_filter_.get());
222 RemoveEnvEventFilter(window_modality_controller_.get());
223 if (mouse_cursor_filter_.get())
224 RemoveEnvEventFilter(mouse_cursor_filter_.get());
225 RemoveEnvEventFilter(system_gesture_filter_.get());
226 #if !defined(OS_MACOSX)
227 RemoveEnvEventFilter(accelerator_filter_.get());
228 #endif
229 if (touch_observer_hud_.get())
230 RemoveEnvEventFilter(touch_observer_hud_.get());
232 // TooltipController is deleted with the Shell so removing its references.
233 RemoveEnvEventFilter(tooltip_controller_.get());
235 // The status area needs to be shut down before the windows are destroyed.
236 status_area_widget_->Shutdown();
238 // AppList needs to be released before shelf layout manager, which is
239 // destroyed with launcher container in the loop below. However, app list
240 // container is now on top of launcher container and released after it.
241 // TODO(xiyuan): Move it back when app list container is no longer needed.
242 app_list_controller_.reset();
245 // Closing the windows frees the workspace controller.
246 shelf_->set_workspace_controller(NULL);
247 // Destroy all child windows including widgets.
248 display_controller_->CloseChildWindows();
250 // These need a valid Shell instance to clean up properly, so explicitly
251 // delete them before invalidating the instance.
252 // Alphabetical.
253 drag_drop_controller_.reset();
254 magnification_controller_.reset();
255 power_button_controller_.reset();
256 resize_shadow_controller_.reset();
257 shadow_controller_.reset();
258 tooltip_controller_.reset();
259 window_cycle_controller_.reset();
260 capture_controller_.reset();
261 nested_dispatcher_controller_.reset();
262 user_action_client_.reset();
263 visibility_controller_.reset();
265 // This also deletes all RootWindows.
266 display_controller_.reset();
267 screen_position_controller_.reset();
269 // Launcher widget has a InputMethodBridge that references to
270 // input_method_filter_'s input_method_. So explicitly release launcher_
271 // before input_method_filter_. And this needs to be after we delete all
272 // containers in case there are still live browser windows which access
273 // LauncherModel during close.
274 launcher_.reset();
276 // Delete the activation controller after other controllers and launcher
277 // because they might have registered ActivationChangeObserver.
278 activation_controller_.reset();
280 DCHECK(instance_ == this);
281 instance_ = NULL;
283 #if defined(OS_CHROMEOS)
284 output_configurator_->RemoveObserver(output_configurator_animation_.get());
285 base::MessagePumpAuraX11::Current()->RemoveDispatcherForRootWindow(
286 output_configurator());
287 #endif // defined(OS_CHROMEOS)
290 // static
291 Shell* Shell::CreateInstance(ShellDelegate* delegate) {
292 CHECK(!instance_);
293 aura::Env::GetInstance()->SetDisplayManager(
294 new internal::MultiDisplayManager());
295 instance_ = new Shell(delegate);
296 instance_->Init();
297 return instance_;
300 // static
301 Shell* Shell::GetInstance() {
302 DCHECK(instance_);
303 return instance_;
306 // static
307 bool Shell::HasInstance() {
308 return !!instance_;
311 // static
312 void Shell::DeleteInstance() {
313 delete instance_;
314 instance_ = NULL;
317 // static
318 internal::RootWindowController* Shell::GetPrimaryRootWindowController() {
319 return GetRootWindowController(GetPrimaryRootWindow());
322 // static
323 Shell::RootWindowControllerList Shell::GetAllRootWindowControllers() {
324 return Shell::GetInstance()->display_controller()->
325 GetAllRootWindowControllers();
328 // static
329 aura::RootWindow* Shell::GetPrimaryRootWindow() {
330 return GetInstance()->display_controller()->GetPrimaryRootWindow();
333 // static
334 aura::RootWindow* Shell::GetActiveRootWindow() {
335 return GetInstance()->active_root_window_;
338 // static
339 Shell::RootWindowList Shell::GetAllRootWindows() {
340 return Shell::GetInstance()->display_controller()->
341 GetAllRootWindows();
344 // static
345 aura::Window* Shell::GetContainer(aura::RootWindow* root_window,
346 int container_id) {
347 return root_window->GetChildById(container_id);
350 // static
351 std::vector<aura::Window*> Shell::GetAllContainers(int container_id) {
352 std::vector<aura::Window*> containers;
353 aura::Window* container = GetPrimaryRootWindow()->GetChildById(container_id);
354 if (container)
355 containers.push_back(container);
356 return containers;
359 void Shell::Init() {
360 // Install the custom factory first so that views::FocusManagers for Tray,
361 // Launcher, and WallPaper could be created by the factory.
362 views::FocusManagerFactory::Install(new AshFocusManagerFactory);
364 env_filter_ = new aura::shared::CompoundEventFilter;
365 // Pass ownership of the filter to the Env.
366 aura::Env::GetInstance()->SetEventFilter(env_filter_);
368 cursor_manager_.set_delegate(this);
370 focus_manager_.reset(new aura::FocusManager);
371 activation_controller_.reset(
372 new internal::ActivationController(focus_manager_.get()));
374 screen_position_controller_.reset(new internal::ScreenPositionController);
375 display_controller_.reset(new DisplayController);
376 display_controller_->InitPrimaryDisplay();
377 aura::RootWindow* root_window = display_controller_->GetPrimaryRootWindow();
378 active_root_window_ = root_window;
380 cursor_manager_.SetDeviceScaleFactor(
381 root_window->AsRootWindowHostDelegate()->GetDeviceScaleFactor());
383 #if !defined(OS_MACOSX)
384 nested_dispatcher_controller_.reset(new NestedDispatcherController);
385 accelerator_controller_.reset(new AcceleratorController);
386 #endif
387 shell_context_menu_.reset(new internal::ShellContextMenu);
389 // The order in which event filters are added is significant.
390 DCHECK(!GetEnvEventFilterCount());
391 user_activity_detector_.reset(new UserActivityDetector);
392 AddEnvEventFilter(user_activity_detector_.get());
394 DCHECK_EQ(1U, GetEnvEventFilterCount());
395 event_rewriter_filter_.reset(new internal::EventRewriterEventFilter);
396 AddEnvEventFilter(event_rewriter_filter_.get());
398 DCHECK_EQ(2U, GetEnvEventFilterCount());
399 overlay_filter_.reset(new internal::OverlayEventFilter);
400 AddEnvEventFilter(overlay_filter_.get());
401 AddShellObserver(overlay_filter_.get());
403 DCHECK_EQ(3U, GetEnvEventFilterCount());
404 input_method_filter_.reset(new aura::shared::InputMethodEventFilter());
405 AddEnvEventFilter(input_method_filter_.get());
407 #if !defined(OS_MACOSX)
408 accelerator_filter_.reset(new internal::AcceleratorFilter);
409 AddEnvEventFilter(accelerator_filter_.get());
410 #endif
412 system_gesture_filter_.reset(new internal::SystemGestureEventFilter);
413 AddEnvEventFilter(system_gesture_filter_.get());
415 capture_controller_.reset(new internal::CaptureController);
417 internal::RootWindowController* root_window_controller =
418 new internal::RootWindowController(root_window);
419 root_window_controller->CreateContainers();
421 CommandLine* command_line = CommandLine::ForCurrentProcess();
423 if (command_line->HasSwitch(switches::kAshTouchHud)) {
424 touch_observer_hud_.reset(new internal::TouchObserverHUD);
425 AddEnvEventFilter(touch_observer_hud_.get());
428 mouse_cursor_filter_.reset(new internal::MouseCursorEventFilter());
429 AddEnvEventFilter(mouse_cursor_filter_.get());
431 // Create Controllers that may need root window.
432 // TODO(oshima): Move as many controllers before creating
433 // RootWindowController as possible.
434 stacking_controller_.reset(new internal::StackingController);
435 visibility_controller_.reset(new internal::VisibilityController);
436 drag_drop_controller_.reset(new internal::DragDropController);
437 if (delegate_.get())
438 user_action_client_.reset(delegate_->CreateUserActionClient());
439 window_modality_controller_.reset(new internal::WindowModalityController);
440 AddEnvEventFilter(window_modality_controller_.get());
442 magnification_controller_.reset(
443 internal::MagnificationController::CreateInstance());
445 high_contrast_controller_.reset(new HighContrastController);
446 video_detector_.reset(new VideoDetector);
447 window_cycle_controller_.reset(
448 new WindowCycleController(activation_controller_.get()));
450 tooltip_controller_.reset(new internal::TooltipController(
451 drag_drop_controller_.get()));
452 AddEnvEventFilter(tooltip_controller_.get());
454 InitRootWindowController(root_window_controller);
456 // This controller needs to be set before SetupManagedWindowMode.
457 desktop_background_controller_.reset(new DesktopBackgroundController());
458 if (delegate_.get())
459 user_wallpaper_delegate_.reset(delegate_->CreateUserWallpaperDelegate());
460 if (!user_wallpaper_delegate_.get())
461 user_wallpaper_delegate_.reset(new DummyUserWallpaperDelegate());
463 // Launcher must be created after secondary displays are initialized.
464 display_controller_->InitSecondaryDisplays();
466 // StatusAreaWidget uses Shell's CapsLockDelegate.
467 if (delegate_.get())
468 caps_lock_delegate_.reset(delegate_->CreateCapsLockDelegate());
469 else
470 caps_lock_delegate_.reset(new CapsLockDelegateStub);
472 // Initialize Primary RootWindow specific items.
473 status_area_widget_ = new internal::StatusAreaWidget();
474 status_area_widget_->CreateTrayViews(delegate_.get());
475 // Login screen manages status area visibility by itself.
476 if (delegate_.get() && delegate_->IsSessionStarted())
477 status_area_widget_->Show();
479 focus_cycler_.reset(new internal::FocusCycler());
480 focus_cycler_->AddWidget(status_area_widget_);
482 InitLayoutManagersForPrimaryDisplay(root_window_controller);
484 if (!command_line->HasSwitch(switches::kAuraNoShadows)) {
485 resize_shadow_controller_.reset(new internal::ResizeShadowController());
486 shadow_controller_.reset(new internal::ShadowController());
489 if (!delegate_.get() || delegate_->IsUserLoggedIn())
490 CreateLauncher();
492 // Force Layout
493 root_window_controller->root_window_layout()->OnWindowResized();
495 // It needs to be created after OnWindowResized has been called, otherwise the
496 // widget will not paint when restoring after a browser crash. Also it needs
497 // to be created after InitSecondaryDisplays() to initialize the wallpapers in
498 // the correct size.
499 user_wallpaper_delegate_->InitializeWallpaper();
501 power_button_controller_.reset(new PowerButtonController);
502 AddShellObserver(power_button_controller_.get());
504 if (initially_hide_cursor_)
505 cursor_manager_.ShowCursor(false);
508 void Shell::AddEnvEventFilter(aura::EventFilter* filter) {
509 env_filter_->AddFilter(filter);
512 void Shell::RemoveEnvEventFilter(aura::EventFilter* filter) {
513 env_filter_->RemoveFilter(filter);
516 size_t Shell::GetEnvEventFilterCount() const {
517 return env_filter_->GetFilterCount();
520 void Shell::ShowBackgroundMenu(views::Widget* widget,
521 const gfx::Point& location) {
522 // No context menus if user have not logged in.
523 if (!delegate_.get() || !delegate_->IsUserLoggedIn())
524 return;
525 // No context menus when screen is locked.
526 if (IsScreenLocked())
527 return;
528 if (shell_context_menu_.get())
529 shell_context_menu_->ShowMenu(widget, location);
532 void Shell::ToggleAppList() {
533 if (!app_list_controller_.get())
534 app_list_controller_.reset(new internal::AppListController);
535 app_list_controller_->SetVisible(!app_list_controller_->IsVisible());
538 bool Shell::GetAppListTargetVisibility() const {
539 return app_list_controller_.get() &&
540 app_list_controller_->GetTargetVisibility();
543 aura::Window* Shell::GetAppListWindow() {
544 return app_list_controller_.get() ? app_list_controller_->GetWindow() : NULL;
547 bool Shell::IsScreenLocked() const {
548 return !delegate_.get() || delegate_->IsScreenLocked();
551 bool Shell::IsModalWindowOpen() const {
552 // TODO(oshima): Walk though all root windows.
553 const aura::Window* modal_container = GetContainer(
554 GetPrimaryRootWindow(),
555 internal::kShellWindowId_SystemModalContainer);
556 return !modal_container->children().empty();
559 views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView(
560 views::Widget* widget) {
561 if (CommandLine::ForCurrentProcess()->HasSwitch(
562 switches::kAuraGoogleDialogFrames)) {
563 return new internal::DialogFrameView;
565 // Use translucent-style window frames for dialogs.
566 CustomFrameViewAsh* frame_view = new CustomFrameViewAsh;
567 frame_view->Init(widget);
568 return frame_view;
571 void Shell::RotateFocus(Direction direction) {
572 focus_cycler_->RotateFocus(
573 direction == FORWARD ? internal::FocusCycler::FORWARD :
574 internal::FocusCycler::BACKWARD);
577 void Shell::SetDisplayWorkAreaInsets(Window* contains,
578 const gfx::Insets& insets) {
579 internal::MultiDisplayManager* display_manager =
580 static_cast<internal::MultiDisplayManager*>(
581 aura::Env::GetInstance()->display_manager());
582 if (!display_manager->UpdateWorkAreaOfDisplayNearestWindow(contains, insets))
583 return;
584 FOR_EACH_OBSERVER(ShellObserver, observers_,
585 OnDisplayWorkAreaInsetsChanged());
588 void Shell::OnLoginStateChanged(user::LoginStatus status) {
589 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLoginStateChanged(status));
590 ash::Shell::GetInstance()->UpdateShelfVisibility();
593 void Shell::OnAppTerminating() {
594 FOR_EACH_OBSERVER(ShellObserver, observers_, OnAppTerminating());
597 void Shell::OnLockStateChanged(bool locked) {
598 FOR_EACH_OBSERVER(ShellObserver, observers_, OnLockStateChanged(locked));
601 void Shell::CreateLauncher() {
602 if (launcher_.get())
603 return;
605 aura::Window* default_container =
606 GetPrimaryRootWindowController()->
607 GetContainer(internal::kShellWindowId_DefaultContainer);
608 launcher_.reset(new Launcher(default_container, shelf_));
610 launcher_->SetFocusCycler(focus_cycler_.get());
611 shelf_->SetLauncher(launcher_.get());
612 if (panel_layout_manager_)
613 panel_layout_manager_->SetLauncher(launcher_.get());
615 if (delegate())
616 launcher_->SetVisible(delegate()->IsSessionStarted());
617 launcher_->widget()->Show();
620 void Shell::ShowLauncher() {
621 if (!launcher_.get())
622 return;
623 launcher_->SetVisible(true);
626 void Shell::AddShellObserver(ShellObserver* observer) {
627 observers_.AddObserver(observer);
630 void Shell::RemoveShellObserver(ShellObserver* observer) {
631 observers_.RemoveObserver(observer);
634 void Shell::UpdateShelfVisibility() {
635 shelf_->UpdateVisibilityState();
638 void Shell::SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) {
639 shelf_->SetAutoHideBehavior(behavior);
642 ShelfAutoHideBehavior Shell::GetShelfAutoHideBehavior() const {
643 return shelf_->auto_hide_behavior();
646 void Shell::SetShelfAlignment(ShelfAlignment alignment) {
647 if (!shelf_->SetAlignment(alignment))
648 return;
649 FOR_EACH_OBSERVER(ShellObserver, observers_, OnShelfAlignmentChanged());
652 ShelfAlignment Shell::GetShelfAlignment() {
653 return shelf_->alignment();
656 void Shell::SetDimming(bool should_dim) {
657 RootWindowControllerList controllers = GetAllRootWindowControllers();
658 for (RootWindowControllerList::iterator iter = controllers.begin();
659 iter != controllers.end(); ++iter)
660 (*iter)->screen_dimmer()->SetDimming(should_dim);
663 SystemTrayDelegate* Shell::tray_delegate() {
664 return status_area_widget_->system_tray_delegate();
667 SystemTray* Shell::system_tray() {
668 return status_area_widget_->system_tray();
671 void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) {
672 root->set_focus_manager(focus_manager_.get());
673 internal::RootWindowController* controller =
674 new internal::RootWindowController(root);
675 controller->CreateContainers();
676 InitRootWindowController(controller);
677 controller->root_window_layout()->OnWindowResized();
678 desktop_background_controller_->OnRootWindowAdded(root);
679 root->ShowRootWindow();
680 // Activate new root for testing.
681 active_root_window_ = root;
684 void Shell::DoInitialWorkspaceAnimation() {
685 return GetPrimaryRootWindowController()->workspace_controller()->
686 DoInitialAnimation();
689 void Shell::InitRootWindowController(
690 internal::RootWindowController* controller) {
691 aura::RootWindow* root_window = controller->root_window();
692 DCHECK(activation_controller_.get());
693 DCHECK(visibility_controller_.get());
694 DCHECK(drag_drop_controller_.get());
695 DCHECK(capture_controller_.get());
696 DCHECK(window_cycle_controller_.get());
698 root_window->set_focus_manager(focus_manager_.get());
699 input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
700 aura::client::SetActivationClient(root_window, activation_controller_.get());
701 aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
702 aura::client::SetDragDropClient(root_window, drag_drop_controller_.get());
703 aura::client::SetCaptureClient(root_window, capture_controller_.get());
704 aura::client::SetScreenPositionClient(root_window,
705 screen_position_controller_.get());
706 aura::client::SetCursorClient(root_window, &cursor_manager_);
707 aura::client::SetTooltipClient(root_window, tooltip_controller_.get());
709 if (nested_dispatcher_controller_.get()) {
710 aura::client::SetDispatcherClient(root_window,
711 nested_dispatcher_controller_.get());
713 if (user_action_client_.get())
714 aura::client::SetUserActionClient(root_window, user_action_client_.get());
716 root_window->SetCursor(ui::kCursorPointer);
717 controller->InitLayoutManagers();
719 // TODO(oshima): Move the instance to RootWindowController when
720 // the extended desktop is enabled by default.
721 internal::AlwaysOnTopController* always_on_top_controller =
722 new internal::AlwaysOnTopController;
723 always_on_top_controller->SetContainers(
724 root_window->GetChildById(internal::kShellWindowId_DefaultContainer),
725 root_window->GetChildById(internal::kShellWindowId_AlwaysOnTopContainer));
726 root_window->SetProperty(internal::kAlwaysOnTopControllerKey,
727 always_on_top_controller);
729 window_cycle_controller_->OnRootWindowAdded(root_window);
732 ////////////////////////////////////////////////////////////////////////////////
733 // Shell, private:
735 void Shell::InitLayoutManagersForPrimaryDisplay(
736 internal::RootWindowController* controller) {
737 DCHECK(status_area_widget_);
739 internal::ShelfLayoutManager* shelf_layout_manager =
740 new internal::ShelfLayoutManager(status_area_widget_);
741 controller->GetContainer(internal::kShellWindowId_LauncherContainer)->
742 SetLayoutManager(shelf_layout_manager);
743 shelf_ = shelf_layout_manager;
745 internal::StatusAreaLayoutManager* status_area_layout_manager =
746 new internal::StatusAreaLayoutManager(shelf_layout_manager);
747 controller->GetContainer(internal::kShellWindowId_StatusContainer)->
748 SetLayoutManager(status_area_layout_manager);
750 shelf_layout_manager->set_workspace_controller(
751 controller->workspace_controller());
753 // TODO(oshima): Support multiple displays.
754 controller->workspace_controller()->SetShelf(shelf());
756 // Create Panel layout manager
757 aura::Window* panel_container = GetContainer(
758 GetPrimaryRootWindow(),
759 internal::kShellWindowId_PanelContainer);
760 panel_layout_manager_ =
761 new internal::PanelLayoutManager(panel_container);
762 panel_container->SetEventFilter(
763 new internal::PanelWindowEventFilter(
764 panel_container, panel_layout_manager_));
765 panel_container->SetLayoutManager(panel_layout_manager_);
768 void Shell::SetCursor(gfx::NativeCursor cursor) {
769 RootWindowList root_windows = GetAllRootWindows();
770 for (RootWindowList::iterator iter = root_windows.begin();
771 iter != root_windows.end(); ++iter)
772 (*iter)->SetCursor(cursor);
775 void Shell::ShowCursor(bool visible) {
776 RootWindowList root_windows = GetAllRootWindows();
777 for (RootWindowList::iterator iter = root_windows.begin();
778 iter != root_windows.end(); ++iter)
779 (*iter)->ShowCursor(visible);
782 } // namespace ash