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 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ |
6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ |
7 | 7 |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ui/events/gesture_detection/gesture_detection_export.h" | 10 #include "ui/events/gesture_detection/gesture_detection_export.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Whether |OnTwoFingerTap| should be called for two finger tap | 62 // Whether |OnTwoFingerTap| should be called for two finger tap |
63 // gestures. Defaults to false. | 63 // gestures. Defaults to false. |
64 bool two_finger_tap_enabled; | 64 bool two_finger_tap_enabled; |
65 | 65 |
66 // Maximum distance between pointers for a two finger tap. | 66 // Maximum distance between pointers for a two finger tap. |
67 float two_finger_tap_max_separation; | 67 float two_finger_tap_max_separation; |
68 | 68 |
69 // Maximum time the second pointer can be active for a two finger tap. | 69 // Maximum time the second pointer can be active for a two finger tap. |
70 base::TimeDelta two_finger_tap_timeout; | 70 base::TimeDelta two_finger_tap_timeout; |
71 | 71 |
| 72 // Single tap count repetition length. Defaults to 1 (no repetition count). |
| 73 // Note that when double-tap detection is enabled, the single tap repeat |
| 74 // count will always be 1. |
| 75 int single_tap_repeat_interval; |
| 76 |
72 VelocityTracker::Strategy velocity_tracker_strategy; | 77 VelocityTracker::Strategy velocity_tracker_strategy; |
73 }; | 78 }; |
74 | 79 |
75 GestureDetector(const Config& config, | 80 GestureDetector(const Config& config, |
76 GestureListener* listener, | 81 GestureListener* listener, |
77 DoubleTapListener* optional_double_tap_listener); | 82 DoubleTapListener* optional_double_tap_listener); |
78 ~GestureDetector(); | 83 ~GestureDetector(); |
79 | 84 |
80 bool OnTouchEvent(const MotionEvent& ev); | 85 bool OnTouchEvent(const MotionEvent& ev); |
81 | 86 |
82 // Setting a valid |double_tap_listener| will enable double-tap detection, | 87 // Setting a valid |double_tap_listener| will enable double-tap detection, |
83 // wherein calls to |OnSimpleTapConfirmed| are delayed by the tap timeout. | 88 // wherein calls to |OnSimpleTapConfirmed| are delayed by the tap timeout. |
84 // Note: The listener must never be changed while |is_double_tapping| is true. | 89 // Note: The listener must never be changed while |is_double_tapping| is true. |
85 void SetDoubleTapListener(DoubleTapListener* double_tap_listener); | 90 void SetDoubleTapListener(DoubleTapListener* double_tap_listener); |
86 | 91 |
87 bool has_doubletap_listener() const { return double_tap_listener_ != NULL; } | 92 bool has_doubletap_listener() const { return double_tap_listener_ != NULL; } |
88 | 93 |
89 bool is_double_tapping() const { return is_double_tapping_; } | 94 bool is_double_tapping() const { return is_double_tapping_; } |
90 | 95 |
91 void set_longpress_enabled(bool enabled) { longpress_enabled_ = enabled; } | 96 void set_longpress_enabled(bool enabled) { longpress_enabled_ = enabled; } |
92 void set_showpress_enabled(bool enabled) { showpress_enabled_ = enabled; } | 97 void set_showpress_enabled(bool enabled) { showpress_enabled_ = enabled; } |
93 | 98 |
94 private: | 99 private: |
95 void Init(const Config& config); | 100 void Init(const Config& config); |
96 void OnShowPressTimeout(); | 101 void OnShowPressTimeout(); |
97 void OnLongPressTimeout(); | 102 void OnLongPressTimeout(); |
98 void OnTapTimeout(); | 103 void OnTapTimeout(); |
99 void Cancel(); | 104 void Cancel(); |
100 void CancelTaps(); | 105 void CancelTaps(); |
101 bool IsConsideredDoubleTap(const MotionEvent& first_down, | 106 bool IsRepeatedTap(const MotionEvent& first_down, |
102 const MotionEvent& first_up, | 107 const MotionEvent& first_up, |
103 const MotionEvent& second_down) const; | 108 const MotionEvent& second_down) const; |
104 bool HandleSwipeIfNeeded(const MotionEvent& up, float vx, float vy); | 109 bool HandleSwipeIfNeeded(const MotionEvent& up, float vx, float vy); |
105 | 110 |
106 class TimeoutGestureHandler; | 111 class TimeoutGestureHandler; |
107 scoped_ptr<TimeoutGestureHandler> timeout_handler_; | 112 scoped_ptr<TimeoutGestureHandler> timeout_handler_; |
108 GestureListener* const listener_; | 113 GestureListener* const listener_; |
109 DoubleTapListener* double_tap_listener_; | 114 DoubleTapListener* double_tap_listener_; |
110 | 115 |
111 float touch_slop_square_; | 116 float touch_slop_square_; |
112 float double_tap_touch_slop_square_; | 117 float double_tap_touch_slop_square_; |
113 float double_tap_slop_square_; | 118 float double_tap_slop_square_; |
(...skipping 13 matching lines...) Expand all Loading... |
127 bool two_finger_tap_allowed_for_gesture_; | 132 bool two_finger_tap_allowed_for_gesture_; |
128 | 133 |
129 scoped_ptr<MotionEvent> current_down_event_; | 134 scoped_ptr<MotionEvent> current_down_event_; |
130 scoped_ptr<MotionEvent> previous_up_event_; | 135 scoped_ptr<MotionEvent> previous_up_event_; |
131 scoped_ptr<MotionEvent> secondary_pointer_down_event_; | 136 scoped_ptr<MotionEvent> secondary_pointer_down_event_; |
132 | 137 |
133 // True when the user is still touching for the second tap (down, move, and | 138 // True when the user is still touching for the second tap (down, move, and |
134 // up events). Can only be true if there is a double tap listener attached. | 139 // up events). Can only be true if there is a double tap listener attached. |
135 bool is_double_tapping_; | 140 bool is_double_tapping_; |
136 | 141 |
| 142 // Whether the current ACTION_DOWN event meets the criteria for being a |
| 143 // repeated tap. Note that it will be considered a repeated tap only if the |
| 144 // corresponding ACTION_UP yields a valid tap and double-tap detection is |
| 145 // disabled. |
| 146 bool is_down_candidate_for_repeated_single_tap_; |
| 147 |
| 148 // The number of repeated taps in the current sequence, i.e., for the initial |
| 149 // tap this is 0, for the first *repeated* tap 1, etc... |
| 150 int current_single_tap_repeat_count_; |
| 151 int single_tap_repeat_interval_; |
| 152 |
137 float last_focus_x_; | 153 float last_focus_x_; |
138 float last_focus_y_; | 154 float last_focus_y_; |
139 float down_focus_x_; | 155 float down_focus_x_; |
140 float down_focus_y_; | 156 float down_focus_y_; |
141 | 157 |
142 bool longpress_enabled_; | 158 bool longpress_enabled_; |
143 bool showpress_enabled_; | 159 bool showpress_enabled_; |
144 bool swipe_enabled_; | 160 bool swipe_enabled_; |
145 bool two_finger_tap_enabled_; | 161 bool two_finger_tap_enabled_; |
146 | 162 |
147 // Determines speed during touch scrolling. | 163 // Determines speed during touch scrolling. |
148 VelocityTrackerState velocity_tracker_; | 164 VelocityTrackerState velocity_tracker_; |
149 | 165 |
150 DISALLOW_COPY_AND_ASSIGN(GestureDetector); | 166 DISALLOW_COPY_AND_ASSIGN(GestureDetector); |
151 }; | 167 }; |
152 | 168 |
153 } // namespace ui | 169 } // namespace ui |
154 | 170 |
155 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ | 171 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ |
OLD | NEW |