|
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 { |
|
22 public: |
|
23 /* |
|
24 * Return the HWND or null for this widget. |
|
25 */ |
|
26 virtual HWND GetWindowHandle() MOZ_FINAL { |
|
27 return static_cast<HWND>(GetNativeData(NS_NATIVE_WINDOW)); |
|
28 } |
|
29 |
|
30 /* |
|
31 * Return the parent window, if it exists. |
|
32 */ |
|
33 virtual nsWindowBase* GetParentWindowBase(bool aIncludeOwner) = 0; |
|
34 |
|
35 /* |
|
36 * Return true if this is a top level widget. |
|
37 */ |
|
38 virtual bool IsTopLevelWidget() = 0; |
|
39 |
|
40 /* |
|
41 * Init a standard gecko event for this widget. |
|
42 * @param aEvent the event to initialize. |
|
43 * @param aPoint message position in physical coordinates. |
|
44 */ |
|
45 virtual void InitEvent(mozilla::WidgetGUIEvent& aEvent, |
|
46 nsIntPoint* aPoint = nullptr) = 0; |
|
47 |
|
48 /* |
|
49 * Dispatch a gecko event for this widget. |
|
50 * Returns true if it's consumed. Otherwise, false. |
|
51 */ |
|
52 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent* aEvent) = 0; |
|
53 |
|
54 /* |
|
55 * Dispatch a gecko keyboard event for this widget. This |
|
56 * is called by KeyboardLayout to dispatch gecko events. |
|
57 * Returns true if it's consumed. Otherwise, false. |
|
58 */ |
|
59 virtual bool DispatchKeyboardEvent(mozilla::WidgetGUIEvent* aEvent) = 0; |
|
60 |
|
61 /* |
|
62 * Dispatch a gecko scroll event for this widget. This |
|
63 * is called by ScrollHandler to dispatch gecko events. |
|
64 * Returns true if it's consumed. Otherwise, false. |
|
65 */ |
|
66 virtual bool DispatchScrollEvent(mozilla::WidgetGUIEvent* aEvent) = 0; |
|
67 |
|
68 /* |
|
69 * Default dispatch of a plugin event. |
|
70 */ |
|
71 virtual bool DispatchPluginEvent(const MSG& aMsg); |
|
72 |
|
73 /* |
|
74 * Returns true if a plugin has focus on this widget. Otherwise, false. |
|
75 */ |
|
76 virtual bool PluginHasFocus() const MOZ_FINAL |
|
77 { |
|
78 return (mInputContext.mIMEState.mEnabled == IMEState::PLUGIN); |
|
79 } |
|
80 |
|
81 /* |
|
82 * Touch input injection apis |
|
83 */ |
|
84 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId, |
|
85 TouchPointerState aPointerState, |
|
86 nsIntPoint aPointerScreenPoint, |
|
87 double aPointerPressure, |
|
88 uint32_t aPointerOrientation); |
|
89 virtual nsresult ClearNativeTouchSequence(); |
|
90 |
|
91 /* |
|
92 * WM_APPCOMMAND common handler. Sends events via DispatchWindowEvent. |
|
93 */ |
|
94 virtual bool HandleAppCommandMsg(WPARAM aWParam, |
|
95 LPARAM aLParam, |
|
96 LRESULT *aRetValue); |
|
97 |
|
98 protected: |
|
99 bool DispatchCommandEvent(uint32_t aEventCommand); |
|
100 static bool InitTouchInjection(); |
|
101 bool InjectTouchPoint(uint32_t aId, nsIntPoint& aPointerScreenPoint, |
|
102 POINTER_FLAGS aFlags, uint32_t aPressure = 1024, |
|
103 uint32_t aOrientation = 90); |
|
104 |
|
105 class PointerInfo |
|
106 { |
|
107 public: |
|
108 PointerInfo(int32_t aPointerId, nsIntPoint& aPoint) : |
|
109 mPointerId(aPointerId), |
|
110 mPosition(aPoint) |
|
111 { |
|
112 } |
|
113 |
|
114 int32_t mPointerId; |
|
115 nsIntPoint mPosition; |
|
116 }; |
|
117 |
|
118 static PLDHashOperator CancelTouchPoints(const unsigned int& aPointerId, nsAutoPtr<PointerInfo>& aInfo, void* aUserArg); |
|
119 |
|
120 nsClassHashtable<nsUint32HashKey, PointerInfo> mActivePointers; |
|
121 static bool sTouchInjectInitialized; |
|
122 static InjectTouchInputPtr sInjectTouchFuncPtr; |
|
123 |
|
124 protected: |
|
125 InputContext mInputContext; |
|
126 }; |
|
127 |
|
128 #endif // nsWindowBase_h_ |