[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / ash / shell.h
blob20b787651a330d4aa47bdf5c2dbeb1daad6f14cc
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_types.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/wm/cursor_manager.h"
15 #include "ash/wm/system_modal_container_event_filter_delegate.h"
16 #include "base/basictypes.h"
17 #include "base/compiler_specific.h"
18 #include "base/gtest_prod_util.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/observer_list.h"
21 #include "ui/aura/client/activation_change_observer.h"
22 #include "ui/base/events/event_target.h"
23 #include "ui/gfx/insets.h"
24 #include "ui/gfx/screen.h"
25 #include "ui/gfx/size.h"
27 class CommandLine;
29 namespace aura {
30 class EventFilter;
31 class RootWindow;
32 class Window;
33 namespace client {
34 class ActivationClient;
35 class FocusClient;
36 class StackingClient;
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 VisibilityController;
63 class WindowModalityController;
67 namespace ash {
69 class AcceleratorController;
70 class CapsLockDelegate;
71 class DesktopBackgroundController;
72 class DisplayController;
73 class HighContrastController;
74 class Launcher;
75 class LauncherDelegate;
76 class LauncherModel;
77 class MagnificationController;
78 class NestedDispatcherController;
79 class PartialMagnificationController;
80 class PowerButtonController;
81 class RootWindowHostFactory;
82 class ScreenAsh;
83 class SessionStateController;
84 class ShellDelegate;
85 class ShellObserver;
86 class SystemTray;
87 class SystemTrayDelegate;
88 class SystemTrayNotifier;
89 class UserActivityDetector;
90 class UserWallpaperDelegate;
91 class VideoDetector;
92 class WebNotificationTray;
93 class WindowCycleController;
95 namespace internal {
96 class AcceleratorFilter;
97 class ActivationController;
98 class AppListController;
99 class CaptureController;
100 class DisplayChangeObserverX11;
101 class DisplayManager;
102 class DragDropController;
103 class EventClientImpl;
104 class EventRewriterEventFilter;
105 class FocusCycler;
106 class MouseCursorEventFilter;
107 class OutputConfiguratorAnimation;
108 class OverlayEventFilter;
109 class ResizeShadowController;
110 class RootWindowController;
111 class RootWindowLayoutManager;
112 class ScreenPositionController;
113 class SlowAnimationEventFilter;
114 class StatusAreaWidget;
115 class SystemGestureEventFilter;
116 class SystemModalContainerEventFilter;
117 class TooltipController;
118 class TouchObserverHUD;
119 class WorkspaceController;
122 namespace shell {
123 class WindowWatcher;
126 namespace test {
127 class ShellTestApi;
130 // Shell is a singleton object that presents the Shell API and implements the
131 // RootWindow's delegate interface.
133 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
134 // takes ownership of the Shell.
135 class ASH_EXPORT Shell
136 : public internal::SystemModalContainerEventFilterDelegate,
137 public ui::EventTarget,
138 public aura::client::ActivationChangeObserver {
139 public:
140 typedef std::vector<aura::RootWindow*> RootWindowList;
141 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
143 enum Direction {
144 FORWARD,
145 BACKWARD
148 // A shell must be explicitly created so that it can call |Init()| with the
149 // delegate set. |delegate| can be NULL (if not required for initialization).
150 static Shell* CreateInstance(ShellDelegate* delegate);
152 // Should never be called before |CreateInstance()|.
153 static Shell* GetInstance();
155 // Returns true if the ash shell has been instantiated.
156 static bool HasInstance();
158 static void DeleteInstance();
160 // Returns the root window controller for the primary root window.
161 // TODO(oshima): move this to |RootWindowController|
162 static internal::RootWindowController* GetPrimaryRootWindowController();
164 // Returns all root window controllers.
165 // TODO(oshima): move this to |RootWindowController|
166 static RootWindowControllerList GetAllRootWindowControllers();
168 // Returns the primary RootWindow. The primary RootWindow is the one
169 // that has a launcher.
170 static aura::RootWindow* GetPrimaryRootWindow();
172 // Returns the active RootWindow. The active RootWindow is the one that
173 // contains the current active window as a decendant child. The active
174 // RootWindow remains the same even when the active window becomes NULL,
175 // until the another window who has a different root window becomes active.
176 static aura::RootWindow* GetActiveRootWindow();
178 // Returns the global Screen object that's always active in ash.
179 static gfx::Screen* GetScreen();
181 // Returns all root windows.
182 static RootWindowList GetAllRootWindows();
184 static aura::Window* GetContainer(aura::RootWindow* root_window,
185 int container_id);
186 static const aura::Window* GetContainer(const aura::RootWindow* root_window,
187 int container_id);
189 // Returns the list of containers that match |container_id| in
190 // all root windows.
191 static std::vector<aura::Window*> GetAllContainers(int container_id);
193 // True if "launcher per display" feature is enabled.
194 static bool IsLauncherPerDisplayEnabled();
196 void set_active_root_window(aura::RootWindow* active_root_window) {
197 active_root_window_ = active_root_window;
200 // Shows the context menu for the background and launcher at
201 // |location_in_screen| (in screen coordinates).
202 void ShowContextMenu(const gfx::Point& location_in_screen);
204 // Toggles the app list. |window| specifies in which display the app
205 // list should be shown. If this is NULL, the active root window
206 // will be used.
207 void ToggleAppList(aura::Window* anchor);
209 // Returns app list target visibility.
210 bool GetAppListTargetVisibility() const;
212 // Returns app list window or NULL if it is not visible.
213 aura::Window* GetAppListWindow();
215 // Returns true if a user is logged in whose session can be locked (i.e. the
216 // user has a password with which to unlock the session).
217 bool CanLockScreen();
219 // Returns true if the screen is locked.
220 bool IsScreenLocked() const;
222 // Returns true if a system-modal dialog window is currently open.
223 bool IsSystemModalWindowOpen() const;
225 // For testing only: set simulation that a modal window is open
226 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
227 simulate_modal_window_open_for_testing_ = modal_window_open;
230 // Creates a default views::NonClientFrameView for use by windows in the
231 // Ash environment.
232 views::NonClientFrameView* CreateDefaultNonClientFrameView(
233 views::Widget* widget);
235 // Rotates focus through containers that can receive focus.
236 void RotateFocus(Direction direction);
238 // Sets the work area insets of the display that contains |window|,
239 // this notifies observers too.
240 // TODO(sky): this no longer really replicates what happens and is unreliable.
241 // Remove this.
242 void SetDisplayWorkAreaInsets(aura::Window* window,
243 const gfx::Insets& insets);
245 // Called when the user logs in.
246 void OnLoginStateChanged(user::LoginStatus status);
248 // Called when the login status changes.
249 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
250 void UpdateAfterLoginStatusChange(user::LoginStatus status);
252 // Called when the application is exiting.
253 void OnAppTerminating();
255 // Called when the screen is locked (after the lock window is visible) or
256 // unlocked.
257 void OnLockStateChanged(bool locked);
259 // Initializes |launcher_|. Does nothing if it's already initialized.
260 void CreateLauncher();
262 // Show launcher view if it was created hidden (before session has started).
263 void ShowLauncher();
265 // Adds/removes observer.
266 void AddShellObserver(ShellObserver* observer);
267 void RemoveShellObserver(ShellObserver* observer);
269 #if !defined(OS_MACOSX)
270 AcceleratorController* accelerator_controller() {
271 return accelerator_controller_.get();
273 #endif // !defined(OS_MACOSX)
275 internal::DisplayManager* display_manager() {
276 return display_manager_.get();
278 views::corewm::CompoundEventFilter* env_filter() {
279 return env_filter_.get();
281 internal::TooltipController* tooltip_controller() {
282 return tooltip_controller_.get();
284 internal::EventRewriterEventFilter* event_rewriter_filter() {
285 return event_rewriter_filter_.get();
287 internal::OverlayEventFilter* overlay_filter() {
288 return overlay_filter_.get();
290 DesktopBackgroundController* desktop_background_controller() {
291 return desktop_background_controller_.get();
293 PowerButtonController* power_button_controller() {
294 return power_button_controller_.get();
296 SessionStateController* session_state_controller() {
297 return session_state_controller_.get();
299 UserActivityDetector* user_activity_detector() {
300 return user_activity_detector_.get();
302 VideoDetector* video_detector() {
303 return video_detector_.get();
305 WindowCycleController* window_cycle_controller() {
306 return window_cycle_controller_.get();
308 internal::FocusCycler* focus_cycler() {
309 return focus_cycler_.get();
311 DisplayController* display_controller() {
312 return display_controller_.get();
314 internal::MouseCursorEventFilter* mouse_cursor_filter() {
315 return mouse_cursor_filter_.get();
317 CursorManager* cursor_manager() { return &cursor_manager_; }
319 ShellDelegate* delegate() { return delegate_.get(); }
321 UserWallpaperDelegate* user_wallpaper_delegate() {
322 return user_wallpaper_delegate_.get();
325 CapsLockDelegate* caps_lock_delegate() {
326 return caps_lock_delegate_.get();
329 HighContrastController* high_contrast_controller() {
330 return high_contrast_controller_.get();
333 MagnificationController* magnification_controller() {
334 return magnification_controller_.get();
337 PartialMagnificationController* partial_magnification_controller() {
338 return partial_magnification_controller_.get();
340 aura::client::ActivationClient* activation_client() {
341 return activation_client_;
344 ScreenAsh* screen() { return screen_; }
346 // Force the shelf to query for it's current visibility state.
347 void UpdateShelfVisibility();
349 // TODO(oshima): Define an interface to access shelf/launcher
350 // state, or just use Launcher.
352 // Sets/gets the shelf auto-hide behavior on |root_window|.
353 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
354 aura::RootWindow* root_window);
355 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
356 aura::RootWindow* root_window) const;
358 // Sets/gets shelf's alignment on |root_window|.
359 void SetShelfAlignment(ShelfAlignment alignment,
360 aura::RootWindow* root_window);
361 ShelfAlignment GetShelfAlignment(aura::RootWindow* root_window);
363 // Dims or undims the screen.
364 void SetDimming(bool should_dim);
366 // Creates a modal background (a partially-opaque fullscreen window)
367 // on all displays for |window|.
368 void CreateModalBackground(aura::Window* window);
370 // Called when a modal window is removed. It will activate
371 // another modal window if any, or remove modal screens
372 // on all displays.
373 void OnModalWindowRemoved(aura::Window* removed);
375 // Returns WebNotificationTray on the primary root window.
376 WebNotificationTray* GetWebNotificationTray();
378 // Does the primary display have status area?
379 bool HasPrimaryStatusArea();
381 // Returns the system tray on primary display.
382 SystemTray* GetPrimarySystemTray();
384 SystemTrayDelegate* system_tray_delegate() {
385 return system_tray_delegate_.get();
388 SystemTrayNotifier* system_tray_notifier() {
389 return system_tray_notifier_.get();
392 static void set_initially_hide_cursor(bool hide) {
393 initially_hide_cursor_ = hide;
396 internal::ResizeShadowController* resize_shadow_controller() {
397 return resize_shadow_controller_.get();
400 // Made available for tests.
401 views::corewm::ShadowController* shadow_controller() {
402 return shadow_controller_.get();
405 content::BrowserContext* browser_context() { return browser_context_; }
406 void set_browser_context(content::BrowserContext* browser_context) {
407 browser_context_ = browser_context;
410 // Initializes the root window to be used for a secondary display.
411 void InitRootWindowForSecondaryDisplay(aura::RootWindow* root);
413 // Starts the animation that occurs on first login.
414 void DoInitialWorkspaceAnimation();
416 #if defined(OS_CHROMEOS)
417 chromeos::OutputConfigurator* output_configurator() {
418 return output_configurator_.get();
420 internal::OutputConfiguratorAnimation* output_configurator_animation() {
421 return output_configurator_animation_.get();
423 #endif // defined(OS_CHROMEOS)
425 aura::client::StackingClient* stacking_client();
427 RootWindowHostFactory* root_window_host_factory() {
428 return root_window_host_factory_.get();
431 private:
432 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
433 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
434 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
435 friend class internal::RootWindowController;
436 friend class test::ShellTestApi;
437 friend class shell::WindowWatcher;
439 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
441 explicit Shell(ShellDelegate* delegate);
442 virtual ~Shell();
444 void Init();
446 LauncherModel* launcher_model() {
447 return launcher_model_.get();
450 // Returns the launcher delegate, creating if necesary.
451 LauncherDelegate* GetLauncherDelegate();
453 // Initializes the root window and root window controller so that it
454 // can host browser windows.
455 void InitRootWindowController(internal::RootWindowController* root);
457 // Initializes the layout managers and event filters specific for
458 // primary display.
459 void InitLayoutManagersForPrimaryDisplay(
460 internal::RootWindowController* root_window_controller);
462 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
463 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
465 // Overridden from ui::EventTarget:
466 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
467 virtual EventTarget* GetParentTarget() OVERRIDE;
468 virtual void OnEvent(ui::Event* event) OVERRIDE;
470 // Overridden from aura::client::ActivationChangeObserver:
471 virtual void OnWindowActivated(aura::Window* gained_active,
472 aura::Window* lost_active) OVERRIDE;
474 static Shell* instance_;
476 // If set before the Shell is initialized, the mouse cursor will be hidden
477 // when the screen is initially created.
478 static bool initially_hide_cursor_;
480 ScreenAsh* screen_;
482 // Active root window. Never becomes NULL during the session.
483 aura::RootWindow* active_root_window_;
485 // The CompoundEventFilter owned by aura::Env object.
486 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
488 std::vector<WindowAndBoundsPair> to_restore_;
490 #if !defined(OS_MACOSX)
491 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
493 scoped_ptr<AcceleratorController> accelerator_controller_;
494 #endif // !defined(OS_MACOSX)
496 scoped_ptr<ShellDelegate> delegate_;
497 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
498 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
499 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
500 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
501 scoped_ptr<LauncherDelegate> launcher_delegate_;
503 scoped_ptr<LauncherModel> launcher_model_;
505 scoped_ptr<internal::AppListController> app_list_controller_;
507 scoped_ptr<aura::client::StackingClient> stacking_client_;
508 scoped_ptr<internal::ActivationController> activation_controller_;
509 scoped_ptr<internal::CaptureController> capture_controller_;
510 scoped_ptr<internal::DragDropController> drag_drop_controller_;
511 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
512 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
513 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
514 scoped_ptr<views::corewm::WindowModalityController>
515 window_modality_controller_;
516 scoped_ptr<internal::TooltipController> tooltip_controller_;
517 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
518 scoped_ptr<PowerButtonController> power_button_controller_;
519 scoped_ptr<SessionStateController> session_state_controller_;
520 scoped_ptr<UserActivityDetector> user_activity_detector_;
521 scoped_ptr<VideoDetector> video_detector_;
522 scoped_ptr<WindowCycleController> window_cycle_controller_;
523 scoped_ptr<internal::FocusCycler> focus_cycler_;
524 scoped_ptr<DisplayController> display_controller_;
525 scoped_ptr<HighContrastController> high_contrast_controller_;
526 scoped_ptr<MagnificationController> magnification_controller_;
527 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
528 scoped_ptr<aura::client::FocusClient> focus_client_;
529 scoped_ptr<aura::client::UserActionClient> user_action_client_;
530 aura::client::ActivationClient* activation_client_;
531 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
532 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
533 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
534 scoped_ptr<internal::EventClientImpl> event_client_;
535 scoped_ptr<RootWindowHostFactory> root_window_host_factory_;
537 // An event filter that rewrites or drops an event.
538 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
540 // An event filter that pre-handles key events while the partial
541 // screenshot UI or the keyboard overlay is active.
542 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
544 // An event filter which handles system level gestures
545 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
547 #if !defined(OS_MACOSX)
548 // An event filter that pre-handles global accelerators.
549 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
550 #endif
552 // An event filter that pre-handles all key events to send them to an IME.
553 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
555 // An event filter that silently keeps track of all touch events and controls
556 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
557 scoped_ptr<internal::TouchObserverHUD> touch_observer_hud_;
559 scoped_ptr<internal::DisplayManager> display_manager_;
561 #if defined(OS_CHROMEOS)
562 // Controls video output device state.
563 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
564 scoped_ptr<internal::OutputConfiguratorAnimation>
565 output_configurator_animation_;
567 // Receives output change events and udpates the display manager.
568 scoped_ptr<internal::DisplayChangeObserverX11> display_change_observer_;
569 #endif // defined(OS_CHROMEOS)
571 CursorManager cursor_manager_;
573 ObserverList<ShellObserver> observers_;
575 // Used by ash/shell.
576 content::BrowserContext* browser_context_;
578 // For testing only: simulate that a modal window is open
579 bool simulate_modal_window_open_for_testing_;
581 DISALLOW_COPY_AND_ASSIGN(Shell);
584 } // namespace ash
586 #endif // ASH_SHELL_H_