blob: 1971f4b217df573e85389d153c1a3fa4e9209123 [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;
James Cook840177e2017-05-25 02:20:0156class Shelf;
[email protected]e74aaf0a2012-10-12 18:42:2857class ShelfLayoutManager;
[email protected]093b8d642014-04-03 20:59:2858class StackingController;
[email protected]e74aaf0a2012-10-12 18:42:2859class StatusAreaWidget;
skyb6643832017-01-11 22:08:4560class SystemModalContainerLayoutManager;
[email protected]093b8d642014-04-03 20:59:2861class SystemTray;
msw607227f82016-08-30 17:22:3962class SystemWallpaperController;
[email protected]2b8a9bb2013-07-01 22:43:4063class TouchHudDebug;
64class TouchHudProjection;
skyb6643832017-01-11 22:08:4565class WallpaperWidgetController;
varkha6b016b0f2017-05-26 16:14:1866class WmWindow;
[email protected]d90b8392012-06-13 09:34:5667class WorkspaceController;
68
sky00f98a372017-01-11 06:03:4969namespace mus {
sky8a8ffd22017-01-19 15:55:2970class WindowManager;
sky00f98a372017-01-11 06:03:4971}
72
skyb6643832017-01-11 22:08:4573namespace wm {
74class RootWindowLayoutManager;
75}
76
[email protected]d90b8392012-06-13 09:34:5677// This class maintains the per root window state for ash. This class
78// owns the root window and other dependent objects that should be
[email protected]a273d33a2013-10-17 12:41:2179// deleted upon the deletion of the root window. This object is
oshimae2818922015-07-28 01:18:5280// indirectly owned and deleted by |WindowTreeHostManager|.
[email protected]a273d33a2013-10-17 12:41:2181// The RootWindowController for particular root window is stored in
82// its property (RootWindowSettings) and can be obtained using
[email protected]056ce052014-02-21 05:19:3283// |GetRootWindowController(aura::WindowEventDispatcher*)| function.
[email protected]d141b922013-07-09 08:13:1784class ASH_EXPORT RootWindowController : public ShellObserver {
[email protected]d90b8392012-06-13 09:34:5685 public:
sky00f98a372017-01-11 06:03:4986 // Enumerates the type of display. If there is only a single display then
87 // it is primary. In a multi-display environment one monitor is deemed the
88 // PRIMARY and all others SECONDARY.
89 enum class RootWindowType { PRIMARY, SECONDARY };
90
91 ~RootWindowController() override;
92
[email protected]a273d33a2013-10-17 12:41:2193 // Creates and Initialize the RootWindowController for primary display.
[email protected]f5c9dbc2014-04-11 08:13:4594 static void CreateForPrimaryDisplay(AshWindowTreeHost* host);
[email protected]a273d33a2013-10-17 12:41:2195
96 // Creates and Initialize the RootWindowController for secondary displays.
[email protected]f5c9dbc2014-04-11 08:13:4597 static void CreateForSecondaryDisplay(AshWindowTreeHost* host);
[email protected]d90b8392012-06-13 09:34:5698
[email protected]a0afeb12012-12-10 22:57:0999 // Returns a RootWindowController of the window's root window.
[email protected]ccff3d72013-02-06 04:26:28100 static RootWindowController* ForWindow(const aura::Window* window);
[email protected]a0afeb12012-12-10 22:57:09101
[email protected]d17642d2013-09-12 23:44:38102 // Returns the RootWindowController of the target root window.
[email protected]093b8d642014-04-03 20:59:28103 static RootWindowController* ForTargetRootWindow();
[email protected]a0afeb12012-12-10 22:57:09104
skyabcae812017-01-18 17:01:34105 static std::vector<RootWindowController*> root_window_controllers() {
106 return root_window_controllers_ ? *root_window_controllers_
107 : std::vector<RootWindowController*>();
108 }
109
skyb6643832017-01-11 22:08:45110 // Configures |init_params| prior to initializing |widget|.
111 // |shell_container_id| is the id of the container to parent |widget| to.
112 // TODO(sky): remove this, http://crbug.com/671246.
113 void ConfigureWidgetInitParamsForContainer(
114 views::Widget* widget,
115 int shell_container_id,
116 views::Widget::InitParams* init_params);
117
sky00f98a372017-01-11 06:03:49118 // TODO(sky): move these to a separate class or use AshWindowTreeHost in
119 // mash. http://crbug.com/671246.
[email protected]f5c9dbc2014-04-11 08:13:45120 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
121 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
122
123 aura::WindowTreeHost* GetHost();
124 const aura::WindowTreeHost* GetHost() const;
125 aura::Window* GetRootWindow();
126 const aura::Window* GetRootWindow() const;
[email protected]d90b8392012-06-13 09:34:56127
skyb6643832017-01-11 22:08:45128 // TODO(sky): remove these. http://crbug.com/671246.
129 WmWindow* GetWindow() {
130 return const_cast<WmWindow*>(
131 const_cast<const RootWindowController*>(this)->GetWindow());
132 }
133 const WmWindow* GetWindow() const;
134
135 WorkspaceController* workspace_controller() {
136 return workspace_controller_.get();
137 }
138
139 wm::WorkspaceWindowState GetWorkspaceWindowState();
[email protected]d90b8392012-06-13 09:34:56140
James Cook840177e2017-05-25 02:20:01141 Shelf* shelf() const { return shelf_.get(); }
142 // TODO(jamescook): Eliminate in favor of shelf().
143 Shelf* GetShelf() const { return shelf_.get(); }
jamescookbe6ed822016-06-06 20:08:55144
jamescook788b4fc2017-05-18 16:16:06145 // Initializes the shelf for this root window and notifies observers.
146 void InitializeShelf();
skyb6643832017-01-11 22:08:45147
[email protected]2b8a9bb2013-07-01 22:43:40148 // Get touch HUDs associated with this root window controller.
jamescookb8dcef522016-06-25 14:42:55149 TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
[email protected]2b8a9bb2013-07-01 22:43:40150 TouchHudProjection* touch_hud_projection() const {
151 return touch_hud_projection_;
152 }
153
154 // Set touch HUDs for this root window controller. The root window controller
155 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
156 // the widget showing a HUD is being destroyed (e.g. because of detaching a
157 // display), the HUD deletes itself.
jamescookb8dcef522016-06-25 14:42:55158 void set_touch_hud_debug(TouchHudDebug* hud) { touch_hud_debug_ = hud; }
[email protected]2b8a9bb2013-07-01 22:43:40159 void set_touch_hud_projection(TouchHudProjection* hud) {
160 touch_hud_projection_ = hud;
161 }
162
skyb6643832017-01-11 22:08:45163 PanelLayoutManager* panel_layout_manager() { return panel_layout_manager_; }
164
165 wm::RootWindowLayoutManager* root_window_layout_manager() {
166 return root_window_layout_manager_;
167 }
168
[email protected]478c6c32013-03-09 02:50:58169 // Access the shelf layout manager associated with this root
170 // window controller, NULL if no such shelf exists.
171 ShelfLayoutManager* GetShelfLayoutManager();
[email protected]d90b8392012-06-13 09:34:56172
skyb6643832017-01-11 22:08:45173 // Returns the layout manager for the appropriate modal-container. If the
174 // window is inside the lockscreen modal container, then the layout manager
175 // for that is returned. Otherwise the layout manager for the default modal
176 // container is returned.
177 // If no window is specified (i.e. |window| is null), then the lockscreen
178 // modal container is used if the screen is currently locked. Otherwise, the
179 // default modal container is used.
180 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
sky97f9a7432017-05-09 05:14:31181 aura::Window* window);
skyb6643832017-01-11 22:08:45182
183 AlwaysOnTopController* always_on_top_controller() {
184 return always_on_top_controller_.get();
185 }
186
jamescookb551aba2016-09-01 01:00:16187 // May return null, for example for a secondary monitor at the login screen.
188 StatusAreaWidget* GetStatusAreaWidget();
189
[email protected]a0afeb12012-12-10 22:57:09190 // Returns the system tray on this root window. Note that
[email protected]864b58552013-12-19 04:19:38191 // calling this on the root window that doesn't have a shelf will
[email protected]a0afeb12012-12-10 22:57:09192 // lead to a crash.
193 SystemTray* GetSystemTray();
194
oshima9a61ecf2016-06-18 10:43:05195 // True if the window can receive events on this root window.
196 bool CanWindowReceiveEvents(aura::Window* window);
197
skyb6643832017-01-11 22:08:45198 // Returns the window events will be targeted at for the specified location
199 // (in screen coordinates).
200 //
201 // NOTE: the returned window may not contain the location as resize handles
202 // may extend outside the bounds of the window.
sky4befdb0d2017-05-18 23:50:26203 aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
skyb6643832017-01-11 22:08:45204
205 // Gets the last location seen in a mouse event in this root window's
206 // coordinates. This may return a point outside the root window's bounds.
207 gfx::Point GetLastMouseLocationInRoot();
208
[email protected]d90b8392012-06-13 09:34:56209 aura::Window* GetContainer(int container_id);
[email protected]d8a24952013-08-05 20:05:05210 const aura::Window* GetContainer(int container_id) const;
[email protected]d90b8392012-06-13 09:34:56211
skyb6643832017-01-11 22:08:45212 // TODO(sky): remove these. http://crbug.com/671246.
213 WmWindow* GetWmContainer(int container_id) {
214 return const_cast<WmWindow*>(
215 const_cast<const RootWindowController*>(this)->GetWmContainer(
216 container_id));
217 }
218 const WmWindow* GetWmContainer(int container_id) const;
219
220 WallpaperWidgetController* wallpaper_widget_controller() {
221 return wallpaper_widget_controller_.get();
222 }
223 void SetWallpaperWidgetController(WallpaperWidgetController* controller);
224
225 AnimatingWallpaperWidgetController* animating_wallpaper_widget_controller() {
226 return animating_wallpaper_widget_controller_.get();
227 }
228 void SetAnimatingWallpaperWidgetController(
229 AnimatingWallpaperWidgetController* controller);
230
[email protected]bca9a7e2012-11-10 06:25:49231 // Called when the brightness/grayscale animation from white to the login
msw607227f82016-08-30 17:22:39232 // wallpaper image has started. Starts |boot_splash_screen_|'s hiding
233 // animation (if the screen is non-NULL).
msw3f439af2016-09-08 22:35:26234 void OnInitialWallpaperAnimationStarted();
[email protected]bca9a7e2012-11-10 06:25:49235
msw607227f82016-08-30 17:22:39236 // Called when the wallpaper animation is finished. Updates
237 // |system_wallpaper_| to be black and drops |boot_splash_screen_| and moves
238 // the wallpaper controller into the root window controller. |widget| holds
239 // the wallpaper image, or NULL if the wallpaper is a solid color.
[email protected]0bf61732013-07-02 04:35:10240 void OnWallpaperAnimationFinished(views::Widget* widget);
[email protected]d90b8392012-06-13 09:34:56241
[email protected]6675e1c2012-09-11 09:15:45242 // Deletes associated objects and clears the state, but doesn't delete
243 // the root window yet. This is used to delete a secondary displays'
244 // root window safely when the display disconnect signal is received,
gab2998ee72017-05-05 16:23:50245 // which may come while we're in the nested run loop.
[email protected]6675e1c2012-09-11 09:15:45246 void Shutdown();
247
[email protected]d90b8392012-06-13 09:34:56248 // Deletes all child windows and performs necessary cleanup.
249 void CloseChildWindows();
250
[email protected]f1853122012-06-27 16:21:26251 // Moves child windows to |dest|.
[email protected]bf9cdb362013-10-25 19:22:45252 void MoveWindowsTo(aura::Window* dest);
[email protected]f1853122012-06-27 16:21:26253
[email protected]e74aaf0a2012-10-12 18:42:28254 // Force the shelf to query for it's current visibility state.
255 void UpdateShelfVisibility();
256
[email protected]2b8a9bb2013-07-01 22:43:40257 // Initialize touch HUDs if necessary.
258 void InitTouchHuds();
259
[email protected]2c9171d22013-12-10 21:55:10260 // Returns the topmost window or one of its transient parents, if any of them
261 // are in fullscreen mode.
varkhad99fa94f2015-06-29 22:35:46262 aura::Window* GetWindowForFullscreenMode();
[email protected]2ee2f5d2013-01-10 23:37:16263
[email protected]b6ba05d902013-10-04 21:38:45264 // Activate virtual keyboard on current root window controller.
265 void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
266
267 // Deactivate virtual keyboard on current root window controller.
268 void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
269
[email protected]602022b2014-03-31 17:07:31270 // Tests if a window is associated with the virtual keyboard.
271 bool IsVirtualKeyboardWindow(aura::Window* window);
272
dmazzoniff86e3472016-06-03 19:52:32273 // If touch exploration is enabled, update the touch exploration
274 // controller so that synthesized touch events are anchored at this point.
275 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
276
skyb6643832017-01-11 22:08:45277 // Shows a context menu at the |location_in_screen|.
278 void ShowContextMenu(const gfx::Point& location_in_screen,
279 ui::MenuSourceType source_type);
280
281 // Called when the login status changes after login (such as lock/unlock).
skyb6643832017-01-11 22:08:45282 void UpdateAfterLoginStatusChange(LoginStatus status);
283
[email protected]431552c2012-10-23 00:38:33284 private:
sky00f98a372017-01-11 06:03:49285 // TODO(sky): remove this. Temporary during ash-mus unification.
286 // http://crbug.com/671246.
sky8a8ffd22017-01-19 15:55:29287 friend class mus::WindowManager;
sky00f98a372017-01-11 06:03:49288
289 // Creates a new RootWindowController with the specified host. Only one of
290 // |ash_host| or |window_tree_host| should be specified. This takes ownership
291 // of the supplied arguments.
292 // TODO(sky): mash should create AshWindowTreeHost, http://crbug.com/671246.
293 RootWindowController(AshWindowTreeHost* ash_host,
294 aura::WindowTreeHost* window_tree_host);
[email protected]a273d33a2013-10-17 12:41:21295
jamescookfda159002016-10-21 18:48:57296 // Initializes the RootWindowController based on |root_window_type|.
297 void Init(RootWindowType root_window_type);
[email protected]a273d33a2013-10-17 12:41:21298
[email protected]756bda12013-07-03 08:17:06299 void InitLayoutManagers();
300
varkha515b43462017-05-26 23:21:27301 // Creates the containers (aura::Windows) used by the shell.
skyb6643832017-01-11 22:08:45302 void CreateContainers();
303
msw607227f82016-08-30 17:22:39304 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
jamescookfda159002016-10-21 18:48:57305 // The initial color is determined by the |root_window_type| and whether or
306 // not this is the first boot.
307 void CreateSystemWallpaper(RootWindowType root_window_type);
[email protected]756bda12013-07-03 08:17:06308
[email protected]d141b922013-07-09 08:13:17309 // Enables projection touch HUD.
310 void EnableTouchHudProjection();
311
312 // Disables projection touch HUD.
313 void DisableTouchHudProjection();
314
sky27344382017-03-08 21:30:32315 // Resets Shell::GetRootWindowForNewWindows() if appropriate. This is called
skyb6643832017-01-11 22:08:45316 // during shutdown to make sure GetRootWindowForNewWindows() isn't referencing
317 // this.
318 void ResetRootForNewWindowsIfNecessary();
319
320 // Callback for MenuModelAdapter.
321 void OnMenuClosed();
sky8d971a0a2016-09-21 23:37:57322
[email protected]d141b922013-07-09 08:13:17323 // Overridden from ShellObserver.
dcheng1f4538e2014-10-27 23:57:05324 void OnTouchHudProjectionToggled(bool enabled) override;
[email protected]d141b922013-07-09 08:13:17325
dchenga94547472016-04-08 08:41:11326 std::unique_ptr<AshWindowTreeHost> ash_host_;
sky00f98a372017-01-11 06:03:49327 std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
328 // This comes from |ash_host_| or |mus_window_tree_host_|.
329 aura::WindowTreeHost* window_tree_host_;
skyee78dde2016-06-01 01:21:43330
skyb6643832017-01-11 22:08:45331 // LayoutManagers are owned by the window they are installed on.
skyb6643832017-01-11 22:08:45332 PanelLayoutManager* panel_layout_manager_ = nullptr;
333 wm::RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
334
335 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
336 std::unique_ptr<AnimatingWallpaperWidgetController>
337 animating_wallpaper_widget_controller_;
338 std::unique_ptr<WorkspaceController> workspace_controller_;
339
340 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
341
342 // Manages the context menu.
343 std::unique_ptr<ui::MenuModel> menu_model_;
344 std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_;
345 std::unique_ptr<views::MenuRunner> menu_runner_;
skyee78dde2016-06-01 01:21:43346
dchenga94547472016-04-08 08:41:11347 std::unique_ptr<StackingController> stacking_controller_;
[email protected]2a2caa02013-01-22 20:50:36348
jamescookbe6ed822016-06-06 20:08:55349 // The shelf controller for this root window. Exists for the entire lifetime
350 // of the RootWindowController so that it is safe for observers to be added
351 // to it during construction of the shelf widget and status tray.
James Cook840177e2017-05-25 02:20:01352 std::unique_ptr<Shelf> shelf_;
jamescookbe6ed822016-06-06 20:08:55353
jamescook788b4fc2017-05-18 16:16:06354 // TODO(jamescook): Eliminate this. It is left over from legacy shelf code and
355 // doesn't mean anything in particular.
356 bool shelf_initialized_ = false;
357
msw607227f82016-08-30 17:22:39358 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
[email protected]a825e8312014-05-05 22:05:01359
dchenga94547472016-04-08 08:41:11360 std::unique_ptr<BootSplashScreen> boot_splash_screen_;
[email protected]a825e8312014-05-05 22:05:01361 // Responsible for initializing TouchExplorationController when spoken
362 // feedback is on.
dchenga94547472016-04-08 08:41:11363 std::unique_ptr<AshTouchExplorationManager> touch_exploration_manager_;
[email protected]697f04c2012-10-03 01:15:10364
[email protected]2b8a9bb2013-07-01 22:43:40365 // Heads-up displays for touch events. These HUDs are not owned by the root
366 // window controller and manage their own lifetimes.
skyb6643832017-01-11 22:08:45367 TouchHudDebug* touch_hud_debug_ = nullptr;
368 TouchHudProjection* touch_hud_projection_ = nullptr;
[email protected]58175042013-04-01 19:27:13369
[email protected]3537d472014-01-15 05:45:31370 // Handles double clicks on the panel window header.
dchenga94547472016-04-08 08:41:11371 std::unique_ptr<ui::EventHandler> panel_container_handler_;
[email protected]a4cd6d32012-09-12 03:42:13372
dchenga94547472016-04-08 08:41:11373 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
[email protected]0bf61732013-07-02 04:35:10374
skyabcae812017-01-18 17:01:34375 static std::vector<RootWindowController*>* root_window_controllers_;
376
[email protected]d90b8392012-06-13 09:34:56377 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
378};
379
jamescook5d74ac02016-05-12 19:57:12380// On classic ash, returns the RootWindowController for the given |root_window|.
381// On mus ash, returns the RootWindowController for the primary display.
382// See RootWindowController class comment above.
[email protected]6b2d4a0b2013-09-06 06:29:54383ASH_EXPORT RootWindowController* GetRootWindowController(
[email protected]bf9cdb362013-10-25 19:22:45384 const aura::Window* root_window);
[email protected]6b2d4a0b2013-09-06 06:29:54385
[email protected]76bc4632014-06-16 19:07:46386} // namespace ash
[email protected]d90b8392012-06-13 09:34:56387
[email protected]76bc4632014-06-16 19:07:46388#endif // ASH_ROOT_WINDOW_CONTROLLER_H_