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;
67 #if defined(OS_CHROMEOS)
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. This object is
74 // indirectly owned and deleted by |DisplayController|.
75 // The RootWindowController for particular root window is stored in
76 // its property (RootWindowSettings) and can be obtained using
77 // |GetRootWindowController(aura::RootWindow*)| function.
78 class ASH_EXPORT RootWindowController : public ShellObserver {
81 // Creates and Initialize the RootWindowController for primary display.
82 static void CreateForPrimaryDisplay(aura::RootWindow* root_window);
84 // Creates and Initialize the RootWindowController for secondary displays.
85 static void CreateForSecondaryDisplay(aura::RootWindow* root_window);
87 // Creates and Initialize the RootWindowController for virtual
89 static void CreateForVirtualKeyboardDisplay(aura::RootWindow* root_window);
91 // Returns a RootWindowController that has a launcher for given
92 // |window|. This returns the RootWindowController for the |window|'s
93 // root window when multiple launcher mode is enabled, or the primary
94 // RootWindowController otherwise.
95 static RootWindowController* ForLauncher(aura::Window* window);
97 // Returns a RootWindowController of the window's root window.
98 static RootWindowController* ForWindow(const aura::Window* window);
100 // Returns the RootWindowController of the target root window.
101 static internal::RootWindowController* ForTargetRootWindow();
103 virtual ~RootWindowController();
105 aura::RootWindow* root_window() { return root_window_.get(); }
107 RootWindowLayoutManager* root_window_layout() { return root_window_layout_; }
109 WorkspaceController* workspace_controller() {
110 return workspace_controller_.get();
113 AlwaysOnTopController* always_on_top_controller() {
114 return always_on_top_controller_.get();
117 ScreenDimmer* screen_dimmer() { return screen_dimmer_.get(); }
119 // Access the shelf associated with this root window controller,
120 // NULL if no such shelf exists.
121 ShelfWidget* shelf() { return shelf_.get(); }
123 // Get touch HUDs associated with this root window controller.
124 TouchHudDebug* touch_hud_debug() const {
125 return touch_hud_debug_;
127 TouchHudProjection* touch_hud_projection() const {
128 return touch_hud_projection_;
131 // Set touch HUDs for this root window controller. The root window controller
132 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
133 // the widget showing a HUD is being destroyed (e.g. because of detaching a
134 // display), the HUD deletes itself.
135 void set_touch_hud_debug(TouchHudDebug* hud) {
136 touch_hud_debug_ = hud;
138 void set_touch_hud_projection(TouchHudProjection* hud) {
139 touch_hud_projection_ = hud;
142 DesktopBackgroundWidgetController* wallpaper_controller() {
143 return wallpaper_controller_.get();
145 void SetWallpaperController(DesktopBackgroundWidgetController* controller);
146 AnimatingDesktopController* animating_wallpaper_controller() {
147 return animating_wallpaper_controller_.get();
149 void SetAnimatingWallpaperController(AnimatingDesktopController* controller);
151 // Access the shelf layout manager associated with this root
152 // window controller, NULL if no such shelf exists.
153 ShelfLayoutManager* GetShelfLayoutManager();
155 // Returns the system tray on this root window. Note that
156 // calling this on the root window that doesn't have a launcher will
158 SystemTray* GetSystemTray();
160 // Shows context menu at the |location_in_screen|. This uses
161 // |ShellDelegate::CreateContextMenu| to define the content of the menu.
162 void ShowContextMenu(const gfx::Point& location_in_screen,
163 ui::MenuSourceType source_type);
165 // Returns the layout-manager for the appropriate modal-container. If the
166 // window is inside the lockscreen modal container, then the layout manager
167 // for that is returned. Otherwise the layout manager for the default modal
168 // container is returned.
169 // If no window is specified (i.e. |window| is NULL), then the lockscreen
170 // modal container is used if the screen is currently locked. Otherwise, the
171 // default modal container is used.
172 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
173 aura::Window* window);
175 aura::Window* GetContainer(int container_id);
176 const aura::Window* GetContainer(int container_id) const;
178 // Show launcher view if it was created hidden (before session has started).
181 // Called when the launcher associated with this root window is created.
182 void OnLauncherCreated();
184 // Called when the login status changes after login (such as lock/unlock).
185 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
186 void UpdateAfterLoginStatusChange(user::LoginStatus status);
188 // Called when the brightness/grayscale animation from white to the login
189 // desktop background image has started. Starts |boot_splash_screen_|'s
190 // hiding animation (if the screen is non-NULL).
191 void HandleInitialDesktopBackgroundAnimationStarted();
193 // Called when the wallpaper ainmation is finished. Updates |background_|
194 // to be black and drops |boot_splash_screen_| and moves the wallpaper
195 // controller into the root window controller. |widget| holds the wallpaper
196 // image, or NULL if the background is a solid color.
197 void OnWallpaperAnimationFinished(views::Widget* widget);
199 // Deletes associated objects and clears the state, but doesn't delete
200 // the root window yet. This is used to delete a secondary displays'
201 // root window safely when the display disconnect signal is received,
202 // which may come while we're in the nested message loop.
205 // Deletes all child windows and performs necessary cleanup.
206 void CloseChildWindows();
208 // Moves child windows to |dest|.
209 void MoveWindowsTo(aura::Window* dest);
211 // Force the shelf to query for it's current visibility state.
212 void UpdateShelfVisibility();
214 // Initialize touch HUDs if necessary.
215 void InitTouchHuds();
217 // Returns the window, if any, which is in fullscreen mode. If multiple
218 // windows are in fullscreen state, the topmost one is preferred.
219 const aura::Window* GetTopmostFullscreenWindow() const;
221 // Activate virtual keyboard on current root window controller.
222 void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
224 // Deactivate virtual keyboard on current root window controller.
225 void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
228 explicit RootWindowController(aura::RootWindow* root_window);
229 enum RootWindowType {
235 // Initializes the RootWindowController. |is_primary| is true if
236 // the controller is for primary display. |first_run_after_boot| is
237 // set to true only for primary root window after boot.
238 void Init(RootWindowType root_window_type, bool first_run_after_boot);
240 void InitLayoutManagers();
242 // Initializes |system_background_| and possibly also |boot_splash_screen_|.
243 // |is_first_run_after_boot| determines the background's initial color.
244 void CreateSystemBackground(bool is_first_run_after_boot);
246 // Creates each of the special window containers that holds windows of various
247 // types in the shell UI.
248 void CreateContainersInRootWindow(aura::RootWindow* root_window);
250 // Enables projection touch HUD.
251 void EnableTouchHudProjection();
253 // Disables projection touch HUD.
254 void DisableTouchHudProjection();
256 // Overridden from ShellObserver.
257 virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE;
258 virtual void OnTouchHudProjectionToggled(bool enabled) OVERRIDE;
260 scoped_ptr<aura::RootWindow> root_window_;
261 RootWindowLayoutManager* root_window_layout_;
263 scoped_ptr<StackingController> stacking_controller_;
265 // The shelf for managing the launcher and the status widget.
266 scoped_ptr<ShelfWidget> shelf_;
268 // An invisible/empty window used as a event target for
269 // |MouseCursorEventFilter| before a user logs in.
270 // (crbug.com/266987)
271 // Its container is |LockScreenBackgroundContainer| and
272 // this must be deleted before the container is deleted.
273 scoped_ptr<aura::Window> mouse_event_target_;
275 // Manages layout of docked windows. Owned by DockedContainer.
276 DockedWindowLayoutManager* docked_layout_manager_;
278 // Manages layout of panels. Owned by PanelContainer.
279 PanelLayoutManager* panel_layout_manager_;
281 scoped_ptr<SystemBackgroundController> system_background_;
282 #if defined(OS_CHROMEOS)
283 scoped_ptr<BootSplashScreen> boot_splash_screen_;
286 scoped_ptr<ScreenDimmer> screen_dimmer_;
287 scoped_ptr<WorkspaceController> workspace_controller_;
288 scoped_ptr<AlwaysOnTopController> always_on_top_controller_;
290 // Heads-up displays for touch events. These HUDs are not owned by the root
291 // window controller and manage their own lifetimes.
292 TouchHudDebug* touch_hud_debug_;
293 TouchHudProjection* touch_hud_projection_;
295 // We need to own event handlers for various containers.
296 scoped_ptr<ToplevelWindowEventHandler> default_container_handler_;
297 scoped_ptr<ToplevelWindowEventHandler> always_on_top_container_handler_;
298 scoped_ptr<ToplevelWindowEventHandler> modal_container_handler_;
299 scoped_ptr<ToplevelWindowEventHandler> lock_modal_container_handler_;
300 scoped_ptr<ToplevelWindowEventHandler> panel_container_handler_;
301 scoped_ptr<ToplevelWindowEventHandler> docked_container_handler_;
303 scoped_ptr<DesktopBackgroundWidgetController> wallpaper_controller_;
304 scoped_ptr<AnimatingDesktopController> animating_wallpaper_controller_;
305 scoped_ptr<views::corewm::ScopedCaptureClient> capture_client_;
307 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
311 // Gets the RootWindowController for |root_window|.
312 ASH_EXPORT RootWindowController* GetRootWindowController(
313 const aura::Window* root_window);
315 } // namespace internal
318 #endif // ASH_ROOT_WINDOW_CONTROLLER_H_