Add MetricsService::WasLastShutdownClean()
[chromium-blink-merge.git] / ash / root_window_controller.h
blob44d1b40db1672e2ee8fb03e60084f7881cc3c8c2
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_
8 #include <map>
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"
20 class SkBitmap;
22 namespace aura {
23 class EventFilter;
24 class Window;
27 namespace gfx {
28 class Point;
31 namespace keyboard {
32 class KeyboardController;
35 namespace ui {
36 class EventHandler;
39 namespace views {
40 class Widget;
43 namespace wm {
44 class InputMethodEventFilter;
45 class RootWindowEventFilter;
46 class ScopedCaptureClient;
49 namespace ash {
50 class AshWindowTreeHost;
51 class AlwaysOnTopController;
52 class AnimatingDesktopController;
53 class DesktopBackgroundWidgetController;
54 class DockedWindowLayoutManager;
55 class PanelLayoutManager;
56 class RootWindowLayoutManager;
57 class ScreenDimmer;
58 class ShelfLayoutManager;
59 class ShelfWidget;
60 class StackingController;
61 class StatusAreaWidget;
62 class SystemBackgroundController;
63 class SystemModalContainerLayoutManager;
64 class SystemTray;
65 class TouchHudDebug;
66 class TouchHudProjection;
67 class WorkspaceController;
69 #if defined(OS_CHROMEOS)
70 class BootSplashScreen;
71 class AshTouchExplorationManager;
72 #endif
74 // This class maintains the per root window state for ash. This class
75 // owns the root window and other dependent objects that should be
76 // deleted upon the deletion of the root window. This object is
77 // indirectly owned and deleted by |DisplayController|.
78 // The RootWindowController for particular root window is stored in
79 // its property (RootWindowSettings) and can be obtained using
80 // |GetRootWindowController(aura::WindowEventDispatcher*)| function.
81 class ASH_EXPORT RootWindowController : public ShellObserver {
82 public:
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 // Returns a RootWindowController that has a shelf for given
90 // |window|. This returns the RootWindowController for the |window|'s
91 // root window when multiple shelf mode is enabled, or the primary
92 // RootWindowController otherwise.
93 static RootWindowController* ForShelf(const aura::Window* window);
95 // Returns a RootWindowController of the window's root window.
96 static RootWindowController* ForWindow(const aura::Window* window);
98 // Returns the RootWindowController of the target root window.
99 static RootWindowController* ForTargetRootWindow();
101 // Returns container which contains a given |window|.
102 static aura::Window* GetContainerForWindow(aura::Window* window);
104 ~RootWindowController() override;
106 AshWindowTreeHost* ash_host() { return ash_host_.get(); }
107 const AshWindowTreeHost* ash_host() const { return ash_host_.get(); }
109 aura::WindowTreeHost* GetHost();
110 const aura::WindowTreeHost* GetHost() const;
111 aura::Window* GetRootWindow();
112 const aura::Window* GetRootWindow() const;
114 RootWindowLayoutManager* root_window_layout() { return root_window_layout_; }
116 WorkspaceController* workspace_controller() {
117 return workspace_controller_.get();
120 AlwaysOnTopController* always_on_top_controller() {
121 return always_on_top_controller_.get();
124 ScreenDimmer* screen_dimmer() { return screen_dimmer_.get(); }
126 // Access the shelf associated with this root window controller,
127 // NULL if no such shelf exists.
128 ShelfWidget* shelf() { return shelf_.get(); }
130 // Get touch HUDs associated with this root window controller.
131 TouchHudDebug* touch_hud_debug() const {
132 return touch_hud_debug_;
134 TouchHudProjection* touch_hud_projection() const {
135 return touch_hud_projection_;
138 // Set touch HUDs for this root window controller. The root window controller
139 // will not own the HUDs; their lifetimes are managed by themselves. Whenever
140 // the widget showing a HUD is being destroyed (e.g. because of detaching a
141 // display), the HUD deletes itself.
142 void set_touch_hud_debug(TouchHudDebug* hud) {
143 touch_hud_debug_ = hud;
145 void set_touch_hud_projection(TouchHudProjection* hud) {
146 touch_hud_projection_ = hud;
149 DesktopBackgroundWidgetController* wallpaper_controller() {
150 return wallpaper_controller_.get();
152 void SetWallpaperController(DesktopBackgroundWidgetController* controller);
153 AnimatingDesktopController* animating_wallpaper_controller() {
154 return animating_wallpaper_controller_.get();
156 void SetAnimatingWallpaperController(AnimatingDesktopController* controller);
158 // Access the shelf layout manager associated with this root
159 // window controller, NULL if no such shelf exists.
160 ShelfLayoutManager* GetShelfLayoutManager();
162 // Returns the system tray on this root window. Note that
163 // calling this on the root window that doesn't have a shelf will
164 // lead to a crash.
165 SystemTray* GetSystemTray();
167 // Shows context menu at the |location_in_screen|. This uses
168 // |ShellDelegate::CreateContextMenu| to define the content of the menu.
169 void ShowContextMenu(const gfx::Point& location_in_screen,
170 ui::MenuSourceType source_type);
172 // Returns the layout-manager for the appropriate modal-container. If the
173 // window is inside the lockscreen modal container, then the layout manager
174 // for that is returned. Otherwise the layout manager for the default modal
175 // container is returned.
176 // If no window is specified (i.e. |window| is NULL), then the lockscreen
177 // modal container is used if the screen is currently locked. Otherwise, the
178 // default modal container is used.
179 SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
180 aura::Window* window);
182 aura::Window* GetContainer(int container_id);
183 const aura::Window* GetContainer(int container_id) const;
185 // Show shelf view if it was created hidden (before session has started).
186 void ShowShelf();
188 // Called when the shelf associated with this root window is created.
189 void OnShelfCreated();
191 // Called when the login status changes after login (such as lock/unlock).
192 // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
193 void UpdateAfterLoginStatusChange(user::LoginStatus status);
195 // Called when the brightness/grayscale animation from white to the login
196 // desktop background image has started. Starts |boot_splash_screen_|'s
197 // hiding animation (if the screen is non-NULL).
198 void HandleInitialDesktopBackgroundAnimationStarted();
200 // Called when the wallpaper ainmation is finished. Updates |background_|
201 // to be black and drops |boot_splash_screen_| and moves the wallpaper
202 // controller into the root window controller. |widget| holds the wallpaper
203 // image, or NULL if the background is a solid color.
204 void OnWallpaperAnimationFinished(views::Widget* widget);
206 // Deletes associated objects and clears the state, but doesn't delete
207 // the root window yet. This is used to delete a secondary displays'
208 // root window safely when the display disconnect signal is received,
209 // which may come while we're in the nested message loop.
210 void Shutdown();
212 // Deletes all child windows and performs necessary cleanup.
213 void CloseChildWindows();
215 // Moves child windows to |dest|.
216 void MoveWindowsTo(aura::Window* dest);
218 // Force the shelf to query for it's current visibility state.
219 void UpdateShelfVisibility();
221 // Initialize touch HUDs if necessary.
222 void InitTouchHuds();
224 // Returns the topmost window or one of its transient parents, if any of them
225 // are in fullscreen mode.
226 aura::Window* GetWindowForFullscreenMode();
228 // Activate virtual keyboard on current root window controller.
229 void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
231 // Deactivate virtual keyboard on current root window controller.
232 void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
234 // Tests if a window is associated with the virtual keyboard.
235 bool IsVirtualKeyboardWindow(aura::Window* window);
237 private:
238 explicit RootWindowController(AshWindowTreeHost* host);
239 enum RootWindowType {
240 PRIMARY,
241 SECONDARY
244 // Initializes the RootWindowController. |is_primary| is true if
245 // the controller is for primary display. |first_run_after_boot| is
246 // set to true only for primary root window after boot.
247 void Init(RootWindowType root_window_type, bool first_run_after_boot);
249 void InitLayoutManagers();
251 // Initializes |system_background_| and possibly also |boot_splash_screen_|.
252 // |is_first_run_after_boot| determines the background's initial color.
253 void CreateSystemBackground(bool is_first_run_after_boot);
255 // Creates each of the special window containers that holds windows of various
256 // types in the shell UI.
257 void CreateContainersInRootWindow(aura::Window* root_window);
259 // Enables projection touch HUD.
260 void EnableTouchHudProjection();
262 // Disables projection touch HUD.
263 void DisableTouchHudProjection();
265 // Overridden from ShellObserver.
266 void OnLoginStateChanged(user::LoginStatus status) override;
267 void OnTouchHudProjectionToggled(bool enabled) override;
269 scoped_ptr<AshWindowTreeHost> ash_host_;
270 RootWindowLayoutManager* root_window_layout_;
272 scoped_ptr<StackingController> stacking_controller_;
274 // The shelf for managing the shelf and the status widget.
275 scoped_ptr<ShelfWidget> shelf_;
277 // An invisible/empty window used as a event target for
278 // |MouseCursorEventFilter| before a user logs in.
279 // (crbug.com/266987)
280 // Its container is |LockScreenBackgroundContainer| and
281 // this must be deleted before the container is deleted.
282 scoped_ptr<aura::Window> mouse_event_target_;
284 // Manages layout of docked windows. Owned by DockedContainer.
285 DockedWindowLayoutManager* docked_layout_manager_;
287 // Manages layout of panels. Owned by PanelContainer.
288 PanelLayoutManager* panel_layout_manager_;
290 scoped_ptr<SystemBackgroundController> system_background_;
292 #if defined(OS_CHROMEOS)
293 scoped_ptr<BootSplashScreen> boot_splash_screen_;
294 // Responsible for initializing TouchExplorationController when spoken
295 // feedback is on.
296 scoped_ptr<AshTouchExplorationManager> touch_exploration_manager_;
297 #endif
299 scoped_ptr<ScreenDimmer> screen_dimmer_;
300 scoped_ptr<WorkspaceController> workspace_controller_;
301 scoped_ptr<AlwaysOnTopController> always_on_top_controller_;
303 // Heads-up displays for touch events. These HUDs are not owned by the root
304 // window controller and manage their own lifetimes.
305 TouchHudDebug* touch_hud_debug_;
306 TouchHudProjection* touch_hud_projection_;
308 // Handles double clicks on the panel window header.
309 scoped_ptr<ui::EventHandler> panel_container_handler_;
311 scoped_ptr<DesktopBackgroundWidgetController> wallpaper_controller_;
312 scoped_ptr<AnimatingDesktopController> animating_wallpaper_controller_;
313 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_;
315 DISALLOW_COPY_AND_ASSIGN(RootWindowController);
319 // Gets the RootWindowController for |root_window|.
320 ASH_EXPORT RootWindowController* GetRootWindowController(
321 const aura::Window* root_window);
323 } // namespace ash
325 #endif // ASH_ROOT_WINDOW_CONTROLLER_H_