root_window_controller.h 12 KB

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