1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef ASH_ROOT_WINDOW_CONTROLLER_H_
6 #define ASH_ROOT_WINDOW_CONTROLLER_H_
12 #include "ash/ash_export.h"
13 #include "ash/public/cpp/shelf_types.h"
14 #include "ash/style/ash_color_provider_source.h"
15 #include "ash/wm/workspace/workspace_types.h"
16 #include "base/gtest_prod_util.h"
17 #include "ui/aura/window.h"
18 #include "ui/aura/window_tree_host.h"
30 class SimpleMenuModel;
39 class ScopedCaptureClient;
43 class AccessibilityPanelLayoutManager;
44 class AlwaysOnTopController;
45 class AppMenuModelAdapter;
46 class AshWindowTreeHost;
47 class LockScreenActionBackgroundController;
48 enum class LoginStatus;
49 class RootWindowLayoutManager;
51 class ShelfLayoutManager;
52 class SplitViewController;
53 class StackingController;
54 class StatusAreaWidget;
55 class SystemModalContainerLayoutManager;
56 class SystemWallpaperController;
57 class TouchExplorationManager;
59 class TouchHudProjection;
60 class WallpaperWidgetController;
64 class SecurityCurtainWidgetController;
67 // This class maintains the per root window state for ash. This class
68 // owns the root window and other dependent objects that should be
69 // deleted upon the deletion of the root window. This object is
70 // indirectly owned and deleted by |WindowTreeHostManager|.
71 // The RootWindowController for particular root window is stored in
72 // its property (RootWindowSettings) and can be obtained using
73 // |RootWindowController::ForWindow(aura::Window*)| function.
74 class ASH_EXPORT RootWindowController {
76 // Enumerates the type of display. If there is only a single display then
77 // it is primary. In a multi-display environment one monitor is deemed the
78 // PRIMARY and all others SECONDARY.
79 enum class RootWindowType { PRIMARY, SECONDARY };
81 RootWindowController(const RootWindowController&) = delete;
82 RootWindowController& operator=(const RootWindowController&) = delete;
84 ~RootWindowController();
86 // Creates and Initialize the RootWindowController for primary display.
87 // Returns a pointer to the newly created controller.
88 static RootWindowController* CreateForPrimaryDisplay(AshWindowTreeHost* host);
90 // Creates and Initialize the RootWindowController for secondary displays.
91 // Returns a pointer to the newly created controller.
92 static RootWindowController* CreateForSecondaryDisplay(
93 AshWindowTreeHost* host);
95 // Returns a RootWindowController of the window's root window.
96 static RootWindowController* ForWindow(const aura::Window* window);
98 // Returns the RootWindowController of the target root window.
99 static RootWindowController* ForTargetRootWindow();
101 static std::vector<RootWindowController*> root_window_controllers() {
102 return root_window_controllers_ ? *root_window_controllers_
103 : std::vector<RootWindowController*>();
106 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
107 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
109 aura::WindowTreeHost* GetHost();
110 const aura::WindowTreeHost* GetHost() const;
111 aura::Window* GetRootWindow();
112 const aura::Window* GetRootWindow() const;
114 SplitViewController* split_view_controller() const {
115 return split_view_controller_.get();
118 Shelf* shelf() const { return shelf_.get(); }
120 TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
121 TouchHudProjection* touch_hud_projection() const {
122 return touch_hud_projection_;
125 // Set touch HUDs for this root window controller. The root window controller
126 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
127 // the widget showing a HUD is being destroyed (e.g. because of detaching a
128 // display), the HUD deletes itself.
129 void set_touch_hud_debug(TouchHudDebug* hud) { touch_hud_debug_ = hud; }
130 void set_touch_hud_projection(TouchHudProjection* hud) {
131 touch_hud_projection_ = hud;
134 RootWindowLayoutManager* root_window_layout_manager() {
135 return root_window_layout_manager_;
138 // Returns parameters of the work area associated with this root window.
139 WorkAreaInsets* work_area_insets() { return work_area_insets_.get(); }
141 // Access the shelf layout manager associated with this root
142 // window controller, NULL if no such shelf exists.
143 ShelfLayoutManager* GetShelfLayoutManager();
145 // Returns the layout manager for the appropriate modal-container. If the
146 // window is inside the lockscreen modal container, then the layout manager
147 // for that is returned. Otherwise the layout manager for the default modal
148 // container is returned.
149 // If no window is specified (i.e. |window| is null), then the lockscreen
150 // modal container is used if the screen is currently locked. Otherwise, the
151 // default modal container is used.
152 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
153 aura::Window* window);
155 AlwaysOnTopController* always_on_top_controller() {
156 return always_on_top_controller_.get();
159 // May return null, for example for a secondary monitor at the login screen.
160 StatusAreaWidget* GetStatusAreaWidget();
162 // Returns if system tray and its widget is visible.
163 bool IsSystemTrayVisible();
165 // True if the window can receive events on this root window.
166 bool CanWindowReceiveEvents(aura::Window* window);
168 // Returns the window events will be targeted at for the specified location
169 // (in screen coordinates).
171 // NOTE: the returned window may not contain the location as resize handles
172 // may extend outside the bounds of the window.
173 aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
175 // Gets the last location seen in a mouse event in this root window's
176 // coordinates. This may return a point outside the root window's bounds.
177 gfx::Point GetLastMouseLocationInRoot();
179 aura::Window* GetContainer(int container_id);
180 const aura::Window* GetContainer(int container_id) const;
182 WallpaperWidgetController* wallpaper_widget_controller() {
183 return wallpaper_widget_controller_.get();
186 LockScreenActionBackgroundController*
187 lock_screen_action_background_controller() {
188 return lock_screen_action_background_controller_.get();
191 AshColorProviderSource* color_provider_source() {
192 return color_provider_source_.get();
195 // Deletes associated objects and clears the state, but doesn't delete
196 // the root window yet. This is used to delete a secondary displays'
197 // root window safely when the display disconnect signal is received,
198 // which may come while we're in the nested run loop.
201 // Deletes all child windows and performs necessary cleanup.
202 void CloseChildWindows();
204 // Moves child windows to |dest|.
205 // TODO(afakhry): Consider renaming this function to avoid misuse. It is only
206 // called by WindowTreeHostManager::DeleteHost(), and has destructive side
207 // effects like deleting the workspace controllers, so it shouldn't be called
208 // for something else.
209 void MoveWindowsTo(aura::Window* dest);
211 // Initialize touch HUDs if necessary.
212 void InitTouchHuds();
214 // Returns the topmost window or one of its transient parents, if any of them
215 // are in fullscreen mode.
216 // TODO(afakhry): Rename this to imply getting the fullscreen window on the
217 // currently active desk on this root.
218 aura::Window* GetWindowForFullscreenMode();
220 // Returns true if window is fulllscreen and the shelf is hidden.
221 bool IsInFullscreenMode();
223 // If touch exploration is enabled, update the touch exploration
224 // controller so that synthesized touch events are anchored at this point.
225 void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
227 // Shows a context menu at the |location_in_screen|.
228 void ShowContextMenu(const gfx::Point& location_in_screen,
229 ui::MenuSourceType source_type);
230 void HideContextMenu();
231 void HideContextMenuNoAnimation();
232 bool IsContextMenuShown() const;
234 // Called when the login status changes after login (such as lock/unlock).
235 void UpdateAfterLoginStatusChange(LoginStatus status);
237 void CreateAmbientWidget();
238 void CloseAmbientWidget(bool immediately);
239 bool HasAmbientWidget() const;
241 views::Widget* ambient_widget_for_testing() { return ambient_widget_.get(); }
242 AppMenuModelAdapter* menu_model_adapter_for_testing() {
243 return root_window_menu_model_adapter_.get();
246 // Returns accessibility panel layout manager for this root window.
247 AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest();
249 void SetSecurityCurtainWidgetController(
250 std::unique_ptr<curtain::SecurityCurtainWidgetController> controller);
251 void ClearSecurityCurtainWidgetController();
252 curtain::SecurityCurtainWidgetController*
253 security_curtain_widget_controller();
256 FRIEND_TEST_ALL_PREFIXES(RootWindowControllerTest,
257 ContextMenuDisappearsInTabletMode);
259 // Takes ownership of |ash_host|.
260 explicit RootWindowController(AshWindowTreeHost* ash_host);
262 // Initializes the RootWindowController based on |root_window_type|.
263 void Init(RootWindowType root_window_type);
265 void InitLayoutManagers(
266 std::unique_ptr<RootWindowLayoutManager> root_window_layout_manager);
268 AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManager() const;
270 // Creates the containers (aura::Windows) used by the shell.
271 void CreateContainers();
273 // Creates a new window for use as a container.
274 aura::Window* CreateContainer(int window_id,
276 aura::Window* parent);
278 // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
279 // The initial color is determined by the |root_window_type| and whether or
280 // not this is the first boot.
281 void CreateSystemWallpaper(RootWindowType root_window_type);
283 // Callback for MenuRunner.
286 // Passed as callback to |wallpaper_widget_controller_| - run when the
287 // wallpaper widget is first set.
288 void OnFirstWallpaperWidgetSet();
290 std::unique_ptr<AshWindowTreeHost> ash_host_;
291 // |ash_host_| as a WindowTreeHost.
292 aura::WindowTreeHost* window_tree_host_;
294 // LayoutManagers are owned by the window they are installed on.
295 RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
297 std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
299 std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
301 // Manages the context menu.
302 std::unique_ptr<AppMenuModelAdapter> root_window_menu_model_adapter_;
303 std::unique_ptr<ui::SimpleMenuModel> sort_apps_submenu_;
305 std::unique_ptr<StackingController> stacking_controller_;
307 std::unique_ptr<SplitViewController> split_view_controller_;
309 // The shelf controller for this root window. Exists for the entire lifetime
310 // of the RootWindowController so that it is safe for observers to be added
311 // to it during construction of the shelf widget and status tray.
312 std::unique_ptr<Shelf> shelf_;
314 std::unique_ptr<SystemWallpaperController> system_wallpaper_;
316 // Responsible for initializing TouchExplorationController when spoken
318 std::unique_ptr<TouchExplorationManager> touch_exploration_manager_;
320 // Heads-up displays for touch events. These HUDs are not owned by the root
321 // window controller and manage their own lifetimes.
322 TouchHudDebug* touch_hud_debug_ = nullptr;
323 TouchHudProjection* touch_hud_projection_ = nullptr;
325 std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
327 std::unique_ptr<LockScreenActionBackgroundController>
328 lock_screen_action_background_controller_;
330 std::unique_ptr<views::Widget> ambient_widget_;
332 std::unique_ptr<curtain::SecurityCurtainWidgetController>
333 security_curtain_widget_controller_;
335 std::unique_ptr<AshColorProviderSource> color_provider_source_;
337 // Whether child windows have been closed during shutdown. Exists to avoid
338 // calling related cleanup code more than once.
339 bool did_close_child_windows_ = false;
341 std::unique_ptr<WorkAreaInsets> work_area_insets_;
343 static std::vector<RootWindowController*>* root_window_controllers_;
348 #endif // ASH_ROOT_WINDOW_CONTROLLER_H_