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/root_window.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/activation_client.h" | |
18 #include "ui/aura/client/drag_drop_client.h" | 17 #include "ui/aura/client/drag_drop_client.h" |
19 #include "ui/aura/client/stacking_client.h" | 18 #include "ui/aura/client/stacking_client.h" |
20 #include "ui/aura/client/tooltip_client.h" | 19 #include "ui/aura/client/tooltip_client.h" |
21 #include "ui/aura/client/window_drag_drop_delegate.h" | 20 #include "ui/aura/client/window_drag_drop_delegate.h" |
22 #include "ui/aura/root_window_host.h" | 21 #include "ui/aura/root_window_host.h" |
23 #include "ui/aura/root_window_observer.h" | 22 #include "ui/aura/root_window_observer.h" |
24 #include "ui/aura/event.h" | 23 #include "ui/aura/event.h" |
25 #include "ui/aura/event_filter.h" | 24 #include "ui/aura/event_filter.h" |
26 #include "ui/aura/focus_manager.h" | 25 #include "ui/aura/focus_manager.h" |
27 #include "ui/aura/screen_aura.h" | 26 #include "ui/aura/screen_aura.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 explicit DefaultStackingClient(RootWindow* root_window) | 62 explicit DefaultStackingClient(RootWindow* root_window) |
64 : root_window_(root_window) {} | 63 : root_window_(root_window) {} |
65 virtual ~DefaultStackingClient() {} | 64 virtual ~DefaultStackingClient() {} |
66 | 65 |
67 private: | 66 private: |
68 | 67 |
69 // Overridden from StackingClient: | 68 // Overridden from StackingClient: |
70 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { | 69 virtual void AddChildToDefaultParent(Window* window) OVERRIDE { |
71 root_window_->AddChild(window); | 70 root_window_->AddChild(window); |
72 } | 71 } |
| 72 virtual bool CanActivateWindow(Window* window) const OVERRIDE { |
| 73 return window->parent() == root_window_; |
| 74 } |
| 75 virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE { |
| 76 Window::Windows::const_reverse_iterator i; |
| 77 for (i = root_window_->children().rbegin(); |
| 78 i != root_window_->children().rend(); |
| 79 ++i) { |
| 80 if (*i == ignore) |
| 81 continue; |
| 82 return *i; |
| 83 } |
| 84 return NULL; |
| 85 } |
73 | 86 |
74 RootWindow* root_window_; | 87 RootWindow* root_window_; |
75 | 88 |
76 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); | 89 DISALLOW_COPY_AND_ASSIGN(DefaultStackingClient); |
77 }; | 90 }; |
78 | 91 |
79 typedef std::vector<EventFilter*> EventFilters; | 92 typedef std::vector<EventFilter*> EventFilters; |
80 | 93 |
81 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 94 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
82 Window* window = target->parent(); | 95 Window* window = target->parent(); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 SetBounds(gfx::Rect(bounds.size())); | 240 SetBounds(gfx::Rect(bounds.size())); |
228 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | 241 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
229 OnRootWindowResized(bounds.size())); | 242 OnRootWindowResized(bounds.size())); |
230 } | 243 } |
231 | 244 |
232 void RootWindow::OnNativeScreenResized(const gfx::Size& size) { | 245 void RootWindow::OnNativeScreenResized(const gfx::Size& size) { |
233 if (use_fullscreen_host_window_) | 246 if (use_fullscreen_host_window_) |
234 SetHostSize(size); | 247 SetHostSize(size); |
235 } | 248 } |
236 | 249 |
| 250 void RootWindow::SetActiveWindow(Window* window, Window* to_focus) { |
| 251 if (!window) |
| 252 return; |
| 253 // The stacking client may impose rules on what window configurations can be |
| 254 // activated or deactivated. |
| 255 if (!stacking_client_->CanActivateWindow(window)) |
| 256 return; |
| 257 // The window may not be activate-able. |
| 258 if (!window->CanActivate()) |
| 259 return; |
| 260 // Nothing may actually have changed. |
| 261 if (active_window_ == window) |
| 262 return; |
| 263 |
| 264 Window* old_active = active_window_; |
| 265 active_window_ = window; |
| 266 // Invoke OnLostActive after we've changed the active window. That way if the |
| 267 // delegate queries for active state it doesn't think the window is still |
| 268 // active. |
| 269 if (old_active && old_active->delegate()) |
| 270 old_active->delegate()->OnLostActive(); |
| 271 if (active_window_) { |
| 272 active_window_->parent()->StackChildAtTop(active_window_); |
| 273 if (active_window_->delegate()) |
| 274 active_window_->delegate()->OnActivated(); |
| 275 active_window_->GetFocusManager()->SetFocusedWindow( |
| 276 to_focus ? to_focus : active_window_); |
| 277 } |
| 278 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
| 279 OnActiveWindowChanged(active_window_)); |
| 280 } |
| 281 |
| 282 void RootWindow::ActivateTopmostWindow() { |
| 283 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(NULL), NULL); |
| 284 } |
| 285 |
| 286 void RootWindow::Deactivate(Window* window) { |
| 287 // The stacking client may impose rules on what window configurations can be |
| 288 // activated or deactivated. |
| 289 if (!window || !stacking_client_->CanActivateWindow(window)) |
| 290 return; |
| 291 if (active_window_ != window) |
| 292 return; |
| 293 |
| 294 Window* to_activate = stacking_client_->GetTopmostWindowToActivate(window); |
| 295 if (to_activate) |
| 296 SetActiveWindow(to_activate, NULL); |
| 297 } |
| 298 |
237 void RootWindow::WindowInitialized(Window* window) { | 299 void RootWindow::WindowInitialized(Window* window) { |
238 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | 300 FOR_EACH_OBSERVER(RootWindowObserver, observers_, |
239 OnWindowInitialized(window)); | 301 OnWindowInitialized(window)); |
240 } | 302 } |
241 | 303 |
242 void RootWindow::WindowDestroying(Window* window) { | 304 void RootWindow::WindowDestroying(Window* window) { |
243 // Update the focused window state if the window was focused. | 305 // Update the focused window state if the window was focused. |
244 if (focused_window_ == window) | 306 if (focused_window_ == window) |
245 SetFocusedWindow(NULL); | 307 SetFocusedWindow(NULL); |
246 | 308 |
247 // When a window is being destroyed it's likely that the WindowDelegate won't | 309 // When a window is being destroyed it's likely that the WindowDelegate won't |
248 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and | 310 // want events, so we reset the mouse_pressed_handler_ and capture_window_ and |
249 // don't sent it release/capture lost events. | 311 // don't sent it release/capture lost events. |
250 if (mouse_pressed_handler_ == window) | 312 if (mouse_pressed_handler_ == window) |
251 mouse_pressed_handler_ = NULL; | 313 mouse_pressed_handler_ = NULL; |
252 if (mouse_moved_handler_ == window) | 314 if (mouse_moved_handler_ == window) |
253 mouse_moved_handler_ = NULL; | 315 mouse_moved_handler_ = NULL; |
254 if (capture_window_ == window) | 316 if (capture_window_ == window) |
255 capture_window_ = NULL; | 317 capture_window_ = NULL; |
256 if (touch_event_handler_ == window) | 318 if (touch_event_handler_ == window) |
257 touch_event_handler_ = NULL; | 319 touch_event_handler_ = NULL; |
| 320 |
| 321 if (in_destructor_ || window != active_window_) |
| 322 return; |
| 323 |
| 324 // Reset active_window_ before invoking SetActiveWindow so that we don't |
| 325 // attempt to notify it while running its destructor. |
| 326 active_window_ = NULL; |
| 327 SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(window), NULL); |
258 } | 328 } |
259 | 329 |
260 MessageLoop::Dispatcher* RootWindow::GetDispatcher() { | 330 MessageLoop::Dispatcher* RootWindow::GetDispatcher() { |
261 return host_.get(); | 331 return host_.get(); |
262 } | 332 } |
263 | 333 |
264 void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) { | 334 void RootWindow::AddObserver(RootWindowObserver* observer) { |
265 observers_.AddObserver(observer); | 335 observers_.AddObserver(observer); |
266 } | 336 } |
267 | 337 |
268 void RootWindow::RemoveRootWindowObserver(RootWindowObserver* observer) { | 338 void RootWindow::RemoveObserver(RootWindowObserver* observer) { |
269 observers_.RemoveObserver(observer); | 339 observers_.RemoveObserver(observer); |
270 } | 340 } |
271 | 341 |
272 bool RootWindow::IsMouseButtonDown() const { | 342 bool RootWindow::IsMouseButtonDown() const { |
273 return mouse_button_flags_ != 0; | 343 return mouse_button_flags_ != 0; |
274 } | 344 } |
275 | 345 |
276 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { | 346 void RootWindow::PostNativeEvent(const base::NativeEvent& native_event) { |
277 host_->PostNativeEvent(native_event); | 347 host_->PostNativeEvent(native_event); |
278 } | 348 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 399 |
330 //////////////////////////////////////////////////////////////////////////////// | 400 //////////////////////////////////////////////////////////////////////////////// |
331 // RootWindow, private: | 401 // RootWindow, private: |
332 | 402 |
333 RootWindow::RootWindow() | 403 RootWindow::RootWindow() |
334 : Window(NULL), | 404 : Window(NULL), |
335 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), | 405 host_(aura::RootWindowHost::Create(GetInitialHostWindowBounds())), |
336 ALLOW_THIS_IN_INITIALIZER_LIST( | 406 ALLOW_THIS_IN_INITIALIZER_LIST( |
337 stacking_client_(new DefaultStackingClient(this))), | 407 stacking_client_(new DefaultStackingClient(this))), |
338 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 408 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 409 active_window_(NULL), |
339 mouse_button_flags_(0), | 410 mouse_button_flags_(0), |
340 last_cursor_(kCursorNull), | 411 last_cursor_(kCursorNull), |
| 412 in_destructor_(false), |
341 screen_(new ScreenAura), | 413 screen_(new ScreenAura), |
342 capture_window_(NULL), | 414 capture_window_(NULL), |
343 mouse_pressed_handler_(NULL), | 415 mouse_pressed_handler_(NULL), |
344 mouse_moved_handler_(NULL), | 416 mouse_moved_handler_(NULL), |
345 focused_window_(NULL), | 417 focused_window_(NULL), |
346 touch_event_handler_(NULL) { | 418 touch_event_handler_(NULL) { |
347 SetName("RootWindow"); | 419 SetName("RootWindow"); |
348 gfx::Screen::SetInstance(screen_); | 420 gfx::Screen::SetInstance(screen_); |
349 host_->SetRootWindow(this); | 421 host_->SetRootWindow(this); |
350 last_mouse_location_ = host_->QueryMouseLocation(); | 422 last_mouse_location_ = host_->QueryMouseLocation(); |
351 | 423 |
352 if (ui::Compositor::compositor_factory()) { | 424 if (ui::Compositor::compositor_factory()) { |
353 compositor_ = (*ui::Compositor::compositor_factory())(this); | 425 compositor_ = (*ui::Compositor::compositor_factory())(this); |
354 } else { | 426 } else { |
355 #ifdef USE_WEBKIT_COMPOSITOR | 427 #ifdef USE_WEBKIT_COMPOSITOR |
356 ui::CompositorCC::Initialize(false); | 428 ui::CompositorCC::Initialize(false); |
357 #endif | 429 #endif |
358 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), | 430 compositor_ = ui::Compositor::Create(this, host_->GetAcceleratedWidget(), |
359 host_->GetSize()); | 431 host_->GetSize()); |
360 } | 432 } |
361 DCHECK(compositor_.get()); | 433 DCHECK(compositor_.get()); |
362 } | 434 } |
363 | 435 |
364 RootWindow::~RootWindow() { | 436 RootWindow::~RootWindow() { |
| 437 in_destructor_ = true; |
365 // Make sure to destroy the compositor before terminating so that state is | 438 // Make sure to destroy the compositor before terminating so that state is |
366 // cleared and we don't hit asserts. | 439 // cleared and we don't hit asserts. |
367 compositor_ = NULL; | 440 compositor_ = NULL; |
368 // An observer may have been added by an animation on the RootWindow. | 441 // An observer may have been added by an animation on the RootWindow. |
369 layer()->GetAnimator()->RemoveObserver(this); | 442 layer()->GetAnimator()->RemoveObserver(this); |
370 #ifdef USE_WEBKIT_COMPOSITOR | 443 #ifdef USE_WEBKIT_COMPOSITOR |
371 if (!ui::Compositor::compositor_factory()) | 444 if (!ui::Compositor::compositor_factory()) |
372 ui::CompositorCC::Terminate(); | 445 ui::CompositorCC::Terminate(); |
373 #endif | 446 #endif |
374 if (instance_ == this) | 447 if (instance_ == this) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 | 564 |
492 void RootWindow::OnLayerAnimationScheduled( | 565 void RootWindow::OnLayerAnimationScheduled( |
493 const ui::LayerAnimationSequence* animation) { | 566 const ui::LayerAnimationSequence* animation) { |
494 } | 567 } |
495 | 568 |
496 void RootWindow::OnLayerAnimationAborted( | 569 void RootWindow::OnLayerAnimationAborted( |
497 const ui::LayerAnimationSequence* animation) { | 570 const ui::LayerAnimationSequence* animation) { |
498 } | 571 } |
499 | 572 |
500 void RootWindow::SetFocusedWindow(Window* focused_window) { | 573 void RootWindow::SetFocusedWindow(Window* focused_window) { |
501 if (focused_window == focused_window_) | 574 if (focused_window == focused_window_ || |
502 return; | 575 (focused_window && !focused_window->CanFocus())) { |
503 if (focused_window && !focused_window->CanFocus()) | |
504 return; | |
505 // The NULL-check of |focused)window| is essential here before asking the | |
506 // activation client, since it is valid to clear the focus by calling | |
507 // SetFocusedWindow() to NULL. | |
508 if (focused_window && ActivationClient::GetActivationClient() && | |
509 !ActivationClient::GetActivationClient()->CanFocusWindow( | |
510 focused_window)) { | |
511 return; | 576 return; |
512 } | 577 } |
513 | |
514 if (focused_window_ && focused_window_->delegate()) | 578 if (focused_window_ && focused_window_->delegate()) |
515 focused_window_->delegate()->OnBlur(); | 579 focused_window_->delegate()->OnBlur(); |
516 focused_window_ = focused_window; | 580 focused_window_ = focused_window; |
517 if (focused_window_ && focused_window_->delegate()) | 581 if (focused_window_ && focused_window_->delegate()) |
518 focused_window_->delegate()->OnFocus(); | 582 focused_window_->delegate()->OnFocus(); |
519 if (focused_window_) { | |
520 FOR_EACH_OBSERVER(RootWindowObserver, observers_, | |
521 OnWindowFocused(focused_window_)); | |
522 } | |
523 } | 583 } |
524 | 584 |
525 Window* RootWindow::GetFocusedWindow() { | 585 Window* RootWindow::GetFocusedWindow() { |
526 return focused_window_; | 586 return focused_window_; |
527 } | 587 } |
528 | 588 |
529 bool RootWindow::IsFocusedWindow(const Window* window) const { | 589 bool RootWindow::IsFocusedWindow(const Window* window) const { |
530 return focused_window_ == window; | 590 return focused_window_ == window; |
531 } | 591 } |
532 | 592 |
(...skipping 18 matching lines...) Expand all Loading... |
551 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { | 611 base::StringToInt(parts[1], &parsed_height) && parsed_height > 0) { |
552 bounds.set_size(gfx::Size(parsed_width, parsed_height)); | 612 bounds.set_size(gfx::Size(parsed_width, parsed_height)); |
553 } else if (use_fullscreen_host_window_) { | 613 } else if (use_fullscreen_host_window_) { |
554 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); | 614 bounds = gfx::Rect(RootWindowHost::GetNativeScreenSize()); |
555 } | 615 } |
556 | 616 |
557 return bounds; | 617 return bounds; |
558 } | 618 } |
559 | 619 |
560 } // namespace aura | 620 } // namespace aura |
OLD | NEW |