Bug 1760380 [wpt PR 33241] - Update wpt metadata, a=testonly
[gecko.git] / widget / nsBaseWidget.h
blob9671e9c71d83c5be225c2f44645cc54518e7233e
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(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 SetSizeMode(nsSizeMode aMode) override;
186 nsSizeMode SizeMode() override { return mSizeMode; }
187 void GetWorkspaceID(nsAString& workspaceID) override;
188 void MoveToWorkspace(const nsAString& workspaceID) override;
189 bool IsTiled() const override { return mIsTiled; }
191 bool IsFullyOccluded() const override { return mIsFullyOccluded; }
193 void SetCursor(const Cursor&) override;
194 void ClearCachedCursor() final {
195 mCursor = {};
196 mUpdateCursor = true;
198 void SetTransparencyMode(nsTransparencyMode aMode) override;
199 nsTransparencyMode GetTransparencyMode() override;
200 void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle) override {}
201 void SetShowsToolbarButton(bool aShow) override {}
202 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) override {}
203 void SetWindowAnimationType(WindowAnimationType aType) override {}
204 void HideWindowChrome(bool aShouldHide) override {}
205 bool PrepareForFullscreenTransition(nsISupports** aData) override {
206 return false;
208 void PerformFullscreenTransition(FullscreenTransitionStage aStage,
209 uint16_t aDuration, nsISupports* aData,
210 nsIRunnable* aCallback) override;
211 void CleanupFullscreenTransition() override {}
212 already_AddRefed<nsIScreen> GetWidgetScreen() override;
213 nsresult MakeFullScreen(bool aFullScreen) override;
214 void InfallibleMakeFullScreen(bool aFullScreen);
216 WindowRenderer* GetWindowRenderer() override;
218 // A remote compositor session tied to this window has been lost and IPC
219 // messages will no longer work. The widget must clean up any lingering
220 // resources and possibly schedule another paint.
222 // A reference to the session object is held until this function has
223 // returned.
224 virtual void NotifyCompositorSessionLost(
225 mozilla::layers::CompositorSession* aSession);
227 already_AddRefed<mozilla::CompositorVsyncDispatcher>
228 GetCompositorVsyncDispatcher();
229 virtual void CreateCompositorVsyncDispatcher();
230 virtual void CreateCompositor();
231 virtual void CreateCompositor(int aWidth, int aHeight);
232 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate*) {}
233 void PrepareWindowEffects() override {}
234 void UpdateThemeGeometries(
235 const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
236 void SetModal(bool aModal) override {}
237 uint32_t GetMaxTouchPoints() const override;
238 void SetWindowClass(const nsAString& xulWinType) 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 <= eWindowType_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(bool aAllowSlop, int32_t* aX, int32_t* aY) 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(LayoutDeviceIntMargin& aMargins) 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 void SetDrawsInTitlebar(bool aState) override {}
276 bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
277 void FreeNativeData(void* data, uint32_t aDataType) override {}
278 [[nodiscard]] nsresult BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
279 int32_t aHorizontal,
280 int32_t aVertical) override {
281 return NS_ERROR_NOT_IMPLEMENTED;
283 nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override {
284 return NS_ERROR_NOT_IMPLEMENTED;
286 nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override {
287 return NS_ERROR_NOT_IMPLEMENTED;
289 nsresult NotifyIME(const IMENotification& aIMENotification) final;
290 [[nodiscard]] nsresult AttachNativeKeyEvent(
291 mozilla::WidgetKeyboardEvent& aEvent) override {
292 return NS_ERROR_NOT_IMPLEMENTED;
294 bool ComputeShouldAccelerate();
295 virtual bool WidgetTypeSupportsAcceleration() { return true; }
296 [[nodiscard]] nsresult OnDefaultButtonLoaded(
297 const LayoutDeviceIntRect& aButtonRect) override {
298 return NS_ERROR_NOT_IMPLEMENTED;
300 already_AddRefed<nsIWidget> CreateChild(
301 const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData = nullptr,
302 bool aForceUseIWidgetParent = false) override;
303 void AttachViewToTopLevel(bool aUseAttachedEvents) override;
304 nsIWidgetListener* GetAttachedWidgetListener() const override;
305 void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
306 nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
307 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener*) override;
308 NativeIMEContext GetNativeIMEContext() override;
309 TextEventDispatcher* GetTextEventDispatcher() final;
310 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
311 void ZoomToRect(const uint32_t& aPresShellId,
312 const ScrollableLayerGuid::ViewID& aViewId,
313 const CSSRect& aRect, const uint32_t& aFlags) override;
315 // Dispatch an event that must be first be routed through APZ.
316 ContentAndAPZEventStatus DispatchInputEvent(
317 mozilla::WidgetInputEvent* aEvent) override;
318 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
320 bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event) override;
322 void SetConfirmedTargetAPZC(
323 uint64_t aInputBlockId,
324 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
326 void UpdateZoomConstraints(
327 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
328 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
330 bool AsyncPanZoomEnabled() const override;
332 void SwipeFinished() override;
333 void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
334 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
335 uint32_t aAllowedDirections);
336 struct SwipeInfo {
337 bool wantsSwipe;
338 uint32_t allowedDirections;
340 SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
341 enum class CanTriggerSwipe : bool {
342 No = false,
343 Yes = true,
345 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
346 // whether |aPanInput| event was used for SwipeTracker or not.
347 mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
348 const mozilla::PanGestureInput& aPanInput,
349 const mozilla::layers::APZEventResult& aApzResult,
350 CanTriggerSwipe aCanTriggerSwipe);
352 // Returns true if |aPanInput| event was used for SwipeTracker, false
353 // otherwise.
354 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput,
355 CanTriggerSwipe aCanTriggerSwipe);
357 void NotifyWindowDestroyed();
358 void NotifySizeMoveDone();
359 void NotifyWindowMoved(int32_t aX, int32_t aY);
361 void SetNativeData(uint32_t aDataType, uintptr_t aVal) override {}
363 // Should be called by derived implementations to notify on system color and
364 // theme changes.
365 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
366 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings);
368 #ifdef ACCESSIBILITY
369 // Get the accessible for the window.
370 mozilla::a11y::LocalAccessible* GetRootAccessible();
371 #endif
373 // Return true if this is a simple widget (that is typically not worth
374 // accelerating)
375 bool IsSmallPopup() const;
377 nsPopupLevel PopupLevel() { return mPopupLevel; }
379 LayoutDeviceIntSize ClientToWindowSize(
380 const LayoutDeviceIntSize& aClientSize) override {
381 return aClientSize;
384 // return true if this is a popup widget with a native titlebar
385 bool IsPopupWithTitleBar() const {
386 return (mWindowType == eWindowType_popup &&
387 mBorderStyle != eBorderStyle_default &&
388 mBorderStyle & eBorderStyle_title);
391 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
393 const SizeConstraints GetSizeConstraints() override;
394 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
396 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
398 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
399 const ScrollableLayerGuid& aGuid) override;
401 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
403 mozilla::layers::LayersId GetRootLayerTreeId() override;
406 * Use this when GetLayerManager() returns a BasicLayerManager
407 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
408 * layer manager to temporarily render into aTarget.
410 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
411 * |aRotation| is the "virtual rotation" to apply when rendering to
412 * the target. When |aRotation| is ROTATION_0,
413 * |aNaturalWidgetBounds| is not used.
415 class AutoLayerManagerSetup {
416 public:
417 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
418 BufferMode aDoubleBuffering);
419 ~AutoLayerManagerSetup();
421 private:
422 nsBaseWidget* mWidget;
423 mozilla::FallbackRenderer* mRenderer = nullptr;
425 friend class AutoLayerManagerSetup;
427 virtual bool ShouldUseOffMainThreadCompositing();
429 static nsIRollupListener* GetActiveRollupListener();
431 void Shutdown();
433 void QuitIME();
435 // These functions should be called at the start and end of a "live" widget
436 // resize (i.e. when the window contents are repainting during the resize,
437 // such as when the user drags a window border). It will suppress the
438 // displayport during the live resize to avoid unneccessary overpainting.
439 void NotifyLiveResizeStarted();
440 void NotifyLiveResizeStopped();
442 #if defined(MOZ_WIDGET_ANDROID)
443 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
444 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
445 const CSSToScreenScale& aZoom) override{};
446 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
447 bool aNeedsYFlip) override{};
448 #endif
450 virtual void LocalesChanged() {}
452 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
454 protected:
455 // These are methods for CompositorWidgetWrapper, and should only be
456 // accessed from that class. Derived widgets can choose which methods to
457 // implement, or none if supporting out-of-process compositing.
458 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
459 return true;
461 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
462 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
463 return nullptr;
465 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
466 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
467 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
468 return StartRemoteDrawing();
470 virtual void EndRemoteDrawing() {}
471 virtual void EndRemoteDrawingInRegion(
472 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
473 EndRemoteDrawing();
475 virtual void CleanupRemoteDrawing() {}
476 virtual void CleanupWindowEffects() {}
477 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
478 return true;
480 virtual uint32_t GetGLFrameBufferFormat();
481 virtual bool CompositorInitiallyPaused() { return false; }
483 protected:
484 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
485 nsIFile** aResult);
486 virtual void OnDestroy();
487 void BaseCreate(nsIWidget* aParent, nsWidgetInitData* aInitData);
489 virtual void ConfigureAPZCTreeManager();
490 virtual void ConfigureAPZControllerThread();
491 virtual already_AddRefed<GeckoContentController>
492 CreateRootContentController();
494 // Dispatch an event that has already been routed through APZ.
495 nsEventStatus ProcessUntransformedAPZEvent(
496 mozilla::WidgetInputEvent* aEvent,
497 const mozilla::layers::APZEventResult& aApzResult);
499 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
500 int32_t aNativeKeyCode,
501 uint32_t aModifierFlags,
502 const nsAString& aCharacters,
503 const nsAString& aUnmodifiedCharacters,
504 nsIObserver* aObserver) override {
505 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
506 return NS_ERROR_UNEXPECTED;
509 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
510 NativeMouseMessage aNativeMessage,
511 mozilla::MouseButton aButton,
512 nsIWidget::Modifiers aModifierFlags,
513 nsIObserver* aObserver) override {
514 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
515 return NS_ERROR_UNEXPECTED;
518 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
519 nsIObserver* aObserver) override {
520 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
521 return NS_ERROR_UNEXPECTED;
524 nsresult SynthesizeNativeMouseScrollEvent(
525 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
526 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
527 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
528 mozilla::widget::AutoObserverNotifier notifier(aObserver,
529 "mousescrollevent");
530 return NS_ERROR_UNEXPECTED;
533 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
534 TouchPointerState aPointerState,
535 LayoutDeviceIntPoint aPoint,
536 double aPointerPressure,
537 uint32_t aPointerOrientation,
538 nsIObserver* aObserver) override {
539 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
540 return NS_ERROR_UNEXPECTED;
543 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
544 float aScale,
545 LayoutDeviceIntPoint aPoint,
546 int32_t aModifierFlags) override {
547 MOZ_RELEASE_ASSERT(
548 false, "This method is not implemented on the current platform");
549 return NS_ERROR_UNEXPECTED;
552 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
553 TouchPointerState aPointerState,
554 LayoutDeviceIntPoint aPoint,
555 double aPressure, uint32_t aRotation,
556 int32_t aTiltX, int32_t aTiltY,
557 int32_t aButton,
558 nsIObserver* aObserver) override {
559 MOZ_RELEASE_ASSERT(
560 false, "This method is not implemented on the current platform");
561 return NS_ERROR_UNEXPECTED;
564 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
565 uint32_t aModifierFlags) override {
566 MOZ_RELEASE_ASSERT(
567 false, "This method is not implemented on the current platform");
568 return NS_ERROR_UNEXPECTED;
571 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
572 LayoutDeviceIntPoint aPoint,
573 double aDeltaX, double aDeltaY,
574 int32_t aModifierFlags) override {
575 MOZ_RELEASE_ASSERT(
576 false, "This method is not implemented on the current platform");
577 return NS_ERROR_UNEXPECTED;
581 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
582 * has non-native input transaction. Otherwise, returns nullptr.
584 void* GetPseudoIMEContext();
586 protected:
587 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
588 return nsIWidget::CreateChildWindow();
591 WindowRenderer* CreateFallbackRenderer();
593 nsPopupType PopupType() const { return mPopupType; }
595 bool HasRemoteContent() const { return mHasRemoteContent; }
597 void NotifyRollupGeometryChange() {
598 // XULPopupManager isn't interested in this notification, so only
599 // send it if gRollupListener is set.
600 if (gRollupListener) {
601 gRollupListener->NotifyGeometryChange();
606 * Apply the current size constraints to the given size.
608 * @param aWidth width to constrain
609 * @param aHeight height to constrain
611 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
612 SizeConstraints c = GetSizeConstraints();
613 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
614 *aHeight =
615 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
618 CompositorBridgeChild* GetRemoteRenderer() override;
620 void ClearCachedWebrenderResources() override;
623 * Notify the widget that this window is being used with OMTC.
625 virtual void WindowUsesOMTC() {}
626 virtual void RegisterTouchWindow() {}
628 mozilla::dom::Document* GetDocument() const;
630 void EnsureTextEventDispatcher();
632 // Notify the compositor that a device reset has occurred.
633 void OnRenderingDeviceReset();
635 bool UseAPZ();
637 bool AllowWebRenderForThisWindow();
640 * For widgets that support synthesizing native touch events, this function
641 * can be used to manage the current state of synthetic pointers. Each widget
642 * must maintain its own MultiTouchInput instance and pass it in as the state,
643 * along with the desired parameters for the changes. This function returns
644 * a new MultiTouchInput object that is ready to be dispatched.
646 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
647 mozilla::MultiTouchInput* aState, uint32_t aTime,
648 mozilla::TimeStamp aTimeStamp, uint32_t aPointerId,
649 TouchPointerState aPointerState, LayoutDeviceIntPoint aPoint,
650 double aPointerPressure, uint32_t aPointerOrientation);
653 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
654 * or directly to gecko (if APZ is not enabled). This function must only
655 * be called from the main thread, and if APZ is enabled, that must also be
656 * the APZ controller thread.
658 void DispatchTouchInput(
659 mozilla::MultiTouchInput& aInput,
660 uint16_t aInputSource =
661 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
664 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
665 * or directly to gecko (if APZ is not enabled). This function must only
666 * be called from the main thread, and if APZ is enabled, that must also be
667 * the APZ controller thread.
669 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
670 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
672 static bool ConvertStatus(nsEventStatus aStatus) {
673 return aStatus == nsEventStatus_eConsumeNoDefault;
676 protected:
677 // Returns whether compositing should use an external surface size.
678 virtual bool UseExternalCompositingSurface() const { return false; }
681 * Starts the OMTC compositor destruction sequence.
683 * When this function returns, the compositor should not be
684 * able to access the opengl context anymore.
685 * It is safe to call it several times if platform implementations
686 * require the compositor to be destroyed before ~nsBaseWidget is
687 * reached (This is the case with gtk2 for instance).
689 virtual void DestroyCompositor();
690 void DestroyLayerManager();
691 void ReleaseContentController();
692 void RevokeTransactionIdAllocator();
694 void FreeShutdownObserver();
695 void FreeLocalesChangedObserver();
697 nsIWidgetListener* mWidgetListener;
698 nsIWidgetListener* mAttachedWidgetListener;
699 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
700 RefPtr<WindowRenderer> mWindowRenderer;
701 RefPtr<CompositorSession> mCompositorSession;
702 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
704 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
705 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
707 RefPtr<IAPZCTreeManager> mAPZC;
708 RefPtr<GeckoContentController> mRootContentController;
709 RefPtr<APZEventState> mAPZEventState;
710 RefPtr<WidgetShutdownObserver> mShutdownObserver;
711 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
712 RefPtr<TextEventDispatcher> mTextEventDispatcher;
713 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
714 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
715 Cursor mCursor;
716 nsBorderStyle mBorderStyle;
717 LayoutDeviceIntRect mBounds;
718 LayoutDeviceIntRect* mOriginalBounds;
719 nsSizeMode mSizeMode;
720 bool mIsTiled;
721 nsPopupLevel mPopupLevel;
722 nsPopupType mPopupType;
723 SizeConstraints mSizeConstraints;
724 bool mHasRemoteContent;
725 bool mFissionWindow;
727 bool mUpdateCursor;
728 bool mUseAttachedEvents;
729 bool mIMEHasFocus;
730 bool mIMEHasQuit;
731 bool mIsFullyOccluded;
732 // This flag is only used when APZ is off. It indicates that the current pan
733 // gesture was processed as a swipe. Sometimes the swipe animation can finish
734 // before momentum events of the pan gesture have stopped firing, so this
735 // flag tells us that we shouldn't allow the remaining events to cause
736 // scrolling. It is reset to false once a new gesture starts (as indicated by
737 // a PANGESTURE_(MAY)START event).
738 bool mCurrentPanGestureBelongsToSwipe;
740 static nsIRollupListener* gRollupListener;
742 struct InitialZoomConstraints {
743 InitialZoomConstraints(const uint32_t& aPresShellID,
744 const ScrollableLayerGuid::ViewID& aViewID,
745 const ZoomConstraints& aConstraints)
746 : mPresShellID(aPresShellID),
747 mViewID(aViewID),
748 mConstraints(aConstraints) {}
750 uint32_t mPresShellID;
751 ScrollableLayerGuid::ViewID mViewID;
752 ZoomConstraints mConstraints;
755 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
757 // This points to the resize listeners who have been notified that a live
758 // resize is in progress. This should always be empty when a live-resize is
759 // not in progress.
760 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
762 #ifdef DEBUG
763 protected:
764 static nsAutoString debug_GuiEventToString(
765 mozilla::WidgetGUIEvent* aGuiEvent);
767 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
768 const LayoutDeviceIntRect* aRect,
769 const char* aWidgetName, int32_t aWindowID);
771 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
772 mozilla::WidgetGUIEvent* aGuiEvent,
773 const char* aWidgetName, int32_t aWindowID);
775 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
776 const nsIntRegion& aPaintEvent,
777 const char* aWidgetName, int32_t aWindowID);
779 static bool debug_GetCachedBoolPref(const char* aPrefName);
780 #endif
782 private:
783 already_AddRefed<mozilla::layers::WebRenderLayerManager>
784 CreateCompositorSession(int aWidth, int aHeight,
785 mozilla::layers::CompositorOptions* aOptionsOut);
788 #endif // nsBaseWidget_h__