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"
20 #include "nsIWidget.h"
21 #include "nsWidgetsCID.h"
25 #include "nsIRollupListener.h"
26 #include "nsIObserver.h"
27 #include "nsIWidgetListener.h"
28 #include "nsPIDOMWindow.h"
29 #include "nsWeakReference.h"
34 // Scroll capture constants
35 const uint32_t kScrollCaptureFillColor
= 0xFFa0a0a0; // gray
36 const mozilla::gfx::SurfaceFormat kScrollCaptureFormat
=
37 mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32
;
44 class CompositorVsyncDispatcher
;
45 class LiveResizeListener
;
49 class LocalAccessible
;
59 class BasicLayerManager
;
60 class CompositorBridgeChild
;
61 class CompositorBridgeParent
;
62 class IAPZCTreeManager
;
63 class GeckoContentController
;
65 struct APZEventResult
;
66 class CompositorSession
;
68 struct ScrollableLayerGuid
;
69 class RemoteCompositorSession
;
73 class CompositorWidgetDelegate
;
74 class InProcessCompositorWidget
;
75 class WidgetRenderingContext
;
78 class CompositorVsyncDispatcher
;
79 } // namespace mozilla
85 // Windows specific constant indicating the maximum number of touch points the
86 // inject api will allow. This also sets the maximum numerical value for touch
87 // ids we can use when injecting touch points on Windows.
88 #define TOUCH_INJECT_MAX_POINTS 256
92 // Helper class used in shutting down gfx related code.
93 class WidgetShutdownObserver final
: public nsIObserver
{
94 ~WidgetShutdownObserver();
97 explicit WidgetShutdownObserver(nsBaseWidget
* aWidget
);
105 nsBaseWidget
* mWidget
;
110 * Common widget implementation used as base class for native
111 * or crossplatform implementations of Widgets.
112 * All cross-platform behavior that all widgets need to implement
113 * should be placed in this class.
114 * (Note: widget implementations are not required to use this
115 * class, but it gives them a head start.)
118 class nsBaseWidget
: public nsIWidget
, public nsSupportsWeakReference
{
119 template <class EventType
, class InputType
>
120 friend class DispatchEventOnMainThread
;
121 friend class mozilla::widget::InProcessCompositorWidget
;
122 friend class mozilla::layers::RemoteCompositorSession
;
125 typedef base::Thread Thread
;
126 typedef mozilla::gfx::DrawTarget DrawTarget
;
127 typedef mozilla::gfx::SourceSurface SourceSurface
;
128 typedef mozilla::layers::BasicLayerManager BasicLayerManager
;
129 typedef mozilla::layers::BufferMode BufferMode
;
130 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild
;
131 typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent
;
132 typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager
;
133 typedef mozilla::layers::GeckoContentController GeckoContentController
;
134 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid
;
135 typedef mozilla::layers::APZEventState APZEventState
;
136 typedef mozilla::layers::SetAllowedTouchBehaviorCallback
137 SetAllowedTouchBehaviorCallback
;
138 typedef mozilla::CSSIntRect CSSIntRect
;
139 typedef mozilla::CSSRect CSSRect
;
140 typedef mozilla::ScreenRotation ScreenRotation
;
141 typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate
;
142 typedef mozilla::layers::CompositorSession CompositorSession
;
143 typedef mozilla::layers::ImageContainer ImageContainer
;
145 virtual ~nsBaseWidget();
152 // nsIWidget interface
153 void CaptureMouse(bool aCapture
) override
{}
154 void CaptureRollupEvents(nsIRollupListener
* aListener
,
155 bool aDoCapture
) override
{}
156 nsIWidgetListener
* GetWidgetListener() override
;
157 void SetWidgetListener(nsIWidgetListener
* alistener
) override
;
158 void Destroy() override
;
159 void SetParent(nsIWidget
* aNewParent
) override
{};
160 nsIWidget
* GetParent() override
;
161 nsIWidget
* GetTopLevelWidget() override
;
162 nsIWidget
* GetSheetWindowParent(void) override
;
163 float GetDPI() override
;
164 void AddChild(nsIWidget
* aChild
) override
;
165 void RemoveChild(nsIWidget
* aChild
) override
;
167 void SetZIndex(int32_t aZIndex
) override
;
168 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
, nsIWidget
* aWidget
,
169 bool aActivate
) override
{}
171 void SetSizeMode(nsSizeMode aMode
) override
;
172 nsSizeMode
SizeMode() override
{ return mSizeMode
; }
173 void GetWorkspaceID(nsAString
& workspaceID
) override
;
174 void MoveToWorkspace(const nsAString
& workspaceID
) override
;
175 bool IsTiled() const override
{ return mIsTiled
; }
177 bool IsFullyOccluded() const override
{ return mIsFullyOccluded
; }
179 void SetCursor(const Cursor
&) override
;
180 void ClearCachedCursor() final
{
182 mUpdateCursor
= true;
184 void SetTransparencyMode(nsTransparencyMode aMode
) override
;
185 nsTransparencyMode
GetTransparencyMode() override
;
186 void GetWindowClipRegion(nsTArray
<LayoutDeviceIntRect
>* aRects
) override
;
187 void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle
) override
{}
188 void SetShowsToolbarButton(bool aShow
) override
{}
189 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen
) override
{}
190 void SetWindowAnimationType(WindowAnimationType aType
) override
{}
191 void HideWindowChrome(bool aShouldHide
) override
{}
192 bool PrepareForFullscreenTransition(nsISupports
** aData
) override
{
195 void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
196 uint16_t aDuration
, nsISupports
* aData
,
197 nsIRunnable
* aCallback
) override
;
198 void CleanupFullscreenTransition() override
{}
199 already_AddRefed
<nsIScreen
> GetWidgetScreen() override
;
200 nsresult
MakeFullScreen(bool aFullScreen
,
201 nsIScreen
* aScreen
= nullptr) override
;
202 void InfallibleMakeFullScreen(bool aFullScreen
, nsIScreen
* aScreen
= nullptr);
204 LayerManager
* GetLayerManager(
205 PLayerTransactionChild
* aShadowManager
= nullptr,
206 LayersBackend aBackendHint
= mozilla::layers::LayersBackend::LAYERS_NONE
,
207 LayerManagerPersistence aPersistence
= LAYER_MANAGER_CURRENT
) override
;
209 // A remote compositor session tied to this window has been lost and IPC
210 // messages will no longer work. The widget must clean up any lingering
211 // resources and possibly schedule another paint.
213 // A reference to the session object is held until this function has
215 void NotifyCompositorSessionLost(
216 mozilla::layers::CompositorSession
* aSession
);
218 already_AddRefed
<mozilla::CompositorVsyncDispatcher
>
219 GetCompositorVsyncDispatcher();
220 virtual void CreateCompositorVsyncDispatcher();
221 virtual void CreateCompositor();
222 virtual void CreateCompositor(int aWidth
, int aHeight
);
223 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate
*) {}
224 void PrepareWindowEffects() override
{}
225 void UpdateThemeGeometries(
226 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) override
{}
227 void SetModal(bool aModal
) override
{}
228 uint32_t GetMaxTouchPoints() const override
;
229 void SetWindowClass(const nsAString
& xulWinType
) override
{}
230 nsresult
SetWindowClipRegion(const nsTArray
<LayoutDeviceIntRect
>& aRects
,
231 bool aIntersectWithExisting
) override
;
232 // Return whether this widget interprets parameters to Move and Resize APIs
233 // as "desktop pixels" rather than "device pixels", and therefore
234 // applies its GetDefaultScale() value to them before using them as mBounds
235 // etc (which are always stored in device pixels).
236 // Note that APIs that -get- the widget's position/size/bounds, rather than
237 // -setting- them (i.e. moving or resizing the widget) will always return
238 // values in the widget's device pixels.
239 bool BoundsUseDesktopPixels() const {
240 return mWindowType
<= eWindowType_popup
;
242 // Default implementation, to be overridden by platforms where desktop coords
243 // are virtualized and may not correspond to device pixels on the screen.
244 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
245 return mozilla::DesktopToLayoutDeviceScale(1.0);
247 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScaleByScreen()
250 void ConstrainPosition(bool aAllowSlop
, int32_t* aX
, int32_t* aY
) override
{}
251 void MoveClient(const DesktopPoint
& aOffset
) override
;
252 void ResizeClient(const DesktopSize
& aSize
, bool aRepaint
) override
;
253 void ResizeClient(const DesktopRect
& aRect
, bool aRepaint
) override
;
254 LayoutDeviceIntRect
GetBounds() override
;
255 LayoutDeviceIntRect
GetClientBounds() override
;
256 LayoutDeviceIntRect
GetScreenBounds() override
;
257 [[nodiscard
]] nsresult
GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
258 nsresult
SetNonClientMargins(LayoutDeviceIntMargin
& aMargins
) override
;
259 LayoutDeviceIntPoint
GetClientOffset() override
;
260 void EnableDragDrop(bool aEnable
) override
{};
261 nsresult
AsyncEnableDragDrop(bool aEnable
) override
;
262 [[nodiscard
]] nsresult
GetAttention(int32_t aCycleCount
) override
{
265 bool HasPendingInputEvent() override
;
266 void SetIcon(const nsAString
& aIconSpec
) override
{}
267 void SetDrawsInTitlebar(bool aState
) override
{}
268 bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) override
;
269 void FreeNativeData(void* data
, uint32_t aDataType
) override
{}
270 [[nodiscard
]] nsresult
BeginResizeDrag(mozilla::WidgetGUIEvent
* aEvent
,
272 int32_t aVertical
) override
{
273 return NS_ERROR_NOT_IMPLEMENTED
;
275 nsresult
ActivateNativeMenuItemAt(const nsAString
& indexString
) override
{
276 return NS_ERROR_NOT_IMPLEMENTED
;
278 nsresult
ForceUpdateNativeMenuAt(const nsAString
& indexString
) override
{
279 return NS_ERROR_NOT_IMPLEMENTED
;
281 nsresult
NotifyIME(const IMENotification
& aIMENotification
) final
;
282 [[nodiscard
]] nsresult
AttachNativeKeyEvent(
283 mozilla::WidgetKeyboardEvent
& aEvent
) override
{
284 return NS_ERROR_NOT_IMPLEMENTED
;
286 bool ComputeShouldAccelerate();
287 virtual bool WidgetTypeSupportsAcceleration() { return true; }
288 [[nodiscard
]] nsresult
OnDefaultButtonLoaded(
289 const LayoutDeviceIntRect
& aButtonRect
) override
{
290 return NS_ERROR_NOT_IMPLEMENTED
;
292 already_AddRefed
<nsIWidget
> CreateChild(
293 const LayoutDeviceIntRect
& aRect
, nsWidgetInitData
* aInitData
= nullptr,
294 bool aForceUseIWidgetParent
= false) override
;
295 void AttachViewToTopLevel(bool aUseAttachedEvents
) override
;
296 nsIWidgetListener
* GetAttachedWidgetListener() override
;
297 void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) override
;
298 nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() override
;
299 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener
*) override
;
300 NativeIMEContext
GetNativeIMEContext() override
;
301 TextEventDispatcher
* GetTextEventDispatcher() final
;
302 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
303 void ZoomToRect(const uint32_t& aPresShellId
,
304 const ScrollableLayerGuid::ViewID
& aViewId
,
305 const CSSRect
& aRect
, const uint32_t& aFlags
) override
;
307 // Dispatch an event that must be first be routed through APZ.
308 ContentAndAPZEventStatus
DispatchInputEvent(
309 mozilla::WidgetInputEvent
* aEvent
) override
;
310 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) 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 NotifyWindowDestroyed();
323 void NotifySizeMoveDone();
324 void NotifyWindowMoved(int32_t aX
, int32_t aY
);
326 // Register plugin windows for remote updates from the compositor
327 void RegisterPluginWindowForRemoteUpdates() override
;
328 void UnregisterPluginWindowForRemoteUpdates() override
;
330 void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
{}
332 // Should be called by derived implementations to notify on system color and
334 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind
);
335 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings
);
338 // Get the accessible for the window.
339 mozilla::a11y::LocalAccessible
* GetRootAccessible();
342 // Return true if this is a simple widget (that is typically not worth
344 bool IsSmallPopup() const;
346 nsPopupLevel
PopupLevel() { return mPopupLevel
; }
348 LayoutDeviceIntSize
ClientToWindowSize(
349 const LayoutDeviceIntSize
& aClientSize
) override
{
353 // return true if this is a popup widget with a native titlebar
354 bool IsPopupWithTitleBar() const {
355 return (mWindowType
== eWindowType_popup
&&
356 mBorderStyle
!= eBorderStyle_default
&&
357 mBorderStyle
& eBorderStyle_title
);
360 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
{}
362 const SizeConstraints
GetSizeConstraints() override
;
363 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
365 void StartAsyncScrollbarDrag(const AsyncDragMetrics
& aDragMetrics
) override
;
367 bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
368 const ScrollableLayerGuid
& aGuid
) override
;
370 void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) override
;
373 * Use this when GetLayerManager() returns a BasicLayerManager
374 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
375 * layer manager to temporarily render into aTarget.
377 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
378 * |aRotation| is the "virtual rotation" to apply when rendering to
379 * the target. When |aRotation| is ROTATION_0,
380 * |aNaturalWidgetBounds| is not used.
382 class AutoLayerManagerSetup
{
384 AutoLayerManagerSetup(nsBaseWidget
* aWidget
, gfxContext
* aTarget
,
385 BufferMode aDoubleBuffering
,
386 ScreenRotation aRotation
= mozilla::ROTATION_0
);
387 ~AutoLayerManagerSetup();
390 nsBaseWidget
* mWidget
;
391 RefPtr
<BasicLayerManager
> mLayerManager
;
393 friend class AutoLayerManagerSetup
;
395 virtual bool ShouldUseOffMainThreadCompositing();
397 static nsIRollupListener
* GetActiveRollupListener();
404 uint64_t CreateScrollCaptureContainer() override
;
407 // These functions should be called at the start and end of a "live" widget
408 // resize (i.e. when the window contents are repainting during the resize,
409 // such as when the user drags a window border). It will suppress the
410 // displayport during the live resize to avoid unneccessary overpainting.
411 void NotifyLiveResizeStarted();
412 void NotifyLiveResizeStopped();
414 #if defined(MOZ_WIDGET_ANDROID)
415 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override
{};
416 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
417 const CSSToScreenScale
& aZoom
) override
{};
418 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
419 bool aNeedsYFlip
) override
{};
423 // These are methods for CompositorWidgetWrapper, and should only be
424 // accessed from that class. Derived widgets can choose which methods to
425 // implement, or none if supporting out-of-process compositing.
426 virtual bool PreRender(mozilla::widget::WidgetRenderingContext
* aContext
) {
429 virtual void PostRender(mozilla::widget::WidgetRenderingContext
* aContext
) {}
430 virtual RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() {
433 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawing();
434 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawingInRegion(
435 const LayoutDeviceIntRegion
& aInvalidRegion
, BufferMode
* aBufferMode
) {
436 return StartRemoteDrawing();
438 virtual void EndRemoteDrawing() {}
439 virtual void EndRemoteDrawingInRegion(
440 DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
443 virtual void CleanupRemoteDrawing() {}
444 virtual void CleanupWindowEffects() {}
445 virtual bool InitCompositor(mozilla::layers::Compositor
* aCompositor
) {
448 virtual uint32_t GetGLFrameBufferFormat();
449 virtual bool CompositorInitiallyPaused() { return false; }
452 void ResolveIconName(const nsAString
& aIconName
, const nsAString
& aIconSuffix
,
454 virtual void OnDestroy();
455 void BaseCreate(nsIWidget
* aParent
, nsWidgetInitData
* aInitData
);
457 virtual void ConfigureAPZCTreeManager();
458 virtual void ConfigureAPZControllerThread();
459 virtual already_AddRefed
<GeckoContentController
>
460 CreateRootContentController();
462 // Dispatch an event that has already been routed through APZ.
463 nsEventStatus
ProcessUntransformedAPZEvent(
464 mozilla::WidgetInputEvent
* aEvent
,
465 const mozilla::layers::APZEventResult
& aApzResult
);
467 const LayoutDeviceIntRegion
RegionFromArray(
468 const nsTArray
<LayoutDeviceIntRect
>& aRects
);
469 void ArrayFromRegion(const LayoutDeviceIntRegion
& aRegion
,
470 nsTArray
<LayoutDeviceIntRect
>& aRects
);
472 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
473 int32_t aNativeKeyCode
,
474 uint32_t aModifierFlags
,
475 const nsAString
& aCharacters
,
476 const nsAString
& aUnmodifiedCharacters
,
477 nsIObserver
* aObserver
) override
{
478 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "keyevent");
479 return NS_ERROR_UNEXPECTED
;
482 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
483 NativeMouseMessage aNativeMessage
,
484 mozilla::MouseButton aButton
,
485 nsIWidget::Modifiers aModifierFlags
,
486 nsIObserver
* aObserver
) override
{
487 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
488 return NS_ERROR_UNEXPECTED
;
491 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
492 nsIObserver
* aObserver
) override
{
493 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
494 return NS_ERROR_UNEXPECTED
;
497 nsresult
SynthesizeNativeMouseScrollEvent(
498 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
499 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
500 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
{
501 mozilla::widget::AutoObserverNotifier
notifier(aObserver
,
503 return NS_ERROR_UNEXPECTED
;
506 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
507 TouchPointerState aPointerState
,
508 LayoutDeviceIntPoint aPoint
,
509 double aPointerPressure
,
510 uint32_t aPointerOrientation
,
511 nsIObserver
* aObserver
) override
{
512 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "touchpoint");
513 return NS_ERROR_UNEXPECTED
;
516 nsresult
SynthesizeNativeTouchPadPinch(TouchpadPinchPhase aEventPhase
,
518 LayoutDeviceIntPoint aPoint
,
519 int32_t aModifierFlags
) override
{
521 false, "This method is not implemented on the current platform");
522 return NS_ERROR_UNEXPECTED
;
525 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
526 TouchPointerState aPointerState
,
527 LayoutDeviceIntPoint aPoint
,
528 double aPressure
, uint32_t aRotation
,
529 int32_t aTiltX
, int32_t aTiltY
,
530 nsIObserver
* aObserver
) override
{
532 false, "This method is not implemented on the current platform");
533 return NS_ERROR_UNEXPECTED
;
536 nsresult
SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint
,
537 uint32_t aModifierFlags
) override
{
539 false, "This method is not implemented on the current platform");
540 return NS_ERROR_UNEXPECTED
;
544 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
545 * has non-native input transaction. Otherwise, returns nullptr.
547 void* GetPseudoIMEContext();
550 // Utility to check if an array of clip rects is equal to our
551 // internally stored clip rect array mClipRects.
552 bool IsWindowClipRegionEqual(const nsTArray
<LayoutDeviceIntRect
>& aRects
);
554 // Stores the clip rectangles in aRects into mClipRects.
555 void StoreWindowClipRegion(const nsTArray
<LayoutDeviceIntRect
>& aRects
);
557 virtual already_AddRefed
<nsIWidget
> AllocateChildPopupWidget() {
558 return nsIWidget::CreateChildWindow();
561 LayerManager
* CreateBasicLayerManager();
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
) {
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 void UpdateScrollCapture() override
;
646 * To be overridden by derived classes to return a snapshot that can be used
647 * during scrolling. Returning null means we won't update the container.
648 * @return an already AddRefed SourceSurface containing the snapshot
650 virtual already_AddRefed
<SourceSurface
> CreateScrollSnapshot() {
655 * Used by derived classes to create a fallback scroll image.
656 * @param aSnapshotDrawTarget DrawTarget to fill with fallback image.
658 void DefaultFillScrollCapture(DrawTarget
* aSnapshotDrawTarget
);
660 RefPtr
<ImageContainer
> mScrollCaptureContainer
;
664 // Returns whether compositing should use an external surface size.
665 virtual bool UseExternalCompositingSurface() const { return false; }
668 * Starts the OMTC compositor destruction sequence.
670 * When this function returns, the compositor should not be
671 * able to access the opengl context anymore.
672 * It is safe to call it several times if platform implementations
673 * require the compositor to be destroyed before ~nsBaseWidget is
674 * reached (This is the case with gtk2 for instance).
676 virtual void DestroyCompositor();
677 void DestroyLayerManager();
678 void ReleaseContentController();
679 void RevokeTransactionIdAllocator();
681 void FreeShutdownObserver();
683 nsIWidgetListener
* mWidgetListener
;
684 nsIWidgetListener
* mAttachedWidgetListener
;
685 nsIWidgetListener
* mPreviouslyAttachedWidgetListener
;
686 RefPtr
<LayerManager
> mLayerManager
;
687 RefPtr
<CompositorSession
> mCompositorSession
;
688 RefPtr
<CompositorBridgeChild
> mCompositorBridgeChild
;
690 mozilla::UniquePtr
<mozilla::Mutex
> mCompositorVsyncDispatcherLock
;
691 RefPtr
<mozilla::CompositorVsyncDispatcher
> mCompositorVsyncDispatcher
;
693 RefPtr
<IAPZCTreeManager
> mAPZC
;
694 RefPtr
<GeckoContentController
> mRootContentController
;
695 RefPtr
<APZEventState
> mAPZEventState
;
696 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback
;
697 RefPtr
<WidgetShutdownObserver
> mShutdownObserver
;
698 RefPtr
<TextEventDispatcher
> mTextEventDispatcher
;
700 nsBorderStyle mBorderStyle
;
701 LayoutDeviceIntRect mBounds
;
702 LayoutDeviceIntRect
* mOriginalBounds
;
703 // When this pointer is null, the widget is not clipped
704 mozilla::UniquePtr
<LayoutDeviceIntRect
[]> mClipRects
;
705 uint32_t mClipRectCount
;
706 nsSizeMode mSizeMode
;
708 nsPopupLevel mPopupLevel
;
709 nsPopupType mPopupType
;
710 SizeConstraints mSizeConstraints
;
711 bool mHasRemoteContent
;
715 bool mUseAttachedEvents
;
718 bool mIsFullyOccluded
;
719 static nsIRollupListener
* gRollupListener
;
721 struct InitialZoomConstraints
{
722 InitialZoomConstraints(const uint32_t& aPresShellID
,
723 const ScrollableLayerGuid::ViewID
& aViewID
,
724 const ZoomConstraints
& aConstraints
)
725 : mPresShellID(aPresShellID
),
727 mConstraints(aConstraints
) {}
729 uint32_t mPresShellID
;
730 ScrollableLayerGuid::ViewID mViewID
;
731 ZoomConstraints mConstraints
;
734 mozilla::Maybe
<InitialZoomConstraints
> mInitialZoomConstraints
;
736 // This points to the resize listeners who have been notified that a live
737 // resize is in progress. This should always be empty when a live-resize is
739 nsTArray
<RefPtr
<mozilla::LiveResizeListener
>> mLiveResizeListeners
;
743 static nsAutoString
debug_GuiEventToString(
744 mozilla::WidgetGUIEvent
* aGuiEvent
);
745 static bool debug_WantPaintFlashing();
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
<LayerManager
> CreateCompositorSession(
764 int aWidth
, int aHeight
, mozilla::layers::CompositorOptions
* aOptionsOut
);
767 #endif // nsBaseWidget_h__