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" |
11 #include "ui/aura/client/capture_client.h" | 11 #include "ui/aura/client/capture_client.h" |
12 #include "ui/aura/client/cursor_client.h" | 12 #include "ui/aura/client/cursor_client.h" |
13 #include "ui/aura/client/event_client.h" | 13 #include "ui/aura/client/event_client.h" |
14 #include "ui/aura/client/focus_client.h" | 14 #include "ui/aura/client/focus_client.h" |
15 #include "ui/aura/client/screen_position_client.h" | 15 #include "ui/aura/client/screen_position_client.h" |
16 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
19 #include "ui/aura/window_targeter.h" | 19 #include "ui/aura/window_targeter.h" |
20 #include "ui/aura/window_tracker.h" | 20 #include "ui/aura/window_tracker.h" |
21 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
22 #include "ui/base/hit_test.h" | 22 #include "ui/base/hit_test.h" |
23 #include "ui/compositor/dip_util.h" | 23 #include "ui/compositor/dip_util.h" |
24 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
25 #include "ui/events/gestures/gesture_recognizer.h" | 25 #include "ui/events/gestures/gesture_recognizer.h" |
26 #include "ui/events/gestures/gesture_types.h" | 26 #include "ui/events/gestures/gesture_types.h" |
27 #include "ui/events/gestures/unified_gesture_detector_enabled.h" | |
27 | 28 |
28 typedef ui::EventDispatchDetails DispatchDetails; | 29 typedef ui::EventDispatchDetails DispatchDetails; |
29 | 30 |
30 namespace aura { | 31 namespace aura { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 // Returns true if |target| has a non-client (frame) component at |location|, | 35 // Returns true if |target| has a non-client (frame) component at |location|, |
35 // in window coordinates. | 36 // in window coordinates. |
36 bool IsNonClientLocation(Window* target, const gfx::Point& location) { | 37 bool IsNonClientLocation(Window* target, const gfx::Point& location) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 const gfx::Point& point) { | 155 const gfx::Point& point) { |
155 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, | 156 ui::MouseEvent event(ui::ET_MOUSE_EXITED, point, point, ui::EF_NONE, |
156 ui::EF_NONE); | 157 ui::EF_NONE); |
157 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); | 158 return DispatchMouseEnterOrExit(event, ui::ET_MOUSE_EXITED); |
158 } | 159 } |
159 | 160 |
160 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, | 161 void WindowEventDispatcher::ProcessedTouchEvent(ui::TouchEvent* event, |
161 Window* window, | 162 Window* window, |
162 ui::EventResult result) { | 163 ui::EventResult result) { |
163 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 164 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
164 gestures.reset(ui::GestureRecognizer::Get()-> | 165 |
165 ProcessTouchEventForGesture(*event, result, window)); | 166 if (ui::IsUnifiedGestureDetectorEnabled()) { |
jdduke (slow)
2014/07/31 16:19:02
Would it be crazy to abstract all of these differe
tdresser
2014/08/01 13:35:32
Done.
| |
167 gestures.reset( | |
168 ui::GestureRecognizer::Get()->AckTouchEventForGesture(result, window)); | |
169 } else { | |
170 ui::TouchEvent orig_event(*static_cast<const ui::TouchEvent*>(event), | |
171 static_cast<Window*>(window), | |
172 this->window()); | |
173 gestures.reset( | |
174 ui::GestureRecognizer::Get()->ProcessTouchEventForGestureForOldAuraGR( | |
175 orig_event, result, window)); | |
176 } | |
177 | |
166 DispatchDetails details = ProcessGestures(gestures.get()); | 178 DispatchDetails details = ProcessGestures(gestures.get()); |
167 if (details.dispatcher_destroyed) | 179 if (details.dispatcher_destroyed) |
168 return; | 180 return; |
169 } | 181 } |
170 | 182 |
171 void WindowEventDispatcher::HoldPointerMoves() { | 183 void WindowEventDispatcher::HoldPointerMoves() { |
172 if (!move_hold_count_) | 184 if (!move_hold_count_) |
173 held_event_factory_.InvalidateWeakPtrs(); | 185 held_event_factory_.InvalidateWeakPtrs(); |
174 ++move_hold_count_; | 186 ++move_hold_count_; |
175 TRACE_EVENT_ASYNC_BEGIN0("ui", "WindowEventDispatcher::HoldPointerMoves", | 187 TRACE_EVENT_ASYNC_BEGIN0("ui", "WindowEventDispatcher::HoldPointerMoves", |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
478 old_dispatch_target_ = NULL; | 490 old_dispatch_target_ = NULL; |
479 #ifndef NDEBUG | 491 #ifndef NDEBUG |
480 DCHECK(!event_dispatch_target_ || window()->Contains(event_dispatch_target_)); | 492 DCHECK(!event_dispatch_target_ || window()->Contains(event_dispatch_target_)); |
481 #endif | 493 #endif |
482 | 494 |
483 if (event.IsTouchEvent() && !details.target_destroyed) { | 495 if (event.IsTouchEvent() && !details.target_destroyed) { |
484 // Do not let 'held' touch events contribute to any gestures unless it is | 496 // Do not let 'held' touch events contribute to any gestures unless it is |
485 // being dispatched. | 497 // being dispatched. |
486 if (dispatching_held_event_ || !held_move_event_ || | 498 if (dispatching_held_event_ || !held_move_event_ || |
487 !held_move_event_->IsTouchEvent()) { | 499 !held_move_event_->IsTouchEvent()) { |
488 ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event), | 500 // If the event isn't being handled asynchronously, handle it now. |
489 static_cast<Window*>(event.target()), window()); | |
490 // Get the list of GestureEvents from GestureRecognizer. | |
491 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; | 501 scoped_ptr<ui::GestureRecognizer::Gestures> gestures; |
492 gestures.reset(ui::GestureRecognizer::Get()-> | 502 |
493 ProcessTouchEventForGesture(orig_event, event.result(), | 503 if (ui::IsUnifiedGestureDetectorEnabled()) { |
494 static_cast<Window*>(target))); | 504 if (event.result() & ui::ER_CONSUMED) |
505 return details; | |
506 gestures.reset(ui::GestureRecognizer::Get()->AckTouchEventForGesture( | |
507 event.result(), static_cast<Window*>(target))); | |
508 } else { | |
509 ui::TouchEvent orig_event(static_cast<const ui::TouchEvent&>(event), | |
510 static_cast<Window*>(event.target()), | |
511 window()); | |
512 gestures.reset( | |
513 ui::GestureRecognizer::Get() | |
514 ->ProcessTouchEventForGestureForOldAuraGR( | |
515 orig_event, event.result(), static_cast<Window*>(target))); | |
516 } | |
495 return ProcessGestures(gestures.get()); | 517 return ProcessGestures(gestures.get()); |
496 } | 518 } |
497 } | 519 } |
498 | 520 |
499 return details; | 521 return details; |
500 } | 522 } |
501 | 523 |
502 //////////////////////////////////////////////////////////////////////////////// | 524 //////////////////////////////////////////////////////////////////////////////// |
503 // WindowEventDispatcher, ui::GestureEventHelper implementation: | 525 // WindowEventDispatcher, ui::GestureEventHelper implementation: |
504 | 526 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
859 held_move_event_.reset(new ui::TouchEvent(*event, target, window())); | 881 held_move_event_.reset(new ui::TouchEvent(*event, target, window())); |
860 event->SetHandled(); | 882 event->SetHandled(); |
861 return; | 883 return; |
862 } | 884 } |
863 break; | 885 break; |
864 | 886 |
865 default: | 887 default: |
866 NOTREACHED(); | 888 NOTREACHED(); |
867 break; | 889 break; |
868 } | 890 } |
891 | |
892 if (ui::IsUnifiedGestureDetectorEnabled() && | |
893 (dispatching_held_event_ || !held_move_event_ || | |
894 !held_move_event_->IsTouchEvent())) { | |
895 ui::TouchEvent orig_event( | |
896 static_cast<const ui::TouchEvent&>(*event), target, window()); | |
897 if (!ui::GestureRecognizer::Get()->ProcessTouchEventForGesture(orig_event, | |
898 target)) { | |
899 // If the touch event is invalid in some way, the gesture recognizer will | |
900 // reject it. In this case, stop the touch from reaching the next event | |
901 // phase. | |
902 event->SetHandled(); | |
903 } | |
904 } | |
905 | |
869 PreDispatchLocatedEvent(target, event); | 906 PreDispatchLocatedEvent(target, event); |
870 } | 907 } |
871 | 908 |
872 } // namespace aura | 909 } // namespace aura |
OLD | NEW |