1. Enable large object pointer offset check in release build.
[chromium-blink-merge.git] / ash / shell.h
blobfa8c50da33bfab38dcb252048640b8783705295c
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_
7 #pragma once
9 #include <utility>
10 #include <vector>
12 #include "ash/ash_export.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/wm/shelf_auto_hide_behavior.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/gfx/size.h"
21 #include "ui/gfx/insets.h"
23 class CommandLine;
24 class SkBitmap;
26 namespace aura {
27 class EventFilter;
28 class Monitor;
29 class RootWindow;
30 class Window;
31 namespace shared {
32 class InputMethodEventFilter;
33 class RootWindowEventFilter;
36 namespace content {
37 class BrowserContext;
40 namespace gfx {
41 class Point;
42 class Rect;
44 namespace ui {
45 class Layer;
47 namespace views {
48 class NonClientFrameView;
49 class Widget;
52 namespace ash {
54 class AcceleratorController;
55 class DesktopBackgroundController;
56 class HighContrastController;
57 class Launcher;
58 class NestedDispatcherController;
59 class PowerButtonController;
60 class ScreenAsh;
61 class ShellDelegate;
62 class ShellObserver;
63 class SystemTrayDelegate;
64 class SystemTray;
65 class UserWallpaperDelegate;
66 class VideoDetector;
67 class WindowCycleController;
69 namespace internal {
70 class AcceleratorFilter;
71 class ActivationController;
72 class AppListController;
73 class DragDropController;
74 class EventClientImpl;
75 class FocusCycler;
76 class KeyRewriterEventFilter;
77 class MagnificationController;
78 class MonitorController;
79 class PanelLayoutManager;
80 class PartialScreenshotEventFilter;
81 class ResizeShadowController;
82 class RootWindowLayoutManager;
83 class ScreenDimmer;
84 class ShadowController;
85 class ShelfLayoutManager;
86 class ShellContextMenu;
87 class SystemGestureEventFilter;
88 class StackingController;
89 class TooltipController;
90 class TouchObserverHUD;
91 class VisibilityController;
92 class WindowModalityController;
93 class WorkspaceController;
96 // Shell is a singleton object that presents the Shell API and implements the
97 // RootWindow's delegate interface.
99 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
100 // takes ownership of the Shell.
101 class ASH_EXPORT Shell {
102 public:
103 enum Direction {
104 FORWARD,
105 BACKWARD
108 // Accesses private data from a Shell for testing.
109 class ASH_EXPORT TestApi {
110 public:
111 explicit TestApi(Shell* shell);
113 internal::RootWindowLayoutManager* root_window_layout();
114 aura::shared::InputMethodEventFilter* input_method_event_filter();
115 internal::SystemGestureEventFilter* system_gesture_event_filter();
116 internal::WorkspaceController* workspace_controller();
118 private:
119 Shell* shell_; // not owned
121 DISALLOW_COPY_AND_ASSIGN(TestApi);
124 // A shell must be explicitly created so that it can call |Init()| with the
125 // delegate set. |delegate| can be NULL (if not required for initialization).
126 static Shell* CreateInstance(ShellDelegate* delegate);
128 // Should never be called before |CreateInstance()|.
129 static Shell* GetInstance();
131 // Returns true if the ash shell has been instantiated.
132 static bool HasInstance();
134 static void DeleteInstance();
136 // Gets the singleton RootWindow used by the Shell.
137 static aura::RootWindow* GetRootWindow();
139 internal::RootWindowLayoutManager* root_window_layout() const {
140 return root_window_layout_;
143 aura::Window* GetContainer(int container_id);
144 const aura::Window* GetContainer(int container_id) const;
146 // Adds or removes |filter| from the RootWindowEventFilter.
147 void AddRootWindowEventFilter(aura::EventFilter* filter);
148 void RemoveRootWindowEventFilter(aura::EventFilter* filter);
149 size_t GetRootWindowEventFilterCount() const;
151 // Shows the background menu over |widget|.
152 void ShowBackgroundMenu(views::Widget* widget, const gfx::Point& location);
154 // Toggles app list.
155 void ToggleAppList();
157 // Returns app list target visibility.
158 bool GetAppListTargetVisibility() const;
160 // Returns app list window or NULL if it is not visible.
161 aura::Window* GetAppListWindow();
163 // Returns true if the screen is locked.
164 bool IsScreenLocked() const;
166 // Returns true if a modal dialog window is currently open.
167 bool IsModalWindowOpen() const;
169 // Creates a default views::NonClientFrameView for use by windows in the
170 // Ash environment.
171 views::NonClientFrameView* CreateDefaultNonClientFrameView(
172 views::Widget* widget);
174 // Rotates focus through containers that can receive focus.
175 void RotateFocus(Direction direction);
177 // Sets the work area insets of the monitor that contains |window|,
178 // this notifies observers too.
179 // TODO(sky): this no longer really replicates what happens and is unreliable.
180 // Remove this.
181 void SetMonitorWorkAreaInsets(aura::Window* window,
182 const gfx::Insets& insets);
184 // Called when the user logs in.
185 void OnLoginStateChanged(user::LoginStatus status);
187 // Called when the application is exiting.
188 void OnAppTerminating();
190 // Called when the screen is locked (after the lock window is visible) or
191 // unlocked.
192 void OnLockStateChanged(bool locked);
194 // Initializes |launcher_|. Does nothing if it's already initialized.
195 void CreateLauncher();
197 // Adds/removes observer.
198 void AddShellObserver(ShellObserver* observer);
199 void RemoveShellObserver(ShellObserver* observer);
201 #if !defined(OS_MACOSX)
202 AcceleratorController* accelerator_controller() {
203 return accelerator_controller_.get();
205 #endif // !defined(OS_MACOSX)
207 aura::shared::RootWindowEventFilter* root_filter() {
208 return root_filter_;
210 internal::TooltipController* tooltip_controller() {
211 return tooltip_controller_.get();
213 internal::KeyRewriterEventFilter* key_rewriter_filter() {
214 return key_rewriter_filter_.get();
216 internal::PartialScreenshotEventFilter* partial_screenshot_filter() {
217 return partial_screenshot_filter_.get();
219 DesktopBackgroundController* desktop_background_controller() {
220 return desktop_background_controller_.get();
222 PowerButtonController* power_button_controller() {
223 return power_button_controller_.get();
225 VideoDetector* video_detector() {
226 return video_detector_.get();
228 WindowCycleController* window_cycle_controller() {
229 return window_cycle_controller_.get();
231 internal::FocusCycler* focus_cycler() {
232 return focus_cycler_.get();
235 ShellDelegate* delegate() { return delegate_.get(); }
236 SystemTrayDelegate* tray_delegate() { return tray_delegate_.get(); }
237 UserWallpaperDelegate* user_wallpaper_delegate() {
238 return user_wallpaper_delegate_.get();
241 HighContrastController* high_contrast_controller() {
242 return high_contrast_controller_.get();
245 internal::MagnificationController* magnification_controller() {
246 return magnification_controller_.get();
249 internal::ScreenDimmer* screen_dimmer() {
250 return screen_dimmer_.get();
253 Launcher* launcher() { return launcher_.get(); }
255 const ScreenAsh* screen() { return screen_; }
257 // Force the shelf to query for it's current visibility state.
258 void UpdateShelfVisibility();
260 // Sets/gets the shelf auto-hide behavior.
261 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior);
262 ShelfAutoHideBehavior GetShelfAutoHideBehavior() const;
264 void SetShelfAlignment(ShelfAlignment alignment);
265 ShelfAlignment GetShelfAlignment();
267 // TODO(sky): don't expose this!
268 internal::ShelfLayoutManager* shelf() const { return shelf_; }
270 SystemTray* tray() const { return tray_.get(); }
272 // Returns the size of the grid.
273 int GetGridSize() const;
275 // Returns true if in maximized or fullscreen mode.
276 bool IsInMaximizedMode() const;
278 static void set_initially_hide_cursor(bool hide) {
279 initially_hide_cursor_ = hide;
282 internal::ResizeShadowController* resize_shadow_controller() {
283 return resize_shadow_controller_.get();
286 // Made available for tests.
287 internal::ShadowController* shadow_controller() {
288 return shadow_controller_.get();
291 content::BrowserContext* browser_context() { return browser_context_; }
292 void set_browser_context(content::BrowserContext* browser_context) {
293 browser_context_ = browser_context;
296 private:
297 FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, MouseEventCursors);
298 FRIEND_TEST_ALL_PREFIXES(RootWindowEventFilterTest, TransformActivate);
300 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
302 explicit Shell(ShellDelegate* delegate);
303 virtual ~Shell();
305 void Init();
307 // Initializes the layout managers and event filters.
308 void InitLayoutManagers();
310 // Disables the workspace grid layout.
311 void DisableWorkspaceGridLayout();
313 static Shell* instance_;
315 // If set before the Shell is initialized, the mouse cursor will be hidden
316 // when the screen is initially created.
317 static bool initially_hide_cursor_;
319 scoped_ptr<aura::RootWindow> root_window_;
320 ScreenAsh* screen_;
322 aura::shared::RootWindowEventFilter* root_filter_; // not owned
324 std::vector<WindowAndBoundsPair> to_restore_;
326 #if !defined(OS_MACOSX)
327 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
329 scoped_ptr<AcceleratorController> accelerator_controller_;
330 #endif // !defined(OS_MACOSX)
332 scoped_ptr<ShellDelegate> delegate_;
333 scoped_ptr<SystemTrayDelegate> tray_delegate_;
334 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
336 scoped_ptr<Launcher> launcher_;
338 scoped_ptr<internal::AppListController> app_list_controller_;
340 scoped_ptr<internal::ShellContextMenu> shell_context_menu_;
341 scoped_ptr<internal::StackingController> stacking_controller_;
342 scoped_ptr<internal::ActivationController> activation_controller_;
343 scoped_ptr<internal::WindowModalityController> window_modality_controller_;
344 scoped_ptr<internal::DragDropController> drag_drop_controller_;
345 scoped_ptr<internal::WorkspaceController> workspace_controller_;
346 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
347 scoped_ptr<internal::ShadowController> shadow_controller_;
348 scoped_ptr<internal::TooltipController> tooltip_controller_;
349 scoped_ptr<internal::VisibilityController> visibility_controller_;
350 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
351 scoped_ptr<PowerButtonController> power_button_controller_;
352 scoped_ptr<VideoDetector> video_detector_;
353 scoped_ptr<WindowCycleController> window_cycle_controller_;
354 scoped_ptr<internal::FocusCycler> focus_cycler_;
355 scoped_ptr<internal::EventClientImpl> event_client_;
356 scoped_ptr<internal::MonitorController> monitor_controller_;
357 scoped_ptr<HighContrastController> high_contrast_controller_;
358 scoped_ptr<internal::MagnificationController> magnification_controller_;
359 scoped_ptr<internal::ScreenDimmer> screen_dimmer_;
361 // An event filter that rewrites or drops a key event.
362 scoped_ptr<internal::KeyRewriterEventFilter> key_rewriter_filter_;
364 // An event filter that pre-handles key events while the partial
365 // screenshot UI is active.
366 scoped_ptr<internal::PartialScreenshotEventFilter> partial_screenshot_filter_;
368 // An event filter which handles system level gestures
369 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
371 #if !defined(OS_MACOSX)
372 // An event filter that pre-handles global accelerators.
373 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
374 #endif
376 // An event filter that pre-handles all key events to send them to an IME.
377 scoped_ptr<aura::shared::InputMethodEventFilter> input_method_filter_;
379 // An event filter that silently keeps track of all touch events and controls
380 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
381 scoped_ptr<internal::TouchObserverHUD> touch_observer_hud_;
383 // The shelf for managing the launcher and the status widget in non-compact
384 // mode. Shell does not own the shelf. Instead, it is owned by container of
385 // the status area.
386 internal::ShelfLayoutManager* shelf_;
388 // Manages layout of panels. Owned by PanelContainer.
389 internal::PanelLayoutManager* panel_layout_manager_;
391 ObserverList<ShellObserver> observers_;
393 // Owned by aura::RootWindow, cached here for type safety.
394 internal::RootWindowLayoutManager* root_window_layout_;
396 // System tray with clock, Wi-Fi signal, etc.
397 scoped_ptr<SystemTray> tray_;
399 // Used by ash/shell.
400 content::BrowserContext* browser_context_;
402 DISALLOW_COPY_AND_ASSIGN(Shell);
405 } // namespace ash
407 #endif // ASH_SHELL_H_