xref: /aosp_15_r20/external/libchrome-gestures/include/gestures.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1*aed3e508SAndroid Build Coastguard Worker // Copyright 2012 The ChromiumOS Authors
2*aed3e508SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*aed3e508SAndroid Build Coastguard Worker // found in the LICENSE file.
4*aed3e508SAndroid Build Coastguard Worker 
5*aed3e508SAndroid Build Coastguard Worker #ifndef GESTURES_GESTURES_H__
6*aed3e508SAndroid Build Coastguard Worker #define GESTURES_GESTURES_H__
7*aed3e508SAndroid Build Coastguard Worker 
8*aed3e508SAndroid Build Coastguard Worker #include <stdint.h>
9*aed3e508SAndroid Build Coastguard Worker #include <sys/time.h>
10*aed3e508SAndroid Build Coastguard Worker #include <sys/types.h>
11*aed3e508SAndroid Build Coastguard Worker 
12*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
13*aed3e508SAndroid Build Coastguard Worker #include <string>
14*aed3e508SAndroid Build Coastguard Worker 
15*aed3e508SAndroid Build Coastguard Worker #include <memory>
16*aed3e508SAndroid Build Coastguard Worker 
17*aed3e508SAndroid Build Coastguard Worker extern "C" {
18*aed3e508SAndroid Build Coastguard Worker #endif
19*aed3e508SAndroid Build Coastguard Worker 
20*aed3e508SAndroid Build Coastguard Worker // C API:
21*aed3e508SAndroid Build Coastguard Worker 
22*aed3e508SAndroid Build Coastguard Worker // external logging interface
23*aed3e508SAndroid Build Coastguard Worker #define GESTURES_LOG_ERROR 0
24*aed3e508SAndroid Build Coastguard Worker #define GESTURES_LOG_INFO 1
25*aed3e508SAndroid Build Coastguard Worker 
26*aed3e508SAndroid Build Coastguard Worker // this function has to be provided by the user of the library.
27*aed3e508SAndroid Build Coastguard Worker void gestures_log(int verb, const char* format, ...)
28*aed3e508SAndroid Build Coastguard Worker     __attribute__((format(printf, 2, 3)));
29*aed3e508SAndroid Build Coastguard Worker 
30*aed3e508SAndroid Build Coastguard Worker typedef double stime_t;  // seconds
31*aed3e508SAndroid Build Coastguard Worker 
32*aed3e508SAndroid Build Coastguard Worker // Represents "unset" when stime_t is used for timeouts or deadlines.
33*aed3e508SAndroid Build Coastguard Worker #define NO_DEADLINE -1.0
34*aed3e508SAndroid Build Coastguard Worker 
35*aed3e508SAndroid Build Coastguard Worker enum GestureInterpreterDeviceClass {
36*aed3e508SAndroid Build Coastguard Worker   GESTURES_DEVCLASS_UNKNOWN,
37*aed3e508SAndroid Build Coastguard Worker   GESTURES_DEVCLASS_MOUSE,
38*aed3e508SAndroid Build Coastguard Worker   GESTURES_DEVCLASS_MULTITOUCH_MOUSE,
39*aed3e508SAndroid Build Coastguard Worker   GESTURES_DEVCLASS_TOUCHPAD,
40*aed3e508SAndroid Build Coastguard Worker   GESTURES_DEVCLASS_TOUCHSCREEN,
41*aed3e508SAndroid Build Coastguard Worker   GESTURES_DEVCLASS_POINTING_STICK,
42*aed3e508SAndroid Build Coastguard Worker };
43*aed3e508SAndroid Build Coastguard Worker 
44*aed3e508SAndroid Build Coastguard Worker stime_t StimeFromTimeval(const struct timeval*);
45*aed3e508SAndroid Build Coastguard Worker stime_t StimeFromTimespec(const struct timespec*);
46*aed3e508SAndroid Build Coastguard Worker 
47*aed3e508SAndroid Build Coastguard Worker // Describes the capabilities of a touchpad or mouse.
48*aed3e508SAndroid Build Coastguard Worker struct HardwareProperties {
49*aed3e508SAndroid Build Coastguard Worker   // Touch properties
50*aed3e508SAndroid Build Coastguard Worker   // The minimum X coordinate that the device can report.
51*aed3e508SAndroid Build Coastguard Worker   float left = 0;
52*aed3e508SAndroid Build Coastguard Worker   // The minimum Y coordinate that the device can report.
53*aed3e508SAndroid Build Coastguard Worker   float top = 0;
54*aed3e508SAndroid Build Coastguard Worker   // The maximum X coordinate that the device can report.
55*aed3e508SAndroid Build Coastguard Worker   float right;
56*aed3e508SAndroid Build Coastguard Worker   // The maximum Y coordinate that the device can report.
57*aed3e508SAndroid Build Coastguard Worker   float bottom;
58*aed3e508SAndroid Build Coastguard Worker   // The resolutions of the X and Y axes, in units per mm. Set to 0 if the
59*aed3e508SAndroid Build Coastguard Worker   // resolution is unknown.
60*aed3e508SAndroid Build Coastguard Worker   float res_x;
61*aed3e508SAndroid Build Coastguard Worker   float res_y;
62*aed3e508SAndroid Build Coastguard Worker 
63*aed3e508SAndroid Build Coastguard Worker   // The minimum and maximum orientation values.
64*aed3e508SAndroid Build Coastguard Worker   float orientation_minimum;
65*aed3e508SAndroid Build Coastguard Worker   float orientation_maximum;
66*aed3e508SAndroid Build Coastguard Worker 
67*aed3e508SAndroid Build Coastguard Worker   // The maximum number of finger slots that the device can report in one
68*aed3e508SAndroid Build Coastguard Worker   // HardwareState struct.
69*aed3e508SAndroid Build Coastguard Worker   unsigned short max_finger_cnt;
70*aed3e508SAndroid Build Coastguard Worker   // The maximum number of contacts that the device can detect at once, whether
71*aed3e508SAndroid Build Coastguard Worker   // or not it can report their coordinates.
72*aed3e508SAndroid Build Coastguard Worker   unsigned short max_touch_cnt;
73*aed3e508SAndroid Build Coastguard Worker 
74*aed3e508SAndroid Build Coastguard Worker   // Whether this is a "Track 5, Report 2" touchpad, which can track up to five
75*aed3e508SAndroid Build Coastguard Worker   // fingers but only report the locations of two. (For more details, see
76*aed3e508SAndroid Build Coastguard Worker   // https://crrev.com/37cccb42e652b50f9e788d90e82252f78c78f1ed)
77*aed3e508SAndroid Build Coastguard Worker   unsigned supports_t5r2:1;
78*aed3e508SAndroid Build Coastguard Worker 
79*aed3e508SAndroid Build Coastguard Worker   // Whether this is a "Semi-Multitouch" touchpad, which can detect two separate
80*aed3e508SAndroid Build Coastguard Worker   // fingers but only report their bounding box, not individual locations.
81*aed3e508SAndroid Build Coastguard Worker   unsigned support_semi_mt:1;
82*aed3e508SAndroid Build Coastguard Worker 
83*aed3e508SAndroid Build Coastguard Worker   // Whether the touchpad has a button under its touch surface, allowing the
84*aed3e508SAndroid Build Coastguard Worker   // user to click by pressing (almost) anywhere on the pad, as opposed to
85*aed3e508SAndroid Build Coastguard Worker   // having one or more separate buttons for clicking.
86*aed3e508SAndroid Build Coastguard Worker   unsigned is_button_pad:1;
87*aed3e508SAndroid Build Coastguard Worker 
88*aed3e508SAndroid Build Coastguard Worker   // Mouse properties
89*aed3e508SAndroid Build Coastguard Worker   // Whether the mouse has a scroll wheel.
90*aed3e508SAndroid Build Coastguard Worker   unsigned has_wheel:1;
91*aed3e508SAndroid Build Coastguard Worker   // Whether the mouse's scroll wheel is high-resolution (reported through the
92*aed3e508SAndroid Build Coastguard Worker   // rel_wheel_hi_res field of the HardwareState struct).
93*aed3e508SAndroid Build Coastguard Worker   unsigned wheel_is_hi_res:1;
94*aed3e508SAndroid Build Coastguard Worker 
95*aed3e508SAndroid Build Coastguard Worker   // Whether the touchpad is haptic, meaning that it reports true pressure (not
96*aed3e508SAndroid Build Coastguard Worker   // just touch area) via the pressure axis, and can provide haptic feedback.
97*aed3e508SAndroid Build Coastguard Worker   unsigned is_haptic_pad:1;
98*aed3e508SAndroid Build Coastguard Worker 
99*aed3e508SAndroid Build Coastguard Worker   // Whether the touchpad reports pressure values in any way.
100*aed3e508SAndroid Build Coastguard Worker   bool reports_pressure = true;
101*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
102*aed3e508SAndroid Build Coastguard Worker   std::string String() const;
103*aed3e508SAndroid Build Coastguard Worker #endif  // __cplusplus
104*aed3e508SAndroid Build Coastguard Worker };
105*aed3e508SAndroid Build Coastguard Worker 
106*aed3e508SAndroid Build Coastguard Worker // Warp: If a finger has the 'warp' flag set for an axis, it means that while
107*aed3e508SAndroid Build Coastguard Worker // the finger may have moved, it should not cause any motion in that direction.
108*aed3e508SAndroid Build Coastguard Worker // This may occur is some situations where we thought a finger was in one place,
109*aed3e508SAndroid Build Coastguard Worker // but then we realized later it was actually in another place.
110*aed3e508SAndroid Build Coastguard Worker // The *_WARP_X/Y_MOVE version is an indication for suppressing unwanted
111*aed3e508SAndroid Build Coastguard Worker // cursor movement, while the *_WARP_X/Y_NON_MOVE version is for unwanted
112*aed3e508SAndroid Build Coastguard Worker // non-cursor movement (e.g. scrolling)
113*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_X_NON_MOVE        (1 << 0)
114*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_Y_NON_MOVE        (1 << 1)
115*aed3e508SAndroid Build Coastguard Worker // If a finger has notap set, it shouldn't begin a tap gesture.
116*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_NO_TAP        (1 << 2)
117*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_POSSIBLE_PALM (1 << 3)
118*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_PALM          (1 << 4)
119*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_X_MOVE   (1 << 5)
120*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_Y_MOVE   (1 << 6)
121*aed3e508SAndroid Build Coastguard Worker // If tap to click movement detection should warp:
122*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_X_TAP_MOVE   (1 << 7)
123*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_Y_TAP_MOVE   (1 << 8)
124*aed3e508SAndroid Build Coastguard Worker // If a finger is a merged finger or one of close fingers
125*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_MERGE   (1 << 9)
126*aed3e508SAndroid Build Coastguard Worker // If a finger is showing a trend of moving (see the TrendClassifyingFilter).
127*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_INC_X (1 << 10)
128*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_DEC_X (1 << 11)
129*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_INC_Y (1 << 12)
130*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_DEC_Y (1 << 13)
131*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_INC_PRESSURE (1 << 14)
132*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_DEC_PRESSURE (1 << 15)
133*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_INC_TOUCH_MAJOR (1 << 16)
134*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_TREND_DEC_TOUCH_MAJOR (1 << 17)
135*aed3e508SAndroid Build Coastguard Worker // If a finger is non-stationary recently (see the StationaryWiggleFilter).
136*aed3e508SAndroid Build Coastguard Worker // Compared to the trend flags, this one takes the magnitude of movements
137*aed3e508SAndroid Build Coastguard Worker // into account so it might be more useful in some cases. However, it is also
138*aed3e508SAndroid Build Coastguard Worker // more prone to abrupt noisy jumps than the trend flags. It also looks at
139*aed3e508SAndroid Build Coastguard Worker // a shorter period of time than the trend ones so it may provide faster
140*aed3e508SAndroid Build Coastguard Worker // response and lower latency.
141*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_INSTANTANEOUS_MOVING (1 << 18)
142*aed3e508SAndroid Build Coastguard Worker // We sometimes use the warp flags only because we want to suppress unwanted
143*aed3e508SAndroid Build Coastguard Worker // movements and not that we really have no good idea of the finger position.
144*aed3e508SAndroid Build Coastguard Worker // This poses additional difficulty for some classifying logics that relies
145*aed3e508SAndroid Build Coastguard Worker // much on the finger position. To maximize the use of any available data,
146*aed3e508SAndroid Build Coastguard Worker // we further mark a finger as GESTURES_FINGER_WARP_TELEPORTATION only if we
147*aed3e508SAndroid Build Coastguard Worker // indeed have no idea of its position (e.g. due to sensor jumps). For all
148*aed3e508SAndroid Build Coastguard Worker // other cases (e.g. click wiggle, plams suppression, stationary wiggle), we
149*aed3e508SAndroid Build Coastguard Worker // skip the flag so that we can have the option to use the not-that-accurate
150*aed3e508SAndroid Build Coastguard Worker // positions.
151*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_TELEPORTATION (1 << 19)
152*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_LARGE_PALM (1 << 20)
153*aed3e508SAndroid Build Coastguard Worker 
154*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_X    (GESTURES_FINGER_WARP_X_NON_MOVE | \
155*aed3e508SAndroid Build Coastguard Worker                                    GESTURES_FINGER_WARP_X_MOVE)
156*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FINGER_WARP_Y    (GESTURES_FINGER_WARP_Y_NON_MOVE | \
157*aed3e508SAndroid Build Coastguard Worker                                    GESTURES_FINGER_WARP_Y_MOVE)
158*aed3e508SAndroid Build Coastguard Worker 
159*aed3e508SAndroid Build Coastguard Worker // Describes a single contact on a touch surface. Generally, the fields have the
160*aed3e508SAndroid Build Coastguard Worker // same meaning as the equivalent ABS_MT_... axis in the Linux evdev protocol.
161*aed3e508SAndroid Build Coastguard Worker struct FingerState {
162*aed3e508SAndroid Build Coastguard Worker   enum class ToolType {
163*aed3e508SAndroid Build Coastguard Worker     kFinger = 0,
164*aed3e508SAndroid Build Coastguard Worker     kPalm,
165*aed3e508SAndroid Build Coastguard Worker   };
166*aed3e508SAndroid Build Coastguard Worker   // The large and small radii of the ellipse of the finger touching the pad.
167*aed3e508SAndroid Build Coastguard Worker   float touch_major, touch_minor;
168*aed3e508SAndroid Build Coastguard Worker 
169*aed3e508SAndroid Build Coastguard Worker   // The large and small radii of the ellipse of the finger, including parts
170*aed3e508SAndroid Build Coastguard Worker   // that are hovering over the pad but not quite touching. Devices normally
171*aed3e508SAndroid Build Coastguard Worker   // don't report these values, in which case they should be left at 0.
172*aed3e508SAndroid Build Coastguard Worker   float width_major, width_minor;
173*aed3e508SAndroid Build Coastguard Worker   float pressure;
174*aed3e508SAndroid Build Coastguard Worker   float orientation;
175*aed3e508SAndroid Build Coastguard Worker 
176*aed3e508SAndroid Build Coastguard Worker   float position_x;
177*aed3e508SAndroid Build Coastguard Worker   float position_y;
178*aed3e508SAndroid Build Coastguard Worker 
179*aed3e508SAndroid Build Coastguard Worker   // A number that identifies a single physical finger across consecutive
180*aed3e508SAndroid Build Coastguard Worker   // frames. If a finger is the same physical finger across two consecutive
181*aed3e508SAndroid Build Coastguard Worker   // frames, it must have the same tracking ID; if it's a different finger, it
182*aed3e508SAndroid Build Coastguard Worker   // should have a different tracking ID. It should be ≥ 0 (see documentation
183*aed3e508SAndroid Build Coastguard Worker   // comment for HardwareState::fingers).
184*aed3e508SAndroid Build Coastguard Worker   short tracking_id;
185*aed3e508SAndroid Build Coastguard Worker 
186*aed3e508SAndroid Build Coastguard Worker   // A bit field of flags that are used internally by the library. (See the
187*aed3e508SAndroid Build Coastguard Worker   // GESTURES_FINGER_* constants.) Should be set to 0 on incoming FingerStates.
188*aed3e508SAndroid Build Coastguard Worker   unsigned flags;
189*aed3e508SAndroid Build Coastguard Worker 
190*aed3e508SAndroid Build Coastguard Worker   ToolType tool_type = ToolType::kFinger;
191*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
NonFlagsEqualsFingerState192*aed3e508SAndroid Build Coastguard Worker   bool NonFlagsEquals(const FingerState& that) const {
193*aed3e508SAndroid Build Coastguard Worker     return touch_major == that.touch_major &&
194*aed3e508SAndroid Build Coastguard Worker         touch_minor == that.touch_minor &&
195*aed3e508SAndroid Build Coastguard Worker         width_major == that.width_major &&
196*aed3e508SAndroid Build Coastguard Worker         width_minor == that.width_minor &&
197*aed3e508SAndroid Build Coastguard Worker         pressure == that.pressure &&
198*aed3e508SAndroid Build Coastguard Worker         orientation == that.orientation &&
199*aed3e508SAndroid Build Coastguard Worker         position_x == that.position_x &&
200*aed3e508SAndroid Build Coastguard Worker         position_y == that.position_y &&
201*aed3e508SAndroid Build Coastguard Worker         tracking_id == that.tracking_id;
202*aed3e508SAndroid Build Coastguard Worker   }
203*aed3e508SAndroid Build Coastguard Worker   bool operator==(const FingerState& that) const {
204*aed3e508SAndroid Build Coastguard Worker     return NonFlagsEquals(that) && flags == that.flags;
205*aed3e508SAndroid Build Coastguard Worker   }
206*aed3e508SAndroid Build Coastguard Worker   bool operator!=(const FingerState& that) const { return !(*this == that); }
207*aed3e508SAndroid Build Coastguard Worker   static std::string FlagsString(unsigned flags);
208*aed3e508SAndroid Build Coastguard Worker   std::string String() const;
209*aed3e508SAndroid Build Coastguard Worker #endif
210*aed3e508SAndroid Build Coastguard Worker };
211*aed3e508SAndroid Build Coastguard Worker 
212*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_NONE 0
213*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_LEFT 1
214*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_MIDDLE 2
215*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_RIGHT 4
216*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_BACK 8
217*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_FORWARD 16
218*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_SIDE 32
219*aed3e508SAndroid Build Coastguard Worker #define GESTURES_BUTTON_EXTRA 64
220*aed3e508SAndroid Build Coastguard Worker 
221*aed3e508SAndroid Build Coastguard Worker // Describes one frame of data from the input device.
222*aed3e508SAndroid Build Coastguard Worker struct HardwareState {
223*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
224*aed3e508SAndroid Build Coastguard Worker   FingerState* GetFingerState(short tracking_id);
225*aed3e508SAndroid Build Coastguard Worker   const FingerState* GetFingerState(short tracking_id) const;
226*aed3e508SAndroid Build Coastguard Worker   bool SameFingersAs(const HardwareState& that) const;
227*aed3e508SAndroid Build Coastguard Worker   std::string String() const;
228*aed3e508SAndroid Build Coastguard Worker   void DeepCopy(const HardwareState& that, unsigned short max_finger_cnt);
229*aed3e508SAndroid Build Coastguard Worker #endif  // __cplusplus
230*aed3e508SAndroid Build Coastguard Worker   // The time at which the event was received by the system.
231*aed3e508SAndroid Build Coastguard Worker   stime_t timestamp;
232*aed3e508SAndroid Build Coastguard Worker   // A bit field indicating which buttons are pressed. (See the
233*aed3e508SAndroid Build Coastguard Worker   // GESTURES_BUTTON_* constants.)
234*aed3e508SAndroid Build Coastguard Worker   int buttons_down;
235*aed3e508SAndroid Build Coastguard Worker   // The number of FingerState structs pointed to by the fingers field.
236*aed3e508SAndroid Build Coastguard Worker   unsigned short finger_cnt;
237*aed3e508SAndroid Build Coastguard Worker   // The number of fingers touching the pad, which may be more than finger_cnt.
238*aed3e508SAndroid Build Coastguard Worker   unsigned short touch_cnt;
239*aed3e508SAndroid Build Coastguard Worker   // A pointer to an array of FingerState structs with finger_cnt entries,
240*aed3e508SAndroid Build Coastguard Worker   // representing the contacts currently being tracked. If finger_cnt is 0, this
241*aed3e508SAndroid Build Coastguard Worker   // pointer will be null.
242*aed3e508SAndroid Build Coastguard Worker   //
243*aed3e508SAndroid Build Coastguard Worker   // The order in which FingerStates appear need not be stable between
244*aed3e508SAndroid Build Coastguard Worker   // HardwareStates — only the tracking ID is used to track individual contacts
245*aed3e508SAndroid Build Coastguard Worker   // over time. Accordingly, when a finger is lifted from the pad (and therefore
246*aed3e508SAndroid Build Coastguard Worker   // its ABS_MT_TRACKING_ID becomes -1), the client should simply stop including
247*aed3e508SAndroid Build Coastguard Worker   // it in this array, rather than including a final FingerState for it.
248*aed3e508SAndroid Build Coastguard Worker   struct FingerState* fingers;
249*aed3e508SAndroid Build Coastguard Worker 
250*aed3e508SAndroid Build Coastguard Worker   // Mouse axes, which have the same meanings as the Linux evdev axes of the
251*aed3e508SAndroid Build Coastguard Worker   // same name.
252*aed3e508SAndroid Build Coastguard Worker   float rel_x;
253*aed3e508SAndroid Build Coastguard Worker   float rel_y;
254*aed3e508SAndroid Build Coastguard Worker   float rel_wheel;
255*aed3e508SAndroid Build Coastguard Worker   float rel_wheel_hi_res;
256*aed3e508SAndroid Build Coastguard Worker   float rel_hwheel;
257*aed3e508SAndroid Build Coastguard Worker 
258*aed3e508SAndroid Build Coastguard Worker   // The timestamp for the frame, as reported by the device's firmware. This may
259*aed3e508SAndroid Build Coastguard Worker   // be different from the timestamp field above, for example if events were
260*aed3e508SAndroid Build Coastguard Worker   // batched when being sent over Bluetooth. Set to 0.0 if no such timestamp is
261*aed3e508SAndroid Build Coastguard Worker   // available. (Named after the MSC_TIMESTAMP axis from evdev.)
262*aed3e508SAndroid Build Coastguard Worker   stime_t msc_timestamp;
263*aed3e508SAndroid Build Coastguard Worker };
264*aed3e508SAndroid Build Coastguard Worker 
265*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FLING_START 0  // Scroll end/fling begin
266*aed3e508SAndroid Build Coastguard Worker #define GESTURES_FLING_TAP_DOWN 1  // Finger touched down/fling end
267*aed3e508SAndroid Build Coastguard Worker 
268*aed3e508SAndroid Build Coastguard Worker #define GESTURES_ZOOM_START 0  // Pinch zoom begin
269*aed3e508SAndroid Build Coastguard Worker #define GESTURES_ZOOM_UPDATE 1  // Zoom-in/Zoom-out update
270*aed3e508SAndroid Build Coastguard Worker #define GESTURES_ZOOM_END 2  // Pinch zoom end
271*aed3e508SAndroid Build Coastguard Worker 
272*aed3e508SAndroid Build Coastguard Worker // Gesture sub-structs
273*aed3e508SAndroid Build Coastguard Worker 
274*aed3e508SAndroid Build Coastguard Worker // Note about ordinal_* values: Sometimes, UI will want to use unaccelerated
275*aed3e508SAndroid Build Coastguard Worker // values for various gestures, so we expose the non-accelerated values in
276*aed3e508SAndroid Build Coastguard Worker // the ordinal_* fields.
277*aed3e508SAndroid Build Coastguard Worker 
278*aed3e508SAndroid Build Coastguard Worker typedef struct {
279*aed3e508SAndroid Build Coastguard Worker   // The movement in the X axis. Positive values indicate motion to the right.
280*aed3e508SAndroid Build Coastguard Worker   float dx;
281*aed3e508SAndroid Build Coastguard Worker   // The movement in the Y axis. Positive values indicate downwards motion.
282*aed3e508SAndroid Build Coastguard Worker   float dy;
283*aed3e508SAndroid Build Coastguard Worker   float ordinal_dx, ordinal_dy;
284*aed3e508SAndroid Build Coastguard Worker } GestureMove;
285*aed3e508SAndroid Build Coastguard Worker 
286*aed3e508SAndroid Build Coastguard Worker // Represents scroll gestures on a touch device.
287*aed3e508SAndroid Build Coastguard Worker typedef struct{
288*aed3e508SAndroid Build Coastguard Worker   // The scroll movement in the X axis. Unlike with move gestures, *negative*
289*aed3e508SAndroid Build Coastguard Worker   // values indicate the fingers moving to the right, unless the "Australian
290*aed3e508SAndroid Build Coastguard Worker   // Scrolling" or "Invert Scrolling" properties are set.
291*aed3e508SAndroid Build Coastguard Worker   float dx;
292*aed3e508SAndroid Build Coastguard Worker   // The scroll movement in the Y axis. Unlike with move gestures, *negative*
293*aed3e508SAndroid Build Coastguard Worker   // values indicate the fingers moving downwards, unless the "Australian
294*aed3e508SAndroid Build Coastguard Worker   // Scrolling" or "Invert Scrolling" properties are set.
295*aed3e508SAndroid Build Coastguard Worker   float dy;
296*aed3e508SAndroid Build Coastguard Worker   float ordinal_dx, ordinal_dy;
297*aed3e508SAndroid Build Coastguard Worker   // If set, stop_fling means that this scroll should stop flinging, thus
298*aed3e508SAndroid Build Coastguard Worker   // if an interpreter suppresses it for any reason (e.g., rounds the size
299*aed3e508SAndroid Build Coastguard Worker   // down to 0, thus making it a noop), it will replace it with a Fling
300*aed3e508SAndroid Build Coastguard Worker   // TAP_DOWN gesture
301*aed3e508SAndroid Build Coastguard Worker   unsigned stop_fling:1;
302*aed3e508SAndroid Build Coastguard Worker } GestureScroll;
303*aed3e508SAndroid Build Coastguard Worker 
304*aed3e508SAndroid Build Coastguard Worker // Represents mouse wheel movements.
305*aed3e508SAndroid Build Coastguard Worker typedef struct {
306*aed3e508SAndroid Build Coastguard Worker   // The amount to scroll by, after acceleration and scaling have been applied.
307*aed3e508SAndroid Build Coastguard Worker   float dx, dy;
308*aed3e508SAndroid Build Coastguard Worker   // The amount the wheel actually moved. A change of 120 represents moving the
309*aed3e508SAndroid Build Coastguard Worker   // wheel one whole tick (a.k.a. notch).
310*aed3e508SAndroid Build Coastguard Worker   int tick_120ths_dx, tick_120ths_dy;
311*aed3e508SAndroid Build Coastguard Worker } GestureMouseWheel;
312*aed3e508SAndroid Build Coastguard Worker 
313*aed3e508SAndroid Build Coastguard Worker typedef struct {
314*aed3e508SAndroid Build Coastguard Worker   // If a bit is set in both down and up, client should process down first
315*aed3e508SAndroid Build Coastguard Worker   unsigned down;  // bit field, use GESTURES_BUTTON_*
316*aed3e508SAndroid Build Coastguard Worker   unsigned up;  // bit field, use GESTURES_BUTTON_*
317*aed3e508SAndroid Build Coastguard Worker   bool is_tap; // was the gesture generated with tap-to-click?
318*aed3e508SAndroid Build Coastguard Worker } GestureButtonsChange;
319*aed3e508SAndroid Build Coastguard Worker 
320*aed3e508SAndroid Build Coastguard Worker typedef struct {
321*aed3e508SAndroid Build Coastguard Worker   // The fling velocity in the X axis, only valid when fling_state is
322*aed3e508SAndroid Build Coastguard Worker   // GESTURES_FLING_START. Unlike with move gestures, *negative* values indicate
323*aed3e508SAndroid Build Coastguard Worker   // the fingers moving to the right, unless the "Australian Scrolling" or
324*aed3e508SAndroid Build Coastguard Worker   // "Invert Scrolling" properties are set.
325*aed3e508SAndroid Build Coastguard Worker   float vx;
326*aed3e508SAndroid Build Coastguard Worker   // The fling velocity in the Y axis, only valid when fling_state is
327*aed3e508SAndroid Build Coastguard Worker   // GESTURES_FLING_START. Unlike with move gestures, *negative* values indicate
328*aed3e508SAndroid Build Coastguard Worker   // the fingers moving downwards, unless the "Australian Scrolling" or "Invert
329*aed3e508SAndroid Build Coastguard Worker   // Scrolling" properties are set.
330*aed3e508SAndroid Build Coastguard Worker   float vy;
331*aed3e508SAndroid Build Coastguard Worker   float ordinal_vx, ordinal_vy;
332*aed3e508SAndroid Build Coastguard Worker   unsigned fling_state:1;  // GESTURES_FLING_START or GESTURES_FLING_TAP_DOWN
333*aed3e508SAndroid Build Coastguard Worker } GestureFling;
334*aed3e508SAndroid Build Coastguard Worker 
335*aed3e508SAndroid Build Coastguard Worker typedef struct {
336*aed3e508SAndroid Build Coastguard Worker   // The swipe movement in the X axis. Positive values indicate motion to the
337*aed3e508SAndroid Build Coastguard Worker   // right.
338*aed3e508SAndroid Build Coastguard Worker   float dx;
339*aed3e508SAndroid Build Coastguard Worker   // The swipe movement in the Y axis. Unlike with move gestures, *negative*
340*aed3e508SAndroid Build Coastguard Worker   // values indicate downwards motion, unless the "Australian Scrolling"
341*aed3e508SAndroid Build Coastguard Worker   // property is set.
342*aed3e508SAndroid Build Coastguard Worker   float dy;
343*aed3e508SAndroid Build Coastguard Worker   float ordinal_dx, ordinal_dy;
344*aed3e508SAndroid Build Coastguard Worker } GestureSwipe;
345*aed3e508SAndroid Build Coastguard Worker 
346*aed3e508SAndroid Build Coastguard Worker typedef struct {
347*aed3e508SAndroid Build Coastguard Worker   // The swipe movement in the X axis. Positive values indicate motion to the
348*aed3e508SAndroid Build Coastguard Worker   // right.
349*aed3e508SAndroid Build Coastguard Worker   float dx;
350*aed3e508SAndroid Build Coastguard Worker   // The swipe movement in the Y axis. Unlike with move gestures, *negative*
351*aed3e508SAndroid Build Coastguard Worker   // values indicate downwards motion, unless the "Australian Scrolling"
352*aed3e508SAndroid Build Coastguard Worker   // property is set.
353*aed3e508SAndroid Build Coastguard Worker   float dy;
354*aed3e508SAndroid Build Coastguard Worker   float ordinal_dx, ordinal_dy;
355*aed3e508SAndroid Build Coastguard Worker } GestureFourFingerSwipe;
356*aed3e508SAndroid Build Coastguard Worker 
357*aed3e508SAndroid Build Coastguard Worker typedef struct {
358*aed3e508SAndroid Build Coastguard Worker   char __dummy;
359*aed3e508SAndroid Build Coastguard Worker   // Remove this when there is a member in this struct. http://crbug.com/341155
360*aed3e508SAndroid Build Coastguard Worker   // Currently no members
361*aed3e508SAndroid Build Coastguard Worker } GestureFourFingerSwipeLift;
362*aed3e508SAndroid Build Coastguard Worker 
363*aed3e508SAndroid Build Coastguard Worker typedef struct {
364*aed3e508SAndroid Build Coastguard Worker   char __dummy;
365*aed3e508SAndroid Build Coastguard Worker   // Remove this when there is a member in this struct. http://crbug.com/341155
366*aed3e508SAndroid Build Coastguard Worker   // Currently no members
367*aed3e508SAndroid Build Coastguard Worker } GestureSwipeLift;
368*aed3e508SAndroid Build Coastguard Worker 
369*aed3e508SAndroid Build Coastguard Worker typedef struct {
370*aed3e508SAndroid Build Coastguard Worker   // Relative pinch factor starting with 1.0 = no pinch
371*aed3e508SAndroid Build Coastguard Worker   // <1.0 for outwards pinch
372*aed3e508SAndroid Build Coastguard Worker   // >1.0 for inwards pinch
373*aed3e508SAndroid Build Coastguard Worker   float dz;
374*aed3e508SAndroid Build Coastguard Worker   float ordinal_dz;
375*aed3e508SAndroid Build Coastguard Worker   // GESTURES_ZOOM_START, GESTURES_ZOOM_UPDATE, or GESTURES_ZOOM_END
376*aed3e508SAndroid Build Coastguard Worker   unsigned zoom_state;
377*aed3e508SAndroid Build Coastguard Worker } GesturePinch;
378*aed3e508SAndroid Build Coastguard Worker 
379*aed3e508SAndroid Build Coastguard Worker // Metrics types that we care about
380*aed3e508SAndroid Build Coastguard Worker enum GestureMetricsType {
381*aed3e508SAndroid Build Coastguard Worker   kGestureMetricsTypeNoisyGround = 0,
382*aed3e508SAndroid Build Coastguard Worker   kGestureMetricsTypeMouseMovement,
383*aed3e508SAndroid Build Coastguard Worker   kGestureMetricsTypeUnknown,
384*aed3e508SAndroid Build Coastguard Worker };
385*aed3e508SAndroid Build Coastguard Worker 
386*aed3e508SAndroid Build Coastguard Worker typedef struct {
387*aed3e508SAndroid Build Coastguard Worker   enum GestureMetricsType type;
388*aed3e508SAndroid Build Coastguard Worker   // Optional values for the metrics. 2 are more than enough for now.
389*aed3e508SAndroid Build Coastguard Worker   float data[2];
390*aed3e508SAndroid Build Coastguard Worker } GestureMetrics;
391*aed3e508SAndroid Build Coastguard Worker 
392*aed3e508SAndroid Build Coastguard Worker // Describes the type of gesture that is being reported.
393*aed3e508SAndroid Build Coastguard Worker enum GestureType {
394*aed3e508SAndroid Build Coastguard Worker #ifdef GESTURES_INTERNAL
395*aed3e508SAndroid Build Coastguard Worker   kGestureTypeNull = -1,  // internal to Gestures library only
396*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_INTERNAL
397*aed3e508SAndroid Build Coastguard Worker   // No longer used.
398*aed3e508SAndroid Build Coastguard Worker   kGestureTypeContactInitiated = 0,
399*aed3e508SAndroid Build Coastguard Worker   // For touchpads, a movement of a single finger on the pad. For mice, a
400*aed3e508SAndroid Build Coastguard Worker   // movement of the whole mouse.
401*aed3e508SAndroid Build Coastguard Worker   kGestureTypeMove,
402*aed3e508SAndroid Build Coastguard Worker   // A two-finger scroll gesture on a touchpad. (See kGestureTypeMouseWheel for
403*aed3e508SAndroid Build Coastguard Worker   // the mouse equivalent.)
404*aed3e508SAndroid Build Coastguard Worker   kGestureTypeScroll,
405*aed3e508SAndroid Build Coastguard Worker   // A change in the buttons that are currently pressed on the device.
406*aed3e508SAndroid Build Coastguard Worker   kGestureTypeButtonsChange,
407*aed3e508SAndroid Build Coastguard Worker   // The start or end of a fling motion, where scrolling should continue after
408*aed3e508SAndroid Build Coastguard Worker   // the user's fingers have left the touchpad.
409*aed3e508SAndroid Build Coastguard Worker   kGestureTypeFling,
410*aed3e508SAndroid Build Coastguard Worker   // A movement of three fingers on a touchpad.
411*aed3e508SAndroid Build Coastguard Worker   kGestureTypeSwipe,
412*aed3e508SAndroid Build Coastguard Worker   // A movement of two fingers on a touchpad that are primarily moving closer to
413*aed3e508SAndroid Build Coastguard Worker   // or further from each other.
414*aed3e508SAndroid Build Coastguard Worker   kGestureTypePinch,
415*aed3e508SAndroid Build Coastguard Worker   // The end of a movement of three fingers on a touchpad.
416*aed3e508SAndroid Build Coastguard Worker   kGestureTypeSwipeLift,
417*aed3e508SAndroid Build Coastguard Worker   // Used to report metrics to the client.
418*aed3e508SAndroid Build Coastguard Worker   kGestureTypeMetrics,
419*aed3e508SAndroid Build Coastguard Worker   // A movement of four fingers on a touchpad.
420*aed3e508SAndroid Build Coastguard Worker   kGestureTypeFourFingerSwipe,
421*aed3e508SAndroid Build Coastguard Worker   // The end of a movement of four fingers on a touchpad.
422*aed3e508SAndroid Build Coastguard Worker   kGestureTypeFourFingerSwipeLift,
423*aed3e508SAndroid Build Coastguard Worker   // The movement of a scroll wheel on a mouse.
424*aed3e508SAndroid Build Coastguard Worker   kGestureTypeMouseWheel,
425*aed3e508SAndroid Build Coastguard Worker };
426*aed3e508SAndroid Build Coastguard Worker 
427*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
428*aed3e508SAndroid Build Coastguard Worker // Pass these into Gesture() ctor as first arg
429*aed3e508SAndroid Build Coastguard Worker extern const GestureMove kGestureMove;
430*aed3e508SAndroid Build Coastguard Worker extern const GestureScroll kGestureScroll;
431*aed3e508SAndroid Build Coastguard Worker extern const GestureMouseWheel kGestureMouseWheel;
432*aed3e508SAndroid Build Coastguard Worker extern const GestureButtonsChange kGestureButtonsChange;
433*aed3e508SAndroid Build Coastguard Worker extern const GestureFling kGestureFling;
434*aed3e508SAndroid Build Coastguard Worker extern const GestureSwipe kGestureSwipe;
435*aed3e508SAndroid Build Coastguard Worker extern const GestureFourFingerSwipe kGestureFourFingerSwipe;
436*aed3e508SAndroid Build Coastguard Worker extern const GesturePinch kGesturePinch;
437*aed3e508SAndroid Build Coastguard Worker extern const GestureSwipeLift kGestureSwipeLift;
438*aed3e508SAndroid Build Coastguard Worker extern const GestureFourFingerSwipeLift kGestureFourFingerSwipeLift;
439*aed3e508SAndroid Build Coastguard Worker extern const GestureMetrics kGestureMetrics;
440*aed3e508SAndroid Build Coastguard Worker #endif  // __cplusplus
441*aed3e508SAndroid Build Coastguard Worker 
442*aed3e508SAndroid Build Coastguard Worker struct Gesture {
443*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
444*aed3e508SAndroid Build Coastguard Worker   // Create Move/Scroll gesture
445*aed3e508SAndroid Build Coastguard Worker #ifdef GESTURES_INTERNAL
GestureGesture446*aed3e508SAndroid Build Coastguard Worker   Gesture() : start_time(0), end_time(0), type(kGestureTypeNull) {}
447*aed3e508SAndroid Build Coastguard Worker   bool operator==(const Gesture& that) const;
448*aed3e508SAndroid Build Coastguard Worker   bool operator!=(const Gesture& that) const { return !(*this == that); };
449*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_INTERNAL
450*aed3e508SAndroid Build Coastguard Worker   std::string String() const;
GestureGesture451*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureMove&, stime_t start, stime_t end, float dx, float dy)
452*aed3e508SAndroid Build Coastguard Worker       : start_time(start), end_time(end), type(kGestureTypeMove) {
453*aed3e508SAndroid Build Coastguard Worker     details.move.ordinal_dx = details.move.dx = dx;
454*aed3e508SAndroid Build Coastguard Worker     details.move.ordinal_dy = details.move.dy = dy;
455*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture456*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureScroll&,
457*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, float dx, float dy)
458*aed3e508SAndroid Build Coastguard Worker       : start_time(start), end_time(end), type(kGestureTypeScroll) {
459*aed3e508SAndroid Build Coastguard Worker     details.scroll.ordinal_dx = details.scroll.dx = dx;
460*aed3e508SAndroid Build Coastguard Worker     details.scroll.ordinal_dy = details.scroll.dy = dy;
461*aed3e508SAndroid Build Coastguard Worker     details.scroll.stop_fling = 0;
462*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture463*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureMouseWheel&,
464*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, float dx, float dy, int tick_120ths_dx,
465*aed3e508SAndroid Build Coastguard Worker           int tick_120ths_dy)
466*aed3e508SAndroid Build Coastguard Worker       : start_time(start), end_time(end), type(kGestureTypeMouseWheel) {
467*aed3e508SAndroid Build Coastguard Worker     details.wheel.dx = dx;
468*aed3e508SAndroid Build Coastguard Worker     details.wheel.dy = dy;
469*aed3e508SAndroid Build Coastguard Worker     details.wheel.tick_120ths_dx = tick_120ths_dx;
470*aed3e508SAndroid Build Coastguard Worker     details.wheel.tick_120ths_dy = tick_120ths_dy;
471*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture472*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureButtonsChange&,
473*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, unsigned down, unsigned up, bool is_tap)
474*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
475*aed3e508SAndroid Build Coastguard Worker         end_time(end),
476*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypeButtonsChange) {
477*aed3e508SAndroid Build Coastguard Worker     details.buttons.down = down;
478*aed3e508SAndroid Build Coastguard Worker     details.buttons.up = up;
479*aed3e508SAndroid Build Coastguard Worker     details.buttons.is_tap = is_tap;
480*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture481*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureFling&,
482*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, float vx, float vy, unsigned state)
483*aed3e508SAndroid Build Coastguard Worker       : start_time(start), end_time(end), type(kGestureTypeFling) {
484*aed3e508SAndroid Build Coastguard Worker     details.fling.ordinal_vx = details.fling.vx = vx;
485*aed3e508SAndroid Build Coastguard Worker     details.fling.ordinal_vy = details.fling.vy = vy;
486*aed3e508SAndroid Build Coastguard Worker     details.fling.fling_state = state;
487*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture488*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureSwipe&,
489*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, float dx, float dy)
490*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
491*aed3e508SAndroid Build Coastguard Worker         end_time(end),
492*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypeSwipe) {
493*aed3e508SAndroid Build Coastguard Worker     details.swipe.ordinal_dx = details.swipe.dx = dx;
494*aed3e508SAndroid Build Coastguard Worker     details.swipe.ordinal_dy = details.swipe.dy = dy;
495*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture496*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureFourFingerSwipe&,
497*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, float dx, float dy)
498*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
499*aed3e508SAndroid Build Coastguard Worker         end_time(end),
500*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypeFourFingerSwipe) {
501*aed3e508SAndroid Build Coastguard Worker     details.four_finger_swipe.ordinal_dx = details.four_finger_swipe.dx = dx;
502*aed3e508SAndroid Build Coastguard Worker     details.four_finger_swipe.ordinal_dy = details.four_finger_swipe.dy = dy;
503*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture504*aed3e508SAndroid Build Coastguard Worker   Gesture(const GesturePinch&,
505*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, float dz, unsigned state)
506*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
507*aed3e508SAndroid Build Coastguard Worker         end_time(end),
508*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypePinch) {
509*aed3e508SAndroid Build Coastguard Worker     details.pinch.ordinal_dz = details.pinch.dz = dz;
510*aed3e508SAndroid Build Coastguard Worker     details.pinch.zoom_state = state;
511*aed3e508SAndroid Build Coastguard Worker   }
GestureGesture512*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureSwipeLift&, stime_t start, stime_t end)
513*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
514*aed3e508SAndroid Build Coastguard Worker         end_time(end),
515*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypeSwipeLift) {}
GestureGesture516*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureFourFingerSwipeLift&, stime_t start, stime_t end)
517*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
518*aed3e508SAndroid Build Coastguard Worker         end_time(end),
519*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypeFourFingerSwipeLift) {}
GestureGesture520*aed3e508SAndroid Build Coastguard Worker   Gesture(const GestureMetrics&,
521*aed3e508SAndroid Build Coastguard Worker           stime_t start, stime_t end, GestureMetricsType m_type,
522*aed3e508SAndroid Build Coastguard Worker           float d1, float d2)
523*aed3e508SAndroid Build Coastguard Worker       : start_time(start),
524*aed3e508SAndroid Build Coastguard Worker         end_time(end),
525*aed3e508SAndroid Build Coastguard Worker         type(kGestureTypeMetrics) {
526*aed3e508SAndroid Build Coastguard Worker     details.metrics.type = m_type;
527*aed3e508SAndroid Build Coastguard Worker     details.metrics.data[0] = d1;
528*aed3e508SAndroid Build Coastguard Worker     details.metrics.data[1] = d2;
529*aed3e508SAndroid Build Coastguard Worker   }
530*aed3e508SAndroid Build Coastguard Worker #endif  // __cplusplus
531*aed3e508SAndroid Build Coastguard Worker 
532*aed3e508SAndroid Build Coastguard Worker   stime_t start_time, end_time;
533*aed3e508SAndroid Build Coastguard Worker   enum GestureType type;
534*aed3e508SAndroid Build Coastguard Worker   union {
535*aed3e508SAndroid Build Coastguard Worker     GestureMove move;
536*aed3e508SAndroid Build Coastguard Worker     GestureScroll scroll;
537*aed3e508SAndroid Build Coastguard Worker     GestureMouseWheel wheel;
538*aed3e508SAndroid Build Coastguard Worker     GestureButtonsChange buttons;
539*aed3e508SAndroid Build Coastguard Worker     GestureFling fling;
540*aed3e508SAndroid Build Coastguard Worker     GestureSwipe swipe;
541*aed3e508SAndroid Build Coastguard Worker     GesturePinch pinch;
542*aed3e508SAndroid Build Coastguard Worker     GestureSwipeLift swipe_lift;
543*aed3e508SAndroid Build Coastguard Worker     GestureMetrics metrics;
544*aed3e508SAndroid Build Coastguard Worker     GestureFourFingerSwipe four_finger_swipe;
545*aed3e508SAndroid Build Coastguard Worker     GestureFourFingerSwipeLift four_finger_swipe_lift;
546*aed3e508SAndroid Build Coastguard Worker   } details;
547*aed3e508SAndroid Build Coastguard Worker };
548*aed3e508SAndroid Build Coastguard Worker 
549*aed3e508SAndroid Build Coastguard Worker typedef void (*GestureReadyFunction)(void* client_data,
550*aed3e508SAndroid Build Coastguard Worker                                      const struct Gesture* gesture);
551*aed3e508SAndroid Build Coastguard Worker 
552*aed3e508SAndroid Build Coastguard Worker // Gestures Timer Provider Interface
553*aed3e508SAndroid Build Coastguard Worker struct GesturesTimer;
554*aed3e508SAndroid Build Coastguard Worker typedef struct GesturesTimer GesturesTimer;
555*aed3e508SAndroid Build Coastguard Worker 
556*aed3e508SAndroid Build Coastguard Worker // If this returns < 0, the timer should be freed. If it returns >= 0.0, it
557*aed3e508SAndroid Build Coastguard Worker // should be called again after that amount of delay.
558*aed3e508SAndroid Build Coastguard Worker typedef stime_t (*GesturesTimerCallback)(stime_t now,
559*aed3e508SAndroid Build Coastguard Worker                                          void* callback_data);
560*aed3e508SAndroid Build Coastguard Worker // Allocate and return a new timer, or nullptr if error.
561*aed3e508SAndroid Build Coastguard Worker typedef GesturesTimer* (*GesturesTimerCreate)(void* data);
562*aed3e508SAndroid Build Coastguard Worker // Set a timer:
563*aed3e508SAndroid Build Coastguard Worker typedef void (*GesturesTimerSet)(void* data,
564*aed3e508SAndroid Build Coastguard Worker                                  GesturesTimer* timer,
565*aed3e508SAndroid Build Coastguard Worker                                  stime_t delay,
566*aed3e508SAndroid Build Coastguard Worker                                  GesturesTimerCallback callback,
567*aed3e508SAndroid Build Coastguard Worker                                  void* callback_data);
568*aed3e508SAndroid Build Coastguard Worker // Cancel a set timer:
569*aed3e508SAndroid Build Coastguard Worker typedef void (*GesturesTimerCancel)(void* data, GesturesTimer* timer);
570*aed3e508SAndroid Build Coastguard Worker // Free the timer. Will not be called from within a timer callback.
571*aed3e508SAndroid Build Coastguard Worker typedef void (*GesturesTimerFree)(void* data, GesturesTimer* timer);
572*aed3e508SAndroid Build Coastguard Worker 
573*aed3e508SAndroid Build Coastguard Worker typedef struct {
574*aed3e508SAndroid Build Coastguard Worker   GesturesTimerCreate create_fn;
575*aed3e508SAndroid Build Coastguard Worker   GesturesTimerSet set_fn;
576*aed3e508SAndroid Build Coastguard Worker   GesturesTimerCancel cancel_fn;
577*aed3e508SAndroid Build Coastguard Worker   GesturesTimerFree free_fn;
578*aed3e508SAndroid Build Coastguard Worker } GesturesTimerProvider;
579*aed3e508SAndroid Build Coastguard Worker 
580*aed3e508SAndroid Build Coastguard Worker // Gestures Property Provider Interface
581*aed3e508SAndroid Build Coastguard Worker struct GesturesProp;
582*aed3e508SAndroid Build Coastguard Worker typedef struct GesturesProp GesturesProp;
583*aed3e508SAndroid Build Coastguard Worker 
584*aed3e508SAndroid Build Coastguard Worker typedef unsigned char GesturesPropBool;
585*aed3e508SAndroid Build Coastguard Worker 
586*aed3e508SAndroid Build Coastguard Worker // These functions create a named property of given type.
587*aed3e508SAndroid Build Coastguard Worker //   data - data used by PropProvider
588*aed3e508SAndroid Build Coastguard Worker //   loc - location of a variable to be updated by PropProvider
589*aed3e508SAndroid Build Coastguard Worker //         (Chromium calls its own GesturesPropCreate... functions with loc set
590*aed3e508SAndroid Build Coastguard Worker //         to null to create read-only properties, but the Gestures library
591*aed3e508SAndroid Build Coastguard Worker //         itself doesn't, so other clients don't need to support them.)
592*aed3e508SAndroid Build Coastguard Worker //   init - initial value for the property.
593*aed3e508SAndroid Build Coastguard Worker //          If the PropProvider has an alternate configuration source, it may
594*aed3e508SAndroid Build Coastguard Worker //          override this initial value, in which case *loc returns the
595*aed3e508SAndroid Build Coastguard Worker //          value from the configuration source.
596*aed3e508SAndroid Build Coastguard Worker typedef GesturesProp* (*GesturesPropCreateInt)(void* data, const char* name,
597*aed3e508SAndroid Build Coastguard Worker                                                int* loc, size_t count,
598*aed3e508SAndroid Build Coastguard Worker                                                const int* init);
599*aed3e508SAndroid Build Coastguard Worker 
600*aed3e508SAndroid Build Coastguard Worker // Deprecated: the gestures library no longer uses short gesture properties.
601*aed3e508SAndroid Build Coastguard Worker typedef GesturesProp* (*GesturesPropCreateShort_Deprecated)(
602*aed3e508SAndroid Build Coastguard Worker     void*, const char*, short*, size_t, const short*);
603*aed3e508SAndroid Build Coastguard Worker 
604*aed3e508SAndroid Build Coastguard Worker typedef GesturesProp* (*GesturesPropCreateBool)(void* data, const char* name,
605*aed3e508SAndroid Build Coastguard Worker                                                 GesturesPropBool* loc,
606*aed3e508SAndroid Build Coastguard Worker                                                 size_t count,
607*aed3e508SAndroid Build Coastguard Worker                                                 const GesturesPropBool* init);
608*aed3e508SAndroid Build Coastguard Worker 
609*aed3e508SAndroid Build Coastguard Worker typedef GesturesProp* (*GesturesPropCreateString)(void* data, const char* name,
610*aed3e508SAndroid Build Coastguard Worker                                                   const char** loc,
611*aed3e508SAndroid Build Coastguard Worker                                                   const char* const init);
612*aed3e508SAndroid Build Coastguard Worker 
613*aed3e508SAndroid Build Coastguard Worker typedef GesturesProp* (*GesturesPropCreateReal)(void* data, const char* name,
614*aed3e508SAndroid Build Coastguard Worker                                                 double* loc, size_t count,
615*aed3e508SAndroid Build Coastguard Worker                                                 const double* init);
616*aed3e508SAndroid Build Coastguard Worker 
617*aed3e508SAndroid Build Coastguard Worker // A function to call just before a property is to be read.
618*aed3e508SAndroid Build Coastguard Worker // |handler_data| is a local context pointer that can be used by the handler.
619*aed3e508SAndroid Build Coastguard Worker // Handler should return non-zero if it modifies the property's value.
620*aed3e508SAndroid Build Coastguard Worker typedef GesturesPropBool (*GesturesPropGetHandler)(void* handler_data);
621*aed3e508SAndroid Build Coastguard Worker 
622*aed3e508SAndroid Build Coastguard Worker // A function to call just after a property's value is updated.
623*aed3e508SAndroid Build Coastguard Worker // |handler_data| is a local context pointer that can be used by the handler.
624*aed3e508SAndroid Build Coastguard Worker typedef void (*GesturesPropSetHandler)(void* handler_data);
625*aed3e508SAndroid Build Coastguard Worker 
626*aed3e508SAndroid Build Coastguard Worker // Register handlers for the client to call when a GesturesProp is accessed.
627*aed3e508SAndroid Build Coastguard Worker //
628*aed3e508SAndroid Build Coastguard Worker // The get handler, if not nullptr, should be called immediately before the
629*aed3e508SAndroid Build Coastguard Worker // property's value is to be read. This gives the library a chance to update its
630*aed3e508SAndroid Build Coastguard Worker // value.
631*aed3e508SAndroid Build Coastguard Worker //
632*aed3e508SAndroid Build Coastguard Worker // The set handler, if not nullptr, should be called immediately after the
633*aed3e508SAndroid Build Coastguard Worker // property's value is updated. This can be used to create a property that is
634*aed3e508SAndroid Build Coastguard Worker // used to trigger an action, or to force an update to multiple properties
635*aed3e508SAndroid Build Coastguard Worker // atomically.
636*aed3e508SAndroid Build Coastguard Worker //
637*aed3e508SAndroid Build Coastguard Worker // Note: the handlers are called from non-signal/interrupt context
638*aed3e508SAndroid Build Coastguard Worker typedef void (*GesturesPropRegisterHandlers)(void* data, GesturesProp* prop,
639*aed3e508SAndroid Build Coastguard Worker                                              void* handler_data,
640*aed3e508SAndroid Build Coastguard Worker                                              GesturesPropGetHandler getter,
641*aed3e508SAndroid Build Coastguard Worker                                              GesturesPropSetHandler setter);
642*aed3e508SAndroid Build Coastguard Worker 
643*aed3e508SAndroid Build Coastguard Worker // Free a property.
644*aed3e508SAndroid Build Coastguard Worker typedef void (*GesturesPropFree)(void* data, GesturesProp* prop);
645*aed3e508SAndroid Build Coastguard Worker 
646*aed3e508SAndroid Build Coastguard Worker typedef struct GesturesPropProvider {
647*aed3e508SAndroid Build Coastguard Worker   GesturesPropCreateInt create_int_fn;
648*aed3e508SAndroid Build Coastguard Worker   // Deprecated: the library no longer uses short gesture properties, so this
649*aed3e508SAndroid Build Coastguard Worker   // function pointer should be null.
650*aed3e508SAndroid Build Coastguard Worker   GesturesPropCreateShort_Deprecated create_short_fn;
651*aed3e508SAndroid Build Coastguard Worker   GesturesPropCreateBool create_bool_fn;
652*aed3e508SAndroid Build Coastguard Worker   GesturesPropCreateString create_string_fn;
653*aed3e508SAndroid Build Coastguard Worker   GesturesPropCreateReal create_real_fn;
654*aed3e508SAndroid Build Coastguard Worker   GesturesPropRegisterHandlers register_handlers_fn;
655*aed3e508SAndroid Build Coastguard Worker   GesturesPropFree free_fn;
656*aed3e508SAndroid Build Coastguard Worker } GesturesPropProvider;
657*aed3e508SAndroid Build Coastguard Worker 
658*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
659*aed3e508SAndroid Build Coastguard Worker // C++ API:
660*aed3e508SAndroid Build Coastguard Worker 
661*aed3e508SAndroid Build Coastguard Worker namespace gestures {
662*aed3e508SAndroid Build Coastguard Worker 
663*aed3e508SAndroid Build Coastguard Worker class Interpreter;
664*aed3e508SAndroid Build Coastguard Worker class IntProperty;
665*aed3e508SAndroid Build Coastguard Worker class PropRegistry;
666*aed3e508SAndroid Build Coastguard Worker class LoggingFilterInterpreter;
667*aed3e508SAndroid Build Coastguard Worker class Tracer;
668*aed3e508SAndroid Build Coastguard Worker class GestureInterpreterConsumer;
669*aed3e508SAndroid Build Coastguard Worker class MetricsProperties;
670*aed3e508SAndroid Build Coastguard Worker 
671*aed3e508SAndroid Build Coastguard Worker struct GestureInterpreter {
672*aed3e508SAndroid Build Coastguard Worker  public:
673*aed3e508SAndroid Build Coastguard Worker   explicit GestureInterpreter(int version);
674*aed3e508SAndroid Build Coastguard Worker   ~GestureInterpreter();
675*aed3e508SAndroid Build Coastguard Worker   void PushHardwareState(HardwareState* hwstate);
676*aed3e508SAndroid Build Coastguard Worker 
677*aed3e508SAndroid Build Coastguard Worker   void SetHardwareProperties(const HardwareProperties& hwprops);
678*aed3e508SAndroid Build Coastguard Worker 
679*aed3e508SAndroid Build Coastguard Worker   void TimerCallback(stime_t now, stime_t* timeout);
680*aed3e508SAndroid Build Coastguard Worker 
681*aed3e508SAndroid Build Coastguard Worker   void SetCallback(GestureReadyFunction callback, void* client_data);
682*aed3e508SAndroid Build Coastguard Worker   // Deprecated; use SetCallback instead.
683*aed3e508SAndroid Build Coastguard Worker   void set_callback(GestureReadyFunction callback,
684*aed3e508SAndroid Build Coastguard Worker                     void* client_data);
685*aed3e508SAndroid Build Coastguard Worker   void SetTimerProvider(GesturesTimerProvider* tp, void* data);
686*aed3e508SAndroid Build Coastguard Worker   void SetPropProvider(GesturesPropProvider* pp, void* data);
687*aed3e508SAndroid Build Coastguard Worker 
688*aed3e508SAndroid Build Coastguard Worker   // Initialize GestureInterpreter based on device configuration.  This must be
689*aed3e508SAndroid Build Coastguard Worker   // called after GesturesPropProvider is set and before it accepts any inputs.
690*aed3e508SAndroid Build Coastguard Worker   void Initialize(
691*aed3e508SAndroid Build Coastguard Worker       GestureInterpreterDeviceClass type=GESTURES_DEVCLASS_TOUCHPAD);
692*aed3e508SAndroid Build Coastguard Worker 
interpreterGestureInterpreter693*aed3e508SAndroid Build Coastguard Worker   Interpreter* interpreter() const { return interpreter_.get(); }
prop_regGestureInterpreter694*aed3e508SAndroid Build Coastguard Worker   PropRegistry* prop_reg() const { return prop_reg_.get(); }
695*aed3e508SAndroid Build Coastguard Worker 
696*aed3e508SAndroid Build Coastguard Worker   std::string EncodeActivityLog();
697*aed3e508SAndroid Build Coastguard Worker  private:
698*aed3e508SAndroid Build Coastguard Worker   void InitializeTouchpad(void);
699*aed3e508SAndroid Build Coastguard Worker   void InitializeTouchpad2(void);
700*aed3e508SAndroid Build Coastguard Worker   void InitializeMouse(GestureInterpreterDeviceClass cls);
701*aed3e508SAndroid Build Coastguard Worker   void InitializeMultitouchMouse(void);
702*aed3e508SAndroid Build Coastguard Worker 
703*aed3e508SAndroid Build Coastguard Worker   GestureReadyFunction callback_;
704*aed3e508SAndroid Build Coastguard Worker   void* callback_data_;
705*aed3e508SAndroid Build Coastguard Worker 
706*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<PropRegistry> prop_reg_;
707*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<Tracer> tracer_;
708*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<Interpreter> interpreter_;
709*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<MetricsProperties> mprops_;
710*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<IntProperty> stack_version_;
711*aed3e508SAndroid Build Coastguard Worker 
712*aed3e508SAndroid Build Coastguard Worker   GesturesTimerProvider* timer_provider_;
713*aed3e508SAndroid Build Coastguard Worker   void* timer_provider_data_;
714*aed3e508SAndroid Build Coastguard Worker   GesturesTimer* interpret_timer_;
715*aed3e508SAndroid Build Coastguard Worker 
716*aed3e508SAndroid Build Coastguard Worker   LoggingFilterInterpreter* loggingFilter_;
717*aed3e508SAndroid Build Coastguard Worker   std::unique_ptr<GestureInterpreterConsumer> consumer_;
718*aed3e508SAndroid Build Coastguard Worker   HardwareProperties hwprops_;
719*aed3e508SAndroid Build Coastguard Worker 
720*aed3e508SAndroid Build Coastguard Worker   // Disallow copy & assign;
721*aed3e508SAndroid Build Coastguard Worker   GestureInterpreter(const GestureInterpreter&);
722*aed3e508SAndroid Build Coastguard Worker   void operator=(const GestureInterpreter&);
723*aed3e508SAndroid Build Coastguard Worker };
724*aed3e508SAndroid Build Coastguard Worker 
725*aed3e508SAndroid Build Coastguard Worker }  // namespace gestures
726*aed3e508SAndroid Build Coastguard Worker 
727*aed3e508SAndroid Build Coastguard Worker typedef gestures::GestureInterpreter GestureInterpreter;
728*aed3e508SAndroid Build Coastguard Worker #else
729*aed3e508SAndroid Build Coastguard Worker struct GestureInterpreter;
730*aed3e508SAndroid Build Coastguard Worker typedef struct GestureInterpreter GestureInterpreter;
731*aed3e508SAndroid Build Coastguard Worker #endif  // __cplusplus
732*aed3e508SAndroid Build Coastguard Worker 
733*aed3e508SAndroid Build Coastguard Worker #define GESTURES_VERSION 1
734*aed3e508SAndroid Build Coastguard Worker GestureInterpreter* NewGestureInterpreterImpl(int);
735*aed3e508SAndroid Build Coastguard Worker #define NewGestureInterpreter() NewGestureInterpreterImpl(GESTURES_VERSION)
736*aed3e508SAndroid Build Coastguard Worker 
737*aed3e508SAndroid Build Coastguard Worker void DeleteGestureInterpreter(GestureInterpreter*);
738*aed3e508SAndroid Build Coastguard Worker 
739*aed3e508SAndroid Build Coastguard Worker void GestureInterpreterSetHardwareProperties(GestureInterpreter*,
740*aed3e508SAndroid Build Coastguard Worker                                              const struct HardwareProperties*);
741*aed3e508SAndroid Build Coastguard Worker 
742*aed3e508SAndroid Build Coastguard Worker void GestureInterpreterPushHardwareState(GestureInterpreter*,
743*aed3e508SAndroid Build Coastguard Worker                                          struct HardwareState*);
744*aed3e508SAndroid Build Coastguard Worker 
745*aed3e508SAndroid Build Coastguard Worker void GestureInterpreterSetCallback(GestureInterpreter*,
746*aed3e508SAndroid Build Coastguard Worker                                    GestureReadyFunction,
747*aed3e508SAndroid Build Coastguard Worker                                    void*);
748*aed3e508SAndroid Build Coastguard Worker 
749*aed3e508SAndroid Build Coastguard Worker // Gestures will hold a reference to passed provider. Pass nullptr to tell
750*aed3e508SAndroid Build Coastguard Worker // Gestures to stop holding a reference.
751*aed3e508SAndroid Build Coastguard Worker void GestureInterpreterSetTimerProvider(GestureInterpreter*,
752*aed3e508SAndroid Build Coastguard Worker                                         GesturesTimerProvider*,
753*aed3e508SAndroid Build Coastguard Worker                                         void*);
754*aed3e508SAndroid Build Coastguard Worker 
755*aed3e508SAndroid Build Coastguard Worker void GestureInterpreterSetPropProvider(GestureInterpreter*,
756*aed3e508SAndroid Build Coastguard Worker                                        GesturesPropProvider*,
757*aed3e508SAndroid Build Coastguard Worker                                        void*);
758*aed3e508SAndroid Build Coastguard Worker 
759*aed3e508SAndroid Build Coastguard Worker void GestureInterpreterInitialize(GestureInterpreter*,
760*aed3e508SAndroid Build Coastguard Worker                                   enum GestureInterpreterDeviceClass);
761*aed3e508SAndroid Build Coastguard Worker 
762*aed3e508SAndroid Build Coastguard Worker #ifdef __cplusplus
763*aed3e508SAndroid Build Coastguard Worker }
764*aed3e508SAndroid Build Coastguard Worker #endif
765*aed3e508SAndroid Build Coastguard Worker 
766*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_GESTURES_H__
767