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/base/ui_base_types.h"
23 #include "ui/gfx/insets.h"
24 #include "ui/gfx/screen.h"
25 #include "ui/gfx/size.h"
26 #include "ui/views/corewm/cursor_manager.h"
35 class ActivationClient
;
37 class UserActionClient
;
41 class OutputConfigurator
;
56 class NonClientFrameView
;
59 class CompoundEventFilter
;
60 class InputMethodEventFilter
;
61 class ShadowController
;
62 class TooltipController
;
63 class VisibilityController
;
64 class WindowModalityController
;
70 class AcceleratorController
;
71 class AshNativeCursorManager
;
72 class CapsLockDelegate
;
73 class DesktopBackgroundController
;
74 class DisplayController
;
75 class HighContrastController
;
77 class LauncherDelegate
;
78 class LauncherItemDelegateManager
;
80 class MagnificationController
;
81 class MruWindowTracker
;
82 class NestedDispatcherController
;
83 class PartialMagnificationController
;
84 class PowerButtonController
;
85 class RootWindowHostFactory
;
87 class LockStateController
;
88 class SessionStateDelegate
;
92 class SystemTrayDelegate
;
93 class SystemTrayNotifier
;
94 class UserActivityDetector
;
95 class UserWallpaperDelegate
;
97 class WebNotificationTray
;
98 class WindowCycleController
;
99 class WindowSelectorController
;
102 class AcceleratorFilter
;
103 class AppListController
;
104 class AppListLauncherItemDelegate
;
105 class CaptureController
;
106 class DisplayChangeObserver
;
107 class DisplayErrorObserver
;
108 class DisplayManager
;
109 class DragDropController
;
110 class EventClientImpl
;
111 class EventRewriterEventFilter
;
112 class EventTransformationHandler
;
114 class LocaleNotificationController
;
115 class MouseCursorEventFilter
;
116 class OutputConfiguratorAnimation
;
117 class OverlayEventFilter
;
118 class ResizeShadowController
;
119 class ResolutionNotificationController
;
120 class RootWindowController
;
121 class RootWindowLayoutManager
;
122 class ScopedTargetRootWindow
;
123 class ScreenPositionController
;
124 class SlowAnimationEventFilter
;
125 class StatusAreaWidget
;
126 class SystemGestureEventFilter
;
127 class SystemModalContainerEventFilter
;
128 class TouchObserverHUD
;
139 // Shell is a singleton object that presents the Shell API and implements the
140 // RootWindow's delegate interface.
142 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
143 // takes ownership of the Shell.
144 class ASH_EXPORT Shell
145 : public internal::SystemModalContainerEventFilterDelegate
,
146 public ui::EventTarget
,
147 public aura::client::ActivationChangeObserver
{
149 typedef std::vector
<aura::RootWindow
*> RootWindowList
;
150 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
157 // A shell must be explicitly created so that it can call |Init()| with the
158 // delegate set. |delegate| can be NULL (if not required for initialization).
159 // Takes ownership of |delegate|.
160 static Shell
* CreateInstance(ShellDelegate
* delegate
);
162 // Should never be called before |CreateInstance()|.
163 static Shell
* GetInstance();
165 // Returns true if the ash shell has been instantiated.
166 static bool HasInstance();
168 static void DeleteInstance();
170 // Returns the root window controller for the primary root window.
171 // TODO(oshima): move this to |RootWindowController|
172 static internal::RootWindowController
* GetPrimaryRootWindowController();
174 // Returns all root window controllers.
175 // TODO(oshima): move this to |RootWindowController|
176 static RootWindowControllerList
GetAllRootWindowControllers();
178 // Returns the primary RootWindow. The primary RootWindow is the one
179 // that has a launcher.
180 static aura::RootWindow
* GetPrimaryRootWindow();
182 // Returns a RootWindow when used as a target when creating a new window.
183 // The root window of the active window is used in most cases, but can
184 // be overridden by using ScopedTargetRootWindow().
185 // If you want to get a RootWindow of the active window, just use
186 // |wm::GetActiveWindow()->GetRootWindow()|.
187 static aura::RootWindow
* GetTargetRootWindow();
189 // Returns the global Screen object that's always active in ash.
190 static gfx::Screen
* GetScreen();
192 // Returns all root windows.
193 static RootWindowList
GetAllRootWindows();
195 static aura::Window
* GetContainer(aura::RootWindow
* root_window
,
197 static const aura::Window
* GetContainer(const aura::RootWindow
* root_window
,
200 // Returns the list of containers that match |container_id| in
201 // all root windows. If |priority_root| is given, the container
202 // in the |priority_root| will be inserted at the top of the list.
203 static std::vector
<aura::Window
*> GetContainersFromAllRootWindows(
205 aura::RootWindow
* priority_root
);
207 // True if an experimental maximize mode is enabled which forces browser and
208 // application windows to be maximized only.
209 static bool IsForcedMaximizeMode();
211 void set_target_root_window(aura::RootWindow
* target_root_window
) {
212 target_root_window_
= target_root_window
;
215 // Shows the context menu for the background and launcher at
216 // |location_in_screen| (in screen coordinates).
217 void ShowContextMenu(const gfx::Point
& location_in_screen
,
218 ui::MenuSourceType source_type
);
220 // Toggles the app list. |window| specifies in which display the app
221 // list should be shown. If this is NULL, the active root window
223 void ToggleAppList(aura::Window
* anchor
);
225 // Returns app list target visibility.
226 bool GetAppListTargetVisibility() const;
228 // Returns app list window or NULL if it is not visible.
229 aura::Window
* GetAppListWindow();
231 // Returns true if a system-modal dialog window is currently open.
232 bool IsSystemModalWindowOpen() const;
234 // For testing only: set simulation that a modal window is open
235 void SimulateModalWindowOpenForTesting(bool modal_window_open
) {
236 simulate_modal_window_open_for_testing_
= modal_window_open
;
239 // Creates a default views::NonClientFrameView for use by windows in the
241 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
242 views::Widget
* widget
);
244 // Rotates focus through containers that can receive focus.
245 void RotateFocus(Direction direction
);
247 // Sets the work area insets of the display that contains |window|,
248 // this notifies observers too.
249 // TODO(sky): this no longer really replicates what happens and is unreliable.
251 void SetDisplayWorkAreaInsets(aura::Window
* window
,
252 const gfx::Insets
& insets
);
254 // Called when the user logs in.
255 void OnLoginStateChanged(user::LoginStatus status
);
257 // Called when the login status changes.
258 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
259 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
261 // Called when the application is exiting.
262 void OnAppTerminating();
264 // Called when the screen is locked (after the lock window is visible) or
266 void OnLockStateChanged(bool locked
);
268 // Initializes |launcher_|. Does nothing if it's already initialized.
269 void CreateLauncher();
271 // Show launcher view if it was created hidden (before session has started).
274 // Adds/removes observer.
275 void AddShellObserver(ShellObserver
* observer
);
276 void RemoveShellObserver(ShellObserver
* observer
);
278 #if !defined(OS_MACOSX)
279 AcceleratorController
* accelerator_controller() {
280 return accelerator_controller_
.get();
282 #endif // !defined(OS_MACOSX)
284 internal::DisplayManager
* display_manager() {
285 return display_manager_
.get();
287 views::corewm::InputMethodEventFilter
* input_method_filter() {
288 return input_method_filter_
.get();
290 views::corewm::CompoundEventFilter
* env_filter() {
291 return env_filter_
.get();
293 views::corewm::TooltipController
* tooltip_controller() {
294 return tooltip_controller_
.get();
296 internal::EventRewriterEventFilter
* event_rewriter_filter() {
297 return event_rewriter_filter_
.get();
299 internal::OverlayEventFilter
* overlay_filter() {
300 return overlay_filter_
.get();
302 DesktopBackgroundController
* desktop_background_controller() {
303 return desktop_background_controller_
.get();
305 PowerButtonController
* power_button_controller() {
306 return power_button_controller_
.get();
308 LockStateController
* lock_state_controller() {
309 return lock_state_controller_
.get();
311 MruWindowTracker
* mru_window_tracker() {
312 return mru_window_tracker_
.get();
314 UserActivityDetector
* user_activity_detector() {
315 return user_activity_detector_
.get();
317 VideoDetector
* video_detector() {
318 return video_detector_
.get();
320 WindowCycleController
* window_cycle_controller() {
321 return window_cycle_controller_
.get();
323 WindowSelectorController
* window_selector_controller() {
324 return window_selector_controller_
.get();
326 internal::FocusCycler
* focus_cycler() {
327 return focus_cycler_
.get();
329 DisplayController
* display_controller() {
330 return display_controller_
.get();
332 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
333 return mouse_cursor_filter_
.get();
335 internal::EventTransformationHandler
* event_transformation_handler() {
336 return event_transformation_handler_
.get();
338 views::corewm::CursorManager
* cursor_manager() { return &cursor_manager_
; }
340 ShellDelegate
* delegate() { return delegate_
.get(); }
342 UserWallpaperDelegate
* user_wallpaper_delegate() {
343 return user_wallpaper_delegate_
.get();
346 CapsLockDelegate
* caps_lock_delegate() {
347 return caps_lock_delegate_
.get();
350 SessionStateDelegate
* session_state_delegate() {
351 return session_state_delegate_
.get();
354 HighContrastController
* high_contrast_controller() {
355 return high_contrast_controller_
.get();
358 MagnificationController
* magnification_controller() {
359 return magnification_controller_
.get();
362 PartialMagnificationController
* partial_magnification_controller() {
363 return partial_magnification_controller_
.get();
365 aura::client::ActivationClient
* activation_client() {
366 return activation_client_
;
369 LauncherItemDelegateManager
* launcher_item_delegate_manager() {
370 return launcher_item_delegate_manager_
.get();
373 ScreenAsh
* screen() { return screen_
; }
375 // Force the shelf to query for it's current visibility state.
376 void UpdateShelfVisibility();
378 // TODO(oshima): Define an interface to access shelf/launcher
379 // state, or just use Launcher.
381 // Sets/gets the shelf auto-hide behavior on |root_window|.
382 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
,
383 aura::RootWindow
* root_window
);
384 ShelfAutoHideBehavior
GetShelfAutoHideBehavior(
385 aura::RootWindow
* root_window
) const;
387 // Sets/gets shelf's alignment on |root_window|.
388 void SetShelfAlignment(ShelfAlignment alignment
,
389 aura::RootWindow
* root_window
);
390 ShelfAlignment
GetShelfAlignment(aura::RootWindow
* root_window
);
392 // Dims or undims the screen.
393 void SetDimming(bool should_dim
);
395 // Creates a modal background (a partially-opaque fullscreen window)
396 // on all displays for |window|.
397 void CreateModalBackground(aura::Window
* window
);
399 // Called when a modal window is removed. It will activate
400 // another modal window if any, or remove modal screens
402 void OnModalWindowRemoved(aura::Window
* removed
);
404 // Returns WebNotificationTray on the primary root window.
405 WebNotificationTray
* GetWebNotificationTray();
407 // Does the primary display have status area?
408 bool HasPrimaryStatusArea();
410 // Returns the system tray on primary display.
411 SystemTray
* GetPrimarySystemTray();
413 SystemTrayDelegate
* system_tray_delegate() {
414 return system_tray_delegate_
.get();
417 SystemTrayNotifier
* system_tray_notifier() {
418 return system_tray_notifier_
.get();
421 static void set_initially_hide_cursor(bool hide
) {
422 initially_hide_cursor_
= hide
;
425 internal::ResizeShadowController
* resize_shadow_controller() {
426 return resize_shadow_controller_
.get();
429 // Made available for tests.
430 views::corewm::ShadowController
* shadow_controller() {
431 return shadow_controller_
.get();
434 content::BrowserContext
* browser_context() { return browser_context_
; }
435 void set_browser_context(content::BrowserContext
* browser_context
) {
436 browser_context_
= browser_context
;
439 // Initializes the root window to be used for a secondary display.
440 void InitRootWindowForSecondaryDisplay(aura::RootWindow
* root
);
442 // Starts the animation that occurs on first login.
443 void DoInitialWorkspaceAnimation();
445 #if defined(OS_CHROMEOS) && defined(USE_X11)
446 // TODO(oshima): Move these objects to DisplayController.
447 chromeos::OutputConfigurator
* output_configurator() {
448 return output_configurator_
.get();
450 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
451 return output_configurator_animation_
.get();
453 internal::DisplayErrorObserver
* display_error_observer() {
454 return display_error_observer_
.get();
456 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
458 internal::ResolutionNotificationController
*
459 resolution_notification_controller() {
460 return resolution_notification_controller_
.get();
463 RootWindowHostFactory
* root_window_host_factory() {
464 return root_window_host_factory_
.get();
467 LauncherModel
* launcher_model() {
468 return launcher_model_
.get();
471 // Returns the launcher delegate, creating if necesary.
472 LauncherDelegate
* GetLauncherDelegate();
474 void SetTouchHudProjectionEnabled(bool enabled
);
476 bool is_touch_hud_projection_enabled() const {
477 return is_touch_hud_projection_enabled_
;
481 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
482 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
483 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
484 friend class internal::RootWindowController
;
485 friend class internal::ScopedTargetRootWindow
;
486 friend class test::ShellTestApi
;
487 friend class shell::WindowWatcher
;
489 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
491 // Takes ownership of |delegate|.
492 explicit Shell(ShellDelegate
* delegate
);
497 // Initializes the root window and root window controller so that it
498 // can host browser windows. |first_run_after_boot| is true for the
499 // primary display only first time after boot.
500 void InitRootWindowController(internal::RootWindowController
* root
,
501 bool first_run_after_boot
);
503 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
504 virtual bool CanWindowReceiveEvents(aura::Window
* window
) OVERRIDE
;
506 // Overridden from ui::EventTarget:
507 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
508 virtual EventTarget
* GetParentTarget() OVERRIDE
;
509 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
511 // Overridden from aura::client::ActivationChangeObserver:
512 virtual void OnWindowActivated(aura::Window
* gained_active
,
513 aura::Window
* lost_active
) OVERRIDE
;
515 static Shell
* instance_
;
517 // If set before the Shell is initialized, the mouse cursor will be hidden
518 // when the screen is initially created.
519 static bool initially_hide_cursor_
;
523 // When no explicit target display/RootWindow is given, new windows are
524 // created on |scoped_target_root_window_| , unless NULL in
525 // which case they are created on |target_root_window_|.
526 // |target_root_window_| never becomes NULL during the session.
527 aura::RootWindow
* target_root_window_
;
528 aura::RootWindow
* scoped_target_root_window_
;
530 // The CompoundEventFilter owned by aura::Env object.
531 scoped_ptr
<views::corewm::CompoundEventFilter
> env_filter_
;
533 std::vector
<WindowAndBoundsPair
> to_restore_
;
535 #if !defined(OS_MACOSX)
536 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
538 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
539 #endif // !defined(OS_MACOSX)
541 scoped_ptr
<ShellDelegate
> delegate_
;
542 scoped_ptr
<SystemTrayDelegate
> system_tray_delegate_
;
543 scoped_ptr
<SystemTrayNotifier
> system_tray_notifier_
;
544 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
545 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
546 scoped_ptr
<SessionStateDelegate
> session_state_delegate_
;
547 scoped_ptr
<LauncherDelegate
> launcher_delegate_
;
548 scoped_ptr
<LauncherItemDelegateManager
> launcher_item_delegate_manager_
;
549 scoped_ptr
<internal::AppListLauncherItemDelegate
>
550 app_list_launcher_item_delegate_
;
552 scoped_ptr
<LauncherModel
> launcher_model_
;
554 scoped_ptr
<internal::AppListController
> app_list_controller_
;
556 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
557 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
558 scoped_ptr
<views::corewm::ShadowController
> shadow_controller_
;
559 scoped_ptr
<views::corewm::VisibilityController
> visibility_controller_
;
560 scoped_ptr
<views::corewm::WindowModalityController
>
561 window_modality_controller_
;
562 scoped_ptr
<views::corewm::TooltipController
> tooltip_controller_
;
563 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
564 scoped_ptr
<PowerButtonController
> power_button_controller_
;
565 scoped_ptr
<LockStateController
> lock_state_controller_
;
566 scoped_ptr
<MruWindowTracker
> mru_window_tracker_
;
567 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
568 scoped_ptr
<VideoDetector
> video_detector_
;
569 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
570 scoped_ptr
<WindowSelectorController
> window_selector_controller_
;
571 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
572 scoped_ptr
<DisplayController
> display_controller_
;
573 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
574 scoped_ptr
<MagnificationController
> magnification_controller_
;
575 scoped_ptr
<PartialMagnificationController
> partial_magnification_controller_
;
576 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
577 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
578 aura::client::ActivationClient
* activation_client_
;
579 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
580 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
581 scoped_ptr
<internal::SystemModalContainerEventFilter
> modality_filter_
;
582 scoped_ptr
<internal::EventClientImpl
> event_client_
;
583 scoped_ptr
<internal::EventTransformationHandler
>
584 event_transformation_handler_
;
585 scoped_ptr
<RootWindowHostFactory
> root_window_host_factory_
;
587 // An event filter that rewrites or drops an event.
588 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
590 // An event filter that pre-handles key events while the partial
591 // screenshot UI or the keyboard overlay is active.
592 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
594 // An event filter which handles system level gestures
595 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
597 #if !defined(OS_MACOSX)
598 // An event filter that pre-handles global accelerators.
599 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
602 // An event filter that pre-handles all key events to send them to an IME.
603 scoped_ptr
<views::corewm::InputMethodEventFilter
> input_method_filter_
;
605 scoped_ptr
<internal::DisplayManager
> display_manager_
;
607 scoped_ptr
<internal::LocaleNotificationController
>
608 locale_notification_controller_
;
610 #if defined(OS_CHROMEOS) && defined(USE_X11)
611 // Controls video output device state.
612 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
613 scoped_ptr
<internal::OutputConfiguratorAnimation
>
614 output_configurator_animation_
;
615 scoped_ptr
<internal::DisplayErrorObserver
> display_error_observer_
;
617 // Listens for output changes and updates the display manager.
618 scoped_ptr
<internal::DisplayChangeObserver
> display_change_observer_
;
619 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
621 scoped_ptr
<internal::ResolutionNotificationController
>
622 resolution_notification_controller_
;
624 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
625 // pointer to vend to test code.
626 AshNativeCursorManager
* native_cursor_manager_
;
627 views::corewm::CursorManager cursor_manager_
;
629 ObserverList
<ShellObserver
> observers_
;
631 // Used by ash/shell.
632 content::BrowserContext
* browser_context_
;
634 // For testing only: simulate that a modal window is open
635 bool simulate_modal_window_open_for_testing_
;
637 bool is_touch_hud_projection_enabled_
;
639 DISALLOW_COPY_AND_ASSIGN(Shell
);
644 #endif // ASH_SHELL_H_