1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2009
20 * the Initial Developer. All Rights Reserved.
23 * Jim Mathies <jmathies@mozilla.com>.
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef WinGesture_h__
40 #define WinGesture_h__
43 * nsWinGesture - Touch input handling for tablet displays.
49 #include "nsGUIEvent.h"
51 #ifndef HGESTUREINFO // needs WINVER >= 0x0601
53 DECLARE_HANDLE(HGESTUREINFO
);
56 * Gesture flags - GESTUREINFO.dwFlags
58 #define GF_BEGIN 0x00000001
59 #define GF_INERTIA 0x00000002
60 #define GF_END 0x00000004
63 * Gesture configuration structure
64 * - Used in SetGestureConfig and GetGestureConfig
65 * - Note that any setting not included in either GESTURECONFIG.dwWant or
66 * GESTURECONFIG.dwBlock will use the parent window's preferences or
69 typedef struct tagGESTURECONFIG
{
70 DWORD dwID
; // gesture ID
71 DWORD dwWant
; // settings related to gesture ID that are to be turned on
72 DWORD dwBlock
; // settings related to gesture ID that are to be turned off
73 } GESTURECONFIG
, *PGESTURECONFIG
;
76 * Gesture information structure
77 * - Pass the HGESTUREINFO received in the WM_GESTURE message lParam into the
78 * GetGestureInfo function to retrieve this information.
79 * - If cbExtraArgs is non-zero, pass the HGESTUREINFO received in the WM_GESTURE
80 * message lParam into the GetGestureExtraArgs function to retrieve extended
81 * argument information.
83 typedef struct tagGESTUREINFO
{
84 UINT cbSize
; // size, in bytes, of this structure (including variable length Args field)
85 DWORD dwFlags
; // see GF_* flags
86 DWORD dwID
; // gesture ID, see GID_* defines
87 HWND hwndTarget
; // handle to window targeted by this gesture
88 POINTS ptsLocation
; // current location of this gesture
89 DWORD dwInstanceID
; // internally used
90 DWORD dwSequenceID
; // internally used
91 ULONGLONG ullArguments
; // arguments for gestures whose arguments fit in 8 BYTES
92 UINT cbExtraArgs
; // size, in bytes, of extra arguments, if any, that accompany this gesture
93 } GESTUREINFO
, *PGESTUREINFO
;
94 typedef GESTUREINFO
const * PCGESTUREINFO
;
97 * Gesture notification structure
98 * - The WM_GESTURENOTIFY message lParam contains a pointer to this structure.
99 * - The WM_GESTURENOTIFY message notifies a window that gesture recognition is
100 * in progress and a gesture will be generated if one is recognized under the
101 * current gesture settings.
103 typedef struct tagGESTURENOTIFYSTRUCT
{
104 UINT cbSize
; // size, in bytes, of this structure
105 DWORD dwFlags
; // unused
106 HWND hwndTarget
; // handle to window targeted by the gesture
107 POINTS ptsLocation
; // starting location
108 DWORD dwInstanceID
; // internally used
109 } GESTURENOTIFYSTRUCT
, *PGESTURENOTIFYSTRUCT
;
113 * Gesture argument helpers
114 * - Angle should be a double in the range of -2pi to +2pi
115 * - Argument should be an unsigned 16-bit value
117 #define GID_ROTATE_ANGLE_TO_ARGUMENT(_arg_) ((USHORT)((((_arg_) + 2.0 * 3.14159265) / (4.0 * 3.14159265)) * 65535.0))
118 #define GID_ROTATE_ANGLE_FROM_ARGUMENT(_arg_) ((((double)(_arg_) / 65535.0) * 4.0 * 3.14159265) - 2.0 * 3.14159265)
121 * Gesture configuration flags
123 #define GC_ALLGESTURES 0x00000001
125 #define GC_ZOOM 0x00000001
127 #define GC_PAN 0x00000001
128 #define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY 0x00000002
129 #define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY 0x00000004
130 #define GC_PAN_WITH_GUTTER 0x00000008
131 #define GC_PAN_WITH_INERTIA 0x00000010
133 #define GC_ROTATE 0x00000001
135 #define GC_TWOFINGERTAP 0x00000001
137 #define GC_PRESSANDTAP 0x00000001
147 #define GID_TWOFINGERTAP 6
148 #define GID_PRESSANDTAP 7
150 // Maximum number of gestures that can be included
151 // in a single call to SetGestureConfig / GetGestureConfig
152 #define GESTURECONFIGMAXCOUNT 256
154 // If specified, GetGestureConfig returns consolidated configuration
155 // for the specified window and it's parent window chain
156 #define GCF_INCLUDE_ANCESTORS 0x00000001
158 // Window events we need to respond to or receive
159 #define WM_TABLET_QUERYSYSTEMGESTURESTATUS 0x02CC
160 #define WM_GESTURE 0x0119
161 #define WM_GESTURENOTIFY 0x011A
163 // WM_TABLET_QUERYSYSTEMGESTURESTATUS return values
164 #define TABLET_ROTATE_GESTURE_ENABLE 0x02000000
166 #endif /* #ifndef HGESTUREINFO */
168 #ifndef HTOUCHINPUT // needs WINVER >= 0x0601
170 typedef struct _TOUCHINPUT
{
178 ULONG_PTR dwExtraInfo
;
181 } TOUCHINPUT
, *PTOUCHINPUT
;
183 typedef HANDLE HTOUCHINPUT
;
185 #define WM_TOUCH 0x0240
187 #define TOUCHEVENTF_MOVE 0x0001
188 #define TOUCHEVENTF_DOWN 0x0002
189 #define TOUCHEVENTF_UP 0x0004
190 #define TOUCHEVENTF_INRANGE 0x0008
191 #define TOUCHEVENTF_PRIMARY 0x0010
192 #define TOUCHEVENTF_NOCOALESCE 0x0020
193 #define TOUCHEVENTF_PEN 0x0040
194 #define TOUCHEVENTF_PALM 0x0080
196 #define TOUCHINPUTMASKF_TIMEFROMSYSTEM 0x0001
197 #define TOUCHINPUTMASKF_EXTRAINFO 0x0002
198 #define TOUCHINPUTMASKF_CONTACTAREA 0x0004
200 #define TOUCH_COORD_TO_PIXEL(C) (C/100)
202 #define TWF_FINETOUCH 0x0001
203 #define TWF_WANTPALM 0x0002
205 #endif /* #ifndef HTOUCHINPUT */
207 class nsPointWin
: public nsIntPoint
210 nsPointWin
& operator=(const POINTS
& aPoint
) {
211 x
= aPoint
.x
; y
= aPoint
.y
;
214 nsPointWin
& operator=(const POINT
& aPoint
) {
215 x
= aPoint
.x
; y
= aPoint
.y
;
218 nsPointWin
& operator=(int val
) {
222 void ScreenToClient(HWND hWnd
) {
224 tmp
.x
= x
; tmp
.y
= y
;
225 ::ScreenToClient(hWnd
, &tmp
);
236 PRBool
SetWinGestureSupport(HWND hWnd
, nsGestureNotifyEvent::ePanDirection aDirection
);
237 PRBool
ShutdownWinGestureSupport();
238 PRBool
RegisterTouchWindow(HWND hWnd
);
239 PRBool
UnregisterTouchWindow(HWND hWnd
);
240 PRBool
GetTouchInputInfo(HTOUCHINPUT hTouchInput
, PRUint32 cInputs
, PTOUCHINPUT pInputs
);
241 PRBool
CloseTouchInputHandle(HTOUCHINPUT hTouchInput
);
242 PRBool
IsAvailable();
244 // Simple gesture process
245 PRBool
ProcessGestureMessage(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, nsSimpleGestureEvent
& evt
);
248 PRBool
IsPanEvent(LPARAM lParam
);
249 PRBool
ProcessPanMessage(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
250 PRBool
PanDeltaToPixelScrollX(nsMouseScrollEvent
& evt
);
251 PRBool
PanDeltaToPixelScrollY(nsMouseScrollEvent
& evt
);
252 void UpdatePanFeedbackX(HWND hWnd
, PRInt32 scrollOverflow
, PRBool
& endFeedback
);
253 void UpdatePanFeedbackY(HWND hWnd
, PRInt32 scrollOverflow
, PRBool
& endFeedback
);
254 void PanFeedbackFinalize(HWND hWnd
, PRBool endFeedback
);
258 PRBool
GetGestureInfo(HGESTUREINFO hGestureInfo
, PGESTUREINFO pGestureInfo
);
259 PRBool
CloseGestureInfoHandle(HGESTUREINFO hGestureInfo
);
260 PRBool
GetGestureExtraArgs(HGESTUREINFO hGestureInfo
, UINT cbExtraArgs
, PBYTE pExtraArgs
);
261 PRBool
SetGestureConfig(HWND hWnd
, UINT cIDs
, PGESTURECONFIG pGestureConfig
);
262 PRBool
GetGestureConfig(HWND hWnd
, DWORD dwFlags
, PUINT pcIDs
, PGESTURECONFIG pGestureConfig
);
263 PRBool
BeginPanningFeedback(HWND hWnd
);
264 PRBool
EndPanningFeedback(HWND hWnd
);
265 PRBool
UpdatePanningFeedback(HWND hWnd
, LONG offsetX
, LONG offsetY
, BOOL fInInertia
);
270 // Function prototypes
271 typedef BOOL (WINAPI
* GetGestureInfoPtr
)(HGESTUREINFO hGestureInfo
, PGESTUREINFO pGestureInfo
);
272 typedef BOOL (WINAPI
* CloseGestureInfoHandlePtr
)(HGESTUREINFO hGestureInfo
);
273 typedef BOOL (WINAPI
* GetGestureExtraArgsPtr
)(HGESTUREINFO hGestureInfo
, UINT cbExtraArgs
, PBYTE pExtraArgs
);
274 typedef BOOL (WINAPI
* SetGestureConfigPtr
)(HWND hwnd
, DWORD dwReserved
, UINT cIDs
, PGESTURECONFIG pGestureConfig
, UINT cbSize
);
275 typedef BOOL (WINAPI
* GetGestureConfigPtr
)(HWND hwnd
, DWORD dwReserved
, DWORD dwFlags
, PUINT pcIDs
, PGESTURECONFIG pGestureConfig
, UINT cbSize
);
276 typedef BOOL (WINAPI
* BeginPanningFeedbackPtr
)(HWND hWnd
);
277 typedef BOOL (WINAPI
* EndPanningFeedbackPtr
)(HWND hWnd
, BOOL fAnimateBack
);
278 typedef BOOL (WINAPI
* UpdatePanningFeedbackPtr
)(HWND hWnd
, LONG offsetX
, LONG offsetY
, BOOL fInInertia
);
279 typedef BOOL (WINAPI
* RegisterTouchWindowPtr
)(HWND hWnd
, ULONG flags
);
280 typedef BOOL (WINAPI
* UnregisterTouchWindowPtr
)(HWND hWnd
);
281 typedef BOOL (WINAPI
* GetTouchInputInfoPtr
)(HTOUCHINPUT hTouchInput
, PRUint32 cInputs
, PTOUCHINPUT pInputs
, PRInt32 cbSize
);
282 typedef BOOL (WINAPI
* CloseTouchInputHandlePtr
)(HTOUCHINPUT hTouchInput
);
284 // Static function pointers
285 static GetGestureInfoPtr getGestureInfo
;
286 static CloseGestureInfoHandlePtr closeGestureInfoHandle
;
287 static GetGestureExtraArgsPtr getGestureExtraArgs
;
288 static SetGestureConfigPtr setGestureConfig
;
289 static GetGestureConfigPtr getGestureConfig
;
290 static BeginPanningFeedbackPtr beginPanningFeedback
;
291 static EndPanningFeedbackPtr endPanningFeedback
;
292 static UpdatePanningFeedbackPtr updatePanningFeedback
;
293 static RegisterTouchWindowPtr registerTouchWindow
;
294 static UnregisterTouchWindowPtr unregisterTouchWindow
;
295 static GetTouchInputInfoPtr getTouchInputInfo
;
296 static CloseTouchInputHandlePtr closeTouchInputHandle
;
299 PRBool
InitLibrary();
301 static HMODULE sLibraryHandle
;
302 static const PRUnichar kGestureLibraryName
[];
304 // Pan and feedback state
305 nsPointWin mPanIntermediate
;
306 nsPointWin mPanRefPoint
;
307 nsPointWin mPixelScrollDelta
;
308 PRPackedBool mPanActive
;
309 PRPackedBool mFeedbackActive
;
310 PRPackedBool mXAxisFeedback
;
311 PRPackedBool mYAxisFeedback
;
312 PRPackedBool mPanInertiaActive
;
313 nsPointWin mPixelScrollOverflow
;
316 double mZoomIntermediate
;
319 double mRotateIntermediate
;
322 #endif /* WinGesture_h__ */