Skip to content

Commit add7802

Browse files
committed
Gesture stuffs working on Vista part 1
1 parent 7b59bbb commit add7802

File tree

5 files changed

+245
-10
lines changed

5 files changed

+245
-10
lines changed

widget/windows/nsUXThemeData.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,14 @@
2121
using namespace mozilla;
2222
using namespace mozilla::widget;
2323

24+
const wchar_t
25+
nsUXThemeData::kThemeLibraryName[] = L"uxtheme.dll";
26+
2427
nsUXThemeData::ThemeHandle nsUXThemeData::sThemes[eUXNumClasses];
2528

29+
HMODULE
30+
nsUXThemeData::sThemeDLL = nullptr;
31+
2632
const int NUM_COMMAND_BUTTONS = 3;
2733
SIZE nsUXThemeData::sCommandButtonMetrics[NUM_COMMAND_BUTTONS];
2834
bool nsUXThemeData::sCommandButtonMetricsInitialized = false;
@@ -84,6 +90,12 @@ nsUXThemeData::GetTheme(nsUXThemeClass cls) {
8490
return sThemes[cls];
8591
}
8692

93+
HMODULE nsUXThemeData::GetThemeDLL() {
94+
if (!sThemeDLL)
95+
sThemeDLL = ::LoadLibraryW(kThemeLibraryName);
96+
return sThemeDLL;
97+
}
98+
8799
const wchar_t* nsUXThemeData::GetClassName(nsUXThemeClass cls) {
88100
switch (cls) {
89101
case eUXButton:

widget/windows/nsUXThemeData.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class nsUXThemeData {
7070
void Close();
7171
};
7272

73+
static HMODULE sThemeDLL;
7374
static ThemeHandle sThemes[eUXNumClasses];
7475

7576
// We initialize sCommandButtonBoxMetrics separately as a performance
@@ -85,6 +86,7 @@ class nsUXThemeData {
8586
static void EnsureCommandButtonBoxMetrics();
8687

8788
public:
89+
static const wchar_t kThemeLibraryName[];
8890
static bool sTitlebarInfoPopulatedAero;
8991
static bool sTitlebarInfoPopulatedThemed;
9092
static bool sIsDefaultWindowsTheme;

widget/windows/nsWinGesture.cpp

Lines changed: 179 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ using namespace mozilla::widget;
2424

2525
extern mozilla::LazyLogModule gWindowsLog;
2626

27+
const wchar_t nsWinGesture::kGestureLibraryName[] = L"user32.dll";
28+
HMODULE nsWinGesture::sLibraryHandle = nullptr;
29+
nsWinGesture::GetGestureInfoPtr nsWinGesture::getGestureInfo = nullptr;
30+
nsWinGesture::CloseGestureInfoHandlePtr nsWinGesture::closeGestureInfoHandle = nullptr;
31+
nsWinGesture::GetGestureExtraArgsPtr nsWinGesture::getGestureExtraArgs = nullptr;
32+
nsWinGesture::SetGestureConfigPtr nsWinGesture::setGestureConfig = nullptr;
33+
nsWinGesture::GetGestureConfigPtr nsWinGesture::getGestureConfig = nullptr;
34+
nsWinGesture::BeginPanningFeedbackPtr nsWinGesture::beginPanningFeedback = nullptr;
35+
nsWinGesture::EndPanningFeedbackPtr nsWinGesture::endPanningFeedback = nullptr;
36+
nsWinGesture::UpdatePanningFeedbackPtr nsWinGesture::updatePanningFeedback = nullptr;
37+
38+
nsWinGesture::RegisterTouchWindowPtr nsWinGesture::registerTouchWindow = nullptr;
39+
nsWinGesture::UnregisterTouchWindowPtr nsWinGesture::unregisterTouchWindow = nullptr;
40+
nsWinGesture::GetTouchInputInfoPtr nsWinGesture::getTouchInputInfo = nullptr;
41+
nsWinGesture::CloseTouchInputHandlePtr nsWinGesture::closeTouchInputHandle = nullptr;
42+
2743
static bool gEnableSingleFingerPanEvents = false;
2844

2945
nsWinGesture::nsWinGesture()
@@ -39,6 +55,58 @@ nsWinGesture::nsWinGesture()
3955
/* Load and shutdown */
4056

4157
bool nsWinGesture::InitLibrary() {
58+
if (getGestureInfo) {
59+
return true;
60+
} else if (sLibraryHandle) {
61+
return false;
62+
}
63+
64+
sLibraryHandle = ::LoadLibraryW(kGestureLibraryName);
65+
HMODULE hTheme = nsUXThemeData::GetThemeDLL();
66+
67+
// gesture interfaces
68+
if (sLibraryHandle) {
69+
getGestureInfo = (GetGestureInfoPtr)GetProcAddress(sLibraryHandle, "GetGestureInfo");
70+
closeGestureInfoHandle = (CloseGestureInfoHandlePtr)GetProcAddress(sLibraryHandle, "CloseGestureInfoHandle");
71+
getGestureExtraArgs = (GetGestureExtraArgsPtr)GetProcAddress(sLibraryHandle, "GetGestureExtraArgs");
72+
setGestureConfig = (SetGestureConfigPtr)GetProcAddress(sLibraryHandle, "SetGestureConfig");
73+
getGestureConfig = (GetGestureConfigPtr)GetProcAddress(sLibraryHandle, "GetGestureConfig");
74+
registerTouchWindow = (RegisterTouchWindowPtr)GetProcAddress(sLibraryHandle, "RegisterTouchWindow");
75+
unregisterTouchWindow = (UnregisterTouchWindowPtr)GetProcAddress(sLibraryHandle, "UnregisterTouchWindow");
76+
getTouchInputInfo = (GetTouchInputInfoPtr)GetProcAddress(sLibraryHandle, "GetTouchInputInfo");
77+
closeTouchInputHandle = (CloseTouchInputHandlePtr)GetProcAddress(sLibraryHandle, "CloseTouchInputHandle");
78+
}
79+
80+
if (!getGestureInfo || !closeGestureInfoHandle || !getGestureExtraArgs ||
81+
!setGestureConfig || !getGestureConfig) {
82+
getGestureInfo = nullptr;
83+
closeGestureInfoHandle = nullptr;
84+
getGestureExtraArgs = nullptr;
85+
setGestureConfig = nullptr;
86+
getGestureConfig = nullptr;
87+
return false;
88+
}
89+
90+
if (!registerTouchWindow || !unregisterTouchWindow || !getTouchInputInfo || !closeTouchInputHandle) {
91+
registerTouchWindow = nullptr;
92+
unregisterTouchWindow = nullptr;
93+
getTouchInputInfo = nullptr;
94+
closeTouchInputHandle = nullptr;
95+
}
96+
97+
// panning feedback interfaces
98+
if (hTheme) {
99+
beginPanningFeedback = (BeginPanningFeedbackPtr)GetProcAddress(hTheme, "BeginPanningFeedback");
100+
endPanningFeedback = (EndPanningFeedbackPtr)GetProcAddress(hTheme, "EndPanningFeedback");
101+
updatePanningFeedback = (UpdatePanningFeedbackPtr)GetProcAddress(hTheme, "UpdatePanningFeedback");
102+
}
103+
104+
if (!beginPanningFeedback || !endPanningFeedback || !updatePanningFeedback) {
105+
beginPanningFeedback = nullptr;
106+
endPanningFeedback = nullptr;
107+
updatePanningFeedback = nullptr;
108+
}
109+
42110
// Check to see if we want single finger gesture input. Only do this once
43111
// for the app so we don't have to look it up on every window create.
44112
gEnableSingleFingerPanEvents =
@@ -51,6 +119,11 @@ bool nsWinGesture::InitLibrary() {
51119

52120
bool nsWinGesture::SetWinGestureSupport(
53121
HWND hWnd, WidgetGestureNotifyEvent::PanDirection aDirection) {
122+
123+
if (!getGestureInfo) {
124+
return false;
125+
}
126+
54127
GESTURECONFIG config[GCOUNT];
55128

56129
memset(&config, 0, sizeof(config));
@@ -90,12 +163,115 @@ bool nsWinGesture::SetWinGestureSupport(
90163
config[4].dwID = GID_PRESSANDTAP;
91164
config[4].dwBlock = 0;
92165

93-
return SetGestureConfig(hWnd, 0, GCOUNT, (PGESTURECONFIG)&config,
94-
sizeof(GESTURECONFIG));
166+
return SetGestureConfig(hWnd, GCOUNT, (PGESTURECONFIG)&config);
95167
}
96168

97169
/* Helpers */
98170

171+
//bool nsWinGesture::IsAvailable()
172+
//{
173+
// return getGestureInfo != nullptr;
174+
//}
175+
176+
bool nsWinGesture::RegisterTouchWindow(HWND hWnd)
177+
{
178+
if (!registerTouchWindow)
179+
return false;
180+
181+
return registerTouchWindow(hWnd, TWF_WANTPALM);
182+
}
183+
184+
bool nsWinGesture::UnregisterTouchWindow(HWND hWnd)
185+
{
186+
if (!unregisterTouchWindow)
187+
return false;
188+
189+
return unregisterTouchWindow(hWnd);
190+
}
191+
192+
bool nsWinGesture::GetTouchInputInfo(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs)
193+
{
194+
if (!getTouchInputInfo)
195+
return false;
196+
197+
return getTouchInputInfo(hTouchInput, cInputs, pInputs, sizeof(TOUCHINPUT));
198+
}
199+
200+
bool nsWinGesture::CloseTouchInputHandle(HTOUCHINPUT hTouchInput)
201+
{
202+
if (!closeTouchInputHandle)
203+
return false;
204+
205+
return closeTouchInputHandle(hTouchInput);
206+
}
207+
208+
bool nsWinGesture::GetGestureInfo(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo)
209+
{
210+
if (!getGestureInfo || !hGestureInfo || !pGestureInfo)
211+
return false;
212+
213+
ZeroMemory(pGestureInfo, sizeof(GESTUREINFO));
214+
pGestureInfo->cbSize = sizeof(GESTUREINFO);
215+
216+
return getGestureInfo(hGestureInfo, pGestureInfo);
217+
}
218+
219+
bool nsWinGesture::CloseGestureInfoHandle(HGESTUREINFO hGestureInfo)
220+
{
221+
if (!getGestureInfo || !hGestureInfo)
222+
return false;
223+
224+
return closeGestureInfoHandle(hGestureInfo);
225+
}
226+
227+
bool nsWinGesture::GetGestureExtraArgs(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs)
228+
{
229+
if (!getGestureInfo || !hGestureInfo || !pExtraArgs)
230+
return false;
231+
232+
return getGestureExtraArgs(hGestureInfo, cbExtraArgs, pExtraArgs);
233+
}
234+
235+
bool nsWinGesture::SetGestureConfig(HWND hWnd, UINT cIDs, PGESTURECONFIG pGestureConfig)
236+
{
237+
if (!getGestureInfo || !pGestureConfig)
238+
return false;
239+
240+
return setGestureConfig(hWnd, 0, cIDs, pGestureConfig, sizeof(GESTURECONFIG));
241+
}
242+
243+
bool nsWinGesture::GetGestureConfig(HWND hWnd, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig)
244+
{
245+
if (!getGestureInfo || !pGestureConfig)
246+
return false;
247+
248+
return getGestureConfig(hWnd, 0, dwFlags, pcIDs, pGestureConfig, sizeof(GESTURECONFIG));
249+
}
250+
251+
bool nsWinGesture::BeginPanningFeedback(HWND hWnd)
252+
{
253+
if (!beginPanningFeedback)
254+
return false;
255+
256+
return beginPanningFeedback(hWnd);
257+
}
258+
259+
bool nsWinGesture::EndPanningFeedback(HWND hWnd)
260+
{
261+
if (!beginPanningFeedback)
262+
return false;
263+
264+
return endPanningFeedback(hWnd, TRUE);
265+
}
266+
267+
bool nsWinGesture::UpdatePanningFeedback(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia)
268+
{
269+
if (!beginPanningFeedback)
270+
return false;
271+
272+
return updatePanningFeedback(hWnd, offsetX, offsetY, fInInertia);
273+
}
274+
99275
bool nsWinGesture::IsPanEvent(LPARAM lParam) {
100276
GESTUREINFO gi;
101277

@@ -354,7 +530,7 @@ void nsWinGesture::PanFeedbackFinalize(HWND hWnd, bool endFeedback) {
354530
mXAxisFeedback = false;
355531
mYAxisFeedback = false;
356532
mPixelScrollOverflow = 0;
357-
EndPanningFeedback(hWnd, TRUE);
533+
EndPanningFeedback(hWnd);
358534
return;
359535
}
360536

widget/windows/nsWinGesture.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ class nsWinGesture {
5353
bool SetWinGestureSupport(
5454
HWND hWnd, mozilla::WidgetGestureNotifyEvent::PanDirection aDirection);
5555
bool ShutdownWinGestureSupport();
56+
bool RegisterTouchWindow(HWND hWnd);
57+
bool UnregisterTouchWindow(HWND hWnd);
58+
bool GetTouchInputInfo(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs);
59+
bool CloseTouchInputHandle(HTOUCHINPUT hTouchInput);
60+
bool IsAvailable();
5661

5762
// Simple gesture process
5863
bool ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam,
@@ -66,10 +71,51 @@ class nsWinGesture {
6671
void UpdatePanFeedbackY(HWND hWnd, int32_t scrollOverflow, bool& endFeedback);
6772
void PanFeedbackFinalize(HWND hWnd, bool endFeedback);
6873

74+
// Helpers
75+
bool GetGestureInfo(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo);
76+
bool CloseGestureInfoHandle(HGESTUREINFO hGestureInfo);
77+
bool GetGestureExtraArgs(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs);
78+
bool SetGestureConfig(HWND hWnd, UINT cIDs, PGESTURECONFIG pGestureConfig);
79+
bool GetGestureConfig(HWND hWnd, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig);
80+
bool BeginPanningFeedback(HWND hWnd);
81+
bool EndPanningFeedback(HWND hWnd);
82+
bool UpdatePanningFeedback(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia);
83+
6984
private:
85+
// Function prototypes
86+
typedef BOOL (WINAPI * GetGestureInfoPtr)(HGESTUREINFO hGestureInfo, PGESTUREINFO pGestureInfo);
87+
typedef BOOL (WINAPI * CloseGestureInfoHandlePtr)(HGESTUREINFO hGestureInfo);
88+
typedef BOOL (WINAPI * GetGestureExtraArgsPtr)(HGESTUREINFO hGestureInfo, UINT cbExtraArgs, PBYTE pExtraArgs);
89+
typedef BOOL (WINAPI * SetGestureConfigPtr)(HWND hwnd, DWORD dwReserved, UINT cIDs, PGESTURECONFIG pGestureConfig, UINT cbSize);
90+
typedef BOOL (WINAPI * GetGestureConfigPtr)(HWND hwnd, DWORD dwReserved, DWORD dwFlags, PUINT pcIDs, PGESTURECONFIG pGestureConfig, UINT cbSize);
91+
typedef BOOL (WINAPI * BeginPanningFeedbackPtr)(HWND hWnd);
92+
typedef BOOL (WINAPI * EndPanningFeedbackPtr)(HWND hWnd, BOOL fAnimateBack);
93+
typedef BOOL (WINAPI * UpdatePanningFeedbackPtr)(HWND hWnd, LONG offsetX, LONG offsetY, BOOL fInInertia);
94+
typedef BOOL (WINAPI * RegisterTouchWindowPtr)(HWND hWnd, ULONG flags);
95+
typedef BOOL (WINAPI * UnregisterTouchWindowPtr)(HWND hWnd);
96+
typedef BOOL (WINAPI * GetTouchInputInfoPtr)(HTOUCHINPUT hTouchInput, uint32_t cInputs, PTOUCHINPUT pInputs, int32_t cbSize);
97+
typedef BOOL (WINAPI * CloseTouchInputHandlePtr)(HTOUCHINPUT hTouchInput);
98+
99+
// Static function pointers
100+
static GetGestureInfoPtr getGestureInfo;
101+
static CloseGestureInfoHandlePtr closeGestureInfoHandle;
102+
static GetGestureExtraArgsPtr getGestureExtraArgs;
103+
static SetGestureConfigPtr setGestureConfig;
104+
static GetGestureConfigPtr getGestureConfig;
105+
static BeginPanningFeedbackPtr beginPanningFeedback;
106+
static EndPanningFeedbackPtr endPanningFeedback;
107+
static UpdatePanningFeedbackPtr updatePanningFeedback;
108+
static RegisterTouchWindowPtr registerTouchWindow;
109+
static UnregisterTouchWindowPtr unregisterTouchWindow;
110+
static GetTouchInputInfoPtr getTouchInputInfo;
111+
static CloseTouchInputHandlePtr closeTouchInputHandle;
112+
70113
// Delay load info
71114
bool InitLibrary();
72115

116+
static HMODULE sLibraryHandle;
117+
static const wchar_t kGestureLibraryName[];
118+
73119
// Pan and feedback state
74120
nsPointWin mPanIntermediate;
75121
nsPointWin mPanRefPoint;

widget/windows/nsWindow.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,14 +1831,14 @@ void nsWindow::ClearThemeRegion() {
18311831

18321832
void nsWindow::RegisterTouchWindow() {
18331833
mTouchWindow = true;
1834-
::RegisterTouchWindow(mWnd, TWF_WANTPALM);
1834+
mGesture.RegisterTouchWindow(mWnd);
18351835
::EnumChildWindows(mWnd, nsWindow::RegisterTouchForDescendants, 0);
18361836
}
18371837

18381838
BOOL CALLBACK nsWindow::RegisterTouchForDescendants(HWND aWnd, LPARAM aMsg) {
18391839
nsWindow* win = WinUtils::GetNSWindowPtr(aWnd);
18401840
if (win) {
1841-
::RegisterTouchWindow(aWnd, TWF_WANTPALM);
1841+
win->mGesture.RegisterTouchWindow(aWnd);
18421842
}
18431843
return TRUE;
18441844
}
@@ -7318,8 +7318,7 @@ bool nsWindow::OnTouch(WPARAM wParam, LPARAM lParam) {
73187318
uint32_t cInputs = LOWORD(wParam);
73197319
PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
73207320

7321-
if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs,
7322-
sizeof(TOUCHINPUT))) {
7321+
if (mGesture.GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs)) {
73237322
MultiTouchInput touchInput, touchEndInput;
73247323

73257324
// Walk across the touch point array processing each contact point.
@@ -7409,7 +7408,7 @@ bool nsWindow::OnTouch(WPARAM wParam, LPARAM lParam) {
74097408
}
74107409

74117410
delete[] pInputs;
7412-
CloseTouchInputHandle((HTOUCHINPUT)lParam);
7411+
mGesture.CloseTouchInputHandle((HTOUCHINPUT)lParam);
74137412
return true;
74147413
}
74157414

@@ -7447,7 +7446,7 @@ bool nsWindow::OnGesture(WPARAM wParam, LPARAM lParam) {
74477446
mGesture.PanFeedbackFinalize(mWnd, endFeedback);
74487447
}
74497448

7450-
CloseGestureInfoHandle((HGESTUREINFO)lParam);
7449+
mGesture.CloseGestureInfoHandle((HGESTUREINFO)lParam);
74517450

74527451
return true;
74537452
}
@@ -7472,7 +7471,7 @@ bool nsWindow::OnGesture(WPARAM wParam, LPARAM lParam) {
74727471
}
74737472

74747473
// Only close this if we process and return true.
7475-
CloseGestureInfoHandle((HGESTUREINFO)lParam);
7474+
mGesture.CloseGestureInfoHandle((HGESTUREINFO)lParam);
74767475

74777476
return true; // Handled
74787477
}

0 commit comments

Comments
 (0)