[M108 Migration] Support standard build for armv7hl architecture
[platform/framework/web/chromium-efl.git] / ash / root_window_controller.h
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.
4
5 #ifndef ASH_ROOT_WINDOW_CONTROLLER_H_
6 #define ASH_ROOT_WINDOW_CONTROLLER_H_
7
8 #include <map>
9 #include <memory>
10 #include <vector>
11
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"
19
20 namespace aura {
21 class Window;
22 }
23
24 namespace gfx {
25 class Point;
26 }
27
28 namespace ui {
29 class WindowTreeHost;
30 class SimpleMenuModel;
31 }  // namespace ui
32
33 namespace views {
34 class MenuRunner;
35 class Widget;
36 }  // namespace views
37
38 namespace wm {
39 class ScopedCaptureClient;
40 }
41
42 namespace ash {
43 class AccessibilityPanelLayoutManager;
44 class AlwaysOnTopController;
45 class AppMenuModelAdapter;
46 class AshWindowTreeHost;
47 class LockScreenActionBackgroundController;
48 enum class LoginStatus;
49 class RootWindowLayoutManager;
50 class Shelf;
51 class ShelfLayoutManager;
52 class SplitViewController;
53 class StackingController;
54 class StatusAreaWidget;
55 class SystemModalContainerLayoutManager;
56 class SystemWallpaperController;
57 class TouchExplorationManager;
58 class TouchHudDebug;
59 class TouchHudProjection;
60 class WallpaperWidgetController;
61 class WorkAreaInsets;
62
63 namespace curtain {
64 class SecurityCurtainWidgetController;
65 }
66
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 {
75  public:
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 };
80
81   RootWindowController(const RootWindowController&) = delete;
82   RootWindowController& operator=(const RootWindowController&) = delete;
83
84   ~RootWindowController();
85
86   // Creates and Initialize the RootWindowController for primary display.
87   // Returns a pointer to the newly created controller.
88   static RootWindowController* CreateForPrimaryDisplay(AshWindowTreeHost* host);
89
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);
94
95   // Returns a RootWindowController of the window's root window.
96   static RootWindowController* ForWindow(const aura::Window* window);
97
98   // Returns the RootWindowController of the target root window.
99   static RootWindowController* ForTargetRootWindow();
100
101   static std::vector<RootWindowController*> root_window_controllers() {
102     return root_window_controllers_ ? *root_window_controllers_
103                                     : std::vector<RootWindowController*>();
104   }
105
106   AshWindowTreeHost* ash_host() { return ash_host_.get(); }
107   const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
108
109   aura::WindowTreeHost* GetHost();
110   const aura::WindowTreeHost* GetHost() const;
111   aura::Window* GetRootWindow();
112   const aura::Window* GetRootWindow() const;
113
114   SplitViewController* split_view_controller() const {
115     return split_view_controller_.get();
116   }
117
118   Shelf* shelf() const { return shelf_.get(); }
119
120   TouchHudDebug* touch_hud_debug() const { return touch_hud_debug_; }
121   TouchHudProjection* touch_hud_projection() const {
122     return touch_hud_projection_;
123   }
124
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;
132   }
133
134   RootWindowLayoutManager* root_window_layout_manager() {
135     return root_window_layout_manager_;
136   }
137
138   // Returns parameters of the work area associated with this root window.
139   WorkAreaInsets* work_area_insets() { return work_area_insets_.get(); }
140
141   // Access the shelf layout manager associated with this root
142   // window controller, NULL if no such shelf exists.
143   ShelfLayoutManager* GetShelfLayoutManager();
144
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);
154
155   AlwaysOnTopController* always_on_top_controller() {
156     return always_on_top_controller_.get();
157   }
158
159   // May return null, for example for a secondary monitor at the login screen.
160   StatusAreaWidget* GetStatusAreaWidget();
161
162   // Returns if system tray and its widget is visible.
163   bool IsSystemTrayVisible();
164
165   // True if the window can receive events on this root window.
166   bool CanWindowReceiveEvents(aura::Window* window);
167
168   // Returns the window events will be targeted at for the specified location
169   // (in screen coordinates).
170   //
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);
174
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();
178
179   aura::Window* GetContainer(int container_id);
180   const aura::Window* GetContainer(int container_id) const;
181
182   WallpaperWidgetController* wallpaper_widget_controller() {
183     return wallpaper_widget_controller_.get();
184   }
185
186   LockScreenActionBackgroundController*
187   lock_screen_action_background_controller() {
188     return lock_screen_action_background_controller_.get();
189   }
190
191   AshColorProviderSource* color_provider_source() {
192     return color_provider_source_.get();
193   }
194
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.
199   void Shutdown();
200
201   // Deletes all child windows and performs necessary cleanup.
202   void CloseChildWindows();
203
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);
210
211   // Initialize touch HUDs if necessary.
212   void InitTouchHuds();
213
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();
219
220   // Returns true if window is fulllscreen and the shelf is hidden.
221   bool IsInFullscreenMode();
222
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);
226
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;
233
234   // Called when the login status changes after login (such as lock/unlock).
235   void UpdateAfterLoginStatusChange(LoginStatus status);
236
237   void CreateAmbientWidget();
238   void CloseAmbientWidget(bool immediately);
239   bool HasAmbientWidget() const;
240
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();
244   }
245
246   // Returns accessibility panel layout manager for this root window.
247   AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManagerForTest();
248
249   void SetSecurityCurtainWidgetController(
250       std::unique_ptr<curtain::SecurityCurtainWidgetController> controller);
251   void ClearSecurityCurtainWidgetController();
252   curtain::SecurityCurtainWidgetController*
253   security_curtain_widget_controller();
254
255  private:
256   FRIEND_TEST_ALL_PREFIXES(RootWindowControllerTest,
257                            ContextMenuDisappearsInTabletMode);
258
259   // Takes ownership of |ash_host|.
260   explicit RootWindowController(AshWindowTreeHost* ash_host);
261
262   // Initializes the RootWindowController based on |root_window_type|.
263   void Init(RootWindowType root_window_type);
264
265   void InitLayoutManagers(
266       std::unique_ptr<RootWindowLayoutManager> root_window_layout_manager);
267
268   AccessibilityPanelLayoutManager* GetAccessibilityPanelLayoutManager() const;
269
270   // Creates the containers (aura::Windows) used by the shell.
271   void CreateContainers();
272
273   // Creates a new window for use as a container.
274   aura::Window* CreateContainer(int window_id,
275                                 const char* name,
276                                 aura::Window* parent);
277
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);
282
283   // Callback for MenuRunner.
284   void OnMenuClosed();
285
286   // Passed as callback to |wallpaper_widget_controller_| - run when the
287   // wallpaper widget is first set.
288   void OnFirstWallpaperWidgetSet();
289
290   std::unique_ptr<AshWindowTreeHost> ash_host_;
291   // |ash_host_| as a WindowTreeHost.
292   aura::WindowTreeHost* window_tree_host_;
293
294   // LayoutManagers are owned by the window they are installed on.
295   RootWindowLayoutManager* root_window_layout_manager_ = nullptr;
296
297   std::unique_ptr<WallpaperWidgetController> wallpaper_widget_controller_;
298
299   std::unique_ptr<AlwaysOnTopController> always_on_top_controller_;
300
301   // Manages the context menu.
302   std::unique_ptr<AppMenuModelAdapter> root_window_menu_model_adapter_;
303   std::unique_ptr<ui::SimpleMenuModel> sort_apps_submenu_;
304
305   std::unique_ptr<StackingController> stacking_controller_;
306
307   std::unique_ptr<SplitViewController> split_view_controller_;
308
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_;
313
314   std::unique_ptr<SystemWallpaperController> system_wallpaper_;
315
316   // Responsible for initializing TouchExplorationController when spoken
317   // feedback is on.
318   std::unique_ptr<TouchExplorationManager> touch_exploration_manager_;
319
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;
324
325   std::unique_ptr<::wm::ScopedCaptureClient> capture_client_;
326
327   std::unique_ptr<LockScreenActionBackgroundController>
328       lock_screen_action_background_controller_;
329
330   std::unique_ptr<views::Widget> ambient_widget_;
331
332   std::unique_ptr<curtain::SecurityCurtainWidgetController>
333       security_curtain_widget_controller_;
334
335   std::unique_ptr<AshColorProviderSource> color_provider_source_;
336
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;
340
341   std::unique_ptr<WorkAreaInsets> work_area_insets_;
342
343   static std::vector<RootWindowController*>* root_window_controllers_;
344 };
345
346 }  // namespace ash
347
348 #endif  // ASH_ROOT_WINDOW_CONTROLLER_H_