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/shelf/shelf_types.h"
13 #include "ash/system/user/login_status.h"
14 #include "ash/wm/system_modal_container_event_filter_delegate.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/client/activation_change_observer.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"
25 #include "ui/views/corewm/cursor_manager.h"
34 class ActivationClient
;
36 class UserActionClient
;
40 class OutputConfigurator
;
55 class NonClientFrameView
;
58 class CompoundEventFilter
;
59 class InputMethodEventFilter
;
60 class ShadowController
;
61 class TooltipController
;
62 class VisibilityController
;
63 class WindowModalityController
;
69 class AcceleratorController
;
70 class AshNativeCursorManager
;
71 class CapsLockDelegate
;
72 class DesktopBackgroundController
;
73 class DisplayController
;
74 class HighContrastController
;
76 class LauncherDelegate
;
78 class MagnificationController
;
79 class NestedDispatcherController
;
80 class PartialMagnificationController
;
81 class PowerButtonController
;
82 class RootWindowHostFactory
;
84 class SessionStateController
;
88 class SystemTrayDelegate
;
89 class SystemTrayNotifier
;
90 class UserActivityDetector
;
91 class UserWallpaperDelegate
;
93 class WebNotificationTray
;
94 class WindowCycleController
;
97 class AcceleratorFilter
;
98 class ActivationController
;
99 class AppListController
;
100 class CaptureController
;
101 class DisplayChangeObserverX11
;
102 class DisplayErrorObserver
;
103 class DisplayManager
;
104 class DragDropController
;
105 class EventClientImpl
;
106 class EventRewriterEventFilter
;
107 class EventTransformationHandler
;
109 class MouseCursorEventFilter
;
110 class OutputConfiguratorAnimation
;
111 class OverlayEventFilter
;
112 class ResizeShadowController
;
113 class RootWindowController
;
114 class RootWindowLayoutManager
;
115 class ScreenPositionController
;
116 class SlowAnimationEventFilter
;
117 class StatusAreaWidget
;
118 class SystemGestureEventFilter
;
119 class SystemModalContainerEventFilter
;
120 class TouchObserverHUD
;
121 class WorkspaceController
;
132 // Shell is a singleton object that presents the Shell API and implements the
133 // RootWindow's delegate interface.
135 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
136 // takes ownership of the Shell.
137 class ASH_EXPORT Shell
138 : public internal::SystemModalContainerEventFilterDelegate
,
139 public ui::EventTarget
,
140 public aura::client::ActivationChangeObserver
{
142 typedef std::vector
<aura::RootWindow
*> RootWindowList
;
143 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
150 // A shell must be explicitly created so that it can call |Init()| with the
151 // delegate set. |delegate| can be NULL (if not required for initialization).
152 static Shell
* CreateInstance(ShellDelegate
* delegate
);
154 // Should never be called before |CreateInstance()|.
155 static Shell
* GetInstance();
157 // Returns true if the ash shell has been instantiated.
158 static bool HasInstance();
160 static void DeleteInstance();
162 // Returns the root window controller for the primary root window.
163 // TODO(oshima): move this to |RootWindowController|
164 static internal::RootWindowController
* GetPrimaryRootWindowController();
166 // Returns all root window controllers.
167 // TODO(oshima): move this to |RootWindowController|
168 static RootWindowControllerList
GetAllRootWindowControllers();
170 // Returns the primary RootWindow. The primary RootWindow is the one
171 // that has a launcher.
172 static aura::RootWindow
* GetPrimaryRootWindow();
174 // Returns the active RootWindow. The active RootWindow is the one that
175 // contains the current active window as a decendant child. The active
176 // RootWindow remains the same even when the active window becomes NULL,
177 // until the another window who has a different root window becomes active.
178 static aura::RootWindow
* GetActiveRootWindow();
180 // Returns the global Screen object that's always active in ash.
181 static gfx::Screen
* GetScreen();
183 // Returns all root windows.
184 static RootWindowList
GetAllRootWindows();
186 static aura::Window
* GetContainer(aura::RootWindow
* root_window
,
188 static const aura::Window
* GetContainer(const aura::RootWindow
* root_window
,
191 // Returns the list of containers that match |container_id| in
192 // all root windows. If |priority_root| is given, the container
193 // in the |priority_root| will be inserted at the top of the list.
194 static std::vector
<aura::Window
*> GetContainersFromAllRootWindows(
196 aura::RootWindow
* priority_root
);
198 // True if "launcher per display" feature is enabled.
199 static bool IsLauncherPerDisplayEnabled();
201 void set_active_root_window(aura::RootWindow
* active_root_window
) {
202 active_root_window_
= active_root_window
;
205 // Shows the context menu for the background and launcher at
206 // |location_in_screen| (in screen coordinates).
207 void ShowContextMenu(const gfx::Point
& location_in_screen
);
209 // Toggles the app list. |window| specifies in which display the app
210 // list should be shown. If this is NULL, the active root window
212 void ToggleAppList(aura::Window
* anchor
);
214 // Returns app list target visibility.
215 bool GetAppListTargetVisibility() const;
217 // Returns app list window or NULL if it is not visible.
218 aura::Window
* GetAppListWindow();
220 // Returns true if a user is logged in whose session can be locked (i.e. the
221 // user has a password with which to unlock the session).
222 bool CanLockScreen();
224 // Returns true if the screen is locked.
225 bool IsScreenLocked() const;
227 // Returns true if a system-modal dialog window is currently open.
228 bool IsSystemModalWindowOpen() const;
230 // For testing only: set simulation that a modal window is open
231 void SimulateModalWindowOpenForTesting(bool modal_window_open
) {
232 simulate_modal_window_open_for_testing_
= modal_window_open
;
235 // Creates a default views::NonClientFrameView for use by windows in the
237 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
238 views::Widget
* widget
);
240 // Rotates focus through containers that can receive focus.
241 void RotateFocus(Direction direction
);
243 // Sets the work area insets of the display that contains |window|,
244 // this notifies observers too.
245 // TODO(sky): this no longer really replicates what happens and is unreliable.
247 void SetDisplayWorkAreaInsets(aura::Window
* window
,
248 const gfx::Insets
& insets
);
250 // Called when the user logs in.
251 void OnLoginStateChanged(user::LoginStatus status
);
253 // Called when the login status changes.
254 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
255 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
257 // Called when the application is exiting.
258 void OnAppTerminating();
260 // Called when the screen is locked (after the lock window is visible) or
262 void OnLockStateChanged(bool locked
);
264 // Initializes |launcher_|. Does nothing if it's already initialized.
265 void CreateLauncher();
267 // Show launcher view if it was created hidden (before session has started).
270 // Adds/removes observer.
271 void AddShellObserver(ShellObserver
* observer
);
272 void RemoveShellObserver(ShellObserver
* observer
);
274 #if !defined(OS_MACOSX)
275 AcceleratorController
* accelerator_controller() {
276 return accelerator_controller_
.get();
278 #endif // !defined(OS_MACOSX)
280 internal::DisplayManager
* display_manager() {
281 return display_manager_
.get();
283 views::corewm::CompoundEventFilter
* env_filter() {
284 return env_filter_
.get();
286 views::corewm::TooltipController
* tooltip_controller() {
287 return tooltip_controller_
.get();
289 internal::TouchObserverHUD
* touch_observer_hud() {
290 return touch_observer_hud_
.get();
292 internal::EventRewriterEventFilter
* event_rewriter_filter() {
293 return event_rewriter_filter_
.get();
295 internal::OverlayEventFilter
* overlay_filter() {
296 return overlay_filter_
.get();
298 DesktopBackgroundController
* desktop_background_controller() {
299 return desktop_background_controller_
.get();
301 PowerButtonController
* power_button_controller() {
302 return power_button_controller_
.get();
304 SessionStateController
* session_state_controller() {
305 return session_state_controller_
.get();
307 UserActivityDetector
* user_activity_detector() {
308 return user_activity_detector_
.get();
310 VideoDetector
* video_detector() {
311 return video_detector_
.get();
313 WindowCycleController
* window_cycle_controller() {
314 return window_cycle_controller_
.get();
316 internal::FocusCycler
* focus_cycler() {
317 return focus_cycler_
.get();
319 DisplayController
* display_controller() {
320 return display_controller_
.get();
322 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
323 return mouse_cursor_filter_
.get();
325 internal::EventTransformationHandler
* event_transformation_handler() {
326 return event_transformation_handler_
.get();
328 views::corewm::CursorManager
* cursor_manager() { return &cursor_manager_
; }
330 ShellDelegate
* delegate() { return delegate_
.get(); }
332 UserWallpaperDelegate
* user_wallpaper_delegate() {
333 return user_wallpaper_delegate_
.get();
336 CapsLockDelegate
* caps_lock_delegate() {
337 return caps_lock_delegate_
.get();
340 HighContrastController
* high_contrast_controller() {
341 return high_contrast_controller_
.get();
344 MagnificationController
* magnification_controller() {
345 return magnification_controller_
.get();
348 PartialMagnificationController
* partial_magnification_controller() {
349 return partial_magnification_controller_
.get();
351 aura::client::ActivationClient
* activation_client() {
352 return activation_client_
;
355 ScreenAsh
* screen() { return screen_
; }
357 // Force the shelf to query for it's current visibility state.
358 void UpdateShelfVisibility();
360 // TODO(oshima): Define an interface to access shelf/launcher
361 // state, or just use Launcher.
363 // Sets/gets the shelf auto-hide behavior on |root_window|.
364 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
,
365 aura::RootWindow
* root_window
);
366 ShelfAutoHideBehavior
GetShelfAutoHideBehavior(
367 aura::RootWindow
* root_window
) const;
369 // Sets/gets shelf's alignment on |root_window|.
370 void SetShelfAlignment(ShelfAlignment alignment
,
371 aura::RootWindow
* root_window
);
372 ShelfAlignment
GetShelfAlignment(aura::RootWindow
* root_window
);
374 // Dims or undims the screen.
375 void SetDimming(bool should_dim
);
377 // Creates a modal background (a partially-opaque fullscreen window)
378 // on all displays for |window|.
379 void CreateModalBackground(aura::Window
* window
);
381 // Called when a modal window is removed. It will activate
382 // another modal window if any, or remove modal screens
384 void OnModalWindowRemoved(aura::Window
* removed
);
386 // Returns WebNotificationTray on the primary root window.
387 WebNotificationTray
* GetWebNotificationTray();
389 // Does the primary display have status area?
390 bool HasPrimaryStatusArea();
392 // Returns the system tray on primary display.
393 SystemTray
* GetPrimarySystemTray();
395 SystemTrayDelegate
* system_tray_delegate() {
396 return system_tray_delegate_
.get();
399 SystemTrayNotifier
* system_tray_notifier() {
400 return system_tray_notifier_
.get();
403 static void set_initially_hide_cursor(bool hide
) {
404 initially_hide_cursor_
= hide
;
407 internal::ResizeShadowController
* resize_shadow_controller() {
408 return resize_shadow_controller_
.get();
411 // Made available for tests.
412 views::corewm::ShadowController
* shadow_controller() {
413 return shadow_controller_
.get();
416 content::BrowserContext
* browser_context() { return browser_context_
; }
417 void set_browser_context(content::BrowserContext
* browser_context
) {
418 browser_context_
= browser_context
;
421 // Initializes the root window to be used for a secondary display.
422 void InitRootWindowForSecondaryDisplay(aura::RootWindow
* root
);
424 // Starts the animation that occurs on first login.
425 void DoInitialWorkspaceAnimation();
427 #if defined(OS_CHROMEOS)
428 chromeos::OutputConfigurator
* output_configurator() {
429 return output_configurator_
.get();
431 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
432 return output_configurator_animation_
.get();
434 internal::DisplayErrorObserver
* display_error_observer() {
435 return display_error_observer_
.get();
437 #endif // defined(OS_CHROMEOS)
439 RootWindowHostFactory
* root_window_host_factory() {
440 return root_window_host_factory_
.get();
443 LauncherModel
* launcher_model() {
444 return launcher_model_
.get();
447 // Returns the launcher delegate, creating if necesary.
448 LauncherDelegate
* GetLauncherDelegate();
451 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
452 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
453 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
454 friend class internal::RootWindowController
;
455 friend class test::ShellTestApi
;
456 friend class shell::WindowWatcher
;
458 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
460 explicit Shell(ShellDelegate
* delegate
);
465 // Initializes the root window and root window controller so that it
466 // can host browser windows.
467 void InitRootWindowController(internal::RootWindowController
* root
);
469 // Initializes the layout managers and event filters specific for
471 void InitLayoutManagersForPrimaryDisplay(
472 internal::RootWindowController
* root_window_controller
);
474 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
475 virtual bool CanWindowReceiveEvents(aura::Window
* window
) OVERRIDE
;
477 // Overridden from ui::EventTarget:
478 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
479 virtual EventTarget
* GetParentTarget() OVERRIDE
;
480 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
482 // Overridden from aura::client::ActivationChangeObserver:
483 virtual void OnWindowActivated(aura::Window
* gained_active
,
484 aura::Window
* lost_active
) OVERRIDE
;
486 static Shell
* instance_
;
488 // If set before the Shell is initialized, the mouse cursor will be hidden
489 // when the screen is initially created.
490 static bool initially_hide_cursor_
;
494 // Active root window. Never becomes NULL during the session.
495 aura::RootWindow
* active_root_window_
;
497 // The CompoundEventFilter owned by aura::Env object.
498 scoped_ptr
<views::corewm::CompoundEventFilter
> env_filter_
;
500 std::vector
<WindowAndBoundsPair
> to_restore_
;
502 #if !defined(OS_MACOSX)
503 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
505 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
506 #endif // !defined(OS_MACOSX)
508 scoped_ptr
<ShellDelegate
> delegate_
;
509 scoped_ptr
<SystemTrayDelegate
> system_tray_delegate_
;
510 scoped_ptr
<SystemTrayNotifier
> system_tray_notifier_
;
511 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
512 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
513 scoped_ptr
<LauncherDelegate
> launcher_delegate_
;
515 scoped_ptr
<LauncherModel
> launcher_model_
;
517 scoped_ptr
<internal::AppListController
> app_list_controller_
;
519 scoped_ptr
<internal::ActivationController
> activation_controller_
;
520 scoped_ptr
<internal::CaptureController
> capture_controller_
;
521 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
522 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
523 scoped_ptr
<views::corewm::ShadowController
> shadow_controller_
;
524 scoped_ptr
<views::corewm::VisibilityController
> visibility_controller_
;
525 scoped_ptr
<views::corewm::WindowModalityController
>
526 window_modality_controller_
;
527 scoped_ptr
<views::corewm::TooltipController
> tooltip_controller_
;
528 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
529 scoped_ptr
<PowerButtonController
> power_button_controller_
;
530 scoped_ptr
<SessionStateController
> session_state_controller_
;
531 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
532 scoped_ptr
<VideoDetector
> video_detector_
;
533 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
534 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
535 scoped_ptr
<DisplayController
> display_controller_
;
536 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
537 scoped_ptr
<MagnificationController
> magnification_controller_
;
538 scoped_ptr
<PartialMagnificationController
> partial_magnification_controller_
;
539 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
540 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
541 aura::client::ActivationClient
* activation_client_
;
542 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
543 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
544 scoped_ptr
<internal::SystemModalContainerEventFilter
> modality_filter_
;
545 scoped_ptr
<internal::EventClientImpl
> event_client_
;
546 scoped_ptr
<internal::EventTransformationHandler
>
547 event_transformation_handler_
;
548 scoped_ptr
<RootWindowHostFactory
> root_window_host_factory_
;
550 // An event filter that rewrites or drops an event.
551 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
553 // An event filter that pre-handles key events while the partial
554 // screenshot UI or the keyboard overlay is active.
555 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
557 // An event filter which handles system level gestures
558 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
560 #if !defined(OS_MACOSX)
561 // An event filter that pre-handles global accelerators.
562 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
565 // An event filter that pre-handles all key events to send them to an IME.
566 scoped_ptr
<views::corewm::InputMethodEventFilter
> input_method_filter_
;
568 // An event filter that silently keeps track of all touch events and controls
569 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
570 scoped_ptr
<internal::TouchObserverHUD
> touch_observer_hud_
;
572 scoped_ptr
<internal::DisplayManager
> display_manager_
;
574 #if defined(OS_CHROMEOS)
575 // Controls video output device state.
576 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
577 scoped_ptr
<internal::OutputConfiguratorAnimation
>
578 output_configurator_animation_
;
579 scoped_ptr
<internal::DisplayErrorObserver
> display_error_observer_
;
581 // Receives output change events and udpates the display manager.
582 scoped_ptr
<internal::DisplayChangeObserverX11
> display_change_observer_
;
583 #endif // defined(OS_CHROMEOS)
585 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
586 // pointer to vend to test code.
587 AshNativeCursorManager
* native_cursor_manager_
;
588 views::corewm::CursorManager cursor_manager_
;
590 ObserverList
<ShellObserver
> observers_
;
592 // Used by ash/shell.
593 content::BrowserContext
* browser_context_
;
595 // For testing only: simulate that a modal window is open
596 bool simulate_modal_window_open_for_testing_
;
598 DISALLOW_COPY_AND_ASSIGN(Shell
);
603 #endif // ASH_SHELL_H_