1 /* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
2 * vim: set sw=2 ts=4 expandtab:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
10 #include "nsBaseWidget.h"
12 #include "nsIUserIdleServiceInternal.h"
14 #include "EventDispatcher.h"
15 #include "mozilla/EventForwards.h"
16 #include "mozilla/java/GeckoSessionNatives.h"
17 #include "mozilla/java/WebResponseWrappers.h"
18 #include "mozilla/MozPromise.h"
19 #include "mozilla/Mutex.h"
20 #include "mozilla/StaticPtr.h"
21 #include "mozilla/TextRange.h"
22 #include "mozilla/UniquePtr.h"
27 class WidgetTouchEvent
;
30 class CompositorBridgeChild
;
32 class APZCTreeManager
;
33 class UiCompositorControllerChild
;
38 class GeckoEditableSupport
;
39 class GeckoViewSupport
;
40 class LayerViewSupport
;
42 class PlatformCompositorWidgetDelegate
;
50 class SessionAccessibility
;
52 } // namespace mozilla
54 class nsWindow final
: public nsBaseWidget
{
59 using nsBaseWidget::GetWindowRenderer
;
63 NS_INLINE_DECL_REFCOUNTING_INHERITED(nsWindow
, nsBaseWidget
)
65 static void InitNatives();
66 void SetScreenId(uint32_t aScreenId
) { mScreenId
= aScreenId
; }
67 void OnGeckoViewReady();
68 RefPtr
<mozilla::MozPromise
<bool, bool, false>> OnLoadRequest(
69 nsIURI
* aUri
, int32_t aWindowType
, int32_t aFlags
,
70 nsIPrincipal
* aTriggeringPrincipal
, bool aHasUserGesture
,
74 // Unique ID given to each widget, used to map Surfaces to widgets
75 // in the CompositorSurfaceManager.
80 RefPtr
<mozilla::widget::AndroidView
> mAndroidView
;
82 // Object that implements native LayerView calls.
83 // Owned by the Java Compositor instance.
84 mozilla::jni::NativeWeakPtr
<mozilla::widget::LayerViewSupport
>
87 // Object that implements native NativePanZoomController calls.
88 // Owned by the Java NativePanZoomController instance.
89 mozilla::jni::NativeWeakPtr
<mozilla::widget::NPZCSupport
> mNPZCSupport
;
91 // Object that implements native GeckoEditable calls.
92 // Strong referenced by the Java instance.
93 mozilla::jni::NativeWeakPtr
<mozilla::widget::GeckoEditableSupport
>
95 mozilla::jni::Object::GlobalRef mEditableParent
;
97 // Object that implements native SessionAccessibility calls.
98 // Strong referenced by the Java instance.
99 mozilla::jni::NativeWeakPtr
<mozilla::a11y::SessionAccessibility
>
100 mSessionAccessibility
;
102 // Object that implements native GeckoView calls and associated states.
103 // nullptr for nsWindows that were not opened from GeckoView.
104 mozilla::jni::NativeWeakPtr
<mozilla::widget::GeckoViewSupport
>
107 mozilla::Atomic
<bool, mozilla::ReleaseAcquire
> mContentDocumentDisplayed
;
110 static already_AddRefed
<nsWindow
> From(nsPIDOMWindowOuter
* aDOMWindow
);
111 static already_AddRefed
<nsWindow
> From(nsIWidget
* aWidget
);
113 static nsWindow
* TopWindow();
115 static mozilla::Modifiers
GetModifiers(int32_t aMetaState
);
116 static mozilla::TimeStamp
GetEventTimeStamp(int64_t aEventTime
);
118 void OnSizeChanged(const mozilla::gfx::IntSize
& aSize
);
120 void InitEvent(mozilla::WidgetGUIEvent
& event
,
121 LayoutDeviceIntPoint
* aPoint
= 0);
123 void UpdateOverscrollVelocity(const float aX
, const float aY
);
124 void UpdateOverscrollOffset(const float aX
, const float aY
);
126 mozilla::widget::EventDispatcher
* GetEventDispatcher() const;
128 void PassExternalResponse(mozilla::java::WebResponse::Param aResponse
);
130 void ShowDynamicToolbar();
132 void DetachNatives();
138 using nsBaseWidget::Create
; // for Create signature not overridden here
139 [[nodiscard
]] virtual nsresult
Create(nsIWidget
* aParent
,
140 nsNativeWidget aNativeParent
,
141 const LayoutDeviceIntRect
& aRect
,
142 nsWidgetInitData
* aInitData
) override
;
143 virtual void Destroy() override
;
144 virtual void SetParent(nsIWidget
* aNewParent
) override
;
145 virtual nsIWidget
* GetParent(void) override
;
146 virtual float GetDPI() override
;
147 virtual double GetDefaultScaleInternal() override
;
148 virtual void Show(bool aState
) override
;
149 virtual bool IsVisible() const override
;
150 virtual void ConstrainPosition(bool aAllowSlop
, int32_t* aX
,
151 int32_t* aY
) override
;
152 virtual void Move(double aX
, double aY
) override
;
153 virtual void Resize(double aWidth
, double aHeight
, bool aRepaint
) override
;
154 virtual void Resize(double aX
, double aY
, double aWidth
, double aHeight
,
155 bool aRepaint
) override
;
156 void SetZIndex(int32_t aZIndex
) override
;
157 virtual void SetSizeMode(nsSizeMode aMode
) override
;
158 virtual void Enable(bool aState
) override
;
159 virtual bool IsEnabled() const override
;
160 virtual void Invalidate(const LayoutDeviceIntRect
& aRect
) override
;
161 virtual void SetFocus(Raise
, mozilla::dom::CallerType aCallerType
) override
;
162 virtual LayoutDeviceIntRect
GetScreenBounds() override
;
163 virtual LayoutDeviceIntPoint
WidgetToScreenOffset() override
;
164 virtual nsresult
DispatchEvent(mozilla::WidgetGUIEvent
* aEvent
,
165 nsEventStatus
& aStatus
) override
;
166 nsEventStatus
DispatchEvent(mozilla::WidgetGUIEvent
* aEvent
);
167 virtual already_AddRefed
<nsIScreen
> GetWidgetScreen() override
;
168 virtual nsresult
MakeFullScreen(bool aFullScreen
,
169 nsIScreen
* aTargetScreen
= nullptr) override
;
170 void SetCursor(const Cursor
& aDefaultCursor
) override
;
171 void* GetNativeData(uint32_t aDataType
) override
;
172 void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
;
173 virtual nsresult
SetTitle(const nsAString
& aTitle
) override
{ return NS_OK
; }
174 [[nodiscard
]] virtual nsresult
GetAttention(int32_t aCycleCount
) override
{
175 return NS_ERROR_NOT_IMPLEMENTED
;
178 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
179 virtual void SetInputContext(const InputContext
& aContext
,
180 const InputContextAction
& aAction
) override
;
181 virtual InputContext
GetInputContext() override
;
183 WindowRenderer
* GetWindowRenderer() override
;
185 void NotifyCompositorSessionLost(
186 mozilla::layers::CompositorSession
* aSession
) override
;
188 virtual bool NeedsPaint() override
;
190 virtual bool WidgetPaintsBackground() override
;
192 virtual uint32_t GetMaxTouchPoints() const override
;
194 void UpdateZoomConstraints(
195 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
196 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) override
;
198 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
199 TouchPointerState aPointerState
,
200 LayoutDeviceIntPoint aPoint
,
201 double aPointerPressure
,
202 uint32_t aPointerOrientation
,
203 nsIObserver
* aObserver
) override
;
204 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
205 NativeMouseMessage aNativeMessage
,
206 mozilla::MouseButton aButton
,
207 nsIWidget::Modifiers aModifierFlags
,
208 nsIObserver
* aObserver
) override
;
209 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
210 nsIObserver
* aObserver
) override
;
212 void SetCompositorWidgetDelegate(CompositorWidgetDelegate
* delegate
) override
;
214 virtual void GetCompositorWidgetInitData(
215 mozilla::widget::CompositorWidgetInitData
* aInitData
) override
;
217 mozilla::layers::CompositorBridgeChild
* GetCompositorBridgeChild() const;
219 void SetContentDocumentDisplayed(bool aDisplayed
);
220 bool IsContentDocumentDisplayed();
222 // Call this function when the users activity is the direct cause of an
223 // event (like a keypress or mouse click).
226 mozilla::jni::Object::Ref
& GetEditableParent() { return mEditableParent
; }
228 RefPtr
<mozilla::a11y::SessionAccessibility
> GetSessionAccessibility();
230 void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage
) override
;
231 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
232 const CSSToScreenScale
& aZoom
) override
;
233 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
234 bool aNeedsYFlip
) override
;
235 void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight
) override
;
236 mozilla::ScreenIntCoord
GetDynamicToolbarMaxHeight() const override
{
237 return mDynamicToolbarMaxHeight
;
240 void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset
);
242 virtual mozilla::ScreenIntMargin
GetSafeAreaInsets() const override
;
243 void UpdateSafeAreaInsets(const mozilla::ScreenIntMargin
& aSafeAreaInsets
);
247 nsWindow
* FindTopLevel();
250 void ConfigureAPZControllerThread() override
;
251 void DispatchHitTest(const mozilla::WidgetTouchEvent
& aEvent
);
253 already_AddRefed
<GeckoContentController
> CreateRootContentController()
257 nsTArray
<nsWindow
*> mChildren
;
260 nsCOMPtr
<nsIUserIdleServiceInternal
> mIdleService
;
261 mozilla::ScreenIntCoord mDynamicToolbarMaxHeight
;
262 mozilla::ScreenIntMargin mSafeAreaInsets
;
266 bool UseExternalCompositingSurface() const override
{ return true; }
268 static void DumpWindows();
269 static void DumpWindows(const nsTArray
<nsWindow
*>& wins
, int indent
= 0);
270 static void LogWindow(nsWindow
* win
, int index
, int indent
);
273 void CreateLayerManager();
276 mozilla::layers::LayersId
GetRootLayerId() const;
277 RefPtr
<mozilla::layers::UiCompositorControllerChild
>
278 GetUiCompositorControllerChild();
280 mozilla::widget::PlatformCompositorWidgetDelegate
* mCompositorWidgetDelegate
;
282 friend class mozilla::widget::GeckoViewSupport
;
283 friend class mozilla::widget::LayerViewSupport
;
284 friend class mozilla::widget::NPZCSupport
;
287 #endif /* NSWINDOW_H_ */