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_unique_touch_event_id_( | 20 last_unique_touch_event_id_( |
21 std::numeric_limits<unsigned long long>::max()) { | 21 std::numeric_limits<unsigned long long>::max()) { |
22 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); | 22 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); |
23 } | 23 } |
24 | 24 |
25 GestureProviderAura::~GestureProviderAura() {} | 25 GestureProviderAura::~GestureProviderAura() {} |
26 | 26 |
27 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { | 27 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { |
28 last_unique_touch_event_id_ = event.unique_event_id(); | 28 last_unique_touch_event_id_ = event.unique_event_id(); |
29 int index = pointer_state_.FindPointerIndexOfId(event.touch_id()); | 29 last_touch_event_latency_info_ = *event.latency(); |
30 bool pointer_id_is_active = index != -1; | 30 if (!pointer_state_.OnTouch(event)) |
31 | |
32 if (event.type() == ET_TOUCH_PRESSED && pointer_id_is_active) { | |
33 // Ignore touch press events if we already believe the pointer is down. | |
34 return false; | 31 return false; |
35 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { | |
36 // We could have an active touch stream transfered to us, resulting in touch | |
37 // move or touch up events without associated touch down events. Ignore | |
38 // them. | |
39 return false; | |
40 } | |
41 | |
42 // If this is a touchmove event, and it isn't different from the last | |
43 // event, ignore it. | |
44 if (event.type() == ET_TOUCH_MOVED && | |
45 event.x() == pointer_state_.GetX(index) && | |
46 event.y() == pointer_state_.GetY(index)) { | |
47 return false; | |
48 } | |
49 | |
50 last_touch_event_latency_info_ = *event.latency(); | |
51 pointer_state_.OnTouch(event); | |
52 | 32 |
53 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); | 33 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); |
54 pointer_state_.CleanupRemovedTouchPoints(event); | 34 pointer_state_.CleanupRemovedTouchPoints(event); |
55 return result; | 35 return result; |
56 } | 36 } |
57 | 37 |
58 void GestureProviderAura::OnAsyncTouchEventAck(bool event_consumed) { | 38 void GestureProviderAura::OnAsyncTouchEventAck(bool event_consumed) { |
59 DCHECK(pending_gestures_.empty()); | 39 DCHECK(pending_gestures_.empty()); |
60 DCHECK(!handling_event_); | 40 DCHECK(!handling_event_); |
61 base::AutoReset<bool> handling_event(&handling_event_, true); | 41 base::AutoReset<bool> handling_event(&handling_event_, true); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 float double_tap_slop_square = | 123 float double_tap_slop_square = |
144 GestureConfiguration::GetInstance() | 124 GestureConfiguration::GetInstance() |
145 ->max_distance_between_taps_for_double_tap(); | 125 ->max_distance_between_taps_for_double_tap(); |
146 double_tap_slop_square *= double_tap_slop_square; | 126 double_tap_slop_square *= double_tap_slop_square; |
147 const float delta_x = previous_tap.x - current_tap.x; | 127 const float delta_x = previous_tap.x - current_tap.x; |
148 const float delta_y = previous_tap.y - current_tap.y; | 128 const float delta_y = previous_tap.y - current_tap.y; |
149 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); | 129 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); |
150 } | 130 } |
151 | 131 |
152 } // namespace content | 132 } // namespace content |
OLD | NEW |