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.
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/aura/cursor_delegate.h"
21 #include "ui/gfx/insets.h"
22 #include "ui/gfx/size.h"
32 class UserActionClient
;
35 class CompoundEventFilter
;
36 class InputMethodEventFilter
;
40 class OutputConfigurator
;
55 class NonClientFrameView
;
61 class AcceleratorController
;
62 class DesktopBackgroundController
;
63 class HighContrastController
;
65 class NestedDispatcherController
;
66 class PowerButtonController
;
70 class SystemTrayDelegate
;
72 class UserActivityDetector
;
73 class UserWallpaperDelegate
;
75 class WindowCycleController
;
78 class AcceleratorFilter
;
79 class ActivationController
;
80 class AppListController
;
81 class CaptureController
;
82 class DragDropController
;
83 class EventClientImpl
;
85 class KeyRewriterEventFilter
;
86 class MagnificationController
;
87 class MonitorController
;
88 class PanelLayoutManager
;
89 class PartialScreenshotEventFilter
;
90 class ResizeShadowController
;
91 class RootWindowLayoutManager
;
93 class ShadowController
;
94 class ShelfLayoutManager
;
95 class ShellContextMenu
;
96 class SlowAnimationEventFilter
;
97 class SystemGestureEventFilter
;
98 class StackingController
;
99 class StatusAreaWidget
;
100 class TooltipController
;
101 class TouchObserverHUD
;
102 class VisibilityController
;
103 class WindowModalityController
;
104 class WorkspaceController
;
107 // Shell is a singleton object that presents the Shell API and implements the
108 // RootWindow's delegate interface.
110 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
111 // takes ownership of the Shell.
112 class ASH_EXPORT Shell
: aura::CursorDelegate
{
119 // Accesses private data from a Shell for testing.
120 class ASH_EXPORT TestApi
{
122 explicit TestApi(Shell
* shell
);
124 internal::RootWindowLayoutManager
* root_window_layout();
125 aura::shared::InputMethodEventFilter
* input_method_event_filter();
126 internal::SystemGestureEventFilter
* system_gesture_event_filter();
127 internal::WorkspaceController
* workspace_controller();
130 Shell
* shell_
; // not owned
132 DISALLOW_COPY_AND_ASSIGN(TestApi
);
135 // A shell must be explicitly created so that it can call |Init()| with the
136 // delegate set. |delegate| can be NULL (if not required for initialization).
137 static Shell
* CreateInstance(ShellDelegate
* delegate
);
139 // Should never be called before |CreateInstance()|.
140 static Shell
* GetInstance();
142 // Returns true if the ash shell has been instantiated.
143 static bool HasInstance();
145 static void DeleteInstance();
147 // Gets the primary RootWindow. The primary RootWindow is the one
148 // that has a launcher.
149 static aura::RootWindow
* GetPrimaryRootWindow();
151 // Gets the active RootWindow. The active RootWindow is the one that
152 // contains the current active window as a decendant child. The active
153 // RootWindow remains the same even when the active window becomes NULL,
154 // until the another window who has a different root window becomes active.
155 static aura::RootWindow
* GetActiveRootWindow();
157 // Gets the RootWindow at |point| in the virtual screen coordinates.
158 // Returns NULL if the root window does not exist at the given
160 static aura::RootWindow
* GetRootWindowAt(const gfx::Point
& point
);
162 static aura::Window
* GetContainer(aura::RootWindow
* root_window
,
165 // Returns the list of containers that match |container_id| in
167 static std::vector
<aura::Window
*> GetAllContainers(int container_id
);
169 void set_active_root_window(aura::RootWindow
* active_root_window
) {
170 active_root_window_
= active_root_window
;
173 internal::RootWindowLayoutManager
* root_window_layout() const {
174 return root_window_layout_
;
177 // Adds or removes |filter| from the aura::Env's CompoundEventFilter.
178 void AddEnvEventFilter(aura::EventFilter
* filter
);
179 void RemoveEnvEventFilter(aura::EventFilter
* filter
);
180 size_t GetEnvEventFilterCount() const;
182 // Shows the background menu over |widget|.
183 void ShowBackgroundMenu(views::Widget
* widget
, const gfx::Point
& location
);
186 void ToggleAppList();
188 // Returns app list target visibility.
189 bool GetAppListTargetVisibility() const;
191 // Returns app list window or NULL if it is not visible.
192 aura::Window
* GetAppListWindow();
194 // Returns true if the screen is locked.
195 bool IsScreenLocked() const;
197 // Returns true if a modal dialog window is currently open.
198 bool IsModalWindowOpen() const;
200 // Creates a default views::NonClientFrameView for use by windows in the
202 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
203 views::Widget
* widget
);
205 // Rotates focus through containers that can receive focus.
206 void RotateFocus(Direction direction
);
208 // Sets the work area insets of the monitor that contains |window|,
209 // this notifies observers too.
210 // TODO(sky): this no longer really replicates what happens and is unreliable.
212 void SetMonitorWorkAreaInsets(aura::Window
* window
,
213 const gfx::Insets
& insets
);
215 // Called when the user logs in.
216 void OnLoginStateChanged(user::LoginStatus status
);
218 // Called when the application is exiting.
219 void OnAppTerminating();
221 // Called when the screen is locked (after the lock window is visible) or
223 void OnLockStateChanged(bool locked
);
225 // Initializes |launcher_|. Does nothing if it's already initialized.
226 void CreateLauncher();
228 // Adds/removes observer.
229 void AddShellObserver(ShellObserver
* observer
);
230 void RemoveShellObserver(ShellObserver
* observer
);
232 #if !defined(OS_MACOSX)
233 AcceleratorController
* accelerator_controller() {
234 return accelerator_controller_
.get();
236 #endif // !defined(OS_MACOSX)
238 aura::shared::CompoundEventFilter
* env_filter() {
241 internal::TooltipController
* tooltip_controller() {
242 return tooltip_controller_
.get();
244 internal::KeyRewriterEventFilter
* key_rewriter_filter() {
245 return key_rewriter_filter_
.get();
247 internal::PartialScreenshotEventFilter
* partial_screenshot_filter() {
248 return partial_screenshot_filter_
.get();
250 DesktopBackgroundController
* desktop_background_controller() {
251 return desktop_background_controller_
.get();
253 PowerButtonController
* power_button_controller() {
254 return power_button_controller_
.get();
256 UserActivityDetector
* user_activity_detector() {
257 return user_activity_detector_
.get();
259 VideoDetector
* video_detector() {
260 return video_detector_
.get();
262 WindowCycleController
* window_cycle_controller() {
263 return window_cycle_controller_
.get();
265 internal::FocusCycler
* focus_cycler() {
266 return focus_cycler_
.get();
268 internal::MonitorController
* monitor_controller() {
269 return monitor_controller_
.get();
272 ShellDelegate
* delegate() { return delegate_
.get(); }
274 UserWallpaperDelegate
* user_wallpaper_delegate() {
275 return user_wallpaper_delegate_
.get();
278 HighContrastController
* high_contrast_controller() {
279 return high_contrast_controller_
.get();
282 internal::MagnificationController
* magnification_controller() {
283 return magnification_controller_
.get();
286 internal::ScreenDimmer
* screen_dimmer() {
287 return screen_dimmer_
.get();
290 Launcher
* launcher() { return launcher_
.get(); }
292 const ScreenAsh
* screen() { return screen_
; }
294 // Force the shelf to query for it's current visibility state.
295 void UpdateShelfVisibility();
297 // Sets/gets the shelf auto-hide behavior.
298 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
);
299 ShelfAutoHideBehavior
GetShelfAutoHideBehavior() const;
301 void SetShelfAlignment(ShelfAlignment alignment
);
302 ShelfAlignment
GetShelfAlignment();
304 // TODO(sky): don't expose this!
305 internal::ShelfLayoutManager
* shelf() const { return shelf_
; }
307 internal::StatusAreaWidget
* status_area_widget() const {
308 return status_area_widget_
;
311 // Convenience accessor for members of StatusAreaWidget.
312 SystemTrayDelegate
* tray_delegate();
313 SystemTray
* system_tray();
315 // Returns the size of the grid.
316 int GetGridSize() const;
318 // Returns true if in maximized or fullscreen mode.
319 bool IsInMaximizedMode() const;
321 static void set_initially_hide_cursor(bool hide
) {
322 initially_hide_cursor_
= hide
;
325 internal::ResizeShadowController
* resize_shadow_controller() {
326 return resize_shadow_controller_
.get();
329 // Made available for tests.
330 internal::ShadowController
* shadow_controller() {
331 return shadow_controller_
.get();
334 content::BrowserContext
* browser_context() { return browser_context_
; }
335 void set_browser_context(content::BrowserContext
* browser_context
) {
336 browser_context_
= browser_context
;
339 // Initialize the root window to be used for a secondary monitor.
340 void InitRootWindowForSecondaryMonitor(aura::RootWindow
* root
);
342 #if defined(OS_CHROMEOS)
343 chromeos::OutputConfigurator
* output_configurator() {
344 return output_configurator_
.get();
346 #endif // defined(OS_CHROMEOS)
349 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
350 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
352 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
354 explicit Shell(ShellDelegate
* delegate
);
359 // Initializes the layout managers and event filters.
360 void InitLayoutManagers();
362 // Disables the workspace grid layout.
363 void DisableWorkspaceGridLayout();
365 // aura::CursorManager::Delegate overrides:
366 virtual void SetCursor(gfx::NativeCursor cursor
) OVERRIDE
;
367 virtual void ShowCursor(bool visible
) OVERRIDE
;
369 static Shell
* instance_
;
371 // If set before the Shell is initialized, the mouse cursor will be hidden
372 // when the screen is initially created.
373 static bool initially_hide_cursor_
;
375 scoped_ptr
<aura::RootWindow
> root_window_
;
378 // Active root window. Never become NULL.
379 aura::RootWindow
* active_root_window_
;
381 // The CompoundEventFilter owned by aura::Env object.
382 aura::shared::CompoundEventFilter
* env_filter_
;
384 std::vector
<WindowAndBoundsPair
> to_restore_
;
386 #if !defined(OS_MACOSX)
387 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
389 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
390 #endif // !defined(OS_MACOSX)
392 scoped_ptr
<ShellDelegate
> delegate_
;
393 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
395 scoped_ptr
<Launcher
> launcher_
;
397 scoped_ptr
<internal::AppListController
> app_list_controller_
;
399 scoped_ptr
<internal::ShellContextMenu
> shell_context_menu_
;
400 scoped_ptr
<internal::StackingController
> stacking_controller_
;
401 scoped_ptr
<internal::ActivationController
> activation_controller_
;
402 scoped_ptr
<internal::CaptureController
> capture_controller_
;
403 scoped_ptr
<internal::WindowModalityController
> window_modality_controller_
;
404 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
405 scoped_ptr
<internal::WorkspaceController
> workspace_controller_
;
406 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
407 scoped_ptr
<internal::ShadowController
> shadow_controller_
;
408 scoped_ptr
<internal::TooltipController
> tooltip_controller_
;
409 scoped_ptr
<internal::VisibilityController
> visibility_controller_
;
410 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
411 scoped_ptr
<PowerButtonController
> power_button_controller_
;
412 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
413 scoped_ptr
<VideoDetector
> video_detector_
;
414 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
415 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
416 scoped_ptr
<internal::EventClientImpl
> event_client_
;
417 scoped_ptr
<internal::MonitorController
> monitor_controller_
;
418 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
419 scoped_ptr
<internal::MagnificationController
> magnification_controller_
;
420 scoped_ptr
<internal::ScreenDimmer
> screen_dimmer_
;
421 scoped_ptr
<aura::FocusManager
> focus_manager_
;
422 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
424 // An event filter that rewrites or drops a key event.
425 scoped_ptr
<internal::KeyRewriterEventFilter
> key_rewriter_filter_
;
427 // An event filter that pre-handles key events while the partial
428 // screenshot UI is active.
429 scoped_ptr
<internal::PartialScreenshotEventFilter
> partial_screenshot_filter_
;
431 // An event filter which handles system level gestures
432 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
434 #if !defined(OS_MACOSX)
435 // An event filter that pre-handles global accelerators.
436 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
439 // An event filter that pre-handles all key events to send them to an IME.
440 scoped_ptr
<aura::shared::InputMethodEventFilter
> input_method_filter_
;
442 // An event filter that silently keeps track of all touch events and controls
443 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
444 scoped_ptr
<internal::TouchObserverHUD
> touch_observer_hud_
;
446 // An event filter that looks for modifier keypresses and triggers a slowdown
447 // of layer animations for visual debugging.
448 scoped_ptr
<internal::SlowAnimationEventFilter
> slow_animation_filter_
;
450 #if defined(OS_CHROMEOS)
451 // Controls video output device state.
452 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
453 #endif // defined(OS_CHROMEOS)
455 // The shelf for managing the launcher and the status widget in non-compact
456 // mode. Shell does not own the shelf. Instead, it is owned by container of
458 internal::ShelfLayoutManager
* shelf_
;
460 // Manages layout of panels. Owned by PanelContainer.
461 internal::PanelLayoutManager
* panel_layout_manager_
;
463 ObserverList
<ShellObserver
> observers_
;
465 // Owned by aura::RootWindow, cached here for type safety.
466 internal::RootWindowLayoutManager
* root_window_layout_
;
468 // Widget containing system tray.
469 internal::StatusAreaWidget
* status_area_widget_
;
471 // Used by ash/shell.
472 content::BrowserContext
* browser_context_
;
474 DISALLOW_COPY_AND_ASSIGN(Shell
);
479 #endif // ASH_SHELL_H_