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/events/gestures/gesture_provider_aura.h" | 5 #include "ui/events/gestures/gesture_provider_aura.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
10 #include "ui/events/gesture_detection/gesture_configuration.h" | 10 #include "ui/events/gesture_detection/gesture_configuration.h" |
11 #include "ui/events/gesture_detection/gesture_event_data.h" | 11 #include "ui/events/gesture_detection/gesture_event_data.h" |
12 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 12 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
13 | 13 |
14 namespace ui { | 14 namespace ui { |
15 | 15 |
16 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) | 16 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) |
17 : client_(client), | 17 : client_(client), |
18 filtered_gesture_provider_(DefaultGestureProviderConfig(), this), | 18 filtered_gesture_provider_(DefaultGestureProviderConfig(), this), |
19 handling_event_(false) { | 19 handling_event_(false), |
| 20 last_touch_event_id_(-1) { |
20 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); | 21 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); |
21 } | 22 } |
22 | 23 |
23 GestureProviderAura::~GestureProviderAura() {} | 24 GestureProviderAura::~GestureProviderAura() {} |
24 | 25 |
25 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { | 26 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { |
| 27 last_touch_event_id_ = event.touch_event_id(); |
26 int index = pointer_state_.FindPointerIndexOfId(event.touch_id()); | 28 int index = pointer_state_.FindPointerIndexOfId(event.touch_id()); |
27 bool pointer_id_is_active = index != -1; | 29 bool pointer_id_is_active = index != -1; |
28 | 30 |
29 if (event.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { | 31 if (event.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { |
30 // Ignore touch press events if we already believe the pointer is down. | 32 // Ignore touch press events if we already believe the pointer is down. |
31 return false; | 33 return false; |
32 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { | 34 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { |
33 // We could have an active touch stream transfered to us, resulting in touch | 35 // We could have an active touch stream transfered to us, resulting in touch |
34 // move or touch up events without associated touch down events. Ignore | 36 // move or touch up events without associated touch down events. Ignore |
35 // them. | 37 // them. |
36 return false; | 38 return false; |
37 } | 39 } |
38 | 40 |
39 // If this is a touchmove event, and it isn't different from the last | 41 // If this is a touchmove event, and it isn't different from the last |
40 // event, ignore it. | 42 // event, ignore it. |
41 if (event.type() == ET_TOUCH_MOVED && | 43 if (event.type() == ET_TOUCH_MOVED && |
42 event.x() == pointer_state_.GetX(index) && | 44 event.x() == pointer_state_.GetX(index) && |
43 event.y() == pointer_state_.GetY(index)) { | 45 event.y() == pointer_state_.GetY(index)) { |
44 return false; | 46 return false; |
45 } | 47 } |
46 | 48 |
47 last_touch_event_latency_info_ = *event.latency(); | 49 last_touch_event_latency_info_ = *event.latency(); |
48 pointer_state_.OnTouch(event); | 50 pointer_state_.OnTouch(event); |
49 | 51 |
50 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); | 52 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); |
51 pointer_state_.CleanupRemovedTouchPoints(event); | 53 pointer_state_.CleanupRemovedTouchPoints(event); |
52 return result; | 54 return result; |
53 } | 55 } |
54 | 56 |
55 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { | 57 void GestureProviderAura::OnAsyncTouchEventAck(bool event_consumed) { |
56 DCHECK(pending_gestures_.empty()); | 58 DCHECK(pending_gestures_.empty()); |
57 DCHECK(!handling_event_); | 59 DCHECK(!handling_event_); |
58 base::AutoReset<bool> handling_event(&handling_event_, true); | 60 base::AutoReset<bool> handling_event(&handling_event_, true); |
59 filtered_gesture_provider_.OnTouchEventAck(event_consumed); | 61 filtered_gesture_provider_.OnAsyncTouchEventAck(event_consumed); |
60 last_touch_event_latency_info_.Clear(); | 62 last_touch_event_latency_info_.Clear(); |
61 } | 63 } |
62 | 64 |
| 65 void GestureProviderAura::OnSyncTouchEventAck(const ui::TouchEvent& event, |
| 66 bool event_consumed) { |
| 67 DCHECK_EQ(last_touch_event_id_, event.touch_event_id()); |
| 68 DCHECK(pending_gestures_.empty()); |
| 69 DCHECK(!handling_event_); |
| 70 base::AutoReset<bool> handling_event(&handling_event_, true); |
| 71 filtered_gesture_provider_.OnSyncTouchEventAck(event_consumed); |
| 72 last_touch_event_latency_info_.Clear(); |
| 73 } |
| 74 |
63 void GestureProviderAura::OnGestureEvent( | 75 void GestureProviderAura::OnGestureEvent( |
64 const GestureEventData& gesture) { | 76 const GestureEventData& gesture) { |
65 GestureEventDetails details = gesture.details; | 77 GestureEventDetails details = gesture.details; |
66 details.set_oldest_touch_id(gesture.motion_event_id); | 78 details.set_oldest_touch_id(gesture.motion_event_id); |
67 | 79 |
68 if (gesture.type() == ET_GESTURE_TAP) { | 80 if (gesture.type() == ET_GESTURE_TAP) { |
69 int tap_count = 1; | 81 int tap_count = 1; |
70 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) | 82 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) |
71 tap_count = 1 + (previous_tap_->details.tap_count() % 3); | 83 tap_count = 1 + (previous_tap_->details.tap_count() % 3); |
72 details.set_tap_count(tap_count); | 84 details.set_tap_count(tap_count); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 float double_tap_slop_square = | 142 float double_tap_slop_square = |
131 GestureConfiguration::GetInstance() | 143 GestureConfiguration::GetInstance() |
132 ->max_distance_between_taps_for_double_tap(); | 144 ->max_distance_between_taps_for_double_tap(); |
133 double_tap_slop_square *= double_tap_slop_square; | 145 double_tap_slop_square *= double_tap_slop_square; |
134 const float delta_x = previous_tap.x - current_tap.x; | 146 const float delta_x = previous_tap.x - current_tap.x; |
135 const float delta_y = previous_tap.y - current_tap.y; | 147 const float delta_y = previous_tap.y - current_tap.y; |
136 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); | 148 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); |
137 } | 149 } |
138 | 150 |
139 } // namespace content | 151 } // namespace content |
OLD | NEW |