Chromium Code Reviews| Index: ui/events/gestures/gesture_provider_aura.cc |
| diff --git a/ui/events/gestures/gesture_provider_aura.cc b/ui/events/gestures/gesture_provider_aura.cc |
| index c73d3179bc6b711afdd23e82587b33a83fe04cd2..f982ad283002458dab4d7d5b148e21622c1d6cab 100644 |
| --- a/ui/events/gestures/gesture_provider_aura.cc |
| +++ b/ui/events/gestures/gesture_provider_aura.cc |
| @@ -8,11 +8,13 @@ |
| #include "ui/events/event.h" |
| #include "ui/events/gesture_detection/gesture_config_helper.h" |
| #include "ui/events/gesture_detection/gesture_event_data.h" |
| +#include "ui/events/gestures/gesture_configuration.h" |
| namespace ui { |
| GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) |
| - : client_(client), |
| + : tap_count_(0), |
| + client_(client), |
| filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { |
| filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); |
| } |
| @@ -40,6 +42,12 @@ bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { |
| } |
| pointer_state_.OnTouch(event); |
| + |
| + if (pointer_state_.GetAction() == MotionEvent::ACTION_DOWN) { |
| + previous_down_event_ = current_down_event_.Pass(); |
| + current_down_event_ = pointer_state_.Clone(); |
| + } |
| + |
| bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); |
| pointer_state_.CleanupRemovedTouchPoints(event); |
| return result; |
| @@ -51,12 +59,30 @@ void GestureProviderAura::OnTouchEventAck(bool event_consumed) { |
| void GestureProviderAura::OnGestureEvent( |
| const GestureEventData& gesture) { |
| + const GestureEventDetails* details = &gesture.details; |
| + scoped_ptr<GestureEventDetails> tap_details; |
|
tdresser
2014/05/21 16:39:16
Do you have any other ideas on how to avoid constr
jdduke (slow)
2014/05/21 17:21:48
Hmm, yeah, the details object is pretty small, mig
tdresser
2014/05/21 18:47:49
Done.
|
| + |
| + if (gesture.type == ET_GESTURE_TAP) { |
| + if (previous_down_event_ && current_down_event_ && |
| + IsConsideredDoubleTap( |
| + *previous_down_event_, previous_tap_time_, *current_down_event_)) { |
| + tap_count_ = 1 + (tap_count_ % 3); |
| + } else { |
| + tap_count_ = 1; |
| + } |
| + tap_details.reset(new GestureEventDetails(ET_GESTURE_TAP, tap_count_, 0)); |
| + details = tap_details.get(); |
| + previous_tap_time_ = gesture.time; |
| + } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { |
| + tap_count_ = 0; |
| + } |
| + |
| ui::GestureEvent event(gesture.type, |
| gesture.x, |
| gesture.y, |
| last_touch_event_flags_, |
| gesture.time - base::TimeTicks(), |
| - gesture.details, |
| + *details, |
| // ui::GestureEvent stores a bitfield indicating the |
| // ids of active touch points. This is currently only |
| // used when one finger is down, and will eventually |
| @@ -65,4 +91,23 @@ void GestureProviderAura::OnGestureEvent( |
| client_->OnGestureEvent(&event); |
| } |
| +bool GestureProviderAura::IsConsideredDoubleTap( |
| + const MotionEvent& previous_down, |
| + const base::TimeTicks previous_tap_time, |
|
jdduke (slow)
2014/05/21 17:21:48
Hmm, could we just store the previous_tap_event_?
tdresser
2014/05/21 18:47:49
Done, with a scoped_ptr.
|
| + const MotionEvent& current_down) const { |
| + if (current_down.GetEventTime() - previous_tap_time > |
| + base::TimeDelta::FromMilliseconds( |
| + ui::GestureConfiguration::max_seconds_between_double_click() * |
| + 1000)) { |
| + return false; |
| + } |
| + |
| + double double_tap_slop_square = |
| + GestureConfiguration::max_distance_between_taps_for_double_tap(); |
| + double_tap_slop_square *= double_tap_slop_square; |
| + const float delta_x = previous_down.GetX() - current_down.GetX(); |
| + const float delta_y = previous_down.GetY() - current_down.GetY(); |
| + return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); |
| +} |
| + |
| } // namespace content |