OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 DispatchDetails WindowEventDispatcher::DispatchMouseExitAtPoint( | 152 DispatchDetails WindowEventDispatcher::DispatchMouseExitAtPoint( |
153 const gfx::Point& point) { | 153 const gfx::Point& point) { |
154 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, | 154 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, |
155 ui::EF_NONE); | 155 ui::EF_NONE); |
156 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); | 156 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); |
157 } | 157 } |
158 | 158 |
159 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, | 159 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, |
160 Window* window, | 160 Window* window, |
161 ui::EventResult result) { | 161 ui::EventResult result) { |
162 // TODO(tdresser): Move this to PreDispatchTouchEvent, to enable eager | |
163 // gesture detection. See crbug.com/410280. | |
164 if (!ui::GestureRecognizer::Get() | |
165 ->ProcessTouchEventPreDispatch(*event, window)) { | |
166 return; | |
167 } | |
168 | |
169 // Once we've fully migrated to the eager gesture detector, we won't need to | 162 // Once we've fully migrated to the eager gesture detector, we won't need to |
170 // pass an event here. | 163 // pass an event here. |
171 scoped_ptr<ui::GestureRecognizer::Gestures> gestures( | 164 scoped_ptr<ui::GestureRecognizer::Gestures> gestures( |
172 ui::GestureRecognizer::Get()->ProcessTouchEventOnAsyncAck( | 165 ui::GestureRecognizer::Get() |
173 *event, result, window)); | 166 ->ProcessTouchEventAck(*event, result, window)); |
174 DispatchDetails details = ProcessGestures(gestures.get()); | 167 DispatchDetails details = ProcessGestures(gestures.get()); |
175 if (details.dispatcher_destroyed) | 168 if (details.dispatcher_destroyed) |
176 return; | 169 return; |
177 } | 170 } |
178 | 171 |
179 void WindowEventDispatcher::HoldPointerMoves() { | 172 void WindowEventDispatcher::HoldPointerMoves() { |
180 if (!move_hold_count_) | 173 if (!move_hold_count_) |
181 held_event_factory_.InvalidateWeakPtrs(); | 174 held_event_factory_.InvalidateWeakPtrs(); |
182 ++move_hold_count_; | 175 ++move_hold_count_; |
183 TRACE_EVENT_ASYNC_BEGIN0("ui", "WindowEventDispatcher::HoldPointerMoves", | 176 TRACE_EVENT_ASYNC_BEGIN0("ui", "WindowEventDispatcher::HoldPointerMoves", |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 old_dispatch_target_ = NULL; | 484 old_dispatch_target_ = NULL; |
492 #ifndef NDEBUG | 485 #ifndef NDEBUG |
493 DCHECK(!event_dispatch_target_ || window()->Contains(event_dispatch_target_)); | 486 DCHECK(!event_dispatch_target_ || window()->Contains(event_dispatch_target_)); |
494 #endif | 487 #endif |
495 | 488 |
496 if (event.IsTouchEvent() && !details.target_destroyed) { | 489 if (event.IsTouchEvent() && !details.target_destroyed) { |
497 // Do not let 'held' touch events contribute to any gestures unless it is | 490 // Do not let 'held' touch events contribute to any gestures unless it is |
498 // being dispatched. | 491 // being dispatched. |
499 if (dispatching_held_event_ || !held_move_event_ || | 492 if (dispatching_held_event_ || !held_move_event_ || |
500 !held_move_event_->IsTouchEvent()) { | 493 !held_move_event_->IsTouchEvent()) { |
| 494 // If the event is being handled asynchronously, ignore it. |
| 495 if (event.result() & ui::ER_CONSUMED) |
| 496 return details; |
| 497 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
501 | 498 |
502 // Once we've fully migrated to the eager gesture detector, we won't | 499 // Once we've fully migrated to the eager gesture detector, we won't |
503 // need to pass an event here. | 500 // need to pass an event here. |
504 ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event), | 501 ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event), |
505 static_cast<Window*>(event.target()), | 502 static_cast<Window*>(event.target()), |
506 window()); | 503 window()); |
507 | 504 |
508 if (event.result() & ui::ER_CONSUMED) | 505 if (ui::GestureRecognizer::Get()->ProcessTouchEvent( |
509 orig_event.StopPropagation(); | 506 orig_event, static_cast<Window*>(target))) { |
510 | 507 gestures.reset(ui::GestureRecognizer::Get()->ProcessTouchEventAck( |
511 // TODO(tdresser): Move this to PreDispatchTouchEvent, to enable eager | 508 orig_event, event.result(), static_cast<Window*>(target))); |
512 // gesture detection. See crbug.com/410280. | 509 return ProcessGestures(gestures.get()); |
513 if (!ui::GestureRecognizer::Get() | |
514 ->ProcessTouchEventPreDispatch(orig_event, | |
515 static_cast<Window*>(target))) { | |
516 return details; | |
517 } | 510 } |
518 | |
519 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | |
520 | |
521 gestures.reset( | |
522 ui::GestureRecognizer::Get()->ProcessTouchEventPostDispatch( | |
523 orig_event, event.result(), static_cast<Window*>(target))); | |
524 | |
525 return ProcessGestures(gestures.get()); | |
526 } | 511 } |
527 } | 512 } |
528 | 513 |
529 return details; | 514 return details; |
530 } | 515 } |
531 | 516 |
| 517 bool WindowEventDispatcher::OnProcessingTouchEventAsync(ui::TouchEvent* event) { |
| 518 ui::TouchEvent orig_event( |
| 519 *event, static_cast<aura::Window*>(event->target()), window()); |
| 520 |
| 521 bool should_forward = ui::GestureRecognizer::Get()->ProcessTouchEvent( |
| 522 orig_event, static_cast<aura::Window*>(event->target())); |
| 523 |
| 524 // Make sure that |PostDispatch| doesn't give |event| to the GestureRecognizer |
| 525 // again. |
| 526 event->StopPropagation(); |
| 527 return should_forward; |
| 528 } |
| 529 |
532 //////////////////////////////////////////////////////////////////////////////// | 530 //////////////////////////////////////////////////////////////////////////////// |
533 // WindowEventDispatcher, ui::GestureEventHelper implementation: | 531 // WindowEventDispatcher, ui::GestureEventHelper implementation: |
534 | 532 |
535 bool WindowEventDispatcher::CanDispatchToConsumer( | 533 bool WindowEventDispatcher::CanDispatchToConsumer( |
536 ui::GestureConsumer* consumer) { | 534 ui::GestureConsumer* consumer) { |
537 Window* consumer_window = ConsumerToWindow(consumer); | 535 Window* consumer_window = ConsumerToWindow(consumer); |
538 return (consumer_window && consumer_window->GetRootWindow() == window()); | 536 return (consumer_window && consumer_window->GetRootWindow() == window()); |
539 } | 537 } |
540 | 538 |
541 void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { | 539 void WindowEventDispatcher::DispatchCancelTouchEvent(ui::TouchEvent* event) { |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 | 896 |
899 default: | 897 default: |
900 NOTREACHED(); | 898 NOTREACHED(); |
901 break; | 899 break; |
902 } | 900 } |
903 | 901 |
904 PreDispatchLocatedEvent(target, event); | 902 PreDispatchLocatedEvent(target, event); |
905 } | 903 } |
906 | 904 |
907 } // namespace aura | 905 } // namespace aura |
OLD | NEW |