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 #include "ui/aura/desktop.h" | 5 #include "ui/aura/root_window.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "ui/aura/aura_switches.h" | 16 #include "ui/aura/aura_switches.h" |
17 #include "ui/aura/client/stacking_client.h" | 17 #include "ui/aura/client/stacking_client.h" |
18 #include "ui/aura/desktop_host.h" | 18 #include "ui/aura/root_window_host.h" |
19 #include "ui/aura/desktop_observer.h" | 19 #include "ui/aura/root_window_observer.h" |
20 #include "ui/aura/event.h" | 20 #include "ui/aura/event.h" |
21 #include "ui/aura/event_filter.h" | 21 #include "ui/aura/event_filter.h" |
22 #include "ui/aura/focus_manager.h" | 22 #include "ui/aura/focus_manager.h" |
23 #include "ui/aura/screen_aura.h" | 23 #include "ui/aura/screen_aura.h" |
24 #include "ui/aura/window.h" | 24 #include "ui/aura/window.h" |
25 #include "ui/aura/window_delegate.h" | 25 #include "ui/aura/window_delegate.h" |
26 #include "ui/base/hit_test.h" | 26 #include "ui/base/hit_test.h" |
27 #include "ui/gfx/compositor/compositor.h" | 27 #include "ui/gfx/compositor/compositor.h" |
28 #include "ui/gfx/compositor/layer.h" | 28 #include "ui/gfx/compositor/layer.h" |
29 #include "ui/gfx/compositor/layer_animator.h" | 29 #include "ui/gfx/compositor/layer_animator.h" |
(...skipping 19 matching lines...) Expand all Loading... |
49 // in window coordinates. | 49 // in window coordinates. |
50 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 50 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
51 if (!target->delegate()) | 51 if (!target->delegate()) |
52 return false; | 52 return false; |
53 int hit_test_code = target->delegate()->GetNonClientComponent(location); | 53 int hit_test_code = target->delegate()->GetNonClientComponent(location); |
54 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; | 54 return hit_test_code != HTCLIENT && hit_test_code != HTNOWHERE; |
55 } | 55 } |
56 | 56 |
57 class DefaultStackingClient : public StackingClient { | 57 class DefaultStackingClient : public StackingClient { |
58 public: | 58 public: |
59 explicit DefaultStackingClient(Desktop* desktop) : desktop_(desktop) {} | 59 explicit DefaultStackingClient(RootWindow* root_window) |
| 60 : root_window_(root_window) {} |
60 virtual ~DefaultStackingClient() {} | 61 virtual ~DefaultStackingClient() {} |
61 | 62 |
62 private: | 63 private: |
63 | 64 |
64 // Overridden from StackingClient: | 65 // Overridden from StackingClient: |
65 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { | 66 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { |
66 desktop_->AddChild(window); | 67 root_window_->AddChild(window); |
67 } | 68 } |
68 virtual bool CanActivateWindow(Window* window) const OVERRIDE { | 69 virtual bool CanActivateWindow(Window* window) const OVERRIDE { |
69 return window->parent() == desktop_; | 70 return window->parent() == root_window_; |
70 } | 71 } |
71 virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE { | 72 virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE { |
72 Window::Windows::const_reverse_iterator i; | 73 Window::Windows::const_reverse_iterator i; |
73 for (i = desktop_->children().rbegin(); | 74 for (i = root_window_->children().rbegin(); |
74 i != desktop_->children().rend(); | 75 i != root_window_->children().rend(); |
75 ++i) { | 76 ++i) { |
76 if (*i == ignore) | 77 if (*i == ignore) |
77 continue; | 78 continue; |
78 return *i; | 79 return *i; |
79 } | 80 } |
80 return NULL; | 81 return NULL; |
81 } | 82 } |
82 | 83 |
83 Desktop* desktop_; | 84 RootWindow* root_window_; |
84 | 85 |
85 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); | 86 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); |
86 }; | 87 }; |
87 | 88 |
88 typedef std::vector<EventFilter*> EventFilters; | 89 typedef std::vector<EventFilter*> EventFilters; |
89 | 90 |
90 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 91 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
91 Window* window = target->parent(); | 92 Window* window = target->parent(); |
92 while (window) { | 93 while (window) { |
93 if (window->event_filter()) | 94 if (window->event_filter()) |
94 filters->push_back(window->event_filter()); | 95 filters->push_back(window->event_filter()); |
95 window = window->parent(); | 96 window = window->parent(); |
96 } | 97 } |
97 } | 98 } |
98 | 99 |
99 } // namespace | 100 } // namespace |
100 | 101 |
101 Desktop* Desktop::instance_ = NULL; | 102 RootWindow* RootWindow::instance_ = NULL; |
102 bool Desktop::use_fullscreen_host_window_ = false; | 103 bool RootWindow::use_fullscreen_host_window_ = false; |
103 | 104 |
104 //////////////////////////////////////////////////////////////////////////////// | 105 //////////////////////////////////////////////////////////////////////////////// |
105 // Desktop, public: | 106 // RootWindow, public: |
106 | 107 |
107 // static | 108 // static |
108 Desktop* Desktop::GetInstance() { | 109 RootWindow* RootWindow::GetInstance() { |
109 if (!instance_) { | 110 if (!instance_) { |
110 instance_ = new Desktop; | 111 instance_ = new RootWindow; |
111 instance_->Init(); | 112 instance_->Init(); |
112 } | 113 } |
113 return instance_; | 114 return instance_; |
114 } | 115 } |
115 | 116 |
116 // static | 117 // static |
117 void Desktop::DeleteInstance() { | 118 void RootWindow::DeleteInstance() { |
118 delete instance_; | 119 delete instance_; |
119 instance_ = NULL; | 120 instance_ = NULL; |
120 } | 121 } |
121 | 122 |
122 void Desktop::SetStackingClient(StackingClient* stacking_client) { | 123 void RootWindow::SetStackingClient(StackingClient* stacking_client) { |
123 stacking_client_.reset(stacking_client); | 124 stacking_client_.reset(stacking_client); |
124 } | 125 } |
125 | 126 |
126 void Desktop::ShowDesktop() { | 127 void RootWindow::ShowRootWindow() { |
127 host_->Show(); | 128 host_->Show(); |
128 } | 129 } |
129 | 130 |
130 void Desktop::SetHostSize(const gfx::Size& size) { | 131 void RootWindow::SetHostSize(const gfx::Size& size) { |
131 host_->SetSize(size); | 132 host_->SetSize(size); |
132 // Requery the location to constrain it within the new desktop size. | 133 // Requery the location to constrain it within the new root window size. |
133 last_mouse_location_ = host_->QueryMouseLocation(); | 134 last_mouse_location_ = host_->QueryMouseLocation(); |
134 } | 135 } |
135 | 136 |
136 gfx::Size Desktop::GetHostSize() const { | 137 gfx::Size RootWindow::GetHostSize() const { |
137 gfx::Rect rect(host_->GetSize()); | 138 gfx::Rect rect(host_->GetSize()); |
138 layer()->transform().TransformRect(&rect); | 139 layer()->transform().TransformRect(&rect); |
139 return rect.size(); | 140 return rect.size(); |
140 } | 141 } |
141 | 142 |
142 void Desktop::SetCursor(gfx::NativeCursor cursor) { | 143 void RootWindow::SetCursor(gfx::NativeCursor cursor) { |
143 last_cursor_ = cursor; | 144 last_cursor_ = cursor; |
144 // A lot of code seems to depend on NULL cursors actually showing an arrow, | 145 // A lot of code seems to depend on NULL cursors actually showing an arrow, |
145 // so just pass everything along to the host. | 146 // so just pass everything along to the host. |
146 host_->SetCursor(cursor); | 147 host_->SetCursor(cursor); |
147 } | 148 } |
148 | 149 |
149 void Desktop::Run() { | 150 void RootWindow::Run() { |
150 ShowDesktop(); | 151 ShowRootWindow(); |
151 MessageLoopForUI::current()->Run(); | 152 MessageLoopForUI::current()->Run(); |
152 } | 153 } |
153 | 154 |
154 void Desktop::Draw() { | 155 void RootWindow::Draw() { |
155 compositor_->Draw(false); | 156 compositor_->Draw(false); |
156 } | 157 } |
157 | 158 |
158 bool Desktop::DispatchMouseEvent(MouseEvent* event) { | 159 bool RootWindow::DispatchMouseEvent(MouseEvent* event) { |
159 static const int kMouseButtonFlagMask = | 160 static const int kMouseButtonFlagMask = |
160 ui::EF_LEFT_BUTTON_DOWN | | 161 ui::EF_LEFT_BUTTON_DOWN | |
161 ui::EF_MIDDLE_BUTTON_DOWN | | 162 ui::EF_MIDDLE_BUTTON_DOWN | |
162 ui::EF_RIGHT_BUTTON_DOWN; | 163 ui::EF_RIGHT_BUTTON_DOWN; |
163 | 164 |
164 event->UpdateForTransform(layer()->transform()); | 165 event->UpdateForTransform(layer()->transform()); |
165 | 166 |
166 last_mouse_location_ = event->location(); | 167 last_mouse_location_ = event->location(); |
167 | 168 |
168 Window* target = | 169 Window* target = |
(...skipping 21 matching lines...) Expand all Loading... |
190 gfx::Point location_in_window = event->location(); | 191 gfx::Point location_in_window = event->location(); |
191 Window::ConvertPointToWindow(this, target, &location_in_window); | 192 Window::ConvertPointToWindow(this, target, &location_in_window); |
192 if (IsNonClientLocation(target, location_in_window)) | 193 if (IsNonClientLocation(target, location_in_window)) |
193 flags |= ui::EF_IS_NON_CLIENT; | 194 flags |= ui::EF_IS_NON_CLIENT; |
194 MouseEvent translated_event(*event, this, target, event->type(), flags); | 195 MouseEvent translated_event(*event, this, target, event->type(), flags); |
195 return ProcessMouseEvent(target, &translated_event); | 196 return ProcessMouseEvent(target, &translated_event); |
196 } | 197 } |
197 return false; | 198 return false; |
198 } | 199 } |
199 | 200 |
200 bool Desktop::DispatchKeyEvent(KeyEvent* event) { | 201 bool RootWindow::DispatchKeyEvent(KeyEvent* event) { |
201 if (focused_window_) { | 202 if (focused_window_) { |
202 KeyEvent translated_event(*event); | 203 KeyEvent translated_event(*event); |
203 return ProcessKeyEvent(focused_window_, &translated_event); | 204 return ProcessKeyEvent(focused_window_, &translated_event); |
204 } | 205 } |
205 return false; | 206 return false; |
206 } | 207 } |
207 | 208 |
208 bool Desktop::DispatchTouchEvent(TouchEvent* event) { | 209 bool RootWindow::DispatchTouchEvent(TouchEvent* event) { |
209 event->UpdateForTransform(layer()->transform()); | 210 event->UpdateForTransform(layer()->transform()); |
210 bool handled = false; | 211 bool handled = false; |
211 Window* target = | 212 Window* target = |
212 touch_event_handler_ ? touch_event_handler_ : capture_window_; | 213 touch_event_handler_ ? touch_event_handler_ : capture_window_; |
213 if (!target) | 214 if (!target) |
214 target = GetEventHandlerForPoint(event->location()); | 215 target = GetEventHandlerForPoint(event->location()); |
215 if (target) { | 216 if (target) { |
216 TouchEvent translated_event(*event, this, target); | 217 TouchEvent translated_event(*event, this, target); |
217 ui::TouchStatus status = ProcessTouchEvent(target, &translated_event); | 218 ui::TouchStatus status = ProcessTouchEvent(target, &translated_event); |
218 if (status == ui::TOUCH_STATUS_START) | 219 if (status == ui::TOUCH_STATUS_START) |
219 touch_event_handler_ = target; | 220 touch_event_handler_ = target; |
220 else if (status == ui::TOUCH_STATUS_END || | 221 else if (status == ui::TOUCH_STATUS_END || |
221 status == ui::TOUCH_STATUS_CANCEL) | 222 status == ui::TOUCH_STATUS_CANCEL) |
222 touch_event_handler_ = NULL; | 223 touch_event_handler_ = NULL; |
223 handled = status != ui::TOUCH_STATUS_UNKNOWN; | 224 handled = status != ui::TOUCH_STATUS_UNKNOWN; |
224 } | 225 } |
225 return handled; | 226 return handled; |
226 } | 227 } |
227 | 228 |
228 void Desktop::OnHostResized(const gfx::Size& size) { | 229 void RootWindow::OnHostResized(const gfx::Size& size) { |
229 // The compositor should have the same size as the native desktop host. | 230 // The compositor should have the same size as the native root window host. |
230 compositor_->WidgetSizeChanged(size); | 231 compositor_->WidgetSizeChanged(size); |
231 | 232 |
232 // The layer, and all the observers should be notified of the | 233 // The layer, and all the observers should be notified of the |
233 // transformed size of the desktop. | 234 // transformed size of the root window. |
234 gfx::Rect bounds(size); | 235 gfx::Rect bounds(size); |
235 layer()->transform().TransformRect(&bounds); | 236 layer()->transform().TransformRect(&bounds); |
236 SetBounds(gfx::Rect(bounds.size())); | 237 SetBounds(gfx::Rect(bounds.size())); |
237 FOR_EACH_OBSERVER(DesktopObserver, observers_, | 238 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
238 OnDesktopResized(bounds.size())); | 239 OnRootWindowResized(bounds.size())); |
239 } | 240 } |
240 | 241 |
241 void Desktop::OnNativeScreenResized(const gfx::Size& size) { | 242 void RootWindow::OnNativeScreenResized(const gfx::Size& size) { |
242 if (use_fullscreen_host_window_) | 243 if (use_fullscreen_host_window_) |
243 SetHostSize(size); | 244 SetHostSize(size); |
244 } | 245 } |
245 | 246 |
246 void Desktop::SetActiveWindow(Window* window, Window* to_focus) { | 247 void RootWindow::SetActiveWindow(Window* window, Window* to_focus) { |
247 if (!window) | 248 if (!window) |
248 return; | 249 return; |
249 // The stacking client may impose rules on what window configurations can be | 250 // The stacking client may impose rules on what window configurations can be |
250 // activated or deactivated. | 251 // activated or deactivated. |
251 if (!stacking_client_->CanActivateWindow(window)) | 252 if (!stacking_client_->CanActivateWindow(window)) |
252 return; | 253 return; |
253 // The window may not be activate-able. | 254 // The window may not be activate-able. |
254 if (!window->CanActivate()) | 255 if (!window->CanActivate()) |
255 return; | 256 return; |
256 // Nothing may actually have changed. | 257 // Nothing may actually have changed. |
257 if (active_window_ == window) | 258 if (active_window_ == window) |
258 return; | 259 return; |
259 | 260 |
260 Window* old_active = active_window_; | 261 Window* old_active = active_window_; |
261 active_window_ = window; | 262 active_window_ = window; |
262 // Invoke OnLostActive after we've changed the active window. That way if the | 263 // Invoke OnLostActive after we've changed the active window. That way if the |
263 // delegate queries for active state it doesn't think the window is still | 264 // delegate queries for active state it doesn't think the window is still |
264 // active. | 265 // active. |
265 if (old_active && old_active->delegate()) | 266 if (old_active && old_active->delegate()) |
266 old_active->delegate()->OnLostActive(); | 267 old_active->delegate()->OnLostActive(); |
267 if (active_window_) { | 268 if (active_window_) { |
268 active_window_->parent()->StackChildAtTop(active_window_); | 269 active_window_->parent()->StackChildAtTop(active_window_); |
269 if (active_window_->delegate()) | 270 if (active_window_->delegate()) |
270 active_window_->delegate()->OnActivated(); | 271 active_window_->delegate()->OnActivated(); |
271 active_window_->GetFocusManager()->SetFocusedWindow( | 272 active_window_->GetFocusManager()->SetFocusedWindow( |
272 to_focus ? to_focus : active_window_); | 273 to_focus ? to_focus : active_window_); |
273 } | 274 } |
274 FOR_EACH_OBSERVER(DesktopObserver, observers_, | 275 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
275 OnActiveWindowChanged(active_window_)); | 276 OnActiveWindowChanged(active_window_)); |
276 } | 277 } |
277 | 278 |
278 void Desktop::ActivateTopmostWindow() { | 279 void RootWindow::ActivateTopmostWindow() { |
279 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(NULL), NULL); | 280 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(NULL), NULL); |
280 } | 281 } |
281 | 282 |
282 void Desktop::Deactivate(Window* window) { | 283 void RootWindow::Deactivate(Window* window) { |
283 // The stacking client may impose rules on what window configurations can be | 284 // The stacking client may impose rules on what window configurations can be |
284 // activated or deactivated. | 285 // activated or deactivated. |
285 if (!window || !stacking_client_->CanActivateWindow(window)) | 286 if (!window || !stacking_client_->CanActivateWindow(window)) |
286 return; | 287 return; |
287 if (active_window_ != window) | 288 if (active_window_ != window) |
288 return; | 289 return; |
289 | 290 |
290 Window* to_activate = stacking_client_->GetTopmostWindowToActivate(window); | 291 Window* to_activate = stacking_client_->GetTopmostWindowToActivate(window); |
291 if (to_activate) | 292 if (to_activate) |
292 SetActiveWindow(to_activate, NULL); | 293 SetActiveWindow(to_activate, NULL); |
293 } | 294 } |
294 | 295 |
295 void Desktop::WindowInitialized(Window* window) { | 296 void RootWindow::WindowInitialized(Window* window) { |
296 FOR_EACH_OBSERVER(DesktopObserver, observers_, OnWindowInitialized(window)); | 297 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
| 298 OnWindowInitialized(window)); |
297 } | 299 } |
298 | 300 |
299 void Desktop::WindowDestroying(Window* window) { | 301 void RootWindow::WindowDestroying(Window* window) { |
300 // Update the focused window state if the window was focused. | 302 // Update the focused window state if the window was focused. |
301 if (focused_window_ == window) | 303 if (focused_window_ == window) |
302 SetFocusedWindow(NULL); | 304 SetFocusedWindow(NULL); |
303 | 305 |
304 // When a window is being destroyed it's likely that the WindowDelegate won't | 306 // When a window is being destroyed it's likely that the WindowDelegate won't |
305 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and | 307 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and |
306 // don't sent it release/capture lost events. | 308 // don't sent it release/capture lost events. |
307 if (mouse_pressed_handler_ == window) | 309 if (mouse_pressed_handler_ == window) |
308 mouse_pressed_handler_ = NULL; | 310 mouse_pressed_handler_ = NULL; |
309 if (mouse_moved_handler_ == window) | 311 if (mouse_moved_handler_ == window) |
310 mouse_moved_handler_ = NULL; | 312 mouse_moved_handler_ = NULL; |
311 if (capture_window_ == window) | 313 if (capture_window_ == window) |
312 capture_window_ = NULL; | 314 capture_window_ = NULL; |
313 if (touch_event_handler_ == window) | 315 if (touch_event_handler_ == window) |
314 touch_event_handler_ = NULL; | 316 touch_event_handler_ = NULL; |
315 | 317 |
316 if (in_destructor_ || window != active_window_) | 318 if (in_destructor_ || window != active_window_) |
317 return; | 319 return; |
318 | 320 |
319 // Reset active_window_ before invoking SetActiveWindow so that we don't | 321 // Reset active_window_ before invoking SetActiveWindow so that we don't |
320 // attempt to notify it while running its destructor. | 322 // attempt to notify it while running its destructor. |
321 active_window_ = NULL; | 323 active_window_ = NULL; |
322 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(window), NULL); | 324 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(window), NULL); |
323 } | 325 } |
324 | 326 |
325 MessageLoop::Dispatcher* Desktop::GetDispatcher() { | 327 MessageLoop::Dispatcher* RootWindow::GetDispatcher() { |
326 return host_.get(); | 328 return host_.get(); |
327 } | 329 } |
328 | 330 |
329 void Desktop::AddObserver(DesktopObserver* observer) { | 331 void RootWindow::AddObserver(RootWindowObserver* observer) { |
330 observers_.AddObserver(observer); | 332 observers_.AddObserver(observer); |
331 } | 333 } |
332 | 334 |
333 void Desktop::RemoveObserver(DesktopObserver* observer) { | 335 void RootWindow::RemoveObserver(RootWindowObserver* observer) { |
334 observers_.RemoveObserver(observer); | 336 observers_.RemoveObserver(observer); |
335 } | 337 } |
336 | 338 |
337 bool Desktop::IsMouseButtonDown() const { | 339 bool RootWindow::IsMouseButtonDown() const { |
338 return mouse_button_flags_ != 0; | 340 return mouse_button_flags_ != 0; |
339 } | 341 } |
340 | 342 |
341 void Desktop::PostNativeEvent(const base::NativeEvent& native_event) { | 343 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { |
342 host_->PostNativeEvent(native_event); | 344 host_->PostNativeEvent(native_event); |
343 } | 345 } |
344 | 346 |
345 void Desktop::ConvertPointToNativeScreen(gfx::Point* point) const { | 347 void RootWindow::ConvertPointToNativeScreen(gfx::Point* point) const { |
346 gfx::Point location = host_->GetLocationOnNativeScreen(); | 348 gfx::Point location = host_->GetLocationOnNativeScreen(); |
347 point->Offset(location.x(), location.y()); | 349 point->Offset(location.x(), location.y()); |
348 } | 350 } |
349 | 351 |
350 void Desktop::SetCapture(Window* window) { | 352 void RootWindow::SetCapture(Window* window) { |
351 if (capture_window_ == window) | 353 if (capture_window_ == window) |
352 return; | 354 return; |
353 | 355 |
354 if (capture_window_ && capture_window_->delegate()) | 356 if (capture_window_ && capture_window_->delegate()) |
355 capture_window_->delegate()->OnCaptureLost(); | 357 capture_window_->delegate()->OnCaptureLost(); |
356 capture_window_ = window; | 358 capture_window_ = window; |
357 | 359 |
358 if (capture_window_) { | 360 if (capture_window_) { |
359 // Make all subsequent mouse events and touch go to the capture window. We | 361 // Make all subsequent mouse events and touch go to the capture window. We |
360 // shouldn't need to send an event here as OnCaptureLost should take care of | 362 // shouldn't need to send an event here as OnCaptureLost should take care of |
361 // that. | 363 // that. |
362 if (mouse_pressed_handler_) | 364 if (mouse_pressed_handler_) |
363 mouse_pressed_handler_ = capture_window_; | 365 mouse_pressed_handler_ = capture_window_; |
364 if (touch_event_handler_) | 366 if (touch_event_handler_) |
365 touch_event_handler_ = capture_window_; | 367 touch_event_handler_ = capture_window_; |
366 } else { | 368 } else { |
367 // When capture is lost, we must reset the event handlers. | 369 // When capture is lost, we must reset the event handlers. |
368 mouse_pressed_handler_ = NULL; | 370 mouse_pressed_handler_ = NULL; |
369 touch_event_handler_ = NULL; | 371 touch_event_handler_ = NULL; |
370 } | 372 } |
371 } | 373 } |
372 | 374 |
373 void Desktop::ReleaseCapture(Window* window) { | 375 void RootWindow::ReleaseCapture(Window* window) { |
374 if (capture_window_ != window) | 376 if (capture_window_ != window) |
375 return; | 377 return; |
376 SetCapture(NULL); | 378 SetCapture(NULL); |
377 } | 379 } |
378 | 380 |
379 void Desktop::SetTransform(const ui::Transform& transform) { | 381 void RootWindow::SetTransform(const ui::Transform& transform) { |
380 Window::SetTransform(transform); | 382 Window::SetTransform(transform); |
381 | 383 |
382 // If the layer is not animating, then we need to update the host size | 384 // If the layer is not animating, then we need to update the host size |
383 // immediately. | 385 // immediately. |
384 if (!layer()->GetAnimator()->is_animating()) | 386 if (!layer()->GetAnimator()->is_animating()) |
385 OnHostResized(host_->GetSize()); | 387 OnHostResized(host_->GetSize()); |
386 } | 388 } |
387 | 389 |
388 #if !defined(NDEBUG) | 390 #if !defined(NDEBUG) |
389 void Desktop::ToggleFullScreen() { | 391 void RootWindow::ToggleFullScreen() { |
390 host_->ToggleFullScreen(); | 392 host_->ToggleFullScreen(); |
391 } | 393 } |
392 #endif | 394 #endif |
393 | 395 |
394 //////////////////////////////////////////////////////////////////////////////// | 396 //////////////////////////////////////////////////////////////////////////////// |
395 // Desktop, private: | 397 // RootWindow, private: |
396 | 398 |
397 Desktop::Desktop() | 399 RootWindow::RootWindow() |
398 : Window(NULL), | 400 : Window(NULL), |
399 host_(aura::DesktopHost::Create(GetInitialHostWindowBounds())), | 401 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), |
400 ALLOW_THIS_IN_INITIALIZER_LIST( | 402 ALLOW_THIS_IN_INITIALIZER_LIST( |
401 stacking_client_(new DefaultStackingClient(this))), | 403 stacking_client_(new DefaultStackingClient(this))), |
402 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 404 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
403 active_window_(NULL), | 405 active_window_(NULL), |
404 mouse_button_flags_(0), | 406 mouse_button_flags_(0), |
405 last_cursor_(kCursorNull), | 407 last_cursor_(kCursorNull), |
406 in_destructor_(false), | 408 in_destructor_(false), |
407 screen_(new ScreenAura), | 409 screen_(new ScreenAura), |
408 capture_window_(NULL), | 410 capture_window_(NULL), |
409 mouse_pressed_handler_(NULL), | 411 mouse_pressed_handler_(NULL), |
410 mouse_moved_handler_(NULL), | 412 mouse_moved_handler_(NULL), |
411 focused_window_(NULL), | 413 focused_window_(NULL), |
412 touch_event_handler_(NULL) { | 414 touch_event_handler_(NULL) { |
413 SetName("RootWindow"); | 415 SetName("RootWindow"); |
414 gfx::Screen::SetInstance(screen_); | 416 gfx::Screen::SetInstance(screen_); |
415 host_->SetDesktop(this); | 417 host_->SetRootWindow(this); |
416 last_mouse_location_ = host_->QueryMouseLocation(); | 418 last_mouse_location_ = host_->QueryMouseLocation(); |
417 | 419 |
418 if (ui::Compositor::compositor_factory()) { | 420 if (ui::Compositor::compositor_factory()) { |
419 compositor_ = (*ui::Compositor::compositor_factory())(this); | 421 compositor_ = (*ui::Compositor::compositor_factory())(this); |
420 } else { | 422 } else { |
421 #ifdef USE_WEBKIT_COMPOSITOR | 423 #ifdef USE_WEBKIT_COMPOSITOR |
422 ui::CompositorCC::Initialize(false); | 424 ui::CompositorCC::Initialize(false); |
423 #endif | 425 #endif |
424 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), | 426 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), |
425 host_->GetSize()); | 427 host_->GetSize()); |
426 } | 428 } |
427 DCHECK(compositor_.get()); | 429 DCHECK(compositor_.get()); |
428 } | 430 } |
429 | 431 |
430 Desktop::~Desktop() { | 432 RootWindow::~RootWindow() { |
431 in_destructor_ = true; | 433 in_destructor_ = true; |
432 // Make sure to destroy the compositor before terminating so that state is | 434 // Make sure to destroy the compositor before terminating so that state is |
433 // cleared and we don't hit asserts. | 435 // cleared and we don't hit asserts. |
434 compositor_ = NULL; | 436 compositor_ = NULL; |
435 #ifdef USE_WEBKIT_COMPOSITOR | 437 #ifdef USE_WEBKIT_COMPOSITOR |
436 if (!ui::Compositor::compositor_factory()) | 438 if (!ui::Compositor::compositor_factory()) |
437 ui::CompositorCC::Terminate(); | 439 ui::CompositorCC::Terminate(); |
438 #endif | 440 #endif |
439 if (instance_ == this) | 441 if (instance_ == this) |
440 instance_ = NULL; | 442 instance_ = NULL; |
441 } | 443 } |
442 | 444 |
443 void Desktop::HandleMouseMoved(const MouseEvent& event, Window* target) { | 445 void RootWindow::HandleMouseMoved(const MouseEvent& event, Window* target) { |
444 if (target == mouse_moved_handler_) | 446 if (target == mouse_moved_handler_) |
445 return; | 447 return; |
446 | 448 |
447 // Send an exited event. | 449 // Send an exited event. |
448 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { | 450 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { |
449 MouseEvent translated_event(event, this, mouse_moved_handler_, | 451 MouseEvent translated_event(event, this, mouse_moved_handler_, |
450 ui::ET_MOUSE_EXITED, event.flags()); | 452 ui::ET_MOUSE_EXITED, event.flags()); |
451 ProcessMouseEvent(mouse_moved_handler_, &translated_event); | 453 ProcessMouseEvent(mouse_moved_handler_, &translated_event); |
452 } | 454 } |
453 mouse_moved_handler_ = target; | 455 mouse_moved_handler_ = target; |
454 // Send an entered event. | 456 // Send an entered event. |
455 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { | 457 if (mouse_moved_handler_ && mouse_moved_handler_->delegate()) { |
456 MouseEvent translated_event(event, this, mouse_moved_handler_, | 458 MouseEvent translated_event(event, this, mouse_moved_handler_, |
457 ui::ET_MOUSE_ENTERED, event.flags()); | 459 ui::ET_MOUSE_ENTERED, event.flags()); |
458 ProcessMouseEvent(mouse_moved_handler_, &translated_event); | 460 ProcessMouseEvent(mouse_moved_handler_, &translated_event); |
459 } | 461 } |
460 } | 462 } |
461 | 463 |
462 bool Desktop::ProcessMouseEvent(Window* target, MouseEvent* event) { | 464 bool RootWindow::ProcessMouseEvent(Window* target, MouseEvent* event) { |
463 if (!target->IsVisible()) | 465 if (!target->IsVisible()) |
464 return false; | 466 return false; |
465 | 467 |
466 EventFilters filters; | 468 EventFilters filters; |
467 GetEventFiltersToNotify(target, &filters); | 469 GetEventFiltersToNotify(target, &filters); |
468 for (EventFilters::const_reverse_iterator it = filters.rbegin(); | 470 for (EventFilters::const_reverse_iterator it = filters.rbegin(); |
469 it != filters.rend(); ++it) { | 471 it != filters.rend(); ++it) { |
470 if ((*it)->PreHandleMouseEvent(target, event)) | 472 if ((*it)->PreHandleMouseEvent(target, event)) |
471 return true; | 473 return true; |
472 } | 474 } |
473 | 475 |
474 return target->delegate()->OnMouseEvent(event); | 476 return target->delegate()->OnMouseEvent(event); |
475 } | 477 } |
476 | 478 |
477 bool Desktop::ProcessKeyEvent(Window* target, KeyEvent* event) { | 479 bool RootWindow::ProcessKeyEvent(Window* target, KeyEvent* event) { |
478 if (!target->IsVisible()) | 480 if (!target->IsVisible()) |
479 return false; | 481 return false; |
480 | 482 |
481 EventFilters filters; | 483 EventFilters filters; |
482 GetEventFiltersToNotify(target, &filters); | 484 GetEventFiltersToNotify(target, &filters); |
483 for (EventFilters::const_reverse_iterator it = filters.rbegin(); | 485 for (EventFilters::const_reverse_iterator it = filters.rbegin(); |
484 it != filters.rend(); ++it) { | 486 it != filters.rend(); ++it) { |
485 if ((*it)->PreHandleKeyEvent(target, event)) | 487 if ((*it)->PreHandleKeyEvent(target, event)) |
486 return true; | 488 return true; |
487 } | 489 } |
488 | 490 |
489 return target->delegate()->OnKeyEvent(event); | 491 return target->delegate()->OnKeyEvent(event); |
490 } | 492 } |
491 | 493 |
492 ui::TouchStatus Desktop::ProcessTouchEvent(Window* target, TouchEvent* event) { | 494 ui::TouchStatus RootWindow::ProcessTouchEvent(Window* target, |
| 495 TouchEvent* event) { |
493 if (!target->IsVisible()) | 496 if (!target->IsVisible()) |
494 return ui::TOUCH_STATUS_UNKNOWN; | 497 return ui::TOUCH_STATUS_UNKNOWN; |
495 | 498 |
496 EventFilters filters; | 499 EventFilters filters; |
497 GetEventFiltersToNotify(target, &filters); | 500 GetEventFiltersToNotify(target, &filters); |
498 for (EventFilters::const_reverse_iterator it = filters.rbegin(); | 501 for (EventFilters::const_reverse_iterator it = filters.rbegin(); |
499 it != filters.rend(); ++it) { | 502 it != filters.rend(); ++it) { |
500 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event); | 503 ui::TouchStatus status = (*it)->PreHandleTouchEvent(target, event); |
501 if (status != ui::TOUCH_STATUS_UNKNOWN) | 504 if (status != ui::TOUCH_STATUS_UNKNOWN) |
502 return status; | 505 return status; |
503 } | 506 } |
504 | 507 |
505 return target->delegate()->OnTouchEvent(event); | 508 return target->delegate()->OnTouchEvent(event); |
506 } | 509 } |
507 | 510 |
508 void Desktop::ScheduleDraw() { | 511 void RootWindow::ScheduleDraw() { |
509 if (!schedule_paint_factory_.HasWeakPtrs()) { | 512 if (!schedule_paint_factory_.HasWeakPtrs()) { |
510 MessageLoop::current()->PostTask( | 513 MessageLoop::current()->PostTask( |
511 FROM_HERE, | 514 FROM_HERE, |
512 base::Bind(&Desktop::Draw, schedule_paint_factory_.GetWeakPtr())); | 515 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); |
513 } | 516 } |
514 } | 517 } |
515 | 518 |
516 bool Desktop::CanFocus() const { | 519 bool RootWindow::CanFocus() const { |
517 return IsVisible(); | 520 return IsVisible(); |
518 } | 521 } |
519 | 522 |
520 internal::FocusManager* Desktop::GetFocusManager() { | 523 internal::FocusManager* RootWindow::GetFocusManager() { |
521 return this; | 524 return this; |
522 } | 525 } |
523 | 526 |
524 Desktop* Desktop::GetDesktop() { | 527 RootWindow* RootWindow::GetRootWindow() { |
525 return this; | 528 return this; |
526 } | 529 } |
527 | 530 |
528 void Desktop::WindowDetachedFromDesktop(Window* detached) { | 531 void RootWindow::WindowDetachedFromRootWindow(Window* detached) { |
529 DCHECK(capture_window_ != this); | 532 DCHECK(capture_window_ != this); |
530 | 533 |
531 // If the ancestor of the capture window is detached, | 534 // If the ancestor of the capture window is detached, |
532 // release the capture. | 535 // release the capture. |
533 if (detached->Contains(capture_window_) && detached != this) | 536 if (detached->Contains(capture_window_) && detached != this) |
534 ReleaseCapture(capture_window_); | 537 ReleaseCapture(capture_window_); |
535 | 538 |
536 // If the ancestor of the focused window is detached, | 539 // If the ancestor of the focused window is detached, |
537 // release the focus. | 540 // release the focus. |
538 if (detached->Contains(focused_window_)) | 541 if (detached->Contains(focused_window_)) |
539 SetFocusedWindow(NULL); | 542 SetFocusedWindow(NULL); |
540 | 543 |
541 // If the ancestor of any event handler windows are detached, release the | 544 // If the ancestor of any event handler windows are detached, release the |
542 // pointer to those windows. | 545 // pointer to those windows. |
543 if (detached->Contains(mouse_pressed_handler_)) | 546 if (detached->Contains(mouse_pressed_handler_)) |
544 mouse_pressed_handler_ = NULL; | 547 mouse_pressed_handler_ = NULL; |
545 if (detached->Contains(mouse_moved_handler_)) | 548 if (detached->Contains(mouse_moved_handler_)) |
546 mouse_moved_handler_ = NULL; | 549 mouse_moved_handler_ = NULL; |
547 if (detached->Contains(touch_event_handler_)) | 550 if (detached->Contains(touch_event_handler_)) |
548 touch_event_handler_ = NULL; | 551 touch_event_handler_ = NULL; |
549 } | 552 } |
550 | 553 |
551 void Desktop::OnLayerAnimationEnded( | 554 void RootWindow::OnLayerAnimationEnded( |
552 const ui::LayerAnimationSequence* animation) { | 555 const ui::LayerAnimationSequence* animation) { |
553 OnHostResized(host_->GetSize()); | 556 OnHostResized(host_->GetSize()); |
554 } | 557 } |
555 | 558 |
556 void Desktop::OnLayerAnimationScheduled( | 559 void RootWindow::OnLayerAnimationScheduled( |
557 const ui::LayerAnimationSequence* animation) { | 560 const ui::LayerAnimationSequence* animation) { |
558 } | 561 } |
559 | 562 |
560 void Desktop::OnLayerAnimationAborted( | 563 void RootWindow::OnLayerAnimationAborted( |
561 const ui::LayerAnimationSequence* animation) { | 564 const ui::LayerAnimationSequence* animation) { |
562 } | 565 } |
563 | 566 |
564 void Desktop::SetFocusedWindow(Window* focused_window) { | 567 void RootWindow::SetFocusedWindow(Window* focused_window) { |
565 if (focused_window == focused_window_ || | 568 if (focused_window == focused_window_ || |
566 (focused_window && !focused_window->CanFocus())) { | 569 (focused_window && !focused_window->CanFocus())) { |
567 return; | 570 return; |
568 } | 571 } |
569 if (focused_window_ && focused_window_->delegate()) | 572 if (focused_window_ && focused_window_->delegate()) |
570 focused_window_->delegate()->OnBlur(); | 573 focused_window_->delegate()->OnBlur(); |
571 focused_window_ = focused_window; | 574 focused_window_ = focused_window; |
572 if (focused_window_ && focused_window_->delegate()) | 575 if (focused_window_ && focused_window_->delegate()) |
573 focused_window_->delegate()->OnFocus(); | 576 focused_window_->delegate()->OnFocus(); |
574 } | 577 } |
575 | 578 |
576 Window* Desktop::GetFocusedWindow() { | 579 Window* RootWindow::GetFocusedWindow() { |
577 return focused_window_; | 580 return focused_window_; |
578 } | 581 } |
579 | 582 |
580 bool Desktop::IsFocusedWindow(const Window* window) const { | 583 bool RootWindow::IsFocusedWindow(const Window* window) const { |
581 return focused_window_ == window; | 584 return focused_window_ == window; |
582 } | 585 } |
583 | 586 |
584 void Desktop::Init() { | 587 void RootWindow::Init() { |
585 Window::Init(ui::Layer::LAYER_HAS_NO_TEXTURE); | 588 Window::Init(ui::Layer::LAYER_HAS_NO_TEXTURE); |
586 SetBounds(gfx::Rect(host_->GetSize())); | 589 SetBounds(gfx::Rect(host_->GetSize())); |
587 Show(); | 590 Show(); |
588 compositor()->SetRootLayer(layer()); | 591 compositor()->SetRootLayer(layer()); |
589 } | 592 } |
590 | 593 |
591 gfx::Rect Desktop::GetInitialHostWindowBounds() const { | 594 gfx::Rect RootWindow::GetInitialHostWindowBounds() const { |
592 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, | 595 gfx::Rect bounds(kDefaultHostWindowX, kDefaultHostWindowY, |
593 kDefaultHostWindowWidth, kDefaultHostWindowHeight); | 596 kDefaultHostWindowWidth, kDefaultHostWindowHeight); |
594 | 597 |
595 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 598 const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
596 switches::kAuraHostWindowSize); | 599 switches::kAuraHostWindowSize); |
597 vector<string> parts; | 600 vector<string> parts; |
598 base::SplitString(size_str, 'x', &parts); | 601 base::SplitString(size_str, 'x', &parts); |
599 int parsed_width = 0, parsed_height = 0; | 602 int parsed_width = 0, parsed_height = 0; |
600 if (parts.size() == 2 && | 603 if (parts.size() == 2 && |
601 base::StringToInt(parts[0], &parsed_width) && parsed_width > 0 && | 604 base::StringToInt(parts[0], &parsed_width) && parsed_width > 0 && |
602 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 605 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
603 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 606 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
604 } else if (use_fullscreen_host_window_) { | 607 } else if (use_fullscreen_host_window_) { |
605 bounds = gfx::Rect(DesktopHost::GetNativeScreenSize()); | 608 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); |
606 } | 609 } |
607 | 610 |
608 return bounds; | 611 return bounds; |
609 } | 612 } |
610 | 613 |
611 } // namespace aura | 614 } // namespace aura |
OLD | NEW |