Chromium Code Reviews| 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 int tap_count = 1; | |
|
jdduke (slow)
2014/05/21 20:02:00
Nit: Move tap_count into the if case?
tdresser
2014/05/22 12:56:47
Done.
| |
| 59 if (gesture.type == ET_GESTURE_TAP) { | |
| 60 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) | |
| 61 tap_count = 1 + (previous_tap_->details.tap_count() % 3); | |
| 62 details = GestureEventDetails(ET_GESTURE_TAP, tap_count, 0); | |
|
jdduke (slow)
2014/05/21 20:02:00
Feel free to add a GestureEventDetails::set_tap_co
tdresser
2014/05/22 12:56:47
Done.
| |
| 63 previous_tap_.reset(new GestureEventData(gesture)); | |
|
jdduke (slow)
2014/05/21 20:02:00
if (!previous_tap_)
previous_tap_.reset(new gest
tdresser
2014/05/22 12:56:47
Done.
| |
| 64 previous_tap_->details = details; | |
| 65 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { | |
| 66 previous_tap_.reset(); | |
| 67 } | |
| 68 | |
| 54 ui::GestureEvent event(gesture.type, | 69 ui::GestureEvent event(gesture.type, |
| 55 gesture.x, | 70 gesture.x, |
| 56 gesture.y, | 71 gesture.y, |
| 57 last_touch_event_flags_, | 72 last_touch_event_flags_, |
| 58 gesture.time - base::TimeTicks(), | 73 gesture.time - base::TimeTicks(), |
| 59 gesture.details, | 74 details, |
| 60 // ui::GestureEvent stores a bitfield indicating the | 75 // ui::GestureEvent stores a bitfield indicating the |
| 61 // ids of active touch points. This is currently only | 76 // ids of active touch points. This is currently only |
| 62 // used when one finger is down, and will eventually | 77 // used when one finger is down, and will eventually |
| 63 // be cleaned up. See crbug.com/366707. | 78 // be cleaned up. See crbug.com/366707. |
| 64 1 << gesture.motion_event_id); | 79 1 << gesture.motion_event_id); |
| 65 client_->OnGestureEvent(&event); | 80 client_->OnGestureEvent(&event); |
| 66 } | 81 } |
| 67 | 82 |
| 83 bool GestureProviderAura::IsConsideredDoubleTap( | |
| 84 const GestureEventData& previous_tap, | |
| 85 const GestureEventData& current_tap) const { | |
| 86 if (current_tap.time - previous_tap.time > | |
| 87 base::TimeDelta::FromMilliseconds( | |
| 88 ui::GestureConfiguration::max_seconds_between_double_click() * | |
| 89 1000)) { | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 double double_tap_slop_square = | |
| 94 GestureConfiguration::max_distance_between_taps_for_double_tap(); | |
| 95 double_tap_slop_square *= double_tap_slop_square; | |
| 96 const float delta_x = previous_tap.x - current_tap.x; | |
| 97 const float delta_y = previous_tap.y - current_tap.y; | |
| 98 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); | |
| 99 } | |
| 100 | |
| 68 } // namespace content | 101 } // namespace content |
| OLD | NEW |