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(nsBorderStyle aBorderStyle
);
164 NS_DECL_THREADSAFE_ISUPPORTS
166 // nsIWidget interface
167 void CaptureMouse(bool aCapture
) override
{}
168 void CaptureRollupEvents(nsIRollupListener
* aListener
,
169 bool aDoCapture
) override
{}
170 nsIWidgetListener
* GetWidgetListener() const override
;
171 void SetWidgetListener(nsIWidgetListener
* alistener
) override
;
172 void Destroy() override
;
173 void SetParent(nsIWidget
* aNewParent
) override
{};
174 nsIWidget
* GetParent() override
;
175 nsIWidget
* GetTopLevelWidget() override
;
176 nsIWidget
* GetSheetWindowParent(void) override
;
177 float GetDPI() override
;
178 void AddChild(nsIWidget
* aChild
) override
;
179 void RemoveChild(nsIWidget
* aChild
) override
;
181 void SetZIndex(int32_t aZIndex
) override
;
182 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
, nsIWidget
* aWidget
,
183 bool aActivate
) override
{}
185 void GetWorkspaceID(nsAString
& workspaceID
) override
;
186 void MoveToWorkspace(const nsAString
& workspaceID
) override
;
187 bool IsTiled() const override
{ return mIsTiled
; }
189 bool IsFullyOccluded() const override
{ return mIsFullyOccluded
; }
191 void SetCursor(const Cursor
&) override
;
192 void ClearCachedCursor() final
{
194 mUpdateCursor
= true;
196 void SetTransparencyMode(nsTransparencyMode aMode
) override
;
197 nsTransparencyMode
GetTransparencyMode() override
;
198 void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle
) override
{}
199 void SetShowsToolbarButton(bool aShow
) override
{}
200 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen
) override
{}
201 void SetWindowAnimationType(WindowAnimationType aType
) override
{}
202 void HideWindowChrome(bool aShouldHide
) override
{}
203 bool PrepareForFullscreenTransition(nsISupports
** aData
) override
{
206 void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
207 uint16_t aDuration
, nsISupports
* aData
,
208 nsIRunnable
* aCallback
) override
;
209 void CleanupFullscreenTransition() override
{}
210 already_AddRefed
<nsIScreen
> GetWidgetScreen() override
;
211 nsresult
MakeFullScreen(bool aFullScreen
) override
;
212 void InfallibleMakeFullScreen(bool aFullScreen
);
214 WindowRenderer
* GetWindowRenderer() override
;
215 bool HasWindowRenderer() const final
{ return !!mWindowRenderer
; }
217 // A remote compositor session tied to this window has been lost and IPC
218 // messages will no longer work. The widget must clean up any lingering
219 // resources and possibly schedule another paint.
221 // A reference to the session object is held until this function has
223 virtual void NotifyCompositorSessionLost(
224 mozilla::layers::CompositorSession
* aSession
);
226 already_AddRefed
<mozilla::CompositorVsyncDispatcher
>
227 GetCompositorVsyncDispatcher();
228 virtual void CreateCompositorVsyncDispatcher();
229 virtual void CreateCompositor();
230 virtual void CreateCompositor(int aWidth
, int aHeight
);
231 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate
*) {}
232 void PrepareWindowEffects() override
{}
233 void UpdateThemeGeometries(
234 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) override
{}
235 void SetModal(bool aModal
) override
{}
236 uint32_t GetMaxTouchPoints() const override
;
237 void SetWindowClass(const nsAString
& xulWinType
) override
{}
238 // Return whether this widget interprets parameters to Move and Resize APIs
239 // as "desktop pixels" rather than "device pixels", and therefore
240 // applies its GetDefaultScale() value to them before using them as mBounds
241 // etc (which are always stored in device pixels).
242 // Note that APIs that -get- the widget's position/size/bounds, rather than
243 // -setting- them (i.e. moving or resizing the widget) will always return
244 // values in the widget's device pixels.
245 bool BoundsUseDesktopPixels() const {
246 return mWindowType
<= eWindowType_popup
;
248 // Default implementation, to be overridden by platforms where desktop coords
249 // are virtualized and may not correspond to device pixels on the screen.
250 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
251 return mozilla::DesktopToLayoutDeviceScale(1.0);
253 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScaleByScreen()
256 void ConstrainPosition(bool aAllowSlop
, int32_t* aX
, int32_t* aY
) override
{}
257 void MoveClient(const DesktopPoint
& aOffset
) override
;
258 void ResizeClient(const DesktopSize
& aSize
, bool aRepaint
) override
;
259 void ResizeClient(const DesktopRect
& aRect
, bool aRepaint
) override
;
260 LayoutDeviceIntRect
GetBounds() override
;
261 LayoutDeviceIntRect
GetClientBounds() override
;
262 LayoutDeviceIntRect
GetScreenBounds() override
;
263 [[nodiscard
]] nsresult
GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
264 nsresult
SetNonClientMargins(LayoutDeviceIntMargin
& aMargins
) override
;
265 LayoutDeviceIntPoint
GetClientOffset() override
;
266 void EnableDragDrop(bool aEnable
) override
{};
267 nsresult
AsyncEnableDragDrop(bool aEnable
) override
;
268 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin
) override
;
269 [[nodiscard
]] nsresult
GetAttention(int32_t aCycleCount
) override
{
272 bool HasPendingInputEvent() override
;
273 void SetIcon(const nsAString
& aIconSpec
) override
{}
274 void SetDrawsInTitlebar(bool aState
) override
{}
275 bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) override
;
276 void FreeNativeData(void* data
, uint32_t aDataType
) override
{}
277 [[nodiscard
]] nsresult
BeginResizeDrag(mozilla::WidgetGUIEvent
* aEvent
,
279 int32_t aVertical
) override
{
280 return NS_ERROR_NOT_IMPLEMENTED
;
282 nsresult
ActivateNativeMenuItemAt(const nsAString
& indexString
) override
{
283 return NS_ERROR_NOT_IMPLEMENTED
;
285 nsresult
ForceUpdateNativeMenuAt(const nsAString
& indexString
) override
{
286 return NS_ERROR_NOT_IMPLEMENTED
;
288 nsresult
NotifyIME(const IMENotification
& aIMENotification
) final
;
289 [[nodiscard
]] nsresult
AttachNativeKeyEvent(
290 mozilla::WidgetKeyboardEvent
& aEvent
) override
{
291 return NS_ERROR_NOT_IMPLEMENTED
;
293 bool ComputeShouldAccelerate();
294 virtual bool WidgetTypeSupportsAcceleration() { return true; }
295 [[nodiscard
]] nsresult
OnDefaultButtonLoaded(
296 const LayoutDeviceIntRect
& aButtonRect
) override
{
297 return NS_ERROR_NOT_IMPLEMENTED
;
299 already_AddRefed
<nsIWidget
> CreateChild(
300 const LayoutDeviceIntRect
& aRect
, nsWidgetInitData
* aInitData
= nullptr,
301 bool aForceUseIWidgetParent
= false) override
;
302 void AttachViewToTopLevel(bool aUseAttachedEvents
) override
;
303 nsIWidgetListener
* GetAttachedWidgetListener() const override
;
304 void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) override
;
305 nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() override
;
306 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener
*) override
;
307 NativeIMEContext
GetNativeIMEContext() override
;
308 TextEventDispatcher
* GetTextEventDispatcher() final
;
309 TextEventDispatcherListener
* GetNativeTextEventDispatcherListener() override
;
310 void ZoomToRect(const uint32_t& aPresShellId
,
311 const ScrollableLayerGuid::ViewID
& aViewId
,
312 const CSSRect
& aRect
, const uint32_t& aFlags
) override
;
314 // Dispatch an event that must be first be routed through APZ.
315 ContentAndAPZEventStatus
DispatchInputEvent(
316 mozilla::WidgetInputEvent
* aEvent
) override
;
317 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) override
;
319 bool DispatchWindowEvent(mozilla::WidgetGUIEvent
& event
) override
;
321 void SetConfirmedTargetAPZC(
322 uint64_t aInputBlockId
,
323 const nsTArray
<ScrollableLayerGuid
>& aTargets
) const override
;
325 void UpdateZoomConstraints(
326 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
327 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) override
;
329 bool AsyncPanZoomEnabled() const override
;
331 void SwipeFinished() override
;
332 void ReportSwipeStarted(uint64_t aInputBlockId
, bool aStartSwipe
) override
;
333 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput
& aSwipeStartEvent
,
334 uint32_t aAllowedDirections
);
337 uint32_t allowedDirections
;
339 SwipeInfo
SendMayStartSwipe(const mozilla::PanGestureInput
& aSwipeStartEvent
);
340 enum class CanTriggerSwipe
: bool {
344 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
345 // whether |aPanInput| event was used for SwipeTracker or not.
346 mozilla::WidgetWheelEvent
MayStartSwipeForAPZ(
347 const mozilla::PanGestureInput
& aPanInput
,
348 const mozilla::layers::APZEventResult
& aApzResult
,
349 CanTriggerSwipe aCanTriggerSwipe
);
351 // Returns true if |aPanInput| event was used for SwipeTracker, false
353 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput
& aPanInput
,
354 CanTriggerSwipe aCanTriggerSwipe
);
356 void NotifyWindowDestroyed();
357 void NotifySizeMoveDone();
358 void NotifyWindowMoved(int32_t aX
, int32_t aY
);
360 void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
{}
362 // Should be called by derived implementations to notify on system color and
364 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind
);
365 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings
);
368 // Get the accessible for the window.
369 mozilla::a11y::LocalAccessible
* GetRootAccessible();
372 // Return true if this is a simple widget (that is typically not worth
374 bool IsSmallPopup() const;
376 nsPopupLevel
PopupLevel() { return mPopupLevel
; }
378 LayoutDeviceIntSize
ClientToWindowSize(
379 const LayoutDeviceIntSize
& aClientSize
) override
{
383 // return true if this is a popup widget with a native titlebar
384 bool IsPopupWithTitleBar() const {
385 return (mWindowType
== eWindowType_popup
&&
386 mBorderStyle
!= eBorderStyle_default
&&
387 mBorderStyle
& eBorderStyle_title
);
390 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
{}
392 const SizeConstraints
GetSizeConstraints() override
;
393 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
395 void StartAsyncScrollbarDrag(const AsyncDragMetrics
& aDragMetrics
) override
;
397 bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
398 const ScrollableLayerGuid
& aGuid
) override
;
400 void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) override
;
402 mozilla::layers::LayersId
GetRootLayerTreeId() override
;
405 * Use this when GetLayerManager() returns a BasicLayerManager
406 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
407 * layer manager to temporarily render into aTarget.
409 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
410 * |aRotation| is the "virtual rotation" to apply when rendering to
411 * the target. When |aRotation| is ROTATION_0,
412 * |aNaturalWidgetBounds| is not used.
414 class AutoLayerManagerSetup
{
416 AutoLayerManagerSetup(nsBaseWidget
* aWidget
, gfxContext
* aTarget
,
417 BufferMode aDoubleBuffering
);
418 ~AutoLayerManagerSetup();
421 nsBaseWidget
* mWidget
;
422 mozilla::FallbackRenderer
* mRenderer
= nullptr;
424 friend class AutoLayerManagerSetup
;
426 virtual bool ShouldUseOffMainThreadCompositing();
428 static nsIRollupListener
* GetActiveRollupListener();
434 // These functions should be called at the start and end of a "live" widget
435 // resize (i.e. when the window contents are repainting during the resize,
436 // such as when the user drags a window border). It will suppress the
437 // displayport during the live resize to avoid unneccessary overpainting.
438 void NotifyLiveResizeStarted();
439 void NotifyLiveResizeStopped();
441 #if defined(MOZ_WIDGET_ANDROID)
442 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override
{};
443 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
444 const CSSToScreenScale
& aZoom
) override
{};
445 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
446 bool aNeedsYFlip
) override
{};
449 virtual void LocalesChanged() {}
451 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState
) {}
454 // These are methods for CompositorWidgetWrapper, and should only be
455 // accessed from that class. Derived widgets can choose which methods to
456 // implement, or none if supporting out-of-process compositing.
457 virtual bool PreRender(mozilla::widget::WidgetRenderingContext
* aContext
) {
460 virtual void PostRender(mozilla::widget::WidgetRenderingContext
* aContext
) {}
461 virtual RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() {
464 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawing();
465 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawingInRegion(
466 const LayoutDeviceIntRegion
& aInvalidRegion
, BufferMode
* aBufferMode
) {
467 return StartRemoteDrawing();
469 virtual void EndRemoteDrawing() {}
470 virtual void EndRemoteDrawingInRegion(
471 DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
474 virtual void CleanupRemoteDrawing() {}
475 virtual void CleanupWindowEffects() {}
476 virtual bool InitCompositor(mozilla::layers::Compositor
* aCompositor
) {
479 virtual uint32_t GetGLFrameBufferFormat();
480 virtual bool CompositorInitiallyPaused() { return false; }
483 void ResolveIconName(const nsAString
& aIconName
, const nsAString
& aIconSuffix
,
485 virtual void OnDestroy();
486 void BaseCreate(nsIWidget
* aParent
, nsWidgetInitData
* aInitData
);
488 virtual void ConfigureAPZCTreeManager();
489 virtual void ConfigureAPZControllerThread();
490 virtual already_AddRefed
<GeckoContentController
>
491 CreateRootContentController();
493 // Dispatch an event that has already been routed through APZ.
494 nsEventStatus
ProcessUntransformedAPZEvent(
495 mozilla::WidgetInputEvent
* aEvent
,
496 const mozilla::layers::APZEventResult
& aApzResult
);
498 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
499 int32_t aNativeKeyCode
,
500 uint32_t aModifierFlags
,
501 const nsAString
& aCharacters
,
502 const nsAString
& aUnmodifiedCharacters
,
503 nsIObserver
* aObserver
) override
{
504 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "keyevent");
505 return NS_ERROR_UNEXPECTED
;
508 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
509 NativeMouseMessage aNativeMessage
,
510 mozilla::MouseButton aButton
,
511 nsIWidget::Modifiers aModifierFlags
,
512 nsIObserver
* aObserver
) override
{
513 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
514 return NS_ERROR_UNEXPECTED
;
517 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
518 nsIObserver
* aObserver
) override
{
519 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
520 return NS_ERROR_UNEXPECTED
;
523 nsresult
SynthesizeNativeMouseScrollEvent(
524 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
525 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
526 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
{
527 mozilla::widget::AutoObserverNotifier
notifier(aObserver
,
529 return NS_ERROR_UNEXPECTED
;
532 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
533 TouchPointerState aPointerState
,
534 LayoutDeviceIntPoint aPoint
,
535 double aPointerPressure
,
536 uint32_t aPointerOrientation
,
537 nsIObserver
* aObserver
) override
{
538 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "touchpoint");
539 return NS_ERROR_UNEXPECTED
;
542 nsresult
SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase
,
544 LayoutDeviceIntPoint aPoint
,
545 int32_t aModifierFlags
) override
{
547 false, "This method is not implemented on the current platform");
548 return NS_ERROR_UNEXPECTED
;
551 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
552 TouchPointerState aPointerState
,
553 LayoutDeviceIntPoint aPoint
,
554 double aPressure
, uint32_t aRotation
,
555 int32_t aTiltX
, int32_t aTiltY
,
557 nsIObserver
* aObserver
) override
{
559 false, "This method is not implemented on the current platform");
560 return NS_ERROR_UNEXPECTED
;
563 nsresult
SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint
,
564 uint32_t aModifierFlags
) override
{
566 false, "This method is not implemented on the current platform");
567 return NS_ERROR_UNEXPECTED
;
570 nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
571 LayoutDeviceIntPoint aPoint
,
572 double aDeltaX
, double aDeltaY
,
573 int32_t aModifierFlags
,
574 nsIObserver
* aObserver
) override
{
576 false, "This method is not implemented on the current platform");
577 return NS_ERROR_UNEXPECTED
;
581 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
582 * has non-native input transaction. Otherwise, returns nullptr.
584 void* GetPseudoIMEContext();
587 virtual already_AddRefed
<nsIWidget
> AllocateChildPopupWidget() {
588 return nsIWidget::CreateChildWindow();
591 WindowRenderer
* CreateFallbackRenderer();
593 nsPopupType
PopupType() const { return mPopupType
; }
595 bool HasRemoteContent() const { return mHasRemoteContent
; }
598 * Apply the current size constraints to the given size.
600 * @param aWidth width to constrain
601 * @param aHeight height to constrain
603 void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) override
{
604 SizeConstraints c
= GetSizeConstraints();
605 *aWidth
= std::max(c
.mMinSize
.width
, std::min(c
.mMaxSize
.width
, *aWidth
));
607 std::max(c
.mMinSize
.height
, std::min(c
.mMaxSize
.height
, *aHeight
));
610 CompositorBridgeChild
* GetRemoteRenderer() override
;
612 void ClearCachedWebrenderResources() override
;
614 bool SetNeedFastSnaphot() override
;
617 * Notify the widget that this window is being used with OMTC.
619 virtual void WindowUsesOMTC() {}
620 virtual void RegisterTouchWindow() {}
622 mozilla::dom::Document
* GetDocument() const;
624 void EnsureTextEventDispatcher();
626 // Notify the compositor that a device reset has occurred.
627 void OnRenderingDeviceReset();
631 bool AllowWebRenderForThisWindow();
634 * For widgets that support synthesizing native touch events, this function
635 * can be used to manage the current state of synthetic pointers. Each widget
636 * must maintain its own MultiTouchInput instance and pass it in as the state,
637 * along with the desired parameters for the changes. This function returns
638 * a new MultiTouchInput object that is ready to be dispatched.
640 mozilla::MultiTouchInput
UpdateSynthesizedTouchState(
641 mozilla::MultiTouchInput
* aState
, uint32_t aTime
,
642 mozilla::TimeStamp aTimeStamp
, uint32_t aPointerId
,
643 TouchPointerState aPointerState
, LayoutDeviceIntPoint aPoint
,
644 double aPointerPressure
, uint32_t aPointerOrientation
);
647 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
648 * or directly to gecko (if APZ is not enabled). This function must only
649 * be called from the main thread, and if APZ is enabled, that must also be
650 * the APZ controller thread.
652 void DispatchTouchInput(
653 mozilla::MultiTouchInput
& aInput
,
654 uint16_t aInputSource
=
655 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH
);
658 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
659 * or directly to gecko (if APZ is not enabled). This function must only
660 * be called from the main thread, and if APZ is enabled, that must also be
661 * the APZ controller thread.
663 void DispatchPanGestureInput(mozilla::PanGestureInput
& aInput
);
664 void DispatchPinchGestureInput(mozilla::PinchGestureInput
& aInput
);
666 static bool ConvertStatus(nsEventStatus aStatus
) {
667 return aStatus
== nsEventStatus_eConsumeNoDefault
;
671 // Returns whether compositing should use an external surface size.
672 virtual bool UseExternalCompositingSurface() const { return false; }
675 * Starts the OMTC compositor destruction sequence.
677 * When this function returns, the compositor should not be
678 * able to access the opengl context anymore.
679 * It is safe to call it several times if platform implementations
680 * require the compositor to be destroyed before ~nsBaseWidget is
681 * reached (This is the case with gtk2 for instance).
683 virtual void DestroyCompositor();
684 void DestroyLayerManager();
685 void ReleaseContentController();
686 void RevokeTransactionIdAllocator();
688 void FreeShutdownObserver();
689 void FreeLocalesChangedObserver();
691 nsIWidgetListener
* mWidgetListener
;
692 nsIWidgetListener
* mAttachedWidgetListener
;
693 nsIWidgetListener
* mPreviouslyAttachedWidgetListener
;
694 RefPtr
<WindowRenderer
> mWindowRenderer
;
695 RefPtr
<CompositorSession
> mCompositorSession
;
696 RefPtr
<CompositorBridgeChild
> mCompositorBridgeChild
;
698 mozilla::UniquePtr
<mozilla::Mutex
> mCompositorVsyncDispatcherLock
;
699 RefPtr
<mozilla::CompositorVsyncDispatcher
> mCompositorVsyncDispatcher
;
701 RefPtr
<IAPZCTreeManager
> mAPZC
;
702 RefPtr
<GeckoContentController
> mRootContentController
;
703 RefPtr
<APZEventState
> mAPZEventState
;
704 RefPtr
<WidgetShutdownObserver
> mShutdownObserver
;
705 RefPtr
<LocalesChangedObserver
> mLocalesChangedObserver
;
706 RefPtr
<TextEventDispatcher
> mTextEventDispatcher
;
707 RefPtr
<mozilla::SwipeTracker
> mSwipeTracker
;
708 mozilla::UniquePtr
<mozilla::SwipeEventQueue
> mSwipeEventQueue
;
710 nsBorderStyle mBorderStyle
;
711 LayoutDeviceIntRect mBounds
;
712 LayoutDeviceIntRect
* mOriginalBounds
;
714 nsPopupLevel mPopupLevel
;
715 nsPopupType mPopupType
;
716 SizeConstraints mSizeConstraints
;
717 bool mHasRemoteContent
;
720 bool mUseAttachedEvents
;
723 bool mIsFullyOccluded
;
724 bool mNeedFastSnaphot
;
725 // This flag is only used when APZ is off. It indicates that the current pan
726 // gesture was processed as a swipe. Sometimes the swipe animation can finish
727 // before momentum events of the pan gesture have stopped firing, so this
728 // flag tells us that we shouldn't allow the remaining events to cause
729 // scrolling. It is reset to false once a new gesture starts (as indicated by
730 // a PANGESTURE_(MAY)START event).
731 bool mCurrentPanGestureBelongsToSwipe
;
733 static nsIRollupListener
* gRollupListener
;
735 struct InitialZoomConstraints
{
736 InitialZoomConstraints(const uint32_t& aPresShellID
,
737 const ScrollableLayerGuid::ViewID
& aViewID
,
738 const ZoomConstraints
& aConstraints
)
739 : mPresShellID(aPresShellID
),
741 mConstraints(aConstraints
) {}
743 uint32_t mPresShellID
;
744 ScrollableLayerGuid::ViewID mViewID
;
745 ZoomConstraints mConstraints
;
748 mozilla::Maybe
<InitialZoomConstraints
> mInitialZoomConstraints
;
750 // This points to the resize listeners who have been notified that a live
751 // resize is in progress. This should always be empty when a live-resize is
753 nsTArray
<RefPtr
<mozilla::LiveResizeListener
>> mLiveResizeListeners
;
757 static nsAutoString
debug_GuiEventToString(
758 mozilla::WidgetGUIEvent
* aGuiEvent
);
760 static void debug_DumpInvalidate(FILE* aFileOut
, nsIWidget
* aWidget
,
761 const LayoutDeviceIntRect
* aRect
,
762 const char* aWidgetName
, int32_t aWindowID
);
764 static void debug_DumpEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
765 mozilla::WidgetGUIEvent
* aGuiEvent
,
766 const char* aWidgetName
, int32_t aWindowID
);
768 static void debug_DumpPaintEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
769 const nsIntRegion
& aPaintEvent
,
770 const char* aWidgetName
, int32_t aWindowID
);
772 static bool debug_GetCachedBoolPref(const char* aPrefName
);
776 already_AddRefed
<mozilla::layers::WebRenderLayerManager
>
777 CreateCompositorSession(int aWidth
, int aHeight
,
778 mozilla::layers::CompositorOptions
* aOptionsOut
);
781 #endif // nsBaseWidget_h__