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
;
44 class LocalAccessible
;
54 class CompositorBridgeChild
;
55 class CompositorBridgeParent
;
56 class IAPZCTreeManager
;
57 class GeckoContentController
;
59 struct APZEventResult
;
60 class CompositorSession
;
62 class WebRenderLayerManager
;
63 struct ScrollableLayerGuid
;
64 class RemoteCompositorSession
;
68 class CompositorWidgetDelegate
;
69 class InProcessCompositorWidget
;
70 class WidgetRenderingContext
;
73 class CompositorVsyncDispatcher
;
74 } // namespace mozilla
80 // Windows specific constant indicating the maximum number of touch points the
81 // inject api will allow. This also sets the maximum numerical value for touch
82 // ids we can use when injecting touch points on Windows.
83 #define TOUCH_INJECT_MAX_POINTS 256
87 // Helper class used in shutting down gfx related code.
88 class WidgetShutdownObserver final
: public nsIObserver
{
89 ~WidgetShutdownObserver();
92 explicit WidgetShutdownObserver(nsBaseWidget
* aWidget
);
100 nsBaseWidget
* mWidget
;
104 // Helper class used for observing locales change.
105 class LocalesChangedObserver final
: public nsIObserver
{
106 ~LocalesChangedObserver();
109 explicit LocalesChangedObserver(nsBaseWidget
* aWidget
);
117 nsBaseWidget
* mWidget
;
122 * Common widget implementation used as base class for native
123 * or crossplatform implementations of Widgets.
124 * All cross-platform behavior that all widgets need to implement
125 * should be placed in this class.
126 * (Note: widget implementations are not required to use this
127 * class, but it gives them a head start.)
130 class nsBaseWidget
: public nsIWidget
, public nsSupportsWeakReference
{
131 template <class EventType
, class InputType
>
132 friend class DispatchEventOnMainThread
;
133 friend class mozilla::widget::InProcessCompositorWidget
;
134 friend class mozilla::layers::RemoteCompositorSession
;
137 typedef base::Thread Thread
;
138 typedef mozilla::gfx::DrawTarget DrawTarget
;
139 typedef mozilla::gfx::SourceSurface SourceSurface
;
140 typedef mozilla::layers::BufferMode BufferMode
;
141 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild
;
142 typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent
;
143 typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager
;
144 typedef mozilla::layers::GeckoContentController GeckoContentController
;
145 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid
;
146 typedef mozilla::layers::APZEventState APZEventState
;
147 typedef mozilla::layers::SetAllowedTouchBehaviorCallback
148 SetAllowedTouchBehaviorCallback
;
149 typedef mozilla::CSSIntRect CSSIntRect
;
150 typedef mozilla::CSSRect CSSRect
;
151 typedef mozilla::ScreenRotation ScreenRotation
;
152 typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate
;
153 typedef mozilla::layers::CompositorSession CompositorSession
;
154 typedef mozilla::layers::ImageContainer ImageContainer
;
156 virtual ~nsBaseWidget();
161 NS_DECL_THREADSAFE_ISUPPORTS
163 // nsIWidget interface
164 void CaptureMouse(bool aCapture
) override
{}
165 void CaptureRollupEvents(nsIRollupListener
* aListener
,
166 bool aDoCapture
) override
{}
167 nsIWidgetListener
* GetWidgetListener() const override
;
168 void SetWidgetListener(nsIWidgetListener
* alistener
) override
;
169 void Destroy() override
;
170 void SetParent(nsIWidget
* aNewParent
) override
{};
171 nsIWidget
* GetParent() override
;
172 nsIWidget
* GetTopLevelWidget() override
;
173 nsIWidget
* GetSheetWindowParent(void) override
;
174 float GetDPI() override
;
175 void AddChild(nsIWidget
* aChild
) override
;
176 void RemoveChild(nsIWidget
* aChild
) override
;
178 void SetZIndex(int32_t aZIndex
) override
;
179 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
, nsIWidget
* aWidget
,
180 bool aActivate
) override
{}
182 void SetSizeMode(nsSizeMode aMode
) override
;
183 nsSizeMode
SizeMode() override
{ return mSizeMode
; }
184 void GetWorkspaceID(nsAString
& workspaceID
) override
;
185 void MoveToWorkspace(const nsAString
& workspaceID
) override
;
186 bool IsTiled() const override
{ return mIsTiled
; }
188 bool IsFullyOccluded() const override
{ return mIsFullyOccluded
; }
190 void SetCursor(const Cursor
&) override
;
191 void ClearCachedCursor() final
{
193 mUpdateCursor
= true;
195 void SetTransparencyMode(nsTransparencyMode aMode
) override
;
196 nsTransparencyMode
GetTransparencyMode() override
;
197 void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle
) override
{}
198 void SetShowsToolbarButton(bool aShow
) override
{}
199 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen
) override
{}
200 void SetWindowAnimationType(WindowAnimationType aType
) override
{}
201 void HideWindowChrome(bool aShouldHide
) override
{}
202 bool PrepareForFullscreenTransition(nsISupports
** aData
) override
{
205 void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
206 uint16_t aDuration
, nsISupports
* aData
,
207 nsIRunnable
* aCallback
) override
;
208 void CleanupFullscreenTransition() override
{}
209 already_AddRefed
<nsIScreen
> GetWidgetScreen() override
;
210 nsresult
MakeFullScreen(bool aFullScreen
,
211 nsIScreen
* aScreen
= nullptr) override
;
212 void InfallibleMakeFullScreen(bool aFullScreen
, nsIScreen
* aScreen
= nullptr);
214 WindowRenderer
* GetWindowRenderer() override
;
216 // A remote compositor session tied to this window has been lost and IPC
217 // messages will no longer work. The widget must clean up any lingering
218 // resources and possibly schedule another paint.
220 // A reference to the session object is held until this function has
222 virtual void NotifyCompositorSessionLost(
223 mozilla::layers::CompositorSession
* aSession
);
225 already_AddRefed
<mozilla::CompositorVsyncDispatcher
>
226 GetCompositorVsyncDispatcher();
227 virtual void CreateCompositorVsyncDispatcher();
228 virtual void CreateCompositor();
229 virtual void CreateCompositor(int aWidth
, int aHeight
);
230 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate
*) {}
231 void PrepareWindowEffects() override
{}
232 void UpdateThemeGeometries(
233 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) override
{}
234 void SetModal(bool aModal
) override
{}
235 uint32_t GetMaxTouchPoints() const override
;
236 void SetWindowClass(const nsAString
& xulWinType
) override
{}
237 // Return whether this widget interprets parameters to Move and Resize APIs
238 // as "desktop pixels" rather than "device pixels", and therefore
239 // applies its GetDefaultScale() value to them before using them as mBounds
240 // etc (which are always stored in device pixels).
241 // Note that APIs that -get- the widget's position/size/bounds, rather than
242 // -setting- them (i.e. moving or resizing the widget) will always return
243 // values in the widget's device pixels.
244 bool BoundsUseDesktopPixels() const {
245 return mWindowType
<= eWindowType_popup
;
247 // Default implementation, to be overridden by platforms where desktop coords
248 // are virtualized and may not correspond to device pixels on the screen.
249 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
250 return mozilla::DesktopToLayoutDeviceScale(1.0);
252 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScaleByScreen()
255 void ConstrainPosition(bool aAllowSlop
, int32_t* aX
, int32_t* aY
) override
{}
256 void MoveClient(const DesktopPoint
& aOffset
) override
;
257 void ResizeClient(const DesktopSize
& aSize
, bool aRepaint
) override
;
258 void ResizeClient(const DesktopRect
& aRect
, bool aRepaint
) override
;
259 LayoutDeviceIntRect
GetBounds() override
;
260 LayoutDeviceIntRect
GetClientBounds() override
;
261 LayoutDeviceIntRect
GetScreenBounds() override
;
262 [[nodiscard
]] nsresult
GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
263 nsresult
SetNonClientMargins(LayoutDeviceIntMargin
& aMargins
) override
;
264 LayoutDeviceIntPoint
GetClientOffset() override
;
265 void EnableDragDrop(bool aEnable
) override
{};
266 nsresult
AsyncEnableDragDrop(bool aEnable
) override
;
267 [[nodiscard
]] nsresult
GetAttention(int32_t aCycleCount
) override
{
270 bool HasPendingInputEvent() override
;
271 void SetIcon(const nsAString
& aIconSpec
) override
{}
272 void SetDrawsInTitlebar(bool aState
) override
{}
273 bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) override
;
274 void FreeNativeData(void* data
, uint32_t aDataType
) override
{}
275 [[nodiscard
]] nsresult
BeginResizeDrag(mozilla::WidgetGUIEvent
* aEvent
,
277 int32_t aVertical
) override
{
278 return NS_ERROR_NOT_IMPLEMENTED
;
280 nsresult
ActivateNativeMenuItemAt(const nsAString
& indexString
) override
{
281 return NS_ERROR_NOT_IMPLEMENTED
;
283 nsresult
ForceUpdateNativeMenuAt(const nsAString
& indexString
) override
{
284 return NS_ERROR_NOT_IMPLEMENTED
;
286 nsresult
NotifyIME(const IMENotification
& aIMENotification
) final
;
287 [[nodiscard
]] nsresult
AttachNativeKeyEvent(
288 mozilla::WidgetKeyboardEvent
& aEvent
) override
{
289 return NS_ERROR_NOT_IMPLEMENTED
;
291 bool ComputeShouldAccelerate();
292 virtual bool WidgetTypeSupportsAcceleration() { return true; }
293 [[nodiscard
]] nsresult
OnDefaultButtonLoaded(
294 const LayoutDeviceIntRect
& aButtonRect
) override
{
295 return NS_ERROR_NOT_IMPLEMENTED
;
297 already_AddRefed
<nsIWidget
> CreateChild(
298 const LayoutDeviceIntRect
& aRect
, nsWidgetInitData
* aInitData
= nullptr,
299 bool aForceUseIWidgetParent
= false) override
;
300 void AttachViewToTopLevel(bool aUseAttachedEvents
) override
;
301 nsIWidgetListener
* GetAttachedWidgetListener() const override
;
302 void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) override
;
303 nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() override
;
304 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener
*) override
;
305 NativeIMEContext
GetNativeIMEContext() override
;
306 TextEventDispatcher
* GetTextEventDispatcher() final
;
307 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
308 void ZoomToRect(const uint32_t& aPresShellId
,
309 const ScrollableLayerGuid::ViewID
& aViewId
,
310 const CSSRect
& aRect
, const uint32_t& aFlags
) override
;
312 // Dispatch an event that must be first be routed through APZ.
313 ContentAndAPZEventStatus
DispatchInputEvent(
314 mozilla::WidgetInputEvent
* aEvent
) override
;
315 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) override
;
317 void SetConfirmedTargetAPZC(
318 uint64_t aInputBlockId
,
319 const nsTArray
<ScrollableLayerGuid
>& aTargets
) const override
;
321 void UpdateZoomConstraints(
322 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
323 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) override
;
325 bool AsyncPanZoomEnabled() const override
;
327 void NotifyWindowDestroyed();
328 void NotifySizeMoveDone();
329 void NotifyWindowMoved(int32_t aX
, int32_t aY
);
331 void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
{}
333 // Should be called by derived implementations to notify on system color and
335 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind
);
336 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings
);
339 // Get the accessible for the window.
340 mozilla::a11y::LocalAccessible
* GetRootAccessible();
343 // Return true if this is a simple widget (that is typically not worth
345 bool IsSmallPopup() const;
347 nsPopupLevel
PopupLevel() { return mPopupLevel
; }
349 LayoutDeviceIntSize
ClientToWindowSize(
350 const LayoutDeviceIntSize
& aClientSize
) override
{
354 // return true if this is a popup widget with a native titlebar
355 bool IsPopupWithTitleBar() const {
356 return (mWindowType
== eWindowType_popup
&&
357 mBorderStyle
!= eBorderStyle_default
&&
358 mBorderStyle
& eBorderStyle_title
);
361 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
{}
363 const SizeConstraints
GetSizeConstraints() override
;
364 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
366 void StartAsyncScrollbarDrag(const AsyncDragMetrics
& aDragMetrics
) override
;
368 bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
369 const ScrollableLayerGuid
& aGuid
) override
;
371 void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) override
;
373 mozilla::layers::LayersId
GetRootLayerTreeId() override
;
376 * Use this when GetLayerManager() returns a BasicLayerManager
377 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
378 * layer manager to temporarily render into aTarget.
380 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
381 * |aRotation| is the "virtual rotation" to apply when rendering to
382 * the target. When |aRotation| is ROTATION_0,
383 * |aNaturalWidgetBounds| is not used.
385 class AutoLayerManagerSetup
{
387 AutoLayerManagerSetup(nsBaseWidget
* aWidget
, gfxContext
* aTarget
,
388 BufferMode aDoubleBuffering
);
389 ~AutoLayerManagerSetup();
392 nsBaseWidget
* mWidget
;
393 mozilla::FallbackRenderer
* mRenderer
= nullptr;
395 friend class AutoLayerManagerSetup
;
397 virtual bool ShouldUseOffMainThreadCompositing();
399 static nsIRollupListener
* GetActiveRollupListener();
405 // These functions should be called at the start and end of a "live" widget
406 // resize (i.e. when the window contents are repainting during the resize,
407 // such as when the user drags a window border). It will suppress the
408 // displayport during the live resize to avoid unneccessary overpainting.
409 void NotifyLiveResizeStarted();
410 void NotifyLiveResizeStopped();
412 #if defined(MOZ_WIDGET_ANDROID)
413 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override
{};
414 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
415 const CSSToScreenScale
& aZoom
) override
{};
416 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
417 bool aNeedsYFlip
) override
{};
420 virtual void LocalesChanged() {}
422 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState
) {}
425 // These are methods for CompositorWidgetWrapper, and should only be
426 // accessed from that class. Derived widgets can choose which methods to
427 // implement, or none if supporting out-of-process compositing.
428 virtual bool PreRender(mozilla::widget::WidgetRenderingContext
* aContext
) {
431 virtual void PostRender(mozilla::widget::WidgetRenderingContext
* aContext
) {}
432 virtual RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() {
435 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawing();
436 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawingInRegion(
437 const LayoutDeviceIntRegion
& aInvalidRegion
, BufferMode
* aBufferMode
) {
438 return StartRemoteDrawing();
440 virtual void EndRemoteDrawing() {}
441 virtual void EndRemoteDrawingInRegion(
442 DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
445 virtual void CleanupRemoteDrawing() {}
446 virtual void CleanupWindowEffects() {}
447 virtual bool InitCompositor(mozilla::layers::Compositor
* aCompositor
) {
450 virtual uint32_t GetGLFrameBufferFormat();
451 virtual bool CompositorInitiallyPaused() { return false; }
454 void ResolveIconName(const nsAString
& aIconName
, const nsAString
& aIconSuffix
,
456 virtual void OnDestroy();
457 void BaseCreate(nsIWidget
* aParent
, nsWidgetInitData
* aInitData
);
459 virtual void ConfigureAPZCTreeManager();
460 virtual void ConfigureAPZControllerThread();
461 virtual already_AddRefed
<GeckoContentController
>
462 CreateRootContentController();
464 // Dispatch an event that has already been routed through APZ.
465 nsEventStatus
ProcessUntransformedAPZEvent(
466 mozilla::WidgetInputEvent
* aEvent
,
467 const mozilla::layers::APZEventResult
& aApzResult
);
469 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
470 int32_t aNativeKeyCode
,
471 uint32_t aModifierFlags
,
472 const nsAString
& aCharacters
,
473 const nsAString
& aUnmodifiedCharacters
,
474 nsIObserver
* aObserver
) override
{
475 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "keyevent");
476 return NS_ERROR_UNEXPECTED
;
479 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
480 NativeMouseMessage aNativeMessage
,
481 mozilla::MouseButton aButton
,
482 nsIWidget::Modifiers aModifierFlags
,
483 nsIObserver
* aObserver
) override
{
484 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
485 return NS_ERROR_UNEXPECTED
;
488 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
489 nsIObserver
* aObserver
) override
{
490 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
491 return NS_ERROR_UNEXPECTED
;
494 nsresult
SynthesizeNativeMouseScrollEvent(
495 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
496 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
497 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
{
498 mozilla::widget::AutoObserverNotifier
notifier(aObserver
,
500 return NS_ERROR_UNEXPECTED
;
503 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
504 TouchPointerState aPointerState
,
505 LayoutDeviceIntPoint aPoint
,
506 double aPointerPressure
,
507 uint32_t aPointerOrientation
,
508 nsIObserver
* aObserver
) override
{
509 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "touchpoint");
510 return NS_ERROR_UNEXPECTED
;
513 nsresult
SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase
,
515 LayoutDeviceIntPoint aPoint
,
516 int32_t aModifierFlags
) override
{
518 false, "This method is not implemented on the current platform");
519 return NS_ERROR_UNEXPECTED
;
522 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
523 TouchPointerState aPointerState
,
524 LayoutDeviceIntPoint aPoint
,
525 double aPressure
, uint32_t aRotation
,
526 int32_t aTiltX
, int32_t aTiltY
,
528 nsIObserver
* aObserver
) override
{
530 false, "This method is not implemented on the current platform");
531 return NS_ERROR_UNEXPECTED
;
534 nsresult
SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint
,
535 uint32_t aModifierFlags
) override
{
537 false, "This method is not implemented on the current platform");
538 return NS_ERROR_UNEXPECTED
;
541 nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
542 LayoutDeviceIntPoint aPoint
,
543 double aDeltaX
, double aDeltaY
,
544 int32_t aModifierFlags
) override
{
546 false, "This method is not implemented on the current platform");
547 return NS_ERROR_UNEXPECTED
;
551 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
552 * has non-native input transaction. Otherwise, returns nullptr.
554 void* GetPseudoIMEContext();
557 virtual already_AddRefed
<nsIWidget
> AllocateChildPopupWidget() {
558 return nsIWidget::CreateChildWindow();
561 WindowRenderer
* CreateFallbackRenderer();
563 nsPopupType
PopupType() const { return mPopupType
; }
565 bool HasRemoteContent() const { return mHasRemoteContent
; }
567 void NotifyRollupGeometryChange() {
568 // XULPopupManager isn't interested in this notification, so only
569 // send it if gRollupListener is set.
570 if (gRollupListener
) {
571 gRollupListener
->NotifyGeometryChange();
576 * Apply the current size constraints to the given size.
578 * @param aWidth width to constrain
579 * @param aHeight height to constrain
581 void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) override
{
582 SizeConstraints c
= GetSizeConstraints();
583 *aWidth
= std::max(c
.mMinSize
.width
, std::min(c
.mMaxSize
.width
, *aWidth
));
585 std::max(c
.mMinSize
.height
, std::min(c
.mMaxSize
.height
, *aHeight
));
588 CompositorBridgeChild
* GetRemoteRenderer() override
;
590 void ClearCachedWebrenderResources() override
;
593 * Notify the widget that this window is being used with OMTC.
595 virtual void WindowUsesOMTC() {}
596 virtual void RegisterTouchWindow() {}
598 mozilla::dom::Document
* GetDocument() const;
600 void EnsureTextEventDispatcher();
602 // Notify the compositor that a device reset has occurred.
603 void OnRenderingDeviceReset();
607 bool AllowWebRenderForThisWindow();
610 * For widgets that support synthesizing native touch events, this function
611 * can be used to manage the current state of synthetic pointers. Each widget
612 * must maintain its own MultiTouchInput instance and pass it in as the state,
613 * along with the desired parameters for the changes. This function returns
614 * a new MultiTouchInput object that is ready to be dispatched.
616 mozilla::MultiTouchInput
UpdateSynthesizedTouchState(
617 mozilla::MultiTouchInput
* aState
, uint32_t aTime
,
618 mozilla::TimeStamp aTimeStamp
, uint32_t aPointerId
,
619 TouchPointerState aPointerState
, LayoutDeviceIntPoint aPoint
,
620 double aPointerPressure
, uint32_t aPointerOrientation
);
623 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
624 * or directly to gecko (if APZ is not enabled). This function must only
625 * be called from the main thread, and if APZ is enabled, that must also be
626 * the APZ controller thread.
628 void DispatchTouchInput(
629 mozilla::MultiTouchInput
& aInput
,
630 uint16_t aInputSource
=
631 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH
);
634 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
635 * or directly to gecko (if APZ is not enabled). This function must only
636 * be called from the main thread, and if APZ is enabled, that must also be
637 * the APZ controller thread.
639 void DispatchPanGestureInput(mozilla::PanGestureInput
& aInput
);
640 void DispatchPinchGestureInput(mozilla::PinchGestureInput
& aInput
);
643 // Returns whether compositing should use an external surface size.
644 virtual bool UseExternalCompositingSurface() const { return false; }
647 * Starts the OMTC compositor destruction sequence.
649 * When this function returns, the compositor should not be
650 * able to access the opengl context anymore.
651 * It is safe to call it several times if platform implementations
652 * require the compositor to be destroyed before ~nsBaseWidget is
653 * reached (This is the case with gtk2 for instance).
655 virtual void DestroyCompositor();
656 void DestroyLayerManager();
657 void ReleaseContentController();
658 void RevokeTransactionIdAllocator();
660 void FreeShutdownObserver();
661 void FreeLocalesChangedObserver();
663 nsIWidgetListener
* mWidgetListener
;
664 nsIWidgetListener
* mAttachedWidgetListener
;
665 nsIWidgetListener
* mPreviouslyAttachedWidgetListener
;
666 RefPtr
<WindowRenderer
> mWindowRenderer
;
667 RefPtr
<CompositorSession
> mCompositorSession
;
668 RefPtr
<CompositorBridgeChild
> mCompositorBridgeChild
;
670 mozilla::UniquePtr
<mozilla::Mutex
> mCompositorVsyncDispatcherLock
;
671 RefPtr
<mozilla::CompositorVsyncDispatcher
> mCompositorVsyncDispatcher
;
673 RefPtr
<IAPZCTreeManager
> mAPZC
;
674 RefPtr
<GeckoContentController
> mRootContentController
;
675 RefPtr
<APZEventState
> mAPZEventState
;
676 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback
;
677 RefPtr
<WidgetShutdownObserver
> mShutdownObserver
;
678 RefPtr
<LocalesChangedObserver
> mLocalesChangedObserver
;
679 RefPtr
<TextEventDispatcher
> mTextEventDispatcher
;
681 nsBorderStyle mBorderStyle
;
682 LayoutDeviceIntRect mBounds
;
683 LayoutDeviceIntRect
* mOriginalBounds
;
684 nsSizeMode mSizeMode
;
686 nsPopupLevel mPopupLevel
;
687 nsPopupType mPopupType
;
688 SizeConstraints mSizeConstraints
;
689 bool mHasRemoteContent
;
693 bool mUseAttachedEvents
;
696 bool mIsFullyOccluded
;
697 static nsIRollupListener
* gRollupListener
;
699 struct InitialZoomConstraints
{
700 InitialZoomConstraints(const uint32_t& aPresShellID
,
701 const ScrollableLayerGuid::ViewID
& aViewID
,
702 const ZoomConstraints
& aConstraints
)
703 : mPresShellID(aPresShellID
),
705 mConstraints(aConstraints
) {}
707 uint32_t mPresShellID
;
708 ScrollableLayerGuid::ViewID mViewID
;
709 ZoomConstraints mConstraints
;
712 mozilla::Maybe
<InitialZoomConstraints
> mInitialZoomConstraints
;
714 // This points to the resize listeners who have been notified that a live
715 // resize is in progress. This should always be empty when a live-resize is
717 nsTArray
<RefPtr
<mozilla::LiveResizeListener
>> mLiveResizeListeners
;
721 static nsAutoString
debug_GuiEventToString(
722 mozilla::WidgetGUIEvent
* aGuiEvent
);
724 static void debug_DumpInvalidate(FILE* aFileOut
, nsIWidget
* aWidget
,
725 const LayoutDeviceIntRect
* aRect
,
726 const char* aWidgetName
, int32_t aWindowID
);
728 static void debug_DumpEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
729 mozilla::WidgetGUIEvent
* aGuiEvent
,
730 const char* aWidgetName
, int32_t aWindowID
);
732 static void debug_DumpPaintEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
733 const nsIntRegion
& aPaintEvent
,
734 const char* aWidgetName
, int32_t aWindowID
);
736 static bool debug_GetCachedBoolPref(const char* aPrefName
);
740 already_AddRefed
<mozilla::layers::WebRenderLayerManager
>
741 CreateCompositorSession(int aWidth
, int aHeight
,
742 mozilla::layers::CompositorOptions
* aOptionsOut
);
745 #endif // nsBaseWidget_h__