Disable Convolver.SIMDVerification under the ThreadSanitizer.
[chromium-blink-merge.git] / ash / shell.h
blob237a1a88666f0ed9273883558034094ab5a40b88
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/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"
28 class CommandLine;
30 namespace app_list {
31 class ApplicationDragAndDropHost;
33 namespace aura {
34 class EventFilter;
35 class RootWindow;
36 class Window;
37 namespace client {
38 class ActivationClient;
39 class FocusClient;
40 class UserActionClient;
43 namespace chromeos {
44 class OutputConfigurator;
46 namespace content {
47 class BrowserContext;
50 namespace gfx {
51 class ImageSkia;
52 class Point;
53 class Rect;
55 namespace ui {
56 class Layer;
58 namespace views {
59 class NonClientFrameView;
60 class Widget;
61 namespace corewm {
62 class CompoundEventFilter;
63 class InputMethodEventFilter;
64 class ShadowController;
65 class TooltipController;
66 class VisibilityController;
67 class WindowModalityController;
71 namespace ash {
73 class AcceleratorController;
74 class AshNativeCursorManager;
75 class CapsLockDelegate;
76 class DesktopBackgroundController;
77 class DisplayController;
78 class HighContrastController;
79 class Launcher;
80 class LauncherDelegate;
81 class LauncherModel;
82 class MagnificationController;
83 class MruWindowTracker;
84 class NestedDispatcherController;
85 class PartialMagnificationController;
86 class PowerButtonController;
87 class RootWindowHostFactory;
88 class ScreenAsh;
89 class LockStateController;
90 class SessionStateDelegate;
91 class ShellDelegate;
92 class ShellObserver;
93 class SystemTray;
94 class SystemTrayDelegate;
95 class SystemTrayNotifier;
96 class UserActivityDetector;
97 class UserWallpaperDelegate;
98 class VideoDetector;
99 class WebNotificationTray;
100 class WindowCycleController;
101 class WindowSelectorController;
103 namespace internal {
104 class AcceleratorFilter;
105 class ActivationController;
106 class AppListController;
107 class CaptureController;
108 class DisplayChangeObserverX11;
109 class DisplayErrorObserver;
110 class DisplayManager;
111 class DragDropController;
112 class EventClientImpl;
113 class EventRewriterEventFilter;
114 class EventTransformationHandler;
115 class FocusCycler;
116 class LocaleNotificationController;
117 class MouseCursorEventFilter;
118 class OutputConfiguratorAnimation;
119 class OverlayEventFilter;
120 class ResizeShadowController;
121 class RootWindowController;
122 class RootWindowLayoutManager;
123 class ScopedTargetRootWindow;
124 class ScreenPositionController;
125 class SlowAnimationEventFilter;
126 class StatusAreaWidget;
127 class SystemGestureEventFilter;
128 class SystemModalContainerEventFilter;
129 class TouchObserverHUD;
132 namespace shell {
133 class WindowWatcher;
136 namespace test {
137 class ShellTestApi;
140 // Shell is a singleton object that presents the Shell API and implements the
141 // RootWindow's delegate interface.
143 // Upon creation, the Shell sets itself as the RootWindow's delegate, which
144 // takes ownership of the Shell.
145 class ASH_EXPORT Shell
146 : public internal::SystemModalContainerEventFilterDelegate,
147 public ui::EventTarget,
148 public aura::client::ActivationChangeObserver {
149 public:
150 typedef std::vector<aura::RootWindow*> RootWindowList;
151 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
153 enum Direction {
154 FORWARD,
155 BACKWARD
158 // A shell must be explicitly created so that it can call |Init()| with the
159 // delegate set. |delegate| can be NULL (if not required for initialization).
160 // Takes ownership of |delegate|.
161 static Shell* CreateInstance(ShellDelegate* delegate);
163 // Should never be called before |CreateInstance()|.
164 static Shell* GetInstance();
166 // Returns true if the ash shell has been instantiated.
167 static bool HasInstance();
169 static void DeleteInstance();
171 // Returns the root window controller for the primary root window.
172 // TODO(oshima): move this to |RootWindowController|
173 static internal::RootWindowController* GetPrimaryRootWindowController();
175 // Returns all root window controllers.
176 // TODO(oshima): move this to |RootWindowController|
177 static RootWindowControllerList GetAllRootWindowControllers();
179 // Returns the primary RootWindow. The primary RootWindow is the one
180 // that has a launcher.
181 static aura::RootWindow* GetPrimaryRootWindow();
183 // Returns a RootWindow when used as a target when creating a new window.
184 // The root window of the active window is used in most cases, but can
185 // be overridden by using ScopedTargetRootWindow().
186 // If you want to get a RootWindow of the active window, just use
187 // |wm::GetActiveWindow()->GetRootWindow()|.
188 // TODO(oshima): Rename to GetTargetRootWindow() crbug.com/266378.
189 static aura::RootWindow* GetActiveRootWindow();
191 // Returns the global Screen object that's always active in ash.
192 static gfx::Screen* GetScreen();
194 // Returns all root windows.
195 static RootWindowList GetAllRootWindows();
197 static aura::Window* GetContainer(aura::RootWindow* root_window,
198 int container_id);
199 static const aura::Window* GetContainer(const aura::RootWindow* root_window,
200 int container_id);
202 // Returns the list of containers that match |container_id| in
203 // all root windows. If |priority_root| is given, the container
204 // in the |priority_root| will be inserted at the top of the list.
205 static std::vector<aura::Window*> GetContainersFromAllRootWindows(
206 int container_id,
207 aura::RootWindow* priority_root);
209 // True if an experimental maximize mode is enabled which forces browser and
210 // application windows to be maximized only.
211 static bool IsForcedMaximizeMode();
213 void set_active_root_window(aura::RootWindow* target_root_window) {
214 target_root_window_ = target_root_window;
217 // Shows the context menu for the background and launcher at
218 // |location_in_screen| (in screen coordinates).
219 void ShowContextMenu(const gfx::Point& location_in_screen,
220 ui::MenuSourceType source_type);
222 // Toggles the app list. |window| specifies in which display the app
223 // list should be shown. If this is NULL, the active root window
224 // will be used.
225 void ToggleAppList(aura::Window* anchor);
227 // If |drag_and_drop_host| is not NULL it will be called upon drag and drop
228 // operations outside the application list.
229 void SetDragAndDropHostOfCurrentAppList(
230 app_list::ApplicationDragAndDropHost* drag_and_drop_host);
232 // Returns app list target visibility.
233 bool GetAppListTargetVisibility() const;
235 // Returns app list window or NULL if it is not visible.
236 aura::Window* GetAppListWindow();
238 // Returns true if a system-modal dialog window is currently open.
239 bool IsSystemModalWindowOpen() const;
241 // For testing only: set simulation that a modal window is open
242 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
243 simulate_modal_window_open_for_testing_ = modal_window_open;
246 // Creates a default views::NonClientFrameView for use by windows in the
247 // Ash environment.
248 views::NonClientFrameView* CreateDefaultNonClientFrameView(
249 views::Widget* widget);
251 // Rotates focus through containers that can receive focus.
252 void RotateFocus(Direction direction);
254 // Sets the work area insets of the display that contains |window|,
255 // this notifies observers too.
256 // TODO(sky): this no longer really replicates what happens and is unreliable.
257 // Remove this.
258 void SetDisplayWorkAreaInsets(aura::Window* window,
259 const gfx::Insets& insets);
261 // Called when the user logs in.
262 void OnLoginStateChanged(user::LoginStatus status);
264 // Called when the login status changes.
265 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
266 void UpdateAfterLoginStatusChange(user::LoginStatus status);
268 // Called when the application is exiting.
269 void OnAppTerminating();
271 // Called when the screen is locked (after the lock window is visible) or
272 // unlocked.
273 void OnLockStateChanged(bool locked);
275 // Initializes |launcher_|. Does nothing if it's already initialized.
276 void CreateLauncher();
278 // Show launcher view if it was created hidden (before session has started).
279 void ShowLauncher();
281 // Adds/removes observer.
282 void AddShellObserver(ShellObserver* observer);
283 void RemoveShellObserver(ShellObserver* observer);
285 #if !defined(OS_MACOSX)
286 AcceleratorController* accelerator_controller() {
287 return accelerator_controller_.get();
289 #endif // !defined(OS_MACOSX)
291 internal::DisplayManager* display_manager() {
292 return display_manager_.get();
294 views::corewm::InputMethodEventFilter* input_method_filter() {
295 return input_method_filter_.get();
297 views::corewm::CompoundEventFilter* env_filter() {
298 return env_filter_.get();
300 views::corewm::TooltipController* tooltip_controller() {
301 return tooltip_controller_.get();
303 internal::EventRewriterEventFilter* event_rewriter_filter() {
304 return event_rewriter_filter_.get();
306 internal::OverlayEventFilter* overlay_filter() {
307 return overlay_filter_.get();
309 DesktopBackgroundController* desktop_background_controller() {
310 return desktop_background_controller_.get();
312 PowerButtonController* power_button_controller() {
313 return power_button_controller_.get();
315 LockStateController* lock_state_controller() {
316 return lock_state_controller_.get();
318 MruWindowTracker* mru_window_tracker() {
319 return mru_window_tracker_.get();
321 UserActivityDetector* user_activity_detector() {
322 return user_activity_detector_.get();
324 VideoDetector* video_detector() {
325 return video_detector_.get();
327 WindowCycleController* window_cycle_controller() {
328 return window_cycle_controller_.get();
330 WindowSelectorController* window_selector_controller() {
331 return window_selector_controller_.get();
333 internal::FocusCycler* focus_cycler() {
334 return focus_cycler_.get();
336 DisplayController* display_controller() {
337 return display_controller_.get();
339 internal::MouseCursorEventFilter* mouse_cursor_filter() {
340 return mouse_cursor_filter_.get();
342 internal::EventTransformationHandler* event_transformation_handler() {
343 return event_transformation_handler_.get();
345 views::corewm::CursorManager* cursor_manager() { return &cursor_manager_; }
347 ShellDelegate* delegate() { return delegate_.get(); }
349 UserWallpaperDelegate* user_wallpaper_delegate() {
350 return user_wallpaper_delegate_.get();
353 CapsLockDelegate* caps_lock_delegate() {
354 return caps_lock_delegate_.get();
357 SessionStateDelegate* session_state_delegate() {
358 return session_state_delegate_.get();
361 HighContrastController* high_contrast_controller() {
362 return high_contrast_controller_.get();
365 MagnificationController* magnification_controller() {
366 return magnification_controller_.get();
369 PartialMagnificationController* partial_magnification_controller() {
370 return partial_magnification_controller_.get();
372 aura::client::ActivationClient* activation_client() {
373 return activation_client_;
376 ScreenAsh* screen() { return screen_; }
378 // Force the shelf to query for it's current visibility state.
379 void UpdateShelfVisibility();
381 // TODO(oshima): Define an interface to access shelf/launcher
382 // state, or just use Launcher.
384 // Sets/gets the shelf auto-hide behavior on |root_window|.
385 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
386 aura::RootWindow* root_window);
387 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
388 aura::RootWindow* root_window) const;
390 // Sets/gets shelf's alignment on |root_window|.
391 void SetShelfAlignment(ShelfAlignment alignment,
392 aura::RootWindow* root_window);
393 ShelfAlignment GetShelfAlignment(aura::RootWindow* root_window);
395 // Dims or undims the screen.
396 void SetDimming(bool should_dim);
398 // Creates a modal background (a partially-opaque fullscreen window)
399 // on all displays for |window|.
400 void CreateModalBackground(aura::Window* window);
402 // Called when a modal window is removed. It will activate
403 // another modal window if any, or remove modal screens
404 // on all displays.
405 void OnModalWindowRemoved(aura::Window* removed);
407 // Returns WebNotificationTray on the primary root window.
408 WebNotificationTray* GetWebNotificationTray();
410 // Does the primary display have status area?
411 bool HasPrimaryStatusArea();
413 // Returns the system tray on primary display.
414 SystemTray* GetPrimarySystemTray();
416 SystemTrayDelegate* system_tray_delegate() {
417 return system_tray_delegate_.get();
420 SystemTrayNotifier* system_tray_notifier() {
421 return system_tray_notifier_.get();
424 static void set_initially_hide_cursor(bool hide) {
425 initially_hide_cursor_ = hide;
428 internal::ResizeShadowController* resize_shadow_controller() {
429 return resize_shadow_controller_.get();
432 // Made available for tests.
433 views::corewm::ShadowController* shadow_controller() {
434 return shadow_controller_.get();
437 content::BrowserContext* browser_context() { return browser_context_; }
438 void set_browser_context(content::BrowserContext* browser_context) {
439 browser_context_ = browser_context;
442 // Initializes the root window to be used for a secondary display.
443 void InitRootWindowForSecondaryDisplay(aura::RootWindow* root);
445 // Starts the animation that occurs on first login.
446 void DoInitialWorkspaceAnimation();
448 #if defined(OS_CHROMEOS) && defined(USE_X11)
449 // TODO(oshima): Move these objects to DisplayController.
450 chromeos::OutputConfigurator* output_configurator() {
451 return output_configurator_.get();
453 internal::OutputConfiguratorAnimation* output_configurator_animation() {
454 return output_configurator_animation_.get();
456 internal::DisplayErrorObserver* display_error_observer() {
457 return display_error_observer_.get();
459 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
461 RootWindowHostFactory* root_window_host_factory() {
462 return root_window_host_factory_.get();
465 LauncherModel* launcher_model() {
466 return launcher_model_.get();
469 // Returns the launcher delegate, creating if necesary.
470 LauncherDelegate* GetLauncherDelegate();
472 void SetTouchHudProjectionEnabled(bool enabled);
474 bool is_touch_hud_projection_enabled() const {
475 return is_touch_hud_projection_enabled_;
478 private:
479 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
480 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
481 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
482 friend class internal::RootWindowController;
483 friend class internal::ScopedTargetRootWindow;
484 friend class test::ShellTestApi;
485 friend class shell::WindowWatcher;
487 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
489 // Takes ownership of |delegate|.
490 explicit Shell(ShellDelegate* delegate);
491 virtual ~Shell();
493 void Init();
495 // Initializes the root window and root window controller so that it
496 // can host browser windows. |first_run_after_boot| is true for the
497 // primary display only first time after boot.
498 void InitRootWindowController(internal::RootWindowController* root,
499 bool first_run_after_boot);
501 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
502 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
504 // Overridden from ui::EventTarget:
505 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
506 virtual EventTarget* GetParentTarget() OVERRIDE;
507 virtual void OnEvent(ui::Event* event) OVERRIDE;
509 // Overridden from aura::client::ActivationChangeObserver:
510 virtual void OnWindowActivated(aura::Window* gained_active,
511 aura::Window* lost_active) OVERRIDE;
513 static Shell* instance_;
515 // If set before the Shell is initialized, the mouse cursor will be hidden
516 // when the screen is initially created.
517 static bool initially_hide_cursor_;
519 ScreenAsh* screen_;
521 // When no explicit target display/RootWindow is given, new windows are
522 // created on |scoped_target_root_window_| , unless NULL in
523 // which case they are created on |target_root_window_|.
524 // |target_root_window_| never becomes NULL during the session.
525 aura::RootWindow* target_root_window_;
526 aura::RootWindow* scoped_target_root_window_;
528 // The CompoundEventFilter owned by aura::Env object.
529 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
531 std::vector<WindowAndBoundsPair> to_restore_;
533 #if !defined(OS_MACOSX)
534 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
536 scoped_ptr<AcceleratorController> accelerator_controller_;
537 #endif // !defined(OS_MACOSX)
539 scoped_ptr<ShellDelegate> delegate_;
540 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
541 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
542 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
543 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
544 scoped_ptr<SessionStateDelegate> session_state_delegate_;
545 scoped_ptr<LauncherDelegate> launcher_delegate_;
547 scoped_ptr<LauncherModel> launcher_model_;
549 scoped_ptr<internal::AppListController> app_list_controller_;
551 scoped_ptr<internal::ActivationController> activation_controller_;
552 scoped_ptr<internal::CaptureController> capture_controller_;
553 scoped_ptr<internal::DragDropController> drag_drop_controller_;
554 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
555 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
556 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
557 scoped_ptr<views::corewm::WindowModalityController>
558 window_modality_controller_;
559 scoped_ptr<views::corewm::TooltipController> tooltip_controller_;
560 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
561 scoped_ptr<PowerButtonController> power_button_controller_;
562 scoped_ptr<LockStateController> lock_state_controller_;
563 scoped_ptr<MruWindowTracker> mru_window_tracker_;
564 scoped_ptr<UserActivityDetector> user_activity_detector_;
565 scoped_ptr<VideoDetector> video_detector_;
566 scoped_ptr<WindowCycleController> window_cycle_controller_;
567 scoped_ptr<WindowSelectorController> window_selector_controller_;
568 scoped_ptr<internal::FocusCycler> focus_cycler_;
569 scoped_ptr<DisplayController> display_controller_;
570 scoped_ptr<HighContrastController> high_contrast_controller_;
571 scoped_ptr<MagnificationController> magnification_controller_;
572 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
573 scoped_ptr<aura::client::FocusClient> focus_client_;
574 scoped_ptr<aura::client::UserActionClient> user_action_client_;
575 aura::client::ActivationClient* activation_client_;
576 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
577 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
578 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
579 scoped_ptr<internal::EventClientImpl> event_client_;
580 scoped_ptr<internal::EventTransformationHandler>
581 event_transformation_handler_;
582 scoped_ptr<RootWindowHostFactory> root_window_host_factory_;
584 // An event filter that rewrites or drops an event.
585 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
587 // An event filter that pre-handles key events while the partial
588 // screenshot UI or the keyboard overlay is active.
589 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
591 // An event filter which handles system level gestures
592 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
594 #if !defined(OS_MACOSX)
595 // An event filter that pre-handles global accelerators.
596 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
597 #endif
599 // An event filter that pre-handles all key events to send them to an IME.
600 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
602 scoped_ptr<internal::DisplayManager> display_manager_;
604 scoped_ptr<internal::LocaleNotificationController>
605 locale_notification_controller_;
607 #if defined(OS_CHROMEOS) && defined(USE_X11)
608 // Controls video output device state.
609 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
610 scoped_ptr<internal::OutputConfiguratorAnimation>
611 output_configurator_animation_;
612 scoped_ptr<internal::DisplayErrorObserver> display_error_observer_;
614 // Receives output change events and udpates the display manager.
615 scoped_ptr<internal::DisplayChangeObserverX11> display_change_observer_;
616 #endif // defined(OS_CHROMEOS) && defined(USE_X11)
618 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
619 // pointer to vend to test code.
620 AshNativeCursorManager* native_cursor_manager_;
621 views::corewm::CursorManager cursor_manager_;
623 ObserverList<ShellObserver> observers_;
625 // Used by ash/shell.
626 content::BrowserContext* browser_context_;
628 // For testing only: simulate that a modal window is open
629 bool simulate_modal_window_open_for_testing_;
631 bool is_touch_hud_projection_enabled_;
633 DISALLOW_COPY_AND_ASSIGN(Shell);
636 } // namespace ash
638 #endif // ASH_SHELL_H_