| 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/logging.h" | 8 #include "base/logging.h" |
| 8 #include "ui/events/event.h" | 9 #include "ui/events/event.h" |
| 9 #include "ui/events/gesture_detection/gesture_config_helper.h" | 10 #include "ui/events/gesture_detection/gesture_config_helper.h" |
| 10 #include "ui/events/gesture_detection/gesture_event_data.h" | 11 #include "ui/events/gesture_detection/gesture_event_data.h" |
| 11 #include "ui/events/gestures/gesture_configuration.h" | 12 #include "ui/events/gestures/gesture_configuration.h" |
| 12 | 13 |
| 13 namespace ui { | 14 namespace ui { |
| 14 | 15 |
| 15 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) | 16 GestureProviderAura::GestureProviderAura(GestureProviderAuraClient* client) |
| 16 : client_(client), | 17 : client_(client), |
| 17 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this) { | 18 filtered_gesture_provider_(ui::DefaultGestureProviderConfig(), this), |
| 19 handling_event_(false) { |
| 18 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); | 20 filtered_gesture_provider_.SetDoubleTapSupportForPlatformEnabled(false); |
| 19 } | 21 } |
| 20 | 22 |
| 21 GestureProviderAura::~GestureProviderAura() {} | 23 GestureProviderAura::~GestureProviderAura() {} |
| 22 | 24 |
| 23 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { | 25 bool GestureProviderAura::OnTouchEvent(const TouchEvent& event) { |
| 24 last_touch_event_flags_ = event.flags(); | 26 last_touch_event_flags_ = event.flags(); |
| 25 bool pointer_id_is_active = false; | 27 bool pointer_id_is_active = false; |
| 26 for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) { | 28 for (size_t i = 0; i < pointer_state_.GetPointerCount(); ++i) { |
| 27 if (event.touch_id() != pointer_state_.GetPointerId(i)) | 29 if (event.touch_id() != pointer_state_.GetPointerId(i)) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 } | 43 } |
| 42 | 44 |
| 43 pointer_state_.OnTouch(event); | 45 pointer_state_.OnTouch(event); |
| 44 | 46 |
| 45 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); | 47 bool result = filtered_gesture_provider_.OnTouchEvent(pointer_state_); |
| 46 pointer_state_.CleanupRemovedTouchPoints(event); | 48 pointer_state_.CleanupRemovedTouchPoints(event); |
| 47 return result; | 49 return result; |
| 48 } | 50 } |
| 49 | 51 |
| 50 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { | 52 void GestureProviderAura::OnTouchEventAck(bool event_consumed) { |
| 53 DCHECK(pending_gestures_.empty()); |
| 54 DCHECK(!handling_event_); |
| 55 base::AutoReset<bool> handling_event(&handling_event_, true); |
| 51 filtered_gesture_provider_.OnTouchEventAck(event_consumed); | 56 filtered_gesture_provider_.OnTouchEventAck(event_consumed); |
| 52 } | 57 } |
| 53 | 58 |
| 54 void GestureProviderAura::OnGestureEvent( | 59 void GestureProviderAura::OnGestureEvent( |
| 55 const GestureEventData& gesture) { | 60 const GestureEventData& gesture) { |
| 56 GestureEventDetails details = gesture.details; | 61 GestureEventDetails details = gesture.details; |
| 57 | 62 |
| 58 if (gesture.type == ET_GESTURE_TAP) { | 63 if (gesture.type == ET_GESTURE_TAP) { |
| 59 int tap_count = 1; | 64 int tap_count = 1; |
| 60 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) | 65 if (previous_tap_ && IsConsideredDoubleTap(*previous_tap_, gesture)) |
| 61 tap_count = 1 + (previous_tap_->details.tap_count() % 3); | 66 tap_count = 1 + (previous_tap_->details.tap_count() % 3); |
| 62 details.set_tap_count(tap_count); | 67 details.set_tap_count(tap_count); |
| 63 if (!previous_tap_) | 68 if (!previous_tap_) |
| 64 previous_tap_.reset(new GestureEventData(gesture)); | 69 previous_tap_.reset(new GestureEventData(gesture)); |
| 65 else | 70 else |
| 66 *previous_tap_ = gesture; | 71 *previous_tap_ = gesture; |
| 67 previous_tap_->details = details; | 72 previous_tap_->details = details; |
| 68 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { | 73 } else if (gesture.type == ET_GESTURE_TAP_CANCEL) { |
| 69 previous_tap_.reset(); | 74 previous_tap_.reset(); |
| 70 } | 75 } |
| 71 | 76 |
| 72 ui::GestureEvent event(gesture.type, | 77 scoped_ptr<ui::GestureEvent> event( |
| 73 gesture.x, | 78 new ui::GestureEvent(gesture.type, |
| 74 gesture.y, | 79 gesture.x, |
| 75 last_touch_event_flags_, | 80 gesture.y, |
| 76 gesture.time - base::TimeTicks(), | 81 last_touch_event_flags_, |
| 77 details, | 82 gesture.time - base::TimeTicks(), |
| 78 // ui::GestureEvent stores a bitfield indicating the | 83 details, |
| 79 // ids of active touch points. This is currently only | 84 // ui::GestureEvent stores a bitfield indicating the |
| 80 // used when one finger is down, and will eventually | 85 // ids of active touch points. This is currently only |
| 81 // be cleaned up. See crbug.com/366707. | 86 // used when one finger is down, and will eventually |
| 82 1 << gesture.motion_event_id); | 87 // be cleaned up. See crbug.com/366707. |
| 83 client_->OnGestureEvent(&event); | 88 1 << gesture.motion_event_id)); |
| 89 |
| 90 if (!handling_event_) { |
| 91 // Dispatching event caused by timer. |
| 92 client_->OnGestureEvent(event.get()); |
| 93 } else { |
| 94 // Memory managed by ScopedVector pending_gestures_. |
| 95 pending_gestures_.push_back(event.release()); |
| 96 } |
| 97 } |
| 98 |
| 99 ScopedVector<GestureEvent>* GestureProviderAura::GetAndResetPendingGestures() { |
| 100 if (pending_gestures_.empty()) |
| 101 return NULL; |
| 102 // Caller is responsible for deleting old_pending_gestures. |
| 103 ScopedVector<GestureEvent>* old_pending_gestures = |
| 104 new ScopedVector<GestureEvent>(); |
| 105 old_pending_gestures->swap(pending_gestures_); |
| 106 return old_pending_gestures; |
| 84 } | 107 } |
| 85 | 108 |
| 86 bool GestureProviderAura::IsConsideredDoubleTap( | 109 bool GestureProviderAura::IsConsideredDoubleTap( |
| 87 const GestureEventData& previous_tap, | 110 const GestureEventData& previous_tap, |
| 88 const GestureEventData& current_tap) const { | 111 const GestureEventData& current_tap) const { |
| 89 if (current_tap.time - previous_tap.time > | 112 if (current_tap.time - previous_tap.time > |
| 90 base::TimeDelta::FromMilliseconds( | 113 base::TimeDelta::FromMilliseconds( |
| 91 ui::GestureConfiguration::max_seconds_between_double_click() * | 114 ui::GestureConfiguration::max_seconds_between_double_click() * |
| 92 1000)) { | 115 1000)) { |
| 93 return false; | 116 return false; |
| 94 } | 117 } |
| 95 | 118 |
| 96 double double_tap_slop_square = | 119 double double_tap_slop_square = |
| 97 GestureConfiguration::max_distance_between_taps_for_double_tap(); | 120 GestureConfiguration::max_distance_between_taps_for_double_tap(); |
| 98 double_tap_slop_square *= double_tap_slop_square; | 121 double_tap_slop_square *= double_tap_slop_square; |
| 99 const float delta_x = previous_tap.x - current_tap.x; | 122 const float delta_x = previous_tap.x - current_tap.x; |
| 100 const float delta_y = previous_tap.y - current_tap.y; | 123 const float delta_y = previous_tap.y - current_tap.y; |
| 101 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); | 124 return (delta_x * delta_x + delta_y * delta_y < double_tap_slop_square); |
| 102 } | 125 } |
| 103 | 126 |
| 104 } // namespace content | 127 } // namespace content |
| OLD | NEW |