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/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/events/event.h" | 8 #include "ui/events/event.h" |
9 #include "ui/events/gesture_detection/gesture_config_helper.h" | 9 #include "ui/events/gesture_detection/gesture_config_helper.h" |
10 #include "ui/events/gesture_detection/gesture_event_data.h" | 10 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 11 #include "ui/events/gestures/gesture_configuration.h" |
11 | 12 |
12 namespace ui { | 13 namespace ui { |
13 | 14 |
14 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) | 15 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) |
15 : client_(client), | 16 : client_(client), |
16 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { | 17 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { |
17 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); | 18 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); |
18 } | 19 } |
19 | 20 |
20 GestureProviderAura::~GestureProviderAura() {} | 21 GestureProviderAura::~GestureProviderAura() {} |
(...skipping 12 matching lines...) Expand all Loading... |
33 // Ignore touch press events if we already believe the pointer is down. | 34 // Ignore touch press events if we already believe the pointer is down. |
34 return false; | 35 return false; |
35 } else if (event.type() != ET_TOUCH_PRESSED && !pointer_id_is_active) { | 36 } 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 // 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 // move or touch up events without associated touch down events. Ignore |
38 // them. | 39 // them. |
39 return false; | 40 return false; |
40 } | 41 } |
41 | 42 |
42 pointer_state_.OnTouch(event); | 43 pointer_state_.OnTouch(event); |
| 44 |
43 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); | 45 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); |
44 pointer_state_.CleanupRemovedTouchPoints(event); | 46 pointer_state_.CleanupRemovedTouchPoints(event); |
45 return result; | 47 return result; |
46 } | 48 } |
47 | 49 |
48 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { | 50 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { |
49 filtered_gesture_provider_.OnTouchEventAck(event_consumed); | 51 filtered_gesture_provider_.OnTouchEventAck(event_consumed); |
50 } | 52 } |
51 | 53 |
52 void GestureProviderAura::OnGestureEvent( | 54 void GestureProviderAura::OnGestureEvent( |
53 const GestureEventData& gesture) { | 55 const GestureEventData& gesture) { |
| 56 GestureEventDetails details = gesture.details; |
| 57 |
| 58 if (gesture.type == ET_GESTURE_TAP) { |
| 59 int tap_count = 1; |
| 60 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) |
| 61 tap_count = 1 + (previous_tap_->details.tap_count() % 3); |
| 62 details.set_tap_count(tap_count); |
| 63 if (!previous_tap_) |
| 64 previous_tap_.reset(new GestureEventData(gesture)); |
| 65 else |
| 66 *previous_tap_ = gesture; |
| 67 previous_tap_->details = details; |
| 68 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { |
| 69 previous_tap_.reset(); |
| 70 } |
| 71 |
54 ui::GestureEvent event(gesture.type, | 72 ui::GestureEvent event(gesture.type, |
55 gesture.x, | 73 gesture.x, |
56 gesture.y, | 74 gesture.y, |
57 last_touch_event_flags_, | 75 last_touch_event_flags_, |
58 gesture.time - base::TimeTicks(), | 76 gesture.time - base::TimeTicks(), |
59 gesture.details, | 77 details, |
60 // ui::GestureEvent stores a bitfield indicating the | 78 // ui::GestureEvent stores a bitfield indicating the |
61 // ids of active touch points. This is currently only | 79 // ids of active touch points. This is currently only |
62 // used when one finger is down, and will eventually | 80 // used when one finger is down, and will eventually |
63 // be cleaned up. See crbug.com/366707. | 81 // be cleaned up. See crbug.com/366707. |
64 1 << gesture.motion_event_id); | 82 1 << gesture.motion_event_id); |
65 client_->OnGestureEvent(&event); | 83 client_->OnGestureEvent(&event); |
66 } | 84 } |
67 | 85 |
| 86 bool GestureProviderAura::IsConsideredDoubleTap( |
| 87 const GestureEventData& previous_tap, |
| 88 const GestureEventData& current_tap) const { |
| 89 if (current_tap.time - previous_tap.time > |
| 90 base::TimeDelta::FromMilliseconds( |
| 91 ui::GestureConfiguration::max_seconds_between_double_click() * |
| 92 1000)) { |
| 93 return false; |
| 94 } |
| 95 |
| 96 double double_tap_slop_square = |
| 97 GestureConfiguration::max_distance_between_taps_for_double_tap(); |
| 98 double_tap_slop_square *= double_tap_slop_square; |
| 99 const float delta_x = previous_tap.x - current_tap.x; |
| 100 const float delta_y = previous_tap.y - current_tap.y; |
| 101 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); |
| 102 } |
| 103 |
68 } // namespace content | 104 } // namespace content |
OLD | NEW |