Bug 1838234 - Implement Quarantine controls in extensions panel and context menus...
[gecko.git] / widget / windows / WinPointerEvents.h
blob1d2f1a07cb7c86f54e7062ea05788ac6401a271e
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 WinPointerEvents_h__
7 #define WinPointerEvents_h__
9 #include "mozilla/MouseEvents.h"
10 #include "touchinjection_sdk80.h"
11 #include <windef.h>
13 // Define PointerEvent related macros and structures when building code on
14 // Windows version before Win8.
15 #if WINVER < 0x0602
17 // These definitions are copied from WinUser.h. Some of them are not used but
18 // keep them here for future usage.
19 # define WM_NCPOINTERUPDATE 0x0241
20 # define WM_NCPOINTERDOWN 0x0242
21 # define WM_NCPOINTERUP 0x0243
22 # define WM_POINTERUPDATE 0x0245
23 # define WM_POINTERDOWN 0x0246
24 # define WM_POINTERUP 0x0247
25 # define WM_POINTERENTER 0x0249
26 # define WM_POINTERLEAVE 0x024A
27 # define WM_POINTERACTIVATE 0x024B
28 # define WM_POINTERCAPTURECHANGED 0x024C
29 # define WM_TOUCHHITTESTING 0x024D
30 # define WM_POINTERWHEEL 0x024E
31 # define WM_POINTERHWHEEL 0x024F
32 # define DM_POINTERHITTEST 0x0250
35 * Flags that appear in pointer input message parameters
37 # define POINTER_MESSAGE_FLAG_NEW 0x00000001 // New pointer
38 # define POINTER_MESSAGE_FLAG_INRANGE 0x00000002 // Pointer has not departed
39 # define POINTER_MESSAGE_FLAG_INCONTACT 0x00000004 // Pointer is in contact
40 # define POINTER_MESSAGE_FLAG_FIRSTBUTTON 0x00000010 // Primary action
41 # define POINTER_MESSAGE_FLAG_SECONDBUTTON 0x00000020 // Secondary action
42 # define POINTER_MESSAGE_FLAG_THIRDBUTTON 0x00000040 // Third button
43 # define POINTER_MESSAGE_FLAG_FOURTHBUTTON 0x00000080 // Fourth button
44 # define POINTER_MESSAGE_FLAG_FIFTHBUTTON 0x00000100 // Fifth button
45 # define POINTER_MESSAGE_FLAG_PRIMARY 0x00002000 // Pointer is primary
46 # define POINTER_MESSAGE_FLAG_CONFIDENCE \
47 0x00004000 // Pointer is considered unlikely to be accidental
48 # define POINTER_MESSAGE_FLAG_CANCELED \
49 0x00008000 // Pointer is departing in an abnormal manner
52 * Macros to retrieve information from pointer input message parameters
54 # define GET_POINTERID_WPARAM(wParam) (LOWORD(wParam))
55 # define IS_POINTER_FLAG_SET_WPARAM(wParam, flag) \
56 (((DWORD)HIWORD(wParam) & (flag)) == (flag))
57 # define IS_POINTER_NEW_WPARAM(wParam) \
58 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_NEW)
59 # define IS_POINTER_INRANGE_WPARAM(wParam) \
60 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_INRANGE)
61 # define IS_POINTER_INCONTACT_WPARAM(wParam) \
62 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_INCONTACT)
63 # define IS_POINTER_FIRSTBUTTON_WPARAM(wParam) \
64 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FIRSTBUTTON)
65 # define IS_POINTER_SECONDBUTTON_WPARAM(wParam) \
66 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_SECONDBUTTON)
67 # define IS_POINTER_THIRDBUTTON_WPARAM(wParam) \
68 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_THIRDBUTTON)
69 # define IS_POINTER_FOURTHBUTTON_WPARAM(wParam) \
70 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FOURTHBUTTON)
71 # define IS_POINTER_FIFTHBUTTON_WPARAM(wParam) \
72 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_FIFTHBUTTON)
73 # define IS_POINTER_PRIMARY_WPARAM(wParam) \
74 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_PRIMARY)
75 # define HAS_POINTER_CONFIDENCE_WPARAM(wParam) \
76 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_CONFIDENCE)
77 # define IS_POINTER_CANCELED_WPARAM(wParam) \
78 IS_POINTER_FLAG_SET_WPARAM(wParam, POINTER_MESSAGE_FLAG_CANCELED)
81 * WM_POINTERACTIVATE return codes
83 # define PA_ACTIVATE MA_ACTIVATE
84 # define PA_NOACTIVATE MA_NOACTIVATE
86 #endif // WINVER < 0x0602
88 /******************************************************************************
89 * WinPointerInfo
91 * This is a helper class to handle WM_POINTER*. It only supports Win8 or later.
93 ******************************************************************************/
94 class WinPointerInfo final : public mozilla::WidgetPointerHelper {
95 public:
96 WinPointerInfo() : WidgetPointerHelper(), mPressure(0), mButtons(0) {}
98 WinPointerInfo(uint32_t aPointerId, uint32_t aTiltX, uint32_t aTiltY,
99 float aPressure, int16_t aButtons)
100 : WidgetPointerHelper(aPointerId, aTiltX, aTiltY),
101 mPressure(aPressure),
102 mButtons(aButtons) {}
104 float mPressure;
105 int16_t mButtons;
108 class WinPointerEvents final {
109 public:
110 explicit WinPointerEvents();
112 public:
113 bool ShouldHandleWinPointerMessages(UINT aMsg, WPARAM aWParam);
115 uint32_t GetPointerId(WPARAM aWParam) {
116 return GET_POINTERID_WPARAM(aWParam);
118 bool GetPointerType(uint32_t aPointerId, POINTER_INPUT_TYPE* aPointerType);
119 POINTER_INPUT_TYPE GetPointerType(uint32_t aPointerId);
120 bool GetPointerInfo(uint32_t aPointerId, POINTER_INFO* aPointerInfo);
121 bool GetPointerPenInfo(uint32_t aPointerId, POINTER_PEN_INFO* aPenInfo);
122 bool ShouldEnableInkCollector();
123 bool ShouldRollupOnPointerEvent(UINT aMsg, WPARAM aWParam);
124 bool ShouldFirePointerEventByWinPointerMessages();
125 WinPointerInfo* GetCachedPointerInfo(UINT aMsg, WPARAM aWParam);
126 void ConvertAndCachePointerInfo(UINT aMsg, WPARAM aWParam);
127 void ConvertAndCachePointerInfo(WPARAM aWParam, WinPointerInfo* aInfo);
129 private:
130 // Function prototypes
131 typedef BOOL(WINAPI* GetPointerTypePtr)(uint32_t aPointerId,
132 POINTER_INPUT_TYPE* aPointerType);
133 typedef BOOL(WINAPI* GetPointerInfoPtr)(uint32_t aPointerId,
134 POINTER_INFO* aPointerInfo);
135 typedef BOOL(WINAPI* GetPointerPenInfoPtr)(uint32_t aPointerId,
136 POINTER_PEN_INFO* aPenInfo);
138 void InitLibrary();
140 static HMODULE sLibraryHandle;
141 static const wchar_t kPointerLibraryName[];
142 // Static function pointers
143 static GetPointerTypePtr getPointerType;
144 static GetPointerInfoPtr getPointerInfo;
145 static GetPointerPenInfoPtr getPointerPenInfo;
146 WinPointerInfo mPenPointerDownInfo;
147 WinPointerInfo mPenPointerUpInfo;
148 WinPointerInfo mPenPointerUpdateInfo;
151 #endif // #ifndef WinPointerEvents_h__