OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_AURA_DESKTOP_H_ | 5 #ifndef UI_AURA_ROOT_WINDOW_H_ |
6 #define UI_AURA_DESKTOP_H_ | 6 #define UI_AURA_ROOT_WINDOW_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/task.h" | 13 #include "base/task.h" |
14 #include "ui/aura/aura_export.h" | 14 #include "ui/aura/aura_export.h" |
15 #include "ui/aura/cursor.h" | 15 #include "ui/aura/cursor.h" |
16 #include "ui/aura/focus_manager.h" | 16 #include "ui/aura/focus_manager.h" |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/base/events.h" | 18 #include "ui/base/events.h" |
19 #include "ui/gfx/compositor/compositor.h" | 19 #include "ui/gfx/compositor/compositor.h" |
20 #include "ui/gfx/compositor/layer_animation_observer.h" | 20 #include "ui/gfx/compositor/layer_animation_observer.h" |
21 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
22 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
23 | 23 |
24 namespace gfx { | 24 namespace gfx { |
25 class Size; | 25 class Size; |
26 } | 26 } |
27 | 27 |
28 namespace ui { | 28 namespace ui { |
29 class LayerAnimationSequence; | 29 class LayerAnimationSequence; |
30 class Transform; | 30 class Transform; |
31 } | 31 } |
32 | 32 |
33 namespace aura { | 33 namespace aura { |
34 | 34 |
35 class DesktopHost; | 35 class RootWindowHost; |
36 class DesktopObserver; | 36 class RootWindowObserver; |
37 class KeyEvent; | 37 class KeyEvent; |
38 class MouseEvent; | 38 class MouseEvent; |
39 class ScreenAura; | 39 class ScreenAura; |
40 class StackingClient; | 40 class StackingClient; |
41 class TouchEvent; | 41 class TouchEvent; |
42 | 42 |
43 // Desktop is responsible for hosting a set of windows. | 43 // RootWindow is responsible for hosting a set of windows. |
44 class AURA_EXPORT Desktop : public ui::CompositorDelegate, | 44 class AURA_EXPORT RootWindow : public ui::CompositorDelegate, |
45 public Window, | 45 public Window, |
46 public internal::FocusManager, | 46 public internal::FocusManager, |
47 public ui::LayerAnimationObserver { | 47 public ui::LayerAnimationObserver { |
48 public: | 48 public: |
49 static Desktop* GetInstance(); | 49 static RootWindow* GetInstance(); |
50 static void DeleteInstance(); | 50 static void DeleteInstance(); |
51 | 51 |
52 static void set_use_fullscreen_host_window(bool use_fullscreen) { | 52 static void set_use_fullscreen_host_window(bool use_fullscreen) { |
53 use_fullscreen_host_window_ = use_fullscreen; | 53 use_fullscreen_host_window_ = use_fullscreen; |
54 } | 54 } |
55 | 55 |
56 ui::Compositor* compositor() { return compositor_.get(); } | 56 ui::Compositor* compositor() { return compositor_.get(); } |
57 gfx::Point last_mouse_location() const { return last_mouse_location_; } | 57 gfx::Point last_mouse_location() const { return last_mouse_location_; } |
58 gfx::NativeCursor last_cursor() const { return last_cursor_; } | 58 gfx::NativeCursor last_cursor() const { return last_cursor_; } |
59 StackingClient* stacking_client() { return stacking_client_.get(); } | 59 StackingClient* stacking_client() { return stacking_client_.get(); } |
60 Window* active_window() { return active_window_; } | 60 Window* active_window() { return active_window_; } |
61 Window* mouse_pressed_handler() { return mouse_pressed_handler_; } | 61 Window* mouse_pressed_handler() { return mouse_pressed_handler_; } |
62 Window* capture_window() { return capture_window_; } | 62 Window* capture_window() { return capture_window_; } |
63 ScreenAura* screen() { return screen_; } | 63 ScreenAura* screen() { return screen_; } |
64 | 64 |
65 void SetStackingClient(StackingClient* stacking_client); | 65 void SetStackingClient(StackingClient* stacking_client); |
66 | 66 |
67 // Shows the desktop host. | 67 // Shows the root window host. |
68 void ShowDesktop(); | 68 void ShowRootWindow(); |
69 | 69 |
70 // Sets the size of the desktop. | 70 // Sets the size of the root window. |
71 void SetHostSize(const gfx::Size& size); | 71 void SetHostSize(const gfx::Size& size); |
72 gfx::Size GetHostSize() const; | 72 gfx::Size GetHostSize() const; |
73 | 73 |
74 // Shows the specified cursor. | 74 // Shows the specified cursor. |
75 void SetCursor(gfx::NativeCursor cursor); | 75 void SetCursor(gfx::NativeCursor cursor); |
76 | 76 |
77 // Shows the desktop host and runs an event loop for it. | 77 // Shows the root window host and runs an event loop for it. |
78 void Run(); | 78 void Run(); |
79 | 79 |
80 // Draws the necessary set of windows. | 80 // Draws the necessary set of windows. |
81 void Draw(); | 81 void Draw(); |
82 | 82 |
83 // Handles a mouse event. Returns true if handled. | 83 // Handles a mouse event. Returns true if handled. |
84 bool DispatchMouseEvent(MouseEvent* event); | 84 bool DispatchMouseEvent(MouseEvent* event); |
85 | 85 |
86 // Handles a key event. Returns true if handled. | 86 // Handles a key event. Returns true if handled. |
87 bool DispatchKeyEvent(KeyEvent* event); | 87 bool DispatchKeyEvent(KeyEvent* event); |
(...skipping 20 matching lines...) Expand all Loading... |
108 // |window| is not a topmost window, or there are no other suitable windows to | 108 // |window| is not a topmost window, or there are no other suitable windows to |
109 // activate. | 109 // activate. |
110 void Deactivate(Window* window); | 110 void Deactivate(Window* window); |
111 | 111 |
112 // Invoked when |window| is initialized. | 112 // Invoked when |window| is initialized. |
113 void WindowInitialized(Window* window); | 113 void WindowInitialized(Window* window); |
114 | 114 |
115 // Invoked when |window| is being destroyed. | 115 // Invoked when |window| is being destroyed. |
116 void WindowDestroying(Window* window); | 116 void WindowDestroying(Window* window); |
117 | 117 |
118 // Returns the desktop's dispatcher. The result should only be passed to | 118 // Returns the root window's dispatcher. The result should only be passed to |
119 // MessageLoopForUI::RunWithDispatcher() or | 119 // MessageLoopForUI::RunWithDispatcher() or |
120 // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch | 120 // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch |
121 // an event by |Dispatch(const NativeEvent&)| on it. It must never be stored. | 121 // an event by |Dispatch(const NativeEvent&)| on it. It must never be stored. |
122 MessageLoop::Dispatcher* GetDispatcher(); | 122 MessageLoop::Dispatcher* GetDispatcher(); |
123 | 123 |
124 // Add/remove observer. | 124 // Add/remove observer. |
125 void AddObserver(DesktopObserver* observer); | 125 void AddObserver(RootWindowObserver* observer); |
126 void RemoveObserver(DesktopObserver* observer); | 126 void RemoveObserver(RootWindowObserver* observer); |
127 | 127 |
128 // Are any mouse buttons currently down? | 128 // Are any mouse buttons currently down? |
129 bool IsMouseButtonDown() const; | 129 bool IsMouseButtonDown() const; |
130 | 130 |
131 // Posts |native_event| to the platform's event queue. | 131 // Posts |native_event| to the platform's event queue. |
132 void PostNativeEvent(const base::NativeEvent& native_event); | 132 void PostNativeEvent(const base::NativeEvent& native_event); |
133 | 133 |
134 // Converts |point| from the desktop's coordinate system to native screen's. | 134 // Converts |point| from the root window's coordinate system to native |
| 135 // screen's. |
135 void ConvertPointToNativeScreen(gfx::Point* point) const; | 136 void ConvertPointToNativeScreen(gfx::Point* point) const; |
136 | 137 |
137 // Capture ------------------------------------------------------------------- | 138 // Capture ------------------------------------------------------------------- |
138 | 139 |
139 // Sets capture to the specified window. | 140 // Sets capture to the specified window. |
140 void SetCapture(Window* window); | 141 void SetCapture(Window* window); |
141 | 142 |
142 // If |window| has mouse capture, the current capture window is set to NULL. | 143 // If |window| has mouse capture, the current capture window is set to NULL. |
143 void ReleaseCapture(Window* window); | 144 void ReleaseCapture(Window* window); |
144 | 145 |
145 // Overridden from Window: | 146 // Overridden from Window: |
146 virtual void SetTransform(const ui::Transform& transform) OVERRIDE; | 147 virtual void SetTransform(const ui::Transform& transform) OVERRIDE; |
147 | 148 |
148 #if !defined(NDEBUG) | 149 #if !defined(NDEBUG) |
149 // Toggles the host's full screen state. | 150 // Toggles the host's full screen state. |
150 void ToggleFullScreen(); | 151 void ToggleFullScreen(); |
151 #endif | 152 #endif |
152 | 153 |
153 // Overridden from ui::CompositorDelegate: | 154 // Overridden from ui::CompositorDelegate: |
154 virtual void ScheduleDraw(); | 155 virtual void ScheduleDraw(); |
155 | 156 |
156 private: | 157 private: |
157 Desktop(); | 158 RootWindow(); |
158 virtual ~Desktop(); | 159 virtual ~RootWindow(); |
159 | 160 |
160 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, | 161 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, |
161 // sending exited and entered events as its value changes. | 162 // sending exited and entered events as its value changes. |
162 void HandleMouseMoved(const MouseEvent& event, Window* target); | 163 void HandleMouseMoved(const MouseEvent& event, Window* target); |
163 | 164 |
164 bool ProcessMouseEvent(Window* target, MouseEvent* event); | 165 bool ProcessMouseEvent(Window* target, MouseEvent* event); |
165 bool ProcessKeyEvent(Window* target, KeyEvent* event); | 166 bool ProcessKeyEvent(Window* target, KeyEvent* event); |
166 ui::TouchStatus ProcessTouchEvent(Window* target, TouchEvent* event); | 167 ui::TouchStatus ProcessTouchEvent(Window* target, TouchEvent* event); |
167 | 168 |
168 // Overridden from Window: | 169 // Overridden from Window: |
169 virtual bool CanFocus() const OVERRIDE; | 170 virtual bool CanFocus() const OVERRIDE; |
170 virtual internal::FocusManager* GetFocusManager() OVERRIDE; | 171 virtual internal::FocusManager* GetFocusManager() OVERRIDE; |
171 virtual Desktop* GetDesktop() OVERRIDE; | 172 virtual RootWindow* GetRootWindow() OVERRIDE; |
172 virtual void WindowDetachedFromDesktop(Window* window) OVERRIDE; | 173 virtual void WindowDetachedFromRootWindow(Window* window) OVERRIDE; |
173 | 174 |
174 // Overridden from ui::LayerAnimationObserver: | 175 // Overridden from ui::LayerAnimationObserver: |
175 virtual void OnLayerAnimationEnded( | 176 virtual void OnLayerAnimationEnded( |
176 const ui::LayerAnimationSequence* animation) OVERRIDE; | 177 const ui::LayerAnimationSequence* animation) OVERRIDE; |
177 virtual void OnLayerAnimationScheduled( | 178 virtual void OnLayerAnimationScheduled( |
178 const ui::LayerAnimationSequence* animation) OVERRIDE; | 179 const ui::LayerAnimationSequence* animation) OVERRIDE; |
179 virtual void OnLayerAnimationAborted( | 180 virtual void OnLayerAnimationAborted( |
180 const ui::LayerAnimationSequence* animation) OVERRIDE; | 181 const ui::LayerAnimationSequence* animation) OVERRIDE; |
181 | 182 |
182 // Overridden from FocusManager: | 183 // Overridden from FocusManager: |
183 virtual void SetFocusedWindow(Window* window) OVERRIDE; | 184 virtual void SetFocusedWindow(Window* window) OVERRIDE; |
184 virtual Window* GetFocusedWindow() OVERRIDE; | 185 virtual Window* GetFocusedWindow() OVERRIDE; |
185 virtual bool IsFocusedWindow(const Window* window) const OVERRIDE; | 186 virtual bool IsFocusedWindow(const Window* window) const OVERRIDE; |
186 | 187 |
187 // Initializes the desktop. | 188 // Initializes the root window. |
188 void Init(); | 189 void Init(); |
189 | 190 |
190 // Parses the switch describing the initial size for the host window and | 191 // Parses the switch describing the initial size for the host window and |
191 // returns bounds for the window. | 192 // returns bounds for the window. |
192 gfx::Rect GetInitialHostWindowBounds() const; | 193 gfx::Rect GetInitialHostWindowBounds() const; |
193 | 194 |
194 scoped_refptr<ui::Compositor> compositor_; | 195 scoped_refptr<ui::Compositor> compositor_; |
195 | 196 |
196 scoped_ptr<DesktopHost> host_; | 197 scoped_ptr<RootWindowHost> host_; |
197 | 198 |
198 scoped_ptr<StackingClient> stacking_client_; | 199 scoped_ptr<StackingClient> stacking_client_; |
199 | 200 |
200 static Desktop* instance_; | 201 static RootWindow* instance_; |
201 | 202 |
202 // If set before the Desktop is created, the host window will cover the entire | 203 // If set before the RootWindow is created, the host window will cover the |
203 // screen. Note that this can still be overridden via the | 204 // entire screen. Note that this can still be overridden via the |
204 // switches::kAuraHostWindowSize flag. | 205 // switches::kAuraHostWindowSize flag. |
205 static bool use_fullscreen_host_window_; | 206 static bool use_fullscreen_host_window_; |
206 | 207 |
207 // Used to schedule painting. | 208 // Used to schedule painting. |
208 base::WeakPtrFactory<Desktop> schedule_paint_factory_; | 209 base::WeakPtrFactory<RootWindow> schedule_paint_factory_; |
209 | 210 |
210 Window* active_window_; | 211 Window* active_window_; |
211 | 212 |
212 // Last location seen in a mouse event. | 213 // Last location seen in a mouse event. |
213 gfx::Point last_mouse_location_; | 214 gfx::Point last_mouse_location_; |
214 | 215 |
215 // ui::EventFlags containing the current state of the mouse buttons. | 216 // ui::EventFlags containing the current state of the mouse buttons. |
216 int mouse_button_flags_; | 217 int mouse_button_flags_; |
217 | 218 |
218 // Last cursor set. Used for testing. | 219 // Last cursor set. Used for testing. |
219 gfx::NativeCursor last_cursor_; | 220 gfx::NativeCursor last_cursor_; |
220 | 221 |
221 // Are we in the process of being destroyed? Used to avoid processing during | 222 // Are we in the process of being destroyed? Used to avoid processing during |
222 // destruction. | 223 // destruction. |
223 bool in_destructor_; | 224 bool in_destructor_; |
224 | 225 |
225 ObserverList<DesktopObserver> observers_; | 226 ObserverList<RootWindowObserver> observers_; |
226 | 227 |
227 ScreenAura* screen_; | 228 ScreenAura* screen_; |
228 | 229 |
229 // The capture window. When not-null, this window receives all the mouse and | 230 // The capture window. When not-null, this window receives all the mouse and |
230 // touch events. | 231 // touch events. |
231 Window* capture_window_; | 232 Window* capture_window_; |
232 | 233 |
233 Window* mouse_pressed_handler_; | 234 Window* mouse_pressed_handler_; |
234 Window* mouse_moved_handler_; | 235 Window* mouse_moved_handler_; |
235 Window* focused_window_; | 236 Window* focused_window_; |
236 Window* touch_event_handler_; | 237 Window* touch_event_handler_; |
237 | 238 |
238 DISALLOW_COPY_AND_ASSIGN(Desktop); | 239 DISALLOW_COPY_AND_ASSIGN(RootWindow); |
239 }; | 240 }; |
240 | 241 |
241 } // namespace aura | 242 } // namespace aura |
242 | 243 |
243 #endif // UI_AURA_DESKTOP_H_ | 244 #endif // UI_AURA_ROOT_WINDOW_H_ |
OLD | NEW |