blob: 1b9968464f5534b7ee7c9d6492da03f7c57366c8 [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 Cook840177e2017-05-25 02:20:0146class Shelf;
[email protected]e74aaf0a2012-10-12 18:42:2847class ShelfLayoutManager;
[email protected]093b8d642014-04-03 20:59:2848class StackingController;
[email protected]e74aaf0a2012-10-12 18:42:2849class StatusAreaWidget;
skyb6643832017-01-11 22:08:4550class SystemModalContainerLayoutManager;
msw607227f82016-08-30 17:22:3951class SystemWallpaperController;
James Cookd3332922018-03-09 15:54:1352class TouchExplorationManager;
James Cookddb9a762018-08-14 20:44:5753class TouchObserverHUD;
skyb6643832017-01-11 22:08:4554class WallpaperWidgetController;
sky8a8ffd22017-01-19 15:55:2955class WindowManager;
Aga Wronskaf053e522019-03-27 00:08:4256class WorkAreaInsets;
sky00f98a372017-01-11 06:03:4957
skyb6643832017-01-11 22:08:4558namespace wm {
59class RootWindowLayoutManager;
60}
61
[email protected]d90b8392012-06-13 09:34:5662// This class maintains the per root window state for ash. This class
63// owns the root window and other dependent objects that should be
[email protected]a273d33a2013-10-17 12:41:2164// deleted upon the deletion of the root window. This object is
oshimae2818922015-07-28 01:18:5265// indirectly owned and deleted by |WindowTreeHostManager|.
[email protected]a273d33a2013-10-17 12:41:2166// The RootWindowController for particular root window is stored in
67// its property (RootWindowSettings) and can be obtained using
msw257a6a232017-06-01 01:46:3068// |RootWindowController::ForWindow(aura::Window*)| function.
James Cookbd0b7792017-11-17 03:24:2669class ASH_EXPORT RootWindowController {
[email protected]d90b8392012-06-13 09:34:5670 public:
sky00f98a372017-01-11 06:03:4971 // Enumerates the type of display. If there is only a single display then
72 // it is primary. In a multi-display environment one monitor is deemed the
73 // PRIMARY and all others SECONDARY.
74 enum class RootWindowType { PRIMARY, SECONDARY };
75
James Cookbd0b7792017-11-17 03:24:2676 ~RootWindowController();
sky00f98a372017-01-11 06:03:4977
[email protected]a273d33a2013-10-17 12:41:2178 // Creates and Initialize the RootWindowController for primary display.
[email protected]f5c9dbc2014-04-11 08:13:4579 static void CreateForPrimaryDisplay(AshWindowTreeHost* host);
[email protected]a273d33a2013-10-17 12:41:2180
81 // Creates and Initialize the RootWindowController for secondary displays.
[email protected]f5c9dbc2014-04-11 08:13:4582 static void CreateForSecondaryDisplay(AshWindowTreeHost* host);
[email protected]d90b8392012-06-13 09:34:5683
[email protected]a0afeb12012-12-10 22:57:0984 // Returns a RootWindowController of the window's root window.
[email protected]ccff3d72013-02-06 04:26:2885 static RootWindowController* ForWindow(const aura::Window* window);
[email protected]a0afeb12012-12-10 22:57:0986
[email protected]d17642d2013-09-12 23:44:3887 // Returns the RootWindowController of the target root window.
[email protected]093b8d642014-04-03 20:59:2888 static RootWindowController* ForTargetRootWindow();
[email protected]a0afeb12012-12-10 22:57:0989
skyabcae812017-01-18 17:01:3490 static std::vector<RootWindowController*> root_window_controllers() {
91 return root_window_controllers_ ? *root_window_controllers_
92 : std::vector<RootWindowController*>();
93 }
94
sky00f98a372017-01-11 06:03:4995 // TODO(sky): move these to a separate class or use AshWindowTreeHost in
96 // mash. http://crbug.com/671246.
[email protected]f5c9dbc2014-04-11 08:13:4597 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
98 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
99
100 aura::WindowTreeHost* GetHost();
101 const aura::WindowTreeHost* GetHost() const;
102 aura::Window* GetRootWindow();
103 const aura::Window* GetRootWindow() const;
[email protected]d90b8392012-06-13 09:34:56104
James Cook840177e2017-05-25 02:20:01105 Shelf* shelf() const { return shelf_.get(); }
jamescookbe6ed822016-06-06 20:08:55106
James Cookddb9a762018-08-14 20:44:57107 TouchObserverHUD* touch_observer_hud() const { return touch_observer_hud_; }
108 void set_touch_observer_hud(TouchObserverHUD* hud) {
109 touch_observer_hud_ = hud;
110 }
[email protected]2b8a9bb2013-07-01 22:43:40111
skyb6643832017-01-11 22:08:45112 wm::RootWindowLayoutManager* root_window_layout_manager() {
113 return root_window_layout_manager_;
114 }
115
Aga Wronskaf053e522019-03-27 00:08:42116 // Returns parameters of the work area associated with this root window.
117 WorkAreaInsets* work_area_insets() { return work_area_insets_.get(); }
118
[email protected]478c6c32013-03-09 02:50:58119 // Access the shelf layout manager associated with this root
120 // window controller, NULL if no such shelf exists.
121 ShelfLayoutManager* GetShelfLayoutManager();
[email protected]d90b8392012-06-13 09:34:56122
skyb6643832017-01-11 22:08:45123 // Returns the layout manager for the appropriate modal-container. If the
124 // window is inside the lockscreen modal container, then the layout manager
125 // for that is returned. Otherwise the layout manager for the default modal
126 // container is returned.
127 // If no window is specified (i.e. |window| is null), then the lockscreen
128 // modal container is used if the screen is currently locked. Otherwise, the
129 // default modal container is used.
130 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
sky97f9a7432017-05-09 05:14:31131 aura::Window* window);
skyb6643832017-01-11 22:08:45132
133 AlwaysOnTopController* always_on_top_controller() {
134 return always_on_top_controller_.get();
135 }
136
jamescookb551aba2016-09-01 01:00:16137 // May return null, for example for a secondary monitor at the login screen.
138 StatusAreaWidget* GetStatusAreaWidget();
139
Tetsui Ohkubo2c474b752018-06-28 01:35:41140 // Returns if system tray and its widget is visible.
141 bool IsSystemTrayVisible();
142
oshima9a61ecf2016-06-18 10:43:05143 // True if the window can receive events on this root window.
144 bool CanWindowReceiveEvents(aura::Window* window);
145
skyb6643832017-01-11 22:08:45146 // Returns the window events will be targeted at for the specified location
147 // (in screen coordinates).
148 //
149 // NOTE: the returned window may not contain the location as resize handles
150 // may extend outside the bounds of the window.
sky4befdb0d2017-05-18 23:50:26151 aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
skyb6643832017-01-11 22:08:45152
153 // Gets the last location seen in a mouse event in this root window's
154 // coordinates. This may return a point outside the root window's bounds.
155 gfx::Point GetLastMouseLocationInRoot();
156
[email protected]d90b8392012-06-13 09:34:56157 aura::Window* GetContainer(int container_id);
[email protected]d8a24952013-08-05 20:05:05158 const aura::Window* GetContainer(int container_id) const;
[email protected]d90b8392012-06-13 09:34:56159
skyb6643832017-01-11 22:08:45160 WallpaperWidgetController* wallpaper_widget_controller() {
161 return wallpaper_widget_controller_.get();
162 }
skyb6643832017-01-11 22:08:45163
Toni Barzic98c44eb2017-10-13 20:57:50164 LockScreenActionBackgroundController*
165 lock_screen_action_background_controller() {
166 return lock_screen_action_background_controller_.get();
167 }
168
[email protected]6675e1c2012-09-11 09:15:45169 // Deletes associated objects and clears the state, but doesn't delete
170 // the root window yet. This is used to delete a secondary displays'
171 // root window safely when the display disconnect signal is received,
gab2998ee72017-05-05 16:23:50172 // which may come while we're in the nested run loop.
[email protected]6675e1c2012-09-11 09:15:45173 void Shutdown();
174
[email protected]d90b8392012-06-13 09:34:56175 // Deletes all child windows and performs necessary cleanup.
176 void CloseChildWindows();
177
[email protected]f1853122012-06-27 16:21:26178 // Moves child windows to |dest|.
Ahmed Fakhryfee7a0a2019-04-05 22:49:48179 // TODO(afakhry): Consider renaming this function to avoid misuse. It is only
180 // called by WindowTreeHostManager::DeleteHost(), and has destructive side
181 // effects like deleting the workspace controllers, so it shouldn't be called
182 // for something else.
[email protected]bf9cdb362013-10-25 19:22:45183 void MoveWindowsTo(aura::Window* dest);
[email protected]f1853122012-06-27 16:21:26184
[email protected]e74aaf0a2012-10-12 18:42:28185 // Force the shelf to query for it's current visibility state.
186 void UpdateShelfVisibility();
187
[email protected]2b8a9bb2013-07-01 22:43:40188 // Initialize touch HUDs if necessary.
189 void InitTouchHuds();
190
[email protected]2c9171d22013-12-10 21:55:10191 // Returns the topmost window or one of its transient parents, if any of them
192 // are in fullscreen mode.
Ahmed Fakhryf1dd847ae2019-03-28 22:15:21193 // TODO(afakhry): Rename this to imply getting the fullscreen window on the
194 // currently active desk on this root.
varkhad99fa94f2015-06-29 22:35:46195 aura::Window* GetWindowForFullscreenMode();
[email protected]2ee2f5d2013-01-10 23:37:16196
dmazzoniff86e3472016-06-03 19:52:32197 // If touch exploration is enabled, update the touch exploration
198 // controller so that synthesized touch events are anchored at this point.
199 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
200
skyb6643832017-01-11 22:08:45201 // Shows a context menu at the |location_in_screen|.
202 void ShowContextMenu(const gfx::Point& location_in_screen,
203 ui::MenuSourceType source_type);
Sammie Quon646e2632018-02-27 19:55:40204 void HideContextMenu();
Weidong Guo053b9292018-04-24 23:46:10205 bool IsContextMenuShown() const;
skyb6643832017-01-11 22:08:45206
207 // Called when the login status changes after login (such as lock/unlock).
skyb6643832017-01-11 22:08:45208 void UpdateAfterLoginStatusChange(LoginStatus status);
209
Aga Wronska0514fd62019-03-25 20:11:37210 // Returns accessibility panel layout manager for this root window.
211 AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest();
212
[email protected]431552c2012-10-23 00:38:33213 private:
Sammie Quon646e2632018-02-27 19:55:40214 FRIEND_TEST_ALL_PREFIXES(RootWindowControllerTest,
215 ContextMenuDisappearsInTabletMode);
216
sky00f98a372017-01-11 06:03:49217 // TODO(sky): remove this. Temporary during ash-mus unification.
218 // http://crbug.com/671246.
Scott Violet58ae95b2017-11-15 06:25:53219 friend class WindowManager;
sky00f98a372017-01-11 06:03:49220
221 // Creates a new RootWindowController with the specified host. Only one of
222 // |ash_host| or |window_tree_host| should be specified. This takes ownership
223 // of the supplied arguments.
224 // TODO(sky): mash should create AshWindowTreeHost, http://crbug.com/671246.
225 RootWindowController(AshWindowTreeHost* ash_host,
226 aura::WindowTreeHost* window_tree_host);
[email protected]a273d33a2013-10-17 12:41:21227
jamescookfda159002016-10-21 18:48:57228 // Initializes the RootWindowController based on |root_window_type|.
229 void Init(RootWindowType root_window_type);
[email protected]a273d33a2013-10-17 12:41:21230
[email protected]756bda12013-07-03 08:17:06231 void InitLayoutManagers();
232
Aga Wronska0514fd62019-03-25 20:11:37233 AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManager() const;
234
Aga Wronskae195ad22017-12-20 01:38:11235 // Initializes the shelf for this root window and notifies observers.
236 void InitializeShelf();
237
varkha515b43462017-05-26 23:21:27238 // Creates the containers (aura::Windows) used by the shell.
skyb6643832017-01-11 22:08:45239 void CreateContainers();
240
msw607227f82016-08-30 17:22:39241 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
jamescookfda159002016-10-21 18:48:57242 // The initial color is determined by the |root_window_type| and whether or
243 // not this is the first boot.
244 void CreateSystemWallpaper(RootWindowType root_window_type);
[email protected]756bda12013-07-03 08:17:06245
sky27344382017-03-08 21:30:32246 // Resets Shell::GetRootWindowForNewWindows() if appropriate. This is called
skyb6643832017-01-11 22:08:45247 // during shutdown to make sure GetRootWindowForNewWindows() isn't referencing
248 // this.
249 void ResetRootForNewWindowsIfNecessary();
250
Alexander Shabalin5c910fc2017-12-08 23:29:47251 // Callback for MenuRunner.
Matthew Mourgos3850cda2019-04-26 21:21:41252 void OnMenuClosed();
sky8d971a0a2016-09-21 23:37:57253
Toni Barzic712399152018-02-15 17:38:40254 // Passed as callback to |wallpaper_widget_controller_| - run when the
255 // wallpaper widget is first set.
256 void OnFirstWallpaperWidgetSet();
257
dchenga94547472016-04-08 08:41:11258 std::unique_ptr<AshWindowTreeHost> ash_host_;
sky00f98a372017-01-11 06:03:49259 std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
260 // This comes from |ash_host_| or |mus_window_tree_host_|.
261 aura::WindowTreeHost* window_tree_host_;
skyee78dde2016-06-01 01:21:43262
skyb6643832017-01-11 22:08:45263 // LayoutManagers are owned by the window they are installed on.
skyb6643832017-01-11 22:08:45264 wm::RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
265
266 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
skyb6643832017-01-11 22:08:45267
268 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
269
270 // Manages the context menu.
Matthew Mourgos3850cda2019-04-26 21:21:41271 std::unique_ptr<AppMenuModelAdapter> root_window_menu_model_adapter_;
skyee78dde2016-06-01 01:21:43272
dchenga94547472016-04-08 08:41:11273 std::unique_ptr<StackingController> stacking_controller_;
[email protected]2a2caa02013-01-22 20:50:36274
jamescookbe6ed822016-06-06 20:08:55275 // The shelf controller for this root window. Exists for the entire lifetime
276 // of the RootWindowController so that it is safe for observers to be added
277 // to it during construction of the shelf widget and status tray.
James Cook840177e2017-05-25 02:20:01278 std::unique_ptr<Shelf> shelf_;
jamescookbe6ed822016-06-06 20:08:55279
jamescook788b4fc2017-05-18 16:16:06280 // TODO(jamescook): Eliminate this. It is left over from legacy shelf code and
281 // doesn't mean anything in particular.
282 bool shelf_initialized_ = false;
283
msw607227f82016-08-30 17:22:39284 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
[email protected]a825e8312014-05-05 22:05:01285
[email protected]a825e8312014-05-05 22:05:01286 // Responsible for initializing TouchExplorationController when spoken
287 // feedback is on.
James Cookd3332922018-03-09 15:54:13288 std::unique_ptr<TouchExplorationManager> touch_exploration_manager_;
[email protected]697f04c2012-10-03 01:15:10289
James Cook08ebee42018-08-07 04:06:42290 // Heads-up displays for touch events for this root. Not owned. Manages its
291 // own lifetime. Whenever the widget showing a HUD is being destroyed (e.g.
292 // because of detaching a display), the HUD deletes itself.
James Cookddb9a762018-08-14 20:44:57293 TouchObserverHUD* touch_observer_hud_ = nullptr;
[email protected]58175042013-04-01 19:27:13294
dchenga94547472016-04-08 08:41:11295 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
[email protected]0bf61732013-07-02 04:35:10296
Toni Barzic98c44eb2017-10-13 20:57:50297 std::unique_ptr<LockScreenActionBackgroundController>
298 lock_screen_action_background_controller_;
299
James Cookee2daef2018-03-10 01:48:10300 // Whether child windows have been closed during shutdown. Exists to avoid
301 // calling related cleanup code more than once.
302 bool did_close_child_windows_ = false;
303
Aga Wronskaf053e522019-03-27 00:08:42304 std::unique_ptr<WorkAreaInsets> work_area_insets_;
Aga Wronska5f0a7e072019-03-26 17:31:20305
skyabcae812017-01-18 17:01:34306 static std::vector<RootWindowController*>* root_window_controllers_;
307
[email protected]d90b8392012-06-13 09:34:56308 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
309};
310
[email protected]76bc4632014-06-16 19:07:46311} // namespace ash
[email protected]d90b8392012-06-13 09:34:56312
[email protected]76bc4632014-06-16 19:07:46313#endif // ASH_ROOT_WINDOW_CONTROLLER_H_