1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/windows/nsWinGesture.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,288 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef WinGesture_h__ 1.10 +#define WinGesture_h__ 1.11 + 1.12 +/* 1.13 + * nsWinGesture - Touch input handling for tablet displays. 1.14 + */ 1.15 + 1.16 +#include "nsdefs.h" 1.17 +#include <winuser.h> 1.18 +#include <tpcshrd.h> 1.19 +#include "nsPoint.h" 1.20 +#include "mozilla/EventForwards.h" 1.21 +#include "mozilla/TouchEvents.h" 1.22 + 1.23 +// Desktop builds target apis for 502. Win8 Metro builds target 602. 1.24 +#if WINVER < 0x0602 1.25 + 1.26 +DECLARE_HANDLE(HGESTUREINFO); 1.27 + 1.28 +/* 1.29 + * Gesture flags - GESTUREINFO.dwFlags 1.30 + */ 1.31 +#define GF_BEGIN 0x00000001 1.32 +#define GF_INERTIA 0x00000002 1.33 +#define GF_END 0x00000004 1.34 + 1.35 +/* 1.36 + * Gesture configuration structure 1.37 + * - Used in SetGestureConfig and GetGestureConfig 1.38 + * - Note that any setting not included in either GESTURECONFIG.dwWant or 1.39 + * GESTURECONFIG.dwBlock will use the parent window's preferences or 1.40 + * system defaults. 1.41 + */ 1.42 +typedef struct tagGESTURECONFIG { 1.43 + DWORD dwID; // gesture ID 1.44 + DWORD dwWant; // settings related to gesture ID that are to be turned on 1.45 + DWORD dwBlock; // settings related to gesture ID that are to be turned off 1.46 +} GESTURECONFIG, *PGESTURECONFIG; 1.47 + 1.48 +/* 1.49 + * Gesture information structure 1.50 + * - Pass the HGESTUREINFO received in the WM_GESTURE message lParam into the 1.51 + * GetGestureInfo function to retrieve this information. 1.52 + * - If cbExtraArgs is non-zero, pass the HGESTUREINFO received in the WM_GESTURE 1.53 + * message lParam into the GetGestureExtraArgs function to retrieve extended 1.54 + * argument information. 1.55 + */ 1.56 +typedef struct tagGESTUREINFO { 1.57 + UINT cbSize; // size, in bytes, of this structure (including variable length Args field) 1.58 + DWORD dwFlags; // see GF_* flags 1.59 + DWORD dwID; // gesture ID, see GID_* defines 1.60 + HWND hwndTarget; // handle to window targeted by this gesture 1.61 + POINTS ptsLocation; // current location of this gesture 1.62 + DWORD dwInstanceID; // internally used 1.63 + DWORD dwSequenceID; // internally used 1.64 + ULONGLONG ullArguments; // arguments for gestures whose arguments fit in 8 BYTES 1.65 + UINT cbExtraArgs; // size, in bytes, of extra arguments, if any, that accompany this gesture 1.66 +} GESTUREINFO, *PGESTUREINFO; 1.67 +typedef GESTUREINFO const * PCGESTUREINFO; 1.68 + 1.69 +/* 1.70 + * Gesture notification structure 1.71 + * - The WM_GESTURENOTIFY message lParam contains a pointer to this structure. 1.72 + * - The WM_GESTURENOTIFY message notifies a window that gesture recognition is 1.73 + * in progress and a gesture will be generated if one is recognized under the 1.74 + * current gesture settings. 1.75 + */ 1.76 +typedef struct tagGESTURENOTIFYSTRUCT { 1.77 + UINT cbSize; // size, in bytes, of this structure 1.78 + DWORD dwFlags; // unused 1.79 + HWND hwndTarget; // handle to window targeted by the gesture 1.80 + POINTS ptsLocation; // starting location 1.81 + DWORD dwInstanceID; // internally used 1.82 +} GESTURENOTIFYSTRUCT, *PGESTURENOTIFYSTRUCT; 1.83 + 1.84 + 1.85 +/* 1.86 + * Gesture argument helpers 1.87 + * - Angle should be a double in the range of -2pi to +2pi 1.88 + * - Argument should be an unsigned 16-bit value 1.89 + */ 1.90 +#define GID_ROTATE_ANGLE_TO_ARGUMENT(_arg_) ((USHORT)((((_arg_) + 2.0 * 3.14159265) / (4.0 * 3.14159265)) * 65535.0)) 1.91 +#define GID_ROTATE_ANGLE_FROM_ARGUMENT(_arg_) ((((double)(_arg_) / 65535.0) * 4.0 * 3.14159265) - 2.0 * 3.14159265) 1.92 + 1.93 +/* 1.94 + * Gesture configuration flags 1.95 + */ 1.96 +#define GC_ALLGESTURES 0x00000001 1.97 + 1.98 +#define GC_ZOOM 0x00000001 1.99 + 1.100 +#define GC_PAN 0x00000001 1.101 +#define GC_PAN_WITH_SINGLE_FINGER_VERTICALLY 0x00000002 1.102 +#define GC_PAN_WITH_SINGLE_FINGER_HORIZONTALLY 0x00000004 1.103 +#define GC_PAN_WITH_GUTTER 0x00000008 1.104 +#define GC_PAN_WITH_INERTIA 0x00000010 1.105 + 1.106 +#define GC_ROTATE 0x00000001 1.107 + 1.108 +#define GC_TWOFINGERTAP 0x00000001 1.109 + 1.110 +#define GC_PRESSANDTAP 0x00000001 1.111 + 1.112 +/* 1.113 + * Gesture IDs 1.114 + */ 1.115 +#define GID_BEGIN 1 1.116 +#define GID_END 2 1.117 +#define GID_ZOOM 3 1.118 +#define GID_PAN 4 1.119 +#define GID_ROTATE 5 1.120 +#define GID_TWOFINGERTAP 6 1.121 +#define GID_PRESSANDTAP 7 1.122 + 1.123 +// Maximum number of gestures that can be included 1.124 +// in a single call to SetGestureConfig / GetGestureConfig 1.125 +#define GESTURECONFIGMAXCOUNT 256 1.126 + 1.127 +// If specified, GetGestureConfig returns consolidated configuration 1.128 +// for the specified window and it's parent window chain 1.129 +#define GCF_INCLUDE_ANCESTORS 0x00000001 1.130 + 1.131 +// Window events we need to respond to or receive 1.132 +#define WM_GESTURE 0x0119 1.133 +#define WM_GESTURENOTIFY 0x011A 1.134 + 1.135 +typedef struct _TOUCHINPUT { 1.136 + LONG x; 1.137 + LONG y; 1.138 + HANDLE hSource; 1.139 + DWORD dwID; 1.140 + DWORD dwFlags; 1.141 + DWORD dwMask; 1.142 + DWORD dwTime; 1.143 + ULONG_PTR dwExtraInfo; 1.144 + DWORD cxContact; 1.145 + DWORD cyContact; 1.146 +} TOUCHINPUT, *PTOUCHINPUT; 1.147 + 1.148 +typedef HANDLE HTOUCHINPUT; 1.149 + 1.150 +#define WM_TOUCH 0x0240 1.151 + 1.152 +#define TOUCHEVENTF_MOVE 0x0001 1.153 +#define TOUCHEVENTF_DOWN 0x0002 1.154 +#define TOUCHEVENTF_UP 0x0004 1.155 +#define TOUCHEVENTF_INRANGE 0x0008 1.156 +#define TOUCHEVENTF_PRIMARY 0x0010 1.157 +#define TOUCHEVENTF_NOCOALESCE 0x0020 1.158 +#define TOUCHEVENTF_PEN 0x0040 1.159 +#define TOUCHEVENTF_PALM 0x0080 1.160 + 1.161 +#define TOUCHINPUTMASKF_TIMEFROMSYSTEM 0x0001 1.162 +#define TOUCHINPUTMASKF_EXTRAINFO 0x0002 1.163 +#define TOUCHINPUTMASKF_CONTACTAREA 0x0004 1.164 + 1.165 +#define TOUCH_COORD_TO_PIXEL(C) (C/100) 1.166 + 1.167 +#define TWF_FINETOUCH 0x0001 1.168 +#define TWF_WANTPALM 0x0002 1.169 + 1.170 +#endif // WINVER < 0x0602 1.171 + 1.172 +// WM_TABLET_QUERYSYSTEMGESTURESTATUS return values 1.173 +#define TABLET_ROTATE_GESTURE_ENABLE 0x02000000 1.174 + 1.175 +class nsPointWin : public nsIntPoint 1.176 +{ 1.177 +public: 1.178 + nsPointWin& operator=(const POINTS& aPoint) { 1.179 + x = aPoint.x; y = aPoint.y; 1.180 + return *this; 1.181 + } 1.182 + nsPointWin& operator=(const POINT& aPoint) { 1.183 + x = aPoint.x; y = aPoint.y; 1.184 + return *this; 1.185 + } 1.186 + nsPointWin& operator=(int val) { 1.187 + x = y = val; 1.188 + return *this; 1.189 + } 1.190 + void ScreenToClient(HWND hWnd) { 1.191 + POINT tmp; 1.192 + tmp.x = x; tmp.y = y; 1.193 + ::ScreenToClient(hWnd, &tmp); 1.194 + *this = tmp; 1.195 + } 1.196 +}; 1.197 + 1.198 +class nsWinGesture 1.199 +{ 1.200 +public: 1.201 + nsWinGesture(); 1.202 + 1.203 +public: 1.204 + bool SetWinGestureSupport(HWND hWnd, mozilla::WidgetGestureNotifyEvent::ePanDirection aDirection); 1.205 + bool ShutdownWinGestureSupport(); 1.206 + bool RegisterTouchWindow(HWND hWnd); 1.207 + bool UnregisterTouchWindow(HWND hWnd); 1.208 + bool GetTouchInputInfo(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs); 1.209 + bool CloseTouchInputHandle(HTOUCHINPUT hTouchInput); 1.210 + bool IsAvailable(); 1.211 + 1.212 + // Simple gesture process 1.213 + bool ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam, mozilla::WidgetSimpleGestureEvent& evt); 1.214 + 1.215 + // Pan processing 1.216 + bool IsPanEvent(LPARAM lParam); 1.217 + bool ProcessPanMessage(HWND hWnd, WPARAM wParam, LPARAM lParam); 1.218 + bool PanDeltaToPixelScroll(mozilla::WidgetWheelEvent& aWheelEvent); 1.219 + void UpdatePanFeedbackX(HWND hWnd, int32_t scrollOverflow, bool& endFeedback); 1.220 + void UpdatePanFeedbackY(HWND hWnd, int32_t scrollOverflow, bool& endFeedback); 1.221 + void PanFeedbackFinalize(HWND hWnd, bool endFeedback); 1.222 + 1.223 +public: 1.224 + // Helpers 1.225 + bool GetGestureInfo(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo); 1.226 + bool CloseGestureInfoHandle(HGESTUREINFO hGestureInfo); 1.227 + bool GetGestureExtraArgs(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs); 1.228 + bool SetGestureConfig(HWND hWnd, UINT cIDs, PGESTURECONFIG pGestureConfig); 1.229 + bool GetGestureConfig(HWND hWnd, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig); 1.230 + bool BeginPanningFeedback(HWND hWnd); 1.231 + bool EndPanningFeedback(HWND hWnd); 1.232 + bool UpdatePanningFeedback(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia); 1.233 + 1.234 +protected: 1.235 + 1.236 +private: 1.237 + // Function prototypes 1.238 + typedef BOOL (WINAPI * GetGestureInfoPtr)(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo); 1.239 + typedef BOOL (WINAPI * CloseGestureInfoHandlePtr)(HGESTUREINFO hGestureInfo); 1.240 + typedef BOOL (WINAPI * GetGestureExtraArgsPtr)(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs); 1.241 + typedef BOOL (WINAPI * SetGestureConfigPtr)(HWND hwnd, DWORD dwReserved, UINT cIDs, PGESTURECONFIG pGestureConfig, UINT cbSize); 1.242 + typedef BOOL (WINAPI * GetGestureConfigPtr)(HWND hwnd, DWORD dwReserved, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig, UINT cbSize); 1.243 + typedef BOOL (WINAPI * BeginPanningFeedbackPtr)(HWND hWnd); 1.244 + typedef BOOL (WINAPI * EndPanningFeedbackPtr)(HWND hWnd, BOOL fAnimateBack); 1.245 + typedef BOOL (WINAPI * UpdatePanningFeedbackPtr)(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia); 1.246 + typedef BOOL (WINAPI * RegisterTouchWindowPtr)(HWND hWnd, ULONG flags); 1.247 + typedef BOOL (WINAPI * UnregisterTouchWindowPtr)(HWND hWnd); 1.248 + typedef BOOL (WINAPI * GetTouchInputInfoPtr)(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs, int32_t cbSize); 1.249 + typedef BOOL (WINAPI * CloseTouchInputHandlePtr)(HTOUCHINPUT hTouchInput); 1.250 + 1.251 + // Static function pointers 1.252 + static GetGestureInfoPtr getGestureInfo; 1.253 + static CloseGestureInfoHandlePtr closeGestureInfoHandle; 1.254 + static GetGestureExtraArgsPtr getGestureExtraArgs; 1.255 + static SetGestureConfigPtr setGestureConfig; 1.256 + static GetGestureConfigPtr getGestureConfig; 1.257 + static BeginPanningFeedbackPtr beginPanningFeedback; 1.258 + static EndPanningFeedbackPtr endPanningFeedback; 1.259 + static UpdatePanningFeedbackPtr updatePanningFeedback; 1.260 + static RegisterTouchWindowPtr registerTouchWindow; 1.261 + static UnregisterTouchWindowPtr unregisterTouchWindow; 1.262 + static GetTouchInputInfoPtr getTouchInputInfo; 1.263 + static CloseTouchInputHandlePtr closeTouchInputHandle; 1.264 + 1.265 + // Delay load info 1.266 + bool InitLibrary(); 1.267 + 1.268 + static HMODULE sLibraryHandle; 1.269 + static const wchar_t kGestureLibraryName[]; 1.270 + 1.271 + // Pan and feedback state 1.272 + nsPointWin mPanIntermediate; 1.273 + nsPointWin mPanRefPoint; 1.274 + nsPointWin mPixelScrollDelta; 1.275 + bool mPanActive; 1.276 + bool mFeedbackActive; 1.277 + bool mXAxisFeedback; 1.278 + bool mYAxisFeedback; 1.279 + bool mPanInertiaActive; 1.280 + nsPointWin mPixelScrollOverflow; 1.281 + 1.282 + // Zoom state 1.283 + double mZoomIntermediate; 1.284 + 1.285 + // Rotate state 1.286 + double mRotateIntermediate; 1.287 +}; 1.288 + 1.289 +#endif /* WinGesture_h__ */ 1.290 + 1.291 +