widget/windows/nsWinGesture.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial