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/base/ui_base_types.h"
34 class InputMethodEventFilter
;
35 class RootWindowEventFilter
;
36 class ScopedCaptureClient
;
41 class KeyboardController
;
45 class StackingController
;
48 class ToplevelWindowEventHandler
;
52 class AlwaysOnTopController
;
53 class AnimatingDesktopController
;
54 class DesktopBackgroundWidgetController
;
55 class DockedWindowLayoutManager
;
56 class PanelLayoutManager
;
57 class RootWindowLayoutManager
;
59 class ShelfLayoutManager
;
60 class StatusAreaWidget
;
61 class SystemBackgroundController
;
62 class SystemModalContainerLayoutManager
;
64 class TouchHudProjection
;
65 class WorkspaceController
;
68 class BootSplashScreen
;
71 // This class maintains the per root window state for ash. This class
72 // owns the root window and other dependent objects that should be
73 // deleted upon the deletion of the root window. The RootWindowController
74 // for particular root window is stored as a property and can be obtained
75 // using |GetRootWindowController(aura::RootWindow*)| function.
76 class ASH_EXPORT RootWindowController
: public ShellObserver
{
78 explicit RootWindowController(aura::RootWindow
* root_window
);
79 virtual ~RootWindowController();
81 // Returns a RootWindowController that has a launcher for given
82 // |window|. This returns the RootWindowController for the |window|'s
83 // root window when multiple launcher mode is enabled, or the primary
84 // RootWindowController otherwise.
85 static RootWindowController
* ForLauncher(aura::Window
* window
);
87 // Returns a RootWindowController of the window's root window.
88 static RootWindowController
* ForWindow(const aura::Window
* window
);
90 // Returns the RootWindowController of the target root window.
91 static internal::RootWindowController
* ForTargetRootWindow();
93 aura::RootWindow
* root_window() { return root_window_
.get(); }
95 RootWindowLayoutManager
* root_window_layout() { return root_window_layout_
; }
97 WorkspaceController
* workspace_controller() {
98 return workspace_controller_
.get();
101 AlwaysOnTopController
* always_on_top_controller() {
102 return always_on_top_controller_
.get();
105 keyboard::KeyboardController
* keyboard_controller() {
106 return keyboard_controller_
.get();
109 ScreenDimmer
* screen_dimmer() { return screen_dimmer_
.get(); }
111 // Access the shelf associated with this root window controller,
112 // NULL if no such shelf exists.
113 ShelfWidget
* shelf() { return shelf_
.get(); }
115 // Get touch HUDs associated with this root window controller.
116 TouchHudDebug
* touch_hud_debug() const {
117 return touch_hud_debug_
;
119 TouchHudProjection
* touch_hud_projection() const {
120 return touch_hud_projection_
;
123 // Set touch HUDs for this root window controller. The root window controller
124 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
125 // the widget showing a HUD is being destroyed (e.g. because of detaching a
126 // display), the HUD deletes itself.
127 void set_touch_hud_debug(TouchHudDebug
* hud
) {
128 touch_hud_debug_
= hud
;
130 void set_touch_hud_projection(TouchHudProjection
* hud
) {
131 touch_hud_projection_
= hud
;
134 DesktopBackgroundWidgetController
* wallpaper_controller() {
135 return wallpaper_controller_
.get();
137 void SetWallpaperController(DesktopBackgroundWidgetController
* controller
);
138 AnimatingDesktopController
* animating_wallpaper_controller() {
139 return animating_wallpaper_controller_
.get();
141 void SetAnimatingWallpaperController(AnimatingDesktopController
* controller
);
143 // Access the shelf layout manager associated with this root
144 // window controller, NULL if no such shelf exists.
145 ShelfLayoutManager
* GetShelfLayoutManager();
147 // Returns the system tray on this root window. Note that
148 // calling this on the root window that doesn't have a launcher will
150 SystemTray
* GetSystemTray();
152 // Shows context menu at the |location_in_screen|. This uses
153 // |ShellDelegate::CreateContextMenu| to define the content of the menu.
154 void ShowContextMenu(const gfx::Point
& location_in_screen
,
155 ui::MenuSourceType source_type
);
157 // Returns the layout-manager for the appropriate modal-container. If the
158 // window is inside the lockscreen modal container, then the layout manager
159 // for that is returned. Otherwise the layout manager for the default modal
160 // container is returned.
161 // If no window is specified (i.e. |window| is NULL), then the lockscreen
162 // modal container is used if the screen is currently locked. Otherwise, the
163 // default modal container is used.
164 SystemModalContainerLayoutManager
* GetSystemModalLayoutManager(
165 aura::Window
* window
);
167 aura::Window
* GetContainer(int container_id
);
168 const aura::Window
* GetContainer(int container_id
) const;
170 // Initializes the RootWindowController. |first_run_after_boot| is
171 // set to true only for primary root window after boot.
172 void Init(bool first_run_after_boot
);
174 // Show launcher view if it was created hidden (before session has started).
177 // Called when the launcher associated with this root window is created.
178 void OnLauncherCreated();
180 // Called when the login status changes after login (such as lock/unlock).
181 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
182 void UpdateAfterLoginStatusChange(user::LoginStatus status
);
184 // Called when the brightness/grayscale animation from white to the login
185 // desktop background image has started. Starts |boot_splash_screen_|'s
186 // hiding animation (if the screen is non-NULL).
187 void HandleInitialDesktopBackgroundAnimationStarted();
189 // Called when the wallpaper ainmation is finished. Updates |background_|
190 // to be black and drops |boot_splash_screen_| and moves the wallpaper
191 // controller into the root window controller. |widget| holds the wallpaper
192 // image, or NULL if the background is a solid color.
193 void OnWallpaperAnimationFinished(views::Widget
* widget
);
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 message loop.
201 // Deletes all child windows and performs necessary cleanup.
202 void CloseChildWindows();
204 // Moves child windows to |dest|.
205 void MoveWindowsTo(aura::RootWindow
* dest
);
207 // Force the shelf to query for it's current visibility state.
208 void UpdateShelfVisibility();
210 // Initialize touch HUDs if necessary.
211 void InitTouchHuds();
213 // Returns the window, if any, which is in fullscreen mode. If multiple
214 // windows are in fullscreen state, the topmost one is preferred.
215 const aura::Window
* GetTopmostFullscreenWindow() const;
218 void InitLayoutManagers();
220 // Initializes |system_background_| and possibly also |boot_splash_screen_|.
221 // |is_first_run_after_boot| determines the background's initial color.
222 void CreateSystemBackground(bool is_first_run_after_boot
);
224 // Creates each of the special window containers that holds windows of various
225 // types in the shell UI.
226 void CreateContainersInRootWindow(aura::RootWindow
* root_window
);
228 // Initializes the virtual keyboard.
231 // Enables projection touch HUD.
232 void EnableTouchHudProjection();
234 // Disables projection touch HUD.
235 void DisableTouchHudProjection();
237 // Overridden from ShellObserver.
238 virtual void OnLoginStateChanged(user::LoginStatus status
) OVERRIDE
;
239 virtual void OnTouchHudProjectionToggled(bool enabled
) OVERRIDE
;
241 scoped_ptr
<aura::RootWindow
> root_window_
;
242 RootWindowLayoutManager
* root_window_layout_
;
244 scoped_ptr
<StackingController
> stacking_controller_
;
246 scoped_ptr
<keyboard::KeyboardController
> keyboard_controller_
;
248 // The shelf for managing the launcher and the status widget.
249 scoped_ptr
<ShelfWidget
> shelf_
;
251 // An invisible/empty window used as a event target for
252 // |MouseCursorEventFilter| before a user logs in.
253 // (crbug.com/266987)
254 // Its container is |LockScreenBackgroundContainer| and
255 // this must be deleted before the container is deleted.
256 scoped_ptr
<aura::Window
> mouse_event_target_
;
258 // Manages layout of docked windows. Owned by DockedContainer.
259 DockedWindowLayoutManager
* docked_layout_manager_
;
261 // Manages layout of panels. Owned by PanelContainer.
262 PanelLayoutManager
* panel_layout_manager_
;
264 scoped_ptr
<SystemBackgroundController
> system_background_
;
266 scoped_ptr
<BootSplashScreen
> boot_splash_screen_
;
269 scoped_ptr
<ScreenDimmer
> screen_dimmer_
;
270 scoped_ptr
<WorkspaceController
> workspace_controller_
;
271 scoped_ptr
<AlwaysOnTopController
> always_on_top_controller_
;
273 // Heads-up displays for touch events. These HUDs are not owned by the root
274 // window controller and manage their own lifetimes.
275 TouchHudDebug
* touch_hud_debug_
;
276 TouchHudProjection
* touch_hud_projection_
;
278 // We need to own event handlers for various containers.
279 scoped_ptr
<ToplevelWindowEventHandler
> default_container_handler_
;
280 scoped_ptr
<ToplevelWindowEventHandler
> always_on_top_container_handler_
;
281 scoped_ptr
<ToplevelWindowEventHandler
> modal_container_handler_
;
282 scoped_ptr
<ToplevelWindowEventHandler
> lock_modal_container_handler_
;
283 scoped_ptr
<ToplevelWindowEventHandler
> panel_container_handler_
;
284 scoped_ptr
<ToplevelWindowEventHandler
> docked_container_handler_
;
286 scoped_ptr
<DesktopBackgroundWidgetController
> wallpaper_controller_
;
287 scoped_ptr
<AnimatingDesktopController
> animating_wallpaper_controller_
;
288 scoped_ptr
<views::corewm::ScopedCaptureClient
> capture_client_
;
290 DISALLOW_COPY_AND_ASSIGN(RootWindowController
);
294 // Gets the RootWindowController for |root_window|.
295 ASH_EXPORT RootWindowController
* GetRootWindowController(
296 const aura::RootWindow
* root_window
);
298 } // namespace internal
301 #endif // ASH_ROOT_WINDOW_CONTROLLER_H_