Properly disable accelerated compositing for extension background pages. Since these
[chromium-blink-merge.git] / ash / shell.h
blob0a1fe5fec8bc7cb66f3286f29db5f74cfafa8910
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/base/events/event_target.h"
22 #include "ui/gfx/insets.h"
23 #include "ui/gfx/screen.h"
24 #include "ui/gfx/size.h"
26 class CommandLine;
28 namespace aura {
29 class EventFilter;
30 class RootWindow;
31 class Window;
32 namespace client {
33 class ActivationClient;
34 class FocusClient;
35 class StackingClient;
36 class UserActionClient;
39 namespace chromeos {
40 class OutputConfigurator;
42 namespace content {
43 class BrowserContext;
46 namespace gfx {
47 class ImageSkia;
48 class Point;
49 class Rect;
51 namespace ui {
52 class Layer;
54 namespace views {
55 class NonClientFrameView;
56 class Widget;
57 namespace corewm {
58 class CompoundEventFilter;
59 class InputMethodEventFilter;
60 class ShadowController;
61 class VisibilityController;
62 class WindowModalityController;
66 namespace ash {
68 class AcceleratorController;
69 class CapsLockDelegate;
70 class DesktopBackgroundController;
71 class DisplayController;
72 class HighContrastController;
73 class Launcher;
74 class LauncherDelegate;
75 class LauncherModel;
76 class MagnificationController;
77 class NestedDispatcherController;
78 class PartialMagnificationController;
79 class PowerButtonController;
80 class ScreenAsh;
81 class SessionStateController;
82 class ShellDelegate;
83 class ShellObserver;
84 class SystemTray;
85 class SystemTrayDelegate;
86 class SystemTrayNotifier;
87 class UserActivityDetector;
88 class UserWallpaperDelegate;
89 class VideoDetector;
90 class WebNotificationTray;
91 class WindowCycleController;
93 namespace internal {
94 class AcceleratorFilter;
95 class ActivationController;
96 class AppListController;
97 class CaptureController;
98 class DisplayChangeObserverX11;
99 class DisplayManager;
100 class DragDropController;
101 class EventClientImpl;
102 class EventRewriterEventFilter;
103 class FocusCycler;
104 class MouseCursorEventFilter;
105 class OutputConfiguratorAnimation;
106 class OverlayEventFilter;
107 class ResizeShadowController;
108 class RootWindowController;
109 class RootWindowLayoutManager;
110 class ScreenPositionController;
111 class SlowAnimationEventFilter;
112 class StatusAreaWidget;
113 class SystemGestureEventFilter;
114 class SystemModalContainerEventFilter;
115 class TooltipController;
116 class TouchObserverHUD;
117 class WorkspaceController;
120 namespace test {
121 class ShellTestApi;
124 // Shell is a singleton object that presents the Shell API and implements the
125 // RootWindow's delegate interface.
127 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
128 // takes ownership of the Shell.
129 class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate,
130 public ui::EventTarget {
131 public:
132 typedef std::vector<aura::RootWindow*> RootWindowList;
133 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
135 enum Direction {
136 FORWARD,
137 BACKWARD
140 // A shell must be explicitly created so that it can call |Init()| with the
141 // delegate set. |delegate| can be NULL (if not required for initialization).
142 static Shell* CreateInstance(ShellDelegate* delegate);
144 // Should never be called before |CreateInstance()|.
145 static Shell* GetInstance();
147 // Returns true if the ash shell has been instantiated.
148 static bool HasInstance();
150 static void DeleteInstance();
152 // Returns the root window controller for the primary root window.
153 // TODO(oshima): move this to |RootWindowController|
154 static internal::RootWindowController* GetPrimaryRootWindowController();
156 // Returns all root window controllers.
157 // TODO(oshima): move this to |RootWindowController|
158 static RootWindowControllerList GetAllRootWindowControllers();
160 // Returns the primary RootWindow. The primary RootWindow is the one
161 // that has a launcher.
162 static aura::RootWindow* GetPrimaryRootWindow();
164 // Returns the active RootWindow. The active RootWindow is the one that
165 // contains the current active window as a decendant child. The active
166 // RootWindow remains the same even when the active window becomes NULL,
167 // until the another window who has a different root window becomes active.
168 static aura::RootWindow* GetActiveRootWindow();
170 // Returns the global Screen object that's always active in ash.
171 static gfx::Screen* GetScreen();
173 // Returns all root windows.
174 static RootWindowList GetAllRootWindows();
176 static aura::Window* GetContainer(aura::RootWindow* root_window,
177 int container_id);
178 static const aura::Window* GetContainer(const aura::RootWindow* root_window,
179 int container_id);
181 // Returns the list of containers that match |container_id| in
182 // all root windows.
183 static std::vector<aura::Window*> GetAllContainers(int container_id);
185 // True if "launcher per display" feature is enabled.
186 static bool IsLauncherPerDisplayEnabled();
188 void set_active_root_window(aura::RootWindow* active_root_window) {
189 active_root_window_ = active_root_window;
192 // Shows the context menu for the background and launcher at
193 // |location_in_screen| (in screen coordinates).
194 void ShowContextMenu(const gfx::Point& location_in_screen);
196 // Toggles the app list. |window| specifies in which display the app
197 // list should be shown. If this is NULL, the active root window
198 // will be used.
199 void ToggleAppList(aura::Window* anchor);
201 // Returns app list target visibility.
202 bool GetAppListTargetVisibility() const;
204 // Returns app list window or NULL if it is not visible.
205 aura::Window* GetAppListWindow();
207 // Returns true if a user is logged in whose session can be locked (i.e. the
208 // user has a password with which to unlock the session).
209 bool CanLockScreen();
211 // Returns true if the screen is locked.
212 bool IsScreenLocked() const;
214 // Returns true if a system-modal dialog window is currently open.
215 bool IsSystemModalWindowOpen() const;
217 // For testing only: set simulation that a modal window is open
218 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
219 simulate_modal_window_open_for_testing_ = modal_window_open;
222 // Creates a default views::NonClientFrameView for use by windows in the
223 // Ash environment.
224 views::NonClientFrameView* CreateDefaultNonClientFrameView(
225 views::Widget* widget);
227 // Rotates focus through containers that can receive focus.
228 void RotateFocus(Direction direction);
230 // Sets the work area insets of the display that contains |window|,
231 // this notifies observers too.
232 // TODO(sky): this no longer really replicates what happens and is unreliable.
233 // Remove this.
234 void SetDisplayWorkAreaInsets(aura::Window* window,
235 const gfx::Insets& insets);
237 // Called when the user logs in.
238 void OnLoginStateChanged(user::LoginStatus status);
240 // Called when the login status changes.
241 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
242 void UpdateAfterLoginStatusChange(user::LoginStatus status);
244 // Called when the application is exiting.
245 void OnAppTerminating();
247 // Called when the screen is locked (after the lock window is visible) or
248 // unlocked.
249 void OnLockStateChanged(bool locked);
251 // Initializes |launcher_|. Does nothing if it's already initialized.
252 void CreateLauncher();
254 // Show launcher view if it was created hidden (before session has started).
255 void ShowLauncher();
257 // Adds/removes observer.
258 void AddShellObserver(ShellObserver* observer);
259 void RemoveShellObserver(ShellObserver* observer);
261 #if !defined(OS_MACOSX)
262 AcceleratorController* accelerator_controller() {
263 return accelerator_controller_.get();
265 #endif // !defined(OS_MACOSX)
267 internal::DisplayManager* display_manager() {
268 return display_manager_.get();
270 views::corewm::CompoundEventFilter* env_filter() {
271 return env_filter_.get();
273 internal::TooltipController* tooltip_controller() {
274 return tooltip_controller_.get();
276 internal::EventRewriterEventFilter* event_rewriter_filter() {
277 return event_rewriter_filter_.get();
279 internal::OverlayEventFilter* overlay_filter() {
280 return overlay_filter_.get();
282 DesktopBackgroundController* desktop_background_controller() {
283 return desktop_background_controller_.get();
285 PowerButtonController* power_button_controller() {
286 return power_button_controller_.get();
288 SessionStateController* session_state_controller() {
289 return session_state_controller_.get();
291 UserActivityDetector* user_activity_detector() {
292 return user_activity_detector_.get();
294 VideoDetector* video_detector() {
295 return video_detector_.get();
297 WindowCycleController* window_cycle_controller() {
298 return window_cycle_controller_.get();
300 internal::FocusCycler* focus_cycler() {
301 return focus_cycler_.get();
303 DisplayController* display_controller() {
304 return display_controller_.get();
306 internal::MouseCursorEventFilter* mouse_cursor_filter() {
307 return mouse_cursor_filter_.get();
309 CursorManager* cursor_manager() { return &cursor_manager_; }
311 ShellDelegate* delegate() { return delegate_.get(); }
313 UserWallpaperDelegate* user_wallpaper_delegate() {
314 return user_wallpaper_delegate_.get();
317 CapsLockDelegate* caps_lock_delegate() {
318 return caps_lock_delegate_.get();
321 HighContrastController* high_contrast_controller() {
322 return high_contrast_controller_.get();
325 MagnificationController* magnification_controller() {
326 return magnification_controller_.get();
329 PartialMagnificationController* partial_magnification_controller() {
330 return partial_magnification_controller_.get();
333 ScreenAsh* screen() { return screen_; }
335 // Force the shelf to query for it's current visibility state.
336 void UpdateShelfVisibility();
338 // TODO(oshima): Define an interface to access shelf/launcher
339 // state, or just use Launcher.
341 // Sets/gets the shelf auto-hide behavior on |root_window|.
342 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
343 aura::RootWindow* root_window);
344 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
345 aura::RootWindow* root_window) const;
347 // Sets/gets shelf's alignment on |root_window|.
348 void SetShelfAlignment(ShelfAlignment alignment,
349 aura::RootWindow* root_window);
350 ShelfAlignment GetShelfAlignment(aura::RootWindow* root_window);
352 // Dims or undims the screen.
353 void SetDimming(bool should_dim);
355 // Creates a modal background (a partially-opaque fullscreen window)
356 // on all displays for |window|.
357 void CreateModalBackground(aura::Window* window);
359 // Called when a modal window is removed. It will activate
360 // another modal window if any, or remove modal screens
361 // on all displays.
362 void OnModalWindowRemoved(aura::Window* removed);
364 // Returns WebNotificationTray on the primary root window.
365 WebNotificationTray* GetWebNotificationTray();
367 // Does the primary display have status area?
368 bool HasPrimaryStatusArea();
370 // Returns the system tray on primary display.
371 SystemTray* GetPrimarySystemTray();
373 // Returns the launcher delegate, creating if necesary.
374 LauncherDelegate* GetLauncherDelegate();
376 // TODO(stevenjb): Rename to system_tray_delegate().
377 SystemTrayDelegate* tray_delegate() {
378 return system_tray_delegate_.get();
381 SystemTrayNotifier* system_tray_notifier() {
382 return system_tray_notifier_.get();
385 LauncherModel* launcher_model() {
386 return launcher_model_.get();
389 static void set_initially_hide_cursor(bool hide) {
390 initially_hide_cursor_ = hide;
393 internal::ResizeShadowController* resize_shadow_controller() {
394 return resize_shadow_controller_.get();
397 // Made available for tests.
398 views::corewm::ShadowController* shadow_controller() {
399 return shadow_controller_.get();
402 content::BrowserContext* browser_context() { return browser_context_; }
403 void set_browser_context(content::BrowserContext* browser_context) {
404 browser_context_ = browser_context;
407 // Initializes the root window to be used for a secondary display.
408 void InitRootWindowForSecondaryDisplay(aura::RootWindow* root);
410 // Starts the animation that occurs on first login.
411 void DoInitialWorkspaceAnimation();
413 #if defined(OS_CHROMEOS)
414 chromeos::OutputConfigurator* output_configurator() {
415 return output_configurator_.get();
417 internal::OutputConfiguratorAnimation* output_configurator_animation() {
418 return output_configurator_animation_.get();
420 #endif // defined(OS_CHROMEOS)
422 aura::client::StackingClient* stacking_client();
424 private:
425 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
426 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
427 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
428 friend class internal::RootWindowController;
429 friend class test::ShellTestApi;
431 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
433 explicit Shell(ShellDelegate* delegate);
434 virtual ~Shell();
436 void Init();
438 // Initializes the root window and root window controller so that it
439 // can host browser windows.
440 void InitRootWindowController(internal::RootWindowController* root);
442 // Initializes the layout managers and event filters specific for
443 // primary display.
444 void InitLayoutManagersForPrimaryDisplay(
445 internal::RootWindowController* root_window_controller);
447 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
448 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
450 // Overridden from ui::EventTarget:
451 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
452 virtual EventTarget* GetParentTarget() OVERRIDE;
453 virtual void OnEvent(ui::Event* event) OVERRIDE;
455 static Shell* instance_;
457 // If set before the Shell is initialized, the mouse cursor will be hidden
458 // when the screen is initially created.
459 static bool initially_hide_cursor_;
461 ScreenAsh* screen_;
463 // Active root window. Never becomes NULL during the session.
464 aura::RootWindow* active_root_window_;
466 // The CompoundEventFilter owned by aura::Env object.
467 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
469 std::vector<WindowAndBoundsPair> to_restore_;
471 #if !defined(OS_MACOSX)
472 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
474 scoped_ptr<AcceleratorController> accelerator_controller_;
475 #endif // !defined(OS_MACOSX)
477 scoped_ptr<ShellDelegate> delegate_;
478 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
479 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
480 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
481 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
482 scoped_ptr<LauncherDelegate> launcher_delegate_;
484 scoped_ptr<LauncherModel> launcher_model_;
486 scoped_ptr<internal::AppListController> app_list_controller_;
488 scoped_ptr<aura::client::StackingClient> stacking_client_;
489 scoped_ptr<internal::ActivationController> activation_controller_;
490 scoped_ptr<internal::CaptureController> capture_controller_;
491 scoped_ptr<internal::DragDropController> drag_drop_controller_;
492 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
493 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
494 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
495 scoped_ptr<views::corewm::WindowModalityController>
496 window_modality_controller_;
497 scoped_ptr<internal::TooltipController> tooltip_controller_;
498 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
499 scoped_ptr<PowerButtonController> power_button_controller_;
500 scoped_ptr<SessionStateController> session_state_controller_;
501 scoped_ptr<UserActivityDetector> user_activity_detector_;
502 scoped_ptr<VideoDetector> video_detector_;
503 scoped_ptr<WindowCycleController> window_cycle_controller_;
504 scoped_ptr<internal::FocusCycler> focus_cycler_;
505 scoped_ptr<DisplayController> display_controller_;
506 scoped_ptr<HighContrastController> high_contrast_controller_;
507 scoped_ptr<MagnificationController> magnification_controller_;
508 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
509 scoped_ptr<aura::client::FocusClient> focus_client_;
510 scoped_ptr<aura::client::UserActionClient> user_action_client_;
511 aura::client::ActivationClient* activation_client_;
512 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
513 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
514 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
515 scoped_ptr<internal::EventClientImpl> event_client_;
517 // An event filter that rewrites or drops an event.
518 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
520 // An event filter that pre-handles key events while the partial
521 // screenshot UI or the keyboard overlay is active.
522 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
524 // An event filter which handles system level gestures
525 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
527 #if !defined(OS_MACOSX)
528 // An event filter that pre-handles global accelerators.
529 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
530 #endif
532 // An event filter that pre-handles all key events to send them to an IME.
533 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
535 // An event filter that silently keeps track of all touch events and controls
536 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
537 scoped_ptr<internal::TouchObserverHUD> touch_observer_hud_;
539 scoped_ptr<internal::DisplayManager> display_manager_;
541 #if defined(OS_CHROMEOS)
542 // Controls video output device state.
543 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
544 scoped_ptr<internal::OutputConfiguratorAnimation>
545 output_configurator_animation_;
547 // Receives output change events and udpates the display manager.
548 scoped_ptr<internal::DisplayChangeObserverX11> display_change_observer_;
549 #endif // defined(OS_CHROMEOS)
551 CursorManager cursor_manager_;
553 ObserverList<ShellObserver> observers_;
555 // Used by ash/shell.
556 content::BrowserContext* browser_context_;
558 // For testing only: simulate that a modal window is open
559 bool simulate_modal_window_open_for_testing_;
561 DISALLOW_COPY_AND_ASSIGN(Shell);
564 } // namespace ash
566 #endif // ASH_SHELL_H_