| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 typedef std::vector<EventFilter*> EventFilters; | 47 typedef std::vector<EventFilter*> EventFilters; |
| 48 | 48 |
| 49 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { | 49 void GetEventFiltersToNotify(Window* target, EventFilters* filters) { |
| 50 while (target) { | 50 while (target) { |
| 51 if (target->event_filter()) | 51 if (target->event_filter()) |
| 52 filters->push_back(target->event_filter()); | 52 filters->push_back(target->event_filter()); |
| 53 target = target->parent(); | 53 target = target->parent(); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 const int kCompositorLockTimeoutMs = 67; |
| 58 |
| 57 } // namespace | 59 } // namespace |
| 58 | 60 |
| 61 CompositorLock::CompositorLock(RootWindow* root_window) |
| 62 : root_window_(root_window) { |
| 63 MessageLoop::current()->PostDelayedTask( |
| 64 FROM_HERE, |
| 65 base::Bind(&CompositorLock::CancelLock, AsWeakPtr()), |
| 66 kCompositorLockTimeoutMs); |
| 67 } |
| 68 |
| 69 CompositorLock::~CompositorLock() { |
| 70 CancelLock(); |
| 71 } |
| 72 |
| 73 void CompositorLock::CancelLock() { |
| 74 if (!root_window_) |
| 75 return; |
| 76 root_window_->UnlockCompositor(); |
| 77 root_window_ = NULL; |
| 78 } |
| 79 |
| 59 bool RootWindow::hide_host_cursor_ = false; | 80 bool RootWindow::hide_host_cursor_ = false; |
| 60 | 81 |
| 61 //////////////////////////////////////////////////////////////////////////////// | 82 //////////////////////////////////////////////////////////////////////////////// |
| 62 // RootWindow, public: | 83 // RootWindow, public: |
| 63 | 84 |
| 64 RootWindow::RootWindow(const gfx::Rect& initial_bounds) | 85 RootWindow::RootWindow(const gfx::Rect& initial_bounds) |
| 65 : Window(NULL), | 86 : Window(NULL), |
| 66 host_(aura::RootWindowHost::Create(initial_bounds)), | 87 host_(aura::RootWindowHost::Create(initial_bounds)), |
| 67 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), | 88 ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)), |
| 68 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), | 89 ALLOW_THIS_IN_INITIALIZER_LIST(event_factory_(this)), |
| 69 mouse_button_flags_(0), | 90 mouse_button_flags_(0), |
| 70 last_cursor_(kCursorNull), | 91 last_cursor_(kCursorNull), |
| 71 cursor_shown_(true), | 92 cursor_shown_(true), |
| 72 capture_window_(NULL), | 93 capture_window_(NULL), |
| 73 mouse_pressed_handler_(NULL), | 94 mouse_pressed_handler_(NULL), |
| 74 mouse_moved_handler_(NULL), | 95 mouse_moved_handler_(NULL), |
| 75 focused_window_(NULL), | 96 focused_window_(NULL), |
| 76 ALLOW_THIS_IN_INITIALIZER_LIST( | 97 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 77 gesture_recognizer_(GestureRecognizer::Create())), | 98 gesture_recognizer_(GestureRecognizer::Create())), |
| 78 synthesize_mouse_move_(false), | 99 synthesize_mouse_move_(false), |
| 79 waiting_on_compositing_end_(false), | 100 waiting_on_compositing_end_(false), |
| 80 draw_on_compositing_end_(false), | 101 draw_on_compositing_end_(false), |
| 81 defer_draw_scheduling_(false), | 102 defer_draw_scheduling_(false), |
| 82 mouse_move_hold_count_(0), | 103 mouse_move_hold_count_(0), |
| 83 should_hold_mouse_moves_(false) { | 104 should_hold_mouse_moves_(false), |
| 105 compositor_lock_(NULL), |
| 106 draw_on_compositor_unlock_(false) { |
| 84 SetName("RootWindow"); | 107 SetName("RootWindow"); |
| 85 last_mouse_location_ = host_->QueryMouseLocation(); | 108 last_mouse_location_ = host_->QueryMouseLocation(); |
| 86 | 109 |
| 87 should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( | 110 should_hold_mouse_moves_ = !CommandLine::ForCurrentProcess()->HasSwitch( |
| 88 switches::kAuraDisableHoldMouseMoves); | 111 switches::kAuraDisableHoldMouseMoves); |
| 89 | 112 |
| 90 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), | 113 compositor_.reset(new ui::Compositor(this, host_->GetAcceleratedWidget(), |
| 91 host_->GetBounds().size())); | 114 host_->GetBounds().size())); |
| 92 DCHECK(compositor_.get()); | 115 DCHECK(compositor_.get()); |
| 93 compositor_->AddObserver(this); | 116 compositor_->AddObserver(this); |
| 94 Init(); | 117 Init(); |
| 95 } | 118 } |
| 96 | 119 |
| 97 RootWindow::~RootWindow() { | 120 RootWindow::~RootWindow() { |
| 121 if (compositor_lock_) { |
| 122 // No need to schedule a draw, we're going away. |
| 123 draw_on_compositor_unlock_ = false; |
| 124 compositor_lock_->CancelLock(); |
| 125 DCHECK(!compositor_lock_); |
| 126 } |
| 98 compositor_->RemoveObserver(this); | 127 compositor_->RemoveObserver(this); |
| 99 // Make sure to destroy the compositor before terminating so that state is | 128 // Make sure to destroy the compositor before terminating so that state is |
| 100 // cleared and we don't hit asserts. | 129 // cleared and we don't hit asserts. |
| 101 compositor_.reset(); | 130 compositor_.reset(); |
| 102 | 131 |
| 103 // Tear down in reverse. Frees any references held by the host. | 132 // Tear down in reverse. Frees any references held by the host. |
| 104 host_.reset(NULL); | 133 host_.reset(NULL); |
| 105 | 134 |
| 106 // An observer may have been added by an animation on the RootWindow. | 135 // An observer may have been added by an animation on the RootWindow. |
| 107 layer()->GetAnimator()->RemoveObserver(this); | 136 layer()->GetAnimator()->RemoveObserver(this); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 // being used in fullscreen mode, so root_window bounds = window bounds. | 185 // being used in fullscreen mode, so root_window bounds = window bounds. |
| 157 return host_->ConfineCursorToRootWindow(); | 186 return host_->ConfineCursorToRootWindow(); |
| 158 } | 187 } |
| 159 | 188 |
| 160 void RootWindow::Draw() { | 189 void RootWindow::Draw() { |
| 161 if (waiting_on_compositing_end_) { | 190 if (waiting_on_compositing_end_) { |
| 162 draw_on_compositing_end_ = true; | 191 draw_on_compositing_end_ = true; |
| 163 defer_draw_scheduling_ = false; | 192 defer_draw_scheduling_ = false; |
| 164 return; | 193 return; |
| 165 } | 194 } |
| 195 if (compositor_lock_) { |
| 196 draw_on_compositor_unlock_ = true; |
| 197 defer_draw_scheduling_ = false; |
| 198 return; |
| 199 } |
| 166 waiting_on_compositing_end_ = true; | 200 waiting_on_compositing_end_ = true; |
| 167 | 201 |
| 168 compositor_->Draw(false); | 202 compositor_->Draw(false); |
| 169 defer_draw_scheduling_ = false; | 203 defer_draw_scheduling_ = false; |
| 170 } | 204 } |
| 171 | 205 |
| 172 void RootWindow::ScheduleFullDraw() { | 206 void RootWindow::ScheduleFullDraw() { |
| 173 compositor_->ScheduleFullDraw(); | 207 compositor_->ScheduleFullDraw(); |
| 174 } | 208 } |
| 175 | 209 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 427 |
| 394 void RootWindow::ReleaseMouseMoves() { | 428 void RootWindow::ReleaseMouseMoves() { |
| 395 if (should_hold_mouse_moves_) { | 429 if (should_hold_mouse_moves_) { |
| 396 --mouse_move_hold_count_; | 430 --mouse_move_hold_count_; |
| 397 DCHECK_GE(mouse_move_hold_count_, 0); | 431 DCHECK_GE(mouse_move_hold_count_, 0); |
| 398 if (!mouse_move_hold_count_) | 432 if (!mouse_move_hold_count_) |
| 399 DispatchHeldMouseMove(); | 433 DispatchHeldMouseMove(); |
| 400 } | 434 } |
| 401 } | 435 } |
| 402 | 436 |
| 437 scoped_refptr<CompositorLock> RootWindow::GetCompositorLock() { |
| 438 if (!compositor_lock_) |
| 439 compositor_lock_ = new CompositorLock(this); |
| 440 return compositor_lock_; |
| 441 } |
| 442 |
| 403 void RootWindow::SetFocusWhenShown(bool focused) { | 443 void RootWindow::SetFocusWhenShown(bool focused) { |
| 404 host_->SetFocusWhenShown(focused); | 444 host_->SetFocusWhenShown(focused); |
| 405 } | 445 } |
| 406 | 446 |
| 407 //////////////////////////////////////////////////////////////////////////////// | 447 //////////////////////////////////////////////////////////////////////////////// |
| 408 // RootWindow, Window overrides: | 448 // RootWindow, Window overrides: |
| 409 | 449 |
| 410 RootWindow* RootWindow::GetRootWindow() { | 450 RootWindow* RootWindow::GetRootWindow() { |
| 411 return this; | 451 return this; |
| 412 } | 452 } |
| 413 | 453 |
| 414 const RootWindow* RootWindow::GetRootWindow() const { | 454 const RootWindow* RootWindow::GetRootWindow() const { |
| 415 return this; | 455 return this; |
| 416 } | 456 } |
| 417 | 457 |
| 418 void RootWindow::SetTransform(const ui::Transform& transform) { | 458 void RootWindow::SetTransform(const ui::Transform& transform) { |
| 419 Window::SetTransform(transform); | 459 Window::SetTransform(transform); |
| 420 | 460 |
| 421 // If the layer is not animating, then we need to update the host size | 461 // If the layer is not animating, then we need to update the host size |
| 422 // immediately. | 462 // immediately. |
| 423 if (!layer()->GetAnimator()->is_animating()) | 463 if (!layer()->GetAnimator()->is_animating()) |
| 424 OnHostResized(host_->GetBounds().size()); | 464 OnHostResized(host_->GetBounds().size()); |
| 425 } | 465 } |
| 426 | 466 |
| 427 //////////////////////////////////////////////////////////////////////////////// | 467 //////////////////////////////////////////////////////////////////////////////// |
| 428 // RootWindow, ui::CompositorDelegate implementation: | 468 // RootWindow, ui::CompositorDelegate implementation: |
| 429 | 469 |
| 430 void RootWindow::ScheduleDraw() { | 470 void RootWindow::ScheduleDraw() { |
| 431 if (!defer_draw_scheduling_) { | 471 if (compositor_lock_) { |
| 472 draw_on_compositor_unlock_ = true; |
| 473 } else if (!defer_draw_scheduling_) { |
| 432 defer_draw_scheduling_ = true; | 474 defer_draw_scheduling_ = true; |
| 433 MessageLoop::current()->PostTask( | 475 MessageLoop::current()->PostTask( |
| 434 FROM_HERE, | 476 FROM_HERE, |
| 435 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); | 477 base::Bind(&RootWindow::Draw, schedule_paint_factory_.GetWeakPtr())); |
| 436 } | 478 } |
| 437 } | 479 } |
| 438 | 480 |
| 439 //////////////////////////////////////////////////////////////////////////////// | 481 //////////////////////////////////////////////////////////////////////////////// |
| 440 // RootWindow, ui::CompositorObserver implementation: | 482 // RootWindow, ui::CompositorObserver implementation: |
| 441 | 483 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's | 860 // TODO(derat|oshima): Don't use mouse_button_flags_ as it's |
| 819 // is currently broken. See/ crbug.com/107931. | 861 // is currently broken. See/ crbug.com/107931. |
| 820 MouseEvent event(ui::ET_MOUSE_MOVED, | 862 MouseEvent event(ui::ET_MOUSE_MOVED, |
| 821 orig_mouse_location, | 863 orig_mouse_location, |
| 822 orig_mouse_location, | 864 orig_mouse_location, |
| 823 ui::EF_IS_SYNTHESIZED); | 865 ui::EF_IS_SYNTHESIZED); |
| 824 DispatchMouseEvent(&event); | 866 DispatchMouseEvent(&event); |
| 825 #endif | 867 #endif |
| 826 } | 868 } |
| 827 | 869 |
| 870 void RootWindow::UnlockCompositor() { |
| 871 DCHECK(compositor_lock_); |
| 872 compositor_lock_ = NULL; |
| 873 if (draw_on_compositor_unlock_) { |
| 874 draw_on_compositor_unlock_ = false; |
| 875 ScheduleDraw(); |
| 876 } |
| 877 } |
| 878 |
| 828 } // namespace aura | 879 } // namespace aura |
| OLD | NEW |