| 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" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 DCHECK(pending_gestures_.empty()); | 42 DCHECK(pending_gestures_.empty()); |
| 43 DCHECK(!handling_event_); | 43 DCHECK(!handling_event_); |
| 44 base::AutoReset<bool> handling_event(&handling_event_, true); | 44 base::AutoReset<bool> handling_event(&handling_event_, true); |
| 45 filtered_gesture_provider_.OnTouchEventAck(unique_event_id, event_consumed); | 45 filtered_gesture_provider_.OnTouchEventAck(unique_event_id, event_consumed); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void GestureProviderAura::OnGestureEvent( | 48 void GestureProviderAura::OnGestureEvent( |
| 49 const GestureEventData& gesture) { | 49 const GestureEventData& gesture) { |
| 50 GestureEventDetails details = gesture.details; | 50 GestureEventDetails details = gesture.details; |
| 51 details.set_oldest_touch_id(gesture.motion_event_id); | 51 details.set_oldest_touch_id(gesture.motion_event_id); |
| 52 | |
| 53 if (gesture.type() == ET_GESTURE_TAP) { | |
| 54 int tap_count = 1; | |
| 55 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) | |
| 56 tap_count = 1 + (previous_tap_->details.tap_count() % 3); | |
| 57 details.set_tap_count(tap_count); | |
| 58 if (!previous_tap_) | |
| 59 previous_tap_.reset(new GestureEventData(gesture)); | |
| 60 else | |
| 61 *previous_tap_ = gesture; | |
| 62 previous_tap_->details = details; | |
| 63 } else if (gesture.type() == ET_GESTURE_TAP_CANCEL) { | |
| 64 previous_tap_.reset(); | |
| 65 } | |
| 66 | |
| 67 scoped_ptr<ui::GestureEvent> event( | 52 scoped_ptr<ui::GestureEvent> event( |
| 68 new ui::GestureEvent(gesture.x, | 53 new ui::GestureEvent(gesture.x, |
| 69 gesture.y, | 54 gesture.y, |
| 70 gesture.flags, | 55 gesture.flags, |
| 71 gesture.time - base::TimeTicks(), | 56 gesture.time - base::TimeTicks(), |
| 72 details)); | 57 details)); |
| 73 | 58 |
| 74 if (!handling_event_) { | 59 if (!handling_event_) { |
| 75 // Dispatching event caused by timer. | 60 // Dispatching event caused by timer. |
| 76 client_->OnGestureEvent(event.get()); | 61 client_->OnGestureEvent(event.get()); |
| 77 } else { | 62 } else { |
| 78 // Memory managed by ScopedVector pending_gestures_. | 63 // Memory managed by ScopedVector pending_gestures_. |
| 79 pending_gestures_.push_back(event.Pass()); | 64 pending_gestures_.push_back(event.Pass()); |
| 80 } | 65 } |
| 81 } | 66 } |
| 82 | 67 |
| 83 ScopedVector<GestureEvent>* GestureProviderAura::GetAndResetPendingGestures() { | 68 ScopedVector<GestureEvent>* GestureProviderAura::GetAndResetPendingGestures() { |
| 84 if (pending_gestures_.empty()) | 69 if (pending_gestures_.empty()) |
| 85 return NULL; | 70 return NULL; |
| 86 // Caller is responsible for deleting old_pending_gestures. | 71 // Caller is responsible for deleting old_pending_gestures. |
| 87 ScopedVector<GestureEvent>* old_pending_gestures = | 72 ScopedVector<GestureEvent>* old_pending_gestures = |
| 88 new ScopedVector<GestureEvent>(); | 73 new ScopedVector<GestureEvent>(); |
| 89 old_pending_gestures->swap(pending_gestures_); | 74 old_pending_gestures->swap(pending_gestures_); |
| 90 return old_pending_gestures; | 75 return old_pending_gestures; |
| 91 } | 76 } |
| 92 | 77 |
| 93 bool GestureProviderAura::IsConsideredDoubleTap( | |
| 94 const GestureEventData& previous_tap, | |
| 95 const GestureEventData& current_tap) const { | |
| 96 if (current_tap.time - previous_tap.time > | |
| 97 base::TimeDelta::FromMilliseconds( | |
| 98 GestureConfiguration::GetInstance() | |
| 99 ->max_time_between_double_click_in_ms())) { | |
| 100 return false; | |
| 101 } | |
| 102 | |
| 103 float double_tap_slop_square = | |
| 104 GestureConfiguration::GetInstance() | |
| 105 ->max_distance_between_taps_for_double_tap(); | |
| 106 double_tap_slop_square *= double_tap_slop_square; | |
| 107 const float delta_x = previous_tap.x - current_tap.x; | |
| 108 const float delta_y = previous_tap.y - current_tap.y; | |
| 109 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); | |
| 110 } | |
| 111 | |
| 112 } // namespace content | 78 } // namespace content |
| OLD | NEW |