blob: d8698cc7d6d1926639f79171e4aa7d861b873ed7 [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/wm/workspace/workspace_types.h"
avidb567a8a2015-12-20 17:07:2415#include "base/macros.h"
[email protected]f7c05b22013-11-12 21:07:2416#include "ui/aura/window.h"
[email protected]2f2620332014-02-28 10:07:3817#include "ui/aura/window_tree_host.h"
[email protected]d90b8392012-06-13 09:34:5618
[email protected]d90b8392012-06-13 09:34:5619namespace aura {
[email protected]d90b8392012-06-13 09:34:5620class Window;
[email protected]4a59e4e2012-11-12 21:15:4021}
22
23namespace gfx {
24class Point;
25}
26
[email protected]3537d472014-01-15 05:45:3127namespace ui {
sky00f98a372017-01-11 06:03:4928class WindowTreeHost;
[email protected]3537d472014-01-15 05:45:3129}
30
[email protected]e319c7e2014-03-14 19:56:1431namespace views {
skyb6643832017-01-11 22:08:4532class MenuRunner;
[email protected]e319c7e2014-03-14 19:56:1433}
34
35namespace wm {
[email protected]e319c7e2014-03-14 19:56:1436class ScopedCaptureClient;
37}
38
[email protected]d90b8392012-06-13 09:34:5639namespace ash {
Aga Wronska0514fd62019-03-25 20:11:3740class AccessibilityPanelLayoutManager;
skyb6643832017-01-11 22:08:4541class AlwaysOnTopController;
Matthew Mourgos3850cda2019-04-26 21:21:4142class AppMenuModelAdapter;
[email protected]f5c9dbc2014-04-11 08:13:4543class AshWindowTreeHost;
Toni Barzic98c44eb2017-10-13 20:57:5044class LockScreenActionBackgroundController;
mswb2416052016-06-24 21:23:4545enum class LoginStatus;
James Cook00e65e92019-07-25 03:19:0846class RootWindowLayoutManager;
James Cook840177e2017-05-25 02:20:0147class Shelf;
[email protected]e74aaf0a2012-10-12 18:42:2848class ShelfLayoutManager;
Avery Musbachd17265f32019-10-11 17:01:0349class SplitViewController;
[email protected]093b8d642014-04-03 20:59:2850class StackingController;
[email protected]e74aaf0a2012-10-12 18:42:2851class StatusAreaWidget;
skyb6643832017-01-11 22:08:4552class SystemModalContainerLayoutManager;
msw607227f82016-08-30 17:22:3953class SystemWallpaperController;
James Cookd3332922018-03-09 15:54:1354class TouchExplorationManager;
Evan Stadebf510a02019-05-03 01:51:3155class TouchHudDebug;
56class TouchHudProjection;
skyb6643832017-01-11 22:08:4557class WallpaperWidgetController;
sky8a8ffd22017-01-19 15:55:2958class WindowManager;
Aga Wronskaf053e522019-03-27 00:08:4259class WorkAreaInsets;
sky00f98a372017-01-11 06:03:4960
[email protected]d90b8392012-06-13 09:34:5661// This class maintains the per root window state for ash. This class
62// owns the root window and other dependent objects that should be
[email protected]a273d33a2013-10-17 12:41:2163// deleted upon the deletion of the root window. This object is
oshimae2818922015-07-28 01:18:5264// indirectly owned and deleted by |WindowTreeHostManager|.
[email protected]a273d33a2013-10-17 12:41:2165// The RootWindowController for particular root window is stored in
66// its property (RootWindowSettings) and can be obtained using
msw257a6a232017-06-01 01:46:3067// |RootWindowController::ForWindow(aura::Window*)| function.
James Cookbd0b7792017-11-17 03:24:2668class ASH_EXPORT RootWindowController {
[email protected]d90b8392012-06-13 09:34:5669 public:
sky00f98a372017-01-11 06:03:4970 // Enumerates the type of display. If there is only a single display then
71 // it is primary. In a multi-display environment one monitor is deemed the
72 // PRIMARY and all others SECONDARY.
73 enum class RootWindowType { PRIMARY, SECONDARY };
74
James Cookbd0b7792017-11-17 03:24:2675 ~RootWindowController();
sky00f98a372017-01-11 06:03:4976
[email protected]a273d33a2013-10-17 12:41:2177 // Creates and Initialize the RootWindowController for primary display.
Avery Musbach57eba6c2019-10-23 20:06:4278 // Returns a pointer to the newly created controller.
79 static RootWindowController* CreateForPrimaryDisplay(AshWindowTreeHost* host);
[email protected]a273d33a2013-10-17 12:41:2180
81 // Creates and Initialize the RootWindowController for secondary displays.
Avery Musbach57eba6c2019-10-23 20:06:4282 // Returns a pointer to the newly created controller.
83 static RootWindowController* CreateForSecondaryDisplay(
84 AshWindowTreeHost* host);
[email protected]d90b8392012-06-13 09:34:5685
[email protected]a0afeb12012-12-10 22:57:0986 // Returns a RootWindowController of the window's root window.
[email protected]ccff3d72013-02-06 04:26:2887 static RootWindowController* ForWindow(const aura::Window* window);
[email protected]a0afeb12012-12-10 22:57:0988
[email protected]d17642d2013-09-12 23:44:3889 // Returns the RootWindowController of the target root window.
[email protected]093b8d642014-04-03 20:59:2890 static RootWindowController* ForTargetRootWindow();
[email protected]a0afeb12012-12-10 22:57:0991
skyabcae812017-01-18 17:01:3492 static std::vector<RootWindowController*> root_window_controllers() {
93 return root_window_controllers_ ? *root_window_controllers_
94 : std::vector<RootWindowController*>();
95 }
96
sky00f98a372017-01-11 06:03:4997 // TODO(sky): move these to a separate class or use AshWindowTreeHost in
98 // mash. http://crbug.com/671246.
[email protected]f5c9dbc2014-04-11 08:13:4599 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
100 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
101
102 aura::WindowTreeHost* GetHost();
103 const aura::WindowTreeHost* GetHost() const;
104 aura::Window* GetRootWindow();
105 const aura::Window* GetRootWindow() const;
[email protected]d90b8392012-06-13 09:34:56106
Avery Musbachd17265f32019-10-11 17:01:03107 SplitViewController* split_view_controller() const {
108 return split_view_controller_.get();
109 }
110
James Cook840177e2017-05-25 02:20:01111 Shelf* shelf() const { return shelf_.get(); }
jamescookbe6ed822016-06-06 20:08:55112
Evan Stadebf510a02019-05-03 01:51:31113 TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
114 TouchHudProjection* touch_hud_projection() const {
115 return touch_hud_projection_;
116 }
117
118 // Set touch HUDs for this root window controller. The root window controller
119 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
120 // the widget showing a HUD is being destroyed (e.g. because of detaching a
121 // display), the HUD deletes itself.
122 void set_touch_hud_debug(TouchHudDebug* hud) { touch_hud_debug_ = hud; }
123 void set_touch_hud_projection(TouchHudProjection* hud) {
124 touch_hud_projection_ = hud;
James Cookddb9a762018-08-14 20:44:57125 }
[email protected]2b8a9bb2013-07-01 22:43:40126
James Cook00e65e92019-07-25 03:19:08127 RootWindowLayoutManager* root_window_layout_manager() {
skyb6643832017-01-11 22:08:45128 return root_window_layout_manager_;
129 }
130
Aga Wronskaf053e522019-03-27 00:08:42131 // Returns parameters of the work area associated with this root window.
132 WorkAreaInsets* work_area_insets() { return work_area_insets_.get(); }
133
[email protected]478c6c32013-03-09 02:50:58134 // Access the shelf layout manager associated with this root
135 // window controller, NULL if no such shelf exists.
136 ShelfLayoutManager* GetShelfLayoutManager();
[email protected]d90b8392012-06-13 09:34:56137
skyb6643832017-01-11 22:08:45138 // Returns the layout manager for the appropriate modal-container. If the
139 // window is inside the lockscreen modal container, then the layout manager
140 // for that is returned. Otherwise the layout manager for the default modal
141 // container is returned.
142 // If no window is specified (i.e. |window| is null), then the lockscreen
143 // modal container is used if the screen is currently locked. Otherwise, the
144 // default modal container is used.
145 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
sky97f9a7432017-05-09 05:14:31146 aura::Window* window);
skyb6643832017-01-11 22:08:45147
148 AlwaysOnTopController* always_on_top_controller() {
149 return always_on_top_controller_.get();
150 }
151
jamescookb551aba2016-09-01 01:00:16152 // May return null, for example for a secondary monitor at the login screen.
153 StatusAreaWidget* GetStatusAreaWidget();
154
Tetsui Ohkubo2c474b752018-06-28 01:35:41155 // Returns if system tray and its widget is visible.
156 bool IsSystemTrayVisible();
157
oshima9a61ecf2016-06-18 10:43:05158 // True if the window can receive events on this root window.
159 bool CanWindowReceiveEvents(aura::Window* window);
160
skyb6643832017-01-11 22:08:45161 // Returns the window events will be targeted at for the specified location
162 // (in screen coordinates).
163 //
164 // NOTE: the returned window may not contain the location as resize handles
165 // may extend outside the bounds of the window.
sky4befdb0d2017-05-18 23:50:26166 aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
skyb6643832017-01-11 22:08:45167
168 // Gets the last location seen in a mouse event in this root window's
169 // coordinates. This may return a point outside the root window's bounds.
170 gfx::Point GetLastMouseLocationInRoot();
171
[email protected]d90b8392012-06-13 09:34:56172 aura::Window* GetContainer(int container_id);
[email protected]d8a24952013-08-05 20:05:05173 const aura::Window* GetContainer(int container_id) const;
[email protected]d90b8392012-06-13 09:34:56174
skyb6643832017-01-11 22:08:45175 WallpaperWidgetController* wallpaper_widget_controller() {
176 return wallpaper_widget_controller_.get();
177 }
skyb6643832017-01-11 22:08:45178
Toni Barzic98c44eb2017-10-13 20:57:50179 LockScreenActionBackgroundController*
180 lock_screen_action_background_controller() {
181 return lock_screen_action_background_controller_.get();
182 }
183
[email protected]6675e1c2012-09-11 09:15:45184 // Deletes associated objects and clears the state, but doesn't delete
185 // the root window yet. This is used to delete a secondary displays'
186 // root window safely when the display disconnect signal is received,
gab2998ee72017-05-05 16:23:50187 // which may come while we're in the nested run loop.
[email protected]6675e1c2012-09-11 09:15:45188 void Shutdown();
189
[email protected]d90b8392012-06-13 09:34:56190 // Deletes all child windows and performs necessary cleanup.
191 void CloseChildWindows();
192
[email protected]f1853122012-06-27 16:21:26193 // Moves child windows to |dest|.
Ahmed Fakhryfee7a0a2019-04-05 22:49:48194 // TODO(afakhry): Consider renaming this function to avoid misuse. It is only
195 // called by WindowTreeHostManager::DeleteHost(), and has destructive side
196 // effects like deleting the workspace controllers, so it shouldn't be called
197 // for something else.
[email protected]bf9cdb362013-10-25 19:22:45198 void MoveWindowsTo(aura::Window* dest);
[email protected]f1853122012-06-27 16:21:26199
[email protected]e74aaf0a2012-10-12 18:42:28200 // Force the shelf to query for it's current visibility state.
201 void UpdateShelfVisibility();
202
[email protected]2b8a9bb2013-07-01 22:43:40203 // Initialize touch HUDs if necessary.
204 void InitTouchHuds();
205
[email protected]2c9171d22013-12-10 21:55:10206 // Returns the topmost window or one of its transient parents, if any of them
207 // are in fullscreen mode.
Ahmed Fakhryf1dd847ae2019-03-28 22:15:21208 // TODO(afakhry): Rename this to imply getting the fullscreen window on the
209 // currently active desk on this root.
varkhad99fa94f2015-06-29 22:35:46210 aura::Window* GetWindowForFullscreenMode();
[email protected]2ee2f5d2013-01-10 23:37:16211
dmazzoniff86e3472016-06-03 19:52:32212 // If touch exploration is enabled, update the touch exploration
213 // controller so that synthesized touch events are anchored at this point.
214 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
215
skyb6643832017-01-11 22:08:45216 // Shows a context menu at the |location_in_screen|.
217 void ShowContextMenu(const gfx::Point& location_in_screen,
218 ui::MenuSourceType source_type);
Sammie Quon646e2632018-02-27 19:55:40219 void HideContextMenu();
Weidong Guo053b9292018-04-24 23:46:10220 bool IsContextMenuShown() const;
skyb6643832017-01-11 22:08:45221
222 // Called when the login status changes after login (such as lock/unlock).
skyb6643832017-01-11 22:08:45223 void UpdateAfterLoginStatusChange(LoginStatus status);
224
Aga Wronska0514fd62019-03-25 20:11:37225 // Returns accessibility panel layout manager for this root window.
226 AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest();
227
[email protected]431552c2012-10-23 00:38:33228 private:
Sammie Quon646e2632018-02-27 19:55:40229 FRIEND_TEST_ALL_PREFIXES(RootWindowControllerTest,
230 ContextMenuDisappearsInTabletMode);
231
sky00f98a372017-01-11 06:03:49232 // TODO(sky): remove this. Temporary during ash-mus unification.
233 // http://crbug.com/671246.
Scott Violet58ae95b2017-11-15 06:25:53234 friend class WindowManager;
sky00f98a372017-01-11 06:03:49235
236 // Creates a new RootWindowController with the specified host. Only one of
237 // |ash_host| or |window_tree_host| should be specified. This takes ownership
238 // of the supplied arguments.
239 // TODO(sky): mash should create AshWindowTreeHost, http://crbug.com/671246.
240 RootWindowController(AshWindowTreeHost* ash_host,
241 aura::WindowTreeHost* window_tree_host);
[email protected]a273d33a2013-10-17 12:41:21242
jamescookfda159002016-10-21 18:48:57243 // Initializes the RootWindowController based on |root_window_type|.
244 void Init(RootWindowType root_window_type);
[email protected]a273d33a2013-10-17 12:41:21245
[email protected]756bda12013-07-03 08:17:06246 void InitLayoutManagers();
247
Aga Wronska0514fd62019-03-25 20:11:37248 AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManager() const;
249
Aga Wronskae195ad22017-12-20 01:38:11250 // Initializes the shelf for this root window and notifies observers.
251 void InitializeShelf();
252
varkha515b43462017-05-26 23:21:27253 // Creates the containers (aura::Windows) used by the shell.
skyb6643832017-01-11 22:08:45254 void CreateContainers();
255
Mitsuru Oshima7f05b252019-06-12 19:21:32256 // Creates a new window for use as a container.
257 aura::Window* CreateContainer(int window_id,
258 const char* name,
259 aura::Window* parent);
260
msw607227f82016-08-30 17:22:39261 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
jamescookfda159002016-10-21 18:48:57262 // The initial color is determined by the |root_window_type| and whether or
263 // not this is the first boot.
264 void CreateSystemWallpaper(RootWindowType root_window_type);
[email protected]756bda12013-07-03 08:17:06265
Alexander Shabalin5c910fc2017-12-08 23:29:47266 // Callback for MenuRunner.
Matthew Mourgos3850cda2019-04-26 21:21:41267 void OnMenuClosed();
sky8d971a0a2016-09-21 23:37:57268
Toni Barzic712399152018-02-15 17:38:40269 // Passed as callback to |wallpaper_widget_controller_| - run when the
270 // wallpaper widget is first set.
271 void OnFirstWallpaperWidgetSet();
272
dchenga94547472016-04-08 08:41:11273 std::unique_ptr<AshWindowTreeHost> ash_host_;
sky00f98a372017-01-11 06:03:49274 std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
275 // This comes from |ash_host_| or |mus_window_tree_host_|.
276 aura::WindowTreeHost* window_tree_host_;
skyee78dde2016-06-01 01:21:43277
skyb6643832017-01-11 22:08:45278 // LayoutManagers are owned by the window they are installed on.
James Cook00e65e92019-07-25 03:19:08279 RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
skyb6643832017-01-11 22:08:45280
281 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
skyb6643832017-01-11 22:08:45282
283 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
284
285 // Manages the context menu.
Matthew Mourgos3850cda2019-04-26 21:21:41286 std::unique_ptr<AppMenuModelAdapter> root_window_menu_model_adapter_;
skyee78dde2016-06-01 01:21:43287
dchenga94547472016-04-08 08:41:11288 std::unique_ptr<StackingController> stacking_controller_;
[email protected]2a2caa02013-01-22 20:50:36289
Avery Musbachd17265f32019-10-11 17:01:03290 std::unique_ptr<SplitViewController> split_view_controller_;
291
jamescookbe6ed822016-06-06 20:08:55292 // The shelf controller for this root window. Exists for the entire lifetime
293 // of the RootWindowController so that it is safe for observers to be added
294 // to it during construction of the shelf widget and status tray.
James Cook840177e2017-05-25 02:20:01295 std::unique_ptr<Shelf> shelf_;
jamescookbe6ed822016-06-06 20:08:55296
jamescook788b4fc2017-05-18 16:16:06297 // TODO(jamescook): Eliminate this. It is left over from legacy shelf code and
298 // doesn't mean anything in particular.
299 bool shelf_initialized_ = false;
300
msw607227f82016-08-30 17:22:39301 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
[email protected]a825e8312014-05-05 22:05:01302
[email protected]a825e8312014-05-05 22:05:01303 // Responsible for initializing TouchExplorationController when spoken
304 // feedback is on.
James Cookd3332922018-03-09 15:54:13305 std::unique_ptr<TouchExplorationManager> touch_exploration_manager_;
[email protected]697f04c2012-10-03 01:15:10306
Evan Stadebf510a02019-05-03 01:51:31307 // Heads-up displays for touch events. These HUDs are not owned by the root
308 // window controller and manage their own lifetimes.
309 TouchHudDebug* touch_hud_debug_ = nullptr;
310 TouchHudProjection* touch_hud_projection_ = nullptr;
[email protected]58175042013-04-01 19:27:13311
dchenga94547472016-04-08 08:41:11312 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
[email protected]0bf61732013-07-02 04:35:10313
Toni Barzic98c44eb2017-10-13 20:57:50314 std::unique_ptr<LockScreenActionBackgroundController>
315 lock_screen_action_background_controller_;
316
James Cookee2daef2018-03-10 01:48:10317 // Whether child windows have been closed during shutdown. Exists to avoid
318 // calling related cleanup code more than once.
319 bool did_close_child_windows_ = false;
320
Aga Wronskaf053e522019-03-27 00:08:42321 std::unique_ptr<WorkAreaInsets> work_area_insets_;
Aga Wronska5f0a7e072019-03-26 17:31:20322
skyabcae812017-01-18 17:01:34323 static std::vector<RootWindowController*>* root_window_controllers_;
324
[email protected]d90b8392012-06-13 09:34:56325 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
326};
327
[email protected]76bc4632014-06-16 19:07:46328} // namespace ash
[email protected]d90b8392012-06-13 09:34:56329
[email protected]76bc4632014-06-16 19:07:46330#endif // ASH_ROOT_WINDOW_CONTROLLER_H_