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 OnGeckoViewReady();
67 RefPtr
<mozilla::MozPromise
<bool, bool, false>> OnLoadRequest(
68 nsIURI
* aUri
, int32_t aWindowType
, int32_t aFlags
,
69 nsIPrincipal
* aTriggeringPrincipal
, bool aHasUserGesture
,
72 void OnUpdateSessionStore(mozilla::jni::Object::Param aBundle
);
75 // Unique ID given to each widget, used to map Surfaces to widgets
76 // 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 InitEvent(mozilla::WidgetGUIEvent
& event
,
119 LayoutDeviceIntPoint
* aPoint
= 0);
121 void UpdateOverscrollVelocity(const float aX
, const float aY
);
122 void UpdateOverscrollOffset(const float aX
, const float aY
);
124 mozilla::widget::EventDispatcher
* GetEventDispatcher() const;
126 void PassExternalResponse(mozilla::java::WebResponse::Param aResponse
);
128 void ShowDynamicToolbar();
130 void DetachNatives();
132 mozilla::Mutex
& GetDestroyMutex() { return mDestroyMutex
; }
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 InitData
* 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(DesktopIntPoint
&) override
;
151 virtual void Move(double aX
, double aY
) override
;
152 virtual void Resize(double aWidth
, double aHeight
, bool aRepaint
) override
;
153 virtual void Resize(double aX
, double aY
, double aWidth
, double aHeight
,
154 bool aRepaint
) override
;
155 void SetZIndex(int32_t aZIndex
) override
;
156 virtual nsSizeMode
SizeMode() override
{ return mSizeMode
; }
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 nsresult
MakeFullScreen(bool aFullScreen
) override
;
168 void SetCursor(const Cursor
& aDefaultCursor
) override
;
169 void* GetNativeData(uint32_t aDataType
) override
;
170 virtual nsresult
SetTitle(const nsAString
& aTitle
) override
{ return NS_OK
; }
171 [[nodiscard
]] virtual nsresult
GetAttention(int32_t aCycleCount
) override
{
172 return NS_ERROR_NOT_IMPLEMENTED
;
175 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
176 virtual void SetInputContext(const InputContext
& aContext
,
177 const InputContextAction
& aAction
) override
;
178 virtual InputContext
GetInputContext() override
;
180 WindowRenderer
* GetWindowRenderer() override
;
182 void NotifyCompositorSessionLost(
183 mozilla::layers::CompositorSession
* aSession
) override
;
185 virtual bool NeedsPaint() override
;
187 virtual bool WidgetPaintsBackground() override
;
189 virtual uint32_t GetMaxTouchPoints() const override
;
191 void UpdateZoomConstraints(
192 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
193 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) override
;
195 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
196 TouchPointerState aPointerState
,
197 LayoutDeviceIntPoint aPoint
,
198 double aPointerPressure
,
199 uint32_t aPointerOrientation
,
200 nsIObserver
* aObserver
) override
;
201 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
202 NativeMouseMessage aNativeMessage
,
203 mozilla::MouseButton aButton
,
204 nsIWidget::Modifiers aModifierFlags
,
205 nsIObserver
* aObserver
) override
;
206 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
207 nsIObserver
* aObserver
) override
;
209 void SetCompositorWidgetDelegate(CompositorWidgetDelegate
* delegate
) override
;
211 virtual void GetCompositorWidgetInitData(
212 mozilla::widget::CompositorWidgetInitData
* aInitData
) override
;
214 mozilla::layers::CompositorBridgeChild
* GetCompositorBridgeChild() const;
216 void SetContentDocumentDisplayed(bool aDisplayed
);
217 bool IsContentDocumentDisplayed();
219 // Call this function when the users activity is the direct cause of an
220 // event (like a keypress or mouse click).
223 mozilla::jni::Object::Ref
& GetEditableParent() { return mEditableParent
; }
225 RefPtr
<mozilla::a11y::SessionAccessibility
> GetSessionAccessibility();
227 void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage
) override
;
228 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
229 const CSSToScreenScale
& aZoom
) override
;
230 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
231 bool aNeedsYFlip
) override
;
232 void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight
) override
;
233 mozilla::ScreenIntCoord
GetDynamicToolbarMaxHeight() const override
{
234 return mDynamicToolbarMaxHeight
;
237 void UpdateDynamicToolbarOffset(mozilla::ScreenIntCoord aOffset
);
239 virtual mozilla::ScreenIntMargin
GetSafeAreaInsets() const override
;
240 void UpdateSafeAreaInsets(const mozilla::ScreenIntMargin
& aSafeAreaInsets
);
242 mozilla::jni::NativeWeakPtr
<mozilla::widget::NPZCSupport
>
243 GetNPZCSupportWeakPtr();
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
;
264 nsSizeMode mSizeMode
;
267 bool UseExternalCompositingSurface() const override
{ return true; }
269 static void DumpWindows();
270 static void DumpWindows(const nsTArray
<nsWindow
*>& wins
, int indent
= 0);
271 static void LogWindow(nsWindow
* win
, int index
, int indent
);
274 void CreateLayerManager();
277 void OnSizeChanged(const mozilla::gfx::IntSize
& aSize
);
279 mozilla::layers::LayersId
GetRootLayerId() const;
280 RefPtr
<mozilla::layers::UiCompositorControllerChild
>
281 GetUiCompositorControllerChild();
283 mozilla::widget::PlatformCompositorWidgetDelegate
* mCompositorWidgetDelegate
;
285 mozilla::Mutex mDestroyMutex
;
287 friend class mozilla::widget::GeckoViewSupport
;
288 friend class mozilla::widget::LayerViewSupport
;
289 friend class mozilla::widget::NPZCSupport
;
292 #endif /* NSWINDOW_H_ */