Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1393)

Side by Side Diff: ui/events/gesture_detection/gesture_detector.h

Issue 617423002: Make GestureTextSelector detect its own gestures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sort gyp/gn Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/events.gyp ('k') | ui/events/gesture_detection/gesture_detector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "ui/events/gesture_detection/velocity_tracker_state.h" 11 #include "ui/events/gesture_detection/velocity_tracker_state.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 class DoubleTapListener;
16 class GestureListener;
15 class MotionEvent; 17 class MotionEvent;
16 18
17 // Port of GestureDetector.java from Android 19 // Port of GestureDetector.java from Android
18 // * platform/frameworks/base/core/java/android/view/GestureDetector.java 20 // * platform/frameworks/base/core/java/android/view/GestureDetector.java
19 // * Change-Id: Ib470735ec929b0b358fca4597e92dc81084e675f 21 // * Change-Id: Ib470735ec929b0b358fca4597e92dc81084e675f
20 // * Please update the Change-Id as upstream Android changes are pulled. 22 // * Please update the Change-Id as upstream Android changes are pulled.
21 class GestureDetector { 23 class GESTURE_DETECTION_EXPORT GestureDetector {
22 public: 24 public:
23 struct GESTURE_DETECTION_EXPORT Config { 25 struct GESTURE_DETECTION_EXPORT Config {
24 Config(); 26 Config();
25 ~Config(); 27 ~Config();
26 28
27 base::TimeDelta longpress_timeout; 29 base::TimeDelta longpress_timeout;
28 base::TimeDelta showpress_timeout; 30 base::TimeDelta showpress_timeout;
29 base::TimeDelta double_tap_timeout; 31 base::TimeDelta double_tap_timeout;
30 32
31 // The minimum duration between the first tap's up event and the second 33 // The minimum duration between the first tap's up event and the second
(...skipping 29 matching lines...) Expand all
61 // gestures. Defaults to false. 63 // gestures. Defaults to false.
62 bool two_finger_tap_enabled; 64 bool two_finger_tap_enabled;
63 65
64 // Maximum distance between pointers for a two finger tap. 66 // Maximum distance between pointers for a two finger tap.
65 float two_finger_tap_max_separation; 67 float two_finger_tap_max_separation;
66 68
67 // 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.
68 base::TimeDelta two_finger_tap_timeout; 70 base::TimeDelta two_finger_tap_timeout;
69 }; 71 };
70 72
71 class GestureListener {
72 public:
73 virtual ~GestureListener() {}
74 virtual bool OnDown(const MotionEvent& e) = 0;
75 virtual void OnShowPress(const MotionEvent& e) = 0;
76 virtual bool OnSingleTapUp(const MotionEvent& e) = 0;
77 virtual void OnLongPress(const MotionEvent& e) = 0;
78 virtual bool OnScroll(const MotionEvent& e1,
79 const MotionEvent& e2,
80 float distance_x,
81 float distance_y) = 0;
82 virtual bool OnFling(const MotionEvent& e1,
83 const MotionEvent& e2,
84 float velocity_x,
85 float velocity_y) = 0;
86 // Added for Chromium (Aura).
87 virtual bool OnSwipe(const MotionEvent& e1,
88 const MotionEvent& e2,
89 float velocity_x,
90 float velocity_y) = 0;
91 virtual bool OnTwoFingerTap(const MotionEvent& e1,
92 const MotionEvent& e2) = 0;
93 };
94
95 class DoubleTapListener {
96 public:
97 virtual ~DoubleTapListener() {}
98 virtual bool OnSingleTapConfirmed(const MotionEvent& e) = 0;
99 virtual bool OnDoubleTap(const MotionEvent& e) = 0;
100 virtual bool OnDoubleTapEvent(const MotionEvent& e) = 0;
101 };
102
103 // 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
105 // |GestureListener| and |DoubleTapListener| but does
106 // nothing and returns false for all applicable methods.
107 class SimpleGestureListener : public GestureListener,
108 public DoubleTapListener {
109 public:
110 // GestureListener implementation.
111 virtual bool OnDown(const MotionEvent& e) OVERRIDE;
112 virtual void OnShowPress(const MotionEvent& e) OVERRIDE;
113 virtual bool OnSingleTapUp(const MotionEvent& e) OVERRIDE;
114 virtual void OnLongPress(const MotionEvent& e) OVERRIDE;
115 virtual bool OnScroll(const MotionEvent& e1,
116 const MotionEvent& e2,
117 float distance_x,
118 float distance_y) OVERRIDE;
119 virtual bool OnFling(const MotionEvent& e1,
120 const MotionEvent& e2,
121 float velocity_x,
122 float velocity_y) OVERRIDE;
123 virtual bool OnSwipe(const MotionEvent& e1,
124 const MotionEvent& e2,
125 float velocity_x,
126 float velocity_y) OVERRIDE;
127 virtual bool OnTwoFingerTap(const MotionEvent& e1,
128 const MotionEvent& e2) OVERRIDE;
129
130 // DoubleTapListener implementation.
131 virtual bool OnSingleTapConfirmed(const MotionEvent& e) OVERRIDE;
132 virtual bool OnDoubleTap(const MotionEvent& e) OVERRIDE;
133 virtual bool OnDoubleTapEvent(const MotionEvent& e) OVERRIDE;
134 };
135
136 GestureDetector(const Config& config, 73 GestureDetector(const Config& config,
137 GestureListener* listener, 74 GestureListener* listener,
138 DoubleTapListener* optional_double_tap_listener); 75 DoubleTapListener* optional_double_tap_listener);
139 ~GestureDetector(); 76 ~GestureDetector();
140 77
141 bool OnTouchEvent(const MotionEvent& ev); 78 bool OnTouchEvent(const MotionEvent& ev);
142 79
143 // Setting a valid |double_tap_listener| will enable double-tap detection, 80 // Setting a valid |double_tap_listener| will enable double-tap detection,
144 // wherein calls to |OnSimpleTapConfirmed| are delayed by the tap timeout. 81 // wherein calls to |OnSimpleTapConfirmed| are delayed by the tap timeout.
145 // Note: The listener must never be changed while |is_double_tapping| is true. 82 // Note: The listener must never be changed while |is_double_tapping| is true.
146 void SetDoubleTapListener(DoubleTapListener* double_tap_listener); 83 void SetDoubleTapListener(DoubleTapListener* double_tap_listener);
147 84
148 bool has_doubletap_listener() const { return double_tap_listener_ != NULL; } 85 bool has_doubletap_listener() const { return double_tap_listener_ != NULL; }
149 86
150 bool is_double_tapping() const { return is_double_tapping_; } 87 bool is_double_tapping() const { return is_double_tapping_; }
151 88
152 void set_longpress_enabled(bool enabled) { longpress_enabled_ = enabled; } 89 void set_longpress_enabled(bool enabled) { longpress_enabled_ = enabled; }
90 void set_showpress_enabled(bool enabled) { showpress_enabled_ = enabled; }
153 91
154 private: 92 private:
155 void Init(const Config& config); 93 void Init(const Config& config);
156 void OnShowPressTimeout(); 94 void OnShowPressTimeout();
157 void OnLongPressTimeout(); 95 void OnLongPressTimeout();
158 void OnTapTimeout(); 96 void OnTapTimeout();
159 void Cancel(); 97 void Cancel();
160 void CancelTaps(); 98 void CancelTaps();
161 bool IsConsideredDoubleTap(const MotionEvent& first_down, 99 bool IsConsideredDoubleTap(const MotionEvent& first_down,
162 const MotionEvent& first_up, 100 const MotionEvent& first_up,
(...skipping 30 matching lines...) Expand all
193 // True when the user is still touching for the second tap (down, move, and 131 // 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. 132 // up events). Can only be true if there is a double tap listener attached.
195 bool is_double_tapping_; 133 bool is_double_tapping_;
196 134
197 float last_focus_x_; 135 float last_focus_x_;
198 float last_focus_y_; 136 float last_focus_y_;
199 float down_focus_x_; 137 float down_focus_x_;
200 float down_focus_y_; 138 float down_focus_y_;
201 139
202 bool longpress_enabled_; 140 bool longpress_enabled_;
141 bool showpress_enabled_;
203 bool swipe_enabled_; 142 bool swipe_enabled_;
204 bool two_finger_tap_enabled_; 143 bool two_finger_tap_enabled_;
205 144
206 // Determines speed during touch scrolling. 145 // Determines speed during touch scrolling.
207 VelocityTrackerState velocity_tracker_; 146 VelocityTrackerState velocity_tracker_;
208 147
209 DISALLOW_COPY_AND_ASSIGN(GestureDetector); 148 DISALLOW_COPY_AND_ASSIGN(GestureDetector);
210 }; 149 };
211 150
212 } // namespace ui 151 } // namespace ui
213 152
214 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_ 153 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_DETECTOR_H_
OLDNEW
« no previous file with comments | « ui/events/events.gyp ('k') | ui/events/gesture_detection/gesture_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698