blob: b9222a6706c53818432e504cddbf616014f05c96 [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"
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000012#include "ash/metrics/user_metrics_recorder.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000013#include "ash/shelf/shelf_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014#include "ash/system/user/login_status.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000015#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"
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000020#include "base/memory/weak_ptr.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000021#include "base/observer_list.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000022#include "ui/aura/client/activation_change_observer.h"
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000023#include "ui/aura/window.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010024#include "ui/base/ui_base_types.h"
Torne (Richard Coles)d0247b12013-09-19 22:36:51 +010025#include "ui/events/event_target.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000026#include "ui/gfx/insets.h"
27#include "ui/gfx/screen.h"
28#include "ui/gfx/size.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000029#include "ui/views/corewm/cursor_manager.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000030
31class CommandLine;
32
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +010033namespace app_list {
34class AppListView;
35}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000036namespace aura {
37class EventFilter;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038class RootWindow;
39class Window;
40namespace client {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000041class ActivationClient;
42class FocusClient;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000043class UserActionClient;
44}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000045}
46namespace chromeos {
47class OutputConfigurator;
48}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000049
50namespace gfx {
51class ImageSkia;
52class Point;
53class Rect;
54}
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010055
56namespace keyboard {
57class KeyboardController;
58}
59
Torne (Richard Coles)58218062012-11-14 11:43:16 +000060namespace ui {
61class Layer;
62}
63namespace views {
64class NonClientFrameView;
65class Widget;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000066namespace corewm {
67class CompoundEventFilter;
68class InputMethodEventFilter;
69class ShadowController;
70class TooltipController;
71class VisibilityController;
72class WindowModalityController;
73}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000074}
75
76namespace ash {
77
78class AcceleratorController;
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000079class AccessibilityDelegate;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000080class AshNativeCursorManager;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010081class AutoclickController;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000082class CapsLockDelegate;
83class DesktopBackgroundController;
84class DisplayController;
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +010085class FirstRunHelper;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000086class GPUSupport;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000087class HighContrastController;
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000088class LockStateController;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000089class MagnificationController;
Torne (Richard Coles)0f1bc082013-11-06 12:27:47 +000090class MediaDelegate;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010091class MruWindowTracker;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000092class NestedDispatcherController;
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000093class NewWindowDelegate;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000094class PartialMagnificationController;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000095class PowerButtonController;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000096class WindowTreeHostFactory;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000097class ScreenAsh;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010098class SessionStateDelegate;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000099class Shelf;
100class ShelfDelegate;
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000101class ShelfItemDelegateManager;
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000102class ShelfModel;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000103class ShellDelegate;
104class ShellObserver;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000105class StickyKeysController;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000106class SystemTray;
107class SystemTrayDelegate;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000108class SystemTrayNotifier;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000109class ToplevelWindowEventHandler;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000110class UserActivityDetector;
111class UserWallpaperDelegate;
112class VideoDetector;
113class WebNotificationTray;
114class WindowCycleController;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100115class WindowPositioner;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100116class WindowSelectorController;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000117
118namespace internal {
119class AcceleratorFilter;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000120class AppListController;
121class CaptureController;
Torne (Richard Coles)3551c9c2013-08-23 16:39:15 +0100122class DisplayChangeObserver;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000123class DisplayErrorObserver;
124class DisplayManager;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000125class DragDropController;
126class EventClientImpl;
127class EventRewriterEventFilter;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000128class EventTransformationHandler;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000129class FocusCycler;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100130class KeyboardUMAEventFilter;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100131class LocaleNotificationController;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000132class MouseCursorEventFilter;
133class OutputConfiguratorAnimation;
134class OverlayEventFilter;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100135class PowerEventObserver;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000136class ProjectingObserver;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000137class ResizeShadowController;
Ben Murdochba5b9a62013-08-12 14:20:17 +0100138class ResolutionNotificationController;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000139class RootWindowController;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100140class ScopedTargetRootWindow;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000141class ScreenPositionController;
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000142class ShelfWindowWatcher;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000143class SlowAnimationEventFilter;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000144class StatusAreaWidget;
145class SystemGestureEventFilter;
146class SystemModalContainerEventFilter;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000147class TouchObserverHUD;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100148class UserActivityNotifier;
149class VideoActivityNotifier;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000150}
151
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000152namespace shell {
153class WindowWatcher;
154}
155
156namespace test {
157class ShellTestApi;
158}
159
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000160// Shell is a singleton object that presents the Shell API and implements the
161// RootWindow's delegate interface.
162//
163// Upon creation, the Shell sets itself as the RootWindow's delegate, which
164// takes ownership of the Shell.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000165class ASH_EXPORT Shell
166 : public internal::SystemModalContainerEventFilterDelegate,
167 public ui::EventTarget,
168 public aura::client::ActivationChangeObserver {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000169 public:
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000170 typedef std::vector<internal::RootWindowController*> RootWindowControllerList;
171
172 enum Direction {
173 FORWARD,
174 BACKWARD
175 };
176
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000177 // A shell must be explicitly created so that it can call |Init()| with the
178 // delegate set. |delegate| can be NULL (if not required for initialization).
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100179 // Takes ownership of |delegate|.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000180 static Shell* CreateInstance(ShellDelegate* delegate);
181
182 // Should never be called before |CreateInstance()|.
183 static Shell* GetInstance();
184
185 // Returns true if the ash shell has been instantiated.
186 static bool HasInstance();
187
188 static void DeleteInstance();
189
190 // Returns the root window controller for the primary root window.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000191 // TODO(oshima): move this to |RootWindowController|
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000192 static internal::RootWindowController* GetPrimaryRootWindowController();
193
194 // Returns all root window controllers.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000195 // TODO(oshima): move this to |RootWindowController|
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000196 static RootWindowControllerList GetAllRootWindowControllers();
197
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000198 // Returns the primary root Window. The primary root Window is the one that
199 // has a launcher.
200 static aura::Window* GetPrimaryRootWindow();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000201
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000202 // Returns a root Window when used as a target when creating a new window.
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100203 // The root window of the active window is used in most cases, but can
204 // be overridden by using ScopedTargetRootWindow().
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000205 // If you want to get the root Window of the active window, just use
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100206 // |wm::GetActiveWindow()->GetRootWindow()|.
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000207 static aura::Window* GetTargetRootWindow();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000208
209 // Returns the global Screen object that's always active in ash.
210 static gfx::Screen* GetScreen();
211
212 // Returns all root windows.
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000213 static aura::Window::Windows GetAllRootWindows();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000214
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000215 static aura::Window* GetContainer(aura::Window* root_window,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000216 int container_id);
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000217 static const aura::Window* GetContainer(const aura::Window* root_window,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000218 int container_id);
219
220 // Returns the list of containers that match |container_id| in
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000221 // all root windows. If |priority_root| is given, the container
222 // in the |priority_root| will be inserted at the top of the list.
223 static std::vector<aura::Window*> GetContainersFromAllRootWindows(
224 int container_id,
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000225 aura::Window* priority_root);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000226
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000227 void set_target_root_window(aura::Window* target_root_window) {
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100228 target_root_window_ = target_root_window;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000229 }
230
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000231 // Shows the context menu for the background and launcher at
232 // |location_in_screen| (in screen coordinates).
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100233 void ShowContextMenu(const gfx::Point& location_in_screen,
234 ui::MenuSourceType source_type);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000235
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000236 // Toggles the app list. |window| specifies in which display the app
237 // list should be shown. If this is NULL, the active root window
238 // will be used.
239 void ToggleAppList(aura::Window* anchor);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000240
241 // Returns app list target visibility.
242 bool GetAppListTargetVisibility() const;
243
244 // Returns app list window or NULL if it is not visible.
245 aura::Window* GetAppListWindow();
246
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +0100247 // Returns app list view or NULL if it is not visible.
248 app_list::AppListView* GetAppListView();
249
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000250 // Returns true if a system-modal dialog window is currently open.
251 bool IsSystemModalWindowOpen() const;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000252
253 // For testing only: set simulation that a modal window is open
254 void SimulateModalWindowOpenForTesting(bool modal_window_open) {
255 simulate_modal_window_open_for_testing_ = modal_window_open;
256 }
257
258 // Creates a default views::NonClientFrameView for use by windows in the
259 // Ash environment.
260 views::NonClientFrameView* CreateDefaultNonClientFrameView(
261 views::Widget* widget);
262
263 // Rotates focus through containers that can receive focus.
264 void RotateFocus(Direction direction);
265
266 // Sets the work area insets of the display that contains |window|,
267 // this notifies observers too.
268 // TODO(sky): this no longer really replicates what happens and is unreliable.
269 // Remove this.
270 void SetDisplayWorkAreaInsets(aura::Window* window,
271 const gfx::Insets& insets);
272
273 // Called when the user logs in.
274 void OnLoginStateChanged(user::LoginStatus status);
275
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000276 // Called after the logged-in user's profile is ready.
277 void OnLoginUserProfilePrepared();
278
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000279 // Called when the login status changes.
280 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
281 void UpdateAfterLoginStatusChange(user::LoginStatus status);
282
283 // Called when the application is exiting.
284 void OnAppTerminating();
285
286 // Called when the screen is locked (after the lock window is visible) or
287 // unlocked.
288 void OnLockStateChanged(bool locked);
289
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000290 // Called when a casting session is started or stopped.
291 void OnCastingSessionStartedOrStopped(bool started);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000292
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000293 // Initializes |shelf_|. Does nothing if it's already initialized.
294 void CreateShelf();
295
296 // Creates a virtual keyboard. Deletes the old virtual keyboard if it already
297 // exists.
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000298 void CreateKeyboard();
299
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000300 // Deactivates the virtual keyboard.
301 void DeactivateKeyboard();
302
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +0100303 // Show shelf view if it was created hidden (before session has started).
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000304 void ShowShelf();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000305
306 // Adds/removes observer.
307 void AddShellObserver(ShellObserver* observer);
308 void RemoveShellObserver(ShellObserver* observer);
309
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100310 keyboard::KeyboardController* keyboard_controller() {
311 return keyboard_controller_.get();
312 }
313
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000314 AcceleratorController* accelerator_controller() {
315 return accelerator_controller_.get();
316 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000317
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000318 internal::DisplayManager* display_manager() {
319 return display_manager_.get();
320 }
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100321 views::corewm::InputMethodEventFilter* input_method_filter() {
322 return input_method_filter_.get();
323 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000324 views::corewm::CompoundEventFilter* env_filter() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000325 return env_filter_.get();
326 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000327 views::corewm::TooltipController* tooltip_controller() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000328 return tooltip_controller_.get();
329 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000330 internal::OverlayEventFilter* overlay_filter() {
331 return overlay_filter_.get();
332 }
333 DesktopBackgroundController* desktop_background_controller() {
334 return desktop_background_controller_.get();
335 }
336 PowerButtonController* power_button_controller() {
337 return power_button_controller_.get();
338 }
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100339 LockStateController* lock_state_controller() {
340 return lock_state_controller_.get();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000341 }
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100342 MruWindowTracker* mru_window_tracker() {
343 return mru_window_tracker_.get();
344 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000345 UserActivityDetector* user_activity_detector() {
346 return user_activity_detector_.get();
347 }
348 VideoDetector* video_detector() {
349 return video_detector_.get();
350 }
351 WindowCycleController* window_cycle_controller() {
352 return window_cycle_controller_.get();
353 }
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100354 WindowSelectorController* window_selector_controller() {
355 return window_selector_controller_.get();
356 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000357 internal::FocusCycler* focus_cycler() {
358 return focus_cycler_.get();
359 }
360 DisplayController* display_controller() {
361 return display_controller_.get();
362 }
363 internal::MouseCursorEventFilter* mouse_cursor_filter() {
364 return mouse_cursor_filter_.get();
365 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000366 internal::EventTransformationHandler* event_transformation_handler() {
367 return event_transformation_handler_.get();
368 }
369 views::corewm::CursorManager* cursor_manager() { return &cursor_manager_; }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000370
371 ShellDelegate* delegate() { return delegate_.get(); }
372
373 UserWallpaperDelegate* user_wallpaper_delegate() {
374 return user_wallpaper_delegate_.get();
375 }
376
377 CapsLockDelegate* caps_lock_delegate() {
378 return caps_lock_delegate_.get();
379 }
380
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100381 SessionStateDelegate* session_state_delegate() {
382 return session_state_delegate_.get();
383 }
384
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000385 AccessibilityDelegate* accessibility_delegate() {
386 return accessibility_delegate_.get();
387 }
388
389 NewWindowDelegate* new_window_delegate() {
390 return new_window_delegate_.get();
391 }
392
Torne (Richard Coles)0f1bc082013-11-06 12:27:47 +0000393 MediaDelegate* media_delegate() {
394 return media_delegate_.get();
395 }
396
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000397 HighContrastController* high_contrast_controller() {
398 return high_contrast_controller_.get();
399 }
400
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000401 MagnificationController* magnification_controller() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000402 return magnification_controller_.get();
403 }
404
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000405 PartialMagnificationController* partial_magnification_controller() {
406 return partial_magnification_controller_.get();
407 }
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100408
409 AutoclickController* autoclick_controller() {
410 return autoclick_controller_.get();
411 }
412
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000413 aura::client::ActivationClient* activation_client() {
414 return activation_client_;
415 }
416
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000417 ShelfItemDelegateManager* shelf_item_delegate_manager() {
418 return shelf_item_delegate_manager_.get();
Torne (Richard Coles)424c4d72013-08-30 15:14:49 +0100419 }
420
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000421 // Force the shelf to query for it's current visibility state.
422 void UpdateShelfVisibility();
423
424 // TODO(oshima): Define an interface to access shelf/launcher
425 // state, or just use Launcher.
426
427 // Sets/gets the shelf auto-hide behavior on |root_window|.
428 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior,
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000429 aura::Window* root_window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000430 ShelfAutoHideBehavior GetShelfAutoHideBehavior(
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000431 aura::Window* root_window) const;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000432
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000433 // Sets/gets shelf's alignment on |root_window|.
434 void SetShelfAlignment(ShelfAlignment alignment,
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000435 aura::Window* root_window);
436 ShelfAlignment GetShelfAlignment(aura::Window* root_window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000437
438 // Dims or undims the screen.
439 void SetDimming(bool should_dim);
440
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100441 // Notifies |observers_| when entering or exiting fullscreen mode in
442 // |root_window|.
443 void NotifyFullscreenStateChange(bool is_fullscreen,
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000444 aura::Window* root_window);
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100445
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000446 // Creates a modal background (a partially-opaque fullscreen window)
447 // on all displays for |window|.
448 void CreateModalBackground(aura::Window* window);
449
450 // Called when a modal window is removed. It will activate
451 // another modal window if any, or remove modal screens
452 // on all displays.
453 void OnModalWindowRemoved(aura::Window* removed);
454
455 // Returns WebNotificationTray on the primary root window.
456 WebNotificationTray* GetWebNotificationTray();
457
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000458 // Does the primary display have status area?
459 bool HasPrimaryStatusArea();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000460
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000461 // Returns the system tray on primary display.
462 SystemTray* GetPrimarySystemTray();
463
464 SystemTrayDelegate* system_tray_delegate() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000465 return system_tray_delegate_.get();
466 }
467
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000468 SystemTrayNotifier* system_tray_notifier() {
469 return system_tray_notifier_.get();
470 }
471
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000472 static void set_initially_hide_cursor(bool hide) {
473 initially_hide_cursor_ = hide;
474 }
475
476 internal::ResizeShadowController* resize_shadow_controller() {
477 return resize_shadow_controller_.get();
478 }
479
480 // Made available for tests.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000481 views::corewm::ShadowController* shadow_controller() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000482 return shadow_controller_.get();
483 }
484
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000485 // Starts the animation that occurs on first login.
486 void DoInitialWorkspaceAnimation();
487
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000488#if defined(OS_CHROMEOS)
489#if defined(USE_X11)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000490 // TODO(oshima): Move these objects to DisplayController.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000491 chromeos::OutputConfigurator* output_configurator() {
492 return output_configurator_.get();
493 }
494 internal::OutputConfiguratorAnimation* output_configurator_animation() {
495 return output_configurator_animation_.get();
496 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000497 internal::DisplayErrorObserver* display_error_observer() {
498 return display_error_observer_.get();
499 }
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000500#endif // defined(USE_X11)
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000501
Ben Murdochba5b9a62013-08-12 14:20:17 +0100502 internal::ResolutionNotificationController*
503 resolution_notification_controller() {
504 return resolution_notification_controller_.get();
505 }
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000506#endif // defined(OS_CHROMEOS)
Ben Murdochba5b9a62013-08-12 14:20:17 +0100507
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000508 WindowTreeHostFactory* window_tree_host_factory() {
509 return window_tree_host_factory_.get();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000510 }
511
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000512 ShelfModel* shelf_model() {
513 return shelf_model_.get();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000514 }
515
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100516 WindowPositioner* window_positioner() {
517 return window_positioner_.get();
518 }
519
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000520 // Returns the launcher delegate, creating if necesary.
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000521 ShelfDelegate* GetShelfDelegate();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000522
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000523 UserMetricsRecorder* metrics() {
524 return user_metrics_recorder_.get();
525 }
526
Ben Murdocheb525c52013-07-10 11:40:50 +0100527 void SetTouchHudProjectionEnabled(bool enabled);
528
529 bool is_touch_hud_projection_enabled() const {
530 return is_touch_hud_projection_enabled_;
531 }
532
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +0100533#if defined(OS_CHROMEOS)
534 // Creates instance of FirstRunHelper. Caller is responsible for deleting
535 // returned object.
536 ash::FirstRunHelper* CreateFirstRunHelper();
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000537
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000538 // Toggles cursor compositing on/off. Native cursor is disabled when cursor
539 // compositing is enabled, and vice versa.
540 void SetCursorCompositingEnabled(bool enabled);
541
542 StickyKeysController* sticky_keys_controller() {
543 return sticky_keys_controller_.get();
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000544 }
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +0100545#endif // defined(OS_CHROMEOS)
546
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000547 GPUSupport* gpu_support() { return gpu_support_.get(); }
548
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000549 private:
550 FRIEND_TEST_ALL_PREFIXES(ExtendedDesktopTest, TestCursor);
551 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, MouseEventCursors);
552 FRIEND_TEST_ALL_PREFIXES(WindowManagerTest, TransformActivate);
553 friend class internal::RootWindowController;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100554 friend class internal::ScopedTargetRootWindow;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000555 friend class test::ShellTestApi;
556 friend class shell::WindowWatcher;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000557
558 typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
559
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100560 // Takes ownership of |delegate|.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000561 explicit Shell(ShellDelegate* delegate);
562 virtual ~Shell();
563
564 void Init();
565
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000566 // Initializes virtual keyboard controller.
567 void InitKeyboard();
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100568
Torne (Richard Coles)8bcbed82013-10-22 16:41:35 +0100569 // Initializes the root window so that it can host browser windows.
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000570 void InitRootWindow(aura::Window* root_window);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000571
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000572 // ash::internal::SystemModalContainerEventFilterDelegate overrides:
573 virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE;
574
575 // Overridden from ui::EventTarget:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000576 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000577 virtual EventTarget* GetParentTarget() OVERRIDE;
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000578 virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE;
579 virtual ui::EventTargeter* GetEventTargeter() OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000580 virtual void OnEvent(ui::Event* event) OVERRIDE;
581
582 // Overridden from aura::client::ActivationChangeObserver:
583 virtual void OnWindowActivated(aura::Window* gained_active,
584 aura::Window* lost_active) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000585
586 static Shell* instance_;
587
588 // If set before the Shell is initialized, the mouse cursor will be hidden
589 // when the screen is initially created.
590 static bool initially_hide_cursor_;
591
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100592 // When no explicit target display/RootWindow is given, new windows are
593 // created on |scoped_target_root_window_| , unless NULL in
594 // which case they are created on |target_root_window_|.
595 // |target_root_window_| never becomes NULL during the session.
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000596 aura::Window* target_root_window_;
597 aura::Window* scoped_target_root_window_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000598
599 // The CompoundEventFilter owned by aura::Env object.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000600 scoped_ptr<views::corewm::CompoundEventFilter> env_filter_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000601
602 std::vector<WindowAndBoundsPair> to_restore_;
603
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000604 scoped_ptr<UserMetricsRecorder> user_metrics_recorder_;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100605 scoped_ptr<keyboard::KeyboardController> keyboard_controller_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000606 scoped_ptr<NestedDispatcherController> nested_dispatcher_controller_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000607 scoped_ptr<AcceleratorController> accelerator_controller_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000608 scoped_ptr<ShellDelegate> delegate_;
609 scoped_ptr<SystemTrayDelegate> system_tray_delegate_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000610 scoped_ptr<SystemTrayNotifier> system_tray_notifier_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000611 scoped_ptr<UserWallpaperDelegate> user_wallpaper_delegate_;
612 scoped_ptr<CapsLockDelegate> caps_lock_delegate_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100613 scoped_ptr<SessionStateDelegate> session_state_delegate_;
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000614 scoped_ptr<AccessibilityDelegate> accessibility_delegate_;
615 scoped_ptr<NewWindowDelegate> new_window_delegate_;
Torne (Richard Coles)0f1bc082013-11-06 12:27:47 +0000616 scoped_ptr<MediaDelegate> media_delegate_;
Torne (Richard Coles)a3f6a492013-12-18 16:25:09 +0000617 scoped_ptr<ShelfDelegate> shelf_delegate_;
618 scoped_ptr<ShelfItemDelegateManager> shelf_item_delegate_manager_;
619 scoped_ptr<internal::ShelfWindowWatcher> shelf_window_watcher_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000620
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +0000621 scoped_ptr<ShelfModel> shelf_model_;
622 scoped_ptr<WindowPositioner> window_positioner_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000623
624 scoped_ptr<internal::AppListController> app_list_controller_;
625
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000626 scoped_ptr<internal::DragDropController> drag_drop_controller_;
627 scoped_ptr<internal::ResizeShadowController> resize_shadow_controller_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000628 scoped_ptr<views::corewm::ShadowController> shadow_controller_;
629 scoped_ptr<views::corewm::VisibilityController> visibility_controller_;
630 scoped_ptr<views::corewm::WindowModalityController>
631 window_modality_controller_;
632 scoped_ptr<views::corewm::TooltipController> tooltip_controller_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000633 scoped_ptr<DesktopBackgroundController> desktop_background_controller_;
634 scoped_ptr<PowerButtonController> power_button_controller_;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100635 scoped_ptr<LockStateController> lock_state_controller_;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100636 scoped_ptr<MruWindowTracker> mru_window_tracker_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000637 scoped_ptr<UserActivityDetector> user_activity_detector_;
638 scoped_ptr<VideoDetector> video_detector_;
639 scoped_ptr<WindowCycleController> window_cycle_controller_;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100640 scoped_ptr<WindowSelectorController> window_selector_controller_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000641 scoped_ptr<internal::FocusCycler> focus_cycler_;
642 scoped_ptr<DisplayController> display_controller_;
643 scoped_ptr<HighContrastController> high_contrast_controller_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000644 scoped_ptr<MagnificationController> magnification_controller_;
645 scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100646 scoped_ptr<AutoclickController> autoclick_controller_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000647 scoped_ptr<aura::client::FocusClient> focus_client_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000648 scoped_ptr<aura::client::UserActionClient> user_action_client_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000649 aura::client::ActivationClient* activation_client_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000650 scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
651 scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
652 scoped_ptr<internal::SystemModalContainerEventFilter> modality_filter_;
653 scoped_ptr<internal::EventClientImpl> event_client_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000654 scoped_ptr<internal::EventTransformationHandler>
655 event_transformation_handler_;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000656 scoped_ptr<WindowTreeHostFactory> window_tree_host_factory_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000657
658 // An event filter that pre-handles key events while the partial
659 // screenshot UI or the keyboard overlay is active.
660 scoped_ptr<internal::OverlayEventFilter> overlay_filter_;
661
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100662 // An event filter for logging keyboard-related metrics.
663 scoped_ptr<internal::KeyboardUMAEventFilter> keyboard_metrics_filter_;
664
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000665 // An event filter which handles moving and resizing windows.
666 scoped_ptr<ToplevelWindowEventHandler> toplevel_window_event_handler_;
667
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000668 // An event filter which handles system level gestures
669 scoped_ptr<internal::SystemGestureEventFilter> system_gesture_filter_;
670
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000671 // An event filter that pre-handles global accelerators.
672 scoped_ptr<internal::AcceleratorFilter> accelerator_filter_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000673
674 // An event filter that pre-handles all key events to send them to an IME.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000675 scoped_ptr<views::corewm::InputMethodEventFilter> input_method_filter_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000676
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000677 scoped_ptr<internal::DisplayManager> display_manager_;
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +0000678 scoped_ptr<base::WeakPtrFactory<internal::DisplayManager> >
679 weak_display_manager_factory_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000680
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100681 scoped_ptr<internal::LocaleNotificationController>
682 locale_notification_controller_;
683
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100684#if defined(OS_CHROMEOS)
685 scoped_ptr<internal::PowerEventObserver> power_event_observer_;
686 scoped_ptr<internal::UserActivityNotifier> user_activity_notifier_;
687 scoped_ptr<internal::VideoActivityNotifier> video_activity_notifier_;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000688 scoped_ptr<StickyKeysController> sticky_keys_controller_;
689 scoped_ptr<internal::ResolutionNotificationController>
690 resolution_notification_controller_;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100691#if defined(USE_X11)
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000692 // Controls video output device state.
693 scoped_ptr<chromeos::OutputConfigurator> output_configurator_;
694 scoped_ptr<internal::OutputConfiguratorAnimation>
695 output_configurator_animation_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000696 scoped_ptr<internal::DisplayErrorObserver> display_error_observer_;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000697 scoped_ptr<internal::ProjectingObserver> projecting_observer_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000698
Torne (Richard Coles)3551c9c2013-08-23 16:39:15 +0100699 // Listens for output changes and updates the display manager.
700 scoped_ptr<internal::DisplayChangeObserver> display_change_observer_;
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000701
702 scoped_ptr<ui::EventHandler> magnifier_key_scroll_handler_;
703 scoped_ptr<ui::EventHandler> speech_feedback_handler_;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +0100704#endif // defined(USE_X11)
705#endif // defined(OS_CHROMEOS)
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000706
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000707 // |native_cursor_manager_| is owned by |cursor_manager_|, but we keep a
708 // pointer to vend to test code.
709 AshNativeCursorManager* native_cursor_manager_;
710 views::corewm::CursorManager cursor_manager_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000711
712 ObserverList<ShellObserver> observers_;
713
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000714 // For testing only: simulate that a modal window is open
715 bool simulate_modal_window_open_for_testing_;
716
Ben Murdocheb525c52013-07-10 11:40:50 +0100717 bool is_touch_hud_projection_enabled_;
718
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +0000719 // Injected content::GPUDataManager support.
720 scoped_ptr<GPUSupport> gpu_support_;
721
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000722 DISALLOW_COPY_AND_ASSIGN(Shell);
723};
724
725} // namespace ash
726
727#endif // ASH_SHELL_H_