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
;
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 ShelfWindowWatcher
;
140 class SlowAnimationEventFilter
;
141 class StatusAreaWidget
;
142 class SystemGestureEventFilter
;
143 class SystemModalContainerEventFilter
;
144 class TouchObserverHUD
;
145 class UserActivityNotifier
;
146 class VideoActivityNotifier
;
157 // Shell is a singleton object that presents the Shell API and implements the
158 // RootWindow's delegate interface.
160 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
161 // takes ownership of the Shell.
162 class ASH_EXPORT Shell
163 : public internal::SystemModalContainerEventFilterDelegate
,
164 public ui::EventTarget
,
165 public aura::client::ActivationChangeObserver
{
167 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
174 // A shell must be explicitly created so that it can call |Init()| with the
175 // delegate set. |delegate| can be NULL (if not required for initialization).
176 // Takes ownership of |delegate|.
177 static Shell
* CreateInstance(ShellDelegate
* delegate
);
179 // Should never be called before |CreateInstance()|.
180 static Shell
* GetInstance();
182 // Returns true if the ash shell has been instantiated.
183 static bool HasInstance();
185 static void DeleteInstance();
187 // Returns the root window controller for the primary root window.
188 // TODO(oshima): move this to |RootWindowController|
189 static internal::RootWindowController
* GetPrimaryRootWindowController();
191 // Returns all root window controllers.
192 // TODO(oshima): move this to |RootWindowController|
193 static RootWindowControllerList
GetAllRootWindowControllers();
195 // Returns the primary root Window. The primary root Window is the one that
197 static aura::Window
* GetPrimaryRootWindow();
199 // Returns a root Window when used as a target when creating a new window.
200 // The root window of the active window is used in most cases, but can
201 // be overridden by using ScopedTargetRootWindow().
202 // If you want to get the root Window of the active window, just use
203 // |wm::GetActiveWindow()->GetRootWindow()|.
204 static aura::Window
* GetTargetRootWindow();
206 // Returns the global Screen object that's always active in ash.
207 static gfx::Screen
* GetScreen();
209 // Returns all root windows.
210 static aura::Window::Windows
GetAllRootWindows();
212 static aura::Window
* GetContainer(aura::Window
* root_window
,
214 static const aura::Window
* GetContainer(const aura::Window
* root_window
,
217 // Returns the list of containers that match |container_id| in
218 // all root windows. If |priority_root| is given, the container
219 // in the |priority_root| will be inserted at the top of the list.
220 static std::vector
<aura::Window
*> GetContainersFromAllRootWindows(
222 aura::Window
* priority_root
);
224 void set_target_root_window(aura::Window
* target_root_window
) {
225 target_root_window_
= target_root_window
;
228 // Shows the context menu for the background and launcher at
229 // |location_in_screen| (in screen coordinates).
230 void ShowContextMenu(const gfx::Point
& location_in_screen
,
231 ui::MenuSourceType source_type
);
233 // Toggles the app list. |window| specifies in which display the app
234 // list should be shown. If this is NULL, the active root window
236 void ToggleAppList(aura::Window
* anchor
);
238 // Returns app list target visibility.
239 bool GetAppListTargetVisibility() const;
241 // Returns app list window or NULL if it is not visible.
242 aura::Window
* GetAppListWindow();
244 // Returns app list view or NULL if it is not visible.
245 app_list::AppListView
* GetAppListView();
247 // Returns true if a system-modal dialog window is currently open.
248 bool IsSystemModalWindowOpen() const;
250 // For testing only: set simulation that a modal window is open
251 void SimulateModalWindowOpenForTesting(bool modal_window_open
) {
252 simulate_modal_window_open_for_testing_
= modal_window_open
;
255 // Creates a default views::NonClientFrameView for use by windows in the
257 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
258 views::Widget
* widget
);
260 // Rotates focus through containers that can receive focus.
261 void RotateFocus(Direction direction
);
263 // Sets the work area insets of the display that contains |window|,
264 // this notifies observers too.
265 // TODO(sky): this no longer really replicates what happens and is unreliable.
267 void SetDisplayWorkAreaInsets(aura::Window
* window
,
268 const gfx::Insets
& insets
);
270 // Called when the user logs in.
271 void OnLoginStateChanged(user::LoginStatus status
);
273 // Called after the logged-in user's profile is ready.
274 void OnLoginUserProfilePrepared();
276 // Called when the login status changes.
277 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
278 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
280 // Called when the application is exiting.
281 void OnAppTerminating();
283 // Called when the screen is locked (after the lock window is visible) or
285 void OnLockStateChanged(bool locked
);
287 // Initializes |launcher_|. Does nothing if it's already initialized.
288 void CreateLauncher();
290 // Creates virtual keyboard. Deletes the old virtual keyboard if it's already
292 void CreateKeyboard();
294 // Show shelf view if it was created hidden (before session has started).
297 // Adds/removes observer.
298 void AddShellObserver(ShellObserver
* observer
);
299 void RemoveShellObserver(ShellObserver
* observer
);
301 keyboard::KeyboardController
* keyboard_controller() {
302 return keyboard_controller_
.get();
305 AcceleratorController
* accelerator_controller() {
306 return accelerator_controller_
.get();
309 internal::DisplayManager
* display_manager() {
310 return display_manager_
.get();
312 views::corewm::InputMethodEventFilter
* input_method_filter() {
313 return input_method_filter_
.get();
315 views::corewm::CompoundEventFilter
* env_filter() {
316 return env_filter_
.get();
318 views::corewm::TooltipController
* tooltip_controller() {
319 return tooltip_controller_
.get();
321 internal::EventRewriterEventFilter
* event_rewriter_filter() {
322 return event_rewriter_filter_
.get();
324 internal::OverlayEventFilter
* overlay_filter() {
325 return overlay_filter_
.get();
327 DesktopBackgroundController
* desktop_background_controller() {
328 return desktop_background_controller_
.get();
330 PowerButtonController
* power_button_controller() {
331 return power_button_controller_
.get();
333 LockStateController
* lock_state_controller() {
334 return lock_state_controller_
.get();
336 MruWindowTracker
* mru_window_tracker() {
337 return mru_window_tracker_
.get();
339 UserActivityDetector
* user_activity_detector() {
340 return user_activity_detector_
.get();
342 VideoDetector
* video_detector() {
343 return video_detector_
.get();
345 WindowCycleController
* window_cycle_controller() {
346 return window_cycle_controller_
.get();
348 WindowSelectorController
* window_selector_controller() {
349 return window_selector_controller_
.get();
351 internal::FocusCycler
* focus_cycler() {
352 return focus_cycler_
.get();
354 DisplayController
* display_controller() {
355 return display_controller_
.get();
357 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
358 return mouse_cursor_filter_
.get();
360 internal::EventTransformationHandler
* event_transformation_handler() {
361 return event_transformation_handler_
.get();
363 views::corewm::CursorManager
* cursor_manager() { return &cursor_manager_
; }
365 ShellDelegate
* delegate() { return delegate_
.get(); }
367 UserWallpaperDelegate
* user_wallpaper_delegate() {
368 return user_wallpaper_delegate_
.get();
371 CapsLockDelegate
* caps_lock_delegate() {
372 return caps_lock_delegate_
.get();
375 SessionStateDelegate
* session_state_delegate() {
376 return session_state_delegate_
.get();
379 AccessibilityDelegate
* accessibility_delegate() {
380 return accessibility_delegate_
.get();
383 NewWindowDelegate
* new_window_delegate() {
384 return new_window_delegate_
.get();
387 MediaDelegate
* media_delegate() {
388 return media_delegate_
.get();
391 HighContrastController
* high_contrast_controller() {
392 return high_contrast_controller_
.get();
395 MagnificationController
* magnification_controller() {
396 return magnification_controller_
.get();
399 PartialMagnificationController
* partial_magnification_controller() {
400 return partial_magnification_controller_
.get();
403 AutoclickController
* autoclick_controller() {
404 return autoclick_controller_
.get();
407 aura::client::ActivationClient
* activation_client() {
408 return activation_client_
;
411 ShelfItemDelegateManager
* shelf_item_delegate_manager() {
412 return shelf_item_delegate_manager_
.get();
415 ScreenAsh
* screen() { return screen_
; }
417 // Force the shelf to query for it's current visibility state.
418 void UpdateShelfVisibility();
420 // TODO(oshima): Define an interface to access shelf/launcher
421 // state, or just use Launcher.
423 // Sets/gets the shelf auto-hide behavior on |root_window|.
424 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
,
425 aura::Window
* root_window
);
426 ShelfAutoHideBehavior
GetShelfAutoHideBehavior(
427 aura::Window
* root_window
) const;
429 // Sets/gets shelf's alignment on |root_window|.
430 void SetShelfAlignment(ShelfAlignment alignment
,
431 aura::Window
* root_window
);
432 ShelfAlignment
GetShelfAlignment(aura::Window
* root_window
);
434 // Dims or undims the screen.
435 void SetDimming(bool should_dim
);
437 // Notifies |observers_| when entering or exiting fullscreen mode in
439 void NotifyFullscreenStateChange(bool is_fullscreen
,
440 aura::Window
* root_window
);
442 // Creates a modal background (a partially-opaque fullscreen window)
443 // on all displays for |window|.
444 void CreateModalBackground(aura::Window
* window
);
446 // Called when a modal window is removed. It will activate
447 // another modal window if any, or remove modal screens
449 void OnModalWindowRemoved(aura::Window
* removed
);
451 // Returns WebNotificationTray on the primary root window.
452 WebNotificationTray
* GetWebNotificationTray();
454 // Does the primary display have status area?
455 bool HasPrimaryStatusArea();
457 // Returns the system tray on primary display.
458 SystemTray
* GetPrimarySystemTray();
460 SystemTrayDelegate
* system_tray_delegate() {
461 return system_tray_delegate_
.get();
464 SystemTrayNotifier
* system_tray_notifier() {
465 return system_tray_notifier_
.get();
468 static void set_initially_hide_cursor(bool hide
) {
469 initially_hide_cursor_
= hide
;
472 internal::ResizeShadowController
* resize_shadow_controller() {
473 return resize_shadow_controller_
.get();
476 // Made available for tests.
477 views::corewm::ShadowController
* shadow_controller() {
478 return shadow_controller_
.get();
481 // Starts the animation that occurs on first login.
482 void DoInitialWorkspaceAnimation();
484 #if defined(OS_CHROMEOS) && defined(USE_X11)
485 // TODO(oshima): Move these objects to DisplayController.
486 chromeos::OutputConfigurator
* output_configurator() {
487 return output_configurator_
.get();
489 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
490 return output_configurator_animation_
.get();
492 internal::DisplayErrorObserver
* display_error_observer() {
493 return display_error_observer_
.get();
495 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
497 internal::ResolutionNotificationController
*
498 resolution_notification_controller() {
499 return resolution_notification_controller_
.get();
502 RootWindowHostFactory
* root_window_host_factory() {
503 return root_window_host_factory_
.get();
506 ShelfModel
* shelf_model() {
507 return shelf_model_
.get();
510 WindowPositioner
* window_positioner() {
511 return window_positioner_
.get();
514 // Returns the launcher delegate, creating if necesary.
515 ShelfDelegate
* GetShelfDelegate();
517 void SetTouchHudProjectionEnabled(bool enabled
);
519 bool is_touch_hud_projection_enabled() const {
520 return is_touch_hud_projection_enabled_
;
523 #if defined(OS_CHROMEOS)
524 // Creates instance of FirstRunHelper. Caller is responsible for deleting
526 ash::FirstRunHelper
* CreateFirstRunHelper();
528 StickyKeys
* sticky_keys() {
529 return sticky_keys_
.get();
531 #endif // defined(OS_CHROMEOS)
534 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
535 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
536 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
537 friend class internal::RootWindowController
;
538 friend class internal::ScopedTargetRootWindow
;
539 friend class test::ShellTestApi
;
540 friend class shell::WindowWatcher
;
542 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
544 // Takes ownership of |delegate|.
545 explicit Shell(ShellDelegate
* delegate
);
550 // Initializes virtual keyboard controller.
553 // Initializes the root window so that it can host browser windows.
554 void InitRootWindow(aura::Window
* root_window
);
556 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
557 virtual bool CanWindowReceiveEvents(aura::Window
* window
) OVERRIDE
;
559 // Overridden from ui::EventTarget:
560 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
561 virtual EventTarget
* GetParentTarget() OVERRIDE
;
562 virtual scoped_ptr
<ui::EventTargetIterator
> GetChildIterator() const OVERRIDE
;
563 virtual ui::EventTargeter
* GetEventTargeter() OVERRIDE
;
564 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
566 // Overridden from aura::client::ActivationChangeObserver:
567 virtual void OnWindowActivated(aura::Window
* gained_active
,
568 aura::Window
* lost_active
) OVERRIDE
;
570 static Shell
* instance_
;
572 // If set before the Shell is initialized, the mouse cursor will be hidden
573 // when the screen is initially created.
574 static bool initially_hide_cursor_
;
578 // When no explicit target display/RootWindow is given, new windows are
579 // created on |scoped_target_root_window_| , unless NULL in
580 // which case they are created on |target_root_window_|.
581 // |target_root_window_| never becomes NULL during the session.
582 aura::Window
* target_root_window_
;
583 aura::Window
* scoped_target_root_window_
;
585 // The CompoundEventFilter owned by aura::Env object.
586 scoped_ptr
<views::corewm::CompoundEventFilter
> env_filter_
;
588 std::vector
<WindowAndBoundsPair
> to_restore_
;
590 scoped_ptr
<PeriodicMetricsRecorder
> periodic_metrics_recorder_
;
591 scoped_ptr
<keyboard::KeyboardController
> keyboard_controller_
;
592 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
593 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
594 scoped_ptr
<ShellDelegate
> delegate_
;
595 scoped_ptr
<SystemTrayDelegate
> system_tray_delegate_
;
596 scoped_ptr
<SystemTrayNotifier
> system_tray_notifier_
;
597 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
598 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
599 scoped_ptr
<SessionStateDelegate
> session_state_delegate_
;
600 scoped_ptr
<AccessibilityDelegate
> accessibility_delegate_
;
601 scoped_ptr
<NewWindowDelegate
> new_window_delegate_
;
602 scoped_ptr
<MediaDelegate
> media_delegate_
;
603 scoped_ptr
<ShelfDelegate
> shelf_delegate_
;
604 scoped_ptr
<ShelfItemDelegateManager
> shelf_item_delegate_manager_
;
605 scoped_ptr
<internal::ShelfWindowWatcher
> shelf_window_watcher_
;
607 scoped_ptr
<ShelfModel
> shelf_model_
;
608 scoped_ptr
<WindowPositioner
> window_positioner_
;
610 scoped_ptr
<internal::AppListController
> app_list_controller_
;
612 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
613 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
614 scoped_ptr
<views::corewm::ShadowController
> shadow_controller_
;
615 scoped_ptr
<views::corewm::VisibilityController
> visibility_controller_
;
616 scoped_ptr
<views::corewm::WindowModalityController
>
617 window_modality_controller_
;
618 scoped_ptr
<views::corewm::TooltipController
> tooltip_controller_
;
619 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
620 scoped_ptr
<PowerButtonController
> power_button_controller_
;
621 scoped_ptr
<LockStateController
> lock_state_controller_
;
622 scoped_ptr
<MruWindowTracker
> mru_window_tracker_
;
623 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
624 scoped_ptr
<VideoDetector
> video_detector_
;
625 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
626 scoped_ptr
<WindowSelectorController
> window_selector_controller_
;
627 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
628 scoped_ptr
<DisplayController
> display_controller_
;
629 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
630 scoped_ptr
<MagnificationController
> magnification_controller_
;
631 scoped_ptr
<PartialMagnificationController
> partial_magnification_controller_
;
632 scoped_ptr
<AutoclickController
> autoclick_controller_
;
633 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
634 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
635 aura::client::ActivationClient
* activation_client_
;
636 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
637 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
638 scoped_ptr
<internal::SystemModalContainerEventFilter
> modality_filter_
;
639 scoped_ptr
<internal::EventClientImpl
> event_client_
;
640 scoped_ptr
<internal::EventTransformationHandler
>
641 event_transformation_handler_
;
642 scoped_ptr
<RootWindowHostFactory
> root_window_host_factory_
;
644 // An event filter that rewrites or drops an event.
645 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
647 // An event filter that pre-handles key events while the partial
648 // screenshot UI or the keyboard overlay is active.
649 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
651 // An event filter for logging keyboard-related metrics.
652 scoped_ptr
<internal::KeyboardUMAEventFilter
> keyboard_metrics_filter_
;
654 // An event filter which handles system level gestures
655 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
657 // An event filter that pre-handles global accelerators.
658 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
660 // An event filter that pre-handles all key events to send them to an IME.
661 scoped_ptr
<views::corewm::InputMethodEventFilter
> input_method_filter_
;
663 scoped_ptr
<internal::DisplayManager
> display_manager_
;
664 scoped_ptr
<base::WeakPtrFactory
<internal::DisplayManager
> >
665 weak_display_manager_factory_
;
667 scoped_ptr
<internal::LocaleNotificationController
>
668 locale_notification_controller_
;
670 #if defined(OS_CHROMEOS)
671 scoped_ptr
<internal::PowerEventObserver
> power_event_observer_
;
672 scoped_ptr
<internal::UserActivityNotifier
> user_activity_notifier_
;
673 scoped_ptr
<internal::VideoActivityNotifier
> video_activity_notifier_
;
674 scoped_ptr
<StickyKeys
> sticky_keys_
;
676 // Controls video output device state.
677 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
678 scoped_ptr
<internal::OutputConfiguratorAnimation
>
679 output_configurator_animation_
;
680 scoped_ptr
<internal::DisplayErrorObserver
> display_error_observer_
;
682 // Listens for output changes and updates the display manager.
683 scoped_ptr
<internal::DisplayChangeObserver
> display_change_observer_
;
684 #endif // defined(USE_X11)
685 #endif // defined(OS_CHROMEOS)
687 scoped_ptr
<internal::ResolutionNotificationController
>
688 resolution_notification_controller_
;
690 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
691 // pointer to vend to test code.
692 AshNativeCursorManager
* native_cursor_manager_
;
693 views::corewm::CursorManager cursor_manager_
;
695 ObserverList
<ShellObserver
> observers_
;
697 // For testing only: simulate that a modal window is open
698 bool simulate_modal_window_open_for_testing_
;
700 bool is_touch_hud_projection_enabled_
;
702 DISALLOW_COPY_AND_ASSIGN(Shell
);
707 #endif // ASH_SHELL_H_