blob: e5ce43850e24c2baf103f28f765be2dc909a5094 [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]86459e2c2013-04-10 13:39:2427namespace keyboard {
28class KeyboardController;
29}
30
[email protected]3537d472014-01-15 05:45:3131namespace ui {
Alex Newcomer76f7dab62018-02-02 17:23:3732class SimpleMenuModel;
sky00f98a372017-01-11 06:03:4933class WindowTreeHost;
[email protected]3537d472014-01-15 05:45:3134}
35
[email protected]e319c7e2014-03-14 19:56:1436namespace views {
skyb6643832017-01-11 22:08:4537class MenuRunner;
[email protected]e319c7e2014-03-14 19:56:1438}
39
40namespace wm {
[email protected]e319c7e2014-03-14 19:56:1441class ScopedCaptureClient;
42}
43
[email protected]d90b8392012-06-13 09:34:5644namespace ash {
skyb6643832017-01-11 22:08:4545class AlwaysOnTopController;
[email protected]f5c9dbc2014-04-11 08:13:4546class AshWindowTreeHost;
Toni Barzic98c44eb2017-10-13 20:57:5047class LockScreenActionBackgroundController;
mswb2416052016-06-24 21:23:4548enum class LoginStatus;
James Cook840177e2017-05-25 02:20:0149class Shelf;
[email protected]e74aaf0a2012-10-12 18:42:2850class ShelfLayoutManager;
[email protected]093b8d642014-04-03 20:59:2851class StackingController;
[email protected]e74aaf0a2012-10-12 18:42:2852class StatusAreaWidget;
skyb6643832017-01-11 22:08:4553class SystemModalContainerLayoutManager;
[email protected]093b8d642014-04-03 20:59:2854class SystemTray;
msw607227f82016-08-30 17:22:3955class SystemWallpaperController;
James Cookd3332922018-03-09 15:54:1356class TouchExplorationManager;
James Cookddb9a762018-08-14 20:44:5757class TouchObserverHUD;
skyb6643832017-01-11 22:08:4558class WallpaperWidgetController;
sky8a8ffd22017-01-19 15:55:2959class WindowManager;
Scott Violet58ae95b2017-11-15 06:25:5360class WorkspaceController;
sky00f98a372017-01-11 06:03:4961
skyb6643832017-01-11 22:08:4562namespace wm {
63class RootWindowLayoutManager;
64}
65
[email protected]d90b8392012-06-13 09:34:5666// This class maintains the per root window state for ash. This class
67// owns the root window and other dependent objects that should be
[email protected]a273d33a2013-10-17 12:41:2168// deleted upon the deletion of the root window. This object is
oshimae2818922015-07-28 01:18:5269// indirectly owned and deleted by |WindowTreeHostManager|.
[email protected]a273d33a2013-10-17 12:41:2170// The RootWindowController for particular root window is stored in
71// its property (RootWindowSettings) and can be obtained using
msw257a6a232017-06-01 01:46:3072// |RootWindowController::ForWindow(aura::Window*)| function.
James Cookbd0b7792017-11-17 03:24:2673class ASH_EXPORT RootWindowController {
[email protected]d90b8392012-06-13 09:34:5674 public:
sky00f98a372017-01-11 06:03:4975 // Enumerates the type of display. If there is only a single display then
76 // it is primary. In a multi-display environment one monitor is deemed the
77 // PRIMARY and all others SECONDARY.
78 enum class RootWindowType { PRIMARY, SECONDARY };
79
James Cookbd0b7792017-11-17 03:24:2680 ~RootWindowController();
sky00f98a372017-01-11 06:03:4981
[email protected]a273d33a2013-10-17 12:41:2182 // Creates and Initialize the RootWindowController for primary display.
[email protected]f5c9dbc2014-04-11 08:13:4583 static void CreateForPrimaryDisplay(AshWindowTreeHost* host);
[email protected]a273d33a2013-10-17 12:41:2184
85 // Creates and Initialize the RootWindowController for secondary displays.
[email protected]f5c9dbc2014-04-11 08:13:4586 static void CreateForSecondaryDisplay(AshWindowTreeHost* host);
[email protected]d90b8392012-06-13 09:34:5687
[email protected]a0afeb12012-12-10 22:57:0988 // Returns a RootWindowController of the window's root window.
[email protected]ccff3d72013-02-06 04:26:2889 static RootWindowController* ForWindow(const aura::Window* window);
[email protected]a0afeb12012-12-10 22:57:0990
[email protected]d17642d2013-09-12 23:44:3891 // Returns the RootWindowController of the target root window.
[email protected]093b8d642014-04-03 20:59:2892 static RootWindowController* ForTargetRootWindow();
[email protected]a0afeb12012-12-10 22:57:0993
skyabcae812017-01-18 17:01:3494 static std::vector<RootWindowController*> root_window_controllers() {
95 return root_window_controllers_ ? *root_window_controllers_
96 : std::vector<RootWindowController*>();
97 }
98
sky00f98a372017-01-11 06:03:4999 // TODO(sky): move these to a separate class or use AshWindowTreeHost in
100 // mash. http://crbug.com/671246.
[email protected]f5c9dbc2014-04-11 08:13:45101 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
102 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
103
104 aura::WindowTreeHost* GetHost();
105 const aura::WindowTreeHost* GetHost() const;
106 aura::Window* GetRootWindow();
107 const aura::Window* GetRootWindow() const;
[email protected]d90b8392012-06-13 09:34:56108
skyb6643832017-01-11 22:08:45109 WorkspaceController* workspace_controller() {
110 return workspace_controller_.get();
111 }
112
113 wm::WorkspaceWindowState GetWorkspaceWindowState();
[email protected]d90b8392012-06-13 09:34:56114
James Cook840177e2017-05-25 02:20:01115 Shelf* shelf() const { return shelf_.get(); }
jamescookbe6ed822016-06-06 20:08:55116
James Cookddb9a762018-08-14 20:44:57117 TouchObserverHUD* touch_observer_hud() const { return touch_observer_hud_; }
118 void set_touch_observer_hud(TouchObserverHUD* hud) {
119 touch_observer_hud_ = hud;
120 }
[email protected]2b8a9bb2013-07-01 22:43:40121
skyb6643832017-01-11 22:08:45122 wm::RootWindowLayoutManager* root_window_layout_manager() {
123 return root_window_layout_manager_;
124 }
125
[email protected]478c6c32013-03-09 02:50:58126 // Access the shelf layout manager associated with this root
127 // window controller, NULL if no such shelf exists.
128 ShelfLayoutManager* GetShelfLayoutManager();
[email protected]d90b8392012-06-13 09:34:56129
skyb6643832017-01-11 22:08:45130 // Returns the layout manager for the appropriate modal-container. If the
131 // window is inside the lockscreen modal container, then the layout manager
132 // for that is returned. Otherwise the layout manager for the default modal
133 // container is returned.
134 // If no window is specified (i.e. |window| is null), then the lockscreen
135 // modal container is used if the screen is currently locked. Otherwise, the
136 // default modal container is used.
137 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
sky97f9a7432017-05-09 05:14:31138 aura::Window* window);
skyb6643832017-01-11 22:08:45139
140 AlwaysOnTopController* always_on_top_controller() {
141 return always_on_top_controller_.get();
142 }
143
jamescookb551aba2016-09-01 01:00:16144 // May return null, for example for a secondary monitor at the login screen.
145 StatusAreaWidget* GetStatusAreaWidget();
146
[email protected]a0afeb12012-12-10 22:57:09147 // Returns the system tray on this root window. Note that
[email protected]864b58552013-12-19 04:19:38148 // calling this on the root window that doesn't have a shelf will
[email protected]a0afeb12012-12-10 22:57:09149 // lead to a crash.
150 SystemTray* GetSystemTray();
151
Tetsui Ohkubo2c474b752018-06-28 01:35:41152 // Returns if system tray and its widget is visible.
153 bool IsSystemTrayVisible();
154
oshima9a61ecf2016-06-18 10:43:05155 // True if the window can receive events on this root window.
156 bool CanWindowReceiveEvents(aura::Window* window);
157
skyb6643832017-01-11 22:08:45158 // Returns the window events will be targeted at for the specified location
159 // (in screen coordinates).
160 //
161 // NOTE: the returned window may not contain the location as resize handles
162 // may extend outside the bounds of the window.
sky4befdb0d2017-05-18 23:50:26163 aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
skyb6643832017-01-11 22:08:45164
165 // Gets the last location seen in a mouse event in this root window's
166 // coordinates. This may return a point outside the root window's bounds.
167 gfx::Point GetLastMouseLocationInRoot();
168
[email protected]d90b8392012-06-13 09:34:56169 aura::Window* GetContainer(int container_id);
[email protected]d8a24952013-08-05 20:05:05170 const aura::Window* GetContainer(int container_id) const;
[email protected]d90b8392012-06-13 09:34:56171
skyb6643832017-01-11 22:08:45172 WallpaperWidgetController* wallpaper_widget_controller() {
173 return wallpaper_widget_controller_.get();
174 }
skyb6643832017-01-11 22:08:45175
Toni Barzic98c44eb2017-10-13 20:57:50176 LockScreenActionBackgroundController*
177 lock_screen_action_background_controller() {
178 return lock_screen_action_background_controller_.get();
179 }
180
[email protected]6675e1c2012-09-11 09:15:45181 // Deletes associated objects and clears the state, but doesn't delete
182 // the root window yet. This is used to delete a secondary displays'
183 // root window safely when the display disconnect signal is received,
gab2998ee72017-05-05 16:23:50184 // which may come while we're in the nested run loop.
[email protected]6675e1c2012-09-11 09:15:45185 void Shutdown();
186
[email protected]d90b8392012-06-13 09:34:56187 // Deletes all child windows and performs necessary cleanup.
188 void CloseChildWindows();
189
[email protected]f1853122012-06-27 16:21:26190 // Moves child windows to |dest|.
[email protected]bf9cdb362013-10-25 19:22:45191 void MoveWindowsTo(aura::Window* dest);
[email protected]f1853122012-06-27 16:21:26192
[email protected]e74aaf0a2012-10-12 18:42:28193 // Force the shelf to query for it's current visibility state.
194 void UpdateShelfVisibility();
195
[email protected]2b8a9bb2013-07-01 22:43:40196 // Initialize touch HUDs if necessary.
197 void InitTouchHuds();
198
[email protected]2c9171d22013-12-10 21:55:10199 // Returns the topmost window or one of its transient parents, if any of them
200 // are in fullscreen mode.
varkhad99fa94f2015-06-29 22:35:46201 aura::Window* GetWindowForFullscreenMode();
[email protected]2ee2f5d2013-01-10 23:37:16202
[email protected]b6ba05d902013-10-04 21:38:45203 // Activate virtual keyboard on current root window controller.
204 void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
205
206 // Deactivate virtual keyboard on current root window controller.
207 void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
208
dmazzoniff86e3472016-06-03 19:52:32209 // If touch exploration is enabled, update the touch exploration
210 // controller so that synthesized touch events are anchored at this point.
211 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
212
skyb6643832017-01-11 22:08:45213 // Shows a context menu at the |location_in_screen|.
214 void ShowContextMenu(const gfx::Point& location_in_screen,
215 ui::MenuSourceType source_type);
Sammie Quon646e2632018-02-27 19:55:40216 void HideContextMenu();
Weidong Guo053b9292018-04-24 23:46:10217 bool IsContextMenuShown() const;
skyb6643832017-01-11 22:08:45218
219 // Called when the login status changes after login (such as lock/unlock).
skyb6643832017-01-11 22:08:45220 void UpdateAfterLoginStatusChange(LoginStatus status);
221
[email protected]431552c2012-10-23 00:38:33222 private:
Sammie Quon646e2632018-02-27 19:55:40223 FRIEND_TEST_ALL_PREFIXES(RootWindowControllerTest,
224 ContextMenuDisappearsInTabletMode);
225
sky00f98a372017-01-11 06:03:49226 // TODO(sky): remove this. Temporary during ash-mus unification.
227 // http://crbug.com/671246.
Scott Violet58ae95b2017-11-15 06:25:53228 friend class WindowManager;
sky00f98a372017-01-11 06:03:49229
230 // Creates a new RootWindowController with the specified host. Only one of
231 // |ash_host| or |window_tree_host| should be specified. This takes ownership
232 // of the supplied arguments.
233 // TODO(sky): mash should create AshWindowTreeHost, http://crbug.com/671246.
234 RootWindowController(AshWindowTreeHost* ash_host,
235 aura::WindowTreeHost* window_tree_host);
[email protected]a273d33a2013-10-17 12:41:21236
jamescookfda159002016-10-21 18:48:57237 // Initializes the RootWindowController based on |root_window_type|.
238 void Init(RootWindowType root_window_type);
[email protected]a273d33a2013-10-17 12:41:21239
[email protected]756bda12013-07-03 08:17:06240 void InitLayoutManagers();
241
Aga Wronskae195ad22017-12-20 01:38:11242 // Initializes the shelf for this root window and notifies observers.
243 void InitializeShelf();
244
varkha515b43462017-05-26 23:21:27245 // Creates the containers (aura::Windows) used by the shell.
skyb6643832017-01-11 22:08:45246 void CreateContainers();
247
msw607227f82016-08-30 17:22:39248 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
jamescookfda159002016-10-21 18:48:57249 // The initial color is determined by the |root_window_type| and whether or
250 // not this is the first boot.
251 void CreateSystemWallpaper(RootWindowType root_window_type);
[email protected]756bda12013-07-03 08:17:06252
sky27344382017-03-08 21:30:32253 // Resets Shell::GetRootWindowForNewWindows() if appropriate. This is called
skyb6643832017-01-11 22:08:45254 // during shutdown to make sure GetRootWindowForNewWindows() isn't referencing
255 // this.
256 void ResetRootForNewWindowsIfNecessary();
257
Alexander Shabalin5c910fc2017-12-08 23:29:47258 // Callback for MenuRunner.
Alex Newcomer76f7dab62018-02-02 17:23:37259 void OnMenuClosed(const base::TimeTicks desktop_context_menu_show_time);
sky8d971a0a2016-09-21 23:37:57260
Toni Barzic712399152018-02-15 17:38:40261 // Passed as callback to |wallpaper_widget_controller_| - run when the
262 // wallpaper widget is first set.
263 void OnFirstWallpaperWidgetSet();
264
dchenga94547472016-04-08 08:41:11265 std::unique_ptr<AshWindowTreeHost> ash_host_;
sky00f98a372017-01-11 06:03:49266 std::unique_ptr<aura::WindowTreeHost> mus_window_tree_host_;
267 // This comes from |ash_host_| or |mus_window_tree_host_|.
268 aura::WindowTreeHost* window_tree_host_;
skyee78dde2016-06-01 01:21:43269
skyb6643832017-01-11 22:08:45270 // LayoutManagers are owned by the window they are installed on.
skyb6643832017-01-11 22:08:45271 wm::RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
272
273 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
skyb6643832017-01-11 22:08:45274 std::unique_ptr<WorkspaceController> workspace_controller_;
275
276 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
277
278 // Manages the context menu.
Alex Newcomer76f7dab62018-02-02 17:23:37279 std::unique_ptr<ui::SimpleMenuModel> menu_model_;
skyb6643832017-01-11 22:08:45280 std::unique_ptr<views::MenuRunner> menu_runner_;
skyee78dde2016-06-01 01:21:43281
dchenga94547472016-04-08 08:41:11282 std::unique_ptr<StackingController> stacking_controller_;
[email protected]2a2caa02013-01-22 20:50:36283
jamescookbe6ed822016-06-06 20:08:55284 // The shelf controller for this root window. Exists for the entire lifetime
285 // of the RootWindowController so that it is safe for observers to be added
286 // to it during construction of the shelf widget and status tray.
James Cook840177e2017-05-25 02:20:01287 std::unique_ptr<Shelf> shelf_;
jamescookbe6ed822016-06-06 20:08:55288
jamescook788b4fc2017-05-18 16:16:06289 // TODO(jamescook): Eliminate this. It is left over from legacy shelf code and
290 // doesn't mean anything in particular.
291 bool shelf_initialized_ = false;
292
msw607227f82016-08-30 17:22:39293 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
[email protected]a825e8312014-05-05 22:05:01294
[email protected]a825e8312014-05-05 22:05:01295 // Responsible for initializing TouchExplorationController when spoken
296 // feedback is on.
James Cookd3332922018-03-09 15:54:13297 std::unique_ptr<TouchExplorationManager> touch_exploration_manager_;
[email protected]697f04c2012-10-03 01:15:10298
James Cook08ebee42018-08-07 04:06:42299 // Heads-up displays for touch events for this root. Not owned. Manages its
300 // own lifetime. Whenever the widget showing a HUD is being destroyed (e.g.
301 // because of detaching a display), the HUD deletes itself.
James Cookddb9a762018-08-14 20:44:57302 TouchObserverHUD* touch_observer_hud_ = nullptr;
[email protected]58175042013-04-01 19:27:13303
dchenga94547472016-04-08 08:41:11304 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
[email protected]0bf61732013-07-02 04:35:10305
Toni Barzic98c44eb2017-10-13 20:57:50306 std::unique_ptr<LockScreenActionBackgroundController>
307 lock_screen_action_background_controller_;
308
James Cookee2daef2018-03-10 01:48:10309 // Whether child windows have been closed during shutdown. Exists to avoid
310 // calling related cleanup code more than once.
311 bool did_close_child_windows_ = false;
312
skyabcae812017-01-18 17:01:34313 static std::vector<RootWindowController*>* root_window_controllers_;
314
[email protected]d90b8392012-06-13 09:34:56315 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
316};
317
[email protected]76bc4632014-06-16 19:07:46318} // namespace ash
[email protected]d90b8392012-06-13 09:34:56319
[email protected]76bc4632014-06-16 19:07:46320#endif // ASH_ROOT_WINDOW_CONTROLLER_H_