Bug 1822331 [wpt PR 38990] - [@scope] Enable implicit :scope and relative selectors...
[gecko.git] / widget / nsBaseWidget.h
blob4de3521512419fb6e99592a6080e04d439ec1a4e
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(bool aAllowSlop, int32_t* aX, int32_t* aY) 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 void SetDrawsInTitlebar(bool aState) override {}
274 bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
275 void FreeNativeData(void* data, uint32_t aDataType) override {}
276 nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override {
277 return NS_ERROR_NOT_IMPLEMENTED;
279 nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override {
280 return NS_ERROR_NOT_IMPLEMENTED;
282 nsresult NotifyIME(const IMENotification& aIMENotification) final;
283 [[nodiscard]] nsresult AttachNativeKeyEvent(
284 mozilla::WidgetKeyboardEvent& aEvent) override {
285 return NS_ERROR_NOT_IMPLEMENTED;
287 bool ComputeShouldAccelerate();
288 virtual bool WidgetTypeSupportsAcceleration() { return true; }
289 [[nodiscard]] nsresult OnDefaultButtonLoaded(
290 const LayoutDeviceIntRect& aButtonRect) override {
291 return NS_ERROR_NOT_IMPLEMENTED;
293 already_AddRefed<nsIWidget> CreateChild(
294 const LayoutDeviceIntRect& aRect, InitData* aInitData = nullptr,
295 bool aForceUseIWidgetParent = false) override;
296 void AttachViewToTopLevel(bool aUseAttachedEvents) override;
297 nsIWidgetListener* GetAttachedWidgetListener() const override;
298 void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
299 nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
300 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener*) override;
301 NativeIMEContext GetNativeIMEContext() override;
302 TextEventDispatcher* GetTextEventDispatcher() final;
303 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
304 void ZoomToRect(const uint32_t& aPresShellId,
305 const ScrollableLayerGuid::ViewID& aViewId,
306 const CSSRect& aRect, const uint32_t& aFlags) override;
308 // Dispatch an event that must be first be routed through APZ.
309 ContentAndAPZEventStatus DispatchInputEvent(
310 mozilla::WidgetInputEvent* aEvent) override;
311 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
313 bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event) override;
315 void SetConfirmedTargetAPZC(
316 uint64_t aInputBlockId,
317 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
319 void UpdateZoomConstraints(
320 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
321 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
323 bool AsyncPanZoomEnabled() const override;
325 void SwipeFinished() override;
326 void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
327 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
328 uint32_t aAllowedDirections,
329 uint64_t aInputBlockId);
330 struct SwipeInfo {
331 bool wantsSwipe;
332 uint32_t allowedDirections;
334 SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
335 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
336 // whether |aPanInput| event was used for SwipeTracker or not.
337 mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
338 const mozilla::PanGestureInput& aPanInput,
339 const mozilla::layers::APZEventResult& aApzResult);
341 // Returns true if |aPanInput| event was used for SwipeTracker, false
342 // otherwise.
343 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput);
345 void NotifyWindowDestroyed();
346 void NotifySizeMoveDone();
348 using ByMoveToRect = nsIWidgetListener::ByMoveToRect;
349 void NotifyWindowMoved(int32_t aX, int32_t aY,
350 ByMoveToRect = ByMoveToRect::No);
352 void SetNativeData(uint32_t aDataType, uintptr_t aVal) override {}
354 // Should be called by derived implementations to notify on system color and
355 // theme changes.
356 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
358 #ifdef ACCESSIBILITY
359 // Get the accessible for the window.
360 mozilla::a11y::LocalAccessible* GetRootAccessible();
361 #endif
363 // Return true if this is a simple widget (that is typically not worth
364 // accelerating)
365 bool IsSmallPopup() const;
367 PopupLevel GetPopupLevel() { return mPopupLevel; }
369 // return true if this is a popup widget with a native titlebar
370 bool IsPopupWithTitleBar() const {
371 return (mWindowType == WindowType::Popup &&
372 mBorderStyle != BorderStyle::Default &&
373 mBorderStyle & BorderStyle::Title);
376 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
378 const SizeConstraints GetSizeConstraints() override;
379 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
381 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
383 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
384 const ScrollableLayerGuid& aGuid) override;
386 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
388 mozilla::layers::LayersId GetRootLayerTreeId() 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 {
401 public:
402 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
403 BufferMode aDoubleBuffering);
404 ~AutoLayerManagerSetup();
406 private:
407 nsBaseWidget* mWidget;
408 mozilla::FallbackRenderer* mRenderer = nullptr;
410 friend class AutoLayerManagerSetup;
412 virtual bool ShouldUseOffMainThreadCompositing();
414 static nsIRollupListener* GetActiveRollupListener();
416 void Shutdown();
418 void QuitIME();
420 // These functions should be called at the start and end of a "live" widget
421 // resize (i.e. when the window contents are repainting during the resize,
422 // such as when the user drags a window border). It will suppress the
423 // displayport during the live resize to avoid unneccessary overpainting.
424 void NotifyLiveResizeStarted();
425 void NotifyLiveResizeStopped();
427 #if defined(MOZ_WIDGET_ANDROID)
428 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
429 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
430 const CSSToScreenScale& aZoom) override{};
431 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
432 bool aNeedsYFlip) override{};
433 #endif
435 virtual void LocalesChanged() {}
437 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
439 protected:
440 // These are methods for CompositorWidgetWrapper, and should only be
441 // accessed from that class. Derived widgets can choose which methods to
442 // implement, or none if supporting out-of-process compositing.
443 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
444 return true;
446 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
447 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
448 return nullptr;
450 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
451 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
452 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
453 return StartRemoteDrawing();
455 virtual void EndRemoteDrawing() {}
456 virtual void EndRemoteDrawingInRegion(
457 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
458 EndRemoteDrawing();
460 virtual void CleanupRemoteDrawing() {}
461 virtual void CleanupWindowEffects() {}
462 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
463 return true;
465 virtual uint32_t GetGLFrameBufferFormat();
466 virtual bool CompositorInitiallyPaused() { return false; }
468 protected:
469 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
470 nsIFile** aResult);
471 virtual void OnDestroy();
472 void BaseCreate(nsIWidget* aParent, InitData* aInitData);
474 virtual void ConfigureAPZCTreeManager();
475 virtual void ConfigureAPZControllerThread();
476 virtual already_AddRefed<GeckoContentController>
477 CreateRootContentController();
479 // Dispatch an event that has already been routed through APZ.
480 nsEventStatus ProcessUntransformedAPZEvent(
481 mozilla::WidgetInputEvent* aEvent,
482 const mozilla::layers::APZEventResult& aApzResult);
484 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
485 int32_t aNativeKeyCode,
486 uint32_t aModifierFlags,
487 const nsAString& aCharacters,
488 const nsAString& aUnmodifiedCharacters,
489 nsIObserver* aObserver) override {
490 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
491 return NS_ERROR_UNEXPECTED;
494 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
495 NativeMouseMessage aNativeMessage,
496 mozilla::MouseButton aButton,
497 nsIWidget::Modifiers aModifierFlags,
498 nsIObserver* aObserver) override {
499 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
500 return NS_ERROR_UNEXPECTED;
503 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
504 nsIObserver* aObserver) override {
505 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
506 return NS_ERROR_UNEXPECTED;
509 nsresult SynthesizeNativeMouseScrollEvent(
510 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
511 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
512 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
513 mozilla::widget::AutoObserverNotifier notifier(aObserver,
514 "mousescrollevent");
515 return NS_ERROR_UNEXPECTED;
518 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
519 TouchPointerState aPointerState,
520 LayoutDeviceIntPoint aPoint,
521 double aPointerPressure,
522 uint32_t aPointerOrientation,
523 nsIObserver* aObserver) override {
524 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
525 return NS_ERROR_UNEXPECTED;
528 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
529 float aScale,
530 LayoutDeviceIntPoint aPoint,
531 int32_t aModifierFlags) override {
532 MOZ_RELEASE_ASSERT(
533 false, "This method is not implemented on the current platform");
534 return NS_ERROR_UNEXPECTED;
537 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
538 TouchPointerState aPointerState,
539 LayoutDeviceIntPoint aPoint,
540 double aPressure, uint32_t aRotation,
541 int32_t aTiltX, int32_t aTiltY,
542 int32_t aButton,
543 nsIObserver* aObserver) override {
544 MOZ_RELEASE_ASSERT(
545 false, "This method is not implemented on the current platform");
546 return NS_ERROR_UNEXPECTED;
549 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
550 uint32_t aModifierFlags) override {
551 MOZ_RELEASE_ASSERT(
552 false, "This method is not implemented on the current platform");
553 return NS_ERROR_UNEXPECTED;
556 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
557 LayoutDeviceIntPoint aPoint,
558 double aDeltaX, double aDeltaY,
559 int32_t aModifierFlags,
560 nsIObserver* aObserver) override {
561 MOZ_RELEASE_ASSERT(
562 false, "This method is not implemented on the current platform");
563 return NS_ERROR_UNEXPECTED;
567 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
568 * has non-native input transaction. Otherwise, returns nullptr.
570 void* GetPseudoIMEContext();
572 protected:
573 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
574 return nsIWidget::CreateChildWindow();
577 WindowRenderer* CreateFallbackRenderer();
579 PopupType GetPopupType() const { return mPopupType; }
581 bool HasRemoteContent() const { return mHasRemoteContent; }
584 * Apply the current size constraints to the given size.
586 * @param aWidth width to constrain
587 * @param aHeight height to constrain
589 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
590 SizeConstraints c = GetSizeConstraints();
591 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
592 *aHeight =
593 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
596 CompositorBridgeChild* GetRemoteRenderer() override;
598 void ClearCachedWebrenderResources() override;
600 void ClearWebrenderAnimationResources() override;
602 bool SetNeedFastSnaphot() override;
605 * Notify the widget that this window is being used with OMTC.
607 virtual void WindowUsesOMTC() {}
608 virtual void RegisterTouchWindow() {}
610 mozilla::dom::Document* GetDocument() const;
612 void EnsureTextEventDispatcher();
614 // Notify the compositor that a device reset has occurred.
615 void OnRenderingDeviceReset();
617 bool UseAPZ();
619 bool AllowWebRenderForThisWindow();
622 * For widgets that support synthesizing native touch events, this function
623 * can be used to manage the current state of synthetic pointers. Each widget
624 * must maintain its own MultiTouchInput instance and pass it in as the state,
625 * along with the desired parameters for the changes. This function returns
626 * a new MultiTouchInput object that is ready to be dispatched.
628 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
629 mozilla::MultiTouchInput* aState, mozilla::TimeStamp aTimeStamp,
630 uint32_t aPointerId, TouchPointerState aPointerState,
631 LayoutDeviceIntPoint aPoint, double aPointerPressure,
632 uint32_t aPointerOrientation);
635 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
636 * or directly to gecko (if APZ is not enabled). This function must only
637 * be called from the main thread, and if APZ is enabled, that must also be
638 * the APZ controller thread.
640 void DispatchTouchInput(
641 mozilla::MultiTouchInput& aInput,
642 uint16_t aInputSource =
643 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
646 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
647 * or directly to gecko (if APZ is not enabled). This function must only
648 * be called from the main thread, and if APZ is enabled, that must also be
649 * the APZ controller thread.
651 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
652 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
654 static bool ConvertStatus(nsEventStatus aStatus) {
655 return aStatus == nsEventStatus_eConsumeNoDefault;
658 protected:
659 // Returns whether compositing should use an external surface size.
660 virtual bool UseExternalCompositingSurface() const { return false; }
663 * Starts the OMTC compositor destruction sequence.
665 * When this function returns, the compositor should not be
666 * able to access the opengl context anymore.
667 * It is safe to call it several times if platform implementations
668 * require the compositor to be destroyed before ~nsBaseWidget is
669 * reached (This is the case with gtk2 for instance).
671 virtual void DestroyCompositor();
672 void DestroyLayerManager();
673 void ReleaseContentController();
674 void RevokeTransactionIdAllocator();
676 void FreeShutdownObserver();
677 void FreeLocalesChangedObserver();
679 nsIWidgetListener* mWidgetListener;
680 nsIWidgetListener* mAttachedWidgetListener;
681 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
682 RefPtr<WindowRenderer> mWindowRenderer;
683 RefPtr<CompositorSession> mCompositorSession;
684 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
686 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
687 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
689 RefPtr<IAPZCTreeManager> mAPZC;
690 RefPtr<GeckoContentController> mRootContentController;
691 RefPtr<APZEventState> mAPZEventState;
692 RefPtr<WidgetShutdownObserver> mShutdownObserver;
693 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
694 RefPtr<TextEventDispatcher> mTextEventDispatcher;
695 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
696 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
697 Cursor mCursor;
698 BorderStyle mBorderStyle;
699 LayoutDeviceIntRect mBounds;
700 bool mIsTiled;
701 PopupLevel mPopupLevel;
702 PopupType mPopupType;
703 SizeConstraints mSizeConstraints;
704 bool mHasRemoteContent;
706 struct FullscreenSavedState {
707 DesktopRect windowRect;
708 DesktopRect screenRect;
710 mozilla::Maybe<FullscreenSavedState> mSavedBounds;
712 bool mUpdateCursor;
713 bool mUseAttachedEvents;
714 bool mIMEHasFocus;
715 bool mIMEHasQuit;
716 bool mIsFullyOccluded;
717 bool mNeedFastSnaphot;
718 // This flag is only used when APZ is off. It indicates that the current pan
719 // gesture was processed as a swipe. Sometimes the swipe animation can finish
720 // before momentum events of the pan gesture have stopped firing, so this
721 // flag tells us that we shouldn't allow the remaining events to cause
722 // scrolling. It is reset to false once a new gesture starts (as indicated by
723 // a PANGESTURE_(MAY)START event).
724 bool mCurrentPanGestureBelongsToSwipe;
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__