• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef ASH_ROOT_WINDOW_CONTROLLER_H_
6 #define ASH_ROOT_WINDOW_CONTROLLER_H_
7 
8 #include <map>
9 
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/root_window.h"
17 #include "ui/aura/window.h"
18 #include "ui/base/ui_base_types.h"
19 
20 class SkBitmap;
21 
22 namespace aura {
23 class EventFilter;
24 class Window;
25 }
26 
27 namespace gfx {
28 class Point;
29 }
30 
31 namespace views {
32 class Widget;
33 
34 namespace corewm {
35 class InputMethodEventFilter;
36 class RootWindowEventFilter;
37 class ScopedCaptureClient;
38 }
39 }
40 
41 namespace keyboard {
42 class KeyboardController;
43 }
44 
45 namespace ash {
46 class ShelfWidget;
47 class SoloWindowTracker;
48 class StackingController;
49 class SystemTray;
50 class ToplevelWindowEventHandler;
51 
52 namespace internal {
53 
54 class AlwaysOnTopController;
55 class AnimatingDesktopController;
56 class DesktopBackgroundWidgetController;
57 class DockedWindowLayoutManager;
58 class PanelLayoutManager;
59 class RootWindowLayoutManager;
60 class ScreenDimmer;
61 class ShelfLayoutManager;
62 class StatusAreaWidget;
63 class SystemBackgroundController;
64 class SystemModalContainerLayoutManager;
65 class TouchHudDebug;
66 class TouchHudProjection;
67 class WorkspaceController;
68 
69 #if defined(OS_CHROMEOS)
70 class BootSplashScreen;
71 #endif
72 
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::RootWindow*)| function.
80 class ASH_EXPORT RootWindowController : public ShellObserver {
81  public:
82 
83   // Creates and Initialize the RootWindowController for primary display.
84   static void CreateForPrimaryDisplay(aura::RootWindow* root_window);
85 
86   // Creates and Initialize the RootWindowController for secondary displays.
87   static void CreateForSecondaryDisplay(aura::RootWindow* root_window);
88 
89   // Creates and Initialize the RootWindowController for virtual
90   // keyboard displays.
91   static void CreateForVirtualKeyboardDisplay(aura::RootWindow* root_window);
92 
93   // Returns a RootWindowController that has a launcher for given
94   // |window|. This returns the RootWindowController for the |window|'s
95   // root window when multiple launcher mode is enabled, or the primary
96   // RootWindowController otherwise.
97   static RootWindowController* ForLauncher(aura::Window* window);
98 
99   // Returns a RootWindowController of the window's root window.
100   static RootWindowController* ForWindow(const aura::Window* window);
101 
102   // Returns the RootWindowController of the target root window.
103   static internal::RootWindowController* ForTargetRootWindow();
104 
105   // Returns container which contains a given |window|.
106   static aura::Window* GetContainerForWindow(aura::Window* window);
107 
108   virtual ~RootWindowController();
109 
root_window()110   aura::Window* root_window() { return dispatcher()->window(); }
dispatcher()111   aura::WindowEventDispatcher* dispatcher() { return root_window_.get(); }
112 
root_window_layout()113   RootWindowLayoutManager* root_window_layout() { return root_window_layout_; }
114 
workspace_controller()115   WorkspaceController* workspace_controller() {
116     return workspace_controller_.get();
117   }
118 
always_on_top_controller()119   AlwaysOnTopController* always_on_top_controller() {
120     return always_on_top_controller_.get();
121   }
122 
screen_dimmer()123   ScreenDimmer* screen_dimmer() { return screen_dimmer_.get(); }
124 
125   // Access the shelf associated with this root window controller,
126   // NULL if no such shelf exists.
shelf()127   ShelfWidget* shelf() { return shelf_.get(); }
128 
129   // Get touch HUDs associated with this root window controller.
touch_hud_debug()130   TouchHudDebug* touch_hud_debug() const {
131     return touch_hud_debug_;
132   }
touch_hud_projection()133   TouchHudProjection* touch_hud_projection() const {
134     return touch_hud_projection_;
135   }
136 
137   // Set touch HUDs for this root window controller. The root window controller
138   // will not own the HUDs; their lifetimes are managed by themselves. Whenever
139   // the widget showing a HUD is being destroyed (e.g. because of detaching a
140   // display), the HUD deletes itself.
set_touch_hud_debug(TouchHudDebug * hud)141   void set_touch_hud_debug(TouchHudDebug* hud) {
142     touch_hud_debug_ = hud;
143   }
set_touch_hud_projection(TouchHudProjection * hud)144   void set_touch_hud_projection(TouchHudProjection* hud) {
145     touch_hud_projection_ = hud;
146   }
147 
wallpaper_controller()148   DesktopBackgroundWidgetController* wallpaper_controller() {
149     return wallpaper_controller_.get();
150   }
151   void SetWallpaperController(DesktopBackgroundWidgetController* controller);
animating_wallpaper_controller()152   AnimatingDesktopController* animating_wallpaper_controller() {
153     return animating_wallpaper_controller_.get();
154   }
155   void SetAnimatingWallpaperController(AnimatingDesktopController* controller);
156 
solo_window_tracker()157   SoloWindowTracker* solo_window_tracker() {
158     return solo_window_tracker_.get();
159   }
160 
161   // Access the shelf layout manager associated with this root
162   // window controller, NULL if no such shelf exists.
163   ShelfLayoutManager* GetShelfLayoutManager();
164 
165   // Returns the system tray on this root window. Note that
166   // calling this on the root window that doesn't have a launcher will
167   // lead to a crash.
168   SystemTray* GetSystemTray();
169 
170   // Shows context menu at the |location_in_screen|. This uses
171   // |ShellDelegate::CreateContextMenu| to define the content of the menu.
172   void ShowContextMenu(const gfx::Point& location_in_screen,
173                        ui::MenuSourceType source_type);
174 
175   // Returns the layout-manager for the appropriate modal-container. If the
176   // window is inside the lockscreen modal container, then the layout manager
177   // for that is returned. Otherwise the layout manager for the default modal
178   // container is returned.
179   // If no window is specified (i.e. |window| is NULL), then the lockscreen
180   // modal container is used if the screen is currently locked. Otherwise, the
181   // default modal container is used.
182   SystemModalContainerLayoutManager* GetSystemModalLayoutManager(
183       aura::Window* window);
184 
185   aura::Window* GetContainer(int container_id);
186   const aura::Window* GetContainer(int container_id) const;
187 
188   // Show launcher view if it was created hidden (before session has started).
189   void ShowLauncher();
190 
191   // Called when the launcher associated with this root window is created.
192   void OnLauncherCreated();
193 
194   // Called when the login status changes after login (such as lock/unlock).
195   // TODO(oshima): Investigate if we can merge this and |OnLoginStateChanged|.
196   void UpdateAfterLoginStatusChange(user::LoginStatus status);
197 
198   // Called when the brightness/grayscale animation from white to the login
199   // desktop background image has started.  Starts |boot_splash_screen_|'s
200   // hiding animation (if the screen is non-NULL).
201   void HandleInitialDesktopBackgroundAnimationStarted();
202 
203   // Called when the wallpaper ainmation is finished. Updates |background_|
204   // to be black and drops |boot_splash_screen_| and moves the wallpaper
205   // controller into the root window controller. |widget| holds the wallpaper
206   // image, or NULL if the background is a solid color.
207   void OnWallpaperAnimationFinished(views::Widget* widget);
208 
209   // Deletes associated objects and clears the state, but doesn't delete
210   // the root window yet. This is used to delete a secondary displays'
211   // root window safely when the display disconnect signal is received,
212   // which may come while we're in the nested message loop.
213   void Shutdown();
214 
215   // Deletes all child windows and performs necessary cleanup.
216   void CloseChildWindows();
217 
218   // Moves child windows to |dest|.
219   void MoveWindowsTo(aura::Window* dest);
220 
221   // Force the shelf to query for it's current visibility state.
222   void UpdateShelfVisibility();
223 
224   // Initialize touch HUDs if necessary.
225   void InitTouchHuds();
226 
227   // Returns the topmost window or one of its transient parents, if any of them
228   // are in fullscreen mode.
229   const aura::Window* GetWindowForFullscreenMode() const;
230 
231   // Activate virtual keyboard on current root window controller.
232   void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
233 
234   // Deactivate virtual keyboard on current root window controller.
235   void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
236 
237  private:
238   explicit RootWindowController(aura::RootWindow* root_window);
239   enum RootWindowType {
240     PRIMARY,
241     SECONDARY,
242     VIRTUAL_KEYBOARD
243   };
244 
245   // Initializes the RootWindowController.  |is_primary| is true if
246   // the controller is for primary display.  |first_run_after_boot| is
247   // set to true only for primary root window after boot.
248   void Init(RootWindowType root_window_type, bool first_run_after_boot);
249 
250   void InitLayoutManagers();
251 
252   // Initializes |system_background_| and possibly also |boot_splash_screen_|.
253   // |is_first_run_after_boot| determines the background's initial color.
254   void CreateSystemBackground(bool is_first_run_after_boot);
255 
256   // Creates each of the special window containers that holds windows of various
257   // types in the shell UI.
258   void CreateContainersInRootWindow(aura::Window* root_window);
259 
260   // Enables projection touch HUD.
261   void EnableTouchHudProjection();
262 
263   // Disables projection touch HUD.
264   void DisableTouchHudProjection();
265 
266   // Overridden from ShellObserver.
267   virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE;
268   virtual void OnTouchHudProjectionToggled(bool enabled) OVERRIDE;
269 
270   scoped_ptr<aura::RootWindow> root_window_;
271   RootWindowLayoutManager* root_window_layout_;
272 
273   scoped_ptr<StackingController> stacking_controller_;
274 
275   // The shelf for managing the launcher and the status widget.
276   scoped_ptr<ShelfWidget> shelf_;
277 
278   // An invisible/empty window used as a event target for
279   // |MouseCursorEventFilter| before a user logs in.
280   // (crbug.com/266987)
281   // Its container is |LockScreenBackgroundContainer| and
282   // this must be deleted before the container is deleted.
283   scoped_ptr<aura::Window> mouse_event_target_;
284 
285   // Manages layout of docked windows. Owned by DockedContainer.
286   DockedWindowLayoutManager* docked_layout_manager_;
287 
288   // Manages layout of panels. Owned by PanelContainer.
289   PanelLayoutManager* panel_layout_manager_;
290 
291   scoped_ptr<SystemBackgroundController> system_background_;
292 #if defined(OS_CHROMEOS)
293   scoped_ptr<BootSplashScreen> boot_splash_screen_;
294 #endif
295 
296   scoped_ptr<ScreenDimmer> screen_dimmer_;
297   scoped_ptr<WorkspaceController> workspace_controller_;
298   scoped_ptr<AlwaysOnTopController> always_on_top_controller_;
299 
300   // Heads-up displays for touch events. These HUDs are not owned by the root
301   // window controller and manage their own lifetimes.
302   TouchHudDebug* touch_hud_debug_;
303   TouchHudProjection* touch_hud_projection_;
304 
305   // We need to own event handlers for various containers.
306   scoped_ptr<ToplevelWindowEventHandler> default_container_handler_;
307   scoped_ptr<ToplevelWindowEventHandler> always_on_top_container_handler_;
308   scoped_ptr<ToplevelWindowEventHandler> modal_container_handler_;
309   scoped_ptr<ToplevelWindowEventHandler> lock_modal_container_handler_;
310   scoped_ptr<ToplevelWindowEventHandler> panel_container_handler_;
311   scoped_ptr<ToplevelWindowEventHandler> docked_container_handler_;
312 
313   scoped_ptr<DesktopBackgroundWidgetController> wallpaper_controller_;
314   scoped_ptr<AnimatingDesktopController> animating_wallpaper_controller_;
315   scoped_ptr<views::corewm::ScopedCaptureClient> capture_client_;
316   scoped_ptr<SoloWindowTracker> solo_window_tracker_;
317 
318   DISALLOW_COPY_AND_ASSIGN(RootWindowController);
319 };
320 
321 
322 // Gets the RootWindowController for |root_window|.
323 ASH_EXPORT RootWindowController* GetRootWindowController(
324     const aura::Window* root_window);
325 
326 }  // namespace internal
327 }  // ash
328 
329 #endif  //  ASH_ROOT_WINDOW_CONTROLLER_H_
330