Bug 1806400 - Move the CancelTask call in HandleTouchEndEvent() into MaybeChangeActiv...
[gecko.git] / widget / nsBaseWidget.h
blob756f2ab7ebc71d99339c42e53f502320e8d6ba95
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 SetCustomCursorAllowed(bool) override;
191 void ClearCachedCursor() final {
192 mCursor = {};
193 mUpdateCursor = true;
195 void SetTransparencyMode(TransparencyMode aMode) override;
196 TransparencyMode GetTransparencyMode() override;
197 void SetWindowShadowStyle(mozilla::WindowShadow) override {}
198 void SetShowsToolbarButton(bool aShow) override {}
199 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) override {}
200 void SetWindowAnimationType(WindowAnimationType aType) override {}
201 void HideWindowChrome(bool aShouldHide) override {}
202 bool PrepareForFullscreenTransition(nsISupports** aData) override {
203 return false;
205 void PerformFullscreenTransition(FullscreenTransitionStage aStage,
206 uint16_t aDuration, nsISupports* aData,
207 nsIRunnable* aCallback) override;
208 void CleanupFullscreenTransition() override {}
209 already_AddRefed<Screen> GetWidgetScreen() override;
210 nsresult MakeFullScreen(bool aFullScreen) override;
211 void InfallibleMakeFullScreen(bool aFullScreen);
213 WindowRenderer* GetWindowRenderer() override;
214 bool HasWindowRenderer() const final { return !!mWindowRenderer; }
216 // A remote compositor session tied to this window has been lost and IPC
217 // messages will no longer work. The widget must clean up any lingering
218 // resources and possibly schedule another paint.
220 // A reference to the session object is held until this function has
221 // returned. Callers should hold a reference to the widget, since this
222 // function could deallocate the widget if it is unparented.
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, const nsAString& xulWinClass,
238 const nsAString& xulWinName) override {}
239 // Return whether this widget interprets parameters to Move and Resize APIs
240 // as "desktop pixels" rather than "device pixels", and therefore
241 // applies its GetDefaultScale() value to them before using them as mBounds
242 // etc (which are always stored in device pixels).
243 // Note that APIs that -get- the widget's position/size/bounds, rather than
244 // -setting- them (i.e. moving or resizing the widget) will always return
245 // values in the widget's device pixels.
246 bool BoundsUseDesktopPixels() const {
247 return mWindowType <= WindowType::Popup;
249 // Default implementation, to be overridden by platforms where desktop coords
250 // are virtualized and may not correspond to device pixels on the screen.
251 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
252 return mozilla::DesktopToLayoutDeviceScale(1.0);
254 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScaleByScreen()
255 override;
257 void ConstrainPosition(DesktopIntPoint&) override {}
258 void MoveClient(const DesktopPoint& aOffset) override;
259 void ResizeClient(const DesktopSize& aSize, bool aRepaint) override;
260 void ResizeClient(const DesktopRect& aRect, bool aRepaint) override;
261 LayoutDeviceIntRect GetBounds() override;
262 LayoutDeviceIntRect GetClientBounds() override;
263 LayoutDeviceIntRect GetScreenBounds() override;
264 [[nodiscard]] nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
265 nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
266 LayoutDeviceIntPoint GetClientOffset() override;
267 void EnableDragDrop(bool aEnable) override{};
268 nsresult AsyncEnableDragDrop(bool aEnable) override;
269 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin) override;
270 [[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override {
271 return NS_OK;
273 bool HasPendingInputEvent() override;
274 void SetIcon(const nsAString& aIconSpec) override {}
275 bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
276 void FreeNativeData(void* data, uint32_t aDataType) override {}
277 nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override {
278 return NS_ERROR_NOT_IMPLEMENTED;
280 nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override {
281 return NS_ERROR_NOT_IMPLEMENTED;
283 nsresult NotifyIME(const IMENotification& aIMENotification) final;
284 [[nodiscard]] nsresult AttachNativeKeyEvent(
285 mozilla::WidgetKeyboardEvent& aEvent) override {
286 return NS_ERROR_NOT_IMPLEMENTED;
288 bool ComputeShouldAccelerate();
289 virtual bool WidgetTypeSupportsAcceleration() { return true; }
290 [[nodiscard]] nsresult OnDefaultButtonLoaded(
291 const LayoutDeviceIntRect& aButtonRect) override {
292 return NS_ERROR_NOT_IMPLEMENTED;
294 already_AddRefed<nsIWidget> CreateChild(
295 const LayoutDeviceIntRect& aRect, InitData* aInitData = nullptr,
296 bool aForceUseIWidgetParent = false) override;
297 void AttachViewToTopLevel(bool aUseAttachedEvents) override;
298 nsIWidgetListener* GetAttachedWidgetListener() const override;
299 void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
300 nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
301 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener*) override;
302 NativeIMEContext GetNativeIMEContext() override;
303 TextEventDispatcher* GetTextEventDispatcher() final;
304 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
305 void ZoomToRect(const uint32_t& aPresShellId,
306 const ScrollableLayerGuid::ViewID& aViewId,
307 const CSSRect& aRect, const uint32_t& aFlags) override;
309 // Dispatch an event that must be first be routed through APZ.
310 ContentAndAPZEventStatus DispatchInputEvent(
311 mozilla::WidgetInputEvent* aEvent) override;
312 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
314 bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event) override;
316 void SetConfirmedTargetAPZC(
317 uint64_t aInputBlockId,
318 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
320 void UpdateZoomConstraints(
321 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
322 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
324 bool AsyncPanZoomEnabled() const override;
326 void SwipeFinished() override;
327 void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
328 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
329 uint32_t aAllowedDirections,
330 uint64_t aInputBlockId);
331 struct SwipeInfo {
332 bool wantsSwipe;
333 uint32_t allowedDirections;
335 SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
336 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
337 // whether |aPanInput| event was used for SwipeTracker or not.
338 mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
339 const mozilla::PanGestureInput& aPanInput,
340 const mozilla::layers::APZEventResult& aApzResult);
342 // Returns true if |aPanInput| event was used for SwipeTracker, false
343 // otherwise.
344 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput);
346 void NotifyWindowDestroyed();
347 void NotifySizeMoveDone();
349 using ByMoveToRect = nsIWidgetListener::ByMoveToRect;
350 void NotifyWindowMoved(int32_t aX, int32_t aY,
351 ByMoveToRect = ByMoveToRect::No);
353 // Should be called by derived implementations to notify on system color and
354 // theme changes.
355 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
357 void NotifyAPZOfDPIChange();
359 #ifdef ACCESSIBILITY
360 // Get the accessible for the window.
361 mozilla::a11y::LocalAccessible* GetRootAccessible();
362 #endif
364 // Return true if this is a simple widget (that is typically not worth
365 // accelerating)
366 bool IsSmallPopup() const;
368 PopupLevel GetPopupLevel() { return mPopupLevel; }
370 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
372 const SizeConstraints GetSizeConstraints() override;
373 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
375 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
377 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
378 const ScrollableLayerGuid& aGuid) override;
380 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
382 mozilla::layers::LayersId GetRootLayerTreeId() override;
385 * Use this when GetLayerManager() returns a BasicLayerManager
386 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
387 * layer manager to temporarily render into aTarget.
389 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
390 * |aRotation| is the "virtual rotation" to apply when rendering to
391 * the target. When |aRotation| is ROTATION_0,
392 * |aNaturalWidgetBounds| is not used.
394 class AutoLayerManagerSetup {
395 public:
396 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
397 BufferMode aDoubleBuffering);
398 ~AutoLayerManagerSetup();
400 private:
401 nsBaseWidget* mWidget;
402 mozilla::FallbackRenderer* mRenderer = nullptr;
404 friend class AutoLayerManagerSetup;
406 virtual bool ShouldUseOffMainThreadCompositing();
408 static nsIRollupListener* GetActiveRollupListener();
410 void Shutdown();
412 void QuitIME();
414 // These functions should be called at the start and end of a "live" widget
415 // resize (i.e. when the window contents are repainting during the resize,
416 // such as when the user drags a window border). It will suppress the
417 // displayport during the live resize to avoid unneccessary overpainting.
418 void NotifyLiveResizeStarted();
419 void NotifyLiveResizeStopped();
421 #if defined(MOZ_WIDGET_ANDROID)
422 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
423 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
424 const CSSToScreenScale& aZoom) override{};
425 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
426 bool aNeedsYFlip) override{};
427 #endif
429 virtual void LocalesChanged() {}
431 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
433 protected:
434 // These are methods for CompositorWidgetWrapper, and should only be
435 // accessed from that class. Derived widgets can choose which methods to
436 // implement, or none if supporting out-of-process compositing.
437 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
438 return true;
440 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
441 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
442 return nullptr;
444 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
445 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
446 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
447 return StartRemoteDrawing();
449 virtual void EndRemoteDrawing() {}
450 virtual void EndRemoteDrawingInRegion(
451 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
452 EndRemoteDrawing();
454 virtual void CleanupRemoteDrawing() {}
455 virtual void CleanupWindowEffects() {}
456 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
457 return true;
459 virtual uint32_t GetGLFrameBufferFormat();
460 virtual bool CompositorInitiallyPaused() { return false; }
462 protected:
463 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
464 nsIFile** aResult);
465 virtual void OnDestroy();
466 void BaseCreate(nsIWidget* aParent, InitData* aInitData);
468 virtual void ConfigureAPZCTreeManager();
469 virtual void ConfigureAPZControllerThread();
470 virtual already_AddRefed<GeckoContentController>
471 CreateRootContentController();
473 // Dispatch an event that has already been routed through APZ.
474 nsEventStatus ProcessUntransformedAPZEvent(
475 mozilla::WidgetInputEvent* aEvent,
476 const mozilla::layers::APZEventResult& aApzResult);
478 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
479 int32_t aNativeKeyCode,
480 uint32_t aModifierFlags,
481 const nsAString& aCharacters,
482 const nsAString& aUnmodifiedCharacters,
483 nsIObserver* aObserver) override {
484 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
485 return NS_ERROR_UNEXPECTED;
488 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
489 NativeMouseMessage aNativeMessage,
490 mozilla::MouseButton aButton,
491 nsIWidget::Modifiers aModifierFlags,
492 nsIObserver* aObserver) override {
493 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
494 return NS_ERROR_UNEXPECTED;
497 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
498 nsIObserver* aObserver) override {
499 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
500 return NS_ERROR_UNEXPECTED;
503 nsresult SynthesizeNativeMouseScrollEvent(
504 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
505 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
506 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
507 mozilla::widget::AutoObserverNotifier notifier(aObserver,
508 "mousescrollevent");
509 return NS_ERROR_UNEXPECTED;
512 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
513 TouchPointerState aPointerState,
514 LayoutDeviceIntPoint aPoint,
515 double aPointerPressure,
516 uint32_t aPointerOrientation,
517 nsIObserver* aObserver) override {
518 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
519 return NS_ERROR_UNEXPECTED;
522 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
523 float aScale,
524 LayoutDeviceIntPoint aPoint,
525 int32_t aModifierFlags) override {
526 MOZ_RELEASE_ASSERT(
527 false, "This method is not implemented on the current platform");
528 return NS_ERROR_UNEXPECTED;
531 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
532 TouchPointerState aPointerState,
533 LayoutDeviceIntPoint aPoint,
534 double aPressure, uint32_t aRotation,
535 int32_t aTiltX, int32_t aTiltY,
536 int32_t aButton,
537 nsIObserver* aObserver) override {
538 MOZ_RELEASE_ASSERT(
539 false, "This method is not implemented on the current platform");
540 return NS_ERROR_UNEXPECTED;
543 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
544 uint32_t aModifierFlags) override {
545 MOZ_RELEASE_ASSERT(
546 false, "This method is not implemented on the current platform");
547 return NS_ERROR_UNEXPECTED;
550 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
551 LayoutDeviceIntPoint aPoint,
552 double aDeltaX, double aDeltaY,
553 int32_t aModifierFlags,
554 nsIObserver* aObserver) override {
555 MOZ_RELEASE_ASSERT(
556 false, "This method is not implemented on the current platform");
557 return NS_ERROR_UNEXPECTED;
561 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
562 * has non-native input transaction. Otherwise, returns nullptr.
564 void* GetPseudoIMEContext();
566 protected:
567 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
568 return nsIWidget::CreateChildWindow();
571 WindowRenderer* CreateFallbackRenderer();
573 PopupType GetPopupType() const { return mPopupType; }
575 bool HasRemoteContent() const { return mHasRemoteContent; }
578 * Apply the current size constraints to the given size.
580 * @param aWidth width to constrain
581 * @param aHeight height to constrain
583 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
584 SizeConstraints c = GetSizeConstraints();
585 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
586 *aHeight =
587 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
590 CompositorBridgeChild* GetRemoteRenderer() override;
592 void ClearCachedWebrenderResources() override;
594 void ClearWebrenderAnimationResources() override;
596 bool SetNeedFastSnaphot() override;
599 * Notify the widget that this window is being used with OMTC.
601 virtual void WindowUsesOMTC() {}
602 virtual void RegisterTouchWindow() {}
604 mozilla::dom::Document* GetDocument() const;
606 void EnsureTextEventDispatcher();
608 // Notify the compositor that a device reset has occurred.
609 void OnRenderingDeviceReset();
611 bool UseAPZ();
613 bool AllowWebRenderForThisWindow();
616 * For widgets that support synthesizing native touch events, this function
617 * can be used to manage the current state of synthetic pointers. Each widget
618 * must maintain its own MultiTouchInput instance and pass it in as the state,
619 * along with the desired parameters for the changes. This function returns
620 * a new MultiTouchInput object that is ready to be dispatched.
622 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
623 mozilla::MultiTouchInput* aState, mozilla::TimeStamp aTimeStamp,
624 uint32_t aPointerId, TouchPointerState aPointerState,
625 LayoutDeviceIntPoint aPoint, double aPointerPressure,
626 uint32_t aPointerOrientation);
629 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
630 * or directly to gecko (if APZ is not enabled). This function must only
631 * be called from the main thread, and if APZ is enabled, that must also be
632 * the APZ controller thread.
634 void DispatchTouchInput(
635 mozilla::MultiTouchInput& aInput,
636 uint16_t aInputSource =
637 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
640 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
641 * or directly to gecko (if APZ is not enabled). This function must only
642 * be called from the main thread, and if APZ is enabled, that must also be
643 * the APZ controller thread.
645 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
646 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
648 static bool ConvertStatus(nsEventStatus aStatus) {
649 return aStatus == nsEventStatus_eConsumeNoDefault;
652 protected:
653 // Returns whether compositing should use an external surface size.
654 virtual bool UseExternalCompositingSurface() const { return false; }
657 * Starts the OMTC compositor destruction sequence.
659 * When this function returns, the compositor should not be
660 * able to access the opengl context anymore.
661 * It is safe to call it several times if platform implementations
662 * require the compositor to be destroyed before ~nsBaseWidget is
663 * reached (This is the case with gtk2 for instance).
665 virtual void DestroyCompositor();
666 void DestroyLayerManager();
667 void ReleaseContentController();
668 void RevokeTransactionIdAllocator();
670 void FreeShutdownObserver();
671 void FreeLocalesChangedObserver();
673 bool IsPIPWindow() const { return mIsPIPWindow; };
675 nsIWidgetListener* mWidgetListener;
676 nsIWidgetListener* mAttachedWidgetListener;
677 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
678 RefPtr<WindowRenderer> mWindowRenderer;
679 RefPtr<CompositorSession> mCompositorSession;
680 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
682 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
683 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
685 RefPtr<IAPZCTreeManager> mAPZC;
686 RefPtr<GeckoContentController> mRootContentController;
687 RefPtr<APZEventState> mAPZEventState;
688 RefPtr<WidgetShutdownObserver> mShutdownObserver;
689 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
690 RefPtr<TextEventDispatcher> mTextEventDispatcher;
691 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
692 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
693 Cursor mCursor;
694 bool mCustomCursorAllowed = true;
695 BorderStyle mBorderStyle;
696 LayoutDeviceIntRect mBounds;
697 bool mIsTiled;
698 PopupLevel mPopupLevel;
699 PopupType mPopupType;
700 SizeConstraints mSizeConstraints;
701 bool mHasRemoteContent;
703 struct FullscreenSavedState {
704 DesktopRect windowRect;
705 DesktopRect screenRect;
707 mozilla::Maybe<FullscreenSavedState> mSavedBounds;
709 bool mUpdateCursor;
710 bool mUseAttachedEvents;
711 bool mIMEHasFocus;
712 bool mIMEHasQuit;
713 bool mIsFullyOccluded;
714 bool mNeedFastSnaphot;
715 // This flag is only used when APZ is off. It indicates that the current pan
716 // gesture was processed as a swipe. Sometimes the swipe animation can finish
717 // before momentum events of the pan gesture have stopped firing, so this
718 // flag tells us that we shouldn't allow the remaining events to cause
719 // scrolling. It is reset to false once a new gesture starts (as indicated by
720 // a PANGESTURE_(MAY)START event).
721 bool mCurrentPanGestureBelongsToSwipe;
723 // It's PictureInPicture window.
724 bool mIsPIPWindow : 1;
726 struct InitialZoomConstraints {
727 InitialZoomConstraints(const uint32_t& aPresShellID,
728 const ScrollableLayerGuid::ViewID& aViewID,
729 const ZoomConstraints& aConstraints)
730 : mPresShellID(aPresShellID),
731 mViewID(aViewID),
732 mConstraints(aConstraints) {}
734 uint32_t mPresShellID;
735 ScrollableLayerGuid::ViewID mViewID;
736 ZoomConstraints mConstraints;
739 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
741 // This points to the resize listeners who have been notified that a live
742 // resize is in progress. This should always be empty when a live-resize is
743 // not in progress.
744 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
746 #ifdef DEBUG
747 protected:
748 static nsAutoString debug_GuiEventToString(
749 mozilla::WidgetGUIEvent* aGuiEvent);
751 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
752 const LayoutDeviceIntRect* aRect,
753 const char* aWidgetName, int32_t aWindowID);
755 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
756 mozilla::WidgetGUIEvent* aGuiEvent,
757 const char* aWidgetName, int32_t aWindowID);
759 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
760 const nsIntRegion& aPaintEvent,
761 const char* aWidgetName, int32_t aWindowID);
763 static bool debug_GetCachedBoolPref(const char* aPrefName);
764 #endif
766 private:
767 already_AddRefed<mozilla::layers::WebRenderLayerManager>
768 CreateCompositorSession(int aWidth, int aHeight,
769 mozilla::layers::CompositorOptions* aOptionsOut);
772 #endif // nsBaseWidget_h__