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"
31 class ApplicationDragAndDropHost
;
38 class ActivationClient
;
40 class UserActionClient
;
44 class OutputConfigurator
;
59 class NonClientFrameView
;
62 class CompoundEventFilter
;
63 class InputMethodEventFilter
;
64 class ShadowController
;
65 class TooltipController
;
66 class VisibilityController
;
67 class WindowModalityController
;
73 class AcceleratorController
;
74 class AshNativeCursorManager
;
75 class CapsLockDelegate
;
76 class DesktopBackgroundController
;
77 class DisplayController
;
78 class HighContrastController
;
80 class LauncherDelegate
;
82 class MagnificationController
;
83 class NestedDispatcherController
;
84 class PartialMagnificationController
;
85 class PowerButtonController
;
86 class RootWindowHostFactory
;
88 class LockStateController
;
89 class SessionStateDelegate
;
93 class SystemTrayDelegate
;
94 class SystemTrayNotifier
;
95 class UserActivityDetector
;
96 class UserWallpaperDelegate
;
98 class WebNotificationTray
;
99 class WindowCycleController
;
102 class AcceleratorFilter
;
103 class ActivationController
;
104 class AppListController
;
105 class CaptureController
;
106 class DisplayChangeObserverX11
;
107 class DisplayErrorObserver
;
108 class DisplayManager
;
109 class DragDropController
;
110 class EventClientImpl
;
111 class EventRewriterEventFilter
;
112 class EventTransformationHandler
;
114 class MouseCursorEventFilter
;
115 class OutputConfiguratorAnimation
;
116 class OverlayEventFilter
;
117 class ResizeShadowController
;
118 class RootWindowController
;
119 class RootWindowLayoutManager
;
120 class ScreenPositionController
;
121 class SlowAnimationEventFilter
;
122 class StatusAreaWidget
;
123 class SystemGestureEventFilter
;
124 class SystemModalContainerEventFilter
;
125 class TouchObserverHUD
;
126 class WorkspaceController
;
137 // Shell is a singleton object that presents the Shell API and implements the
138 // RootWindow's delegate interface.
140 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
141 // takes ownership of the Shell.
142 class ASH_EXPORT Shell
143 : public internal::SystemModalContainerEventFilterDelegate
,
144 public ui::EventTarget
,
145 public aura::client::ActivationChangeObserver
{
147 typedef std::vector
<aura::RootWindow
*> RootWindowList
;
148 typedef std::vector
<internal::RootWindowController
*> RootWindowControllerList
;
155 // A shell must be explicitly created so that it can call |Init()| with the
156 // delegate set. |delegate| can be NULL (if not required for initialization).
157 // Takes ownership of |delegate|.
158 static Shell
* CreateInstance(ShellDelegate
* delegate
);
160 // Should never be called before |CreateInstance()|.
161 static Shell
* GetInstance();
163 // Returns true if the ash shell has been instantiated.
164 static bool HasInstance();
166 static void DeleteInstance();
168 // Returns the root window controller for the primary root window.
169 // TODO(oshima): move this to |RootWindowController|
170 static internal::RootWindowController
* GetPrimaryRootWindowController();
172 // Returns all root window controllers.
173 // TODO(oshima): move this to |RootWindowController|
174 static RootWindowControllerList
GetAllRootWindowControllers();
176 // Returns the primary RootWindow. The primary RootWindow is the one
177 // that has a launcher.
178 static aura::RootWindow
* GetPrimaryRootWindow();
180 // Returns the active RootWindow. The active RootWindow is the one that
181 // contains the current active window as a decendant child. The active
182 // RootWindow remains the same even when the active window becomes NULL,
183 // until the another window who has a different root window becomes active.
184 static aura::RootWindow
* GetActiveRootWindow();
186 // Returns the global Screen object that's always active in ash.
187 static gfx::Screen
* GetScreen();
189 // Returns all root windows.
190 static RootWindowList
GetAllRootWindows();
192 static aura::Window
* GetContainer(aura::RootWindow
* root_window
,
194 static const aura::Window
* GetContainer(const aura::RootWindow
* root_window
,
197 // Returns the list of containers that match |container_id| in
198 // all root windows. If |priority_root| is given, the container
199 // in the |priority_root| will be inserted at the top of the list.
200 static std::vector
<aura::Window
*> GetContainersFromAllRootWindows(
202 aura::RootWindow
* priority_root
);
204 // True if an experimental maximize mode is enabled which forces browser and
205 // application windows to be maximized only.
206 static bool IsForcedMaximizeMode();
208 void set_active_root_window(aura::RootWindow
* active_root_window
) {
209 active_root_window_
= active_root_window
;
212 // Shows the context menu for the background and launcher at
213 // |location_in_screen| (in screen coordinates).
214 void ShowContextMenu(const gfx::Point
& location_in_screen
,
215 ui::MenuSourceType source_type
);
217 // Toggles the app list. |window| specifies in which display the app
218 // list should be shown. If this is NULL, the active root window
220 void ToggleAppList(aura::Window
* anchor
);
222 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
223 // operations outside the application list.
224 void SetDragAndDropHostOfCurrentAppList(
225 app_list::ApplicationDragAndDropHost
* drag_and_drop_host
);
227 // Returns app list target visibility.
228 bool GetAppListTargetVisibility() const;
230 // Returns app list window or NULL if it is not visible.
231 aura::Window
* GetAppListWindow();
233 // Returns true if a system-modal dialog window is currently open.
234 bool IsSystemModalWindowOpen() const;
236 // For testing only: set simulation that a modal window is open
237 void SimulateModalWindowOpenForTesting(bool modal_window_open
) {
238 simulate_modal_window_open_for_testing_
= modal_window_open
;
241 // Creates a default views::NonClientFrameView for use by windows in the
243 views::NonClientFrameView
* CreateDefaultNonClientFrameView(
244 views::Widget
* widget
);
246 // Rotates focus through containers that can receive focus.
247 void RotateFocus(Direction direction
);
249 // Sets the work area insets of the display that contains |window|,
250 // this notifies observers too.
251 // TODO(sky): this no longer really replicates what happens and is unreliable.
253 void SetDisplayWorkAreaInsets(aura::Window
* window
,
254 const gfx::Insets
& insets
);
256 // Called when the user logs in.
257 void OnLoginStateChanged(user::LoginStatus status
);
259 // Called when the login status changes.
260 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
261 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
263 // Called when the application is exiting.
264 void OnAppTerminating();
266 // Called when the screen is locked (after the lock window is visible) or
268 void OnLockStateChanged(bool locked
);
270 // Initializes |launcher_|. Does nothing if it's already initialized.
271 void CreateLauncher();
273 // Show launcher view if it was created hidden (before session has started).
276 // Adds/removes observer.
277 void AddShellObserver(ShellObserver
* observer
);
278 void RemoveShellObserver(ShellObserver
* observer
);
280 #if !defined(OS_MACOSX)
281 AcceleratorController
* accelerator_controller() {
282 return accelerator_controller_
.get();
284 #endif // !defined(OS_MACOSX)
286 internal::DisplayManager
* display_manager() {
287 return display_manager_
.get();
289 views::corewm::InputMethodEventFilter
* input_method_filter() {
290 return input_method_filter_
.get();
292 views::corewm::CompoundEventFilter
* env_filter() {
293 return env_filter_
.get();
295 views::corewm::TooltipController
* tooltip_controller() {
296 return tooltip_controller_
.get();
298 internal::EventRewriterEventFilter
* event_rewriter_filter() {
299 return event_rewriter_filter_
.get();
301 internal::OverlayEventFilter
* overlay_filter() {
302 return overlay_filter_
.get();
304 DesktopBackgroundController
* desktop_background_controller() {
305 return desktop_background_controller_
.get();
307 PowerButtonController
* power_button_controller() {
308 return power_button_controller_
.get();
310 LockStateController
* lock_state_controller() {
311 return lock_state_controller_
.get();
313 UserActivityDetector
* user_activity_detector() {
314 return user_activity_detector_
.get();
316 VideoDetector
* video_detector() {
317 return video_detector_
.get();
319 WindowCycleController
* window_cycle_controller() {
320 return window_cycle_controller_
.get();
322 internal::FocusCycler
* focus_cycler() {
323 return focus_cycler_
.get();
325 DisplayController
* display_controller() {
326 return display_controller_
.get();
328 internal::MouseCursorEventFilter
* mouse_cursor_filter() {
329 return mouse_cursor_filter_
.get();
331 internal::EventTransformationHandler
* event_transformation_handler() {
332 return event_transformation_handler_
.get();
334 views::corewm::CursorManager
* cursor_manager() { return &cursor_manager_
; }
336 ShellDelegate
* delegate() { return delegate_
.get(); }
338 UserWallpaperDelegate
* user_wallpaper_delegate() {
339 return user_wallpaper_delegate_
.get();
342 CapsLockDelegate
* caps_lock_delegate() {
343 return caps_lock_delegate_
.get();
346 SessionStateDelegate
* session_state_delegate() {
347 return session_state_delegate_
.get();
350 HighContrastController
* high_contrast_controller() {
351 return high_contrast_controller_
.get();
354 MagnificationController
* magnification_controller() {
355 return magnification_controller_
.get();
358 PartialMagnificationController
* partial_magnification_controller() {
359 return partial_magnification_controller_
.get();
361 aura::client::ActivationClient
* activation_client() {
362 return activation_client_
;
365 ScreenAsh
* screen() { return screen_
; }
367 // Force the shelf to query for it's current visibility state.
368 void UpdateShelfVisibility();
370 // TODO(oshima): Define an interface to access shelf/launcher
371 // state, or just use Launcher.
373 // Sets/gets the shelf auto-hide behavior on |root_window|.
374 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior
,
375 aura::RootWindow
* root_window
);
376 ShelfAutoHideBehavior
GetShelfAutoHideBehavior(
377 aura::RootWindow
* root_window
) const;
379 // Sets/gets shelf's alignment on |root_window|.
380 void SetShelfAlignment(ShelfAlignment alignment
,
381 aura::RootWindow
* root_window
);
382 ShelfAlignment
GetShelfAlignment(aura::RootWindow
* root_window
);
384 // Dims or undims the screen.
385 void SetDimming(bool should_dim
);
387 // Creates a modal background (a partially-opaque fullscreen window)
388 // on all displays for |window|.
389 void CreateModalBackground(aura::Window
* window
);
391 // Called when a modal window is removed. It will activate
392 // another modal window if any, or remove modal screens
394 void OnModalWindowRemoved(aura::Window
* removed
);
396 // Returns WebNotificationTray on the primary root window.
397 WebNotificationTray
* GetWebNotificationTray();
399 // Does the primary display have status area?
400 bool HasPrimaryStatusArea();
402 // Returns the system tray on primary display.
403 SystemTray
* GetPrimarySystemTray();
405 SystemTrayDelegate
* system_tray_delegate() {
406 return system_tray_delegate_
.get();
409 SystemTrayNotifier
* system_tray_notifier() {
410 return system_tray_notifier_
.get();
413 static void set_initially_hide_cursor(bool hide
) {
414 initially_hide_cursor_
= hide
;
417 internal::ResizeShadowController
* resize_shadow_controller() {
418 return resize_shadow_controller_
.get();
421 // Made available for tests.
422 views::corewm::ShadowController
* shadow_controller() {
423 return shadow_controller_
.get();
426 content::BrowserContext
* browser_context() { return browser_context_
; }
427 void set_browser_context(content::BrowserContext
* browser_context
) {
428 browser_context_
= browser_context
;
431 // Initializes the root window to be used for a secondary display.
432 void InitRootWindowForSecondaryDisplay(aura::RootWindow
* root
);
434 // Starts the animation that occurs on first login.
435 void DoInitialWorkspaceAnimation();
437 #if defined(OS_CHROMEOS) && defined(USE_X11)
438 // TODO(oshima): Move these objects to DisplayController.
439 chromeos::OutputConfigurator
* output_configurator() {
440 return output_configurator_
.get();
442 internal::OutputConfiguratorAnimation
* output_configurator_animation() {
443 return output_configurator_animation_
.get();
445 internal::DisplayErrorObserver
* display_error_observer() {
446 return display_error_observer_
.get();
448 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
450 RootWindowHostFactory
* root_window_host_factory() {
451 return root_window_host_factory_
.get();
454 LauncherModel
* launcher_model() {
455 return launcher_model_
.get();
458 // Returns the launcher delegate, creating if necesary.
459 LauncherDelegate
* GetLauncherDelegate();
461 void SetTouchHudProjectionEnabled(bool enabled
);
463 bool is_touch_hud_projection_enabled() const {
464 return is_touch_hud_projection_enabled_
;
468 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest
, TestCursor
);
469 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, MouseEventCursors
);
470 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest
, TransformActivate
);
471 friend class internal::RootWindowController
;
472 friend class test::ShellTestApi
;
473 friend class shell::WindowWatcher
;
475 typedef std::pair
<aura::Window
*, gfx::Rect
> WindowAndBoundsPair
;
477 // Takes ownership of |delegate|.
478 explicit Shell(ShellDelegate
* delegate
);
483 // Initializes the root window and root window controller so that it
484 // can host browser windows. |first_run_after_boot| is true for the
485 // primary display only first time after boot.
486 void InitRootWindowController(internal::RootWindowController
* root
,
487 bool first_run_after_boot
);
489 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
490 virtual bool CanWindowReceiveEvents(aura::Window
* window
) OVERRIDE
;
492 // Overridden from ui::EventTarget:
493 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
494 virtual EventTarget
* GetParentTarget() OVERRIDE
;
495 virtual void OnEvent(ui::Event
* event
) OVERRIDE
;
497 // Overridden from aura::client::ActivationChangeObserver:
498 virtual void OnWindowActivated(aura::Window
* gained_active
,
499 aura::Window
* lost_active
) OVERRIDE
;
501 static Shell
* instance_
;
503 // If set before the Shell is initialized, the mouse cursor will be hidden
504 // when the screen is initially created.
505 static bool initially_hide_cursor_
;
509 // Active root window. Never becomes NULL during the session.
510 aura::RootWindow
* active_root_window_
;
512 // The CompoundEventFilter owned by aura::Env object.
513 scoped_ptr
<views::corewm::CompoundEventFilter
> env_filter_
;
515 std::vector
<WindowAndBoundsPair
> to_restore_
;
517 #if !defined(OS_MACOSX)
518 scoped_ptr
<NestedDispatcherController
> nested_dispatcher_controller_
;
520 scoped_ptr
<AcceleratorController
> accelerator_controller_
;
521 #endif // !defined(OS_MACOSX)
523 scoped_ptr
<ShellDelegate
> delegate_
;
524 scoped_ptr
<SystemTrayDelegate
> system_tray_delegate_
;
525 scoped_ptr
<SystemTrayNotifier
> system_tray_notifier_
;
526 scoped_ptr
<UserWallpaperDelegate
> user_wallpaper_delegate_
;
527 scoped_ptr
<CapsLockDelegate
> caps_lock_delegate_
;
528 scoped_ptr
<SessionStateDelegate
> session_state_delegate_
;
529 scoped_ptr
<LauncherDelegate
> launcher_delegate_
;
531 scoped_ptr
<LauncherModel
> launcher_model_
;
533 scoped_ptr
<internal::AppListController
> app_list_controller_
;
535 scoped_ptr
<internal::ActivationController
> activation_controller_
;
536 scoped_ptr
<internal::CaptureController
> capture_controller_
;
537 scoped_ptr
<internal::DragDropController
> drag_drop_controller_
;
538 scoped_ptr
<internal::ResizeShadowController
> resize_shadow_controller_
;
539 scoped_ptr
<views::corewm::ShadowController
> shadow_controller_
;
540 scoped_ptr
<views::corewm::VisibilityController
> visibility_controller_
;
541 scoped_ptr
<views::corewm::WindowModalityController
>
542 window_modality_controller_
;
543 scoped_ptr
<views::corewm::TooltipController
> tooltip_controller_
;
544 scoped_ptr
<DesktopBackgroundController
> desktop_background_controller_
;
545 scoped_ptr
<PowerButtonController
> power_button_controller_
;
546 scoped_ptr
<LockStateController
> lock_state_controller_
;
547 scoped_ptr
<UserActivityDetector
> user_activity_detector_
;
548 scoped_ptr
<VideoDetector
> video_detector_
;
549 scoped_ptr
<WindowCycleController
> window_cycle_controller_
;
550 scoped_ptr
<internal::FocusCycler
> focus_cycler_
;
551 scoped_ptr
<DisplayController
> display_controller_
;
552 scoped_ptr
<HighContrastController
> high_contrast_controller_
;
553 scoped_ptr
<MagnificationController
> magnification_controller_
;
554 scoped_ptr
<PartialMagnificationController
> partial_magnification_controller_
;
555 scoped_ptr
<aura::client::FocusClient
> focus_client_
;
556 scoped_ptr
<aura::client::UserActionClient
> user_action_client_
;
557 aura::client::ActivationClient
* activation_client_
;
558 scoped_ptr
<internal::MouseCursorEventFilter
> mouse_cursor_filter_
;
559 scoped_ptr
<internal::ScreenPositionController
> screen_position_controller_
;
560 scoped_ptr
<internal::SystemModalContainerEventFilter
> modality_filter_
;
561 scoped_ptr
<internal::EventClientImpl
> event_client_
;
562 scoped_ptr
<internal::EventTransformationHandler
>
563 event_transformation_handler_
;
564 scoped_ptr
<RootWindowHostFactory
> root_window_host_factory_
;
566 // An event filter that rewrites or drops an event.
567 scoped_ptr
<internal::EventRewriterEventFilter
> event_rewriter_filter_
;
569 // An event filter that pre-handles key events while the partial
570 // screenshot UI or the keyboard overlay is active.
571 scoped_ptr
<internal::OverlayEventFilter
> overlay_filter_
;
573 // An event filter which handles system level gestures
574 scoped_ptr
<internal::SystemGestureEventFilter
> system_gesture_filter_
;
576 #if !defined(OS_MACOSX)
577 // An event filter that pre-handles global accelerators.
578 scoped_ptr
<internal::AcceleratorFilter
> accelerator_filter_
;
581 // An event filter that pre-handles all key events to send them to an IME.
582 scoped_ptr
<views::corewm::InputMethodEventFilter
> input_method_filter_
;
584 scoped_ptr
<internal::DisplayManager
> display_manager_
;
586 #if defined(OS_CHROMEOS) && defined(USE_X11)
587 // Controls video output device state.
588 scoped_ptr
<chromeos::OutputConfigurator
> output_configurator_
;
589 scoped_ptr
<internal::OutputConfiguratorAnimation
>
590 output_configurator_animation_
;
591 scoped_ptr
<internal::DisplayErrorObserver
> display_error_observer_
;
593 // Receives output change events and udpates the display manager.
594 scoped_ptr
<internal::DisplayChangeObserverX11
> display_change_observer_
;
595 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
597 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
598 // pointer to vend to test code.
599 AshNativeCursorManager
* native_cursor_manager_
;
600 views::corewm::CursorManager cursor_manager_
;
602 ObserverList
<ShellObserver
> observers_
;
604 // Used by ash/shell.
605 content::BrowserContext
* browser_context_
;
607 // For testing only: simulate that a modal window is open
608 bool simulate_modal_window_open_for_testing_
;
610 bool is_touch_hud_projection_enabled_
;
612 DISALLOW_COPY_AND_ASSIGN(Shell
);
617 #endif // ASH_SHELL_H_