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 #ifndef nsBaseWidget_h__
6 #define nsBaseWidget_h__
9 #include "mozilla/EventForwards.h"
10 #include "mozilla/Mutex.h"
11 #include "mozilla/RefPtr.h"
12 #include "mozilla/UniquePtr.h"
13 #include "mozilla/WidgetUtils.h"
14 #include "mozilla/dom/MouseEventBinding.h"
15 #include "mozilla/layers/APZCCallbackHelper.h"
16 #include "mozilla/layers/CompositorOptions.h"
17 #include "mozilla/layers/NativeLayer.h"
18 #include "mozilla/widget/ThemeChangeKind.h"
19 #include "mozilla/widget/WindowOcclusionState.h"
21 #include "nsIWidget.h"
22 #include "nsWidgetsCID.h"
26 #include "nsIRollupListener.h"
27 #include "nsIObserver.h"
28 #include "nsIWidgetListener.h"
29 #include "nsPIDOMWindow.h"
30 #include "nsWeakReference.h"
38 class CompositorVsyncDispatcher
;
39 class LiveResizeListener
;
40 class FallbackRenderer
;
42 struct SwipeEventQueue
;
43 class WidgetWheelEvent
;
47 class LocalAccessible
;
57 class CompositorBridgeChild
;
58 class CompositorBridgeParent
;
59 class IAPZCTreeManager
;
60 class GeckoContentController
;
62 struct APZEventResult
;
63 class CompositorSession
;
65 class WebRenderLayerManager
;
66 struct ScrollableLayerGuid
;
67 class RemoteCompositorSession
;
71 class CompositorWidgetDelegate
;
72 class InProcessCompositorWidget
;
73 class WidgetRenderingContext
;
76 class CompositorVsyncDispatcher
;
77 } // namespace mozilla
83 // Windows specific constant indicating the maximum number of touch points the
84 // inject api will allow. This also sets the maximum numerical value for touch
85 // ids we can use when injecting touch points on Windows.
86 #define TOUCH_INJECT_MAX_POINTS 256
90 // Helper class used in shutting down gfx related code.
91 class WidgetShutdownObserver final
: public nsIObserver
{
92 ~WidgetShutdownObserver();
95 explicit WidgetShutdownObserver(nsBaseWidget
* aWidget
);
103 nsBaseWidget
* mWidget
;
107 // Helper class used for observing locales change.
108 class LocalesChangedObserver final
: public nsIObserver
{
109 ~LocalesChangedObserver();
112 explicit LocalesChangedObserver(nsBaseWidget
* aWidget
);
120 nsBaseWidget
* mWidget
;
125 * Common widget implementation used as base class for native
126 * or crossplatform implementations of Widgets.
127 * All cross-platform behavior that all widgets need to implement
128 * should be placed in this class.
129 * (Note: widget implementations are not required to use this
130 * class, but it gives them a head start.)
133 class nsBaseWidget
: public nsIWidget
, public nsSupportsWeakReference
{
134 template <class EventType
, class InputType
>
135 friend class DispatchEventOnMainThread
;
136 friend class mozilla::widget::InProcessCompositorWidget
;
137 friend class mozilla::layers::RemoteCompositorSession
;
140 typedef base::Thread Thread
;
141 typedef mozilla::gfx::DrawTarget DrawTarget
;
142 typedef mozilla::gfx::SourceSurface SourceSurface
;
143 typedef mozilla::layers::BufferMode BufferMode
;
144 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild
;
145 typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent
;
146 typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager
;
147 typedef mozilla::layers::GeckoContentController GeckoContentController
;
148 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid
;
149 typedef mozilla::layers::APZEventState APZEventState
;
150 typedef mozilla::CSSIntRect CSSIntRect
;
151 typedef mozilla::CSSRect CSSRect
;
152 typedef mozilla::ScreenRotation ScreenRotation
;
153 typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate
;
154 typedef mozilla::layers::CompositorSession CompositorSession
;
155 typedef mozilla::layers::ImageContainer ImageContainer
;
157 virtual ~nsBaseWidget();
162 explicit nsBaseWidget(BorderStyle aBorderStyle
);
164 NS_DECL_THREADSAFE_ISUPPORTS
166 // nsIWidget interface
167 void CaptureRollupEvents(bool aDoCapture
) override
{}
168 nsIWidgetListener
* GetWidgetListener() const override
;
169 void SetWidgetListener(nsIWidgetListener
* alistener
) override
;
170 void Destroy() override
;
171 void SetParent(nsIWidget
* aNewParent
) override
{};
172 nsIWidget
* GetParent() override
;
173 nsIWidget
* GetTopLevelWidget() override
;
174 nsIWidget
* GetSheetWindowParent(void) override
;
175 float GetDPI() override
;
176 void AddChild(nsIWidget
* aChild
) override
;
177 void RemoveChild(nsIWidget
* aChild
) override
;
179 void GetWorkspaceID(nsAString
& workspaceID
) override
;
180 void MoveToWorkspace(const nsAString
& workspaceID
) override
;
181 bool IsTiled() const override
{ return mIsTiled
; }
183 bool IsFullyOccluded() const override
{ return mIsFullyOccluded
; }
185 void SetCursor(const Cursor
&) override
;
186 void SetCustomCursorAllowed(bool) override
;
187 void ClearCachedCursor() final
{
189 mUpdateCursor
= true;
191 void SetTransparencyMode(TransparencyMode aMode
) override
;
192 TransparencyMode
GetTransparencyMode() override
;
193 void SetWindowShadowStyle(mozilla::WindowShadow
) override
{}
194 void SetShowsToolbarButton(bool aShow
) override
{}
195 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen
) override
{}
196 void SetWindowAnimationType(WindowAnimationType aType
) override
{}
197 void HideWindowChrome(bool aShouldHide
) override
{}
198 bool PrepareForFullscreenTransition(nsISupports
** aData
) override
{
201 void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
202 uint16_t aDuration
, nsISupports
* aData
,
203 nsIRunnable
* aCallback
) override
;
204 void CleanupFullscreenTransition() override
{}
205 already_AddRefed
<Screen
> GetWidgetScreen() override
;
206 nsresult
MakeFullScreen(bool aFullScreen
) override
;
207 void InfallibleMakeFullScreen(bool aFullScreen
);
209 WindowRenderer
* GetWindowRenderer() override
;
210 bool HasWindowRenderer() const final
{ return !!mWindowRenderer
; }
212 // A remote compositor session tied to this window has been lost and IPC
213 // messages will no longer work. The widget must clean up any lingering
214 // resources and possibly schedule another paint.
216 // A reference to the session object is held until this function has
217 // returned. Callers should hold a reference to the widget, since this
218 // function could deallocate the widget if it is unparented.
219 virtual void NotifyCompositorSessionLost(
220 mozilla::layers::CompositorSession
* aSession
);
222 already_AddRefed
<mozilla::CompositorVsyncDispatcher
>
223 GetCompositorVsyncDispatcher();
224 virtual void CreateCompositorVsyncDispatcher();
225 virtual void CreateCompositor();
226 virtual void CreateCompositor(int aWidth
, int aHeight
);
227 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate
*) {}
228 void PrepareWindowEffects() override
{}
229 void UpdateThemeGeometries(
230 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) override
{}
231 void SetModal(bool aModal
) override
{}
232 uint32_t GetMaxTouchPoints() const override
;
233 void SetWindowClass(const nsAString
& xulWinType
, const nsAString
& xulWinClass
,
234 const nsAString
& xulWinName
) override
{}
235 // Return whether this widget interprets parameters to Move and Resize APIs
236 // as "desktop pixels" rather than "device pixels", and therefore
237 // applies its GetDefaultScale() value to them before using them as mBounds
238 // etc (which are always stored in device pixels).
239 // Note that APIs that -get- the widget's position/size/bounds, rather than
240 // -setting- them (i.e. moving or resizing the widget) will always return
241 // values in the widget's device pixels.
242 bool BoundsUseDesktopPixels() const {
243 return mWindowType
<= WindowType::Popup
;
245 // Default implementation, to be overridden by platforms where desktop coords
246 // are virtualized and may not correspond to device pixels on the screen.
247 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
248 return mozilla::DesktopToLayoutDeviceScale(1.0);
250 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScaleByScreen()
253 void ConstrainPosition(DesktopIntPoint
&) override
{}
254 void MoveClient(const DesktopPoint
& aOffset
) override
;
255 void ResizeClient(const DesktopSize
& aSize
, bool aRepaint
) override
;
256 void ResizeClient(const DesktopRect
& aRect
, bool aRepaint
) override
;
257 LayoutDeviceIntRect
GetBounds() override
;
258 LayoutDeviceIntRect
GetClientBounds() override
;
259 LayoutDeviceIntRect
GetScreenBounds() override
;
260 [[nodiscard
]] nsresult
GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
261 nsresult
SetNonClientMargins(const LayoutDeviceIntMargin
&) override
;
262 LayoutDeviceIntPoint
GetClientOffset() override
;
263 void EnableDragDrop(bool aEnable
) override
{};
264 nsresult
AsyncEnableDragDrop(bool aEnable
) override
;
265 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin
) override
;
266 [[nodiscard
]] nsresult
GetAttention(int32_t aCycleCount
) override
{
269 bool HasPendingInputEvent() override
;
270 void SetIcon(const nsAString
& aIconSpec
) override
{}
271 bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) override
;
272 void FreeNativeData(void* data
, uint32_t aDataType
) override
{}
273 nsresult
ActivateNativeMenuItemAt(const nsAString
& indexString
) override
{
274 return NS_ERROR_NOT_IMPLEMENTED
;
276 nsresult
ForceUpdateNativeMenuAt(const nsAString
& indexString
) override
{
277 return NS_ERROR_NOT_IMPLEMENTED
;
279 nsresult
NotifyIME(const IMENotification
& aIMENotification
) final
;
280 [[nodiscard
]] nsresult
AttachNativeKeyEvent(
281 mozilla::WidgetKeyboardEvent
& aEvent
) override
{
282 return NS_ERROR_NOT_IMPLEMENTED
;
284 bool ComputeShouldAccelerate();
285 virtual bool WidgetTypeSupportsAcceleration() { return true; }
286 [[nodiscard
]] nsresult
OnDefaultButtonLoaded(
287 const LayoutDeviceIntRect
& aButtonRect
) override
{
288 return NS_ERROR_NOT_IMPLEMENTED
;
290 already_AddRefed
<nsIWidget
> CreateChild(
291 const LayoutDeviceIntRect
& aRect
, InitData
* aInitData
= nullptr,
292 bool aForceUseIWidgetParent
= false) override
;
293 void AttachViewToTopLevel(bool aUseAttachedEvents
) override
;
294 nsIWidgetListener
* GetAttachedWidgetListener() const override
;
295 void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) override
;
296 nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() override
;
297 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener
*) override
;
298 NativeIMEContext
GetNativeIMEContext() override
;
299 TextEventDispatcher
* GetTextEventDispatcher() final
;
300 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
301 void ZoomToRect(const uint32_t& aPresShellId
,
302 const ScrollableLayerGuid::ViewID
& aViewId
,
303 const CSSRect
& aRect
, const uint32_t& aFlags
) override
;
305 // Dispatch an event that must be first be routed through APZ.
306 ContentAndAPZEventStatus
DispatchInputEvent(
307 mozilla::WidgetInputEvent
* aEvent
) override
;
308 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) override
;
310 bool DispatchWindowEvent(mozilla::WidgetGUIEvent
& event
) override
;
312 void SetConfirmedTargetAPZC(
313 uint64_t aInputBlockId
,
314 const nsTArray
<ScrollableLayerGuid
>& aTargets
) const override
;
316 void UpdateZoomConstraints(
317 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
318 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) override
;
320 bool AsyncPanZoomEnabled() const override
;
322 void SwipeFinished() override
;
323 void ReportSwipeStarted(uint64_t aInputBlockId
, bool aStartSwipe
) override
;
324 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput
& aSwipeStartEvent
,
325 uint32_t aAllowedDirections
,
326 uint64_t aInputBlockId
);
329 uint32_t allowedDirections
;
331 SwipeInfo
SendMayStartSwipe(const mozilla::PanGestureInput
& aSwipeStartEvent
);
332 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
333 // whether |aPanInput| event was used for SwipeTracker or not.
334 mozilla::WidgetWheelEvent
MayStartSwipeForAPZ(
335 const mozilla::PanGestureInput
& aPanInput
,
336 const mozilla::layers::APZEventResult
& aApzResult
);
338 // Returns true if |aPanInput| event was used for SwipeTracker, false
340 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput
& aPanInput
);
342 void NotifyWindowDestroyed();
343 void NotifySizeMoveDone();
345 using ByMoveToRect
= nsIWidgetListener::ByMoveToRect
;
346 void NotifyWindowMoved(int32_t aX
, int32_t aY
,
347 ByMoveToRect
= ByMoveToRect::No
);
349 // Should be called by derived implementations to notify on system color and
351 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind
);
353 void NotifyAPZOfDPIChange();
356 // Get the accessible for the window.
357 mozilla::a11y::LocalAccessible
* GetRootAccessible();
360 // Return true if this is a simple widget (that is typically not worth
362 bool IsSmallPopup() const;
364 PopupLevel
GetPopupLevel() { return mPopupLevel
; }
366 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
{}
368 const SizeConstraints
GetSizeConstraints() override
;
369 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
371 void StartAsyncScrollbarDrag(const AsyncDragMetrics
& aDragMetrics
) override
;
373 bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
374 const ScrollableLayerGuid
& aGuid
) override
;
376 void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) override
;
378 mozilla::layers::LayersId
GetRootLayerTreeId() override
;
381 * Use this when GetLayerManager() returns a BasicLayerManager
382 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
383 * layer manager to temporarily render into aTarget.
385 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
386 * |aRotation| is the "virtual rotation" to apply when rendering to
387 * the target. When |aRotation| is ROTATION_0,
388 * |aNaturalWidgetBounds| is not used.
390 class AutoLayerManagerSetup
{
392 AutoLayerManagerSetup(nsBaseWidget
* aWidget
, gfxContext
* aTarget
,
393 BufferMode aDoubleBuffering
);
394 ~AutoLayerManagerSetup();
397 nsBaseWidget
* mWidget
;
398 mozilla::FallbackRenderer
* mRenderer
= nullptr;
400 friend class AutoLayerManagerSetup
;
402 virtual bool ShouldUseOffMainThreadCompositing();
404 static nsIRollupListener
* GetActiveRollupListener();
410 // These functions should be called at the start and end of a "live" widget
411 // resize (i.e. when the window contents are repainting during the resize,
412 // such as when the user drags a window border). It will suppress the
413 // displayport during the live resize to avoid unneccessary overpainting.
414 void NotifyLiveResizeStarted();
415 void NotifyLiveResizeStopped();
417 #if defined(MOZ_WIDGET_ANDROID)
418 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override
{};
419 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
420 const CSSToScreenScale
& aZoom
) override
{};
421 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
422 bool aNeedsYFlip
) override
{};
425 virtual void LocalesChanged() {}
427 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState
) {}
430 // These are methods for CompositorWidgetWrapper, and should only be
431 // accessed from that class. Derived widgets can choose which methods to
432 // implement, or none if supporting out-of-process compositing.
433 virtual bool PreRender(mozilla::widget::WidgetRenderingContext
* aContext
) {
436 virtual void PostRender(mozilla::widget::WidgetRenderingContext
* aContext
) {}
437 virtual RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() {
440 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawing();
441 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawingInRegion(
442 const LayoutDeviceIntRegion
& aInvalidRegion
, BufferMode
* aBufferMode
) {
443 return StartRemoteDrawing();
445 virtual void EndRemoteDrawing() {}
446 virtual void EndRemoteDrawingInRegion(
447 DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
450 virtual void CleanupRemoteDrawing() {}
451 virtual void CleanupWindowEffects() {}
452 virtual bool InitCompositor(mozilla::layers::Compositor
* aCompositor
) {
455 virtual uint32_t GetGLFrameBufferFormat();
456 virtual bool CompositorInitiallyPaused() { return false; }
459 void ResolveIconName(const nsAString
& aIconName
, const nsAString
& aIconSuffix
,
461 virtual void OnDestroy();
462 void BaseCreate(nsIWidget
* aParent
, InitData
* aInitData
);
464 virtual void ConfigureAPZCTreeManager();
465 virtual void ConfigureAPZControllerThread();
466 virtual already_AddRefed
<GeckoContentController
>
467 CreateRootContentController();
469 // Dispatch an event that has already been routed through APZ.
470 nsEventStatus
ProcessUntransformedAPZEvent(
471 mozilla::WidgetInputEvent
* aEvent
,
472 const mozilla::layers::APZEventResult
& aApzResult
);
474 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
475 int32_t aNativeKeyCode
,
476 uint32_t aModifierFlags
,
477 const nsAString
& aCharacters
,
478 const nsAString
& aUnmodifiedCharacters
,
479 nsIObserver
* aObserver
) override
{
480 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "keyevent");
481 return NS_ERROR_UNEXPECTED
;
484 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
485 NativeMouseMessage aNativeMessage
,
486 mozilla::MouseButton aButton
,
487 nsIWidget::Modifiers aModifierFlags
,
488 nsIObserver
* aObserver
) override
{
489 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
490 return NS_ERROR_UNEXPECTED
;
493 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
494 nsIObserver
* aObserver
) override
{
495 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
496 return NS_ERROR_UNEXPECTED
;
499 nsresult
SynthesizeNativeMouseScrollEvent(
500 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
501 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
502 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
{
503 mozilla::widget::AutoObserverNotifier
notifier(aObserver
,
505 return NS_ERROR_UNEXPECTED
;
508 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
509 TouchPointerState aPointerState
,
510 LayoutDeviceIntPoint aPoint
,
511 double aPointerPressure
,
512 uint32_t aPointerOrientation
,
513 nsIObserver
* aObserver
) override
{
514 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "touchpoint");
515 return NS_ERROR_UNEXPECTED
;
518 nsresult
SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase
,
520 LayoutDeviceIntPoint aPoint
,
521 int32_t aModifierFlags
) override
{
523 false, "This method is not implemented on the current platform");
524 return NS_ERROR_UNEXPECTED
;
527 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
528 TouchPointerState aPointerState
,
529 LayoutDeviceIntPoint aPoint
,
530 double aPressure
, uint32_t aRotation
,
531 int32_t aTiltX
, int32_t aTiltY
,
533 nsIObserver
* aObserver
) override
{
535 false, "This method is not implemented on the current platform");
536 return NS_ERROR_UNEXPECTED
;
539 nsresult
SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint
,
540 uint32_t aModifierFlags
) override
{
542 false, "This method is not implemented on the current platform");
543 return NS_ERROR_UNEXPECTED
;
546 nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
547 LayoutDeviceIntPoint aPoint
,
548 double aDeltaX
, double aDeltaY
,
549 int32_t aModifierFlags
,
550 nsIObserver
* aObserver
) override
{
552 false, "This method is not implemented on the current platform");
553 return NS_ERROR_UNEXPECTED
;
557 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
558 * has non-native input transaction. Otherwise, returns nullptr.
560 void* GetPseudoIMEContext();
563 virtual already_AddRefed
<nsIWidget
> AllocateChildPopupWidget() {
564 return nsIWidget::CreateChildWindow();
567 WindowRenderer
* CreateFallbackRenderer();
569 PopupType
GetPopupType() const { return mPopupType
; }
571 bool HasRemoteContent() const { return mHasRemoteContent
; }
574 * Apply the current size constraints to the given size.
576 * @param aWidth width to constrain
577 * @param aHeight height to constrain
579 void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) override
{
580 SizeConstraints c
= GetSizeConstraints();
581 *aWidth
= std::max(c
.mMinSize
.width
, std::min(c
.mMaxSize
.width
, *aWidth
));
583 std::max(c
.mMinSize
.height
, std::min(c
.mMaxSize
.height
, *aHeight
));
586 CompositorBridgeChild
* GetRemoteRenderer() override
;
588 void ClearCachedWebrenderResources() override
;
590 void ClearWebrenderAnimationResources() override
;
592 bool SetNeedFastSnaphot() override
;
595 * Notify the widget that this window is being used with OMTC.
597 virtual void WindowUsesOMTC() {}
598 virtual void RegisterTouchWindow() {}
600 mozilla::dom::Document
* GetDocument() const;
602 void EnsureTextEventDispatcher();
604 // Notify the compositor that a device reset has occurred.
605 void OnRenderingDeviceReset();
609 bool AllowWebRenderForThisWindow();
612 * For widgets that support synthesizing native touch events, this function
613 * can be used to manage the current state of synthetic pointers. Each widget
614 * must maintain its own MultiTouchInput instance and pass it in as the state,
615 * along with the desired parameters for the changes. This function returns
616 * a new MultiTouchInput object that is ready to be dispatched.
618 mozilla::MultiTouchInput
UpdateSynthesizedTouchState(
619 mozilla::MultiTouchInput
* aState
, mozilla::TimeStamp aTimeStamp
,
620 uint32_t aPointerId
, TouchPointerState aPointerState
,
621 LayoutDeviceIntPoint aPoint
, double aPointerPressure
,
622 uint32_t aPointerOrientation
);
625 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
626 * or directly to gecko (if APZ is not enabled). This function must only
627 * be called from the main thread, and if APZ is enabled, that must also be
628 * the APZ controller thread.
630 void DispatchTouchInput(
631 mozilla::MultiTouchInput
& aInput
,
632 uint16_t aInputSource
=
633 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH
);
636 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
637 * or directly to gecko (if APZ is not enabled). This function must only
638 * be called from the main thread, and if APZ is enabled, that must also be
639 * the APZ controller thread.
641 void DispatchPanGestureInput(mozilla::PanGestureInput
& aInput
);
642 void DispatchPinchGestureInput(mozilla::PinchGestureInput
& aInput
);
644 static bool ConvertStatus(nsEventStatus aStatus
) {
645 return aStatus
== nsEventStatus_eConsumeNoDefault
;
649 // Returns whether compositing should use an external surface size.
650 virtual bool UseExternalCompositingSurface() const { return false; }
653 * Starts the OMTC compositor destruction sequence.
655 * When this function returns, the compositor should not be
656 * able to access the opengl context anymore.
657 * It is safe to call it several times if platform implementations
658 * require the compositor to be destroyed before ~nsBaseWidget is
659 * reached (This is the case with gtk2 for instance).
661 virtual void DestroyCompositor();
662 void DestroyLayerManager();
663 void ReleaseContentController();
664 void RevokeTransactionIdAllocator();
666 void FreeShutdownObserver();
667 void FreeLocalesChangedObserver();
669 bool IsPIPWindow() const { return mIsPIPWindow
; };
671 nsIWidgetListener
* mWidgetListener
;
672 nsIWidgetListener
* mAttachedWidgetListener
;
673 nsIWidgetListener
* mPreviouslyAttachedWidgetListener
;
674 RefPtr
<WindowRenderer
> mWindowRenderer
;
675 RefPtr
<CompositorSession
> mCompositorSession
;
676 RefPtr
<CompositorBridgeChild
> mCompositorBridgeChild
;
678 mozilla::UniquePtr
<mozilla::Mutex
> mCompositorVsyncDispatcherLock
;
679 RefPtr
<mozilla::CompositorVsyncDispatcher
> mCompositorVsyncDispatcher
;
681 RefPtr
<IAPZCTreeManager
> mAPZC
;
682 RefPtr
<GeckoContentController
> mRootContentController
;
683 RefPtr
<APZEventState
> mAPZEventState
;
684 RefPtr
<WidgetShutdownObserver
> mShutdownObserver
;
685 RefPtr
<LocalesChangedObserver
> mLocalesChangedObserver
;
686 RefPtr
<TextEventDispatcher
> mTextEventDispatcher
;
687 RefPtr
<mozilla::SwipeTracker
> mSwipeTracker
;
688 mozilla::UniquePtr
<mozilla::SwipeEventQueue
> mSwipeEventQueue
;
690 bool mCustomCursorAllowed
= true;
691 BorderStyle mBorderStyle
;
692 LayoutDeviceIntRect mBounds
;
694 PopupLevel mPopupLevel
;
695 PopupType mPopupType
;
696 SizeConstraints mSizeConstraints
;
697 bool mHasRemoteContent
;
699 struct FullscreenSavedState
{
700 DesktopRect windowRect
;
701 DesktopRect screenRect
;
703 mozilla::Maybe
<FullscreenSavedState
> mSavedBounds
;
706 bool mUseAttachedEvents
;
709 bool mIsFullyOccluded
;
710 bool mNeedFastSnaphot
;
711 // This flag is only used when APZ is off. It indicates that the current pan
712 // gesture was processed as a swipe. Sometimes the swipe animation can finish
713 // before momentum events of the pan gesture have stopped firing, so this
714 // flag tells us that we shouldn't allow the remaining events to cause
715 // scrolling. It is reset to false once a new gesture starts (as indicated by
716 // a PANGESTURE_(MAY)START event).
717 bool mCurrentPanGestureBelongsToSwipe
;
719 // It's PictureInPicture window.
720 bool mIsPIPWindow
: 1;
722 struct InitialZoomConstraints
{
723 InitialZoomConstraints(const uint32_t& aPresShellID
,
724 const ScrollableLayerGuid::ViewID
& aViewID
,
725 const ZoomConstraints
& aConstraints
)
726 : mPresShellID(aPresShellID
),
728 mConstraints(aConstraints
) {}
730 uint32_t mPresShellID
;
731 ScrollableLayerGuid::ViewID mViewID
;
732 ZoomConstraints mConstraints
;
735 mozilla::Maybe
<InitialZoomConstraints
> mInitialZoomConstraints
;
737 // This points to the resize listeners who have been notified that a live
738 // resize is in progress. This should always be empty when a live-resize is
740 nsTArray
<RefPtr
<mozilla::LiveResizeListener
>> mLiveResizeListeners
;
744 static nsAutoString
debug_GuiEventToString(
745 mozilla::WidgetGUIEvent
* aGuiEvent
);
747 static void debug_DumpInvalidate(FILE* aFileOut
, nsIWidget
* aWidget
,
748 const LayoutDeviceIntRect
* aRect
,
749 const char* aWidgetName
, int32_t aWindowID
);
751 static void debug_DumpEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
752 mozilla::WidgetGUIEvent
* aGuiEvent
,
753 const char* aWidgetName
, int32_t aWindowID
);
755 static void debug_DumpPaintEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
756 const nsIntRegion
& aPaintEvent
,
757 const char* aWidgetName
, int32_t aWindowID
);
759 static bool debug_GetCachedBoolPref(const char* aPrefName
);
763 already_AddRefed
<mozilla::layers::WebRenderLayerManager
>
764 CreateCompositorSession(int aWidth
, int aHeight
,
765 mozilla::layers::CompositorOptions
* aOptionsOut
);
768 #endif // nsBaseWidget_h__