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 | 62 |
63 // Maximum time the second pointer can be active for a two finger tap. | 63 // Maximum time the second pointer can be active for a two finger tap. |
64 base::TimeDelta two_finger_tap_timeout; | 64 base::TimeDelta two_finger_tap_timeout; |
65 }; | 65 }; |
66 | 66 |
67 class GestureListener { | 67 class GestureListener { |
68 public: | 68 public: |
69 virtual ~GestureListener() {} | 69 virtual ~GestureListener() {} |
70 virtual bool OnDown(const MotionEvent& e) = 0; | 70 virtual bool OnDown(const MotionEvent& e) = 0; |
71 virtual void OnShowPress(const MotionEvent& e) = 0; | 71 virtual void OnShowPress(const MotionEvent& e) = 0; |
72 virtual bool OnSingleTapUp(const MotionEvent& e) = 0; | 72 virtual bool OnSingleTapUp(const MotionEvent& e, int tap_count) = 0; |
73 virtual bool OnLongPress(const MotionEvent& e) = 0; | 73 virtual bool OnLongPress(const MotionEvent& e) = 0; |
74 virtual bool OnScroll(const MotionEvent& e1, | 74 virtual bool OnScroll(const MotionEvent& e1, |
75 const MotionEvent& e2, | 75 const MotionEvent& e2, |
76 float distance_x, | 76 float distance_x, |
77 float distance_y) = 0; | 77 float distance_y) = 0; |
78 virtual bool OnFling(const MotionEvent& e1, | 78 virtual bool OnFling(const MotionEvent& e1, |
79 const MotionEvent& e2, | 79 const MotionEvent& e2, |
80 float velocity_x, | 80 float velocity_x, |
81 float velocity_y) = 0; | 81 float velocity_y) = 0; |
82 // Added for Chromium (Aura). | 82 // Added for Chromium (Aura). |
83 virtual bool OnSwipe(const MotionEvent& e1, | 83 virtual bool OnSwipe(const MotionEvent& e1, |
84 const MotionEvent& e2, | 84 const MotionEvent& e2, |
85 float velocity_x, | 85 float velocity_x, |
86 float velocity_y) = 0; | 86 float velocity_y) = 0; |
87 virtual bool OnTwoFingerTap(const MotionEvent& e1, | 87 virtual bool OnTwoFingerTap(const MotionEvent& e1, |
88 const MotionEvent& e2) = 0; | 88 const MotionEvent& e2) = 0; |
89 }; | 89 }; |
90 | 90 |
91 class DoubleTapListener { | 91 class DoubleTapListener { |
92 public: | 92 public: |
93 virtual ~DoubleTapListener() {} | 93 virtual ~DoubleTapListener() {} |
94 virtual bool OnSingleTapConfirmed(const MotionEvent& e) = 0; | 94 virtual bool OnSingleTapConfirmed(const MotionEvent& e, int tap_count) = 0; |
95 virtual bool OnDoubleTap(const MotionEvent& e) = 0; | 95 virtual bool OnDoubleTap(const MotionEvent& e) = 0; |
96 virtual bool OnDoubleTapEvent(const MotionEvent& e) = 0; | 96 virtual bool OnDoubleTapEvent(const MotionEvent& e) = 0; |
97 }; | 97 }; |
98 | 98 |
99 // A convenience class to extend when you only want to listen for a subset | 99 // A convenience class to extend when you only want to listen for a subset |
100 // of all the gestures. This implements all methods in the | 100 // of all the gestures. This implements all methods in the |
101 // |GestureListener| and |DoubleTapListener| but does | 101 // |GestureListener| and |DoubleTapListener| but does |
102 // nothing and returns false for all applicable methods. | 102 // nothing and returns false for all applicable methods. |
103 class SimpleGestureListener : public GestureListener, | 103 class SimpleGestureListener : public GestureListener, |
104 public DoubleTapListener { | 104 public DoubleTapListener { |
105 public: | 105 public: |
106 // GestureListener implementation. | 106 // GestureListener implementation. |
107 virtual bool OnDown(const MotionEvent& e) OVERRIDE; | 107 virtual bool OnDown(const MotionEvent& e) OVERRIDE; |
108 virtual void OnShowPress(const MotionEvent& e) OVERRIDE; | 108 virtual void OnShowPress(const MotionEvent& e) OVERRIDE; |
109 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE; | 109 virtual bool OnSingleTapUp(const MotionEvent& e, int tap_count) OVERRIDE; |
110 virtual bool OnLongPress(const MotionEvent& e) OVERRIDE; | 110 virtual bool OnLongPress(const MotionEvent& e) OVERRIDE; |
111 virtual bool OnScroll(const MotionEvent& e1, | 111 virtual bool OnScroll(const MotionEvent& e1, |
112 const MotionEvent& e2, | 112 const MotionEvent& e2, |
113 float distance_x, | 113 float distance_x, |
114 float distance_y) OVERRIDE; | 114 float distance_y) OVERRIDE; |
115 virtual bool OnFling(const MotionEvent& e1, | 115 virtual bool OnFling(const MotionEvent& e1, |
116 const MotionEvent& e2, | 116 const MotionEvent& e2, |
117 float velocity_x, | 117 float velocity_x, |
118 float velocity_y) OVERRIDE; | 118 float velocity_y) OVERRIDE; |
119 virtual bool OnSwipe(const MotionEvent& e1, | 119 virtual bool OnSwipe(const MotionEvent& e1, |
120 const MotionEvent& e2, | 120 const MotionEvent& e2, |
121 float velocity_x, | 121 float velocity_x, |
122 float velocity_y) OVERRIDE; | 122 float velocity_y) OVERRIDE; |
123 virtual bool OnTwoFingerTap(const MotionEvent& e1, | 123 virtual bool OnTwoFingerTap(const MotionEvent& e1, |
124 const MotionEvent& e2) OVERRIDE; | 124 const MotionEvent& e2) OVERRIDE; |
125 | 125 |
126 // DoubleTapListener implementation. | 126 // DoubleTapListener implementation. |
127 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE; | 127 virtual bool OnSingleTapConfirmed(const MotionEvent& e, |
| 128 int tap_count) OVERRIDE; |
128 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE; | 129 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE; |
129 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE; | 130 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE; |
130 }; | 131 }; |
131 | 132 |
132 GestureDetector(const Config& config, | 133 GestureDetector(const Config& config, |
133 GestureListener* listener, | 134 GestureListener* listener, |
134 DoubleTapListener* optional_double_tap_listener); | 135 DoubleTapListener* optional_double_tap_listener); |
135 ~GestureDetector(); | 136 ~GestureDetector(); |
136 | 137 |
137 bool OnTouchEvent(const MotionEvent& ev); | 138 bool OnTouchEvent(const MotionEvent& ev); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 base::TimeDelta two_finger_tap_timeout_; | 176 base::TimeDelta two_finger_tap_timeout_; |
176 | 177 |
177 bool still_down_; | 178 bool still_down_; |
178 bool defer_confirm_single_tap_; | 179 bool defer_confirm_single_tap_; |
179 bool in_longpress_; | 180 bool in_longpress_; |
180 bool always_in_tap_region_; | 181 bool always_in_tap_region_; |
181 bool always_in_bigger_tap_region_; | 182 bool always_in_bigger_tap_region_; |
182 bool two_finger_tap_allowed_for_gesture_; | 183 bool two_finger_tap_allowed_for_gesture_; |
183 | 184 |
184 scoped_ptr<MotionEvent> current_down_event_; | 185 scoped_ptr<MotionEvent> current_down_event_; |
| 186 scoped_ptr<MotionEvent> previous_down_event_; |
185 scoped_ptr<MotionEvent> previous_up_event_; | 187 scoped_ptr<MotionEvent> previous_up_event_; |
186 scoped_ptr<MotionEvent> secondary_pointer_down_event_; | 188 scoped_ptr<MotionEvent> secondary_pointer_down_event_; |
187 | 189 |
188 // True when the user is still touching for the second tap (down, move, and | 190 // True when the user is still touching for the second tap (down, move, and |
189 // up events). Can only be true if there is a double tap listener attached. | 191 // up events). Can only be true if there is a double tap listener attached. |
190 bool is_double_tapping_; | 192 bool is_double_tapping_; |
191 | 193 |
192 float last_focus_x_; | 194 float last_focus_x_; |
193 float last_focus_y_; | 195 float last_focus_y_; |
194 float down_focus_x_; | 196 float down_focus_x_; |
195 float down_focus_y_; | 197 float down_focus_y_; |
196 | 198 |
197 bool longpress_enabled_; | 199 bool longpress_enabled_; |
198 bool swipe_enabled_; | 200 bool swipe_enabled_; |
199 bool two_finger_tap_enabled_; | 201 bool two_finger_tap_enabled_; |
200 | 202 |
| 203 // If the double tap gesture is disabled, this counts the number of successive |
| 204 // taps which occured within the double tap window. The current maximum is 3. |
| 205 int tap_count_; |
| 206 |
201 // Determines speed during touch scrolling. | 207 // Determines speed during touch scrolling. |
202 VelocityTrackerState velocity_tracker_; | 208 VelocityTrackerState velocity_tracker_; |
203 | 209 |
204 DISALLOW_COPY_AND_ASSIGN(GestureDetector); | 210 DISALLOW_COPY_AND_ASSIGN(GestureDetector); |
205 }; | 211 }; |
206 | 212 |
207 } // namespace ui | 213 } // namespace ui |
208 | 214 |
209 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ | 215 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ |
OLD | NEW |