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.
11 #include "ash/ash_export.h"
12 #include "ash/system/user/login_status.h"
13 #include "ash/wm/cursor_delegate.h"
14 #include "ash/wm/cursor_manager.h"
15 #include "ash/wm/shelf_types.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/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 CapsLockDelegate
;
63 class DesktopBackgroundController
;
64 class DisplayController
;
65 class HighContrastController
;
67 class NestedDispatcherController
;
68 class PowerButtonController
;
72 class SystemTrayDelegate
;
74 class UserActivityDetector
;
75 class UserWallpaperDelegate
;
77 class WindowCycleController
;
80 class AcceleratorFilter
;
81 class ActivationController
;
82 class AppListController
;
83 class CaptureController
;
84 class DragDropController
;
85 class EventRewriterEventFilter
;
87 class MagnificationController
;
88 class MouseCursorEventFilter
;
89 class OutputConfiguratorAnimation
;
90 class OverlayEventFilter
;
91 class PanelLayoutManager
;
92 class ResizeShadowController
;
93 class RootWindowController
;
94 class RootWindowLayoutManager
;
95 class ScreenPositionController
;
96 class ShadowController
;
97 class ShelfLayoutManager
;
98 class ShellContextMenu
;
99 class SlowAnimationEventFilter
;
100 class StackingController
;
101 class StatusAreaWidget
;
102 class SystemGestureEventFilter
;
103 class TooltipController
;
104 class TouchObserverHUD
;
105 class VisibilityController
;
106 class WindowModalityController
;
107 class WorkspaceController
;
110 // Shell is a singleton object that presents the Shell API and implements the
111 // RootWindow's delegate interface.
113 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
114 // takes ownership of the Shell.
115 class ASH_EXPORT Shell
: ash::CursorDelegate
{
117 typedef std::vector
<aura::RootWindow
*> RootWindowList
;
118 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
125 // Accesses private data from a Shell for testing.
126 class ASH_EXPORT TestApi
{
128 explicit TestApi(Shell
* shell
);
130 internal::RootWindowLayoutManager
* root_window_layout();
131 aura::shared::InputMethodEventFilter
* input_method_event_filter();
132 internal::SystemGestureEventFilter
* system_gesture_event_filter();
133 internal::WorkspaceController
* workspace_controller();
134 internal::ScreenPositionController
* screen_position_controller();
137 Shell
* shell_
; // not owned
139 DISALLOW_COPY_AND_ASSIGN(TestApi
);
142 // A shell must be explicitly created so that it can call |Init()| with the
143 // delegate set. |delegate| can be NULL (if not required for initialization).
144 static Shell
* CreateInstance(ShellDelegate
* delegate
);
146 // Should never be called before |CreateInstance()|.
147 static Shell
* GetInstance();
149 // Returns true if the ash shell has been instantiated.
150 static bool HasInstance();
152 static void DeleteInstance();
154 // Returns the root window controller for the primary root window.
155 static internal::RootWindowController
* GetPrimaryRootWindowController();
157 // Returns all root window controllers.
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 all root windows.
171 static RootWindowList
GetAllRootWindows();
173 static aura::Window
* GetContainer(aura::RootWindow
* root_window
,
176 // Returns the list of containers that match |container_id| in
178 static std::vector
<aura::Window
*> GetAllContainers(int container_id
);
180 void set_active_root_window(aura::RootWindow
* active_root_window
) {
181 active_root_window_
= active_root_window
;
184 // Adds or removes |filter| from the aura::Env's CompoundEventFilter.
185 void AddEnvEventFilter(aura::EventFilter
* filter
);
186 void RemoveEnvEventFilter(aura::EventFilter
* filter
);
187 size_t GetEnvEventFilterCount() const;
189 // Shows the background menu over |widget|.
190 void ShowBackgroundMenu(views::Widget
* widget
, const gfx::Point
& location
);
193 void ToggleAppList();
195 // Returns app list target visibility.
196 bool GetAppListTargetVisibility() const;
198 // Returns app list window or NULL if it is not visible.
199 aura::Window
* GetAppListWindow();
201 // Returns true if the screen is locked.
202 bool IsScreenLocked() const;
204 // Returns true if a modal dialog window is currently open.
205 bool IsModalWindowOpen() const;
207 // Creates a default views::NonClientFrameView for use by windows in the
209 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
210 views::Widget
* widget
);
212 // Rotates focus through containers that can receive focus.
213 void RotateFocus(Direction direction
);
215 // Sets the work area insets of the display that contains |window|,
216 // this notifies observers too.
217 // TODO(sky): this no longer really replicates what happens and is unreliable.
219 void SetDisplayWorkAreaInsets(aura::Window
* window
,
220 const gfx::Insets
& insets
);
222 // Called when the user logs in.
223 void OnLoginStateChanged(user::LoginStatus status
);
225 // Called when the application is exiting.
226 void OnAppTerminating();
228 // Called when the screen is locked (after the lock window is visible) or
230 void OnLockStateChanged(bool locked
);
232 // Initializes |launcher_|. Does nothing if it's already initialized.
233 void CreateLauncher();
235 // Show launcher view if it was created hidden (before session has started).
238 // Adds/removes observer.
239 void AddShellObserver(ShellObserver
* observer
);
240 void RemoveShellObserver(ShellObserver
* observer
);
242 #if !defined(OS_MACOSX)
243 AcceleratorController
* accelerator_controller() {
244 return accelerator_controller_
.get();
246 #endif // !defined(OS_MACOSX)
248 aura::shared::CompoundEventFilter
* env_filter() {
251 internal::TooltipController
* tooltip_controller() {
252 return tooltip_controller_
.get();
254 internal::EventRewriterEventFilter
* event_rewriter_filter() {
255 return event_rewriter_filter_
.get();
257 internal::OverlayEventFilter
* overlay_filter() {
258 return overlay_filter_
.get();
260 DesktopBackgroundController
* desktop_background_controller() {
261 return desktop_background_controller_
.get();
263 PowerButtonController
* power_button_controller() {
264 return power_button_controller_
.get();
266 UserActivityDetector
* user_activity_detector() {
267 return user_activity_detector_
.get();
269 VideoDetector
* video_detector() {
270 return video_detector_
.get();
272 WindowCycleController
* window_cycle_controller() {
273 return window_cycle_controller_
.get();
275 internal::FocusCycler
* focus_cycler() {
276 return focus_cycler_
.get();
278 DisplayController
* display_controller() {
279 return display_controller_
.get();
281 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
282 return mouse_cursor_filter_
.get();
284 CursorManager
* cursor_manager() { return &cursor_manager_
; }
286 ShellDelegate
* delegate() { return delegate_
.get(); }
288 UserWallpaperDelegate
* user_wallpaper_delegate() {
289 return user_wallpaper_delegate_
.get();
292 CapsLockDelegate
* caps_lock_delegate() {
293 return caps_lock_delegate_
.get();
296 HighContrastController
* high_contrast_controller() {
297 return high_contrast_controller_
.get();
300 internal::MagnificationController
* magnification_controller() {
301 return magnification_controller_
.get();
304 Launcher
* launcher() { return launcher_
.get(); }
306 const ScreenAsh
* screen() { return screen_
; }
308 // Force the shelf to query for it's current visibility state.
309 void UpdateShelfVisibility();
311 // Sets/gets the shelf auto-hide behavior.
312 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
);
313 ShelfAutoHideBehavior
GetShelfAutoHideBehavior() const;
315 void SetShelfAlignment(ShelfAlignment alignment
);
316 ShelfAlignment
GetShelfAlignment();
318 // Dims or undims the screen.
319 void SetDimming(bool should_dim
);
321 // TODO(sky): don't expose this!
322 internal::ShelfLayoutManager
* shelf() const { return shelf_
; }
324 internal::StatusAreaWidget
* status_area_widget() const {
325 return status_area_widget_
;
328 // Convenience accessor for members of StatusAreaWidget.
329 SystemTrayDelegate
* tray_delegate();
330 SystemTray
* system_tray();
332 static void set_initially_hide_cursor(bool hide
) {
333 initially_hide_cursor_
= hide
;
336 internal::ResizeShadowController
* resize_shadow_controller() {
337 return resize_shadow_controller_
.get();
340 // Made available for tests.
341 internal::ShadowController
* shadow_controller() {
342 return shadow_controller_
.get();
345 content::BrowserContext
* browser_context() { return browser_context_
; }
346 void set_browser_context(content::BrowserContext
* browser_context
) {
347 browser_context_
= browser_context
;
350 // Initializes the root window to be used for a secondary display.
351 void InitRootWindowForSecondaryDisplay(aura::RootWindow
* root
);
353 // Starts the animation that occurs on first login.
354 void DoInitialWorkspaceAnimation();
356 #if defined(OS_CHROMEOS)
357 chromeos::OutputConfigurator
* output_configurator() {
358 return output_configurator_
.get();
360 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
361 return output_configurator_animation_
.get();
363 #endif // defined(OS_CHROMEOS)
366 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
367 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
368 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
369 friend class internal::RootWindowController
;
371 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
373 explicit Shell(ShellDelegate
* delegate
);
378 // Initializes the root window and root window controller so that it
379 // can host browser windows.
380 void InitRootWindowController(internal::RootWindowController
* root
);
382 // Initializes the layout managers and event filters specific for
384 void InitLayoutManagersForPrimaryDisplay(
385 internal::RootWindowController
* root_window_controller
);
387 // aura::CursorManager::Delegate overrides:
388 virtual void SetCursor(gfx::NativeCursor cursor
) OVERRIDE
;
389 virtual void ShowCursor(bool visible
) OVERRIDE
;
391 static Shell
* instance_
;
393 // If set before the Shell is initialized, the mouse cursor will be hidden
394 // when the screen is initially created.
395 static bool initially_hide_cursor_
;
399 // Active root window. Never becomes NULL during the session.
400 aura::RootWindow
* active_root_window_
;
402 // The CompoundEventFilter owned by aura::Env object.
403 aura::shared::CompoundEventFilter
* env_filter_
;
405 std::vector
<WindowAndBoundsPair
> to_restore_
;
407 #if !defined(OS_MACOSX)
408 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
410 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
411 #endif // !defined(OS_MACOSX)
413 scoped_ptr
<ShellDelegate
> delegate_
;
414 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
415 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
417 scoped_ptr
<Launcher
> launcher_
;
419 scoped_ptr
<internal::AppListController
> app_list_controller_
;
421 scoped_ptr
<internal::ShellContextMenu
> shell_context_menu_
;
422 scoped_ptr
<internal::StackingController
> stacking_controller_
;
423 scoped_ptr
<internal::ActivationController
> activation_controller_
;
424 scoped_ptr
<internal::CaptureController
> capture_controller_
;
425 scoped_ptr
<internal::WindowModalityController
> window_modality_controller_
;
426 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
427 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
428 scoped_ptr
<internal::ShadowController
> shadow_controller_
;
429 scoped_ptr
<internal::TooltipController
> tooltip_controller_
;
430 scoped_ptr
<internal::VisibilityController
> visibility_controller_
;
431 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
432 scoped_ptr
<PowerButtonController
> power_button_controller_
;
433 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
434 scoped_ptr
<VideoDetector
> video_detector_
;
435 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
436 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
437 scoped_ptr
<DisplayController
> display_controller_
;
438 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
439 scoped_ptr
<internal::MagnificationController
> magnification_controller_
;
440 scoped_ptr
<aura::FocusManager
> focus_manager_
;
441 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
442 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
443 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
445 // An event filter that rewrites or drops an event.
446 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
448 // An event filter that pre-handles key events while the partial
449 // screenshot UI or the keyboard overlay is active.
450 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
452 // An event filter which handles system level gestures
453 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
455 #if !defined(OS_MACOSX)
456 // An event filter that pre-handles global accelerators.
457 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
460 // An event filter that pre-handles all key events to send them to an IME.
461 scoped_ptr
<aura::shared::InputMethodEventFilter
> input_method_filter_
;
463 // An event filter that silently keeps track of all touch events and controls
464 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
465 scoped_ptr
<internal::TouchObserverHUD
> touch_observer_hud_
;
467 #if defined(OS_CHROMEOS)
468 // Controls video output device state.
469 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
470 scoped_ptr
<internal::OutputConfiguratorAnimation
>
471 output_configurator_animation_
;
472 #endif // defined(OS_CHROMEOS)
474 CursorManager cursor_manager_
;
476 // The shelf for managing the launcher and the status widget in non-compact
477 // mode. Shell does not own the shelf. Instead, it is owned by container of
479 internal::ShelfLayoutManager
* shelf_
;
481 // Manages layout of panels. Owned by PanelContainer.
482 internal::PanelLayoutManager
* panel_layout_manager_
;
484 ObserverList
<ShellObserver
> observers_
;
486 // Widget containing system tray.
487 internal::StatusAreaWidget
* status_area_widget_
;
489 // Used by ash/shell.
490 content::BrowserContext
* browser_context_
;
492 DISALLOW_COPY_AND_ASSIGN(Shell
);
497 #endif // ASH_SHELL_H_