• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 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 APPS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
6 #define APPS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
7 
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/aura/client/window_tree_client.h"
12 #include "ui/aura/window_tree_host_observer.h"
13 
14 #if defined(OS_CHROMEOS)
15 #include "ui/display/chromeos/display_configurator.h"
16 #endif
17 
18 namespace aura {
19 class TestScreen;
20 class Window;
21 class WindowTreeHost;
22 namespace client {
23 class DefaultCaptureClient;
24 class FocusClient;
25 }
26 }
27 
28 namespace content {
29 class BrowserContext;
30 }
31 
32 namespace gfx {
33 class Size;
34 }
35 
36 #if defined(OS_CHROMEOS)
37 namespace ui {
38 class UserActivityPowerManagerNotifier;
39 }
40 #endif
41 
42 namespace wm {
43 class CompoundEventFilter;
44 class CursorManager;
45 class InputMethodEventFilter;
46 class UserActivityDetector;
47 }
48 
49 namespace apps {
50 
51 class ShellAppWindow;
52 class ShellAppWindowController;
53 
54 // Handles desktop-related tasks for app_shell.
55 class ShellDesktopController : public aura::client::WindowTreeClient,
56                                public aura::WindowTreeHostObserver
57 #if defined(OS_CHROMEOS)
58                                ,
59                                public ui::DisplayConfigurator::Observer
60 #endif
61                                {
62  public:
63   ShellDesktopController();
64   virtual ~ShellDesktopController();
65 
66   // Returns the single instance of the desktop. (Stateless functions like
67   // ShellAppWindowCreateFunction need to be able to access the desktop, so
68   // we need a singleton somewhere).
69   static ShellDesktopController* instance();
70 
host()71   aura::WindowTreeHost* host() { return host_.get(); }
72 
73   // Creates the window that hosts the app.
74   void CreateRootWindow();
75 
76   // Sets the controller to create/close the app windows. Takes the ownership of
77   // |app_window_controller|.
78   void SetAppWindowController(ShellAppWindowController* app_window_controller);
79 
80   // Creates a new app window and adds it to the desktop. The desktop maintains
81   // ownership of the window.
82   ShellAppWindow* CreateAppWindow(content::BrowserContext* context);
83 
84   // Closes and destroys the app windows.
85   void CloseAppWindows();
86 
87   // Overridden from aura::client::WindowTreeClient:
88   virtual aura::Window* GetDefaultParent(aura::Window* context,
89                                          aura::Window* window,
90                                          const gfx::Rect& bounds) OVERRIDE;
91 
92 #if defined(OS_CHROMEOS)
93   // ui::DisplayConfigurator::Observer overrides.
94   virtual void OnDisplayModeChanged(const std::vector<
95       ui::DisplayConfigurator::DisplayState>& displays) OVERRIDE;
96 #endif
97 
98   // aura::WindowTreeHostObserver overrides:
99   virtual void OnHostCloseRequested(const aura::WindowTreeHost* host) OVERRIDE;
100 
101  protected:
102   // Creates and sets the aura clients and window manager stuff. Subclass may
103   // initialize different sets of the clients.
104   virtual void InitWindowManager();
105 
106  private:
107   // Closes and destroys the root window hosting the app.
108   void DestroyRootWindow();
109 
110   // Returns the dimensions (in pixels) of the primary display, or an empty size
111   // if the dimensions can't be determined or no display is connected.
112   gfx::Size GetPrimaryDisplaySize();
113 
114 #if defined(OS_CHROMEOS)
115   scoped_ptr<ui::DisplayConfigurator> display_configurator_;
116 #endif
117 
118   scoped_ptr<aura::TestScreen> test_screen_;
119 
120   scoped_ptr<aura::WindowTreeHost> host_;
121 
122   scoped_ptr<wm::CompoundEventFilter> root_window_event_filter_;
123 
124   scoped_ptr<aura::client::DefaultCaptureClient> capture_client_;
125 
126   scoped_ptr<wm::InputMethodEventFilter> input_method_filter_;
127 
128   scoped_ptr<aura::client::FocusClient> focus_client_;
129 
130   scoped_ptr<wm::CursorManager> cursor_manager_;
131 
132   scoped_ptr<wm::UserActivityDetector> user_activity_detector_;
133 #if defined(OS_CHROMEOS)
134   scoped_ptr<ui::UserActivityPowerManagerNotifier> user_activity_notifier_;
135 #endif
136 
137   // The desktop supports a single app window.
138   scoped_ptr<ShellAppWindowController> app_window_controller_;
139 
140   DISALLOW_COPY_AND_ASSIGN(ShellDesktopController);
141 };
142 
143 }  // namespace apps
144 
145 #endif  // APPS_SHELL_BROWSER_SHELL_DESKTOP_CONTROLLER_H_
146