Adds VolumeManagerWrapper.
[chromium-blink-merge.git] / ash / shell.h
blobb6caac11295831d76f4125c67c10699dc384feaa
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 #ifndef ASH_SHELL_H_
6 #define ASH_SHELL_H_
8 #include <utility>
9 #include <vector>
11 #include "ash/ash_export.h"
12 #include "ash/shelf/shelf_types.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/wm/system_modal_container_event_filter_delegate.h"
15 #include "base/basictypes.h"
16 #include "base/compiler_specific.h"
17 #include "base/gtest_prod_util.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/observer_list.h"
20 #include "ui/aura/client/activation_change_observer.h"
21 #include "ui/base/ui_base_types.h"
22 #include "ui/events/event_target.h"
23 #include "ui/gfx/insets.h"
24 #include "ui/gfx/screen.h"
25 #include "ui/gfx/size.h"
26 #include "ui/views/corewm/cursor_manager.h"
28 class CommandLine;
30 namespace aura {
31 class EventFilter;
32 class RootWindow;
33 class Window;
34 namespace client {
35 class ActivationClient;
36 class FocusClient;
37 class UserActionClient;
40 namespace chromeos {
41 class OutputConfigurator;
43 namespace content {
44 class BrowserContext;
47 namespace gfx {
48 class ImageSkia;
49 class Point;
50 class Rect;
52 namespace ui {
53 class Layer;
55 namespace views {
56 class NonClientFrameView;
57 class Widget;
58 namespace corewm {
59 class CompoundEventFilter;
60 class InputMethodEventFilter;
61 class ShadowController;
62 class TooltipController;
63 class VisibilityController;
64 class WindowModalityController;
68 namespace ash {
70 class AcceleratorController;
71 class AshNativeCursorManager;
72 class CapsLockDelegate;
73 class DesktopBackgroundController;
74 class DisplayController;
75 class HighContrastController;
76 class Launcher;
77 class LauncherDelegate;
78 class LauncherItemDelegateManager;
79 class LauncherModel;
80 class MagnificationController;
81 class MruWindowTracker;
82 class NestedDispatcherController;
83 class PartialMagnificationController;
84 class PowerButtonController;
85 class RootWindowHostFactory;
86 class ScreenAsh;
87 class LockStateController;
88 class SessionStateDelegate;
89 class ShellDelegate;
90 class ShellObserver;
91 class SystemTray;
92 class SystemTrayDelegate;
93 class SystemTrayNotifier;
94 class UserActivityDetector;
95 class UserWallpaperDelegate;
96 class VideoDetector;
97 class WebNotificationTray;
98 class WindowCycleController;
99 class WindowSelectorController;
101 namespace internal {
102 class AcceleratorFilter;
103 class AppListController;
104 class AppListShelfItemDelegate;
105 class CaptureController;
106 class DisplayChangeObserver;
107 class DisplayErrorObserver;
108 class DisplayManager;
109 class DragDropController;
110 class EventClientImpl;
111 class EventRewriterEventFilter;
112 class EventTransformationHandler;
113 class FocusCycler;
114 class KeyboardUMAEventFilter;
115 class LocaleNotificationController;
116 class MouseCursorEventFilter;
117 class OutputConfiguratorAnimation;
118 class OverlayEventFilter;
119 class ResizeShadowController;
120 class ResolutionNotificationController;
121 class RootWindowController;
122 class RootWindowLayoutManager;
123 class ScopedTargetRootWindow;
124 class ScreenPositionController;
125 class SlowAnimationEventFilter;
126 class StatusAreaWidget;
127 class SystemGestureEventFilter;
128 class SystemModalContainerEventFilter;
129 class TouchObserverHUD;
132 namespace shell {
133 class WindowWatcher;
136 namespace test {
137 class ShellTestApi;
140 // Shell is a singleton object that presents the Shell API and implements the
141 // RootWindow's delegate interface.
143 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
144 // takes ownership of the Shell.
145 class ASH_EXPORT Shell
146 : public internal::SystemModalContainerEventFilterDelegate,
147 public ui::EventTarget,
148 public aura::client::ActivationChangeObserver {
149 public:
150 typedef std::vector<aura::RootWindow*> RootWindowList;
151 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
153 enum Direction {
154 FORWARD,
155 BACKWARD
158 // A shell must be explicitly created so that it can call |Init()| with the
159 // delegate set. |delegate| can be NULL (if not required for initialization).
160 // Takes ownership of |delegate|.
161 static Shell* CreateInstance(ShellDelegate* delegate);
163 // Should never be called before |CreateInstance()|.
164 static Shell* GetInstance();
166 // Returns true if the ash shell has been instantiated.
167 static bool HasInstance();
169 static void DeleteInstance();
171 // Returns the root window controller for the primary root window.
172 // TODO(oshima): move this to |RootWindowController|
173 static internal::RootWindowController* GetPrimaryRootWindowController();
175 // Returns all root window controllers.
176 // TODO(oshima): move this to |RootWindowController|
177 static RootWindowControllerList GetAllRootWindowControllers();
179 // Returns the primary RootWindow. The primary RootWindow is the one
180 // that has a launcher.
181 static aura::RootWindow* GetPrimaryRootWindow();
183 // Returns a RootWindow when used as a target when creating a new window.
184 // The root window of the active window is used in most cases, but can
185 // be overridden by using ScopedTargetRootWindow().
186 // If you want to get a RootWindow of the active window, just use
187 // |wm::GetActiveWindow()->GetRootWindow()|.
188 static aura::RootWindow* GetTargetRootWindow();
190 // Returns the global Screen object that's always active in ash.
191 static gfx::Screen* GetScreen();
193 // Returns all root windows.
194 static RootWindowList GetAllRootWindows();
196 static aura::Window* GetContainer(aura::RootWindow* root_window,
197 int container_id);
198 static const aura::Window* GetContainer(const aura::RootWindow* root_window,
199 int container_id);
201 // Returns the list of containers that match |container_id| in
202 // all root windows. If |priority_root| is given, the container
203 // in the |priority_root| will be inserted at the top of the list.
204 static std::vector<aura::Window*> GetContainersFromAllRootWindows(
205 int container_id,
206 aura::RootWindow* priority_root);
208 // True if an experimental maximize mode is enabled which forces browser and
209 // application windows to be maximized only.
210 static bool IsForcedMaximizeMode();
212 void set_target_root_window(aura::RootWindow* target_root_window) {
213 target_root_window_ = target_root_window;
216 // Shows the context menu for the background and launcher at
217 // |location_in_screen| (in screen coordinates).
218 void ShowContextMenu(const gfx::Point& location_in_screen,
219 ui::MenuSourceType source_type);
221 // Toggles the app list. |window| specifies in which display the app
222 // list should be shown. If this is NULL, the active root window
223 // will be used.
224 void ToggleAppList(aura::Window* anchor);
226 // Returns app list target visibility.
227 bool GetAppListTargetVisibility() const;
229 // Returns app list window or NULL if it is not visible.
230 aura::Window* GetAppListWindow();
232 // Returns true if a system-modal dialog window is currently open.
233 bool IsSystemModalWindowOpen() const;
235 // For testing only: set simulation that a modal window is open
236 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
237 simulate_modal_window_open_for_testing_ = modal_window_open;
240 // Creates a default views::NonClientFrameView for use by windows in the
241 // Ash environment.
242 views::NonClientFrameView* CreateDefaultNonClientFrameView(
243 views::Widget* widget);
245 // Rotates focus through containers that can receive focus.
246 void RotateFocus(Direction direction);
248 // Sets the work area insets of the display that contains |window|,
249 // this notifies observers too.
250 // TODO(sky): this no longer really replicates what happens and is unreliable.
251 // Remove this.
252 void SetDisplayWorkAreaInsets(aura::Window* window,
253 const gfx::Insets& insets);
255 // Called when the user logs in.
256 void OnLoginStateChanged(user::LoginStatus status);
258 // Called when the login status changes.
259 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
260 void UpdateAfterLoginStatusChange(user::LoginStatus status);
262 // Called when the application is exiting.
263 void OnAppTerminating();
265 // Called when the screen is locked (after the lock window is visible) or
266 // unlocked.
267 void OnLockStateChanged(bool locked);
269 // Initializes |launcher_|. Does nothing if it's already initialized.
270 void CreateLauncher();
272 // Show launcher view if it was created hidden (before session has started).
273 void ShowLauncher();
275 // Adds/removes observer.
276 void AddShellObserver(ShellObserver* observer);
277 void RemoveShellObserver(ShellObserver* observer);
279 AcceleratorController* accelerator_controller() {
280 return accelerator_controller_.get();
283 internal::DisplayManager* display_manager() {
284 return display_manager_.get();
286 views::corewm::InputMethodEventFilter* input_method_filter() {
287 return input_method_filter_.get();
289 views::corewm::CompoundEventFilter* env_filter() {
290 return env_filter_.get();
292 views::corewm::TooltipController* tooltip_controller() {
293 return tooltip_controller_.get();
295 internal::EventRewriterEventFilter* event_rewriter_filter() {
296 return event_rewriter_filter_.get();
298 internal::OverlayEventFilter* overlay_filter() {
299 return overlay_filter_.get();
301 DesktopBackgroundController* desktop_background_controller() {
302 return desktop_background_controller_.get();
304 PowerButtonController* power_button_controller() {
305 return power_button_controller_.get();
307 LockStateController* lock_state_controller() {
308 return lock_state_controller_.get();
310 MruWindowTracker* mru_window_tracker() {
311 return mru_window_tracker_.get();
313 UserActivityDetector* user_activity_detector() {
314 return user_activity_detector_.get();
316 VideoDetector* video_detector() {
317 return video_detector_.get();
319 WindowCycleController* window_cycle_controller() {
320 return window_cycle_controller_.get();
322 WindowSelectorController* window_selector_controller() {
323 return window_selector_controller_.get();
325 internal::FocusCycler* focus_cycler() {
326 return focus_cycler_.get();
328 DisplayController* display_controller() {
329 return display_controller_.get();
331 internal::MouseCursorEventFilter* mouse_cursor_filter() {
332 return mouse_cursor_filter_.get();
334 internal::EventTransformationHandler* event_transformation_handler() {
335 return event_transformation_handler_.get();
337 views::corewm::CursorManager* cursor_manager() { return &cursor_manager_; }
339 ShellDelegate* delegate() { return delegate_.get(); }
341 UserWallpaperDelegate* user_wallpaper_delegate() {
342 return user_wallpaper_delegate_.get();
345 CapsLockDelegate* caps_lock_delegate() {
346 return caps_lock_delegate_.get();
349 SessionStateDelegate* session_state_delegate() {
350 return session_state_delegate_.get();
353 HighContrastController* high_contrast_controller() {
354 return high_contrast_controller_.get();
357 MagnificationController* magnification_controller() {
358 return magnification_controller_.get();
361 PartialMagnificationController* partial_magnification_controller() {
362 return partial_magnification_controller_.get();
364 aura::client::ActivationClient* activation_client() {
365 return activation_client_;
368 LauncherItemDelegateManager* launcher_item_delegate_manager() {
369 return launcher_item_delegate_manager_.get();
372 ScreenAsh* screen() { return screen_; }
374 // Force the shelf to query for it's current visibility state.
375 void UpdateShelfVisibility();
377 // TODO(oshima): Define an interface to access shelf/launcher
378 // state, or just use Launcher.
380 // Sets/gets the shelf auto-hide behavior on |root_window|.
381 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
382 aura::RootWindow* root_window);
383 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
384 aura::RootWindow* root_window) const;
386 // Sets/gets shelf's alignment on |root_window|.
387 void SetShelfAlignment(ShelfAlignment alignment,
388 aura::RootWindow* root_window);
389 ShelfAlignment GetShelfAlignment(aura::RootWindow* root_window);
391 // Dims or undims the screen.
392 void SetDimming(bool should_dim);
394 // Creates a modal background (a partially-opaque fullscreen window)
395 // on all displays for |window|.
396 void CreateModalBackground(aura::Window* window);
398 // Called when a modal window is removed. It will activate
399 // another modal window if any, or remove modal screens
400 // on all displays.
401 void OnModalWindowRemoved(aura::Window* removed);
403 // Returns WebNotificationTray on the primary root window.
404 WebNotificationTray* GetWebNotificationTray();
406 // Does the primary display have status area?
407 bool HasPrimaryStatusArea();
409 // Returns the system tray on primary display.
410 SystemTray* GetPrimarySystemTray();
412 SystemTrayDelegate* system_tray_delegate() {
413 return system_tray_delegate_.get();
416 SystemTrayNotifier* system_tray_notifier() {
417 return system_tray_notifier_.get();
420 static void set_initially_hide_cursor(bool hide) {
421 initially_hide_cursor_ = hide;
424 internal::ResizeShadowController* resize_shadow_controller() {
425 return resize_shadow_controller_.get();
428 // Made available for tests.
429 views::corewm::ShadowController* shadow_controller() {
430 return shadow_controller_.get();
433 content::BrowserContext* browser_context() { return browser_context_; }
434 void set_browser_context(content::BrowserContext* browser_context) {
435 browser_context_ = browser_context;
438 // Initializes the root window to be used for a secondary display.
439 void InitRootWindowForSecondaryDisplay(aura::RootWindow* root);
441 // Starts the animation that occurs on first login.
442 void DoInitialWorkspaceAnimation();
444 #if defined(OS_CHROMEOS) && defined(USE_X11)
445 // TODO(oshima): Move these objects to DisplayController.
446 chromeos::OutputConfigurator* output_configurator() {
447 return output_configurator_.get();
449 internal::OutputConfiguratorAnimation* output_configurator_animation() {
450 return output_configurator_animation_.get();
452 internal::DisplayErrorObserver* display_error_observer() {
453 return display_error_observer_.get();
455 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
457 internal::ResolutionNotificationController*
458 resolution_notification_controller() {
459 return resolution_notification_controller_.get();
462 RootWindowHostFactory* root_window_host_factory() {
463 return root_window_host_factory_.get();
466 LauncherModel* launcher_model() {
467 return launcher_model_.get();
470 // Returns the launcher delegate, creating if necesary.
471 LauncherDelegate* GetLauncherDelegate();
473 void SetTouchHudProjectionEnabled(bool enabled);
475 bool is_touch_hud_projection_enabled() const {
476 return is_touch_hud_projection_enabled_;
479 private:
480 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
481 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
482 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
483 friend class internal::RootWindowController;
484 friend class internal::ScopedTargetRootWindow;
485 friend class test::ShellTestApi;
486 friend class shell::WindowWatcher;
488 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
490 // Takes ownership of |delegate|.
491 explicit Shell(ShellDelegate* delegate);
492 virtual ~Shell();
494 void Init();
496 // Initializes the root window and root window controller so that it
497 // can host browser windows. |first_run_after_boot| is true for the
498 // primary display only first time after boot.
499 void InitRootWindowController(internal::RootWindowController* root,
500 bool first_run_after_boot);
502 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
503 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
505 // Overridden from ui::EventTarget:
506 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
507 virtual EventTarget* GetParentTarget() OVERRIDE;
508 virtual void OnEvent(ui::Event* event) OVERRIDE;
510 // Overridden from aura::client::ActivationChangeObserver:
511 virtual void OnWindowActivated(aura::Window* gained_active,
512 aura::Window* lost_active) OVERRIDE;
514 static Shell* instance_;
516 // If set before the Shell is initialized, the mouse cursor will be hidden
517 // when the screen is initially created.
518 static bool initially_hide_cursor_;
520 ScreenAsh* screen_;
522 // When no explicit target display/RootWindow is given, new windows are
523 // created on |scoped_target_root_window_| , unless NULL in
524 // which case they are created on |target_root_window_|.
525 // |target_root_window_| never becomes NULL during the session.
526 aura::RootWindow* target_root_window_;
527 aura::RootWindow* scoped_target_root_window_;
529 // The CompoundEventFilter owned by aura::Env object.
530 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
532 std::vector<WindowAndBoundsPair> to_restore_;
534 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
535 scoped_ptr<AcceleratorController> accelerator_controller_;
536 scoped_ptr<ShellDelegate> delegate_;
537 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
538 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
539 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
540 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
541 scoped_ptr<SessionStateDelegate> session_state_delegate_;
542 scoped_ptr<LauncherDelegate> launcher_delegate_;
543 scoped_ptr<LauncherItemDelegateManager> launcher_item_delegate_manager_;
544 scoped_ptr<internal::AppListShelfItemDelegate>
545 app_list_shelf_item_delegate_;
547 scoped_ptr<LauncherModel> launcher_model_;
549 scoped_ptr<internal::AppListController> app_list_controller_;
551 scoped_ptr<internal::DragDropController> drag_drop_controller_;
552 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
553 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
554 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
555 scoped_ptr<views::corewm::WindowModalityController>
556 window_modality_controller_;
557 scoped_ptr<views::corewm::TooltipController> tooltip_controller_;
558 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
559 scoped_ptr<PowerButtonController> power_button_controller_;
560 scoped_ptr<LockStateController> lock_state_controller_;
561 scoped_ptr<MruWindowTracker> mru_window_tracker_;
562 scoped_ptr<UserActivityDetector> user_activity_detector_;
563 scoped_ptr<VideoDetector> video_detector_;
564 scoped_ptr<WindowCycleController> window_cycle_controller_;
565 scoped_ptr<WindowSelectorController> window_selector_controller_;
566 scoped_ptr<internal::FocusCycler> focus_cycler_;
567 scoped_ptr<DisplayController> display_controller_;
568 scoped_ptr<HighContrastController> high_contrast_controller_;
569 scoped_ptr<MagnificationController> magnification_controller_;
570 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
571 scoped_ptr<aura::client::FocusClient> focus_client_;
572 scoped_ptr<aura::client::UserActionClient> user_action_client_;
573 aura::client::ActivationClient* activation_client_;
574 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
575 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
576 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
577 scoped_ptr<internal::EventClientImpl> event_client_;
578 scoped_ptr<internal::EventTransformationHandler>
579 event_transformation_handler_;
580 scoped_ptr<RootWindowHostFactory> root_window_host_factory_;
582 // An event filter that rewrites or drops an event.
583 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
585 // An event filter that pre-handles key events while the partial
586 // screenshot UI or the keyboard overlay is active.
587 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
589 // An event filter for logging keyboard-related metrics.
590 scoped_ptr<internal::KeyboardUMAEventFilter> keyboard_metrics_filter_;
592 // An event filter which handles system level gestures
593 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
595 // An event filter that pre-handles global accelerators.
596 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
598 // An event filter that pre-handles all key events to send them to an IME.
599 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
601 scoped_ptr<internal::DisplayManager> display_manager_;
603 scoped_ptr<internal::LocaleNotificationController>
604 locale_notification_controller_;
606 #if defined(OS_CHROMEOS) && defined(USE_X11)
607 // Controls video output device state.
608 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
609 scoped_ptr<internal::OutputConfiguratorAnimation>
610 output_configurator_animation_;
611 scoped_ptr<internal::DisplayErrorObserver> display_error_observer_;
613 // Listens for output changes and updates the display manager.
614 scoped_ptr<internal::DisplayChangeObserver> display_change_observer_;
615 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
617 scoped_ptr<internal::ResolutionNotificationController>
618 resolution_notification_controller_;
620 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
621 // pointer to vend to test code.
622 AshNativeCursorManager* native_cursor_manager_;
623 views::corewm::CursorManager cursor_manager_;
625 ObserverList<ShellObserver> observers_;
627 // Used by ash/shell.
628 content::BrowserContext* browser_context_;
630 // For testing only: simulate that a modal window is open
631 bool simulate_modal_window_open_for_testing_;
633 bool is_touch_hud_projection_enabled_;
635 DISALLOW_COPY_AND_ASSIGN(Shell);
638 } // namespace ash
640 #endif // ASH_SHELL_H_