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/. */
5 
6 #ifndef WinGesture_h__
7 #define WinGesture_h__
8 
9 /*
10  * nsWinGesture - Touch input handling for tablet displays.
11  */
12 
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"
19 
20 // WM_TABLET_QUERYSYSTEMGESTURESTATUS return values
21 #define TABLET_ROTATE_GESTURE_ENABLE 0x02000000
22 
23 class nsPointWin : public nsIntPoint {
24  public:
25   nsPointWin& operator=(const POINTS& aPoint) {
26     x = aPoint.x;
27     y = aPoint.y;
28     return *this;
29   }
30   nsPointWin& operator=(const POINT& aPoint) {
31     x = aPoint.x;
32     y = aPoint.y;
33     return *this;
34   }
35   nsPointWin& operator=(int val) {
36     x = y = val;
37     return *this;
38   }
ScreenToClient(HWND hWnd)39   void ScreenToClient(HWND hWnd) {
40     POINT tmp;
41     tmp.x = x;
42     tmp.y = y;
43     ::ScreenToClient(hWnd, &tmp);
44     *this = tmp;
45   }
46 };
47 
48 class nsWinGesture {
49  public:
50   nsWinGesture();
51 
52  public:
53   bool SetWinGestureSupport(
54       HWND hWnd, mozilla::WidgetGestureNotifyEvent::PanDirection aDirection);
55   bool ShutdownWinGestureSupport();
56 
57   // Simple gesture process
58   bool ProcessGestureMessage(HWND hWnd, WPARAM wParam, LPARAM lParam,
59                              mozilla::WidgetSimpleGestureEvent& evt);
60 
61   // Pan processing
62   bool IsPanEvent(LPARAM lParam);
63   bool ProcessPanMessage(HWND hWnd, WPARAM wParam, LPARAM lParam);
64   bool PanDeltaToPixelScroll(mozilla::WidgetWheelEvent& aWheelEvent);
65   void UpdatePanFeedbackX(HWND hWnd, int32_t scrollOverflow, bool& endFeedback);
66   void UpdatePanFeedbackY(HWND hWnd, int32_t scrollOverflow, bool& endFeedback);
67   void PanFeedbackFinalize(HWND hWnd, bool endFeedback);
68 
69  private:
70   // Delay load info
71   bool InitLibrary();
72 
73   // Pan and feedback state
74   nsPointWin mPanIntermediate;
75   nsPointWin mPanRefPoint;
76   nsPointWin mPixelScrollDelta;
77   bool mPanActive;
78   bool mFeedbackActive;
79   bool mXAxisFeedback;
80   bool mYAxisFeedback;
81   bool mPanInertiaActive;
82   nsPointWin mPixelScrollOverflow;
83 
84   // Zoom state
85   double mZoomIntermediate;
86 
87   // Rotate state
88   double mRotateIntermediate;
89 };
90 
91 #endif /* WinGesture_h__ */
92