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.
9 #include "ash/app_list/app_list.h"
10 #include "ash/ash_switches.h"
11 #include "ash/desktop_background/desktop_background_controller.h"
12 #include "ash/desktop_background/desktop_background_resources.h"
13 #include "ash/desktop_background/desktop_background_view.h"
14 #include "ash/drag_drop/drag_drop_controller.h"
15 #include "ash/focus_cycler.h"
16 #include "ash/ime/input_method_event_filter.h"
17 #include "ash/launcher/launcher.h"
18 #include "ash/monitor/multi_monitor_manager.h"
19 #include "ash/monitor/monitor_controller.h"
20 #include "ash/screen_ash.h"
21 #include "ash/shell_delegate.h"
22 #include "ash/shell_factory.h"
23 #include "ash/shell_window_ids.h"
24 #include "ash/system/audio/tray_volume.h"
25 #include "ash/system/bluetooth/tray_bluetooth.h"
26 #include "ash/system/brightness/tray_brightness.h"
27 #include "ash/system/date/tray_date.h"
28 #include "ash/system/ime/tray_ime.h"
29 #include "ash/system/network/tray_network.h"
30 #include "ash/system/power/power_status_observer.h"
31 #include "ash/system/power/power_supply_status.h"
32 #include "ash/system/power/tray_power.h"
33 #include "ash/system/settings/tray_settings.h"
34 #include "ash/system/tray/system_tray_delegate.h"
35 #include "ash/system/tray/system_tray.h"
36 #include "ash/system/tray/tray_empty.h"
37 #include "ash/system/tray_accessibility.h"
38 #include "ash/system/tray_caps_lock.h"
39 #include "ash/system/user/tray_user.h"
40 #include "ash/tooltips/tooltip_controller.h"
41 #include "ash/wm/activation_controller.h"
42 #include "ash/wm/base_layout_manager.h"
43 #include "ash/wm/custom_frame_view_ash.h"
44 #include "ash/wm/dialog_frame_view.h"
45 #include "ash/wm/panel_window_event_filter.h"
46 #include "ash/wm/panel_layout_manager.h"
47 #include "ash/wm/partial_screenshot_event_filter.h"
48 #include "ash/wm/power_button_controller.h"
49 #include "ash/wm/resize_shadow_controller.h"
50 #include "ash/wm/root_window_event_filter.h"
51 #include "ash/wm/root_window_layout_manager.h"
52 #include "ash/wm/shadow_controller.h"
53 #include "ash/wm/shelf_layout_manager.h"
54 #include "ash/wm/stacking_controller.h"
55 #include "ash/wm/status_area_layout_manager.h"
56 #include "ash/wm/system_modal_container_layout_manager.h"
57 #include "ash/wm/toplevel_window_event_filter.h"
58 #include "ash/wm/video_detector.h"
59 #include "ash/wm/visibility_controller.h"
60 #include "ash/wm/window_cycle_controller.h"
61 #include "ash/wm/window_modality_controller.h"
62 #include "ash/wm/window_util.h"
63 #include "ash/wm/workspace_controller.h"
64 #include "ash/wm/workspace/workspace_event_filter.h"
65 #include "ash/wm/workspace/workspace_layout_manager.h"
66 #include "ash/wm/workspace/workspace_manager.h"
67 #include "base/bind.h"
68 #include "base/command_line.h"
69 #include "grit/ui_resources.h"
70 #include "third_party/skia/include/core/SkBitmap.h"
71 #include "ui/aura/client/aura_constants.h"
72 #include "ui/aura/env.h"
73 #include "ui/aura/layout_manager.h"
74 #include "ui/aura/monitor.h"
75 #include "ui/aura/monitor_manager.h"
76 #include "ui/aura/monitor_manager.h"
77 #include "ui/aura/root_window.h"
78 #include "ui/aura/ui_controls_aura.h"
79 #include "ui/aura/window.h"
80 #include "ui/gfx/compositor/layer.h"
81 #include "ui/gfx/compositor/layer_animator.h"
82 #include "ui/gfx/size.h"
83 #include "ui/ui_controls/ui_controls.h"
84 #include "ui/views/widget/native_widget_aura.h"
85 #include "ui/views/widget/widget.h"
87 #if !defined(OS_MACOSX)
88 #include "ash/accelerators/accelerator_controller.h"
89 #include "ash/accelerators/accelerator_filter.h"
90 #include "ash/accelerators/nested_dispatcher_controller.h"
100 // Creates a new window for use as a container.
101 aura::Window
* CreateContainer(int window_id
,
103 aura::Window
* parent
) {
104 aura::Window
* container
= new aura::Window(NULL
);
105 container
->set_id(window_id
);
106 container
->SetName(name
);
107 container
->Init(ui::Layer::LAYER_NOT_DRAWN
);
108 parent
->AddChild(container
);
109 if (window_id
!= internal::kShellWindowId_UnparentedControlContainer
)
114 // Creates each of the special window containers that holds windows of various
115 // types in the shell UI.
116 void CreateSpecialContainers(aura::RootWindow
* root_window
) {
117 // These containers are just used by PowerButtonController to animate groups
118 // of containers simultaneously without messing up the current transformations
119 // on those containers. These are direct children of the root window; all of
120 // the other containers are their children.
121 aura::Window
* non_lock_screen_containers
= CreateContainer(
122 internal::kShellWindowId_NonLockScreenContainersContainer
,
123 "NonLockScreenContainersContainer",
125 aura::Window
* lock_screen_containers
= CreateContainer(
126 internal::kShellWindowId_LockScreenContainersContainer
,
127 "LockScreenContainersContainer",
129 aura::Window
* lock_screen_related_containers
= CreateContainer(
130 internal::kShellWindowId_LockScreenRelatedContainersContainer
,
131 "LockScreenRelatedContainersContainer",
134 CreateContainer(internal::kShellWindowId_UnparentedControlContainer
,
135 "UnparentedControlContainer",
136 non_lock_screen_containers
);
138 CreateContainer(internal::kShellWindowId_DesktopBackgroundContainer
,
139 "DesktopBackgroundContainer",
140 non_lock_screen_containers
);
142 aura::Window
* default_container
= CreateContainer(
143 internal::kShellWindowId_DefaultContainer
,
145 non_lock_screen_containers
);
146 default_container
->SetEventFilter(
147 new ToplevelWindowEventFilter(default_container
));
148 SetChildWindowVisibilityChangesAnimated(default_container
);
150 aura::Window
* always_on_top_container
= CreateContainer(
151 internal::kShellWindowId_AlwaysOnTopContainer
,
152 "AlwaysOnTopContainer",
153 non_lock_screen_containers
);
154 always_on_top_container
->SetEventFilter(
155 new ToplevelWindowEventFilter(always_on_top_container
));
156 SetChildWindowVisibilityChangesAnimated(always_on_top_container
);
158 aura::Window
* panel_container
= CreateContainer(
159 internal::kShellWindowId_PanelContainer
,
161 non_lock_screen_containers
);
162 if (CommandLine::ForCurrentProcess()->
163 HasSwitch(switches::kAuraPanelManager
)) {
164 internal::PanelLayoutManager
* layout_manager
=
165 new internal::PanelLayoutManager(panel_container
);
166 panel_container
->SetEventFilter(
167 new internal::PanelWindowEventFilter(panel_container
, layout_manager
));
168 panel_container
->SetLayoutManager(layout_manager
);
171 CreateContainer(internal::kShellWindowId_LauncherContainer
,
173 non_lock_screen_containers
);
175 aura::Window
* modal_container
= CreateContainer(
176 internal::kShellWindowId_SystemModalContainer
,
177 "SystemModalContainer",
178 non_lock_screen_containers
);
179 modal_container
->SetEventFilter(
180 new ToplevelWindowEventFilter(modal_container
));
181 modal_container
->SetLayoutManager(
182 new internal::SystemModalContainerLayoutManager(modal_container
));
183 SetChildWindowVisibilityChangesAnimated(modal_container
);
185 // TODO(beng): Figure out if we can make this use
186 // SystemModalContainerEventFilter instead of stops_event_propagation.
187 aura::Window
* lock_container
= CreateContainer(
188 internal::kShellWindowId_LockScreenContainer
,
189 "LockScreenContainer",
190 lock_screen_containers
);
191 lock_container
->SetLayoutManager(
192 new internal::BaseLayoutManager(root_window
));
193 lock_container
->set_stops_event_propagation(true);
195 aura::Window
* lock_modal_container
= CreateContainer(
196 internal::kShellWindowId_LockSystemModalContainer
,
197 "LockSystemModalContainer",
198 lock_screen_containers
);
199 lock_modal_container
->SetEventFilter(
200 new ToplevelWindowEventFilter(lock_modal_container
));
201 lock_modal_container
->SetLayoutManager(
202 new internal::SystemModalContainerLayoutManager(lock_modal_container
));
203 SetChildWindowVisibilityChangesAnimated(lock_modal_container
);
205 CreateContainer(internal::kShellWindowId_StatusContainer
,
207 lock_screen_related_containers
);
209 aura::Window
* menu_container
= CreateContainer(
210 internal::kShellWindowId_MenuContainer
,
212 lock_screen_related_containers
);
213 SetChildWindowVisibilityChangesAnimated(menu_container
);
215 aura::Window
* drag_drop_container
= CreateContainer(
216 internal::kShellWindowId_DragImageAndTooltipContainer
,
217 "DragImageAndTooltipContainer",
218 lock_screen_related_containers
);
219 SetChildWindowVisibilityChangesAnimated(drag_drop_container
);
221 aura::Window
* settings_bubble_container
= CreateContainer(
222 internal::kShellWindowId_SettingBubbleContainer
,
223 "SettingBubbleContainer",
224 lock_screen_related_containers
);
225 SetChildWindowVisibilityChangesAnimated(settings_bubble_container
);
227 CreateContainer(internal::kShellWindowId_OverlayContainer
,
229 lock_screen_related_containers
);
232 // This dummy class is used for shell unit tests. We dont have chrome delegate
234 class DummyUserWallpaperDelegate
: public UserWallpaperDelegate
{
236 DummyUserWallpaperDelegate() {}
238 virtual ~DummyUserWallpaperDelegate() {}
240 const int GetUserWallpaperIndex() {
245 DISALLOW_COPY_AND_ASSIGN(DummyUserWallpaperDelegate
);
248 class DummySystemTrayDelegate
: public SystemTrayDelegate
{
250 DummySystemTrayDelegate()
253 cellular_enabled_(true),
254 bluetooth_enabled_(true),
258 virtual ~DummySystemTrayDelegate() {}
262 virtual bool GetTrayVisibilityOnStartup() OVERRIDE
{ return true; }
264 // Overridden from SystemTrayDelegate:
265 virtual const std::string
GetUserDisplayName() const OVERRIDE
{
266 return "Ãœber tray Ãœber tray Ãœber tray Ãœber tray";
269 virtual const std::string
GetUserEmail() const OVERRIDE
{
273 virtual const SkBitmap
& GetUserImage() const OVERRIDE
{
277 virtual user::LoginStatus
GetUserLoginStatus() const OVERRIDE
{
278 return user::LOGGED_IN_USER
;
281 virtual bool SystemShouldUpgrade() const OVERRIDE
{
285 virtual int GetSystemUpdateIconResource() const OVERRIDE
{
286 return IDR_AURA_UBER_TRAY_UPDATE
;
289 virtual base::HourClockType
GetHourClockType() const OVERRIDE
{
290 return base::k24HourClock
;
293 virtual PowerSupplyStatus
GetPowerSupplyStatus() const OVERRIDE
{
294 return PowerSupplyStatus();
297 virtual void ShowSettings() OVERRIDE
{
300 virtual void ShowDateSettings() OVERRIDE
{
303 virtual void ShowNetworkSettings() OVERRIDE
{
306 virtual void ShowBluetoothSettings() OVERRIDE
{
309 virtual void ShowIMESettings() OVERRIDE
{
312 virtual void ShowHelp() OVERRIDE
{
315 virtual bool IsAudioMuted() const OVERRIDE
{
319 virtual void SetAudioMuted(bool muted
) OVERRIDE
{
323 virtual float GetVolumeLevel() const OVERRIDE
{
327 virtual void SetVolumeLevel(float volume
) OVERRIDE
{
331 virtual bool IsCapsLockOn() const OVERRIDE
{
335 virtual bool IsInAccessibilityMode() const OVERRIDE
{
339 virtual void ShutDown() OVERRIDE
{}
341 virtual void SignOut() OVERRIDE
{
342 MessageLoop::current()->Quit();
345 virtual void RequestLockScreen() OVERRIDE
{}
347 virtual void GetAvailableBluetoothDevices(
348 BluetoothDeviceList
* list
) OVERRIDE
{
351 virtual void ToggleBluetoothConnection(const std::string
& address
) OVERRIDE
{
354 virtual void GetCurrentIME(IMEInfo
* info
) OVERRIDE
{
357 virtual void GetAvailableIMEList(IMEInfoList
* list
) OVERRIDE
{
360 virtual void SwitchIME(const std::string
& ime_id
) OVERRIDE
{
363 virtual void GetMostRelevantNetworkIcon(NetworkIconInfo
* info
,
364 bool large
) OVERRIDE
{
367 virtual void GetAvailableNetworks(
368 std::vector
<NetworkIconInfo
>* list
) OVERRIDE
{
371 virtual void ConnectToNetwork(const std::string
& network_id
) OVERRIDE
{
374 virtual void AddBluetoothDevice() OVERRIDE
{
377 virtual void ToggleAirplaneMode() OVERRIDE
{
380 virtual void ToggleWifi() OVERRIDE
{
381 wifi_enabled_
= !wifi_enabled_
;
382 ash::NetworkObserver
* observer
=
383 ash::Shell::GetInstance()->tray()->network_observer();
385 ash::NetworkIconInfo info
;
386 observer
->OnNetworkRefresh(info
);
390 virtual void ToggleCellular() OVERRIDE
{
391 cellular_enabled_
= !cellular_enabled_
;
392 ash::NetworkObserver
* observer
=
393 ash::Shell::GetInstance()->tray()->network_observer();
395 ash::NetworkIconInfo info
;
396 observer
->OnNetworkRefresh(info
);
400 virtual void ToggleBluetooth() OVERRIDE
{
401 bluetooth_enabled_
= !bluetooth_enabled_
;
402 ash::BluetoothObserver
* observer
=
403 ash::Shell::GetInstance()->tray()->bluetooth_observer();
405 observer
->OnBluetoothRefresh();
408 virtual bool GetWifiAvailable() OVERRIDE
{
412 virtual bool GetCellularAvailable() OVERRIDE
{
416 virtual bool GetBluetoothAvailable() OVERRIDE
{
420 virtual bool GetWifiEnabled() OVERRIDE
{
421 return wifi_enabled_
;
424 virtual bool GetCellularEnabled() OVERRIDE
{
425 return cellular_enabled_
;
428 virtual bool GetBluetoothEnabled() OVERRIDE
{
429 return bluetooth_enabled_
;
432 virtual void ChangeProxySettings() OVERRIDE
{
437 bool cellular_enabled_
;
438 bool bluetooth_enabled_
;
440 SkBitmap null_image_
;
442 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate
);
448 Shell
* Shell::instance_
= NULL
;
450 bool Shell::initially_hide_cursor_
= false;
452 ////////////////////////////////////////////////////////////////////////////////
455 Shell::TestApi::TestApi(Shell
* shell
) : shell_(shell
) {}
457 internal::RootWindowLayoutManager
* Shell::TestApi::root_window_layout() {
458 return shell_
->root_window_layout_
;
461 internal::InputMethodEventFilter
* Shell::TestApi::input_method_event_filter() {
462 return shell_
->input_method_filter_
.get();
465 internal::WorkspaceController
* Shell::TestApi::workspace_controller() {
466 return shell_
->workspace_controller_
.get();
469 ////////////////////////////////////////////////////////////////////////////////
472 Shell::Shell(ShellDelegate
* delegate
)
473 : root_window_(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()),
474 screen_(new ScreenAsh(root_window_
.get())),
478 root_window_layout_(NULL
),
479 status_widget_(NULL
) {
480 gfx::Screen::SetInstance(screen_
);
481 ui_controls::InstallUIControlsAura(CreateUIControlsAura(root_window_
.get()));
485 RemoveRootWindowEventFilter(partial_screenshot_filter_
.get());
486 RemoveRootWindowEventFilter(input_method_filter_
.get());
487 RemoveRootWindowEventFilter(window_modality_controller_
.get());
488 #if !defined(OS_MACOSX)
489 RemoveRootWindowEventFilter(accelerator_filter_
.get());
492 // Close background widget now so that the focus manager of the
493 // widget gets deleted in the final message loop run.
494 root_window_layout_
->SetBackgroundWidget(NULL
);
496 // TooltipController is deleted with the Shell so removing its references.
497 RemoveRootWindowEventFilter(tooltip_controller_
.get());
498 aura::client::SetTooltipClient(GetRootWindow(), NULL
);
500 // Make sure we delete WorkspaceController before launcher is
501 // deleted as it has a reference to launcher model.
502 workspace_controller_
.reset();
504 // The system tray needs to be reset before all the windows are destroyed.
507 // Delete containers now so that child windows does not access
508 // observers when they are destructed.
509 aura::RootWindow
* root_window
= GetRootWindow();
510 while (!root_window
->children().empty()) {
511 aura::Window
* child
= root_window
->children()[0];
515 // These need a valid Shell instance to clean up properly, so explicitly
516 // delete them before invalidating the instance.
518 activation_controller_
.reset();
519 drag_drop_controller_
.reset();
520 resize_shadow_controller_
.reset();
521 shadow_controller_
.reset();
522 window_cycle_controller_
.reset();
523 monitor_controller_
.reset();
525 // Launcher widget has a InputMethodBridge that references to
526 // input_method_filter_'s input_method_. So explicitly release launcher_
527 // before input_method_filter_. And this needs to be after we delete all
528 // containers in case there are still live browser windows which access
529 // LauncherModel during close.
532 DCHECK(instance_
== this);
537 Shell
* Shell::CreateInstance(ShellDelegate
* delegate
) {
539 aura::Env::GetInstance()->SetMonitorManager(
540 new internal::MultiMonitorManager());
541 instance_
= new Shell(delegate
);
547 Shell
* Shell::GetInstance() {
553 bool Shell::HasInstance() {
558 void Shell::DeleteInstance() {
564 aura::RootWindow
* Shell::GetRootWindow() {
565 return GetInstance()->root_window_
.get();
569 aura::RootWindow
* root_window
= GetRootWindow();
570 root_filter_
= new internal::RootWindowEventFilter(root_window
);
571 #if !defined(OS_MACOSX)
572 nested_dispatcher_controller_
.reset(new NestedDispatcherController
);
573 accelerator_controller_
.reset(new AcceleratorController
);
575 // Pass ownership of the filter to the root window.
576 GetRootWindow()->SetEventFilter(root_filter_
);
578 DCHECK(!GetRootWindowEventFilterCount());
580 // PartialScreenshotEventFilter must be the first one to capture key
581 // events when the taking partial screenshot UI is there.
582 partial_screenshot_filter_
.reset(new internal::PartialScreenshotEventFilter
);
583 AddRootWindowEventFilter(partial_screenshot_filter_
.get());
585 // Then AcceleratorFilter and InputMethodEventFilter must be added (in this
586 // order) since they have the second highest priority.
587 DCHECK_EQ(1U, GetRootWindowEventFilterCount());
588 #if !defined(OS_MACOSX)
589 accelerator_filter_
.reset(new internal::AcceleratorFilter
);
590 AddRootWindowEventFilter(accelerator_filter_
.get());
591 DCHECK_EQ(2U, GetRootWindowEventFilterCount());
593 input_method_filter_
.reset(new internal::InputMethodEventFilter
);
594 AddRootWindowEventFilter(input_method_filter_
.get());
596 root_window
->SetCursor(aura::kCursorPointer
);
597 if (initially_hide_cursor_
)
598 root_window
->ShowCursor(false);
600 activation_controller_
.reset(new internal::ActivationController
);
602 CreateSpecialContainers(root_window
);
604 stacking_controller_
.reset(new internal::StackingController
);
606 root_window_layout_
= new internal::RootWindowLayoutManager(root_window
);
607 root_window
->SetLayoutManager(root_window_layout_
);
610 status_widget_
= delegate_
->CreateStatusArea();
612 CommandLine
* command_line
= CommandLine::ForCurrentProcess();
613 if (!command_line
->HasSwitch(switches::kDisableAshUberTray
)) {
614 // TODO(sad): This is rather ugly at the moment. This is because we are
615 // supporting both the old and the new status bar at the same time. This
616 // will soon get better once the new one is ready and the old one goes out
618 tray_
.reset(new SystemTray());
619 if (status_widget_
) {
620 status_widget_
->GetContentsView()->RemoveAllChildViews(false);
621 status_widget_
->GetContentsView()->AddChildView(tray_
.get());
625 tray_delegate_
.reset(delegate_
->CreateSystemTrayDelegate(tray_
.get()));
626 if (!tray_delegate_
.get())
627 tray_delegate_
.reset(new DummySystemTrayDelegate());
629 internal::TrayVolume
* tray_volume
= new internal::TrayVolume();
630 internal::TrayBluetooth
* tray_bluetooth
= new internal::TrayBluetooth();
631 internal::TrayBrightness
* tray_brightness
= new internal::TrayBrightness();
632 internal::TrayDate
* tray_date
= new internal::TrayDate();
633 internal::TrayPower
* tray_power
= new internal::TrayPower();
634 internal::TrayNetwork
* tray_network
= new internal::TrayNetwork
;
635 internal::TrayUser
* tray_user
= new internal::TrayUser
;
636 internal::TrayAccessibility
* tray_accessibility
=
637 new internal::TrayAccessibility
;
638 internal::TrayCapsLock
* tray_caps_lock
= new internal::TrayCapsLock
;
639 internal::TrayIME
* tray_ime
= new internal::TrayIME
;
641 tray_
->accessibility_observer_
= tray_accessibility
;
642 tray_
->audio_observer_
= tray_volume
;
643 tray_
->bluetooth_observer_
= tray_bluetooth
;
644 tray_
->brightness_observer_
= tray_brightness
;
645 tray_
->caps_lock_observer_
= tray_caps_lock
;
646 tray_
->clock_observer_
= tray_date
;
647 tray_
->ime_observer_
= tray_ime
;
648 tray_
->network_observer_
= tray_network
;
649 tray_
->power_status_observer_
= tray_power
;
650 tray_
->update_observer_
= tray_user
;
651 tray_
->user_observer_
= tray_user
;
653 tray_
->AddTrayItem(tray_user
);
654 tray_
->AddTrayItem(new internal::TrayEmpty());
655 tray_
->AddTrayItem(tray_power
);
656 tray_
->AddTrayItem(tray_network
);
657 tray_
->AddTrayItem(tray_bluetooth
);
658 tray_
->AddTrayItem(tray_ime
);
659 tray_
->AddTrayItem(tray_volume
);
660 tray_
->AddTrayItem(tray_brightness
);
661 tray_
->AddTrayItem(new internal::TraySettings());
662 tray_
->AddTrayItem(tray_date
);
663 tray_
->AddTrayItem(tray_accessibility
);
664 tray_
->AddTrayItem(tray_caps_lock
);
666 tray_
->SetVisible(tray_delegate_
->GetTrayVisibilityOnStartup());
669 status_widget_
= internal::CreateStatusArea(tray_
.get());
671 // This controller needs to be set before SetupManagedWindowMode.
672 desktop_background_controller_
.reset(new DesktopBackgroundController
);
674 user_wallpaper_delegate_
.reset(delegate_
->CreateUserWallpaperDelegate());
675 if (!user_wallpaper_delegate_
.get())
676 user_wallpaper_delegate_
.reset(new DummyUserWallpaperDelegate());
678 InitLayoutManagers();
680 if (!command_line
->HasSwitch(switches::kAuraNoShadows
)) {
681 resize_shadow_controller_
.reset(new internal::ResizeShadowController());
682 shadow_controller_
.reset(new internal::ShadowController());
685 focus_cycler_
.reset(new internal::FocusCycler());
686 focus_cycler_
->AddWidget(status_widget_
);
688 if (!delegate_
.get() || delegate_
->CanCreateLauncher())
692 root_window
->layout_manager()->OnWindowResized();
694 window_modality_controller_
.reset(new internal::WindowModalityController
);
695 AddRootWindowEventFilter(window_modality_controller_
.get());
697 visibility_controller_
.reset(new internal::VisibilityController
);
699 tooltip_controller_
.reset(new internal::TooltipController
);
700 AddRootWindowEventFilter(tooltip_controller_
.get());
702 drag_drop_controller_
.reset(new internal::DragDropController
);
703 power_button_controller_
.reset(new PowerButtonController
);
704 video_detector_
.reset(new VideoDetector
);
705 window_cycle_controller_
.reset(new WindowCycleController
);
706 monitor_controller_
.reset(new internal::MonitorController
);
709 aura::Window
* Shell::GetContainer(int container_id
) {
710 return const_cast<aura::Window
*>(
711 const_cast<const Shell
*>(this)->GetContainer(container_id
));
714 const aura::Window
* Shell::GetContainer(int container_id
) const {
715 return GetRootWindow()->GetChildById(container_id
);
718 void Shell::AddRootWindowEventFilter(aura::EventFilter
* filter
) {
719 static_cast<internal::RootWindowEventFilter
*>(
720 GetRootWindow()->event_filter())->AddFilter(filter
);
723 void Shell::RemoveRootWindowEventFilter(aura::EventFilter
* filter
) {
724 static_cast<internal::RootWindowEventFilter
*>(
725 GetRootWindow()->event_filter())->RemoveFilter(filter
);
728 size_t Shell::GetRootWindowEventFilterCount() const {
729 return static_cast<internal::RootWindowEventFilter
*>(
730 GetRootWindow()->event_filter())->GetFilterCount();
733 void Shell::ShowBackgroundMenu(views::Widget
* widget
,
734 const gfx::Point
& location
) {
735 if (workspace_controller_
.get())
736 workspace_controller_
->ShowMenu(widget
, location
);
739 void Shell::ToggleAppList() {
740 if (!app_list_
.get())
741 app_list_
.reset(new internal::AppList
);
742 app_list_
->SetVisible(!app_list_
->IsVisible());
745 bool Shell::IsScreenLocked() const {
746 const aura::Window
* lock_screen_container
= GetContainer(
747 internal::kShellWindowId_LockScreenContainer
);
748 return lock_screen_container
->StopsEventPropagation();
751 bool Shell::IsModalWindowOpen() const {
752 const aura::Window
* modal_container
= GetContainer(
753 internal::kShellWindowId_SystemModalContainer
);
754 return !modal_container
->children().empty();
757 views::NonClientFrameView
* Shell::CreateDefaultNonClientFrameView(
758 views::Widget
* widget
) {
759 if (CommandLine::ForCurrentProcess()->HasSwitch(
760 switches::kAuraGoogleDialogFrames
)) {
761 return new internal::DialogFrameView
;
763 // Use translucent-style window frames for dialogs.
764 CustomFrameViewAsh
* frame_view
= new CustomFrameViewAsh
;
765 frame_view
->Init(widget
);
769 void Shell::RotateFocus(Direction direction
) {
770 focus_cycler_
->RotateFocus(
771 direction
== FORWARD
? internal::FocusCycler::FORWARD
:
772 internal::FocusCycler::BACKWARD
);
775 void Shell::SetMonitorWorkAreaInsets(Window
* contains
,
776 const gfx::Insets
& insets
) {
777 aura::Monitor
* monitor
= aura::Env::GetInstance()->monitor_manager()->
778 GetMonitorNearestWindow(contains
);
779 if (monitor
->work_area_insets() == insets
)
781 monitor
->set_work_area_insets(insets
);
782 FOR_EACH_OBSERVER(ShellObserver
, observers_
,
783 OnMonitorWorkAreaInsetsChanged());
786 void Shell::CreateLauncher() {
790 aura::Window
* default_container
=
791 GetContainer(internal::kShellWindowId_DefaultContainer
);
792 launcher_
.reset(new Launcher(default_container
));
794 launcher_
->SetFocusCycler(focus_cycler_
.get());
795 shelf_
->SetLauncher(launcher_
.get());
797 launcher_
->widget()->Show();
800 void Shell::AddShellObserver(ShellObserver
* observer
) {
801 observers_
.AddObserver(observer
);
804 void Shell::RemoveShellObserver(ShellObserver
* observer
) {
805 observers_
.RemoveObserver(observer
);
808 int Shell::GetGridSize() const {
809 return workspace_controller_
->workspace_manager()->grid_size();
812 ////////////////////////////////////////////////////////////////////////////////
815 void Shell::InitLayoutManagers() {
816 DCHECK(root_window_layout_
);
817 DCHECK(status_widget_
);
819 internal::ShelfLayoutManager
* shelf_layout_manager
=
820 new internal::ShelfLayoutManager(status_widget_
);
821 GetContainer(internal::kShellWindowId_LauncherContainer
)->
822 SetLayoutManager(shelf_layout_manager
);
823 shelf_
= shelf_layout_manager
;
825 internal::StatusAreaLayoutManager
* status_area_layout_manager
=
826 new internal::StatusAreaLayoutManager(shelf_layout_manager
);
827 GetContainer(internal::kShellWindowId_StatusContainer
)->
828 SetLayoutManager(status_area_layout_manager
);
830 aura::Window
* default_container
=
831 GetContainer(internal::kShellWindowId_DefaultContainer
);
832 // Workspace manager has its own layout managers.
833 workspace_controller_
.reset(
834 new internal::WorkspaceController(default_container
));
835 workspace_controller_
->workspace_manager()->set_shelf(shelf_layout_manager
);
837 // Create desktop background widget.
838 // TODO(bshe): We should be able to use OnDesktopBackgroundChanged function
839 // here after issue 117244 got fixed.
840 desktop_background_controller_
->SetDesktopBackgroundImageMode(
841 GetWallpaper(user_wallpaper_delegate_
->GetUserWallpaperIndex()));
844 void Shell::DisableWorkspaceGridLayout() {
845 if (workspace_controller_
.get())
846 workspace_controller_
->workspace_manager()->set_grid_size(0);