blob: 493e9d94f63c0a8afe86fb67086532a0c6cc63c2 [file] [log] [blame]
[email protected]d90b8392012-06-13 09:34:561// 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_ROOT_WINDOW_CONTROLLER_H_
6#define ASH_ROOT_WINDOW_CONTROLLER_H_
[email protected]d90b8392012-06-13 09:34:567
[email protected]2b8a9bb2013-07-01 22:43:408#include <map>
dchenga94547472016-04-08 08:41:119#include <memory>
skyabcae812017-01-18 17:01:3410#include <vector>
[email protected]2b8a9bb2013-07-01 22:43:4011
[email protected]c0ce80e2012-10-05 23:28:2712#include "ash/ash_export.h"
jamescookd4649fa2016-09-30 17:50:0913#include "ash/public/cpp/shelf_types.h"
James Cookb0bf8e82017-04-09 17:01:4414#include "ash/shell_observer.h"
15#include "ash/wm/workspace/workspace_types.h"
avidb567a8a2015-12-20 17:07:2416#include "base/macros.h"
[email protected]f7c05b22013-11-12 21:07:2417#include "ui/aura/window.h"
[email protected]2f2620332014-02-28 10:07:3818#include "ui/aura/window_tree_host.h"
skyb6643832017-01-11 22:08:4519#include "ui/views/widget/widget.h"
[email protected]d90b8392012-06-13 09:34:5620
[email protected]d90b8392012-06-13 09:34:5621namespace aura {
[email protected]d90b8392012-06-13 09:34:5622class Window;
[email protected]4a59e4e2012-11-12 21:15:4023}
24
25namespace gfx {
26class Point;
27}
28
[email protected]86459e2c2013-04-10 13:39:2429namespace keyboard {
30class KeyboardController;
31}
32
[email protected]3537d472014-01-15 05:45:3133namespace ui {
34class EventHandler;
skyb6643832017-01-11 22:08:4535class MenuModel;
sky00f98a372017-01-11 06:03:4936class WindowTreeHost;
[email protected]3537d472014-01-15 05:45:3137}
38
[email protected]e319c7e2014-03-14 19:56:1439namespace views {
skyb6643832017-01-11 22:08:4540class MenuModelAdapter;
41class MenuRunner;
[email protected]e319c7e2014-03-14 19:56:1442}
43
44namespace wm {
[email protected]e319c7e2014-03-14 19:56:1445class ScopedCaptureClient;
46}
47
[email protected]d90b8392012-06-13 09:34:5648namespace ash {
skyb6643832017-01-11 22:08:4549class AlwaysOnTopController;
50class AnimatingWallpaperWidgetController;
jamescook01bf23e72017-01-09 19:58:1551class AshTouchExplorationManager;
[email protected]f5c9dbc2014-04-11 08:13:4552class AshWindowTreeHost;
jamescook01bf23e72017-01-09 19:58:1553class BootSplashScreen;
mswb2416052016-06-24 21:23:4554enum class LoginStatus;
[email protected]e74aaf0a2012-10-12 18:42:2855class PanelLayoutManager;
[email protected]e74aaf0a2012-10-12 18:42:2856class ShelfLayoutManager;
[email protected]093b8d642014-04-03 20:59:2857class StackingController;
[email protected]e74aaf0a2012-10-12 18:42:2858class StatusAreaWidget;
skyb6643832017-01-11 22:08:4559class SystemModalContainerLayoutManager;
[email protected]093b8d642014-04-03 20:59:2860class SystemTray;
msw607227f82016-08-30 17:22:3961class SystemWallpaperController;
[email protected]2b8a9bb2013-07-01 22:43:4062class TouchHudDebug;
63class TouchHudProjection;
skyb6643832017-01-11 22:08:4564class WallpaperWidgetController;
sky287fe732017-01-09 22:29:1865class WmShelf;
[email protected]d90b8392012-06-13 09:34:5666class WorkspaceController;
67
sky00f98a372017-01-11 06:03:4968namespace mus {
sky8a8ffd22017-01-19 15:55:2969class WindowManager;
sky00f98a372017-01-11 06:03:4970}
71
skyb6643832017-01-11 22:08:4572namespace wm {
73class RootWindowLayoutManager;
74}
75
[email protected]d90b8392012-06-13 09:34:5676// This class maintains the per root window state for ash. This class
77// owns the root window and other dependent objects that should be
[email protected]a273d33a2013-10-17 12:41:2178// deleted upon the deletion of the root window. This object is
oshimae2818922015-07-28 01:18:5279// indirectly owned and deleted by |WindowTreeHostManager|.
[email protected]a273d33a2013-10-17 12:41:2180// The RootWindowController for particular root window is stored in
81// its property (RootWindowSettings) and can be obtained using
[email protected]056ce052014-02-21 05:19:3282// |GetRootWindowController(aura::WindowEventDispatcher*)| function.
[email protected]d141b922013-07-09 08:13:1783class ASH_EXPORT RootWindowController : public ShellObserver {
[email protected]d90b8392012-06-13 09:34:5684 public:
sky00f98a372017-01-11 06:03:4985 // Enumerates the type of display. If there is only a single display then
86 // it is primary. In a multi-display environment one monitor is deemed the
87 // PRIMARY and all others SECONDARY.
88 enum class RootWindowType { PRIMARY, SECONDARY };
89
90 ~RootWindowController() override;
91
[email protected]a273d33a2013-10-17 12:41:2192 // Creates and Initialize the RootWindowController for primary display.
[email protected]f5c9dbc2014-04-11 08:13:4593 static void CreateForPrimaryDisplay(AshWindowTreeHost* host);
[email protected]a273d33a2013-10-17 12:41:2194
95 // Creates and Initialize the RootWindowController for secondary displays.
[email protected]f5c9dbc2014-04-11 08:13:4596 static void CreateForSecondaryDisplay(AshWindowTreeHost* host);
[email protected]d90b8392012-06-13 09:34:5697
[email protected]a0afeb12012-12-10 22:57:0998 // Returns a RootWindowController of the window's root window.
[email protected]ccff3d72013-02-06 04:26:2899 static RootWindowController* ForWindow(const aura::Window* window);
[email protected]a0afeb12012-12-10 22:57:09100
[email protected]d17642d2013-09-12 23:44:38101 // Returns the RootWindowController of the target root window.
[email protected]093b8d642014-04-03 20:59:28102 static RootWindowController* ForTargetRootWindow();
[email protected]a0afeb12012-12-10 22:57:09103
skyabcae812017-01-18 17:01:34104 static std::vector<RootWindowController*> root_window_controllers() {
105 return root_window_controllers_ ? *root_window_controllers_
106 : std::vector<RootWindowController*>();
107 }
108
skyb6643832017-01-11 22:08:45109 // Configures |init_params| prior to initializing |widget|.
110 // |shell_container_id| is the id of the container to parent |widget| to.
111 // TODO(sky): remove this, http://crbug.com/671246.
112 void ConfigureWidgetInitParamsForContainer(
113 views::Widget* widget,
114 int shell_container_id,
115 views::Widget::InitParams* init_params);
116
sky00f98a372017-01-11 06:03:49117 // TODO(sky): move these to a separate class or use AshWindowTreeHost in
118 // mash. http://crbug.com/671246.
[email protected]f5c9dbc2014-04-11 08:13:45119 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
120 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
121
122 aura::WindowTreeHost* GetHost();
123 const aura::WindowTreeHost* GetHost() const;
124 aura::Window* GetRootWindow();
125 const aura::Window* GetRootWindow() const;
[email protected]d90b8392012-06-13 09:34:56126
skyb6643832017-01-11 22:08:45127 // TODO(sky): remove these. http://crbug.com/671246.
128 WmWindow* GetWindow() {
129 return const_cast<WmWindow*>(
130 const_cast<const RootWindowController*>(this)->GetWindow());
131 }
132 const WmWindow* GetWindow() const;
133
134 WorkspaceController* workspace_controller() {
135 return workspace_controller_.get();
136 }
137
138 wm::WorkspaceWindowState GetWorkspaceWindowState();
[email protected]d90b8392012-06-13 09:34:56139
sky287fe732017-01-09 22:29:18140 WmShelf* wm_shelf() const { return wm_shelf_.get(); }
jamescook788b4fc2017-05-18 16:16:06141 // TODO(jamescook): Eliminate in favor of wm_shelf().
142 WmShelf* GetShelf() const { return wm_shelf_.get(); }
jamescookbe6ed822016-06-06 20:08:55143
jamescook788b4fc2017-05-18 16:16:06144 // Initializes the shelf for this root window and notifies observers.
145 void InitializeShelf();
skyb6643832017-01-11 22:08:45146
[email protected]2b8a9bb2013-07-01 22:43:40147 // Get touch HUDs associated with this root window controller.
jamescookb8dcef522016-06-25 14:42:55148 TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
[email protected]2b8a9bb2013-07-01 22:43:40149 TouchHudProjection* touch_hud_projection() const {
150 return touch_hud_projection_;
151 }
152
153 // Set touch HUDs for this root window controller. The root window controller
154 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
155 // the widget showing a HUD is being destroyed (e.g. because of detaching a
156 // display), the HUD deletes itself.
jamescookb8dcef522016-06-25 14:42:55157 void set_touch_hud_debug(TouchHudDebug* hud) { touch_hud_debug_ = hud; }
[email protected]2b8a9bb2013-07-01 22:43:40158 void set_touch_hud_projection(TouchHudProjection* hud) {
159 touch_hud_projection_ = hud;
160 }
161
skyb6643832017-01-11 22:08:45162 PanelLayoutManager* panel_layout_manager() { return panel_layout_manager_; }
163
164 wm::RootWindowLayoutManager* root_window_layout_manager() {
165 return root_window_layout_manager_;
166 }
167
[email protected]478c6c32013-03-09 02:50:58168 // Access the shelf layout manager associated with this root
169 // window controller, NULL if no such shelf exists.
170 ShelfLayoutManager* GetShelfLayoutManager();
[email protected]d90b8392012-06-13 09:34:56171
skyb6643832017-01-11 22:08:45172 // Returns the layout manager for the appropriate modal-container. If the
173 // window is inside the lockscreen modal container, then the layout manager
174 // for that is returned. Otherwise the layout manager for the default modal
175 // container is returned.
176 // If no window is specified (i.e. |window| is null), then the lockscreen
177 // modal container is used if the screen is currently locked. Otherwise, the
178 // default modal container is used.
179 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
sky97f9a7432017-05-09 05:14:31180 aura::Window* window);
skyb6643832017-01-11 22:08:45181
182 AlwaysOnTopController* always_on_top_controller() {
183 return always_on_top_controller_.get();
184 }
185
jamescookb551aba2016-09-01 01:00:16186 // May return null, for example for a secondary monitor at the login screen.
187 StatusAreaWidget* GetStatusAreaWidget();
188
[email protected]a0afeb12012-12-10 22:57:09189 // Returns the system tray on this root window. Note that
[email protected]864b58552013-12-19 04:19:38190 // calling this on the root window that doesn't have a shelf will
[email protected]a0afeb12012-12-10 22:57:09191 // lead to a crash.
192 SystemTray* GetSystemTray();
193
oshima9a61ecf2016-06-18 10:43:05194 // True if the window can receive events on this root window.
195 bool CanWindowReceiveEvents(aura::Window* window);
196
skyb6643832017-01-11 22:08:45197 // Returns the window events will be targeted at for the specified location
198 // (in screen coordinates).
199 //
200 // NOTE: the returned window may not contain the location as resize handles
201 // may extend outside the bounds of the window.
202 WmWindow* FindEventTarget(const gfx::Point& location_in_screen);
203
204 // Gets the last location seen in a mouse event in this root window's
205 // coordinates. This may return a point outside the root window's bounds.
206 gfx::Point GetLastMouseLocationInRoot();
207
[email protected]d90b8392012-06-13 09:34:56208 aura::Window* GetContainer(int container_id);
[email protected]d8a24952013-08-05 20:05:05209 const aura::Window* GetContainer(int container_id) const;
[email protected]d90b8392012-06-13 09:34:56210
skyb6643832017-01-11 22:08:45211 // TODO(sky): remove these. http://crbug.com/671246.
212 WmWindow* GetWmContainer(int container_id) {
213 return const_cast<WmWindow*>(
214 const_cast<const RootWindowController*>(this)->GetWmContainer(
215 container_id));
216 }
217 const WmWindow* GetWmContainer(int container_id) const;
218
219 WallpaperWidgetController* wallpaper_widget_controller() {
220 return wallpaper_widget_controller_.get();
221 }
222 void SetWallpaperWidgetController(WallpaperWidgetController* controller);
223
224 AnimatingWallpaperWidgetController* animating_wallpaper_widget_controller() {
225 return animating_wallpaper_widget_controller_.get();
226 }
227 void SetAnimatingWallpaperWidgetController(
228 AnimatingWallpaperWidgetController* controller);
229
[email protected]bca9a7e2012-11-10 06:25:49230 // Called when the brightness/grayscale animation from white to the login
msw607227f82016-08-30 17:22:39231 // wallpaper image has started. Starts |boot_splash_screen_|'s hiding
232 // animation (if the screen is non-NULL).
msw3f439af2016-09-08 22:35:26233 void OnInitialWallpaperAnimationStarted();
[email protected]bca9a7e2012-11-10 06:25:49234
msw607227f82016-08-30 17:22:39235 // Called when the wallpaper animation is finished. Updates
236 // |system_wallpaper_| to be black and drops |boot_splash_screen_| and moves
237 // the wallpaper controller into the root window controller. |widget| holds
238 // the wallpaper image, or NULL if the wallpaper is a solid color.
[email protected]0bf61732013-07-02 04:35:10239 void OnWallpaperAnimationFinished(views::Widget* widget);
[email protected]d90b8392012-06-13 09:34:56240
[email protected]6675e1c2012-09-11 09:15:45241 // Deletes associated objects and clears the state, but doesn't delete
242 // the root window yet. This is used to delete a secondary displays'
243 // root window safely when the display disconnect signal is received,
gab2998ee72017-05-05 16:23:50244 // which may come while we're in the nested run loop.
[email protected]6675e1c2012-09-11 09:15:45245 void Shutdown();
246
[email protected]d90b8392012-06-13 09:34:56247 // Deletes all child windows and performs necessary cleanup.
248 void CloseChildWindows();
249
[email protected]f1853122012-06-27 16:21:26250 // Moves child windows to |dest|.
[email protected]bf9cdb362013-10-25 19:22:45251 void MoveWindowsTo(aura::Window* dest);
[email protected]f1853122012-06-27 16:21:26252
[email protected]e74aaf0a2012-10-12 18:42:28253 // Force the shelf to query for it's current visibility state.
254 void UpdateShelfVisibility();
255
[email protected]2b8a9bb2013-07-01 22:43:40256 // Initialize touch HUDs if necessary.
257 void InitTouchHuds();
258
[email protected]2c9171d22013-12-10 21:55:10259 // Returns the topmost window or one of its transient parents, if any of them
260 // are in fullscreen mode.
varkhad99fa94f2015-06-29 22:35:46261 aura::Window* GetWindowForFullscreenMode();
[email protected]2ee2f5d2013-01-10 23:37:16262
[email protected]b6ba05d902013-10-04 21:38:45263 // Activate virtual keyboard on current root window controller.
264 void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
265
266 // Deactivate virtual keyboard on current root window controller.
267 void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
268
[email protected]602022b2014-03-31 17:07:31269 // Tests if a window is associated with the virtual keyboard.
270 bool IsVirtualKeyboardWindow(aura::Window* window);
271
dmazzoniff86e3472016-06-03 19:52:32272 // If touch exploration is enabled, update the touch exploration
273 // controller so that synthesized touch events are anchored at this point.
274 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
275
skyb6643832017-01-11 22:08:45276 // Shows a context menu at the |location_in_screen|.
277 void ShowContextMenu(const gfx::Point& location_in_screen,
278 ui::MenuSourceType source_type);
279
280 // Called when the login status changes after login (such as lock/unlock).
skyb6643832017-01-11 22:08:45281 void UpdateAfterLoginStatusChange(LoginStatus status);
282
[email protected]431552c2012-10-23 00:38:33283 private:
sky00f98a372017-01-11 06:03:49284 // TODO(sky): remove this. Temporary during ash-mus unification.
285 // http://crbug.com/671246.
sky8a8ffd22017-01-19 15:55:29286 friend class mus::WindowManager;
sky00f98a372017-01-11 06:03:49287
288 // Creates a new RootWindowController with the specified host. Only one of
289 // |ash_host| or |window_tree_host| should be specified. This takes ownership
290 // of the supplied arguments.
291 // TODO(sky): mash should create AshWindowTreeHost, http://crbug.com/671246.
292 RootWindowController(AshWindowTreeHost* ash_host,
293 aura::WindowTreeHost* window_tree_host);
[email protected]a273d33a2013-10-17 12:41:21294
jamescookfda159002016-10-21 18:48:57295 // Initializes the RootWindowController based on |root_window_type|.
296 void Init(RootWindowType root_window_type);
[email protected]a273d33a2013-10-17 12:41:21297
[email protected]756bda12013-07-03 08:17:06298 void InitLayoutManagers();
299
skyb6643832017-01-11 22:08:45300 // Creates the containers (WmWindows) used by the shell.
301 void CreateContainers();
302
msw607227f82016-08-30 17:22:39303 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
jamescookfda159002016-10-21 18:48:57304 // The initial color is determined by the |root_window_type| and whether or
305 // not this is the first boot.
306 void CreateSystemWallpaper(RootWindowType root_window_type);
[email protected]756bda12013-07-03 08:17:06307
[email protected]d141b922013-07-09 08:13:17308 // Enables projection touch HUD.
309 void EnableTouchHudProjection();
310
311 // Disables projection touch HUD.
312 void DisableTouchHudProjection();
313
sky27344382017-03-08 21:30:32314 // Resets Shell::GetRootWindowForNewWindows() if appropriate. This is called
skyb6643832017-01-11 22:08:45315 // during shutdown to make sure GetRootWindowForNewWindows() isn't referencing
316 // this.
317 void ResetRootForNewWindowsIfNecessary();
318
319 // Callback for MenuModelAdapter.
320 void OnMenuClosed();
sky8d971a0a2016-09-21 23:37:57321
[email protected]d141b922013-07-09 08:13:17322 // Overridden from ShellObserver.
dcheng1f4538e2014-10-27 23:57:05323 void OnTouchHudProjectionToggled(bool enabled) override;
[email protected]d141b922013-07-09 08:13:17324
dchenga94547472016-04-08 08:41:11325 std::unique_ptr<AshWindowTreeHost> ash_host_;
sky00f98a372017-01-11 06:03:49326 std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
327 // This comes from |ash_host_| or |mus_window_tree_host_|.
328 aura::WindowTreeHost* window_tree_host_;
skyee78dde2016-06-01 01:21:43329
skyb6643832017-01-11 22:08:45330 // LayoutManagers are owned by the window they are installed on.
skyb6643832017-01-11 22:08:45331 PanelLayoutManager* panel_layout_manager_ = nullptr;
332 wm::RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
333
334 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
335 std::unique_ptr<AnimatingWallpaperWidgetController>
336 animating_wallpaper_widget_controller_;
337 std::unique_ptr<WorkspaceController> workspace_controller_;
338
339 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
340
341 // Manages the context menu.
342 std::unique_ptr<ui::MenuModel> menu_model_;
343 std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_;
344 std::unique_ptr<views::MenuRunner> menu_runner_;
skyee78dde2016-06-01 01:21:43345
dchenga94547472016-04-08 08:41:11346 std::unique_ptr<StackingController> stacking_controller_;
[email protected]2a2caa02013-01-22 20:50:36347
jamescookbe6ed822016-06-06 20:08:55348 // The shelf controller for this root window. Exists for the entire lifetime
349 // of the RootWindowController so that it is safe for observers to be added
350 // to it during construction of the shelf widget and status tray.
sky287fe732017-01-09 22:29:18351 std::unique_ptr<WmShelf> wm_shelf_;
jamescookbe6ed822016-06-06 20:08:55352
jamescook788b4fc2017-05-18 16:16:06353 // TODO(jamescook): Eliminate this. It is left over from legacy shelf code and
354 // doesn't mean anything in particular.
355 bool shelf_initialized_ = false;
356
msw607227f82016-08-30 17:22:39357 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
[email protected]a825e8312014-05-05 22:05:01358
dchenga94547472016-04-08 08:41:11359 std::unique_ptr<BootSplashScreen> boot_splash_screen_;
[email protected]a825e8312014-05-05 22:05:01360 // Responsible for initializing TouchExplorationController when spoken
361 // feedback is on.
dchenga94547472016-04-08 08:41:11362 std::unique_ptr<AshTouchExplorationManager> touch_exploration_manager_;
[email protected]697f04c2012-10-03 01:15:10363
[email protected]2b8a9bb2013-07-01 22:43:40364 // Heads-up displays for touch events. These HUDs are not owned by the root
365 // window controller and manage their own lifetimes.
skyb6643832017-01-11 22:08:45366 TouchHudDebug* touch_hud_debug_ = nullptr;
367 TouchHudProjection* touch_hud_projection_ = nullptr;
[email protected]58175042013-04-01 19:27:13368
[email protected]3537d472014-01-15 05:45:31369 // Handles double clicks on the panel window header.
dchenga94547472016-04-08 08:41:11370 std::unique_ptr<ui::EventHandler> panel_container_handler_;
[email protected]a4cd6d32012-09-12 03:42:13371
dchenga94547472016-04-08 08:41:11372 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
[email protected]0bf61732013-07-02 04:35:10373
skyabcae812017-01-18 17:01:34374 static std::vector<RootWindowController*>* root_window_controllers_;
375
[email protected]d90b8392012-06-13 09:34:56376 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
377};
378
jamescook5d74ac02016-05-12 19:57:12379// On classic ash, returns the RootWindowController for the given |root_window|.
380// On mus ash, returns the RootWindowController for the primary display.
381// See RootWindowController class comment above.
[email protected]6b2d4a0b2013-09-06 06:29:54382ASH_EXPORT RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:45383 const aura::Window* root_window);
[email protected]6b2d4a0b2013-09-06 06:29:54384
[email protected]76bc4632014-06-16 19:07:46385} // namespace ash
[email protected]d90b8392012-06-13 09:34:56386
[email protected]76bc4632014-06-16 19:07:46387#endif // ASH_ROOT_WINDOW_CONTROLLER_H_