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.
5 #ifndef ASH_ROOT_WINDOW_CONTROLLER_H_
6 #define ASH_ROOT_WINDOW_CONTROLLER_H_
10 #include "ash/ash_export.h"
11 #include "ash/shelf/shelf_types.h"
12 #include "ash/shell_observer.h"
13 #include "ash/system/user/login_status.h"
14 #include "base/basictypes.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_tree_host.h"
18 #include "ui/base/ui_base_types.h"
32 class KeyboardController
;
44 class InputMethodEventFilter
;
45 class RootWindowEventFilter
;
46 class ScopedCaptureClient
;
50 class AshWindowTreeHost
;
51 class AlwaysOnTopController
;
52 class AnimatingDesktopController
;
53 class DesktopBackgroundWidgetController
;
54 class DockedWindowLayoutManager
;
55 class PanelLayoutManager
;
56 class RootWindowLayoutManager
;
58 class ShelfLayoutManager
;
60 class StackingController
;
61 class StatusAreaWidget
;
62 class SystemBackgroundController
;
63 class SystemModalContainerLayoutManager
;
66 class TouchHudProjection
;
67 class WorkspaceController
;
69 #if defined(OS_CHROMEOS)
70 class BootSplashScreen
;
73 // This class maintains the per root window state for ash. This class
74 // owns the root window and other dependent objects that should be
75 // deleted upon the deletion of the root window. This object is
76 // indirectly owned and deleted by |DisplayController|.
77 // The RootWindowController for particular root window is stored in
78 // its property (RootWindowSettings) and can be obtained using
79 // |GetRootWindowController(aura::WindowEventDispatcher*)| function.
80 class ASH_EXPORT RootWindowController
: public ShellObserver
{
83 // Creates and Initialize the RootWindowController for primary display.
84 static void CreateForPrimaryDisplay(AshWindowTreeHost
* host
);
86 // Creates and Initialize the RootWindowController for secondary displays.
87 static void CreateForSecondaryDisplay(AshWindowTreeHost
* host
);
89 // Creates and Initialize the RootWindowController for virtual
91 static void CreateForVirtualKeyboardDisplay(AshWindowTreeHost
* host
);
93 // Returns a RootWindowController that has a shelf for given
94 // |window|. This returns the RootWindowController for the |window|'s
95 // root window when multiple shelf mode is enabled, or the primary
96 // RootWindowController otherwise.
97 static RootWindowController
* ForShelf(aura::Window
* window
);
99 // Returns a RootWindowController of the window's root window.
100 static RootWindowController
* ForWindow(const aura::Window
* window
);
102 // Returns the RootWindowController of the target root window.
103 static RootWindowController
* ForTargetRootWindow();
105 // Returns container which contains a given |window|.
106 static aura::Window
* GetContainerForWindow(aura::Window
* window
);
108 virtual ~RootWindowController();
110 AshWindowTreeHost
* ash_host() { return ash_host_
.get(); }
111 const AshWindowTreeHost
* ash_host() const { return ash_host_
.get(); }
113 aura::WindowTreeHost
* GetHost();
114 const aura::WindowTreeHost
* GetHost() const;
115 aura::Window
* GetRootWindow();
116 const aura::Window
* GetRootWindow() const;
118 RootWindowLayoutManager
* root_window_layout() { return root_window_layout_
; }
120 WorkspaceController
* workspace_controller() {
121 return workspace_controller_
.get();
124 AlwaysOnTopController
* always_on_top_controller() {
125 return always_on_top_controller_
.get();
128 ScreenDimmer
* screen_dimmer() { return screen_dimmer_
.get(); }
130 // Access the shelf associated with this root window controller,
131 // NULL if no such shelf exists.
132 ShelfWidget
* shelf() { return shelf_
.get(); }
134 // Get touch HUDs associated with this root window controller.
135 TouchHudDebug
* touch_hud_debug() const {
136 return touch_hud_debug_
;
138 TouchHudProjection
* touch_hud_projection() const {
139 return touch_hud_projection_
;
142 // Set touch HUDs for this root window controller. The root window controller
143 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
144 // the widget showing a HUD is being destroyed (e.g. because of detaching a
145 // display), the HUD deletes itself.
146 void set_touch_hud_debug(TouchHudDebug
* hud
) {
147 touch_hud_debug_
= hud
;
149 void set_touch_hud_projection(TouchHudProjection
* hud
) {
150 touch_hud_projection_
= hud
;
153 DesktopBackgroundWidgetController
* wallpaper_controller() {
154 return wallpaper_controller_
.get();
156 void SetWallpaperController(DesktopBackgroundWidgetController
* controller
);
157 AnimatingDesktopController
* animating_wallpaper_controller() {
158 return animating_wallpaper_controller_
.get();
160 void SetAnimatingWallpaperController(AnimatingDesktopController
* controller
);
162 // Access the shelf layout manager associated with this root
163 // window controller, NULL if no such shelf exists.
164 ShelfLayoutManager
* GetShelfLayoutManager();
166 // Returns the system tray on this root window. Note that
167 // calling this on the root window that doesn't have a shelf will
169 SystemTray
* GetSystemTray();
171 // Shows context menu at the |location_in_screen|. This uses
172 // |ShellDelegate::CreateContextMenu| to define the content of the menu.
173 void ShowContextMenu(const gfx::Point
& location_in_screen
,
174 ui::MenuSourceType source_type
);
176 // Returns the layout-manager for the appropriate modal-container. If the
177 // window is inside the lockscreen modal container, then the layout manager
178 // for that is returned. Otherwise the layout manager for the default modal
179 // container is returned.
180 // If no window is specified (i.e. |window| is NULL), then the lockscreen
181 // modal container is used if the screen is currently locked. Otherwise, the
182 // default modal container is used.
183 SystemModalContainerLayoutManager
* GetSystemModalLayoutManager(
184 aura::Window
* window
);
186 aura::Window
* GetContainer(int container_id
);
187 const aura::Window
* GetContainer(int container_id
) const;
189 // Show shelf view if it was created hidden (before session has started).
192 // Called when the shelf associated with this root window is created.
193 void OnShelfCreated();
195 // Called when the login status changes after login (such as lock/unlock).
196 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
197 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
199 // Called when the brightness/grayscale animation from white to the login
200 // desktop background image has started. Starts |boot_splash_screen_|'s
201 // hiding animation (if the screen is non-NULL).
202 void HandleInitialDesktopBackgroundAnimationStarted();
204 // Called when the wallpaper ainmation is finished. Updates |background_|
205 // to be black and drops |boot_splash_screen_| and moves the wallpaper
206 // controller into the root window controller. |widget| holds the wallpaper
207 // image, or NULL if the background is a solid color.
208 void OnWallpaperAnimationFinished(views::Widget
* widget
);
210 // Deletes associated objects and clears the state, but doesn't delete
211 // the root window yet. This is used to delete a secondary displays'
212 // root window safely when the display disconnect signal is received,
213 // which may come while we're in the nested message loop.
216 // Deletes all child windows and performs necessary cleanup.
217 void CloseChildWindows();
219 // Moves child windows to |dest|.
220 void MoveWindowsTo(aura::Window
* dest
);
222 // Force the shelf to query for it's current visibility state.
223 void UpdateShelfVisibility();
225 // Initialize touch HUDs if necessary.
226 void InitTouchHuds();
228 // Returns the topmost window or one of its transient parents, if any of them
229 // are in fullscreen mode.
230 const aura::Window
* GetWindowForFullscreenMode() const;
232 // Activate virtual keyboard on current root window controller.
233 void ActivateKeyboard(keyboard::KeyboardController
* keyboard_controller
);
235 // Deactivate virtual keyboard on current root window controller.
236 void DeactivateKeyboard(keyboard::KeyboardController
* keyboard_controller
);
238 // Tests if a window is associated with the virtual keyboard.
239 bool IsVirtualKeyboardWindow(aura::Window
* window
);
242 explicit RootWindowController(AshWindowTreeHost
* host
);
243 enum RootWindowType
{
249 // Initializes the RootWindowController. |is_primary| is true if
250 // the controller is for primary display. |first_run_after_boot| is
251 // set to true only for primary root window after boot.
252 void Init(RootWindowType root_window_type
, bool first_run_after_boot
);
254 void InitLayoutManagers();
256 // Initializes |system_background_| and possibly also |boot_splash_screen_|.
257 // |is_first_run_after_boot| determines the background's initial color.
258 void CreateSystemBackground(bool is_first_run_after_boot
);
260 // Creates each of the special window containers that holds windows of various
261 // types in the shell UI.
262 void CreateContainersInRootWindow(aura::Window
* root_window
);
264 // Enables projection touch HUD.
265 void EnableTouchHudProjection();
267 // Disables projection touch HUD.
268 void DisableTouchHudProjection();
270 // Overridden from ShellObserver.
271 virtual void OnLoginStateChanged(user::LoginStatus status
) OVERRIDE
;
272 virtual void OnTouchHudProjectionToggled(bool enabled
) OVERRIDE
;
274 scoped_ptr
<AshWindowTreeHost
> ash_host_
;
275 RootWindowLayoutManager
* root_window_layout_
;
277 scoped_ptr
<StackingController
> stacking_controller_
;
279 // The shelf for managing the shelf and the status widget.
280 scoped_ptr
<ShelfWidget
> shelf_
;
282 // An invisible/empty window used as a event target for
283 // |MouseCursorEventFilter| before a user logs in.
284 // (crbug.com/266987)
285 // Its container is |LockScreenBackgroundContainer| and
286 // this must be deleted before the container is deleted.
287 scoped_ptr
<aura::Window
> mouse_event_target_
;
289 // Manages layout of docked windows. Owned by DockedContainer.
290 DockedWindowLayoutManager
* docked_layout_manager_
;
292 // Manages layout of panels. Owned by PanelContainer.
293 PanelLayoutManager
* panel_layout_manager_
;
295 scoped_ptr
<SystemBackgroundController
> system_background_
;
296 #if defined(OS_CHROMEOS)
297 scoped_ptr
<BootSplashScreen
> boot_splash_screen_
;
300 scoped_ptr
<ScreenDimmer
> screen_dimmer_
;
301 scoped_ptr
<WorkspaceController
> workspace_controller_
;
302 scoped_ptr
<AlwaysOnTopController
> always_on_top_controller_
;
304 // Heads-up displays for touch events. These HUDs are not owned by the root
305 // window controller and manage their own lifetimes.
306 TouchHudDebug
* touch_hud_debug_
;
307 TouchHudProjection
* touch_hud_projection_
;
309 // Handles double clicks on the panel window header.
310 scoped_ptr
<ui::EventHandler
> panel_container_handler_
;
312 scoped_ptr
<DesktopBackgroundWidgetController
> wallpaper_controller_
;
313 scoped_ptr
<AnimatingDesktopController
> animating_wallpaper_controller_
;
314 scoped_ptr
< ::wm::ScopedCaptureClient
> capture_client_
;
316 DISALLOW_COPY_AND_ASSIGN(RootWindowController
);
320 // Gets the RootWindowController for |root_window|.
321 ASH_EXPORT RootWindowController
* GetRootWindowController(
322 const aura::Window
* root_window
);
326 #endif // ASH_ROOT_WINDOW_CONTROLLER_H_