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();
359 using ByMoveToRect
= nsIWidgetListener::ByMoveToRect
;
360 void NotifyWindowMoved(int32_t aX
, int32_t aY
,
361 ByMoveToRect
= ByMoveToRect::No
);
363 void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
{}
365 // Should be called by derived implementations to notify on system color and
367 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind
);
368 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings
);
371 // Get the accessible for the window.
372 mozilla::a11y::LocalAccessible
* GetRootAccessible();
375 // Return true if this is a simple widget (that is typically not worth
377 bool IsSmallPopup() const;
379 nsPopupLevel
PopupLevel() { return mPopupLevel
; }
381 LayoutDeviceIntSize
ClientToWindowSize(
382 const LayoutDeviceIntSize
& aClientSize
) override
{
386 // return true if this is a popup widget with a native titlebar
387 bool IsPopupWithTitleBar() const {
388 return (mWindowType
== eWindowType_popup
&&
389 mBorderStyle
!= eBorderStyle_default
&&
390 mBorderStyle
& eBorderStyle_title
);
393 void ReparentNativeWidget(nsIWidget
* aNewParent
) override
{}
395 const SizeConstraints
GetSizeConstraints() override
;
396 void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
398 void StartAsyncScrollbarDrag(const AsyncDragMetrics
& aDragMetrics
) override
;
400 bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
401 const ScrollableLayerGuid
& aGuid
) override
;
403 void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) override
;
405 mozilla::layers::LayersId
GetRootLayerTreeId() override
;
408 * Use this when GetLayerManager() returns a BasicLayerManager
409 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
410 * layer manager to temporarily render into aTarget.
412 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
413 * |aRotation| is the "virtual rotation" to apply when rendering to
414 * the target. When |aRotation| is ROTATION_0,
415 * |aNaturalWidgetBounds| is not used.
417 class AutoLayerManagerSetup
{
419 AutoLayerManagerSetup(nsBaseWidget
* aWidget
, gfxContext
* aTarget
,
420 BufferMode aDoubleBuffering
);
421 ~AutoLayerManagerSetup();
424 nsBaseWidget
* mWidget
;
425 mozilla::FallbackRenderer
* mRenderer
= nullptr;
427 friend class AutoLayerManagerSetup
;
429 virtual bool ShouldUseOffMainThreadCompositing();
431 static nsIRollupListener
* GetActiveRollupListener();
437 // These functions should be called at the start and end of a "live" widget
438 // resize (i.e. when the window contents are repainting during the resize,
439 // such as when the user drags a window border). It will suppress the
440 // displayport during the live resize to avoid unneccessary overpainting.
441 void NotifyLiveResizeStarted();
442 void NotifyLiveResizeStopped();
444 #if defined(MOZ_WIDGET_ANDROID)
445 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override
{};
446 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
447 const CSSToScreenScale
& aZoom
) override
{};
448 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
, const ScreenIntSize
& aSize
,
449 bool aNeedsYFlip
) override
{};
452 virtual void LocalesChanged() {}
454 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState
) {}
457 // These are methods for CompositorWidgetWrapper, and should only be
458 // accessed from that class. Derived widgets can choose which methods to
459 // implement, or none if supporting out-of-process compositing.
460 virtual bool PreRender(mozilla::widget::WidgetRenderingContext
* aContext
) {
463 virtual void PostRender(mozilla::widget::WidgetRenderingContext
* aContext
) {}
464 virtual RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() {
467 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawing();
468 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawingInRegion(
469 const LayoutDeviceIntRegion
& aInvalidRegion
, BufferMode
* aBufferMode
) {
470 return StartRemoteDrawing();
472 virtual void EndRemoteDrawing() {}
473 virtual void EndRemoteDrawingInRegion(
474 DrawTarget
* aDrawTarget
, const LayoutDeviceIntRegion
& aInvalidRegion
) {
477 virtual void CleanupRemoteDrawing() {}
478 virtual void CleanupWindowEffects() {}
479 virtual bool InitCompositor(mozilla::layers::Compositor
* aCompositor
) {
482 virtual uint32_t GetGLFrameBufferFormat();
483 virtual bool CompositorInitiallyPaused() { return false; }
486 void ResolveIconName(const nsAString
& aIconName
, const nsAString
& aIconSuffix
,
488 virtual void OnDestroy();
489 void BaseCreate(nsIWidget
* aParent
, nsWidgetInitData
* aInitData
);
491 virtual void ConfigureAPZCTreeManager();
492 virtual void ConfigureAPZControllerThread();
493 virtual already_AddRefed
<GeckoContentController
>
494 CreateRootContentController();
496 // Dispatch an event that has already been routed through APZ.
497 nsEventStatus
ProcessUntransformedAPZEvent(
498 mozilla::WidgetInputEvent
* aEvent
,
499 const mozilla::layers::APZEventResult
& aApzResult
);
501 nsresult
SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout
,
502 int32_t aNativeKeyCode
,
503 uint32_t aModifierFlags
,
504 const nsAString
& aCharacters
,
505 const nsAString
& aUnmodifiedCharacters
,
506 nsIObserver
* aObserver
) override
{
507 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "keyevent");
508 return NS_ERROR_UNEXPECTED
;
511 nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
512 NativeMouseMessage aNativeMessage
,
513 mozilla::MouseButton aButton
,
514 nsIWidget::Modifiers aModifierFlags
,
515 nsIObserver
* aObserver
) override
{
516 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
517 return NS_ERROR_UNEXPECTED
;
520 nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
521 nsIObserver
* aObserver
) override
{
522 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
523 return NS_ERROR_UNEXPECTED
;
526 nsresult
SynthesizeNativeMouseScrollEvent(
527 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
528 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
529 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
{
530 mozilla::widget::AutoObserverNotifier
notifier(aObserver
,
532 return NS_ERROR_UNEXPECTED
;
535 nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
536 TouchPointerState aPointerState
,
537 LayoutDeviceIntPoint aPoint
,
538 double aPointerPressure
,
539 uint32_t aPointerOrientation
,
540 nsIObserver
* aObserver
) override
{
541 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "touchpoint");
542 return NS_ERROR_UNEXPECTED
;
545 nsresult
SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase
,
547 LayoutDeviceIntPoint aPoint
,
548 int32_t aModifierFlags
) override
{
550 false, "This method is not implemented on the current platform");
551 return NS_ERROR_UNEXPECTED
;
554 nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
555 TouchPointerState aPointerState
,
556 LayoutDeviceIntPoint aPoint
,
557 double aPressure
, uint32_t aRotation
,
558 int32_t aTiltX
, int32_t aTiltY
,
560 nsIObserver
* aObserver
) override
{
562 false, "This method is not implemented on the current platform");
563 return NS_ERROR_UNEXPECTED
;
566 nsresult
SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint
,
567 uint32_t aModifierFlags
) override
{
569 false, "This method is not implemented on the current platform");
570 return NS_ERROR_UNEXPECTED
;
573 nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
574 LayoutDeviceIntPoint aPoint
,
575 double aDeltaX
, double aDeltaY
,
576 int32_t aModifierFlags
,
577 nsIObserver
* aObserver
) override
{
579 false, "This method is not implemented on the current platform");
580 return NS_ERROR_UNEXPECTED
;
584 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
585 * has non-native input transaction. Otherwise, returns nullptr.
587 void* GetPseudoIMEContext();
590 virtual already_AddRefed
<nsIWidget
> AllocateChildPopupWidget() {
591 return nsIWidget::CreateChildWindow();
594 WindowRenderer
* CreateFallbackRenderer();
596 nsPopupType
PopupType() const { return mPopupType
; }
598 bool HasRemoteContent() const { return mHasRemoteContent
; }
601 * Apply the current size constraints to the given size.
603 * @param aWidth width to constrain
604 * @param aHeight height to constrain
606 void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) override
{
607 SizeConstraints c
= GetSizeConstraints();
608 *aWidth
= std::max(c
.mMinSize
.width
, std::min(c
.mMaxSize
.width
, *aWidth
));
610 std::max(c
.mMinSize
.height
, std::min(c
.mMaxSize
.height
, *aHeight
));
613 CompositorBridgeChild
* GetRemoteRenderer() override
;
615 void ClearCachedWebrenderResources() override
;
617 void ClearWebrenderAnimationResources() override
;
619 bool SetNeedFastSnaphot() override
;
622 * Notify the widget that this window is being used with OMTC.
624 virtual void WindowUsesOMTC() {}
625 virtual void RegisterTouchWindow() {}
627 mozilla::dom::Document
* GetDocument() const;
629 void EnsureTextEventDispatcher();
631 // Notify the compositor that a device reset has occurred.
632 void OnRenderingDeviceReset();
636 bool AllowWebRenderForThisWindow();
639 * For widgets that support synthesizing native touch events, this function
640 * can be used to manage the current state of synthetic pointers. Each widget
641 * must maintain its own MultiTouchInput instance and pass it in as the state,
642 * along with the desired parameters for the changes. This function returns
643 * a new MultiTouchInput object that is ready to be dispatched.
645 mozilla::MultiTouchInput
UpdateSynthesizedTouchState(
646 mozilla::MultiTouchInput
* aState
, uint32_t aTime
,
647 mozilla::TimeStamp aTimeStamp
, uint32_t aPointerId
,
648 TouchPointerState aPointerState
, LayoutDeviceIntPoint aPoint
,
649 double aPointerPressure
, uint32_t aPointerOrientation
);
652 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
653 * or directly to gecko (if APZ is not enabled). This function must only
654 * be called from the main thread, and if APZ is enabled, that must also be
655 * the APZ controller thread.
657 void DispatchTouchInput(
658 mozilla::MultiTouchInput
& aInput
,
659 uint16_t aInputSource
=
660 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH
);
663 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
664 * or directly to gecko (if APZ is not enabled). This function must only
665 * be called from the main thread, and if APZ is enabled, that must also be
666 * the APZ controller thread.
668 void DispatchPanGestureInput(mozilla::PanGestureInput
& aInput
);
669 void DispatchPinchGestureInput(mozilla::PinchGestureInput
& aInput
);
671 static bool ConvertStatus(nsEventStatus aStatus
) {
672 return aStatus
== nsEventStatus_eConsumeNoDefault
;
676 // Returns whether compositing should use an external surface size.
677 virtual bool UseExternalCompositingSurface() const { return false; }
680 * Starts the OMTC compositor destruction sequence.
682 * When this function returns, the compositor should not be
683 * able to access the opengl context anymore.
684 * It is safe to call it several times if platform implementations
685 * require the compositor to be destroyed before ~nsBaseWidget is
686 * reached (This is the case with gtk2 for instance).
688 virtual void DestroyCompositor();
689 void DestroyLayerManager();
690 void ReleaseContentController();
691 void RevokeTransactionIdAllocator();
693 void FreeShutdownObserver();
694 void FreeLocalesChangedObserver();
696 nsIWidgetListener
* mWidgetListener
;
697 nsIWidgetListener
* mAttachedWidgetListener
;
698 nsIWidgetListener
* mPreviouslyAttachedWidgetListener
;
699 RefPtr
<WindowRenderer
> mWindowRenderer
;
700 RefPtr
<CompositorSession
> mCompositorSession
;
701 RefPtr
<CompositorBridgeChild
> mCompositorBridgeChild
;
703 mozilla::UniquePtr
<mozilla::Mutex
> mCompositorVsyncDispatcherLock
;
704 RefPtr
<mozilla::CompositorVsyncDispatcher
> mCompositorVsyncDispatcher
;
706 RefPtr
<IAPZCTreeManager
> mAPZC
;
707 RefPtr
<GeckoContentController
> mRootContentController
;
708 RefPtr
<APZEventState
> mAPZEventState
;
709 RefPtr
<WidgetShutdownObserver
> mShutdownObserver
;
710 RefPtr
<LocalesChangedObserver
> mLocalesChangedObserver
;
711 RefPtr
<TextEventDispatcher
> mTextEventDispatcher
;
712 RefPtr
<mozilla::SwipeTracker
> mSwipeTracker
;
713 mozilla::UniquePtr
<mozilla::SwipeEventQueue
> mSwipeEventQueue
;
715 nsBorderStyle mBorderStyle
;
716 LayoutDeviceIntRect mBounds
;
718 nsPopupLevel mPopupLevel
;
719 nsPopupType mPopupType
;
720 SizeConstraints mSizeConstraints
;
721 bool mHasRemoteContent
;
723 struct FullscreenSavedState
{
724 DesktopRect windowRect
;
725 DesktopRect screenRect
;
727 mozilla::Maybe
<FullscreenSavedState
> mSavedBounds
;
730 bool mUseAttachedEvents
;
733 bool mIsFullyOccluded
;
734 bool mNeedFastSnaphot
;
735 // This flag is only used when APZ is off. It indicates that the current pan
736 // gesture was processed as a swipe. Sometimes the swipe animation can finish
737 // before momentum events of the pan gesture have stopped firing, so this
738 // flag tells us that we shouldn't allow the remaining events to cause
739 // scrolling. It is reset to false once a new gesture starts (as indicated by
740 // a PANGESTURE_(MAY)START event).
741 bool mCurrentPanGestureBelongsToSwipe
;
743 static nsIRollupListener
* gRollupListener
;
745 struct InitialZoomConstraints
{
746 InitialZoomConstraints(const uint32_t& aPresShellID
,
747 const ScrollableLayerGuid::ViewID
& aViewID
,
748 const ZoomConstraints
& aConstraints
)
749 : mPresShellID(aPresShellID
),
751 mConstraints(aConstraints
) {}
753 uint32_t mPresShellID
;
754 ScrollableLayerGuid::ViewID mViewID
;
755 ZoomConstraints mConstraints
;
758 mozilla::Maybe
<InitialZoomConstraints
> mInitialZoomConstraints
;
760 // This points to the resize listeners who have been notified that a live
761 // resize is in progress. This should always be empty when a live-resize is
763 nsTArray
<RefPtr
<mozilla::LiveResizeListener
>> mLiveResizeListeners
;
767 static nsAutoString
debug_GuiEventToString(
768 mozilla::WidgetGUIEvent
* aGuiEvent
);
770 static void debug_DumpInvalidate(FILE* aFileOut
, nsIWidget
* aWidget
,
771 const LayoutDeviceIntRect
* aRect
,
772 const char* aWidgetName
, int32_t aWindowID
);
774 static void debug_DumpEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
775 mozilla::WidgetGUIEvent
* aGuiEvent
,
776 const char* aWidgetName
, int32_t aWindowID
);
778 static void debug_DumpPaintEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
779 const nsIntRegion
& aPaintEvent
,
780 const char* aWidgetName
, int32_t aWindowID
);
782 static bool debug_GetCachedBoolPref(const char* aPrefName
);
786 already_AddRefed
<mozilla::layers::WebRenderLayerManager
>
787 CreateCompositorSession(int aWidth
, int aHeight
,
788 mozilla::layers::CompositorOptions
* aOptionsOut
);
791 #endif // nsBaseWidget_h__