1 /* -*- Mode: C++; tab-width: 4; 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 nsWindowBase_h_
7 #define nsWindowBase_h_
8 
9 #include "mozilla/EventForwards.h"
10 #include "nsBaseWidget.h"
11 #include "nsClassHashtable.h"
12 
13 #include <windows.h>
14 #include "touchinjection_sdk80.h"
15 
16 /*
17  * nsWindowBase - Base class of common methods other classes need to access
18  * in both win32 and winrt window classes.
19  */
20 class nsWindowBase : public nsBaseWidget {
21  public:
22   typedef mozilla::WidgetEventTime WidgetEventTime;
23 
24   /*
25    * Return the HWND or null for this widget.
26    */
GetWindowHandle()27   HWND GetWindowHandle() {
28     return static_cast<HWND>(GetNativeData(NS_NATIVE_WINDOW));
29   }
30 
31   /*
32    * Return the parent window, if it exists.
33    */
34   virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) = 0;
35 
36   /*
37    * Return true if this is a top level widget.
38    */
39   virtual bool IsTopLevelWidget() = 0;
40 
41   /*
42    * Init a standard gecko event for this widget.
43    * @param aEvent the event to initialize.
44    * @param aPoint message position in physical coordinates.
45    */
46   virtual void InitEvent(mozilla::WidgetGUIEvent& aEvent,
47                          LayoutDeviceIntPoint* aPoint = nullptr) = 0;
48 
49   /*
50    * Returns WidgetEventTime instance which is initialized with current message
51    * time.
52    */
53   virtual WidgetEventTime CurrentMessageWidgetEventTime() const = 0;
54 
55   /*
56    * Dispatch a gecko event for this widget.
57    * Returns true if it's consumed.  Otherwise, false.
58    */
59   virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent) = 0;
60 
61   /*
62    * Dispatch a gecko keyboard event for this widget. This
63    * is called by KeyboardLayout to dispatch gecko events.
64    * Returns true if it's consumed.  Otherwise, false.
65    */
66   virtual bool DispatchKeyboardEvent(mozilla::WidgetKeyboardEvent* aEvent) = 0;
67 
68   /*
69    * Dispatch a gecko wheel event for this widget. This
70    * is called by ScrollHandler to dispatch gecko events.
71    * Returns true if it's consumed.  Otherwise, false.
72    */
73   virtual bool DispatchWheelEvent(mozilla::WidgetWheelEvent* aEvent) = 0;
74 
75   /*
76    * Dispatch a gecko content command event for this widget. This
77    * is called by ScrollHandler to dispatch gecko events.
78    * Returns true if it's consumed.  Otherwise, false.
79    */
80   virtual bool DispatchContentCommandEvent(
81       mozilla::WidgetContentCommandEvent* aEvent) = 0;
82 
83   /*
84    * Default dispatch of a plugin event.
85    */
86   virtual bool DispatchPluginEvent(const MSG& aMsg);
87 
88   /*
89    * Returns true if this should dispatch a plugin event.
90    */
91   bool ShouldDispatchPluginEvent();
92 
93   /*
94    * Touch input injection apis
95    */
96   virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
97                                               TouchPointerState aPointerState,
98                                               LayoutDeviceIntPoint aPoint,
99                                               double aPointerPressure,
100                                               uint32_t aPointerOrientation,
101                                               nsIObserver* aObserver) override;
102   virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver) override;
103 
104   /*
105    * WM_APPCOMMAND common handler.
106    * Sends events via NativeKey::HandleAppCommandMessage().
107    */
108   virtual bool HandleAppCommandMsg(const MSG& aAppCommandMsg,
109                                    LRESULT* aRetValue);
110 
InputContextRef()111   const InputContext& InputContextRef() const { return mInputContext; }
112 
113  protected:
114   virtual int32_t LogToPhys(double aValue) = 0;
115   void ChangedDPI();
116 
117   static bool InitTouchInjection();
118   bool InjectTouchPoint(uint32_t aId, LayoutDeviceIntPoint& aPoint,
119                         POINTER_FLAGS aFlags, uint32_t aPressure = 1024,
120                         uint32_t aOrientation = 90);
121 
122   class PointerInfo {
123    public:
PointerInfo(int32_t aPointerId,LayoutDeviceIntPoint & aPoint)124     PointerInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint)
125         : mPointerId(aPointerId), mPosition(aPoint) {}
126 
127     int32_t mPointerId;
128     LayoutDeviceIntPoint mPosition;
129   };
130 
131   nsClassHashtable<nsUint32HashKey, PointerInfo> mActivePointers;
132   static bool sTouchInjectInitialized;
133   static InjectTouchInputPtr sInjectTouchFuncPtr;
134 
135   // This is used by SynthesizeNativeTouchPoint to maintain state between
136   // multiple synthesized points, in the case where we can't call InjectTouch
137   // directly.
138   mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
139 
140  protected:
141   InputContext mInputContext;
142 };
143 
144 #endif  // nsWindowBase_h_
145