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/layers/APZCCallbackHelper.h"
15 #include "mozilla/layers/CompositorOptions.h"
17 #include "nsIWidget.h"
18 #include "nsWidgetsCID.h"
22 #include "nsIRollupListener.h"
23 #include "nsIObserver.h"
24 #include "nsIWidgetListener.h"
25 #include "nsPIDOMWindow.h"
26 #include "nsWeakReference.h"
31 // Scroll capture constants
32 const uint32_t kScrollCaptureFillColor
= 0xFFa0a0a0; // gray
33 const mozilla::gfx::SurfaceFormat kScrollCaptureFormat
=
34 mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32
;
41 class CompositorVsyncDispatcher
;
42 class LiveResizeListener
;
56 class BasicLayerManager
;
57 class CompositorBridgeChild
;
58 class CompositorBridgeParent
;
59 class IAPZCTreeManager
;
60 class GeckoContentController
;
62 class CompositorSession
;
64 struct ScrollableLayerGuid
;
65 class RemoteCompositorSession
;
69 class CompositorWidgetDelegate
;
70 class InProcessCompositorWidget
;
71 class WidgetRenderingContext
;
74 class CompositorVsyncDispatcher
;
75 } // namespace mozilla
81 // Windows specific constant indicating the maximum number of touch points the
82 // inject api will allow. This also sets the maximum numerical value for touch
83 // ids we can use when injecting touch points on Windows.
84 #define TOUCH_INJECT_MAX_POINTS 256
88 // Helper class used in shutting down gfx related code.
89 class WidgetShutdownObserver final
: public nsIObserver
{
90 ~WidgetShutdownObserver();
93 explicit WidgetShutdownObserver(nsBaseWidget
* aWidget
);
101 nsBaseWidget
* mWidget
;
106 * Common widget implementation used as base class for native
107 * or crossplatform implementations of Widgets.
108 * All cross-platform behavior that all widgets need to implement
109 * should be placed in this class.
110 * (Note: widget implementations are not required to use this
111 * class, but it gives them a head start.)
114 class nsBaseWidget
: public nsIWidget
, public nsSupportsWeakReference
{
115 friend class DispatchWheelEventOnMainThread
;
116 friend class mozilla::widget::InProcessCompositorWidget
;
117 friend class mozilla::layers::RemoteCompositorSession
;
120 typedef base::Thread Thread
;
121 typedef mozilla::gfx::DrawTarget DrawTarget
;
122 typedef mozilla::gfx::SourceSurface SourceSurface
;
123 typedef mozilla::layers::BasicLayerManager BasicLayerManager
;
124 typedef mozilla::layers::BufferMode BufferMode
;
125 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild
;
126 typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent
;
127 typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager
;
128 typedef mozilla::layers::GeckoContentController GeckoContentController
;
129 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid
;
130 typedef mozilla::layers::APZEventState APZEventState
;
131 typedef mozilla::layers::SetAllowedTouchBehaviorCallback
132 SetAllowedTouchBehaviorCallback
;
133 typedef mozilla::CSSIntRect CSSIntRect
;
134 typedef mozilla::CSSRect CSSRect
;
135 typedef mozilla::ScreenRotation ScreenRotation
;
136 typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate
;
137 typedef mozilla::layers::CompositorSession CompositorSession
;
138 typedef mozilla::layers::ImageContainer ImageContainer
;
140 virtual ~nsBaseWidget();
147 // nsIWidget interface
148 virtual void CaptureMouse(bool aCapture
) override
{}
149 virtual void CaptureRollupEvents(nsIRollupListener
* aListener
,
150 bool aDoCapture
) override
{}
151 virtual nsIWidgetListener
* GetWidgetListener() override
;
152 virtual void SetWidgetListener(nsIWidgetListener
* alistener
) override
;
153 virtual void Destroy() override
;
154 virtual void SetParent(nsIWidget
* aNewParent
) override
{};
155 virtual nsIWidget
* GetParent(void) override
;
156 virtual nsIWidget
* GetTopLevelWidget() override
;
157 virtual nsIWidget
* GetSheetWindowParent(void) override
;
158 virtual float GetDPI() override
;
159 virtual void AddChild(nsIWidget
* aChild
) override
;
160 virtual void RemoveChild(nsIWidget
* aChild
) override
;
162 void SetZIndex(int32_t aZIndex
) override
;
163 virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
,
164 nsIWidget
* aWidget
, bool aActivate
) override
{}
166 virtual void SetSizeMode(nsSizeMode aMode
) override
;
167 virtual nsSizeMode
SizeMode() override
{ return mSizeMode
; }
169 virtual bool IsFullyOccluded() const override
{ return mIsFullyOccluded
; }
171 virtual void SetCursor(nsCursor aDefaultCursor
, imgIContainer
* aCursor
,
172 uint32_t aHotspotX
, uint32_t aHotspotY
) override
;
173 virtual void ClearCachedCursor() override
{ mUpdateCursor
= true; }
174 virtual void SetTransparencyMode(nsTransparencyMode aMode
) override
;
175 virtual nsTransparencyMode
GetTransparencyMode() override
;
176 virtual void GetWindowClipRegion(
177 nsTArray
<LayoutDeviceIntRect
>* aRects
) override
;
178 virtual void SetWindowShadowStyle(int32_t aStyle
) override
{}
179 virtual void SetShowsToolbarButton(bool aShow
) override
{}
180 virtual void SetShowsFullScreenButton(bool aShow
) override
{}
181 virtual void SetWindowAnimationType(WindowAnimationType aType
) override
{}
182 virtual void HideWindowChrome(bool aShouldHide
) override
{}
183 virtual bool PrepareForFullscreenTransition(nsISupports
** aData
) override
{
186 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
189 nsIRunnable
* aCallback
) override
;
190 virtual void CleanupFullscreenTransition() override
{};
191 virtual already_AddRefed
<nsIScreen
> GetWidgetScreen() override
;
192 virtual nsresult
MakeFullScreen(bool aFullScreen
,
193 nsIScreen
* aScreen
= nullptr) override
;
194 void InfallibleMakeFullScreen(bool aFullScreen
, nsIScreen
* aScreen
= nullptr);
196 virtual LayerManager
* GetLayerManager(
197 PLayerTransactionChild
* aShadowManager
= nullptr,
198 LayersBackend aBackendHint
= mozilla::layers::LayersBackend::LAYERS_NONE
,
199 LayerManagerPersistence aPersistence
= LAYER_MANAGER_CURRENT
) override
;
201 // A remote compositor session tied to this window has been lost and IPC
202 // messages will no longer work. The widget must clean up any lingering
203 // resources and possibly schedule another paint.
205 // A reference to the session object is held until this function has
207 void NotifyCompositorSessionLost(
208 mozilla::layers::CompositorSession
* aSession
);
210 already_AddRefed
<mozilla::CompositorVsyncDispatcher
>
211 GetCompositorVsyncDispatcher();
212 void CreateCompositorVsyncDispatcher();
213 virtual void CreateCompositor();
214 virtual void CreateCompositor(int aWidth
, int aHeight
);
215 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate
* delegate
) {
217 virtual void PrepareWindowEffects() override
{}
218 virtual void UpdateThemeGeometries(
219 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) override
{}
220 virtual void SetModal(bool aModal
) override
{}
221 virtual uint32_t GetMaxTouchPoints() const override
;
222 virtual void SetWindowClass(const nsAString
& xulWinType
) override
{}
223 virtual nsresult
SetWindowClipRegion(
224 const nsTArray
<LayoutDeviceIntRect
>& aRects
,
225 bool aIntersectWithExisting
) override
;
226 // Return whether this widget interprets parameters to Move and Resize APIs
227 // as "desktop pixels" rather than "device pixels", and therefore
228 // applies its GetDefaultScale() value to them before using them as mBounds
229 // etc (which are always stored in device pixels).
230 // Note that APIs that -get- the widget's position/size/bounds, rather than
231 // -setting- them (i.e. moving or resizing the widget) will always return
232 // values in the widget's device pixels.
233 bool BoundsUseDesktopPixels() const {
234 return mWindowType
<= eWindowType_popup
;
236 // Default implementation, to be overridden by platforms where desktop coords
237 // are virtualized and may not correspond to device pixels on the screen.
238 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() override
{
239 return mozilla::DesktopToLayoutDeviceScale(1.0);
241 mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScaleByScreen()
244 virtual void ConstrainPosition(bool aAllowSlop
, int32_t* aX
,
245 int32_t* aY
) override
{}
246 virtual void MoveClient(double aX
, double aY
) override
;
247 virtual void ResizeClient(double aWidth
, double aHeight
,
248 bool aRepaint
) override
;
249 virtual void ResizeClient(double aX
, double aY
, double aWidth
, double aHeight
,
250 bool aRepaint
) override
;
251 virtual LayoutDeviceIntRect
GetBounds() override
;
252 virtual LayoutDeviceIntRect
GetClientBounds() override
;
253 virtual LayoutDeviceIntRect
GetScreenBounds() override
;
254 virtual MOZ_MUST_USE nsresult
255 GetRestoredBounds(LayoutDeviceIntRect
& aRect
) override
;
256 virtual nsresult
SetNonClientMargins(
257 LayoutDeviceIntMargin
& aMargins
) override
;
258 virtual LayoutDeviceIntPoint
GetClientOffset() override
;
259 virtual void EnableDragDrop(bool aEnable
) override
{};
260 virtual nsresult
AsyncEnableDragDrop(bool aEnable
) override
;
261 virtual MOZ_MUST_USE nsresult
GetAttention(int32_t aCycleCount
) override
{
264 virtual bool HasPendingInputEvent() override
;
265 virtual void SetIcon(const nsAString
& aIconSpec
) override
{}
266 virtual void SetDrawsInTitlebar(bool aState
) override
{}
267 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) override
;
268 virtual void FreeNativeData(void* data
, uint32_t aDataType
) override
{}
269 virtual MOZ_MUST_USE nsresult
BeginResizeDrag(mozilla::WidgetGUIEvent
* aEvent
,
271 int32_t aVertical
) override
{
272 return NS_ERROR_NOT_IMPLEMENTED
;
274 virtual nsresult
ActivateNativeMenuItemAt(
275 const nsAString
& indexString
) override
{
276 return NS_ERROR_NOT_IMPLEMENTED
;
278 virtual nsresult
ForceUpdateNativeMenuAt(
279 const nsAString
& indexString
) override
{
280 return NS_ERROR_NOT_IMPLEMENTED
;
282 nsresult
NotifyIME(const IMENotification
& aIMENotification
) final
;
283 virtual MOZ_MUST_USE nsresult
StartPluginIME(
284 const mozilla::WidgetKeyboardEvent
& aKeyboardEvent
, int32_t aPanelX
,
285 int32_t aPanelY
, nsString
& aCommitted
) override
{
286 return NS_ERROR_NOT_IMPLEMENTED
;
288 virtual void SetPluginFocused(bool& aFocused
) override
{}
289 virtual void SetCandidateWindowForPlugin(
290 const mozilla::widget::CandidateWindowPosition
& aPosition
) override
{}
291 virtual void DefaultProcOfPluginEvent(
292 const mozilla::WidgetPluginEvent
& aEvent
) override
{}
293 virtual MOZ_MUST_USE nsresult
294 AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent
& aEvent
) override
{
295 return NS_ERROR_NOT_IMPLEMENTED
;
297 bool ComputeShouldAccelerate();
298 virtual bool WidgetTypeSupportsAcceleration() { return true; }
299 virtual MOZ_MUST_USE nsresult
300 OnDefaultButtonLoaded(const LayoutDeviceIntRect
& aButtonRect
) override
{
301 return NS_ERROR_NOT_IMPLEMENTED
;
303 virtual already_AddRefed
<nsIWidget
> CreateChild(
304 const LayoutDeviceIntRect
& aRect
, nsWidgetInitData
* aInitData
= nullptr,
305 bool aForceUseIWidgetParent
= false) override
;
306 virtual void AttachViewToTopLevel(bool aUseAttachedEvents
) override
;
307 virtual nsIWidgetListener
* GetAttachedWidgetListener() override
;
308 virtual void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) override
;
309 virtual nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() override
;
310 virtual void SetPreviouslyAttachedWidgetListener(
311 nsIWidgetListener
* aListener
) override
;
312 virtual NativeIMEContext
GetNativeIMEContext() override
;
313 TextEventDispatcher
* GetTextEventDispatcher() final
;
314 virtual TextEventDispatcherListener
* GetNativeTextEventDispatcherListener()
316 virtual void ZoomToRect(const uint32_t& aPresShellId
,
317 const ScrollableLayerGuid::ViewID
& aViewId
,
318 const CSSRect
& aRect
,
319 const uint32_t& aFlags
) override
;
320 // Dispatch an event that must be first be routed through APZ.
321 nsEventStatus
DispatchInputEvent(mozilla::WidgetInputEvent
* aEvent
) override
;
322 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) override
;
324 void SetConfirmedTargetAPZC(
325 uint64_t aInputBlockId
,
326 const nsTArray
<ScrollableLayerGuid
>& aTargets
) const override
;
328 void UpdateZoomConstraints(
329 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
330 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) override
;
332 bool AsyncPanZoomEnabled() const override
;
334 typedef void (nsIPresShell::*NotificationFunc
)(void);
335 void NotifyPresShell(NotificationFunc aNotificationFunc
);
337 void NotifyWindowDestroyed();
338 void NotifySizeMoveDone();
339 void NotifyWindowMoved(int32_t aX
, int32_t aY
);
341 // Register plugin windows for remote updates from the compositor
342 virtual void RegisterPluginWindowForRemoteUpdates() override
;
343 virtual void UnregisterPluginWindowForRemoteUpdates() override
;
345 virtual void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) override
{};
347 // Should be called by derived implementations to notify on system color and
349 void NotifySysColorChanged();
350 void NotifyThemeChanged();
351 void NotifyUIStateChanged(UIStateChangeType aShowAccelerators
,
352 UIStateChangeType aShowFocusRings
);
355 // Get the accessible for the window.
356 mozilla::a11y::Accessible
* GetRootAccessible();
359 // Return true if this is a simple widget (that is typically not worth
361 bool IsSmallPopup() const;
363 nsPopupLevel
PopupLevel() { return mPopupLevel
; }
365 virtual LayoutDeviceIntSize
ClientToWindowSize(
366 const LayoutDeviceIntSize
& aClientSize
) override
{
370 // return true if this is a popup widget with a native titlebar
371 bool IsPopupWithTitleBar() const {
372 return (mWindowType
== eWindowType_popup
&&
373 mBorderStyle
!= eBorderStyle_default
&&
374 mBorderStyle
& eBorderStyle_title
);
377 virtual void ReparentNativeWidget(nsIWidget
* aNewParent
) override
{}
379 virtual const SizeConstraints
GetSizeConstraints() override
;
380 virtual void SetSizeConstraints(const SizeConstraints
& aConstraints
) override
;
382 virtual void StartAsyncScrollbarDrag(
383 const AsyncDragMetrics
& aDragMetrics
) override
;
385 virtual bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
386 const ScrollableLayerGuid
& aGuid
) override
;
388 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) override
;
391 * Use this when GetLayerManager() returns a BasicLayerManager
392 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
393 * layer manager to temporarily render into aTarget.
395 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
396 * |aRotation| is the "virtual rotation" to apply when rendering to
397 * the target. When |aRotation| is ROTATION_0,
398 * |aNaturalWidgetBounds| is not used.
400 class AutoLayerManagerSetup
{
402 AutoLayerManagerSetup(nsBaseWidget
* aWidget
, gfxContext
* aTarget
,
403 BufferMode aDoubleBuffering
,
404 ScreenRotation aRotation
= mozilla::ROTATION_0
);
405 ~AutoLayerManagerSetup();
408 nsBaseWidget
* mWidget
;
409 RefPtr
<BasicLayerManager
> mLayerManager
;
411 friend class AutoLayerManagerSetup
;
413 virtual bool ShouldUseOffMainThreadCompositing();
415 static nsIRollupListener
* GetActiveRollupListener();
420 uint64_t CreateScrollCaptureContainer() override
;
423 // These functions should be called at the start and end of a "live" widget
424 // resize (i.e. when the window contents are repainting during the resize,
425 // such as when the user drags a window border). It will suppress the
426 // displayport during the live resize to avoid unneccessary overpainting.
427 void NotifyLiveResizeStarted();
428 void NotifyLiveResizeStopped();
430 #if defined(MOZ_WIDGET_ANDROID)
431 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override
{};
432 void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
433 const CSSToScreenScale
& aZoom
) override
{};
434 void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
,
435 const ScreenIntSize
& aSize
) override
{};
439 * Whether context menus should only appear on mouseup instead of mousedown,
440 * on OSes where they normally appear on mousedown (macOS, *nix).
442 static bool ShowContextMenuAfterMouseUp();
445 // These are methods for CompositorWidgetWrapper, and should only be
446 // accessed from that class. Derived widgets can choose which methods to
447 // implement, or none if supporting out-of-process compositing.
448 virtual bool PreRender(mozilla::widget::WidgetRenderingContext
* aContext
) {
451 virtual void PostRender(mozilla::widget::WidgetRenderingContext
* aContext
) {}
452 virtual void DrawWindowUnderlay(
453 mozilla::widget::WidgetRenderingContext
* aContext
,
454 LayoutDeviceIntRect aRect
) {}
455 virtual void DrawWindowOverlay(
456 mozilla::widget::WidgetRenderingContext
* aContext
,
457 LayoutDeviceIntRect aRect
) {}
458 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawing();
459 virtual already_AddRefed
<DrawTarget
> StartRemoteDrawingInRegion(
460 LayoutDeviceIntRegion
& aInvalidRegion
, BufferMode
* aBufferMode
) {
461 return StartRemoteDrawing();
463 virtual void EndRemoteDrawing() {}
464 virtual void EndRemoteDrawingInRegion(DrawTarget
* aDrawTarget
,
465 LayoutDeviceIntRegion
& aInvalidRegion
) {
468 virtual void CleanupRemoteDrawing() {}
469 virtual void CleanupWindowEffects() {}
470 virtual bool InitCompositor(mozilla::layers::Compositor
* aCompositor
) {
473 virtual uint32_t GetGLFrameBufferFormat();
476 void ResolveIconName(const nsAString
& aIconName
, const nsAString
& aIconSuffix
,
478 virtual void OnDestroy();
479 void BaseCreate(nsIWidget
* aParent
, nsWidgetInitData
* aInitData
);
481 virtual void ConfigureAPZCTreeManager();
482 virtual void ConfigureAPZControllerThread();
483 virtual already_AddRefed
<GeckoContentController
>
484 CreateRootContentController();
486 // Dispatch an event that has already been routed through APZ.
487 nsEventStatus
ProcessUntransformedAPZEvent(mozilla::WidgetInputEvent
* aEvent
,
488 const ScrollableLayerGuid
& aGuid
,
489 uint64_t aInputBlockId
,
490 nsEventStatus aApzResponse
);
492 const LayoutDeviceIntRegion
RegionFromArray(
493 const nsTArray
<LayoutDeviceIntRect
>& aRects
);
494 void ArrayFromRegion(const LayoutDeviceIntRegion
& aRegion
,
495 nsTArray
<LayoutDeviceIntRect
>& aRects
);
497 virtual nsresult
SynthesizeNativeKeyEvent(
498 int32_t aNativeKeyboardLayout
, int32_t aNativeKeyCode
,
499 uint32_t aModifierFlags
, const nsAString
& aCharacters
,
500 const nsAString
& aUnmodifiedCharacters
, nsIObserver
* aObserver
) override
{
501 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "keyevent");
502 return NS_ERROR_UNEXPECTED
;
505 virtual nsresult
SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint
,
506 uint32_t aNativeMessage
,
507 uint32_t aModifierFlags
,
508 nsIObserver
* aObserver
) override
{
509 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
510 return NS_ERROR_UNEXPECTED
;
513 virtual nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
514 nsIObserver
* aObserver
) override
{
515 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "mouseevent");
516 return NS_ERROR_UNEXPECTED
;
519 virtual nsresult
SynthesizeNativeMouseScrollEvent(
520 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
521 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
522 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) override
{
523 mozilla::widget::AutoObserverNotifier
notifier(aObserver
,
525 return NS_ERROR_UNEXPECTED
;
528 virtual nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
529 TouchPointerState aPointerState
,
530 LayoutDeviceIntPoint aPoint
,
531 double aPointerPressure
,
532 uint32_t aPointerOrientation
,
533 nsIObserver
* aObserver
) override
{
534 mozilla::widget::AutoObserverNotifier
notifier(aObserver
, "touchpoint");
535 return NS_ERROR_UNEXPECTED
;
539 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
540 * has non-native input transaction. Otherwise, returns nullptr.
542 void* GetPseudoIMEContext();
545 // Utility to check if an array of clip rects is equal to our
546 // internally stored clip rect array mClipRects.
547 bool IsWindowClipRegionEqual(const nsTArray
<LayoutDeviceIntRect
>& aRects
);
549 // Stores the clip rectangles in aRects into mClipRects.
550 void StoreWindowClipRegion(const nsTArray
<LayoutDeviceIntRect
>& aRects
);
552 virtual already_AddRefed
<nsIWidget
> AllocateChildPopupWidget() {
553 return nsIWidget::CreateChildWindow();
556 LayerManager
* CreateBasicLayerManager();
558 nsPopupType
PopupType() const { return mPopupType
; }
560 bool HasRemoteContent() const { return mHasRemoteContent
; }
562 void NotifyRollupGeometryChange() {
563 // XULPopupManager isn't interested in this notification, so only
564 // send it if gRollupListener is set.
565 if (gRollupListener
) {
566 gRollupListener
->NotifyGeometryChange();
571 * Apply the current size constraints to the given size.
573 * @param aWidth width to constrain
574 * @param aHeight height to constrain
576 void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) {
577 SizeConstraints c
= GetSizeConstraints();
578 *aWidth
= std::max(c
.mMinSize
.width
, std::min(c
.mMaxSize
.width
, *aWidth
));
580 std::max(c
.mMinSize
.height
, std::min(c
.mMaxSize
.height
, *aHeight
));
583 virtual CompositorBridgeChild
* GetRemoteRenderer() override
;
586 * Notify the widget that this window is being used with OMTC.
588 virtual void WindowUsesOMTC() {}
589 virtual void RegisterTouchWindow() {}
591 mozilla::dom::Document
* GetDocument() const;
593 void EnsureTextEventDispatcher();
595 // Notify the compositor that a device reset has occurred.
596 void OnRenderingDeviceReset();
600 bool AllowWebRenderForThisWindow();
603 * For widgets that support synthesizing native touch events, this function
604 * can be used to manage the current state of synthetic pointers. Each widget
605 * must maintain its own MultiTouchInput instance and pass it in as the state,
606 * along with the desired parameters for the changes. This function returns
607 * a new MultiTouchInput object that is ready to be dispatched.
609 mozilla::MultiTouchInput
UpdateSynthesizedTouchState(
610 mozilla::MultiTouchInput
* aState
, uint32_t aTime
,
611 mozilla::TimeStamp aTimeStamp
, uint32_t aPointerId
,
612 TouchPointerState aPointerState
, LayoutDeviceIntPoint aPoint
,
613 double aPointerPressure
, uint32_t aPointerOrientation
);
616 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
617 * or directly to gecko (if APZ is not enabled). This function must only
618 * be called from the main thread, and if APZ is enabled, that must also be
619 * the APZ controller thread.
621 void DispatchTouchInput(mozilla::MultiTouchInput
& aInput
);
624 void UpdateScrollCapture() override
;
627 * To be overridden by derived classes to return a snapshot that can be used
628 * during scrolling. Returning null means we won't update the container.
629 * @return an already AddRefed SourceSurface containing the snapshot
631 virtual already_AddRefed
<SourceSurface
> CreateScrollSnapshot() {
636 * Used by derived classes to create a fallback scroll image.
637 * @param aSnapshotDrawTarget DrawTarget to fill with fallback image.
639 void DefaultFillScrollCapture(DrawTarget
* aSnapshotDrawTarget
);
641 RefPtr
<ImageContainer
> mScrollCaptureContainer
;
645 // Returns whether compositing should use an external surface size.
646 virtual bool UseExternalCompositingSurface() const { return false; }
649 * Starts the OMTC compositor destruction sequence.
651 * When this function returns, the compositor should not be
652 * able to access the opengl context anymore.
653 * It is safe to call it several times if platform implementations
654 * require the compositor to be destroyed before ~nsBaseWidget is
655 * reached (This is the case with gtk2 for instance).
657 virtual void DestroyCompositor();
658 void DestroyLayerManager();
659 void ReleaseContentController();
660 void RevokeTransactionIdAllocator();
662 void FreeShutdownObserver();
664 nsIWidgetListener
* mWidgetListener
;
665 nsIWidgetListener
* mAttachedWidgetListener
;
666 nsIWidgetListener
* mPreviouslyAttachedWidgetListener
;
667 RefPtr
<LayerManager
> mLayerManager
;
668 RefPtr
<CompositorSession
> mCompositorSession
;
669 RefPtr
<CompositorBridgeChild
> mCompositorBridgeChild
;
671 mozilla::UniquePtr
<mozilla::Mutex
> mCompositorVsyncDispatcherLock
;
672 RefPtr
<mozilla::CompositorVsyncDispatcher
> mCompositorVsyncDispatcher
;
674 RefPtr
<IAPZCTreeManager
> mAPZC
;
675 RefPtr
<GeckoContentController
> mRootContentController
;
676 RefPtr
<APZEventState
> mAPZEventState
;
677 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback
;
678 RefPtr
<WidgetShutdownObserver
> mShutdownObserver
;
679 RefPtr
<TextEventDispatcher
> mTextEventDispatcher
;
681 nsBorderStyle mBorderStyle
;
682 LayoutDeviceIntRect mBounds
;
683 LayoutDeviceIntRect
* mOriginalBounds
;
684 // When this pointer is null, the widget is not clipped
685 mozilla::UniquePtr
<LayoutDeviceIntRect
[]> mClipRects
;
686 uint32_t mClipRectCount
;
687 nsSizeMode mSizeMode
;
688 nsPopupLevel mPopupLevel
;
689 nsPopupType mPopupType
;
690 SizeConstraints mSizeConstraints
;
691 bool mHasRemoteContent
;
694 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
);
723 static bool debug_WantPaintFlashing();
725 static void debug_DumpInvalidate(FILE* aFileOut
, nsIWidget
* aWidget
,
726 const LayoutDeviceIntRect
* aRect
,
727 const char* aWidgetName
, int32_t aWindowID
);
729 static void debug_DumpEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
730 mozilla::WidgetGUIEvent
* aGuiEvent
,
731 const char* aWidgetName
, int32_t aWindowID
);
733 static void debug_DumpPaintEvent(FILE* aFileOut
, nsIWidget
* aWidget
,
734 const nsIntRegion
& aPaintEvent
,
735 const char* aWidgetName
, int32_t aWindowID
);
737 static bool debug_GetCachedBoolPref(const char* aPrefName
);
741 already_AddRefed
<LayerManager
> CreateCompositorSession(
742 int aWidth
, int aHeight
, mozilla::layers::CompositorOptions
* aOptionsOut
);
745 #endif // nsBaseWidget_h__