blob: b5209e2e8f0147a8900eac82be3977d7016cfd7d [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"
[email protected]d90b8392012-06-13 09:34:5619
[email protected]d90b8392012-06-13 09:34:5620namespace aura {
[email protected]d90b8392012-06-13 09:34:5621class Window;
[email protected]4a59e4e2012-11-12 21:15:4022}
23
24namespace gfx {
25class Point;
26}
27
[email protected]86459e2c2013-04-10 13:39:2428namespace keyboard {
29class KeyboardController;
30}
31
[email protected]3537d472014-01-15 05:45:3132namespace ui {
33class EventHandler;
skyb6643832017-01-11 22:08:4534class MenuModel;
sky00f98a372017-01-11 06:03:4935class WindowTreeHost;
[email protected]3537d472014-01-15 05:45:3136}
37
[email protected]e319c7e2014-03-14 19:56:1438namespace views {
skyb6643832017-01-11 22:08:4539class MenuModelAdapter;
40class MenuRunner;
Scott Violet66193f72017-06-26 22:24:1841class Widget;
[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;
Toni Barzic98c44eb2017-10-13 20:57:5053class LockScreenActionBackgroundController;
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;
sky8a8ffd22017-01-19 15:55:2966class WindowManager;
Scott Violet58ae95b2017-11-15 06:25:5367class WorkspaceController;
sky00f98a372017-01-11 06:03:4968
skyb6643832017-01-11 22:08:4569namespace wm {
70class RootWindowLayoutManager;
71}
72
[email protected]d90b8392012-06-13 09:34:5673// This class maintains the per root window state for ash. This class
74// owns the root window and other dependent objects that should be
[email protected]a273d33a2013-10-17 12:41:2175// deleted upon the deletion of the root window. This object is
oshimae2818922015-07-28 01:18:5276// indirectly owned and deleted by |WindowTreeHostManager|.
[email protected]a273d33a2013-10-17 12:41:2177// The RootWindowController for particular root window is stored in
78// its property (RootWindowSettings) and can be obtained using
msw257a6a232017-06-01 01:46:3079// |RootWindowController::ForWindow(aura::Window*)| function.
[email protected]d141b922013-07-09 08:13:1780class ASH_EXPORT RootWindowController : public ShellObserver {
[email protected]d90b8392012-06-13 09:34:5681 public:
sky00f98a372017-01-11 06:03:4982 // Enumerates the type of display. If there is only a single display then
83 // it is primary. In a multi-display environment one monitor is deemed the
84 // PRIMARY and all others SECONDARY.
85 enum class RootWindowType { PRIMARY, SECONDARY };
86
87 ~RootWindowController() override;
88
[email protected]a273d33a2013-10-17 12:41:2189 // Creates and Initialize the RootWindowController for primary display.
[email protected]f5c9dbc2014-04-11 08:13:4590 static void CreateForPrimaryDisplay(AshWindowTreeHost* host);
[email protected]a273d33a2013-10-17 12:41:2191
92 // Creates and Initialize the RootWindowController for secondary displays.
[email protected]f5c9dbc2014-04-11 08:13:4593 static void CreateForSecondaryDisplay(AshWindowTreeHost* host);
[email protected]d90b8392012-06-13 09:34:5694
[email protected]a0afeb12012-12-10 22:57:0995 // Returns a RootWindowController of the window's root window.
[email protected]ccff3d72013-02-06 04:26:2896 static RootWindowController* ForWindow(const aura::Window* window);
[email protected]a0afeb12012-12-10 22:57:0997
[email protected]d17642d2013-09-12 23:44:3898 // Returns the RootWindowController of the target root window.
[email protected]093b8d642014-04-03 20:59:2899 static RootWindowController* ForTargetRootWindow();
[email protected]a0afeb12012-12-10 22:57:09100
skyabcae812017-01-18 17:01:34101 static std::vector<RootWindowController*> root_window_controllers() {
102 return root_window_controllers_ ? *root_window_controllers_
103 : std::vector<RootWindowController*>();
104 }
105
sky00f98a372017-01-11 06:03:49106 // TODO(sky): move these to a separate class or use AshWindowTreeHost in
107 // mash. http://crbug.com/671246.
[email protected]f5c9dbc2014-04-11 08:13:45108 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
109 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
110
111 aura::WindowTreeHost* GetHost();
112 const aura::WindowTreeHost* GetHost() const;
113 aura::Window* GetRootWindow();
114 const aura::Window* GetRootWindow() const;
[email protected]d90b8392012-06-13 09:34:56115
skyb6643832017-01-11 22:08:45116 WorkspaceController* workspace_controller() {
117 return workspace_controller_.get();
118 }
119
120 wm::WorkspaceWindowState GetWorkspaceWindowState();
[email protected]d90b8392012-06-13 09:34:56121
James Cook840177e2017-05-25 02:20:01122 Shelf* shelf() const { return shelf_.get(); }
jamescookbe6ed822016-06-06 20:08:55123
jamescook788b4fc2017-05-18 16:16:06124 // Initializes the shelf for this root window and notifies observers.
125 void InitializeShelf();
skyb6643832017-01-11 22:08:45126
[email protected]2b8a9bb2013-07-01 22:43:40127 // Get touch HUDs associated with this root window controller.
jamescookb8dcef522016-06-25 14:42:55128 TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
[email protected]2b8a9bb2013-07-01 22:43:40129 TouchHudProjection* touch_hud_projection() const {
130 return touch_hud_projection_;
131 }
132
133 // Set touch HUDs for this root window controller. The root window controller
134 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
135 // the widget showing a HUD is being destroyed (e.g. because of detaching a
136 // display), the HUD deletes itself.
jamescookb8dcef522016-06-25 14:42:55137 void set_touch_hud_debug(TouchHudDebug* hud) { touch_hud_debug_ = hud; }
[email protected]2b8a9bb2013-07-01 22:43:40138 void set_touch_hud_projection(TouchHudProjection* hud) {
139 touch_hud_projection_ = hud;
140 }
141
skyb6643832017-01-11 22:08:45142 PanelLayoutManager* panel_layout_manager() { return panel_layout_manager_; }
143
144 wm::RootWindowLayoutManager* root_window_layout_manager() {
145 return root_window_layout_manager_;
146 }
147
[email protected]478c6c32013-03-09 02:50:58148 // Access the shelf layout manager associated with this root
149 // window controller, NULL if no such shelf exists.
150 ShelfLayoutManager* GetShelfLayoutManager();
[email protected]d90b8392012-06-13 09:34:56151
skyb6643832017-01-11 22:08:45152 // Returns the layout manager for the appropriate modal-container. If the
153 // window is inside the lockscreen modal container, then the layout manager
154 // for that is returned. Otherwise the layout manager for the default modal
155 // container is returned.
156 // If no window is specified (i.e. |window| is null), then the lockscreen
157 // modal container is used if the screen is currently locked. Otherwise, the
158 // default modal container is used.
159 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
sky97f9a7432017-05-09 05:14:31160 aura::Window* window);
skyb6643832017-01-11 22:08:45161
162 AlwaysOnTopController* always_on_top_controller() {
163 return always_on_top_controller_.get();
164 }
165
jamescookb551aba2016-09-01 01:00:16166 // May return null, for example for a secondary monitor at the login screen.
167 StatusAreaWidget* GetStatusAreaWidget();
168
[email protected]a0afeb12012-12-10 22:57:09169 // Returns the system tray on this root window. Note that
[email protected]864b58552013-12-19 04:19:38170 // calling this on the root window that doesn't have a shelf will
[email protected]a0afeb12012-12-10 22:57:09171 // lead to a crash.
172 SystemTray* GetSystemTray();
173
oshima9a61ecf2016-06-18 10:43:05174 // True if the window can receive events on this root window.
175 bool CanWindowReceiveEvents(aura::Window* window);
176
skyb6643832017-01-11 22:08:45177 // Returns the window events will be targeted at for the specified location
178 // (in screen coordinates).
179 //
180 // NOTE: the returned window may not contain the location as resize handles
181 // may extend outside the bounds of the window.
sky4befdb0d2017-05-18 23:50:26182 aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
skyb6643832017-01-11 22:08:45183
184 // Gets the last location seen in a mouse event in this root window's
185 // coordinates. This may return a point outside the root window's bounds.
186 gfx::Point GetLastMouseLocationInRoot();
187
[email protected]d90b8392012-06-13 09:34:56188 aura::Window* GetContainer(int container_id);
[email protected]d8a24952013-08-05 20:05:05189 const aura::Window* GetContainer(int container_id) const;
[email protected]d90b8392012-06-13 09:34:56190
skyb6643832017-01-11 22:08:45191 WallpaperWidgetController* wallpaper_widget_controller() {
192 return wallpaper_widget_controller_.get();
193 }
194 void SetWallpaperWidgetController(WallpaperWidgetController* controller);
195
196 AnimatingWallpaperWidgetController* animating_wallpaper_widget_controller() {
197 return animating_wallpaper_widget_controller_.get();
198 }
199 void SetAnimatingWallpaperWidgetController(
200 AnimatingWallpaperWidgetController* controller);
201
Toni Barzic98c44eb2017-10-13 20:57:50202 LockScreenActionBackgroundController*
203 lock_screen_action_background_controller() {
204 return lock_screen_action_background_controller_.get();
205 }
206
msw607227f82016-08-30 17:22:39207 // Called when the wallpaper animation is finished. Updates
208 // |system_wallpaper_| to be black and drops |boot_splash_screen_| and moves
209 // the wallpaper controller into the root window controller. |widget| holds
210 // the wallpaper image, or NULL if the wallpaper is a solid color.
[email protected]0bf61732013-07-02 04:35:10211 void OnWallpaperAnimationFinished(views::Widget* widget);
[email protected]d90b8392012-06-13 09:34:56212
[email protected]6675e1c2012-09-11 09:15:45213 // Deletes associated objects and clears the state, but doesn't delete
214 // the root window yet. This is used to delete a secondary displays'
215 // root window safely when the display disconnect signal is received,
gab2998ee72017-05-05 16:23:50216 // which may come while we're in the nested run loop.
[email protected]6675e1c2012-09-11 09:15:45217 void Shutdown();
218
[email protected]d90b8392012-06-13 09:34:56219 // Deletes all child windows and performs necessary cleanup.
220 void CloseChildWindows();
221
[email protected]f1853122012-06-27 16:21:26222 // Moves child windows to |dest|.
[email protected]bf9cdb362013-10-25 19:22:45223 void MoveWindowsTo(aura::Window* dest);
[email protected]f1853122012-06-27 16:21:26224
[email protected]e74aaf0a2012-10-12 18:42:28225 // Force the shelf to query for it's current visibility state.
226 void UpdateShelfVisibility();
227
[email protected]2b8a9bb2013-07-01 22:43:40228 // Initialize touch HUDs if necessary.
229 void InitTouchHuds();
230
[email protected]2c9171d22013-12-10 21:55:10231 // Returns the topmost window or one of its transient parents, if any of them
232 // are in fullscreen mode.
varkhad99fa94f2015-06-29 22:35:46233 aura::Window* GetWindowForFullscreenMode();
[email protected]2ee2f5d2013-01-10 23:37:16234
[email protected]b6ba05d902013-10-04 21:38:45235 // Activate virtual keyboard on current root window controller.
236 void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
237
238 // Deactivate virtual keyboard on current root window controller.
239 void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
240
[email protected]602022b2014-03-31 17:07:31241 // Tests if a window is associated with the virtual keyboard.
242 bool IsVirtualKeyboardWindow(aura::Window* window);
243
dmazzoniff86e3472016-06-03 19:52:32244 // If touch exploration is enabled, update the touch exploration
245 // controller so that synthesized touch events are anchored at this point.
246 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
247
skyb6643832017-01-11 22:08:45248 // Shows a context menu at the |location_in_screen|.
249 void ShowContextMenu(const gfx::Point& location_in_screen,
250 ui::MenuSourceType source_type);
251
252 // Called when the login status changes after login (such as lock/unlock).
skyb6643832017-01-11 22:08:45253 void UpdateAfterLoginStatusChange(LoginStatus status);
254
[email protected]431552c2012-10-23 00:38:33255 private:
sky00f98a372017-01-11 06:03:49256 // TODO(sky): remove this. Temporary during ash-mus unification.
257 // http://crbug.com/671246.
Scott Violet58ae95b2017-11-15 06:25:53258 friend class WindowManager;
sky00f98a372017-01-11 06:03:49259
260 // Creates a new RootWindowController with the specified host. Only one of
261 // |ash_host| or |window_tree_host| should be specified. This takes ownership
262 // of the supplied arguments.
263 // TODO(sky): mash should create AshWindowTreeHost, http://crbug.com/671246.
264 RootWindowController(AshWindowTreeHost* ash_host,
265 aura::WindowTreeHost* window_tree_host);
[email protected]a273d33a2013-10-17 12:41:21266
jamescookfda159002016-10-21 18:48:57267 // Initializes the RootWindowController based on |root_window_type|.
268 void Init(RootWindowType root_window_type);
[email protected]a273d33a2013-10-17 12:41:21269
[email protected]756bda12013-07-03 08:17:06270 void InitLayoutManagers();
271
varkha515b43462017-05-26 23:21:27272 // Creates the containers (aura::Windows) used by the shell.
skyb6643832017-01-11 22:08:45273 void CreateContainers();
274
msw607227f82016-08-30 17:22:39275 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
jamescookfda159002016-10-21 18:48:57276 // The initial color is determined by the |root_window_type| and whether or
277 // not this is the first boot.
278 void CreateSystemWallpaper(RootWindowType root_window_type);
[email protected]756bda12013-07-03 08:17:06279
[email protected]d141b922013-07-09 08:13:17280 // Enables projection touch HUD.
281 void EnableTouchHudProjection();
282
283 // Disables projection touch HUD.
284 void DisableTouchHudProjection();
285
sky27344382017-03-08 21:30:32286 // Resets Shell::GetRootWindowForNewWindows() if appropriate. This is called
skyb6643832017-01-11 22:08:45287 // during shutdown to make sure GetRootWindowForNewWindows() isn't referencing
288 // this.
289 void ResetRootForNewWindowsIfNecessary();
290
291 // Callback for MenuModelAdapter.
292 void OnMenuClosed();
sky8d971a0a2016-09-21 23:37:57293
[email protected]d141b922013-07-09 08:13:17294 // Overridden from ShellObserver.
dcheng1f4538e2014-10-27 23:57:05295 void OnTouchHudProjectionToggled(bool enabled) override;
[email protected]d141b922013-07-09 08:13:17296
dchenga94547472016-04-08 08:41:11297 std::unique_ptr<AshWindowTreeHost> ash_host_;
sky00f98a372017-01-11 06:03:49298 std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
299 // This comes from |ash_host_| or |mus_window_tree_host_|.
300 aura::WindowTreeHost* window_tree_host_;
skyee78dde2016-06-01 01:21:43301
skyb6643832017-01-11 22:08:45302 // LayoutManagers are owned by the window they are installed on.
skyb6643832017-01-11 22:08:45303 PanelLayoutManager* panel_layout_manager_ = nullptr;
304 wm::RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
305
306 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
307 std::unique_ptr<AnimatingWallpaperWidgetController>
308 animating_wallpaper_widget_controller_;
309 std::unique_ptr<WorkspaceController> workspace_controller_;
310
311 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
312
313 // Manages the context menu.
314 std::unique_ptr<ui::MenuModel> menu_model_;
315 std::unique_ptr<views::MenuModelAdapter> menu_model_adapter_;
316 std::unique_ptr<views::MenuRunner> menu_runner_;
skyee78dde2016-06-01 01:21:43317
dchenga94547472016-04-08 08:41:11318 std::unique_ptr<StackingController> stacking_controller_;
[email protected]2a2caa02013-01-22 20:50:36319
jamescookbe6ed822016-06-06 20:08:55320 // The shelf controller for this root window. Exists for the entire lifetime
321 // of the RootWindowController so that it is safe for observers to be added
322 // to it during construction of the shelf widget and status tray.
James Cook840177e2017-05-25 02:20:01323 std::unique_ptr<Shelf> shelf_;
jamescookbe6ed822016-06-06 20:08:55324
jamescook788b4fc2017-05-18 16:16:06325 // TODO(jamescook): Eliminate this. It is left over from legacy shelf code and
326 // doesn't mean anything in particular.
327 bool shelf_initialized_ = false;
328
msw607227f82016-08-30 17:22:39329 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
[email protected]a825e8312014-05-05 22:05:01330
[email protected]a825e8312014-05-05 22:05:01331 // Responsible for initializing TouchExplorationController when spoken
332 // feedback is on.
dchenga94547472016-04-08 08:41:11333 std::unique_ptr<AshTouchExplorationManager> touch_exploration_manager_;
[email protected]697f04c2012-10-03 01:15:10334
[email protected]2b8a9bb2013-07-01 22:43:40335 // Heads-up displays for touch events. These HUDs are not owned by the root
336 // window controller and manage their own lifetimes.
skyb6643832017-01-11 22:08:45337 TouchHudDebug* touch_hud_debug_ = nullptr;
338 TouchHudProjection* touch_hud_projection_ = nullptr;
[email protected]58175042013-04-01 19:27:13339
[email protected]3537d472014-01-15 05:45:31340 // Handles double clicks on the panel window header.
dchenga94547472016-04-08 08:41:11341 std::unique_ptr<ui::EventHandler> panel_container_handler_;
[email protected]a4cd6d32012-09-12 03:42:13342
dchenga94547472016-04-08 08:41:11343 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
[email protected]0bf61732013-07-02 04:35:10344
Toni Barzic98c44eb2017-10-13 20:57:50345 std::unique_ptr<LockScreenActionBackgroundController>
346 lock_screen_action_background_controller_;
347
skyabcae812017-01-18 17:01:34348 static std::vector<RootWindowController*>* root_window_controllers_;
349
[email protected]d90b8392012-06-13 09:34:56350 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
351};
352
[email protected]76bc4632014-06-16 19:07:46353} // namespace ash
[email protected]d90b8392012-06-13 09:34:56354
[email protected]76bc4632014-06-16 19:07:46355#endif // ASH_ROOT_WINDOW_CONTROLLER_H_