1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef WinGesture_h__
#define WinGesture_h__
/*
* nsWinGesture - Touch input handling for tablet displays.
*/
#include "nsdefs.h"
#include <winuser.h>
#include <tpcshrd.h>
#include "nsPoint.h"
#include "mozilla/EventForwards.h"
#include "mozilla/TouchEvents.h"
// Desktop builds target apis for 502. Win8 Metro builds target 602.
#if WINVER < 0x0602
DECLARE_HANDLE(HGESTUREINFO);
/*
* Gesture flags - GESTUREINFO.dwFlags
*/
#define GF_BEGIN 0x00000001
#define GF_INERTIA 0x00000002
#define GF_END 0x00000004
/*
* Gesture configuration structure
* - Used in SetGestureConfig and GetGestureConfig
* - Note that any setting not included in either GESTURECONFIG.dwWant or
* GESTURECONFIG.dwBlock will use the parent window's preferences or
* system defaults.
*/
typedef struct tagGESTURECONFIG {
DWORD dwID; // gesture ID
DWORD dwWant; // settings related to gesture ID that are to be turned on
DWORD dwBlock; // settings related to gesture ID that are to be turned off
} GESTURECONFIG, *PGESTURECONFIG;
/*
* Gesture information structure
* - Pass the HGESTUREINFO received in the WM_GESTURE message lParam into the
* GetGestureInfo function to retrieve this information.
* - If cbExtraArgs is non-zero, pass the HGESTUREINFO received in the WM_GESTURE
* message lParam into the GetGestureExtraArgs function to retrieve extended
* argument information.
*/
typedef struct tagGESTUREINFO {
UINT cbSize; // size, in bytes, of this structure (including variable length Args field)
DWORD dwFlags; // see GF_* flags
DWORD dwID; // gesture ID, see GID_* defines
HWND hwndTarget; // handle to window targeted by this gesture
POINTS ptsLocation; // current location of this gesture
DWORD dwInstanceID; // internally used
DWORD dwSequenceID; // internally used
ULONGLONG ullArguments; // arguments for gestures whose arguments fit in 8 BYTES
UINT cbExtraArgs; // size, in bytes, of extra arguments, if any, that accompany this gesture
} GESTUREINFO, *PGESTUREINFO;
typedef GESTUREINFO const * PCGESTUREINFO;
/*
* Gesture notification structure
* - The WM_GESTURENOTIFY message lParam contains a pointer to this structure.
* - The WM_GESTURENOTIFY message notifies a window that gesture recognition is
* in progress and a gesture will be generated if one is recognized under the
* current gesture settings.
*/
typedef struct tagGESTURENOTIFYSTRUCT {
UINT cbSize; // size, in bytes, of this structure
DWORD dwFlags; // unused
HWND hwndTarget; // handle to window targeted by the gesture
POINTS ptsLocation; // starting location
DWORD dwInstanceID; // internally used
} GESTURENOTIFYSTRUCT, *PGESTURENOTIFYSTRUCT;
/*
* Gesture argument helpers
* - Angle should be a double in the range of -2pi to +2pi
* - Argument should be an unsigned 16-bit value
*/
#define GID_ROTATE_ANGLE_TO_ARGUMENT(_arg_) ((USHORT)((((_arg_) + 2.0 * 3.14159265) / (4.0 * 3.14159265)) * 65535.0))
#define GID_ROTATE_ANGLE_FROM_ARGUMENT(_arg_) ((((double)(_arg_) / 65535.0) * 4.0 * 3.14159265) - 2.0 * 3.14159265)
/*
* Gesture configuration flags
*/
#define GC_ALLGESTURES 0x00000001
#define GC_ZOOM 0x00000001
#define GC_PAN 0x00000001
#define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY 0x00000002
#define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY 0x00000004
#define GC_PAN_WITH_GUTTER 0x00000008
#define GC_PAN_WITH_INERTIA 0x00000010
#define GC_ROTATE 0x00000001
#define GC_TWOFINGERTAP 0x00000001
#define GC_PRESSANDTAP 0x00000001
/*
* Gesture IDs
*/
#define GID_BEGIN 1
#define GID_END 2
#define GID_ZOOM 3
#define GID_PAN 4
#define GID_ROTATE 5
#define GID_TWOFINGERTAP 6
#define GID_PRESSANDTAP 7
// Maximum number of gestures that can be included
// in a single call to SetGestureConfig / GetGestureConfig
#define GESTURECONFIGMAXCOUNT 256
// If specified, GetGestureConfig returns consolidated configuration
// for the specified window and it's parent window chain
#define GCF_INCLUDE_ANCESTORS 0x00000001
// Window events we need to respond to or receive
#define WM_GESTURE 0x0119
#define WM_GESTURENOTIFY 0x011A
typedef struct _TOUCHINPUT {
LONG x;
LONG y;
HANDLE hSource;
DWORD dwID;
DWORD dwFlags;
DWORD dwMask;
DWORD dwTime;
ULONG_PTR dwExtraInfo;
DWORD cxContact;
DWORD cyContact;
} TOUCHINPUT, *PTOUCHINPUT;
typedef HANDLE HTOUCHINPUT;
#define WM_TOUCH 0x0240
#define TOUCHEVENTF_MOVE 0x0001
#define TOUCHEVENTF_DOWN 0x0002
#define TOUCHEVENTF_UP 0x0004
#define TOUCHEVENTF_INRANGE 0x0008
#define TOUCHEVENTF_PRIMARY 0x0010
#define TOUCHEVENTF_NOCOALESCE 0x0020
#define TOUCHEVENTF_PEN 0x0040
#define TOUCHEVENTF_PALM 0x0080
#define TOUCHINPUTMASKF_TIMEFROMSYSTEM 0x0001
#define TOUCHINPUTMASKF_EXTRAINFO 0x0002
#define TOUCHINPUTMASKF_CONTACTAREA 0x0004
#define TOUCH_COORD_TO_PIXEL(C) (C/100)
#define TWF_FINETOUCH 0x0001
#define TWF_WANTPALM 0x0002
#endif // WINVER < 0x0602
// WM_TABLET_QUERYSYSTEMGESTURESTATUS return values
#define TABLET_ROTATE_GESTURE_ENABLE 0x02000000
class nsPointWin : public nsIntPoint
{
public:
nsPointWin& operator=(const POINTS& aPoint) {
x = aPoint.x; y = aPoint.y;
return *this;
}
nsPointWin& operator=(const POINT& aPoint) {
x = aPoint.x; y = aPoint.y;
return *this;
}
nsPointWin& operator=(int val) {
x = y = val;
return *this;
}
void ScreenToClient(HWND hWnd) {
POINT tmp;
tmp.x = x; tmp.y = y;
::ScreenToClient(hWnd, &tmp);
*this = tmp;
}
};
class nsWinGesture
{
public:
nsWinGesture();
public:
bool SetWinGestureSupport(HWND hWnd, mozilla::WidgetGestureNotifyEvent::PanDirection aDirection);
bool ShutdownWinGestureSupport();
bool RegisterTouchWindow(HWND hWnd);
bool UnregisterTouchWindow(HWND hWnd);
bool GetTouchInputInfo(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs);
bool CloseTouchInputHandle(HTOUCHINPUT hTouchInput);
bool IsAvailable();
// Simple gesture process
bool ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam, mozilla::WidgetSimpleGestureEvent& evt);
// Pan processing
bool IsPanEvent(LPARAM lParam);
bool ProcessPanMessage(HWND hWnd, WPARAM wParam, LPARAM lParam);
bool PanDeltaToPixelScroll(mozilla::WidgetWheelEvent& aWheelEvent);
void UpdatePanFeedbackX(HWND hWnd, int32_t scrollOverflow, bool& endFeedback);
void UpdatePanFeedbackY(HWND hWnd, int32_t scrollOverflow, bool& endFeedback);
void PanFeedbackFinalize(HWND hWnd, bool endFeedback);
public:
// Helpers
bool GetGestureInfo(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo);
bool CloseGestureInfoHandle(HGESTUREINFO hGestureInfo);
bool GetGestureExtraArgs(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs);
bool SetGestureConfig(HWND hWnd, UINT cIDs, PGESTURECONFIG pGestureConfig);
bool GetGestureConfig(HWND hWnd, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig);
bool BeginPanningFeedback(HWND hWnd);
bool EndPanningFeedback(HWND hWnd);
bool UpdatePanningFeedback(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia);
protected:
private:
// Function prototypes
typedef BOOL (WINAPI * GetGestureInfoPtr)(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo);
typedef BOOL (WINAPI * CloseGestureInfoHandlePtr)(HGESTUREINFO hGestureInfo);
typedef BOOL (WINAPI * GetGestureExtraArgsPtr)(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs);
typedef BOOL (WINAPI * SetGestureConfigPtr)(HWND hwnd, DWORD dwReserved, UINT cIDs, PGESTURECONFIG pGestureConfig, UINT cbSize);
typedef BOOL (WINAPI * GetGestureConfigPtr)(HWND hwnd, DWORD dwReserved, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig, UINT cbSize);
typedef BOOL (WINAPI * BeginPanningFeedbackPtr)(HWND hWnd);
typedef BOOL (WINAPI * EndPanningFeedbackPtr)(HWND hWnd, BOOL fAnimateBack);
typedef BOOL (WINAPI * UpdatePanningFeedbackPtr)(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia);
typedef BOOL (WINAPI * RegisterTouchWindowPtr)(HWND hWnd, ULONG flags);
typedef BOOL (WINAPI * UnregisterTouchWindowPtr)(HWND hWnd);
typedef BOOL (WINAPI * GetTouchInputInfoPtr)(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs, int32_t cbSize);
typedef BOOL (WINAPI * CloseTouchInputHandlePtr)(HTOUCHINPUT hTouchInput);
// Static function pointers
static GetGestureInfoPtr getGestureInfo;
static CloseGestureInfoHandlePtr closeGestureInfoHandle;
static GetGestureExtraArgsPtr getGestureExtraArgs;
static SetGestureConfigPtr setGestureConfig;
static GetGestureConfigPtr getGestureConfig;
static BeginPanningFeedbackPtr beginPanningFeedback;
static EndPanningFeedbackPtr endPanningFeedback;
static UpdatePanningFeedbackPtr updatePanningFeedback;
static RegisterTouchWindowPtr registerTouchWindow;
static UnregisterTouchWindowPtr unregisterTouchWindow;
static GetTouchInputInfoPtr getTouchInputInfo;
static CloseTouchInputHandlePtr closeTouchInputHandle;
// Delay load info
bool InitLibrary();
static HMODULE sLibraryHandle;
static const wchar_t kGestureLibraryName[];
// Pan and feedback state
nsPointWin mPanIntermediate;
nsPointWin mPanRefPoint;
nsPointWin mPixelScrollDelta;
bool mPanActive;
bool mFeedbackActive;
bool mXAxisFeedback;
bool mYAxisFeedback;
bool mPanInertiaActive;
nsPointWin mPixelScrollOverflow;
// Zoom state
double mZoomIntermediate;
// Rotate state
double mRotateIntermediate;
};
#endif /* WinGesture_h__ */
|