/src/mozilla-central/widget/headless/HeadlessWidget.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
7 | | #ifndef HEADLESSWIDGET_H |
8 | | #define HEADLESSWIDGET_H |
9 | | |
10 | | #include "mozilla/widget/InProcessCompositorWidget.h" |
11 | | #include "nsBaseWidget.h" |
12 | | #include "CompositorWidget.h" |
13 | | #include "mozilla/dom/WheelEventBinding.h" |
14 | | |
15 | | // The various synthesized event values are hardcoded to avoid pulling |
16 | | // in the platform specific widget code. |
17 | | #if defined(MOZ_WIDGET_GTK) |
18 | 0 | #define MOZ_HEADLESS_MOUSE_MOVE 3 // GDK_MOTION_NOTIFY |
19 | 0 | #define MOZ_HEADLESS_MOUSE_DOWN 4 // GDK_BUTTON_PRESS |
20 | 0 | #define MOZ_HEADLESS_MOUSE_UP 7 // GDK_BUTTON_RELEASE |
21 | 0 | #define MOZ_HEADLESS_SCROLL_MULTIPLIER 3 |
22 | 0 | #define MOZ_HEADLESS_SCROLL_DELTA_MODE mozilla::dom::WheelEvent_Binding::DOM_DELTA_LINE |
23 | | #elif defined(XP_WIN) |
24 | | #define MOZ_HEADLESS_MOUSE_MOVE 1 // MOUSEEVENTF_MOVE |
25 | | #define MOZ_HEADLESS_MOUSE_DOWN 2 // MOUSEEVENTF_LEFTDOWN |
26 | | #define MOZ_HEADLESS_MOUSE_UP 4 // MOUSEEVENTF_LEFTUP |
27 | | #define MOZ_HEADLESS_SCROLL_MULTIPLIER .025 // default scroll lines (3) / WHEEL_DELTA (120) |
28 | | #define MOZ_HEADLESS_SCROLL_DELTA_MODE mozilla::dom::WheelEvent_Binding::DOM_DELTA_LINE |
29 | | #elif defined(XP_MACOSX) |
30 | | #define MOZ_HEADLESS_MOUSE_MOVE 5 // NSMouseMoved |
31 | | #define MOZ_HEADLESS_MOUSE_DOWN 1 // NSLeftMouseDown |
32 | | #define MOZ_HEADLESS_MOUSE_UP 2 // NSLeftMouseUp |
33 | | #define MOZ_HEADLESS_SCROLL_MULTIPLIER 1 |
34 | | #define MOZ_HEADLESS_SCROLL_DELTA_MODE mozilla::dom::WheelEvent_Binding::DOM_DELTA_PIXEL |
35 | | #elif defined(ANDROID) |
36 | | #define MOZ_HEADLESS_MOUSE_MOVE 7 // ACTION_HOVER_MOVE |
37 | | #define MOZ_HEADLESS_MOUSE_DOWN 5 // ACTION_POINTER_DOWN |
38 | | #define MOZ_HEADLESS_MOUSE_UP 6 // ACTION_POINTER_UP |
39 | | #define MOZ_HEADLESS_SCROLL_MULTIPLIER 1 |
40 | | #define MOZ_HEADLESS_SCROLL_DELTA_MODE mozilla::dom::WheelEvent_Binding::DOM_DELTA_LINE |
41 | | #else |
42 | | #define MOZ_HEADLESS_MOUSE_MOVE -1 |
43 | | #define MOZ_HEADLESS_MOUSE_DOWN -1 |
44 | | #define MOZ_HEADLESS_MOUSE_UP -1 |
45 | | #define MOZ_HEADLESS_SCROLL_MULTIPLIER -1 |
46 | | #define MOZ_HEADLESS_SCROLL_DELTA_MODE -1 |
47 | | #endif |
48 | | |
49 | | namespace mozilla { |
50 | | namespace widget { |
51 | | |
52 | | class HeadlessWidget : public nsBaseWidget |
53 | | { |
54 | | public: |
55 | | HeadlessWidget(); |
56 | | |
57 | | NS_INLINE_DECL_REFCOUNTING_INHERITED(HeadlessWidget, nsBaseWidget) |
58 | | |
59 | | void* GetNativeData(uint32_t aDataType) override |
60 | 0 | { |
61 | 0 | // Headless widgets have no native data. |
62 | 0 | return nullptr; |
63 | 0 | } |
64 | | |
65 | | virtual nsresult Create(nsIWidget* aParent, |
66 | | nsNativeWidget aNativeParent, |
67 | | const LayoutDeviceIntRect& aRect, |
68 | | nsWidgetInitData* aInitData = nullptr) override; |
69 | | using nsBaseWidget::Create; // for Create signature not overridden here |
70 | | virtual already_AddRefed<nsIWidget> CreateChild(const LayoutDeviceIntRect& aRect, |
71 | | nsWidgetInitData* aInitData = nullptr, |
72 | | bool aForceUseIWidgetParent = false) override; |
73 | | |
74 | | virtual nsIWidget* GetTopLevelWidget() override; |
75 | | |
76 | | virtual void GetCompositorWidgetInitData(mozilla::widget::CompositorWidgetInitData* aInitData) override; |
77 | | |
78 | | virtual void Destroy() override; |
79 | | virtual void Show(bool aState) override; |
80 | | virtual bool IsVisible() const override; |
81 | | virtual void Move(double aX, double aY) override; |
82 | | virtual void Resize(double aWidth, |
83 | | double aHeight, |
84 | | bool aRepaint) override; |
85 | | virtual void Resize(double aX, |
86 | | double aY, |
87 | | double aWidth, |
88 | | double aHeight, |
89 | | bool aRepaint) override; |
90 | | virtual void SetSizeMode(nsSizeMode aMode) override; |
91 | | virtual nsresult MakeFullScreen(bool aFullScreen, |
92 | | nsIScreen* aTargetScreen = nullptr) override; |
93 | | virtual void Enable(bool aState) override; |
94 | | virtual bool IsEnabled() const override; |
95 | | virtual nsresult SetFocus(bool aRaise) override; |
96 | | virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) override |
97 | 0 | { |
98 | 0 | MOZ_ASSERT_UNREACHABLE("Headless widgets do not support configuring children."); |
99 | 0 | return NS_ERROR_FAILURE; |
100 | 0 | } |
101 | | virtual void Invalidate(const LayoutDeviceIntRect& aRect) override |
102 | 0 | { |
103 | 0 | // TODO: see if we need to do anything here. |
104 | 0 | } |
105 | 0 | virtual nsresult SetTitle(const nsAString& title) override { |
106 | 0 | // Headless widgets have no title, so just ignore it. |
107 | 0 | return NS_OK; |
108 | 0 | } |
109 | 0 | virtual nsresult SetNonClientMargins(LayoutDeviceIntMargin &margins) override { |
110 | 0 | // Headless widgets have no chrome margins, so just ignore the call. |
111 | 0 | return NS_OK; |
112 | 0 | } |
113 | | virtual LayoutDeviceIntPoint WidgetToScreenOffset() override; |
114 | | virtual void SetInputContext(const InputContext& aContext, |
115 | | const InputContextAction& aAction) override |
116 | 0 | { |
117 | 0 | mInputContext = aContext; |
118 | 0 | } |
119 | | virtual InputContext GetInputContext() override |
120 | 0 | { |
121 | 0 | return mInputContext; |
122 | 0 | } |
123 | | |
124 | | virtual LayerManager* |
125 | | GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr, |
126 | | LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE, |
127 | | LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override; |
128 | | |
129 | | void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) override; |
130 | | |
131 | | virtual MOZ_MUST_USE nsresult AttachNativeKeyEvent(WidgetKeyboardEvent& aEvent) override; |
132 | | virtual void GetEditCommands( |
133 | | NativeKeyBindingsType aType, |
134 | | const WidgetKeyboardEvent& aEvent, |
135 | | nsTArray<CommandInt>& aCommands) override; |
136 | | |
137 | | virtual nsresult DispatchEvent(WidgetGUIEvent* aEvent, |
138 | | nsEventStatus& aStatus) override; |
139 | | |
140 | | virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint, |
141 | | uint32_t aNativeMessage, |
142 | | uint32_t aModifierFlags, |
143 | | nsIObserver* aObserver) override; |
144 | | virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint, |
145 | | nsIObserver* aObserver) override |
146 | 0 | { return SynthesizeNativeMouseEvent(aPoint, MOZ_HEADLESS_MOUSE_MOVE, 0, aObserver); }; |
147 | | |
148 | | virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint, |
149 | | uint32_t aNativeMessage, |
150 | | double aDeltaX, |
151 | | double aDeltaY, |
152 | | double aDeltaZ, |
153 | | uint32_t aModifierFlags, |
154 | | uint32_t aAdditionalFlags, |
155 | | nsIObserver* aObserver) override; |
156 | | |
157 | | virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId, |
158 | | TouchPointerState aPointerState, |
159 | | LayoutDeviceIntPoint aPoint, |
160 | | double aPointerPressure, |
161 | | uint32_t aPointerOrientation, |
162 | | nsIObserver* aObserver) override; |
163 | | |
164 | | private: |
165 | | ~HeadlessWidget(); |
166 | | bool mEnabled; |
167 | | bool mVisible; |
168 | | bool mDestroyed; |
169 | | nsIWidget* mTopLevel; |
170 | | HeadlessCompositorWidget* mCompositorWidget; |
171 | | // The size mode before entering fullscreen mode. |
172 | | nsSizeMode mLastSizeMode; |
173 | | // The last size mode set while the window was visible. |
174 | | nsSizeMode mEffectiveSizeMode; |
175 | | InputContext mInputContext; |
176 | | mozilla::UniquePtr<mozilla::MultiTouchInput> mSynthesizedTouchInput; |
177 | | // In headless there is no window manager to track window bounds |
178 | | // across size mode changes, so we must track it to emulate. |
179 | | LayoutDeviceIntRect mRestoreBounds; |
180 | | void ApplySizeModeSideEffects(); |
181 | | // Similarly, we must track the active window ourselves in order |
182 | | // to dispatch (de)activation events properly. |
183 | | void RaiseWindow(); |
184 | | // The top level widgets are tracked for window ordering. They are |
185 | | // stored in order of activation where the last element is always the |
186 | | // currently active widget. |
187 | | static StaticAutoPtr<nsTArray<HeadlessWidget*>> sActiveWindows; |
188 | | // Get the most recently activated widget or null if there are none. |
189 | | static already_AddRefed<HeadlessWidget>GetActiveWindow(); |
190 | | }; |
191 | | |
192 | | } // namespace widget |
193 | | } // namespace mozilla |
194 | | |
195 | | #endif |