blob: 41ce0dd2019367fc0f6d46e690fb19a4a1032177 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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.
4
5#ifndef ASH_SHELL_H_
6#define ASH_SHELL_H_
7
8#include <utility>
9#include <vector>
10
11#include "ash/ash_export.h"
12#include "ash/system/user/login_status.h"
13#include "ash/wm/cursor_manager.h"
14#include "ash/wm/shelf_types.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/observer_list.h"
21#include "ui/base/events/event_target.h"
22#include "ui/gfx/insets.h"
23#include "ui/gfx/screen.h"
24#include "ui/gfx/size.h"
25
26class CommandLine;
27
28namespace aura {
29class EventFilter;
30class FocusManager;
31class RootWindow;
32class Window;
33namespace client {
34class UserActionClient;
35}
36namespace shared {
37class CompoundEventFilter;
38class InputMethodEventFilter;
39}
40}
41namespace chromeos {
42class OutputConfigurator;
43}
44namespace content {
45class BrowserContext;
46}
47
48namespace gfx {
49class ImageSkia;
50class Point;
51class Rect;
52}
53namespace ui {
54class Layer;
55}
56namespace views {
57class NonClientFrameView;
58class Widget;
59}
60
61namespace ash {
62
63class AcceleratorController;
64class CapsLockDelegate;
65class DesktopBackgroundController;
66class DisplayController;
67class HighContrastController;
68class Launcher;
69class NestedDispatcherController;
70class PowerButtonController;
71class ScreenAsh;
72class SessionStateController;
73class ShellDelegate;
74class ShellObserver;
75class SystemTray;
76class SystemTrayDelegate;
77class UserActivityDetector;
78class UserWallpaperDelegate;
79class VideoDetector;
80class WebNotificationTray;
81class WindowCycleController;
82
83namespace internal {
84class AcceleratorFilter;
85class ActivationController;
86class AppListController;
87class CaptureController;
88class DragDropController;
89class EventClientImpl;
90class EventRewriterEventFilter;
91class FocusCycler;
92class MagnificationController;
93class MouseCursorEventFilter;
94class OutputConfiguratorAnimation;
95class OverlayEventFilter;
96class ResizeShadowController;
97class RootWindowController;
98class RootWindowLayoutManager;
99class ScreenPositionController;
100class ShadowController;
101class SlowAnimationEventFilter;
102class StackingController;
103class StatusAreaWidget;
104class SystemGestureEventFilter;
105class SystemModalContainerEventFilter;
106class TooltipController;
107class TouchObserverHUD;
108class VisibilityController;
109class WindowModalityController;
110class WorkspaceController;
111}
112
113// Shell is a singleton object that presents the Shell API and implements the
114// RootWindow's delegate interface.
115//
116// Upon creation, the Shell sets itself as the RootWindow's delegate, which
117// takes ownership of the Shell.
118class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate,
119 public ui::EventTarget {
120 public:
121 typedef std::vector<aura::RootWindow*> RootWindowList;
122 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
123
124 enum Direction {
125 FORWARD,
126 BACKWARD
127 };
128
129 // Accesses private data from a Shell for testing.
130 class ASH_EXPORT TestApi {
131 public:
132 explicit TestApi(Shell* shell);
133
134 internal::RootWindowLayoutManager* root_window_layout();
135 aura::shared::InputMethodEventFilter* input_method_event_filter();
136 internal::SystemGestureEventFilter* system_gesture_event_filter();
137 internal::WorkspaceController* workspace_controller();
138 internal::ScreenPositionController* screen_position_controller();
139
140 private:
141 Shell* shell_; // not owned
142
143 DISALLOW_COPY_AND_ASSIGN(TestApi);
144 };
145
146 // A shell must be explicitly created so that it can call |Init()| with the
147 // delegate set. |delegate| can be NULL (if not required for initialization).
148 static Shell* CreateInstance(ShellDelegate* delegate);
149
150 // Should never be called before |CreateInstance()|.
151 static Shell* GetInstance();
152
153 // Returns true if the ash shell has been instantiated.
154 static bool HasInstance();
155
156 static void DeleteInstance();
157
158 // Returns the root window controller for the primary root window.
159 static internal::RootWindowController* GetPrimaryRootWindowController();
160
161 // Returns all root window controllers.
162 static RootWindowControllerList GetAllRootWindowControllers();
163
164 // Returns the primary RootWindow. The primary RootWindow is the one
165 // that has a launcher.
166 static aura::RootWindow* GetPrimaryRootWindow();
167
168 // Returns the active RootWindow. The active RootWindow is the one that
169 // contains the current active window as a decendant child. The active
170 // RootWindow remains the same even when the active window becomes NULL,
171 // until the another window who has a different root window becomes active.
172 static aura::RootWindow* GetActiveRootWindow();
173
174 // Returns the global Screen object that's always active in ash.
175 static gfx::Screen* GetScreen();
176
177 // Returns all root windows.
178 static RootWindowList GetAllRootWindows();
179
180 static aura::Window* GetContainer(aura::RootWindow* root_window,
181 int container_id);
182 static const aura::Window* GetContainer(const aura::RootWindow* root_window,
183 int container_id);
184
185 // Returns the list of containers that match |container_id| in
186 // all root windows.
187 static std::vector<aura::Window*> GetAllContainers(int container_id);
188
189 // True if "launcher per display" feature is enabled.
190 static bool IsLauncherPerDisplayEnabled();
191
192 void set_active_root_window(aura::RootWindow* active_root_window) {
193 active_root_window_ = active_root_window;
194 }
195
196 // Adds or removes |filter| from the aura::Env's pre-target event-handler
197 // list.
198 void AddEnvEventFilter(aura::EventFilter* filter);
199 void RemoveEnvEventFilter(aura::EventFilter* filter);
200
201 // Shows the context menu for the background and launcher at
202 // |location_in_screen| (in screen coordinates).
203 void ShowContextMenu(const gfx::Point& location_in_screen);
204
205 // Toggles app list.
206 void ToggleAppList();
207
208 // Returns app list target visibility.
209 bool GetAppListTargetVisibility() const;
210
211 // Returns app list window or NULL if it is not visible.
212 aura::Window* GetAppListWindow();
213
214 // Returns true if the screen is locked.
215 bool IsScreenLocked() const;
216
217 // Returns true if a modal dialog window is currently open.
218 bool IsModalWindowOpen() const;
219
220 // For testing only: set simulation that a modal window is open
221 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
222 simulate_modal_window_open_for_testing_ = modal_window_open;
223 }
224
225 // Creates a default views::NonClientFrameView for use by windows in the
226 // Ash environment.
227 views::NonClientFrameView* CreateDefaultNonClientFrameView(
228 views::Widget* widget);
229
230 // Rotates focus through containers that can receive focus.
231 void RotateFocus(Direction direction);
232
233 // Sets the work area insets of the display that contains |window|,
234 // this notifies observers too.
235 // TODO(sky): this no longer really replicates what happens and is unreliable.
236 // Remove this.
237 void SetDisplayWorkAreaInsets(aura::Window* window,
238 const gfx::Insets& insets);
239
240 // Called when the user logs in.
241 void OnLoginStateChanged(user::LoginStatus status);
242
243 // Called when the login status changes.
244 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
245 void UpdateAfterLoginStatusChange(user::LoginStatus status);
246
247 // Called when the application is exiting.
248 void OnAppTerminating();
249
250 // Called when the screen is locked (after the lock window is visible) or
251 // unlocked.
252 void OnLockStateChanged(bool locked);
253
254 // Initializes |launcher_|. Does nothing if it's already initialized.
255 void CreateLauncher();
256
257 // Show launcher view if it was created hidden (before session has started).
258 void ShowLauncher();
259
260 // Adds/removes observer.
261 void AddShellObserver(ShellObserver* observer);
262 void RemoveShellObserver(ShellObserver* observer);
263
264#if !defined(OS_MACOSX)
265 AcceleratorController* accelerator_controller() {
266 return accelerator_controller_.get();
267 }
268#endif // !defined(OS_MACOSX)
269
270 aura::shared::CompoundEventFilter* env_filter() {
271 return env_filter_.get();
272 }
273 internal::TooltipController* tooltip_controller() {
274 return tooltip_controller_.get();
275 }
276 internal::EventRewriterEventFilter* event_rewriter_filter() {
277 return event_rewriter_filter_.get();
278 }
279 internal::OverlayEventFilter* overlay_filter() {
280 return overlay_filter_.get();
281 }
282 DesktopBackgroundController* desktop_background_controller() {
283 return desktop_background_controller_.get();
284 }
285 PowerButtonController* power_button_controller() {
286 return power_button_controller_.get();
287 }
288 SessionStateController* session_state_controller() {
289 return session_state_controller_.get();
290 }
291 UserActivityDetector* user_activity_detector() {
292 return user_activity_detector_.get();
293 }
294 VideoDetector* video_detector() {
295 return video_detector_.get();
296 }
297 WindowCycleController* window_cycle_controller() {
298 return window_cycle_controller_.get();
299 }
300 internal::FocusCycler* focus_cycler() {
301 return focus_cycler_.get();
302 }
303 DisplayController* display_controller() {
304 return display_controller_.get();
305 }
306 internal::MouseCursorEventFilter* mouse_cursor_filter() {
307 return mouse_cursor_filter_.get();
308 }
309 CursorManager* cursor_manager() { return &cursor_manager_; }
310
311 ShellDelegate* delegate() { return delegate_.get(); }
312
313 UserWallpaperDelegate* user_wallpaper_delegate() {
314 return user_wallpaper_delegate_.get();
315 }
316
317 CapsLockDelegate* caps_lock_delegate() {
318 return caps_lock_delegate_.get();
319 }
320
321 HighContrastController* high_contrast_controller() {
322 return high_contrast_controller_.get();
323 }
324
325 internal::MagnificationController* magnification_controller() {
326 return magnification_controller_.get();
327 }
328
329 const ScreenAsh* screen() { return screen_; }
330
331 // Force the shelf to query for it's current visibility state.
332 void UpdateShelfVisibility();
333
334 // TODO(oshima): Define an interface to access shelf/launcher
335 // state, or just use Launcher.
336
337 // Sets/gets the shelf auto-hide behavior on |root_window|.
338 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
339 aura::RootWindow* root_window);
340 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
341 aura::RootWindow* root_window) const;
342
343 bool IsShelfAutoHideMenuHideChecked(aura::RootWindow* root);
344 ShelfAutoHideBehavior GetToggledShelfAutoHideBehavior(
345 aura::RootWindow* root_window);
346
347 // Sets/gets shelf's alignment on |root_window|.
348 void SetShelfAlignment(ShelfAlignment alignment,
349 aura::RootWindow* root_window);
350 ShelfAlignment GetShelfAlignment(aura::RootWindow* root_window);
351
352 // Dims or undims the screen.
353 void SetDimming(bool should_dim);
354
355 // Creates a modal background (a partially-opaque fullscreen window)
356 // on all displays for |window|.
357 void CreateModalBackground(aura::Window* window);
358
359 // Called when a modal window is removed. It will activate
360 // another modal window if any, or remove modal screens
361 // on all displays.
362 void OnModalWindowRemoved(aura::Window* removed);
363
364 // Returns WebNotificationTray on the primary root window.
365 WebNotificationTray* GetWebNotificationTray();
366
367 // Convenience accessor for members of StatusAreaWidget.
368 // NOTE: status_area_widget() may return NULL during shutdown;
369 // tray_delegate() and system_tray() will crash if called after
370 // status_area_widget() has been destroyed; check status_area_widget()
371 // before calling these in destructors.
372 internal::StatusAreaWidget* status_area_widget();
373 SystemTray* system_tray();
374
375 // TODO(stevenjb): Rename to system_tray_delegate().
376 SystemTrayDelegate* tray_delegate() {
377 return system_tray_delegate_.get();
378 }
379
380 static void set_initially_hide_cursor(bool hide) {
381 initially_hide_cursor_ = hide;
382 }
383
384 internal::ResizeShadowController* resize_shadow_controller() {
385 return resize_shadow_controller_.get();
386 }
387
388 // Made available for tests.
389 internal::ShadowController* shadow_controller() {
390 return shadow_controller_.get();
391 }
392
393 content::BrowserContext* browser_context() { return browser_context_; }
394 void set_browser_context(content::BrowserContext* browser_context) {
395 browser_context_ = browser_context;
396 }
397
398 // Initializes the root window to be used for a secondary display.
399 void InitRootWindowForSecondaryDisplay(aura::RootWindow* root);
400
401 // Starts the animation that occurs on first login.
402 void DoInitialWorkspaceAnimation();
403
404#if defined(OS_CHROMEOS)
405 chromeos::OutputConfigurator* output_configurator() {
406 return output_configurator_.get();
407 }
408 internal::OutputConfiguratorAnimation* output_configurator_animation() {
409 return output_configurator_animation_.get();
410 }
411#endif // defined(OS_CHROMEOS)
412
413 private:
414 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
415 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
416 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
417 friend class internal::RootWindowController;
418
419 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
420
421 explicit Shell(ShellDelegate* delegate);
422 virtual ~Shell();
423
424 void Init();
425
426 // Initializes the root window and root window controller so that it
427 // can host browser windows.
428 void InitRootWindowController(internal::RootWindowController* root);
429
430 // Initializes the layout managers and event filters specific for
431 // primary display.
432 void InitLayoutManagersForPrimaryDisplay(
433 internal::RootWindowController* root_window_controller);
434
435 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
436 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
437
438 // Overridden from ui::EventTarget:
439 virtual bool CanAcceptEvents() OVERRIDE;
440 virtual EventTarget* GetParentTarget() OVERRIDE;
441
442 static Shell* instance_;
443
444 // If set before the Shell is initialized, the mouse cursor will be hidden
445 // when the screen is initially created.
446 static bool initially_hide_cursor_;
447
448 ScreenAsh* screen_;
449
450 // Active root window. Never becomes NULL during the session.
451 aura::RootWindow* active_root_window_;
452
453 // The CompoundEventFilter owned by aura::Env object.
454 scoped_ptr<aura::shared::CompoundEventFilter> env_filter_;
455
456 std::vector<WindowAndBoundsPair> to_restore_;
457
458#if !defined(OS_MACOSX)
459 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
460
461 scoped_ptr<AcceleratorController> accelerator_controller_;
462#endif // !defined(OS_MACOSX)
463
464 scoped_ptr<ShellDelegate> delegate_;
465 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
466 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
467 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
468
469 scoped_ptr<internal::AppListController> app_list_controller_;
470
471 scoped_ptr<internal::StackingController> stacking_controller_;
472 scoped_ptr<internal::ActivationController> activation_controller_;
473 scoped_ptr<internal::CaptureController> capture_controller_;
474 scoped_ptr<internal::WindowModalityController> window_modality_controller_;
475 scoped_ptr<internal::DragDropController> drag_drop_controller_;
476 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
477 scoped_ptr<internal::ShadowController> shadow_controller_;
478 scoped_ptr<internal::TooltipController> tooltip_controller_;
479 scoped_ptr<internal::VisibilityController> visibility_controller_;
480 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
481 scoped_ptr<PowerButtonController> power_button_controller_;
482 scoped_ptr<SessionStateController> session_state_controller_;
483 scoped_ptr<UserActivityDetector> user_activity_detector_;
484 scoped_ptr<VideoDetector> video_detector_;
485 scoped_ptr<WindowCycleController> window_cycle_controller_;
486 scoped_ptr<internal::FocusCycler> focus_cycler_;
487 scoped_ptr<DisplayController> display_controller_;
488 scoped_ptr<HighContrastController> high_contrast_controller_;
489 scoped_ptr<internal::MagnificationController> magnification_controller_;
490 scoped_ptr<aura::FocusManager> focus_manager_;
491 scoped_ptr<aura::client::UserActionClient> user_action_client_;
492 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
493 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
494 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
495 scoped_ptr<internal::EventClientImpl> event_client_;
496
497 // An event filter that rewrites or drops an event.
498 scoped_ptr<internal::EventRewriterEventFilter> event_rewriter_filter_;
499
500 // An event filter that pre-handles key events while the partial
501 // screenshot UI or the keyboard overlay is active.
502 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
503
504 // An event filter which handles system level gestures
505 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
506
507#if !defined(OS_MACOSX)
508 // An event filter that pre-handles global accelerators.
509 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
510#endif
511
512 // An event filter that pre-handles all key events to send them to an IME.
513 scoped_ptr<aura::shared::InputMethodEventFilter> input_method_filter_;
514
515 // An event filter that silently keeps track of all touch events and controls
516 // a heads-up display. This is enabled only if --ash-touch-hud flag is used.
517 scoped_ptr<internal::TouchObserverHUD> touch_observer_hud_;
518
519#if defined(OS_CHROMEOS)
520 // Controls video output device state.
521 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
522 scoped_ptr<internal::OutputConfiguratorAnimation>
523 output_configurator_animation_;
524#endif // defined(OS_CHROMEOS)
525
526 CursorManager cursor_manager_;
527
528 ObserverList<ShellObserver> observers_;
529
530 // Used by ash/shell.
531 content::BrowserContext* browser_context_;
532
533 // For testing only: simulate that a modal window is open
534 bool simulate_modal_window_open_for_testing_;
535
536 DISALLOW_COPY_AND_ASSIGN(Shell);
537};
538
539} // namespace ash
540
541#endif // ASH_SHELL_H_