[Android] Fix for overzealous partner bookmarks shim.
[chromium-blink-merge.git] / ash / shell.h
blobfa54faa81839841fafda3b96742b96063468c9ea
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.
5 #ifndef ASH_SHELL_H_
6 #define ASH_SHELL_H_
8 #include <utility>
9 #include <vector>
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/memory/weak_ptr.h"
20 #include "base/observer_list.h"
21 #include "ui/aura/client/activation_change_observer.h"
22 #include "ui/base/ui_base_types.h"
23 #include "ui/events/event_target.h"
24 #include "ui/gfx/insets.h"
25 #include "ui/gfx/screen.h"
26 #include "ui/gfx/size.h"
27 #include "ui/views/corewm/cursor_manager.h"
29 class CommandLine;
31 namespace app_list {
32 class AppListView;
34 namespace aura {
35 class EventFilter;
36 class RootWindow;
37 class Window;
38 namespace client {
39 class ActivationClient;
40 class FocusClient;
41 class UserActionClient;
44 namespace chromeos {
45 class OutputConfigurator;
47 namespace content {
48 class BrowserContext;
51 namespace gfx {
52 class ImageSkia;
53 class Point;
54 class Rect;
57 namespace keyboard {
58 class KeyboardController;
61 namespace ui {
62 class Layer;
64 namespace views {
65 class NonClientFrameView;
66 class Widget;
67 namespace corewm {
68 class CompoundEventFilter;
69 class InputMethodEventFilter;
70 class ShadowController;
71 class TooltipController;
72 class VisibilityController;
73 class WindowModalityController;
77 namespace ash {
79 class AcceleratorController;
80 class AccessibilityDelegate;
81 class AshNativeCursorManager;
82 class AutoclickController;
83 class CapsLockDelegate;
84 class DesktopBackgroundController;
85 class DisplayController;
86 class FirstRunHelper;
87 class HighContrastController;
88 class Launcher;
89 class LauncherDelegate;
90 class LauncherItemDelegate;
91 class LauncherItemDelegateManager;
92 class LauncherModel;
93 class LockStateController;
94 class MagnificationController;
95 class MediaDelegate;
96 class MruWindowTracker;
97 class NestedDispatcherController;
98 class NewWindowDelegate;
99 class PartialMagnificationController;
100 class PowerButtonController;
101 class RootWindowHostFactory;
102 class ScreenAsh;
103 class SessionStateDelegate;
104 class ShellDelegate;
105 class ShellObserver;
106 class SystemTray;
107 class SystemTrayDelegate;
108 class SystemTrayNotifier;
109 class UserActivityDetector;
110 class UserWallpaperDelegate;
111 class VideoDetector;
112 class WebNotificationTray;
113 class WindowCycleController;
114 class WindowPositioner;
115 class WindowSelectorController;
117 namespace internal {
118 class AcceleratorFilter;
119 class AppListController;
120 class CaptureController;
121 class DisplayChangeObserver;
122 class DisplayErrorObserver;
123 class DisplayManager;
124 class DragDropController;
125 class EventClientImpl;
126 class EventRewriterEventFilter;
127 class EventTransformationHandler;
128 class FocusCycler;
129 class KeyboardUMAEventFilter;
130 class LocaleNotificationController;
131 class MouseCursorEventFilter;
132 class OutputConfiguratorAnimation;
133 class OverlayEventFilter;
134 class PowerEventObserver;
135 class ResizeShadowController;
136 class ResolutionNotificationController;
137 class RootWindowController;
138 class ScopedTargetRootWindow;
139 class ScreenPositionController;
140 class SlowAnimationEventFilter;
141 class StatusAreaWidget;
142 class SystemGestureEventFilter;
143 class SystemModalContainerEventFilter;
144 class TouchObserverHUD;
145 class UserActivityNotifier;
146 class VideoActivityNotifier;
149 namespace shell {
150 class WindowWatcher;
153 namespace test {
154 class ShellTestApi;
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 {
166 public:
167 typedef std::vector<aura::RootWindow*> RootWindowList;
168 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
170 enum Direction {
171 FORWARD,
172 BACKWARD
175 // A shell must be explicitly created so that it can call |Init()| with the
176 // delegate set. |delegate| can be NULL (if not required for initialization).
177 // Takes ownership of |delegate|.
178 static Shell* CreateInstance(ShellDelegate* delegate);
180 // Should never be called before |CreateInstance()|.
181 static Shell* GetInstance();
183 // Returns true if the ash shell has been instantiated.
184 static bool HasInstance();
186 static void DeleteInstance();
188 // Returns the root window controller for the primary root window.
189 // TODO(oshima): move this to |RootWindowController|
190 static internal::RootWindowController* GetPrimaryRootWindowController();
192 // Returns all root window controllers.
193 // TODO(oshima): move this to |RootWindowController|
194 static RootWindowControllerList GetAllRootWindowControllers();
196 // Returns the primary root Window. The primary root Window is the one that
197 // has a launcher.
198 static aura::Window* GetPrimaryRootWindow();
200 // Returns a root Window when used as a target when creating a new window.
201 // The root window of the active window is used in most cases, but can
202 // be overridden by using ScopedTargetRootWindow().
203 // If you want to get the root Window of the active window, just use
204 // |wm::GetActiveWindow()->GetRootWindow()|.
205 static aura::Window* GetTargetRootWindow();
207 // Returns the global Screen object that's always active in ash.
208 static gfx::Screen* GetScreen();
210 // Returns all root windows.
211 static RootWindowList GetAllRootWindows();
213 static aura::Window* GetContainer(aura::Window* root_window,
214 int container_id);
215 static const aura::Window* GetContainer(const aura::Window* root_window,
216 int container_id);
218 // Returns the list of containers that match |container_id| in
219 // all root windows. If |priority_root| is given, the container
220 // in the |priority_root| will be inserted at the top of the list.
221 static std::vector<aura::Window*> GetContainersFromAllRootWindows(
222 int container_id,
223 aura::Window* priority_root);
225 void set_target_root_window(aura::Window* target_root_window) {
226 target_root_window_ = target_root_window;
229 // Shows the context menu for the background and launcher at
230 // |location_in_screen| (in screen coordinates).
231 void ShowContextMenu(const gfx::Point& location_in_screen,
232 ui::MenuSourceType source_type);
234 // Toggles the app list. |window| specifies in which display the app
235 // list should be shown. If this is NULL, the active root window
236 // will be used.
237 void ToggleAppList(aura::Window* anchor);
239 // Returns app list target visibility.
240 bool GetAppListTargetVisibility() const;
242 // Returns app list window or NULL if it is not visible.
243 aura::Window* GetAppListWindow();
245 // Returns app list view or NULL if it is not visible.
246 app_list::AppListView* GetAppListView();
248 // Returns true if a system-modal dialog window is currently open.
249 bool IsSystemModalWindowOpen() const;
251 // For testing only: set simulation that a modal window is open
252 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
253 simulate_modal_window_open_for_testing_ = modal_window_open;
256 // Creates a default views::NonClientFrameView for use by windows in the
257 // Ash environment.
258 views::NonClientFrameView* CreateDefaultNonClientFrameView(
259 views::Widget* widget);
261 // Rotates focus through containers that can receive focus.
262 void RotateFocus(Direction direction);
264 // Sets the work area insets of the display that contains |window|,
265 // this notifies observers too.
266 // TODO(sky): this no longer really replicates what happens and is unreliable.
267 // Remove this.
268 void SetDisplayWorkAreaInsets(aura::Window* window,
269 const gfx::Insets& insets);
271 // Called when the user logs in.
272 void OnLoginStateChanged(user::LoginStatus status);
274 // Called when the login status changes.
275 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
276 void UpdateAfterLoginStatusChange(user::LoginStatus status);
278 // Called when the application is exiting.
279 void OnAppTerminating();
281 // Called when the screen is locked (after the lock window is visible) or
282 // unlocked.
283 void OnLockStateChanged(bool locked);
285 // Initializes |launcher_|. Does nothing if it's already initialized.
286 void CreateLauncher();
288 // Show shelf view if it was created hidden (before session has started).
289 void ShowLauncher();
291 // Adds/removes observer.
292 void AddShellObserver(ShellObserver* observer);
293 void RemoveShellObserver(ShellObserver* observer);
295 keyboard::KeyboardController* keyboard_controller() {
296 return keyboard_controller_.get();
299 AcceleratorController* accelerator_controller() {
300 return accelerator_controller_.get();
303 internal::DisplayManager* display_manager() {
304 return display_manager_.get();
306 views::corewm::InputMethodEventFilter* input_method_filter() {
307 return input_method_filter_.get();
309 views::corewm::CompoundEventFilter* env_filter() {
310 return env_filter_.get();
312 views::corewm::TooltipController* tooltip_controller() {
313 return tooltip_controller_.get();
315 internal::EventRewriterEventFilter* event_rewriter_filter() {
316 return event_rewriter_filter_.get();
318 internal::OverlayEventFilter* overlay_filter() {
319 return overlay_filter_.get();
321 DesktopBackgroundController* desktop_background_controller() {
322 return desktop_background_controller_.get();
324 PowerButtonController* power_button_controller() {
325 return power_button_controller_.get();
327 LockStateController* lock_state_controller() {
328 return lock_state_controller_.get();
330 MruWindowTracker* mru_window_tracker() {
331 return mru_window_tracker_.get();
333 UserActivityDetector* user_activity_detector() {
334 return user_activity_detector_.get();
336 VideoDetector* video_detector() {
337 return video_detector_.get();
339 WindowCycleController* window_cycle_controller() {
340 return window_cycle_controller_.get();
342 WindowSelectorController* window_selector_controller() {
343 return window_selector_controller_.get();
345 internal::FocusCycler* focus_cycler() {
346 return focus_cycler_.get();
348 DisplayController* display_controller() {
349 return display_controller_.get();
351 internal::MouseCursorEventFilter* mouse_cursor_filter() {
352 return mouse_cursor_filter_.get();
354 internal::EventTransformationHandler* event_transformation_handler() {
355 return event_transformation_handler_.get();
357 views::corewm::CursorManager* cursor_manager() { return &cursor_manager_; }
359 ShellDelegate* delegate() { return delegate_.get(); }
361 UserWallpaperDelegate* user_wallpaper_delegate() {
362 return user_wallpaper_delegate_.get();
365 CapsLockDelegate* caps_lock_delegate() {
366 return caps_lock_delegate_.get();
369 SessionStateDelegate* session_state_delegate() {
370 return session_state_delegate_.get();
373 AccessibilityDelegate* accessibility_delegate() {
374 return accessibility_delegate_.get();
377 NewWindowDelegate* new_window_delegate() {
378 return new_window_delegate_.get();
381 MediaDelegate* media_delegate() {
382 return media_delegate_.get();
385 HighContrastController* high_contrast_controller() {
386 return high_contrast_controller_.get();
389 MagnificationController* magnification_controller() {
390 return magnification_controller_.get();
393 PartialMagnificationController* partial_magnification_controller() {
394 return partial_magnification_controller_.get();
397 AutoclickController* autoclick_controller() {
398 return autoclick_controller_.get();
401 aura::client::ActivationClient* activation_client() {
402 return activation_client_;
405 LauncherItemDelegateManager* launcher_item_delegate_manager() {
406 return launcher_item_delegate_manager_.get();
409 ScreenAsh* screen() { return screen_; }
411 // Force the shelf to query for it's current visibility state.
412 void UpdateShelfVisibility();
414 // TODO(oshima): Define an interface to access shelf/launcher
415 // state, or just use Launcher.
417 // Sets/gets the shelf auto-hide behavior on |root_window|.
418 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
419 aura::Window* root_window);
420 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
421 aura::Window* root_window) const;
423 // Sets/gets shelf's alignment on |root_window|.
424 void SetShelfAlignment(ShelfAlignment alignment,
425 aura::Window* root_window);
426 ShelfAlignment GetShelfAlignment(aura::Window* root_window);
428 // Dims or undims the screen.
429 void SetDimming(bool should_dim);
431 // Notifies |observers_| when entering or exiting fullscreen mode in
432 // |root_window|.
433 void NotifyFullscreenStateChange(bool is_fullscreen,
434 aura::Window* root_window);
436 // Creates a modal background (a partially-opaque fullscreen window)
437 // on all displays for |window|.
438 void CreateModalBackground(aura::Window* window);
440 // Called when a modal window is removed. It will activate
441 // another modal window if any, or remove modal screens
442 // on all displays.
443 void OnModalWindowRemoved(aura::Window* removed);
445 // Returns WebNotificationTray on the primary root window.
446 WebNotificationTray* GetWebNotificationTray();
448 // Does the primary display have status area?
449 bool HasPrimaryStatusArea();
451 // Returns the system tray on primary display.
452 SystemTray* GetPrimarySystemTray();
454 SystemTrayDelegate* system_tray_delegate() {
455 return system_tray_delegate_.get();
458 SystemTrayNotifier* system_tray_notifier() {
459 return system_tray_notifier_.get();
462 static void set_initially_hide_cursor(bool hide) {
463 initially_hide_cursor_ = hide;
466 internal::ResizeShadowController* resize_shadow_controller() {
467 return resize_shadow_controller_.get();
470 // Made available for tests.
471 views::corewm::ShadowController* shadow_controller() {
472 return shadow_controller_.get();
475 content::BrowserContext* browser_context() { return browser_context_; }
476 void set_browser_context(content::BrowserContext* browser_context) {
477 browser_context_ = browser_context;
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 LauncherModel* launcher_model() {
506 return launcher_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
524 // returned object.
525 ash::FirstRunHelper* CreateFirstRunHelper();
526 #endif // defined(OS_CHROMEOS)
528 private:
529 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
530 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
531 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
532 friend class internal::RootWindowController;
533 friend class internal::ScopedTargetRootWindow;
534 friend class test::ShellTestApi;
535 friend class shell::WindowWatcher;
537 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
539 // Takes ownership of |delegate|.
540 explicit Shell(ShellDelegate* delegate);
541 virtual ~Shell();
543 void Init();
545 // Initializes virtual keyboard controller and attaches it to |root|.
546 void InitKeyboard(internal::RootWindowController* root);
548 // Initializes the root window so that it can host browser windows.
549 void InitRootWindow(aura::RootWindow* root_window);
551 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
552 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
554 // Overridden from ui::EventTarget:
555 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
556 virtual EventTarget* GetParentTarget() OVERRIDE;
557 virtual void OnEvent(ui::Event* event) OVERRIDE;
559 // Overridden from aura::client::ActivationChangeObserver:
560 virtual void OnWindowActivated(aura::Window* gained_active,
561 aura::Window* lost_active) OVERRIDE;
563 static Shell* instance_;
565 // If set before the Shell is initialized, the mouse cursor will be hidden
566 // when the screen is initially created.
567 static bool initially_hide_cursor_;
569 ScreenAsh* screen_;
571 // When no explicit target display/RootWindow is given, new windows are
572 // created on |scoped_target_root_window_| , unless NULL in
573 // which case they are created on |target_root_window_|.
574 // |target_root_window_| never becomes NULL during the session.
575 aura::Window* target_root_window_;
576 aura::Window* scoped_target_root_window_;
578 // The CompoundEventFilter owned by aura::Env object.
579 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
581 std::vector<WindowAndBoundsPair> to_restore_;
583 scoped_ptr<keyboard::KeyboardController> keyboard_controller_;
584 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
585 scoped_ptr<AcceleratorController> accelerator_controller_;
586 scoped_ptr<ShellDelegate> delegate_;
587 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
588 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
589 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
590 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
591 scoped_ptr<SessionStateDelegate> session_state_delegate_;
592 scoped_ptr<AccessibilityDelegate> accessibility_delegate_;
593 scoped_ptr<NewWindowDelegate> new_window_delegate_;
594 scoped_ptr<MediaDelegate> media_delegate_;
595 scoped_ptr<LauncherDelegate> launcher_delegate_;
596 scoped_ptr<LauncherItemDelegateManager> launcher_item_delegate_manager_;
598 scoped_ptr<LauncherModel> launcher_model_;
599 scoped_ptr<ash::WindowPositioner> window_positioner_;
601 scoped_ptr<internal::AppListController> app_list_controller_;
603 scoped_ptr<internal::DragDropController> drag_drop_controller_;
604 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
605 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
606 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
607 scoped_ptr<views::corewm::WindowModalityController>
608 window_modality_controller_;
609 scoped_ptr<views::corewm::TooltipController> tooltip_controller_;
610 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
611 scoped_ptr<PowerButtonController> power_button_controller_;
612 scoped_ptr<LockStateController> lock_state_controller_;
613 scoped_ptr<MruWindowTracker> mru_window_tracker_;
614 scoped_ptr<UserActivityDetector> user_activity_detector_;
615 scoped_ptr<VideoDetector> video_detector_;
616 scoped_ptr<WindowCycleController> window_cycle_controller_;
617 scoped_ptr<WindowSelectorController> window_selector_controller_;
618 scoped_ptr<internal::FocusCycler> focus_cycler_;
619 scoped_ptr<DisplayController> display_controller_;
620 scoped_ptr<HighContrastController> high_contrast_controller_;
621 scoped_ptr<MagnificationController> magnification_controller_;
622 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
623 scoped_ptr<AutoclickController> autoclick_controller_;
624 scoped_ptr<aura::client::FocusClient> focus_client_;
625 scoped_ptr<aura::client::UserActionClient> user_action_client_;
626 aura::client::ActivationClient* activation_client_;
627 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
628 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
629 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
630 scoped_ptr<internal::EventClientImpl> event_client_;
631 scoped_ptr<internal::EventTransformationHandler>
632 event_transformation_handler_;
633 scoped_ptr<RootWindowHostFactory> root_window_host_factory_;
635 // An event filter that rewrites or drops an event.
636 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
638 // An event filter that pre-handles key events while the partial
639 // screenshot UI or the keyboard overlay is active.
640 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
642 // An event filter for logging keyboard-related metrics.
643 scoped_ptr<internal::KeyboardUMAEventFilter> keyboard_metrics_filter_;
645 // An event filter which handles system level gestures
646 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
648 // An event filter that pre-handles global accelerators.
649 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
651 // An event filter that pre-handles all key events to send them to an IME.
652 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
654 scoped_ptr<internal::DisplayManager> display_manager_;
655 scoped_ptr<base::WeakPtrFactory<internal::DisplayManager> >
656 weak_display_manager_factory_;
658 scoped_ptr<internal::LocaleNotificationController>
659 locale_notification_controller_;
661 #if defined(OS_CHROMEOS)
662 scoped_ptr<internal::PowerEventObserver> power_event_observer_;
663 scoped_ptr<internal::UserActivityNotifier> user_activity_notifier_;
664 scoped_ptr<internal::VideoActivityNotifier> video_activity_notifier_;
665 #if defined(USE_X11)
666 // Controls video output device state.
667 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
668 scoped_ptr<internal::OutputConfiguratorAnimation>
669 output_configurator_animation_;
670 scoped_ptr<internal::DisplayErrorObserver> display_error_observer_;
672 // Listens for output changes and updates the display manager.
673 scoped_ptr<internal::DisplayChangeObserver> display_change_observer_;
674 #endif // defined(USE_X11)
675 #endif // defined(OS_CHROMEOS)
677 scoped_ptr<internal::ResolutionNotificationController>
678 resolution_notification_controller_;
680 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
681 // pointer to vend to test code.
682 AshNativeCursorManager* native_cursor_manager_;
683 views::corewm::CursorManager cursor_manager_;
685 ObserverList<ShellObserver> observers_;
687 // Used by ash/shell.
688 content::BrowserContext* browser_context_;
690 // For testing only: simulate that a modal window is open
691 bool simulate_modal_window_open_for_testing_;
693 bool is_touch_hud_projection_enabled_;
695 DISALLOW_COPY_AND_ASSIGN(Shell);
698 } // namespace ash
700 #endif // ASH_SHELL_H_