Backed out changeset e9d46c179688 (bug 1855759) for causing build bustages CLOSED...
[gecko.git] / widget / nsBaseWidget.h
blob91dc63e4860ff303d6a9bf433e94e04781f03376
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__
8 #include "InputData.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"
20 #include "nsRect.h"
21 #include "nsIWidget.h"
22 #include "nsWidgetsCID.h"
23 #include "nsIFile.h"
24 #include "nsString.h"
25 #include "nsCOMPtr.h"
26 #include "nsIRollupListener.h"
27 #include "nsIObserver.h"
28 #include "nsIWidgetListener.h"
29 #include "nsPIDOMWindow.h"
30 #include "nsWeakReference.h"
32 #include <algorithm>
34 class nsIContent;
35 class gfxContext;
37 namespace mozilla {
38 class CompositorVsyncDispatcher;
39 class LiveResizeListener;
40 class FallbackRenderer;
41 class SwipeTracker;
42 struct SwipeEventQueue;
43 class WidgetWheelEvent;
45 #ifdef ACCESSIBILITY
46 namespace a11y {
47 class LocalAccessible;
49 #endif
51 namespace gfx {
52 class DrawTarget;
53 class SourceSurface;
54 } // namespace gfx
56 namespace layers {
57 class CompositorBridgeChild;
58 class CompositorBridgeParent;
59 class IAPZCTreeManager;
60 class GeckoContentController;
61 class APZEventState;
62 struct APZEventResult;
63 class CompositorSession;
64 class ImageContainer;
65 class WebRenderLayerManager;
66 struct ScrollableLayerGuid;
67 class RemoteCompositorSession;
68 } // namespace layers
70 namespace widget {
71 class CompositorWidgetDelegate;
72 class InProcessCompositorWidget;
73 class WidgetRenderingContext;
74 } // namespace widget
76 class CompositorVsyncDispatcher;
77 } // namespace mozilla
79 namespace base {
80 class Thread;
81 } // namespace base
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
88 class nsBaseWidget;
90 // Helper class used in shutting down gfx related code.
91 class WidgetShutdownObserver final : public nsIObserver {
92 ~WidgetShutdownObserver();
94 public:
95 explicit WidgetShutdownObserver(nsBaseWidget* aWidget);
97 NS_DECL_ISUPPORTS
98 NS_DECL_NSIOBSERVER
100 void Register();
101 void Unregister();
103 nsBaseWidget* mWidget;
104 bool mRegistered;
107 // Helper class used for observing locales change.
108 class LocalesChangedObserver final : public nsIObserver {
109 ~LocalesChangedObserver();
111 public:
112 explicit LocalesChangedObserver(nsBaseWidget* aWidget);
114 NS_DECL_ISUPPORTS
115 NS_DECL_NSIOBSERVER
117 void Register();
118 void Unregister();
120 nsBaseWidget* mWidget;
121 bool mRegistered;
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;
139 protected:
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();
159 public:
160 nsBaseWidget();
162 explicit nsBaseWidget(BorderStyle aBorderStyle);
164 NS_DECL_THREADSAFE_ISUPPORTS
166 // nsIWidget interface
167 void CaptureRollupEvents(bool aDoCapture) override {}
168 nsIWidgetListener* GetWidgetListener() const override;
169 void SetWidgetListener(nsIWidgetListener* alistener) override;
170 void Destroy() override;
171 void SetParent(nsIWidget* aNewParent) override{};
172 nsIWidget* GetParent() override;
173 nsIWidget* GetTopLevelWidget() override;
174 nsIWidget* GetSheetWindowParent(void) override;
175 float GetDPI() override;
176 void AddChild(nsIWidget* aChild) override;
177 void RemoveChild(nsIWidget* aChild) override;
179 void SetZIndex(int32_t aZIndex) override;
180 void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget* aWidget,
181 bool aActivate) override {}
183 void GetWorkspaceID(nsAString& workspaceID) override;
184 void MoveToWorkspace(const nsAString& workspaceID) override;
185 bool IsTiled() const override { return mIsTiled; }
187 bool IsFullyOccluded() const override { return mIsFullyOccluded; }
189 void SetCursor(const Cursor&) override;
190 void ClearCachedCursor() final {
191 mCursor = {};
192 mUpdateCursor = true;
194 void SetTransparencyMode(TransparencyMode aMode) override;
195 TransparencyMode GetTransparencyMode() override;
196 void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle) override {}
197 void SetShowsToolbarButton(bool aShow) override {}
198 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) override {}
199 void SetWindowAnimationType(WindowAnimationType aType) override {}
200 void HideWindowChrome(bool aShouldHide) override {}
201 bool PrepareForFullscreenTransition(nsISupports** aData) override {
202 return false;
204 void PerformFullscreenTransition(FullscreenTransitionStage aStage,
205 uint16_t aDuration, nsISupports* aData,
206 nsIRunnable* aCallback) override;
207 void CleanupFullscreenTransition() override {}
208 already_AddRefed<Screen> GetWidgetScreen() override;
209 nsresult MakeFullScreen(bool aFullScreen) override;
210 void InfallibleMakeFullScreen(bool aFullScreen);
212 WindowRenderer* GetWindowRenderer() override;
213 bool HasWindowRenderer() const final { return !!mWindowRenderer; }
215 // A remote compositor session tied to this window has been lost and IPC
216 // messages will no longer work. The widget must clean up any lingering
217 // resources and possibly schedule another paint.
219 // A reference to the session object is held until this function has
220 // returned.
221 virtual void NotifyCompositorSessionLost(
222 mozilla::layers::CompositorSession* aSession);
224 already_AddRefed<mozilla::CompositorVsyncDispatcher>
225 GetCompositorVsyncDispatcher();
226 virtual void CreateCompositorVsyncDispatcher();
227 virtual void CreateCompositor();
228 virtual void CreateCompositor(int aWidth, int aHeight);
229 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate*) {}
230 void PrepareWindowEffects() override {}
231 void UpdateThemeGeometries(
232 const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
233 void SetModal(bool aModal) override {}
234 uint32_t GetMaxTouchPoints() const override;
235 void SetWindowClass(const nsAString& xulWinType, const nsAString& xulWinClass,
236 const nsAString& xulWinName) override {}
237 // Return whether this widget interprets parameters to Move and Resize APIs
238 // as "desktop pixels" rather than "device pixels", and therefore
239 // applies its GetDefaultScale() value to them before using them as mBounds
240 // etc (which are always stored in device pixels).
241 // Note that APIs that -get- the widget's position/size/bounds, rather than
242 // -setting- them (i.e. moving or resizing the widget) will always return
243 // values in the widget's device pixels.
244 bool BoundsUseDesktopPixels() const {
245 return mWindowType <= WindowType::Popup;
247 // Default implementation, to be overridden by platforms where desktop coords
248 // are virtualized and may not correspond to device pixels on the screen.
249 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
250 return mozilla::DesktopToLayoutDeviceScale(1.0);
252 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScaleByScreen()
253 override;
255 void ConstrainPosition(DesktopIntPoint&) override {}
256 void MoveClient(const DesktopPoint& aOffset) override;
257 void ResizeClient(const DesktopSize& aSize, bool aRepaint) override;
258 void ResizeClient(const DesktopRect& aRect, bool aRepaint) override;
259 LayoutDeviceIntRect GetBounds() override;
260 LayoutDeviceIntRect GetClientBounds() override;
261 LayoutDeviceIntRect GetScreenBounds() override;
262 [[nodiscard]] nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
263 nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
264 LayoutDeviceIntPoint GetClientOffset() override;
265 void EnableDragDrop(bool aEnable) override{};
266 nsresult AsyncEnableDragDrop(bool aEnable) override;
267 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin) override;
268 [[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override {
269 return NS_OK;
271 bool HasPendingInputEvent() override;
272 void SetIcon(const nsAString& aIconSpec) override {}
273 bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
274 void FreeNativeData(void* data, uint32_t aDataType) override {}
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, InitData* aInitData = nullptr,
294 bool aForceUseIWidgetParent = false) override;
295 void AttachViewToTopLevel(bool aUseAttachedEvents) override;
296 nsIWidgetListener* GetAttachedWidgetListener() const 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 bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event) override;
314 void SetConfirmedTargetAPZC(
315 uint64_t aInputBlockId,
316 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
318 void UpdateZoomConstraints(
319 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
320 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
322 bool AsyncPanZoomEnabled() const override;
324 void SwipeFinished() override;
325 void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
326 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
327 uint32_t aAllowedDirections,
328 uint64_t aInputBlockId);
329 struct SwipeInfo {
330 bool wantsSwipe;
331 uint32_t allowedDirections;
333 SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
334 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
335 // whether |aPanInput| event was used for SwipeTracker or not.
336 mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
337 const mozilla::PanGestureInput& aPanInput,
338 const mozilla::layers::APZEventResult& aApzResult);
340 // Returns true if |aPanInput| event was used for SwipeTracker, false
341 // otherwise.
342 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput);
344 void NotifyWindowDestroyed();
345 void NotifySizeMoveDone();
347 using ByMoveToRect = nsIWidgetListener::ByMoveToRect;
348 void NotifyWindowMoved(int32_t aX, int32_t aY,
349 ByMoveToRect = ByMoveToRect::No);
351 // Should be called by derived implementations to notify on system color and
352 // theme changes.
353 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
355 #ifdef ACCESSIBILITY
356 // Get the accessible for the window.
357 mozilla::a11y::LocalAccessible* GetRootAccessible();
358 #endif
360 // Return true if this is a simple widget (that is typically not worth
361 // accelerating)
362 bool IsSmallPopup() const;
364 PopupLevel GetPopupLevel() { return mPopupLevel; }
366 // return true if this is a popup widget with a native titlebar
367 bool IsPopupWithTitleBar() const {
368 return (mWindowType == WindowType::Popup &&
369 mBorderStyle != BorderStyle::Default &&
370 mBorderStyle & BorderStyle::Title);
373 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
375 const SizeConstraints GetSizeConstraints() override;
376 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
378 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
380 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
381 const ScrollableLayerGuid& aGuid) override;
383 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
385 mozilla::layers::LayersId GetRootLayerTreeId() override;
388 * Use this when GetLayerManager() returns a BasicLayerManager
389 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
390 * layer manager to temporarily render into aTarget.
392 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
393 * |aRotation| is the "virtual rotation" to apply when rendering to
394 * the target. When |aRotation| is ROTATION_0,
395 * |aNaturalWidgetBounds| is not used.
397 class AutoLayerManagerSetup {
398 public:
399 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
400 BufferMode aDoubleBuffering);
401 ~AutoLayerManagerSetup();
403 private:
404 nsBaseWidget* mWidget;
405 mozilla::FallbackRenderer* mRenderer = nullptr;
407 friend class AutoLayerManagerSetup;
409 virtual bool ShouldUseOffMainThreadCompositing();
411 static nsIRollupListener* GetActiveRollupListener();
413 void Shutdown();
415 void QuitIME();
417 // These functions should be called at the start and end of a "live" widget
418 // resize (i.e. when the window contents are repainting during the resize,
419 // such as when the user drags a window border). It will suppress the
420 // displayport during the live resize to avoid unneccessary overpainting.
421 void NotifyLiveResizeStarted();
422 void NotifyLiveResizeStopped();
424 #if defined(MOZ_WIDGET_ANDROID)
425 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
426 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
427 const CSSToScreenScale& aZoom) override{};
428 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
429 bool aNeedsYFlip) override{};
430 #endif
432 virtual void LocalesChanged() {}
434 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
436 protected:
437 // These are methods for CompositorWidgetWrapper, and should only be
438 // accessed from that class. Derived widgets can choose which methods to
439 // implement, or none if supporting out-of-process compositing.
440 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
441 return true;
443 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
444 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
445 return nullptr;
447 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
448 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
449 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
450 return StartRemoteDrawing();
452 virtual void EndRemoteDrawing() {}
453 virtual void EndRemoteDrawingInRegion(
454 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
455 EndRemoteDrawing();
457 virtual void CleanupRemoteDrawing() {}
458 virtual void CleanupWindowEffects() {}
459 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
460 return true;
462 virtual uint32_t GetGLFrameBufferFormat();
463 virtual bool CompositorInitiallyPaused() { return false; }
465 protected:
466 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
467 nsIFile** aResult);
468 virtual void OnDestroy();
469 void BaseCreate(nsIWidget* aParent, InitData* aInitData);
471 virtual void ConfigureAPZCTreeManager();
472 virtual void ConfigureAPZControllerThread();
473 virtual already_AddRefed<GeckoContentController>
474 CreateRootContentController();
476 // Dispatch an event that has already been routed through APZ.
477 nsEventStatus ProcessUntransformedAPZEvent(
478 mozilla::WidgetInputEvent* aEvent,
479 const mozilla::layers::APZEventResult& aApzResult);
481 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
482 int32_t aNativeKeyCode,
483 uint32_t aModifierFlags,
484 const nsAString& aCharacters,
485 const nsAString& aUnmodifiedCharacters,
486 nsIObserver* aObserver) override {
487 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
488 return NS_ERROR_UNEXPECTED;
491 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
492 NativeMouseMessage aNativeMessage,
493 mozilla::MouseButton aButton,
494 nsIWidget::Modifiers aModifierFlags,
495 nsIObserver* aObserver) override {
496 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
497 return NS_ERROR_UNEXPECTED;
500 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
501 nsIObserver* aObserver) override {
502 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
503 return NS_ERROR_UNEXPECTED;
506 nsresult SynthesizeNativeMouseScrollEvent(
507 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
508 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
509 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
510 mozilla::widget::AutoObserverNotifier notifier(aObserver,
511 "mousescrollevent");
512 return NS_ERROR_UNEXPECTED;
515 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
516 TouchPointerState aPointerState,
517 LayoutDeviceIntPoint aPoint,
518 double aPointerPressure,
519 uint32_t aPointerOrientation,
520 nsIObserver* aObserver) override {
521 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
522 return NS_ERROR_UNEXPECTED;
525 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
526 float aScale,
527 LayoutDeviceIntPoint aPoint,
528 int32_t aModifierFlags) override {
529 MOZ_RELEASE_ASSERT(
530 false, "This method is not implemented on the current platform");
531 return NS_ERROR_UNEXPECTED;
534 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
535 TouchPointerState aPointerState,
536 LayoutDeviceIntPoint aPoint,
537 double aPressure, uint32_t aRotation,
538 int32_t aTiltX, int32_t aTiltY,
539 int32_t aButton,
540 nsIObserver* aObserver) override {
541 MOZ_RELEASE_ASSERT(
542 false, "This method is not implemented on the current platform");
543 return NS_ERROR_UNEXPECTED;
546 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
547 uint32_t aModifierFlags) override {
548 MOZ_RELEASE_ASSERT(
549 false, "This method is not implemented on the current platform");
550 return NS_ERROR_UNEXPECTED;
553 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
554 LayoutDeviceIntPoint aPoint,
555 double aDeltaX, double aDeltaY,
556 int32_t aModifierFlags,
557 nsIObserver* aObserver) override {
558 MOZ_RELEASE_ASSERT(
559 false, "This method is not implemented on the current platform");
560 return NS_ERROR_UNEXPECTED;
564 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
565 * has non-native input transaction. Otherwise, returns nullptr.
567 void* GetPseudoIMEContext();
569 protected:
570 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
571 return nsIWidget::CreateChildWindow();
574 WindowRenderer* CreateFallbackRenderer();
576 PopupType GetPopupType() const { return mPopupType; }
578 bool HasRemoteContent() const { return mHasRemoteContent; }
581 * Apply the current size constraints to the given size.
583 * @param aWidth width to constrain
584 * @param aHeight height to constrain
586 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
587 SizeConstraints c = GetSizeConstraints();
588 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
589 *aHeight =
590 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
593 CompositorBridgeChild* GetRemoteRenderer() override;
595 void ClearCachedWebrenderResources() override;
597 void ClearWebrenderAnimationResources() override;
599 bool SetNeedFastSnaphot() override;
602 * Notify the widget that this window is being used with OMTC.
604 virtual void WindowUsesOMTC() {}
605 virtual void RegisterTouchWindow() {}
607 mozilla::dom::Document* GetDocument() const;
609 void EnsureTextEventDispatcher();
611 // Notify the compositor that a device reset has occurred.
612 void OnRenderingDeviceReset();
614 bool UseAPZ();
616 bool AllowWebRenderForThisWindow();
619 * For widgets that support synthesizing native touch events, this function
620 * can be used to manage the current state of synthetic pointers. Each widget
621 * must maintain its own MultiTouchInput instance and pass it in as the state,
622 * along with the desired parameters for the changes. This function returns
623 * a new MultiTouchInput object that is ready to be dispatched.
625 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
626 mozilla::MultiTouchInput* aState, mozilla::TimeStamp aTimeStamp,
627 uint32_t aPointerId, TouchPointerState aPointerState,
628 LayoutDeviceIntPoint aPoint, double aPointerPressure,
629 uint32_t aPointerOrientation);
632 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
633 * or directly to gecko (if APZ is not enabled). This function must only
634 * be called from the main thread, and if APZ is enabled, that must also be
635 * the APZ controller thread.
637 void DispatchTouchInput(
638 mozilla::MultiTouchInput& aInput,
639 uint16_t aInputSource =
640 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
643 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
644 * or directly to gecko (if APZ is not enabled). This function must only
645 * be called from the main thread, and if APZ is enabled, that must also be
646 * the APZ controller thread.
648 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
649 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
651 static bool ConvertStatus(nsEventStatus aStatus) {
652 return aStatus == nsEventStatus_eConsumeNoDefault;
655 protected:
656 // Returns whether compositing should use an external surface size.
657 virtual bool UseExternalCompositingSurface() const { return false; }
660 * Starts the OMTC compositor destruction sequence.
662 * When this function returns, the compositor should not be
663 * able to access the opengl context anymore.
664 * It is safe to call it several times if platform implementations
665 * require the compositor to be destroyed before ~nsBaseWidget is
666 * reached (This is the case with gtk2 for instance).
668 virtual void DestroyCompositor();
669 void DestroyLayerManager();
670 void ReleaseContentController();
671 void RevokeTransactionIdAllocator();
673 void FreeShutdownObserver();
674 void FreeLocalesChangedObserver();
676 bool IsPIPWindow() const { return mIsPIPWindow; };
678 nsIWidgetListener* mWidgetListener;
679 nsIWidgetListener* mAttachedWidgetListener;
680 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
681 RefPtr<WindowRenderer> mWindowRenderer;
682 RefPtr<CompositorSession> mCompositorSession;
683 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
685 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
686 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
688 RefPtr<IAPZCTreeManager> mAPZC;
689 RefPtr<GeckoContentController> mRootContentController;
690 RefPtr<APZEventState> mAPZEventState;
691 RefPtr<WidgetShutdownObserver> mShutdownObserver;
692 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
693 RefPtr<TextEventDispatcher> mTextEventDispatcher;
694 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
695 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
696 Cursor mCursor;
697 BorderStyle mBorderStyle;
698 LayoutDeviceIntRect mBounds;
699 bool mIsTiled;
700 PopupLevel mPopupLevel;
701 PopupType mPopupType;
702 SizeConstraints mSizeConstraints;
703 bool mHasRemoteContent;
705 struct FullscreenSavedState {
706 DesktopRect windowRect;
707 DesktopRect screenRect;
709 mozilla::Maybe<FullscreenSavedState> mSavedBounds;
711 bool mUpdateCursor;
712 bool mUseAttachedEvents;
713 bool mIMEHasFocus;
714 bool mIMEHasQuit;
715 bool mIsFullyOccluded;
716 bool mNeedFastSnaphot;
717 // This flag is only used when APZ is off. It indicates that the current pan
718 // gesture was processed as a swipe. Sometimes the swipe animation can finish
719 // before momentum events of the pan gesture have stopped firing, so this
720 // flag tells us that we shouldn't allow the remaining events to cause
721 // scrolling. It is reset to false once a new gesture starts (as indicated by
722 // a PANGESTURE_(MAY)START event).
723 bool mCurrentPanGestureBelongsToSwipe;
725 // It's PictureInPicture window.
726 bool mIsPIPWindow : 1;
728 struct InitialZoomConstraints {
729 InitialZoomConstraints(const uint32_t& aPresShellID,
730 const ScrollableLayerGuid::ViewID& aViewID,
731 const ZoomConstraints& aConstraints)
732 : mPresShellID(aPresShellID),
733 mViewID(aViewID),
734 mConstraints(aConstraints) {}
736 uint32_t mPresShellID;
737 ScrollableLayerGuid::ViewID mViewID;
738 ZoomConstraints mConstraints;
741 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
743 // This points to the resize listeners who have been notified that a live
744 // resize is in progress. This should always be empty when a live-resize is
745 // not in progress.
746 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
748 #ifdef DEBUG
749 protected:
750 static nsAutoString debug_GuiEventToString(
751 mozilla::WidgetGUIEvent* aGuiEvent);
753 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
754 const LayoutDeviceIntRect* aRect,
755 const char* aWidgetName, int32_t aWindowID);
757 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
758 mozilla::WidgetGUIEvent* aGuiEvent,
759 const char* aWidgetName, int32_t aWindowID);
761 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
762 const nsIntRegion& aPaintEvent,
763 const char* aWidgetName, int32_t aWindowID);
765 static bool debug_GetCachedBoolPref(const char* aPrefName);
766 #endif
768 private:
769 already_AddRefed<mozilla::layers::WebRenderLayerManager>
770 CreateCompositorSession(int aWidth, int aHeight,
771 mozilla::layers::CompositorOptions* aOptionsOut);
774 #endif // nsBaseWidget_h__