root_window_controller.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. // 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. #ifndef ASH_ROOT_WINDOW_CONTROLLER_H_
  5. #define ASH_ROOT_WINDOW_CONTROLLER_H_
  6. #include <map>
  7. #include <memory>
  8. #include <vector>
  9. #include "ash/ash_export.h"
  10. #include "ash/public/cpp/shelf_types.h"
  11. #include "ash/style/ash_color_provider_source.h"
  12. #include "ash/wm/workspace/workspace_types.h"
  13. #include "base/gtest_prod_util.h"
  14. #include "ui/aura/window.h"
  15. #include "ui/aura/window_tree_host.h"
  16. namespace aura {
  17. class Window;
  18. }
  19. namespace gfx {
  20. class Point;
  21. }
  22. namespace ui {
  23. class WindowTreeHost;
  24. class SimpleMenuModel;
  25. }
  26. namespace views {
  27. class MenuRunner;
  28. class Widget;
  29. } // namespace views
  30. namespace wm {
  31. class ScopedCaptureClient;
  32. }
  33. namespace ash {
  34. class AccessibilityPanelLayoutManager;
  35. class AlwaysOnTopController;
  36. class AppMenuModelAdapter;
  37. class AshWindowTreeHost;
  38. class LockScreenActionBackgroundController;
  39. enum class LoginStatus;
  40. class RootWindowLayoutManager;
  41. class Shelf;
  42. class ShelfLayoutManager;
  43. class SplitViewController;
  44. class StackingController;
  45. class StatusAreaWidget;
  46. class SystemModalContainerLayoutManager;
  47. class SystemWallpaperController;
  48. class TouchExplorationManager;
  49. class TouchHudDebug;
  50. class TouchHudProjection;
  51. class WallpaperWidgetController;
  52. class WorkAreaInsets;
  53. // This class maintains the per root window state for ash. This class
  54. // owns the root window and other dependent objects that should be
  55. // deleted upon the deletion of the root window. This object is
  56. // indirectly owned and deleted by |WindowTreeHostManager|.
  57. // The RootWindowController for particular root window is stored in
  58. // its property (RootWindowSettings) and can be obtained using
  59. // |RootWindowController::ForWindow(aura::Window*)| function.
  60. class ASH_EXPORT RootWindowController {
  61. public:
  62. // Enumerates the type of display. If there is only a single display then
  63. // it is primary. In a multi-display environment one monitor is deemed the
  64. // PRIMARY and all others SECONDARY.
  65. enum class RootWindowType { PRIMARY, SECONDARY };
  66. RootWindowController(const RootWindowController&) = delete;
  67. RootWindowController& operator=(const RootWindowController&) = delete;
  68. ~RootWindowController();
  69. // Creates and Initialize the RootWindowController for primary display.
  70. // Returns a pointer to the newly created controller.
  71. static RootWindowController* CreateForPrimaryDisplay(AshWindowTreeHost* host);
  72. // Creates and Initialize the RootWindowController for secondary displays.
  73. // Returns a pointer to the newly created controller.
  74. static RootWindowController* CreateForSecondaryDisplay(
  75. AshWindowTreeHost* host);
  76. // Returns a RootWindowController of the window's root window.
  77. static RootWindowController* ForWindow(const aura::Window* window);
  78. // Returns the RootWindowController of the target root window.
  79. static RootWindowController* ForTargetRootWindow();
  80. static std::vector<RootWindowController*> root_window_controllers() {
  81. return root_window_controllers_ ? *root_window_controllers_
  82. : std::vector<RootWindowController*>();
  83. }
  84. AshWindowTreeHost* ash_host() { return ash_host_.get(); }
  85. const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
  86. aura::WindowTreeHost* GetHost();
  87. const aura::WindowTreeHost* GetHost() const;
  88. aura::Window* GetRootWindow();
  89. const aura::Window* GetRootWindow() const;
  90. SplitViewController* split_view_controller() const {
  91. return split_view_controller_.get();
  92. }
  93. Shelf* shelf() const { return shelf_.get(); }
  94. TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
  95. TouchHudProjection* touch_hud_projection() const {
  96. return touch_hud_projection_;
  97. }
  98. // Set touch HUDs for this root window controller. The root window controller
  99. // will not own the HUDs; their lifetimes are managed by themselves. Whenever
  100. // the widget showing a HUD is being destroyed (e.g. because of detaching a
  101. // display), the HUD deletes itself.
  102. void set_touch_hud_debug(TouchHudDebug* hud) { touch_hud_debug_ = hud; }
  103. void set_touch_hud_projection(TouchHudProjection* hud) {
  104. touch_hud_projection_ = hud;
  105. }
  106. RootWindowLayoutManager* root_window_layout_manager() {
  107. return root_window_layout_manager_;
  108. }
  109. // Returns parameters of the work area associated with this root window.
  110. WorkAreaInsets* work_area_insets() { return work_area_insets_.get(); }
  111. // Access the shelf layout manager associated with this root
  112. // window controller, NULL if no such shelf exists.
  113. ShelfLayoutManager* GetShelfLayoutManager();
  114. // Returns the layout manager for the appropriate modal-container. If the
  115. // window is inside the lockscreen modal container, then the layout manager
  116. // for that is returned. Otherwise the layout manager for the default modal
  117. // container is returned.
  118. // If no window is specified (i.e. |window| is null), then the lockscreen
  119. // modal container is used if the screen is currently locked. Otherwise, the
  120. // default modal container is used.
  121. SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
  122. aura::Window* window);
  123. AlwaysOnTopController* always_on_top_controller() {
  124. return always_on_top_controller_.get();
  125. }
  126. // May return null, for example for a secondary monitor at the login screen.
  127. StatusAreaWidget* GetStatusAreaWidget();
  128. // Returns if system tray and its widget is visible.
  129. bool IsSystemTrayVisible();
  130. // True if the window can receive events on this root window.
  131. bool CanWindowReceiveEvents(aura::Window* window);
  132. // Returns the window events will be targeted at for the specified location
  133. // (in screen coordinates).
  134. //
  135. // NOTE: the returned window may not contain the location as resize handles
  136. // may extend outside the bounds of the window.
  137. aura::Window* FindEventTarget(const gfx::Point& location_in_screen);
  138. // Gets the last location seen in a mouse event in this root window's
  139. // coordinates. This may return a point outside the root window's bounds.
  140. gfx::Point GetLastMouseLocationInRoot();
  141. aura::Window* GetContainer(int container_id);
  142. const aura::Window* GetContainer(int container_id) const;
  143. WallpaperWidgetController* wallpaper_widget_controller() {
  144. return wallpaper_widget_controller_.get();
  145. }
  146. LockScreenActionBackgroundController*
  147. lock_screen_action_background_controller() {
  148. return lock_screen_action_background_controller_.get();
  149. }
  150. AshColorProviderSource* color_provider_source() {
  151. return color_provider_source_.get();
  152. }
  153. // Deletes associated objects and clears the state, but doesn't delete
  154. // the root window yet. This is used to delete a secondary displays'
  155. // root window safely when the display disconnect signal is received,
  156. // which may come while we're in the nested run loop.
  157. void Shutdown();
  158. // Deletes all child windows and performs necessary cleanup.
  159. void CloseChildWindows();
  160. // Moves child windows to |dest|.
  161. // TODO(afakhry): Consider renaming this function to avoid misuse. It is only
  162. // called by WindowTreeHostManager::DeleteHost(), and has destructive side
  163. // effects like deleting the workspace controllers, so it shouldn't be called
  164. // for something else.
  165. void MoveWindowsTo(aura::Window* dest);
  166. // Initialize touch HUDs if necessary.
  167. void InitTouchHuds();
  168. // Returns the topmost window or one of its transient parents, if any of them
  169. // are in fullscreen mode.
  170. // TODO(afakhry): Rename this to imply getting the fullscreen window on the
  171. // currently active desk on this root.
  172. aura::Window* GetWindowForFullscreenMode();
  173. // Returns true if window is fulllscreen and the shelf is hidden.
  174. bool IsInFullscreenMode();
  175. // If touch exploration is enabled, update the touch exploration
  176. // controller so that synthesized touch events are anchored at this point.
  177. void SetTouchAccessibilityAnchorPoint(const gfx::Point& anchor_point);
  178. // Shows a context menu at the |location_in_screen|.
  179. void ShowContextMenu(const gfx::Point& location_in_screen,
  180. ui::MenuSourceType source_type);
  181. void HideContextMenu();
  182. void HideContextMenuNoAnimation();
  183. bool IsContextMenuShown() const;
  184. // Called when the login status changes after login (such as lock/unlock).
  185. void UpdateAfterLoginStatusChange(LoginStatus status);
  186. void CreateAmbientWidget();
  187. void CloseAmbientWidget(bool immediately);
  188. bool HasAmbientWidget() const;
  189. views::Widget* ambient_widget_for_testing() { return ambient_widget_.get(); }
  190. AppMenuModelAdapter* menu_model_adapter_for_testing() {
  191. return root_window_menu_model_adapter_.get();
  192. }
  193. // Returns accessibility panel layout manager for this root window.
  194. AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest();
  195. private:
  196. FRIEND_TEST_ALL_PREFIXES(RootWindowControllerTest,
  197. ContextMenuDisappearsInTabletMode);
  198. // Takes ownership of |ash_host|.
  199. explicit RootWindowController(AshWindowTreeHost* ash_host);
  200. // Initializes the RootWindowController based on |root_window_type|.
  201. void Init(RootWindowType root_window_type);
  202. void InitLayoutManagers();
  203. AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManager() const;
  204. // Creates the containers (aura::Windows) used by the shell.
  205. void CreateContainers();
  206. // Creates a new window for use as a container.
  207. aura::Window* CreateContainer(int window_id,
  208. const char* name,
  209. aura::Window* parent);
  210. // Initializes |system_wallpaper_| and possibly also |boot_splash_screen_|.
  211. // The initial color is determined by the |root_window_type| and whether or
  212. // not this is the first boot.
  213. void CreateSystemWallpaper(RootWindowType root_window_type);
  214. // Callback for MenuRunner.
  215. void OnMenuClosed();
  216. // Passed as callback to |wallpaper_widget_controller_| - run when the
  217. // wallpaper widget is first set.
  218. void OnFirstWallpaperWidgetSet();
  219. std::unique_ptr<AshWindowTreeHost> ash_host_;
  220. // |ash_host_| as a WindowTreeHost.
  221. aura::WindowTreeHost* window_tree_host_;
  222. // LayoutManagers are owned by the window they are installed on.
  223. RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
  224. std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
  225. std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
  226. // Manages the context menu.
  227. std::unique_ptr<AppMenuModelAdapter> root_window_menu_model_adapter_;
  228. std::unique_ptr<ui::SimpleMenuModel> sort_apps_submenu_;
  229. std::unique_ptr<StackingController> stacking_controller_;
  230. std::unique_ptr<SplitViewController> split_view_controller_;
  231. // The shelf controller for this root window. Exists for the entire lifetime
  232. // of the RootWindowController so that it is safe for observers to be added
  233. // to it during construction of the shelf widget and status tray.
  234. std::unique_ptr<Shelf> shelf_;
  235. std::unique_ptr<SystemWallpaperController> system_wallpaper_;
  236. // Responsible for initializing TouchExplorationController when spoken
  237. // feedback is on.
  238. std::unique_ptr<TouchExplorationManager> touch_exploration_manager_;
  239. // Heads-up displays for touch events. These HUDs are not owned by the root
  240. // window controller and manage their own lifetimes.
  241. TouchHudDebug* touch_hud_debug_ = nullptr;
  242. TouchHudProjection* touch_hud_projection_ = nullptr;
  243. std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
  244. std::unique_ptr<LockScreenActionBackgroundController>
  245. lock_screen_action_background_controller_;
  246. std::unique_ptr<views::Widget> ambient_widget_;
  247. std::unique_ptr<AshColorProviderSource> color_provider_source_;
  248. // Whether child windows have been closed during shutdown. Exists to avoid
  249. // calling related cleanup code more than once.
  250. bool did_close_child_windows_ = false;
  251. std::unique_ptr<WorkAreaInsets> work_area_insets_;
  252. static std::vector<RootWindowController*>* root_window_controllers_;
  253. };
  254. } // namespace ash
  255. #endif // ASH_ROOT_WINDOW_CONTROLLER_H_