- add sources.
[platform/framework/web/crosswalk.git] / src / ash / root_window_controller.h
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/base/ui_base_types.h"
17
18 class SkBitmap;
19
20 namespace aura {
21 class EventFilter;
22 class RootWindow;
23 class Window;
24 }
25
26 namespace gfx {
27 class Point;
28 }
29
30 namespace views {
31 class Widget;
32
33 namespace corewm {
34 class InputMethodEventFilter;
35 class RootWindowEventFilter;
36 class ScopedCaptureClient;
37 }
38 }
39
40 namespace keyboard {
41 class KeyboardController;
42 }
43
44 namespace ash {
45 class StackingController;
46 class ShelfWidget;
47 class SystemTray;
48 class ToplevelWindowEventHandler;
49
50 namespace internal {
51
52 class AlwaysOnTopController;
53 class AnimatingDesktopController;
54 class DesktopBackgroundWidgetController;
55 class DockedWindowLayoutManager;
56 class PanelLayoutManager;
57 class RootWindowLayoutManager;
58 class ScreenDimmer;
59 class ShelfLayoutManager;
60 class StatusAreaWidget;
61 class SystemBackgroundController;
62 class SystemModalContainerLayoutManager;
63 class TouchHudDebug;
64 class TouchHudProjection;
65 class WorkspaceController;
66
67 #if defined(OS_CHROMEOS)
68 class BootSplashScreen;
69 #endif
70
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 {
79  public:
80
81   // Creates and Initialize the RootWindowController for primary display.
82   static void CreateForPrimaryDisplay(aura::RootWindow* root_window);
83
84   // Creates and Initialize the RootWindowController for secondary displays.
85   static void CreateForSecondaryDisplay(aura::RootWindow* root_window);
86
87   // Creates and Initialize the RootWindowController for virtual
88   // keyboard displays.
89   static void CreateForVirtualKeyboardDisplay(aura::RootWindow* root_window);
90
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);
96
97   // Returns a RootWindowController of the window's root window.
98   static RootWindowController* ForWindow(const aura::Window* window);
99
100   // Returns the RootWindowController of the target root window.
101   static internal::RootWindowController* ForTargetRootWindow();
102
103   virtual ~RootWindowController();
104
105   aura::RootWindow* root_window() { return root_window_.get(); }
106
107   RootWindowLayoutManager* root_window_layout() { return root_window_layout_; }
108
109   WorkspaceController* workspace_controller() {
110     return workspace_controller_.get();
111   }
112
113   AlwaysOnTopController* always_on_top_controller() {
114     return always_on_top_controller_.get();
115   }
116
117   ScreenDimmer* screen_dimmer() { return screen_dimmer_.get(); }
118
119   // Access the shelf associated with this root window controller,
120   // NULL if no such shelf exists.
121   ShelfWidget* shelf() { return shelf_.get(); }
122
123   // Get touch HUDs associated with this root window controller.
124   TouchHudDebug* touch_hud_debug() const {
125     return touch_hud_debug_;
126   }
127   TouchHudProjection* touch_hud_projection() const {
128     return touch_hud_projection_;
129   }
130
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;
137   }
138   void set_touch_hud_projection(TouchHudProjection* hud) {
139     touch_hud_projection_ = hud;
140   }
141
142   DesktopBackgroundWidgetController* wallpaper_controller() {
143     return wallpaper_controller_.get();
144   }
145   void SetWallpaperController(DesktopBackgroundWidgetController* controller);
146   AnimatingDesktopController* animating_wallpaper_controller() {
147     return animating_wallpaper_controller_.get();
148   }
149   void SetAnimatingWallpaperController(AnimatingDesktopController* controller);
150
151   // Access the shelf layout manager associated with this root
152   // window controller, NULL if no such shelf exists.
153   ShelfLayoutManager* GetShelfLayoutManager();
154
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
157   // lead to a crash.
158   SystemTray* GetSystemTray();
159
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);
164
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);
174
175   aura::Window* GetContainer(int container_id);
176   const aura::Window* GetContainer(int container_id) const;
177
178   // Show launcher view if it was created hidden (before session has started).
179   void ShowLauncher();
180
181   // Called when the launcher associated with this root window is created.
182   void OnLauncherCreated();
183
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);
187
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();
192
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);
198
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.
203   void Shutdown();
204
205   // Deletes all child windows and performs necessary cleanup.
206   void CloseChildWindows();
207
208   // Moves child windows to |dest|.
209   void MoveWindowsTo(aura::Window* dest);
210
211   // Force the shelf to query for it's current visibility state.
212   void UpdateShelfVisibility();
213
214   // Initialize touch HUDs if necessary.
215   void InitTouchHuds();
216
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;
220
221   // Activate virtual keyboard on current root window controller.
222   void ActivateKeyboard(keyboard::KeyboardController* keyboard_controller);
223
224   // Deactivate virtual keyboard on current root window controller.
225   void DeactivateKeyboard(keyboard::KeyboardController* keyboard_controller);
226
227  private:
228   explicit RootWindowController(aura::RootWindow* root_window);
229   enum RootWindowType {
230     PRIMARY,
231     SECONDARY,
232     VIRTUAL_KEYBOARD
233   };
234
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);
239
240   void InitLayoutManagers();
241
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);
245
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);
249
250   // Enables projection touch HUD.
251   void EnableTouchHudProjection();
252
253   // Disables projection touch HUD.
254   void DisableTouchHudProjection();
255
256   // Overridden from ShellObserver.
257   virtual void OnLoginStateChanged(user::LoginStatus status) OVERRIDE;
258   virtual void OnTouchHudProjectionToggled(bool enabled) OVERRIDE;
259
260   scoped_ptr<aura::RootWindow> root_window_;
261   RootWindowLayoutManager* root_window_layout_;
262
263   scoped_ptr<StackingController> stacking_controller_;
264
265   // The shelf for managing the launcher and the status widget.
266   scoped_ptr<ShelfWidget> shelf_;
267
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_;
274
275   // Manages layout of docked windows. Owned by DockedContainer.
276   DockedWindowLayoutManager* docked_layout_manager_;
277
278   // Manages layout of panels. Owned by PanelContainer.
279   PanelLayoutManager* panel_layout_manager_;
280
281   scoped_ptr<SystemBackgroundController> system_background_;
282 #if defined(OS_CHROMEOS)
283   scoped_ptr<BootSplashScreen> boot_splash_screen_;
284 #endif
285
286   scoped_ptr<ScreenDimmer> screen_dimmer_;
287   scoped_ptr<WorkspaceController> workspace_controller_;
288   scoped_ptr<AlwaysOnTopController> always_on_top_controller_;
289
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_;
294
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_;
302
303   scoped_ptr<DesktopBackgroundWidgetController> wallpaper_controller_;
304   scoped_ptr<AnimatingDesktopController> animating_wallpaper_controller_;
305   scoped_ptr<views::corewm::ScopedCaptureClient> capture_client_;
306
307   DISALLOW_COPY_AND_ASSIGN(RootWindowController);
308 };
309
310
311 // Gets the RootWindowController for |root_window|.
312 ASH_EXPORT RootWindowController* GetRootWindowController(
313     const aura::Window* root_window);
314
315 }  // namespace internal
316 }  // ash
317
318 #endif  //  ASH_ROOT_WINDOW_CONTROLLER_H_