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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 float two_finger_tap_max_separation; | 65 float two_finger_tap_max_separation; |
66 | 66 |
67 // Maximum time the second pointer can be active for a two finger tap. | 67 // Maximum time the second pointer can be active for a two finger tap. |
68 base::TimeDelta two_finger_tap_timeout; | 68 base::TimeDelta two_finger_tap_timeout; |
69 }; | 69 }; |
70 | 70 |
71 class GestureListener { | 71 class GestureListener { |
72 public: | 72 public: |
73 virtual ~GestureListener() {} | 73 virtual ~GestureListener() {} |
74 virtual bool OnDown(const MotionEvent& e) = 0; | 74 virtual bool OnDown(const MotionEvent& e) = 0; |
75 virtual void OnShowPress(const MotionEvent& e) = 0; | 75 virtual void OnShowPress(const MotionEvent& e, float max_radius) = 0; |
76 virtual bool OnSingleTapUp(const MotionEvent& e) = 0; | 76 virtual bool OnSingleTapUp(const MotionEvent& e, |
jdduke (slow)
2014/09/04 15:01:25
These callbacks variations are rather unfortunate,
| |
77 float x, | |
78 float y, | |
79 float max_radius) = 0; | |
77 virtual void OnLongPress(const MotionEvent& e) = 0; | 80 virtual void OnLongPress(const MotionEvent& e) = 0; |
78 virtual bool OnScroll(const MotionEvent& e1, | 81 virtual bool OnScroll(const MotionEvent& e1, |
79 const MotionEvent& e2, | 82 const MotionEvent& e2, |
80 float distance_x, | 83 float distance_x, |
81 float distance_y) = 0; | 84 float distance_y) = 0; |
82 virtual bool OnFling(const MotionEvent& e1, | 85 virtual bool OnFling(const MotionEvent& e1, |
83 const MotionEvent& e2, | 86 const MotionEvent& e2, |
84 float velocity_x, | 87 float velocity_x, |
85 float velocity_y) = 0; | 88 float velocity_y) = 0; |
86 // Added for Chromium (Aura). | 89 // Added for Chromium (Aura). |
87 virtual bool OnSwipe(const MotionEvent& e1, | 90 virtual bool OnSwipe(const MotionEvent& e1, |
88 const MotionEvent& e2, | 91 const MotionEvent& e2, |
89 float velocity_x, | 92 float velocity_x, |
90 float velocity_y) = 0; | 93 float velocity_y) = 0; |
91 virtual bool OnTwoFingerTap(const MotionEvent& e1, | 94 virtual bool OnTwoFingerTap(const MotionEvent& e1, |
92 const MotionEvent& e2) = 0; | 95 const MotionEvent& e2) = 0; |
93 }; | 96 }; |
94 | 97 |
95 class DoubleTapListener { | 98 class DoubleTapListener { |
96 public: | 99 public: |
97 virtual ~DoubleTapListener() {} | 100 virtual ~DoubleTapListener() {} |
98 virtual bool OnSingleTapConfirmed(const MotionEvent& e) = 0; | 101 virtual bool OnSingleTapConfirmed(const MotionEvent& e, |
102 float x, | |
103 float y, | |
104 float max_radius) = 0; | |
99 virtual bool OnDoubleTap(const MotionEvent& e) = 0; | 105 virtual bool OnDoubleTap(const MotionEvent& e) = 0; |
100 virtual bool OnDoubleTapEvent(const MotionEvent& e) = 0; | 106 virtual bool OnDoubleTapEvent(const MotionEvent& e) = 0; |
101 }; | 107 }; |
102 | 108 |
103 // A convenience class to extend when you only want to listen for a subset | 109 // A convenience class to extend when you only want to listen for a subset |
104 // of all the gestures. This implements all methods in the | 110 // of all the gestures. This implements all methods in the |
105 // |GestureListener| and |DoubleTapListener| but does | 111 // |GestureListener| and |DoubleTapListener| but does |
106 // nothing and returns false for all applicable methods. | 112 // nothing and returns false for all applicable methods. |
107 class SimpleGestureListener : public GestureListener, | 113 class SimpleGestureListener : public GestureListener, |
108 public DoubleTapListener { | 114 public DoubleTapListener { |
109 public: | 115 public: |
110 // GestureListener implementation. | 116 // GestureListener implementation. |
111 virtual bool OnDown(const MotionEvent& e) OVERRIDE; | 117 virtual bool OnDown(const MotionEvent& e) OVERRIDE; |
112 virtual void OnShowPress(const MotionEvent& e) OVERRIDE; | 118 virtual void OnShowPress(const MotionEvent& e, float max_radius) OVERRIDE; |
113 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE; | 119 virtual bool OnSingleTapUp(const MotionEvent& e, |
120 float x, | |
121 float y, | |
122 float max_radius) OVERRIDE; | |
114 virtual void OnLongPress(const MotionEvent& e) OVERRIDE; | 123 virtual void OnLongPress(const MotionEvent& e) OVERRIDE; |
115 virtual bool OnScroll(const MotionEvent& e1, | 124 virtual bool OnScroll(const MotionEvent& e1, |
116 const MotionEvent& e2, | 125 const MotionEvent& e2, |
117 float distance_x, | 126 float distance_x, |
118 float distance_y) OVERRIDE; | 127 float distance_y) OVERRIDE; |
119 virtual bool OnFling(const MotionEvent& e1, | 128 virtual bool OnFling(const MotionEvent& e1, |
120 const MotionEvent& e2, | 129 const MotionEvent& e2, |
121 float velocity_x, | 130 float velocity_x, |
122 float velocity_y) OVERRIDE; | 131 float velocity_y) OVERRIDE; |
123 virtual bool OnSwipe(const MotionEvent& e1, | 132 virtual bool OnSwipe(const MotionEvent& e1, |
124 const MotionEvent& e2, | 133 const MotionEvent& e2, |
125 float velocity_x, | 134 float velocity_x, |
126 float velocity_y) OVERRIDE; | 135 float velocity_y) OVERRIDE; |
127 virtual bool OnTwoFingerTap(const MotionEvent& e1, | 136 virtual bool OnTwoFingerTap(const MotionEvent& e1, |
128 const MotionEvent& e2) OVERRIDE; | 137 const MotionEvent& e2) OVERRIDE; |
129 | 138 |
130 // DoubleTapListener implementation. | 139 // DoubleTapListener implementation. |
131 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE; | 140 virtual bool OnSingleTapConfirmed(const MotionEvent& e, |
141 float x, | |
142 float y, | |
143 float max_radius) OVERRIDE; | |
132 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE; | 144 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE; |
133 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE; | 145 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE; |
134 }; | 146 }; |
135 | 147 |
136 GestureDetector(const Config& config, | 148 GestureDetector(const Config& config, |
137 GestureListener* listener, | 149 GestureListener* listener, |
138 DoubleTapListener* optional_double_tap_listener); | 150 DoubleTapListener* optional_double_tap_listener); |
139 ~GestureDetector(); | 151 ~GestureDetector(); |
140 | 152 |
141 bool OnTouchEvent(const MotionEvent& ev); | 153 bool OnTouchEvent(const MotionEvent& ev); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 bool still_down_; | 195 bool still_down_; |
184 bool defer_confirm_single_tap_; | 196 bool defer_confirm_single_tap_; |
185 bool always_in_tap_region_; | 197 bool always_in_tap_region_; |
186 bool always_in_bigger_tap_region_; | 198 bool always_in_bigger_tap_region_; |
187 bool two_finger_tap_allowed_for_gesture_; | 199 bool two_finger_tap_allowed_for_gesture_; |
188 | 200 |
189 scoped_ptr<MotionEvent> current_down_event_; | 201 scoped_ptr<MotionEvent> current_down_event_; |
190 scoped_ptr<MotionEvent> previous_up_event_; | 202 scoped_ptr<MotionEvent> previous_up_event_; |
191 scoped_ptr<MotionEvent> secondary_pointer_down_event_; | 203 scoped_ptr<MotionEvent> secondary_pointer_down_event_; |
192 | 204 |
205 // The maximum diameter of the finger touches before show press gesture is | |
206 // sent. | |
tdresser
2014/09/04 13:54:00
Perhaps:
// The maximum touch diameter before the
lanwei
2014/09/05 20:40:36
Done.
| |
207 float max_touch_diameter_; | |
tdresser
2014/09/04 13:54:00
Perhaps |max_diameter_before_show_press_|.
It's a
lanwei
2014/09/05 20:40:36
Done.
| |
208 | |
193 // True when the user is still touching for the second tap (down, move, and | 209 // True when the user is still touching for the second tap (down, move, and |
194 // up events). Can only be true if there is a double tap listener attached. | 210 // up events). Can only be true if there is a double tap listener attached. |
195 bool is_double_tapping_; | 211 bool is_double_tapping_; |
196 | 212 |
197 float last_focus_x_; | 213 float last_focus_x_; |
198 float last_focus_y_; | 214 float last_focus_y_; |
199 float down_focus_x_; | 215 float down_focus_x_; |
200 float down_focus_y_; | 216 float down_focus_y_; |
201 | 217 |
202 bool longpress_enabled_; | 218 bool longpress_enabled_; |
203 bool swipe_enabled_; | 219 bool swipe_enabled_; |
204 bool two_finger_tap_enabled_; | 220 bool two_finger_tap_enabled_; |
205 | 221 |
206 // Determines speed during touch scrolling. | 222 // Determines speed during touch scrolling. |
207 VelocityTrackerState velocity_tracker_; | 223 VelocityTrackerState velocity_tracker_; |
208 | 224 |
209 DISALLOW_COPY_AND_ASSIGN(GestureDetector); | 225 DISALLOW_COPY_AND_ASSIGN(GestureDetector); |
210 }; | 226 }; |
211 | 227 |
212 } // namespace ui | 228 } // namespace ui |
213 | 229 |
214 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ | 230 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ |
OLD | NEW |