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/periodic_metrics_recorder.h"
13 #include "ash/shelf/shelf_types.h"
14 #include "ash/system/user/login_status.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/memory/weak_ptr.h"
21 #include "base/observer_list.h"
22 #include "ui/aura/client/activation_change_observer.h"
23 #include "ui/aura/window.h"
24 #include "ui/base/ui_base_types.h"
25 #include "ui/events/event_target.h"
26 #include "ui/gfx/insets.h"
27 #include "ui/gfx/screen.h"
28 #include "ui/gfx/size.h"
29 #include "ui/views/corewm/cursor_manager.h"
41 class ActivationClient
;
43 class UserActionClient
;
47 class OutputConfigurator
;
57 class KeyboardController
;
64 class NonClientFrameView
;
67 class CompoundEventFilter
;
68 class InputMethodEventFilter
;
69 class ShadowController
;
70 class TooltipController
;
71 class VisibilityController
;
72 class WindowModalityController
;
78 class AcceleratorController
;
79 class AccessibilityDelegate
;
80 class AshNativeCursorManager
;
81 class AutoclickController
;
82 class CapsLockDelegate
;
83 class DesktopBackgroundController
;
84 class DisplayController
;
86 class HighContrastController
;
88 class LauncherDelegate
;
89 class LockStateController
;
90 class MagnificationController
;
92 class MruWindowTracker
;
93 class NestedDispatcherController
;
94 class NewWindowDelegate
;
95 class PartialMagnificationController
;
96 class PowerButtonController
;
97 class RootWindowHostFactory
;
99 class SessionStateDelegate
;
100 class ShelfItemDelegateManager
;
106 class SystemTrayDelegate
;
107 class SystemTrayNotifier
;
108 class UserActivityDetector
;
109 class UserWallpaperDelegate
;
111 class WebNotificationTray
;
112 class WindowCycleController
;
113 class WindowPositioner
;
114 class WindowSelectorController
;
117 class AcceleratorFilter
;
118 class AppListController
;
119 class CaptureController
;
120 class DisplayChangeObserver
;
121 class DisplayErrorObserver
;
122 class DisplayManager
;
123 class DragDropController
;
124 class EventClientImpl
;
125 class EventRewriterEventFilter
;
126 class EventTransformationHandler
;
128 class KeyboardUMAEventFilter
;
129 class LocaleNotificationController
;
130 class MouseCursorEventFilter
;
131 class OutputConfiguratorAnimation
;
132 class OverlayEventFilter
;
133 class PowerEventObserver
;
134 class ResizeShadowController
;
135 class ResolutionNotificationController
;
136 class RootWindowController
;
137 class ScopedTargetRootWindow
;
138 class ScreenPositionController
;
139 class SlowAnimationEventFilter
;
140 class StatusAreaWidget
;
141 class SystemGestureEventFilter
;
142 class SystemModalContainerEventFilter
;
143 class TouchObserverHUD
;
144 class UserActivityNotifier
;
145 class VideoActivityNotifier
;
156 // Shell is a singleton object that presents the Shell API and implements the
157 // RootWindow's delegate interface.
159 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
160 // takes ownership of the Shell.
161 class ASH_EXPORT Shell
162 : public internal::SystemModalContainerEventFilterDelegate
,
163 public ui::EventTarget
,
164 public aura::client::ActivationChangeObserver
{
166 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
173 // A shell must be explicitly created so that it can call |Init()| with the
174 // delegate set. |delegate| can be NULL (if not required for initialization).
175 // Takes ownership of |delegate|.
176 static Shell
* CreateInstance(ShellDelegate
* delegate
);
178 // Should never be called before |CreateInstance()|.
179 static Shell
* GetInstance();
181 // Returns true if the ash shell has been instantiated.
182 static bool HasInstance();
184 static void DeleteInstance();
186 // Returns the root window controller for the primary root window.
187 // TODO(oshima): move this to |RootWindowController|
188 static internal::RootWindowController
* GetPrimaryRootWindowController();
190 // Returns all root window controllers.
191 // TODO(oshima): move this to |RootWindowController|
192 static RootWindowControllerList
GetAllRootWindowControllers();
194 // Returns the primary root Window. The primary root Window is the one that
196 static aura::Window
* GetPrimaryRootWindow();
198 // Returns a root Window when used as a target when creating a new window.
199 // The root window of the active window is used in most cases, but can
200 // be overridden by using ScopedTargetRootWindow().
201 // If you want to get the root Window of the active window, just use
202 // |wm::GetActiveWindow()->GetRootWindow()|.
203 static aura::Window
* GetTargetRootWindow();
205 // Returns the global Screen object that's always active in ash.
206 static gfx::Screen
* GetScreen();
208 // Returns all root windows.
209 static aura::Window::Windows
GetAllRootWindows();
211 static aura::Window
* GetContainer(aura::Window
* root_window
,
213 static const aura::Window
* GetContainer(const aura::Window
* root_window
,
216 // Returns the list of containers that match |container_id| in
217 // all root windows. If |priority_root| is given, the container
218 // in the |priority_root| will be inserted at the top of the list.
219 static std::vector
<aura::Window
*> GetContainersFromAllRootWindows(
221 aura::Window
* priority_root
);
223 void set_target_root_window(aura::Window
* target_root_window
) {
224 target_root_window_
= target_root_window
;
227 // Shows the context menu for the background and launcher at
228 // |location_in_screen| (in screen coordinates).
229 void ShowContextMenu(const gfx::Point
& location_in_screen
,
230 ui::MenuSourceType source_type
);
232 // Toggles the app list. |window| specifies in which display the app
233 // list should be shown. If this is NULL, the active root window
235 void ToggleAppList(aura::Window
* anchor
);
237 // Returns app list target visibility.
238 bool GetAppListTargetVisibility() const;
240 // Returns app list window or NULL if it is not visible.
241 aura::Window
* GetAppListWindow();
243 // Returns app list view or NULL if it is not visible.
244 app_list::AppListView
* GetAppListView();
246 // Returns true if a system-modal dialog window is currently open.
247 bool IsSystemModalWindowOpen() const;
249 // For testing only: set simulation that a modal window is open
250 void SimulateModalWindowOpenForTesting(bool modal_window_open
) {
251 simulate_modal_window_open_for_testing_
= modal_window_open
;
254 // Creates a default views::NonClientFrameView for use by windows in the
256 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
257 views::Widget
* widget
);
259 // Rotates focus through containers that can receive focus.
260 void RotateFocus(Direction direction
);
262 // Sets the work area insets of the display that contains |window|,
263 // this notifies observers too.
264 // TODO(sky): this no longer really replicates what happens and is unreliable.
266 void SetDisplayWorkAreaInsets(aura::Window
* window
,
267 const gfx::Insets
& insets
);
269 // Called when the user logs in.
270 void OnLoginStateChanged(user::LoginStatus status
);
272 // Called after the logged-in user's profile is ready.
273 void OnLoginUserProfilePrepared();
275 // Called when the login status changes.
276 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
277 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
279 // Called when the application is exiting.
280 void OnAppTerminating();
282 // Called when the screen is locked (after the lock window is visible) or
284 void OnLockStateChanged(bool locked
);
286 // Initializes |launcher_|. Does nothing if it's already initialized.
287 void CreateLauncher();
289 // Creates virtual keyboard. Deletes the old virtual keyboard if it's already
291 void CreateKeyboard();
293 // Show shelf view if it was created hidden (before session has started).
296 // Adds/removes observer.
297 void AddShellObserver(ShellObserver
* observer
);
298 void RemoveShellObserver(ShellObserver
* observer
);
300 keyboard::KeyboardController
* keyboard_controller() {
301 return keyboard_controller_
.get();
304 AcceleratorController
* accelerator_controller() {
305 return accelerator_controller_
.get();
308 internal::DisplayManager
* display_manager() {
309 return display_manager_
.get();
311 views::corewm::InputMethodEventFilter
* input_method_filter() {
312 return input_method_filter_
.get();
314 views::corewm::CompoundEventFilter
* env_filter() {
315 return env_filter_
.get();
317 views::corewm::TooltipController
* tooltip_controller() {
318 return tooltip_controller_
.get();
320 internal::EventRewriterEventFilter
* event_rewriter_filter() {
321 return event_rewriter_filter_
.get();
323 internal::OverlayEventFilter
* overlay_filter() {
324 return overlay_filter_
.get();
326 DesktopBackgroundController
* desktop_background_controller() {
327 return desktop_background_controller_
.get();
329 PowerButtonController
* power_button_controller() {
330 return power_button_controller_
.get();
332 LockStateController
* lock_state_controller() {
333 return lock_state_controller_
.get();
335 MruWindowTracker
* mru_window_tracker() {
336 return mru_window_tracker_
.get();
338 UserActivityDetector
* user_activity_detector() {
339 return user_activity_detector_
.get();
341 VideoDetector
* video_detector() {
342 return video_detector_
.get();
344 WindowCycleController
* window_cycle_controller() {
345 return window_cycle_controller_
.get();
347 WindowSelectorController
* window_selector_controller() {
348 return window_selector_controller_
.get();
350 internal::FocusCycler
* focus_cycler() {
351 return focus_cycler_
.get();
353 DisplayController
* display_controller() {
354 return display_controller_
.get();
356 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
357 return mouse_cursor_filter_
.get();
359 internal::EventTransformationHandler
* event_transformation_handler() {
360 return event_transformation_handler_
.get();
362 views::corewm::CursorManager
* cursor_manager() { return &cursor_manager_
; }
364 ShellDelegate
* delegate() { return delegate_
.get(); }
366 UserWallpaperDelegate
* user_wallpaper_delegate() {
367 return user_wallpaper_delegate_
.get();
370 CapsLockDelegate
* caps_lock_delegate() {
371 return caps_lock_delegate_
.get();
374 SessionStateDelegate
* session_state_delegate() {
375 return session_state_delegate_
.get();
378 AccessibilityDelegate
* accessibility_delegate() {
379 return accessibility_delegate_
.get();
382 NewWindowDelegate
* new_window_delegate() {
383 return new_window_delegate_
.get();
386 MediaDelegate
* media_delegate() {
387 return media_delegate_
.get();
390 HighContrastController
* high_contrast_controller() {
391 return high_contrast_controller_
.get();
394 MagnificationController
* magnification_controller() {
395 return magnification_controller_
.get();
398 PartialMagnificationController
* partial_magnification_controller() {
399 return partial_magnification_controller_
.get();
402 AutoclickController
* autoclick_controller() {
403 return autoclick_controller_
.get();
406 aura::client::ActivationClient
* activation_client() {
407 return activation_client_
;
410 ShelfItemDelegateManager
* shelf_item_delegate_manager() {
411 return shelf_item_delegate_manager_
.get();
414 ScreenAsh
* screen() { return screen_
; }
416 // Force the shelf to query for it's current visibility state.
417 void UpdateShelfVisibility();
419 // TODO(oshima): Define an interface to access shelf/launcher
420 // state, or just use Launcher.
422 // Sets/gets the shelf auto-hide behavior on |root_window|.
423 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
,
424 aura::Window
* root_window
);
425 ShelfAutoHideBehavior
GetShelfAutoHideBehavior(
426 aura::Window
* root_window
) const;
428 // Sets/gets shelf's alignment on |root_window|.
429 void SetShelfAlignment(ShelfAlignment alignment
,
430 aura::Window
* root_window
);
431 ShelfAlignment
GetShelfAlignment(aura::Window
* root_window
);
433 // Dims or undims the screen.
434 void SetDimming(bool should_dim
);
436 // Notifies |observers_| when entering or exiting fullscreen mode in
438 void NotifyFullscreenStateChange(bool is_fullscreen
,
439 aura::Window
* root_window
);
441 // Creates a modal background (a partially-opaque fullscreen window)
442 // on all displays for |window|.
443 void CreateModalBackground(aura::Window
* window
);
445 // Called when a modal window is removed. It will activate
446 // another modal window if any, or remove modal screens
448 void OnModalWindowRemoved(aura::Window
* removed
);
450 // Returns WebNotificationTray on the primary root window.
451 WebNotificationTray
* GetWebNotificationTray();
453 // Does the primary display have status area?
454 bool HasPrimaryStatusArea();
456 // Returns the system tray on primary display.
457 SystemTray
* GetPrimarySystemTray();
459 SystemTrayDelegate
* system_tray_delegate() {
460 return system_tray_delegate_
.get();
463 SystemTrayNotifier
* system_tray_notifier() {
464 return system_tray_notifier_
.get();
467 static void set_initially_hide_cursor(bool hide
) {
468 initially_hide_cursor_
= hide
;
471 internal::ResizeShadowController
* resize_shadow_controller() {
472 return resize_shadow_controller_
.get();
475 // Made available for tests.
476 views::corewm::ShadowController
* shadow_controller() {
477 return shadow_controller_
.get();
480 // Starts the animation that occurs on first login.
481 void DoInitialWorkspaceAnimation();
483 #if defined(OS_CHROMEOS) && defined(USE_X11)
484 // TODO(oshima): Move these objects to DisplayController.
485 chromeos::OutputConfigurator
* output_configurator() {
486 return output_configurator_
.get();
488 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
489 return output_configurator_animation_
.get();
491 internal::DisplayErrorObserver
* display_error_observer() {
492 return display_error_observer_
.get();
494 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
496 internal::ResolutionNotificationController
*
497 resolution_notification_controller() {
498 return resolution_notification_controller_
.get();
501 RootWindowHostFactory
* root_window_host_factory() {
502 return root_window_host_factory_
.get();
505 ShelfModel
* shelf_model() {
506 return shelf_model_
.get();
509 WindowPositioner
* window_positioner() {
510 return window_positioner_
.get();
513 // Returns the launcher delegate, creating if necesary.
514 LauncherDelegate
* GetLauncherDelegate();
516 void SetTouchHudProjectionEnabled(bool enabled
);
518 bool is_touch_hud_projection_enabled() const {
519 return is_touch_hud_projection_enabled_
;
522 #if defined(OS_CHROMEOS)
523 // Creates instance of FirstRunHelper. Caller is responsible for deleting
525 ash::FirstRunHelper
* CreateFirstRunHelper();
527 StickyKeys
* sticky_keys() {
528 return sticky_keys_
.get();
530 #endif // defined(OS_CHROMEOS)
533 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
534 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
535 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
536 friend class internal::RootWindowController
;
537 friend class internal::ScopedTargetRootWindow
;
538 friend class test::ShellTestApi
;
539 friend class shell::WindowWatcher
;
541 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
543 // Takes ownership of |delegate|.
544 explicit Shell(ShellDelegate
* delegate
);
549 // Initializes virtual keyboard controller.
552 // Initializes the root window so that it can host browser windows.
553 void InitRootWindow(aura::Window
* root_window
);
555 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
556 virtual bool CanWindowReceiveEvents(aura::Window
* window
) OVERRIDE
;
558 // Overridden from ui::EventTarget:
559 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
560 virtual EventTarget
* GetParentTarget() OVERRIDE
;
561 virtual scoped_ptr
<ui::EventTargetIterator
> GetChildIterator() const OVERRIDE
;
562 virtual ui::EventTargeter
* GetEventTargeter() OVERRIDE
;
563 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
565 // Overridden from aura::client::ActivationChangeObserver:
566 virtual void OnWindowActivated(aura::Window
* gained_active
,
567 aura::Window
* lost_active
) OVERRIDE
;
569 static Shell
* instance_
;
571 // If set before the Shell is initialized, the mouse cursor will be hidden
572 // when the screen is initially created.
573 static bool initially_hide_cursor_
;
577 // When no explicit target display/RootWindow is given, new windows are
578 // created on |scoped_target_root_window_| , unless NULL in
579 // which case they are created on |target_root_window_|.
580 // |target_root_window_| never becomes NULL during the session.
581 aura::Window
* target_root_window_
;
582 aura::Window
* scoped_target_root_window_
;
584 // The CompoundEventFilter owned by aura::Env object.
585 scoped_ptr
<views::corewm::CompoundEventFilter
> env_filter_
;
587 std::vector
<WindowAndBoundsPair
> to_restore_
;
589 scoped_ptr
<PeriodicMetricsRecorder
> periodic_metrics_recorder_
;
590 scoped_ptr
<keyboard::KeyboardController
> keyboard_controller_
;
591 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
592 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
593 scoped_ptr
<ShellDelegate
> delegate_
;
594 scoped_ptr
<SystemTrayDelegate
> system_tray_delegate_
;
595 scoped_ptr
<SystemTrayNotifier
> system_tray_notifier_
;
596 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
597 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
598 scoped_ptr
<SessionStateDelegate
> session_state_delegate_
;
599 scoped_ptr
<AccessibilityDelegate
> accessibility_delegate_
;
600 scoped_ptr
<NewWindowDelegate
> new_window_delegate_
;
601 scoped_ptr
<MediaDelegate
> media_delegate_
;
602 scoped_ptr
<LauncherDelegate
> launcher_delegate_
;
603 scoped_ptr
<ShelfItemDelegateManager
> shelf_item_delegate_manager_
;
605 scoped_ptr
<ShelfModel
> shelf_model_
;
606 scoped_ptr
<WindowPositioner
> window_positioner_
;
608 scoped_ptr
<internal::AppListController
> app_list_controller_
;
610 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
611 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
612 scoped_ptr
<views::corewm::ShadowController
> shadow_controller_
;
613 scoped_ptr
<views::corewm::VisibilityController
> visibility_controller_
;
614 scoped_ptr
<views::corewm::WindowModalityController
>
615 window_modality_controller_
;
616 scoped_ptr
<views::corewm::TooltipController
> tooltip_controller_
;
617 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
618 scoped_ptr
<PowerButtonController
> power_button_controller_
;
619 scoped_ptr
<LockStateController
> lock_state_controller_
;
620 scoped_ptr
<MruWindowTracker
> mru_window_tracker_
;
621 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
622 scoped_ptr
<VideoDetector
> video_detector_
;
623 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
624 scoped_ptr
<WindowSelectorController
> window_selector_controller_
;
625 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
626 scoped_ptr
<DisplayController
> display_controller_
;
627 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
628 scoped_ptr
<MagnificationController
> magnification_controller_
;
629 scoped_ptr
<PartialMagnificationController
> partial_magnification_controller_
;
630 scoped_ptr
<AutoclickController
> autoclick_controller_
;
631 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
632 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
633 aura::client::ActivationClient
* activation_client_
;
634 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
635 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
636 scoped_ptr
<internal::SystemModalContainerEventFilter
> modality_filter_
;
637 scoped_ptr
<internal::EventClientImpl
> event_client_
;
638 scoped_ptr
<internal::EventTransformationHandler
>
639 event_transformation_handler_
;
640 scoped_ptr
<RootWindowHostFactory
> root_window_host_factory_
;
642 // An event filter that rewrites or drops an event.
643 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
645 // An event filter that pre-handles key events while the partial
646 // screenshot UI or the keyboard overlay is active.
647 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
649 // An event filter for logging keyboard-related metrics.
650 scoped_ptr
<internal::KeyboardUMAEventFilter
> keyboard_metrics_filter_
;
652 // An event filter which handles system level gestures
653 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
655 // An event filter that pre-handles global accelerators.
656 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
658 // An event filter that pre-handles all key events to send them to an IME.
659 scoped_ptr
<views::corewm::InputMethodEventFilter
> input_method_filter_
;
661 scoped_ptr
<internal::DisplayManager
> display_manager_
;
662 scoped_ptr
<base::WeakPtrFactory
<internal::DisplayManager
> >
663 weak_display_manager_factory_
;
665 scoped_ptr
<internal::LocaleNotificationController
>
666 locale_notification_controller_
;
668 #if defined(OS_CHROMEOS)
669 scoped_ptr
<internal::PowerEventObserver
> power_event_observer_
;
670 scoped_ptr
<internal::UserActivityNotifier
> user_activity_notifier_
;
671 scoped_ptr
<internal::VideoActivityNotifier
> video_activity_notifier_
;
672 scoped_ptr
<StickyKeys
> sticky_keys_
;
674 // Controls video output device state.
675 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
676 scoped_ptr
<internal::OutputConfiguratorAnimation
>
677 output_configurator_animation_
;
678 scoped_ptr
<internal::DisplayErrorObserver
> display_error_observer_
;
680 // Listens for output changes and updates the display manager.
681 scoped_ptr
<internal::DisplayChangeObserver
> display_change_observer_
;
682 #endif // defined(USE_X11)
683 #endif // defined(OS_CHROMEOS)
685 scoped_ptr
<internal::ResolutionNotificationController
>
686 resolution_notification_controller_
;
688 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
689 // pointer to vend to test code.
690 AshNativeCursorManager
* native_cursor_manager_
;
691 views::corewm::CursorManager cursor_manager_
;
693 ObserverList
<ShellObserver
> observers_
;
695 // For testing only: simulate that a modal window is open
696 bool simulate_modal_window_open_for_testing_
;
698 bool is_touch_hud_projection_enabled_
;
700 DISALLOW_COPY_AND_ASSIGN(Shell
);
705 #endif // ASH_SHELL_H_