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_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/aura/client/activation_change_observer.h"
22 #include "ui/base/events/event_target.h"
23 #include "ui/gfx/insets.h"
24 #include "ui/gfx/screen.h"
25 #include "ui/gfx/size.h"
34 class ActivationClient
;
36 class UserActionClient
;
40 class OutputConfigurator
;
55 class NonClientFrameView
;
58 class CompoundEventFilter
;
59 class InputMethodEventFilter
;
60 class ShadowController
;
61 class VisibilityController
;
62 class WindowModalityController
;
66 namespace message_center
{
72 class AcceleratorController
;
73 class CapsLockDelegate
;
74 class DesktopBackgroundController
;
75 class DisplayController
;
76 class HighContrastController
;
78 class LauncherDelegate
;
80 class MagnificationController
;
81 class NestedDispatcherController
;
82 class PartialMagnificationController
;
83 class PowerButtonController
;
84 class RootWindowHostFactory
;
86 class SessionStateController
;
90 class SystemTrayDelegate
;
91 class SystemTrayNotifier
;
92 class UserActivityDetector
;
93 class UserWallpaperDelegate
;
95 class WebNotificationTray
;
96 class WindowCycleController
;
99 class AcceleratorFilter
;
100 class ActivationController
;
101 class AppListController
;
102 class CaptureController
;
103 class DisplayChangeObserverX11
;
104 class DisplayManager
;
105 class DragDropController
;
106 class EventClientImpl
;
107 class EventRewriterEventFilter
;
108 class EventTransformationHandler
;
110 class MouseCursorEventFilter
;
111 class OutputConfiguratorAnimation
;
112 class OverlayEventFilter
;
113 class ResizeShadowController
;
114 class RootWindowController
;
115 class RootWindowLayoutManager
;
116 class ScreenPositionController
;
117 class SlowAnimationEventFilter
;
118 class StatusAreaWidget
;
119 class SystemGestureEventFilter
;
120 class SystemModalContainerEventFilter
;
121 class TooltipController
;
122 class TouchObserverHUD
;
123 class WorkspaceController
;
134 // Shell is a singleton object that presents the Shell API and implements the
135 // RootWindow's delegate interface.
137 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
138 // takes ownership of the Shell.
139 class ASH_EXPORT Shell
140 : public internal::SystemModalContainerEventFilterDelegate
,
141 public ui::EventTarget
,
142 public aura::client::ActivationChangeObserver
{
144 typedef std::vector
<aura::RootWindow
*> RootWindowList
;
145 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
152 // A shell must be explicitly created so that it can call |Init()| with the
153 // delegate set. |delegate| can be NULL (if not required for initialization).
154 static Shell
* CreateInstance(ShellDelegate
* delegate
);
156 // Should never be called before |CreateInstance()|.
157 static Shell
* GetInstance();
159 // Returns true if the ash shell has been instantiated.
160 static bool HasInstance();
162 static void DeleteInstance();
164 // Returns the root window controller for the primary root window.
165 // TODO(oshima): move this to |RootWindowController|
166 static internal::RootWindowController
* GetPrimaryRootWindowController();
168 // Returns all root window controllers.
169 // TODO(oshima): move this to |RootWindowController|
170 static RootWindowControllerList
GetAllRootWindowControllers();
172 // Returns the primary RootWindow. The primary RootWindow is the one
173 // that has a launcher.
174 static aura::RootWindow
* GetPrimaryRootWindow();
176 // Returns the active RootWindow. The active RootWindow is the one that
177 // contains the current active window as a decendant child. The active
178 // RootWindow remains the same even when the active window becomes NULL,
179 // until the another window who has a different root window becomes active.
180 static aura::RootWindow
* GetActiveRootWindow();
182 // Returns the global Screen object that's always active in ash.
183 static gfx::Screen
* GetScreen();
185 // Returns all root windows.
186 static RootWindowList
GetAllRootWindows();
188 static aura::Window
* GetContainer(aura::RootWindow
* root_window
,
190 static const aura::Window
* GetContainer(const aura::RootWindow
* root_window
,
193 // Returns the list of containers that match |container_id| in
194 // all root windows. If |priority_root| is given, the container
195 // in the |priority_root| will be inserted at the top of the list.
196 static std::vector
<aura::Window
*> GetContainersFromAllRootWindows(
198 aura::RootWindow
* priority_root
);
200 // True if "launcher per display" feature is enabled.
201 static bool IsLauncherPerDisplayEnabled();
203 void set_active_root_window(aura::RootWindow
* active_root_window
) {
204 active_root_window_
= active_root_window
;
207 // Shows the context menu for the background and launcher at
208 // |location_in_screen| (in screen coordinates).
209 void ShowContextMenu(const gfx::Point
& location_in_screen
);
211 // Toggles the app list. |window| specifies in which display the app
212 // list should be shown. If this is NULL, the active root window
214 void ToggleAppList(aura::Window
* anchor
);
216 // Returns app list target visibility.
217 bool GetAppListTargetVisibility() const;
219 // Returns app list window or NULL if it is not visible.
220 aura::Window
* GetAppListWindow();
222 // Returns true if a user is logged in whose session can be locked (i.e. the
223 // user has a password with which to unlock the session).
224 bool CanLockScreen();
226 // Returns true if the screen is locked.
227 bool IsScreenLocked() const;
229 // Returns true if a system-modal dialog window is currently open.
230 bool IsSystemModalWindowOpen() const;
232 // For testing only: set simulation that a modal window is open
233 void SimulateModalWindowOpenForTesting(bool modal_window_open
) {
234 simulate_modal_window_open_for_testing_
= modal_window_open
;
237 // Creates a default views::NonClientFrameView for use by windows in the
239 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
240 views::Widget
* widget
);
242 // Rotates focus through containers that can receive focus.
243 void RotateFocus(Direction direction
);
245 // Sets the work area insets of the display that contains |window|,
246 // this notifies observers too.
247 // TODO(sky): this no longer really replicates what happens and is unreliable.
249 void SetDisplayWorkAreaInsets(aura::Window
* window
,
250 const gfx::Insets
& insets
);
252 // Called when the user logs in.
253 void OnLoginStateChanged(user::LoginStatus status
);
255 // Called when the login status changes.
256 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
257 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
259 // Called when the application is exiting.
260 void OnAppTerminating();
262 // Called when the screen is locked (after the lock window is visible) or
264 void OnLockStateChanged(bool locked
);
266 // Initializes |launcher_|. Does nothing if it's already initialized.
267 void CreateLauncher();
269 // Show launcher view if it was created hidden (before session has started).
272 // Adds/removes observer.
273 void AddShellObserver(ShellObserver
* observer
);
274 void RemoveShellObserver(ShellObserver
* observer
);
276 #if !defined(OS_MACOSX)
277 AcceleratorController
* accelerator_controller() {
278 return accelerator_controller_
.get();
280 #endif // !defined(OS_MACOSX)
282 internal::DisplayManager
* display_manager() {
283 return display_manager_
.get();
285 views::corewm::CompoundEventFilter
* env_filter() {
286 return env_filter_
.get();
288 internal::TooltipController
* tooltip_controller() {
289 return tooltip_controller_
.get();
291 internal::TouchObserverHUD
* touch_observer_hud() {
292 return touch_observer_hud_
.get();
294 internal::EventRewriterEventFilter
* event_rewriter_filter() {
295 return event_rewriter_filter_
.get();
297 internal::OverlayEventFilter
* overlay_filter() {
298 return overlay_filter_
.get();
300 DesktopBackgroundController
* desktop_background_controller() {
301 return desktop_background_controller_
.get();
303 PowerButtonController
* power_button_controller() {
304 return power_button_controller_
.get();
306 SessionStateController
* session_state_controller() {
307 return session_state_controller_
.get();
309 UserActivityDetector
* user_activity_detector() {
310 return user_activity_detector_
.get();
312 VideoDetector
* video_detector() {
313 return video_detector_
.get();
315 WindowCycleController
* window_cycle_controller() {
316 return window_cycle_controller_
.get();
318 internal::FocusCycler
* focus_cycler() {
319 return focus_cycler_
.get();
321 DisplayController
* display_controller() {
322 return display_controller_
.get();
324 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
325 return mouse_cursor_filter_
.get();
327 internal::EventTransformationHandler
* event_transformation_handler() {
328 return event_transformation_handler_
.get();
330 CursorManager
* cursor_manager() { return &cursor_manager_
; }
332 ShellDelegate
* delegate() { return delegate_
.get(); }
334 UserWallpaperDelegate
* user_wallpaper_delegate() {
335 return user_wallpaper_delegate_
.get();
338 CapsLockDelegate
* caps_lock_delegate() {
339 return caps_lock_delegate_
.get();
342 HighContrastController
* high_contrast_controller() {
343 return high_contrast_controller_
.get();
346 MagnificationController
* magnification_controller() {
347 return magnification_controller_
.get();
350 PartialMagnificationController
* partial_magnification_controller() {
351 return partial_magnification_controller_
.get();
353 aura::client::ActivationClient
* activation_client() {
354 return activation_client_
;
357 ScreenAsh
* screen() { return screen_
; }
359 // Force the shelf to query for it's current visibility state.
360 void UpdateShelfVisibility();
362 // TODO(oshima): Define an interface to access shelf/launcher
363 // state, or just use Launcher.
365 // Sets/gets the shelf auto-hide behavior on |root_window|.
366 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
,
367 aura::RootWindow
* root_window
);
368 ShelfAutoHideBehavior
GetShelfAutoHideBehavior(
369 aura::RootWindow
* root_window
) const;
371 // Sets/gets shelf's alignment on |root_window|.
372 void SetShelfAlignment(ShelfAlignment alignment
,
373 aura::RootWindow
* root_window
);
374 ShelfAlignment
GetShelfAlignment(aura::RootWindow
* root_window
);
376 // Dims or undims the screen.
377 void SetDimming(bool should_dim
);
379 // Creates a modal background (a partially-opaque fullscreen window)
380 // on all displays for |window|.
381 void CreateModalBackground(aura::Window
* window
);
383 // Called when a modal window is removed. It will activate
384 // another modal window if any, or remove modal screens
386 void OnModalWindowRemoved(aura::Window
* removed
);
388 // Returns WebNotificationTray on the primary root window.
389 WebNotificationTray
* GetWebNotificationTray();
391 // Does the primary display have status area?
392 bool HasPrimaryStatusArea();
394 // Returns the system tray on primary display.
395 SystemTray
* GetPrimarySystemTray();
397 SystemTrayDelegate
* system_tray_delegate() {
398 return system_tray_delegate_
.get();
401 SystemTrayNotifier
* system_tray_notifier() {
402 return system_tray_notifier_
.get();
405 static void set_initially_hide_cursor(bool hide
) {
406 initially_hide_cursor_
= hide
;
409 internal::ResizeShadowController
* resize_shadow_controller() {
410 return resize_shadow_controller_
.get();
413 // Made available for tests.
414 views::corewm::ShadowController
* shadow_controller() {
415 return shadow_controller_
.get();
418 content::BrowserContext
* browser_context() { return browser_context_
; }
419 void set_browser_context(content::BrowserContext
* browser_context
) {
420 browser_context_
= browser_context
;
423 // Initializes the root window to be used for a secondary display.
424 void InitRootWindowForSecondaryDisplay(aura::RootWindow
* root
);
426 // Starts the animation that occurs on first login.
427 void DoInitialWorkspaceAnimation();
429 #if defined(OS_CHROMEOS)
430 chromeos::OutputConfigurator
* output_configurator() {
431 return output_configurator_
.get();
433 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
434 return output_configurator_animation_
.get();
436 #endif // defined(OS_CHROMEOS)
438 RootWindowHostFactory
* root_window_host_factory() {
439 return root_window_host_factory_
.get();
442 // MessageCenter is a global list of currently displayed notifications.
443 message_center::MessageCenter
* message_center();
446 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
447 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
448 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
449 friend class internal::RootWindowController
;
450 friend class test::ShellTestApi
;
451 friend class shell::WindowWatcher
;
453 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
455 explicit Shell(ShellDelegate
* delegate
);
460 LauncherModel
* launcher_model() {
461 return launcher_model_
.get();
464 // Returns the launcher delegate, creating if necesary.
465 LauncherDelegate
* GetLauncherDelegate();
467 // Initializes the root window and root window controller so that it
468 // can host browser windows.
469 void InitRootWindowController(internal::RootWindowController
* root
);
471 // Initializes the layout managers and event filters specific for
473 void InitLayoutManagersForPrimaryDisplay(
474 internal::RootWindowController
* root_window_controller
);
476 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
477 virtual bool CanWindowReceiveEvents(aura::Window
* window
) OVERRIDE
;
479 // Overridden from ui::EventTarget:
480 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
481 virtual EventTarget
* GetParentTarget() OVERRIDE
;
482 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
484 // Overridden from aura::client::ActivationChangeObserver:
485 virtual void OnWindowActivated(aura::Window
* gained_active
,
486 aura::Window
* lost_active
) OVERRIDE
;
488 static Shell
* instance_
;
490 // If set before the Shell is initialized, the mouse cursor will be hidden
491 // when the screen is initially created.
492 static bool initially_hide_cursor_
;
496 // Active root window. Never becomes NULL during the session.
497 aura::RootWindow
* active_root_window_
;
499 // The CompoundEventFilter owned by aura::Env object.
500 scoped_ptr
<views::corewm::CompoundEventFilter
> env_filter_
;
502 std::vector
<WindowAndBoundsPair
> to_restore_
;
504 #if !defined(OS_MACOSX)
505 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
507 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
508 #endif // !defined(OS_MACOSX)
510 scoped_ptr
<ShellDelegate
> delegate_
;
511 scoped_ptr
<SystemTrayDelegate
> system_tray_delegate_
;
512 scoped_ptr
<SystemTrayNotifier
> system_tray_notifier_
;
513 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
514 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
515 scoped_ptr
<LauncherDelegate
> launcher_delegate_
;
517 scoped_ptr
<LauncherModel
> launcher_model_
;
519 scoped_ptr
<internal::AppListController
> app_list_controller_
;
521 scoped_ptr
<internal::ActivationController
> activation_controller_
;
522 scoped_ptr
<internal::CaptureController
> capture_controller_
;
523 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
524 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
525 scoped_ptr
<views::corewm::ShadowController
> shadow_controller_
;
526 scoped_ptr
<views::corewm::VisibilityController
> visibility_controller_
;
527 scoped_ptr
<views::corewm::WindowModalityController
>
528 window_modality_controller_
;
529 scoped_ptr
<internal::TooltipController
> tooltip_controller_
;
530 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
531 scoped_ptr
<PowerButtonController
> power_button_controller_
;
532 scoped_ptr
<SessionStateController
> session_state_controller_
;
533 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
534 scoped_ptr
<VideoDetector
> video_detector_
;
535 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
536 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
537 scoped_ptr
<DisplayController
> display_controller_
;
538 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
539 scoped_ptr
<MagnificationController
> magnification_controller_
;
540 scoped_ptr
<PartialMagnificationController
> partial_magnification_controller_
;
541 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
542 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
543 aura::client::ActivationClient
* activation_client_
;
544 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
545 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
546 scoped_ptr
<internal::SystemModalContainerEventFilter
> modality_filter_
;
547 scoped_ptr
<internal::EventClientImpl
> event_client_
;
548 scoped_ptr
<internal::EventTransformationHandler
>
549 event_transformation_handler_
;
550 scoped_ptr
<RootWindowHostFactory
> root_window_host_factory_
;
552 // An event filter that rewrites or drops an event.
553 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
555 // An event filter that pre-handles key events while the partial
556 // screenshot UI or the keyboard overlay is active.
557 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
559 // An event filter which handles system level gestures
560 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
562 #if !defined(OS_MACOSX)
563 // An event filter that pre-handles global accelerators.
564 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
567 // An event filter that pre-handles all key events to send them to an IME.
568 scoped_ptr
<views::corewm::InputMethodEventFilter
> input_method_filter_
;
570 // An event filter that silently keeps track of all touch events and controls
571 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
572 scoped_ptr
<internal::TouchObserverHUD
> touch_observer_hud_
;
574 scoped_ptr
<internal::DisplayManager
> display_manager_
;
576 #if defined(OS_CHROMEOS)
577 // Controls video output device state.
578 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
579 scoped_ptr
<internal::OutputConfiguratorAnimation
>
580 output_configurator_animation_
;
582 // Receives output change events and udpates the display manager.
583 scoped_ptr
<internal::DisplayChangeObserverX11
> display_change_observer_
;
584 #endif // defined(OS_CHROMEOS)
586 scoped_ptr
<message_center::MessageCenter
> message_center_
;
588 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_