Bug 1837620 - Part 7: Keep JitScripts in a linked list to avoid iterating all BaseScr...
[gecko.git] / widget / nsBaseWidget.h
blob4b7c963e9376848689c81c15b127414ca8cb6d5a
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 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 // Should be called by derived implementations to notify on system color and
353 // theme changes.
354 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
356 #ifdef ACCESSIBILITY
357 // Get the accessible for the window.
358 mozilla::a11y::LocalAccessible* GetRootAccessible();
359 #endif
361 // Return true if this is a simple widget (that is typically not worth
362 // accelerating)
363 bool IsSmallPopup() const;
365 PopupLevel GetPopupLevel() { return mPopupLevel; }
367 // return true if this is a popup widget with a native titlebar
368 bool IsPopupWithTitleBar() const {
369 return (mWindowType == WindowType::Popup &&
370 mBorderStyle != BorderStyle::Default &&
371 mBorderStyle & BorderStyle::Title);
374 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
376 const SizeConstraints GetSizeConstraints() override;
377 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
379 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
381 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
382 const ScrollableLayerGuid& aGuid) override;
384 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
386 mozilla::layers::LayersId GetRootLayerTreeId() override;
389 * Use this when GetLayerManager() returns a BasicLayerManager
390 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
391 * layer manager to temporarily render into aTarget.
393 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
394 * |aRotation| is the "virtual rotation" to apply when rendering to
395 * the target. When |aRotation| is ROTATION_0,
396 * |aNaturalWidgetBounds| is not used.
398 class AutoLayerManagerSetup {
399 public:
400 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
401 BufferMode aDoubleBuffering);
402 ~AutoLayerManagerSetup();
404 private:
405 nsBaseWidget* mWidget;
406 mozilla::FallbackRenderer* mRenderer = nullptr;
408 friend class AutoLayerManagerSetup;
410 virtual bool ShouldUseOffMainThreadCompositing();
412 static nsIRollupListener* GetActiveRollupListener();
414 void Shutdown();
416 void QuitIME();
418 // These functions should be called at the start and end of a "live" widget
419 // resize (i.e. when the window contents are repainting during the resize,
420 // such as when the user drags a window border). It will suppress the
421 // displayport during the live resize to avoid unneccessary overpainting.
422 void NotifyLiveResizeStarted();
423 void NotifyLiveResizeStopped();
425 #if defined(MOZ_WIDGET_ANDROID)
426 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
427 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
428 const CSSToScreenScale& aZoom) override{};
429 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
430 bool aNeedsYFlip) override{};
431 #endif
433 virtual void LocalesChanged() {}
435 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
437 protected:
438 // These are methods for CompositorWidgetWrapper, and should only be
439 // accessed from that class. Derived widgets can choose which methods to
440 // implement, or none if supporting out-of-process compositing.
441 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
442 return true;
444 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
445 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
446 return nullptr;
448 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
449 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
450 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
451 return StartRemoteDrawing();
453 virtual void EndRemoteDrawing() {}
454 virtual void EndRemoteDrawingInRegion(
455 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
456 EndRemoteDrawing();
458 virtual void CleanupRemoteDrawing() {}
459 virtual void CleanupWindowEffects() {}
460 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
461 return true;
463 virtual uint32_t GetGLFrameBufferFormat();
464 virtual bool CompositorInitiallyPaused() { return false; }
466 protected:
467 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
468 nsIFile** aResult);
469 virtual void OnDestroy();
470 void BaseCreate(nsIWidget* aParent, InitData* aInitData);
472 virtual void ConfigureAPZCTreeManager();
473 virtual void ConfigureAPZControllerThread();
474 virtual already_AddRefed<GeckoContentController>
475 CreateRootContentController();
477 // Dispatch an event that has already been routed through APZ.
478 nsEventStatus ProcessUntransformedAPZEvent(
479 mozilla::WidgetInputEvent* aEvent,
480 const mozilla::layers::APZEventResult& aApzResult);
482 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
483 int32_t aNativeKeyCode,
484 uint32_t aModifierFlags,
485 const nsAString& aCharacters,
486 const nsAString& aUnmodifiedCharacters,
487 nsIObserver* aObserver) override {
488 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
489 return NS_ERROR_UNEXPECTED;
492 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
493 NativeMouseMessage aNativeMessage,
494 mozilla::MouseButton aButton,
495 nsIWidget::Modifiers aModifierFlags,
496 nsIObserver* aObserver) override {
497 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
498 return NS_ERROR_UNEXPECTED;
501 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
502 nsIObserver* aObserver) override {
503 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
504 return NS_ERROR_UNEXPECTED;
507 nsresult SynthesizeNativeMouseScrollEvent(
508 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
509 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
510 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
511 mozilla::widget::AutoObserverNotifier notifier(aObserver,
512 "mousescrollevent");
513 return NS_ERROR_UNEXPECTED;
516 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
517 TouchPointerState aPointerState,
518 LayoutDeviceIntPoint aPoint,
519 double aPointerPressure,
520 uint32_t aPointerOrientation,
521 nsIObserver* aObserver) override {
522 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
523 return NS_ERROR_UNEXPECTED;
526 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
527 float aScale,
528 LayoutDeviceIntPoint aPoint,
529 int32_t aModifierFlags) override {
530 MOZ_RELEASE_ASSERT(
531 false, "This method is not implemented on the current platform");
532 return NS_ERROR_UNEXPECTED;
535 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
536 TouchPointerState aPointerState,
537 LayoutDeviceIntPoint aPoint,
538 double aPressure, uint32_t aRotation,
539 int32_t aTiltX, int32_t aTiltY,
540 int32_t aButton,
541 nsIObserver* aObserver) override {
542 MOZ_RELEASE_ASSERT(
543 false, "This method is not implemented on the current platform");
544 return NS_ERROR_UNEXPECTED;
547 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
548 uint32_t aModifierFlags) override {
549 MOZ_RELEASE_ASSERT(
550 false, "This method is not implemented on the current platform");
551 return NS_ERROR_UNEXPECTED;
554 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
555 LayoutDeviceIntPoint aPoint,
556 double aDeltaX, double aDeltaY,
557 int32_t aModifierFlags,
558 nsIObserver* aObserver) override {
559 MOZ_RELEASE_ASSERT(
560 false, "This method is not implemented on the current platform");
561 return NS_ERROR_UNEXPECTED;
565 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
566 * has non-native input transaction. Otherwise, returns nullptr.
568 void* GetPseudoIMEContext();
570 protected:
571 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
572 return nsIWidget::CreateChildWindow();
575 WindowRenderer* CreateFallbackRenderer();
577 PopupType GetPopupType() const { return mPopupType; }
579 bool HasRemoteContent() const { return mHasRemoteContent; }
582 * Apply the current size constraints to the given size.
584 * @param aWidth width to constrain
585 * @param aHeight height to constrain
587 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
588 SizeConstraints c = GetSizeConstraints();
589 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
590 *aHeight =
591 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
594 CompositorBridgeChild* GetRemoteRenderer() override;
596 void ClearCachedWebrenderResources() override;
598 void ClearWebrenderAnimationResources() override;
600 bool SetNeedFastSnaphot() override;
603 * Notify the widget that this window is being used with OMTC.
605 virtual void WindowUsesOMTC() {}
606 virtual void RegisterTouchWindow() {}
608 mozilla::dom::Document* GetDocument() const;
610 void EnsureTextEventDispatcher();
612 // Notify the compositor that a device reset has occurred.
613 void OnRenderingDeviceReset();
615 bool UseAPZ();
617 bool AllowWebRenderForThisWindow();
620 * For widgets that support synthesizing native touch events, this function
621 * can be used to manage the current state of synthetic pointers. Each widget
622 * must maintain its own MultiTouchInput instance and pass it in as the state,
623 * along with the desired parameters for the changes. This function returns
624 * a new MultiTouchInput object that is ready to be dispatched.
626 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
627 mozilla::MultiTouchInput* aState, mozilla::TimeStamp aTimeStamp,
628 uint32_t aPointerId, TouchPointerState aPointerState,
629 LayoutDeviceIntPoint aPoint, double aPointerPressure,
630 uint32_t aPointerOrientation);
633 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
634 * or directly to gecko (if APZ is not enabled). This function must only
635 * be called from the main thread, and if APZ is enabled, that must also be
636 * the APZ controller thread.
638 void DispatchTouchInput(
639 mozilla::MultiTouchInput& aInput,
640 uint16_t aInputSource =
641 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
644 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
645 * or directly to gecko (if APZ is not enabled). This function must only
646 * be called from the main thread, and if APZ is enabled, that must also be
647 * the APZ controller thread.
649 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
650 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
652 static bool ConvertStatus(nsEventStatus aStatus) {
653 return aStatus == nsEventStatus_eConsumeNoDefault;
656 protected:
657 // Returns whether compositing should use an external surface size.
658 virtual bool UseExternalCompositingSurface() const { return false; }
661 * Starts the OMTC compositor destruction sequence.
663 * When this function returns, the compositor should not be
664 * able to access the opengl context anymore.
665 * It is safe to call it several times if platform implementations
666 * require the compositor to be destroyed before ~nsBaseWidget is
667 * reached (This is the case with gtk2 for instance).
669 virtual void DestroyCompositor();
670 void DestroyLayerManager();
671 void ReleaseContentController();
672 void RevokeTransactionIdAllocator();
674 void FreeShutdownObserver();
675 void FreeLocalesChangedObserver();
677 bool IsPIPWindow() const { return mIsPIPWindow; };
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 // It's PictureInPicture window.
727 bool mIsPIPWindow : 1;
729 struct InitialZoomConstraints {
730 InitialZoomConstraints(const uint32_t& aPresShellID,
731 const ScrollableLayerGuid::ViewID& aViewID,
732 const ZoomConstraints& aConstraints)
733 : mPresShellID(aPresShellID),
734 mViewID(aViewID),
735 mConstraints(aConstraints) {}
737 uint32_t mPresShellID;
738 ScrollableLayerGuid::ViewID mViewID;
739 ZoomConstraints mConstraints;
742 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
744 // This points to the resize listeners who have been notified that a live
745 // resize is in progress. This should always be empty when a live-resize is
746 // not in progress.
747 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
749 #ifdef DEBUG
750 protected:
751 static nsAutoString debug_GuiEventToString(
752 mozilla::WidgetGUIEvent* aGuiEvent);
754 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
755 const LayoutDeviceIntRect* aRect,
756 const char* aWidgetName, int32_t aWindowID);
758 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
759 mozilla::WidgetGUIEvent* aGuiEvent,
760 const char* aWidgetName, int32_t aWindowID);
762 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
763 const nsIntRegion& aPaintEvent,
764 const char* aWidgetName, int32_t aWindowID);
766 static bool debug_GetCachedBoolPref(const char* aPrefName);
767 #endif
769 private:
770 already_AddRefed<mozilla::layers::WebRenderLayerManager>
771 CreateCompositorSession(int aWidth, int aHeight,
772 mozilla::layers::CompositorOptions* aOptionsOut);
775 #endif // nsBaseWidget_h__