Bug 1689430 [wpt PR 27372] - Rewrite wpt/cookies/http-state/domain-tests.html, a...
[gecko.git] / widget / nsBaseWidget.h
blob1e212638bb3e57d5faa554d2e09a40ee9d057020
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/layers/APZCCallbackHelper.h"
15 #include "mozilla/layers/CompositorOptions.h"
16 #include "mozilla/layers/NativeLayer.h"
17 #include "mozilla/widget/ThemeChangeKind.h"
18 #include "nsRect.h"
19 #include "nsIWidget.h"
20 #include "nsWidgetsCID.h"
21 #include "nsIFile.h"
22 #include "nsString.h"
23 #include "nsCOMPtr.h"
24 #include "nsIRollupListener.h"
25 #include "nsIObserver.h"
26 #include "nsIWidgetListener.h"
27 #include "nsPIDOMWindow.h"
28 #include "nsWeakReference.h"
30 #include <algorithm>
32 #if defined(XP_WIN)
33 // Scroll capture constants
34 const uint32_t kScrollCaptureFillColor = 0xFFa0a0a0; // gray
35 const mozilla::gfx::SurfaceFormat kScrollCaptureFormat =
36 mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32;
37 #endif
39 class nsIContent;
40 class gfxContext;
42 namespace mozilla {
43 class CompositorVsyncDispatcher;
44 class LiveResizeListener;
46 #ifdef ACCESSIBILITY
47 namespace a11y {
48 class Accessible;
50 #endif
52 namespace gfx {
53 class DrawTarget;
54 class SourceSurface;
55 } // namespace gfx
57 namespace layers {
58 class BasicLayerManager;
59 class CompositorBridgeChild;
60 class CompositorBridgeParent;
61 class IAPZCTreeManager;
62 class GeckoContentController;
63 class APZEventState;
64 struct APZEventResult;
65 class CompositorSession;
66 class ImageContainer;
67 struct ScrollableLayerGuid;
68 class RemoteCompositorSession;
69 } // namespace layers
71 namespace widget {
72 class CompositorWidgetDelegate;
73 class InProcessCompositorWidget;
74 class WidgetRenderingContext;
75 } // namespace widget
77 class CompositorVsyncDispatcher;
78 } // namespace mozilla
80 namespace base {
81 class Thread;
82 } // namespace base
84 // Windows specific constant indicating the maximum number of touch points the
85 // inject api will allow. This also sets the maximum numerical value for touch
86 // ids we can use when injecting touch points on Windows.
87 #define TOUCH_INJECT_MAX_POINTS 256
89 class nsBaseWidget;
91 // Helper class used in shutting down gfx related code.
92 class WidgetShutdownObserver final : public nsIObserver {
93 ~WidgetShutdownObserver();
95 public:
96 explicit WidgetShutdownObserver(nsBaseWidget* aWidget);
98 NS_DECL_ISUPPORTS
99 NS_DECL_NSIOBSERVER
101 void Register();
102 void Unregister();
104 nsBaseWidget* mWidget;
105 bool mRegistered;
109 * Common widget implementation used as base class for native
110 * or crossplatform implementations of Widgets.
111 * All cross-platform behavior that all widgets need to implement
112 * should be placed in this class.
113 * (Note: widget implementations are not required to use this
114 * class, but it gives them a head start.)
117 class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference {
118 template <class EventType, class InputType>
119 friend class DispatchEventOnMainThread;
120 friend class mozilla::widget::InProcessCompositorWidget;
121 friend class mozilla::layers::RemoteCompositorSession;
123 protected:
124 typedef base::Thread Thread;
125 typedef mozilla::gfx::DrawTarget DrawTarget;
126 typedef mozilla::gfx::SourceSurface SourceSurface;
127 typedef mozilla::layers::BasicLayerManager BasicLayerManager;
128 typedef mozilla::layers::BufferMode BufferMode;
129 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
130 typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent;
131 typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager;
132 typedef mozilla::layers::GeckoContentController GeckoContentController;
133 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
134 typedef mozilla::layers::APZEventState APZEventState;
135 typedef mozilla::layers::SetAllowedTouchBehaviorCallback
136 SetAllowedTouchBehaviorCallback;
137 typedef mozilla::CSSIntRect CSSIntRect;
138 typedef mozilla::CSSRect CSSRect;
139 typedef mozilla::ScreenRotation ScreenRotation;
140 typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate;
141 typedef mozilla::layers::CompositorSession CompositorSession;
142 typedef mozilla::layers::ImageContainer ImageContainer;
144 virtual ~nsBaseWidget();
146 public:
147 nsBaseWidget();
149 NS_DECL_ISUPPORTS
151 // nsIWidget interface
152 virtual void CaptureMouse(bool aCapture) override {}
153 virtual void CaptureRollupEvents(nsIRollupListener* aListener,
154 bool aDoCapture) override {}
155 virtual nsIWidgetListener* GetWidgetListener() override;
156 virtual void SetWidgetListener(nsIWidgetListener* alistener) override;
157 virtual void Destroy() override;
158 virtual void SetParent(nsIWidget* aNewParent) override{};
159 virtual nsIWidget* GetParent(void) override;
160 virtual nsIWidget* GetTopLevelWidget() override;
161 virtual nsIWidget* GetSheetWindowParent(void) override;
162 virtual float GetDPI() override;
163 virtual void AddChild(nsIWidget* aChild) override;
164 virtual void RemoveChild(nsIWidget* aChild) override;
166 void SetZIndex(int32_t aZIndex) override;
167 virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
168 nsIWidget* aWidget, bool aActivate) override {}
170 virtual void SetSizeMode(nsSizeMode aMode) override;
171 virtual nsSizeMode SizeMode() override { return mSizeMode; }
172 virtual void GetWorkspaceID(nsAString& workspaceID) override;
173 virtual void MoveToWorkspace(const nsAString& workspaceID) override;
174 virtual bool IsTiled() const override { return mIsTiled; }
176 virtual bool IsFullyOccluded() const override { return mIsFullyOccluded; }
178 virtual void SetCursor(nsCursor aDefaultCursor, imgIContainer* aCursor,
179 uint32_t aHotspotX, uint32_t aHotspotY) override;
180 virtual void ClearCachedCursor() override { mUpdateCursor = true; }
181 virtual void SetTransparencyMode(nsTransparencyMode aMode) override;
182 virtual nsTransparencyMode GetTransparencyMode() override;
183 virtual void GetWindowClipRegion(
184 nsTArray<LayoutDeviceIntRect>* aRects) override;
185 virtual void SetWindowShadowStyle(
186 mozilla::StyleWindowShadow aStyle) override {}
187 virtual void SetShowsToolbarButton(bool aShow) override {}
188 virtual void SetSupportsNativeFullscreen(
189 bool aSupportsNativeFullscreen) override {}
190 virtual void SetWindowAnimationType(WindowAnimationType aType) override {}
191 virtual void HideWindowChrome(bool aShouldHide) override {}
192 virtual bool PrepareForFullscreenTransition(nsISupports** aData) override {
193 return false;
195 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
196 uint16_t aDuration,
197 nsISupports* aData,
198 nsIRunnable* aCallback) override;
199 virtual void CleanupFullscreenTransition() override{};
200 virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
201 virtual nsresult MakeFullScreen(bool aFullScreen,
202 nsIScreen* aScreen = nullptr) override;
203 void InfallibleMakeFullScreen(bool aFullScreen, nsIScreen* aScreen = nullptr);
205 virtual LayerManager* GetLayerManager(
206 PLayerTransactionChild* aShadowManager = nullptr,
207 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
208 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;
210 // A remote compositor session tied to this window has been lost and IPC
211 // messages will no longer work. The widget must clean up any lingering
212 // resources and possibly schedule another paint.
214 // A reference to the session object is held until this function has
215 // returned.
216 void NotifyCompositorSessionLost(
217 mozilla::layers::CompositorSession* aSession);
219 already_AddRefed<mozilla::CompositorVsyncDispatcher>
220 GetCompositorVsyncDispatcher();
221 virtual void CreateCompositorVsyncDispatcher();
222 virtual void CreateCompositor();
223 virtual void CreateCompositor(int aWidth, int aHeight);
224 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) {
226 virtual void PrepareWindowEffects() override {}
227 virtual void UpdateThemeGeometries(
228 const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
229 virtual void SetModal(bool aModal) override {}
230 virtual uint32_t GetMaxTouchPoints() const override;
231 virtual void SetWindowClass(const nsAString& xulWinType) override {}
232 virtual nsresult SetWindowClipRegion(
233 const nsTArray<LayoutDeviceIntRect>& aRects,
234 bool aIntersectWithExisting) override;
235 // Return whether this widget interprets parameters to Move and Resize APIs
236 // as "desktop pixels" rather than "device pixels", and therefore
237 // applies its GetDefaultScale() value to them before using them as mBounds
238 // etc (which are always stored in device pixels).
239 // Note that APIs that -get- the widget's position/size/bounds, rather than
240 // -setting- them (i.e. moving or resizing the widget) will always return
241 // values in the widget's device pixels.
242 bool BoundsUseDesktopPixels() const {
243 return mWindowType <= eWindowType_popup;
245 // Default implementation, to be overridden by platforms where desktop coords
246 // are virtualized and may not correspond to device pixels on the screen.
247 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
248 return mozilla::DesktopToLayoutDeviceScale(1.0);
250 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScaleByScreen()
251 override;
253 virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX,
254 int32_t* aY) override {}
255 virtual void MoveClient(const DesktopPoint& aOffset) override;
256 virtual void ResizeClient(const DesktopSize& aSize, bool aRepaint) override;
257 virtual void ResizeClient(const DesktopRect& aRect, bool aRepaint) override;
258 virtual LayoutDeviceIntRect GetBounds() override;
259 virtual LayoutDeviceIntRect GetClientBounds() override;
260 virtual LayoutDeviceIntRect GetScreenBounds() override;
261 [[nodiscard]] virtual nsresult GetRestoredBounds(
262 LayoutDeviceIntRect& aRect) override;
263 virtual nsresult SetNonClientMargins(
264 LayoutDeviceIntMargin& aMargins) override;
265 virtual LayoutDeviceIntPoint GetClientOffset() override;
266 virtual void EnableDragDrop(bool aEnable) override{};
267 virtual nsresult AsyncEnableDragDrop(bool aEnable) override;
268 [[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) override {
269 return NS_OK;
271 virtual bool HasPendingInputEvent() override;
272 virtual void SetIcon(const nsAString& aIconSpec) override {}
273 virtual void SetDrawsInTitlebar(bool aState) override {}
274 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
275 virtual void FreeNativeData(void* data, uint32_t aDataType) override {}
276 [[nodiscard]] virtual nsresult BeginResizeDrag(
277 mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal,
278 int32_t aVertical) override {
279 return NS_ERROR_NOT_IMPLEMENTED;
281 virtual nsresult ActivateNativeMenuItemAt(
282 const nsAString& indexString) override {
283 return NS_ERROR_NOT_IMPLEMENTED;
285 virtual nsresult ForceUpdateNativeMenuAt(
286 const nsAString& indexString) override {
287 return NS_ERROR_NOT_IMPLEMENTED;
289 nsresult NotifyIME(const IMENotification& aIMENotification) final;
290 [[nodiscard]] virtual nsresult AttachNativeKeyEvent(
291 mozilla::WidgetKeyboardEvent& aEvent) override {
292 return NS_ERROR_NOT_IMPLEMENTED;
294 bool ComputeShouldAccelerate();
295 virtual bool WidgetTypeSupportsAcceleration() { return true; }
296 [[nodiscard]] virtual nsresult OnDefaultButtonLoaded(
297 const LayoutDeviceIntRect& aButtonRect) override {
298 return NS_ERROR_NOT_IMPLEMENTED;
300 virtual already_AddRefed<nsIWidget> CreateChild(
301 const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData = nullptr,
302 bool aForceUseIWidgetParent = false) override;
303 virtual void AttachViewToTopLevel(bool aUseAttachedEvents) override;
304 virtual nsIWidgetListener* GetAttachedWidgetListener() override;
305 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
306 virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
307 virtual void SetPreviouslyAttachedWidgetListener(
308 nsIWidgetListener* aListener) override;
309 virtual NativeIMEContext GetNativeIMEContext() override;
310 TextEventDispatcher* GetTextEventDispatcher() final;
311 virtual TextEventDispatcherListener* GetNativeTextEventDispatcherListener()
312 override;
313 virtual void ZoomToRect(const uint32_t& aPresShellId,
314 const ScrollableLayerGuid::ViewID& aViewId,
315 const CSSRect& aRect,
316 const uint32_t& aFlags) override;
317 // Dispatch an event that must be first be routed through APZ.
318 nsEventStatus DispatchInputEvent(mozilla::WidgetInputEvent* aEvent) override;
319 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
321 void SetConfirmedTargetAPZC(
322 uint64_t aInputBlockId,
323 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
325 void UpdateZoomConstraints(
326 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
327 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
329 bool AsyncPanZoomEnabled() const override;
331 void NotifyWindowDestroyed();
332 void NotifySizeMoveDone();
333 void NotifyWindowMoved(int32_t aX, int32_t aY);
335 // Register plugin windows for remote updates from the compositor
336 virtual void RegisterPluginWindowForRemoteUpdates() override;
337 virtual void UnregisterPluginWindowForRemoteUpdates() override;
339 virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) override{};
341 // Should be called by derived implementations to notify on system color and
342 // theme changes.
343 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
344 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings);
346 #ifdef ACCESSIBILITY
347 // Get the accessible for the window.
348 mozilla::a11y::Accessible* GetRootAccessible();
349 #endif
351 // Return true if this is a simple widget (that is typically not worth
352 // accelerating)
353 bool IsSmallPopup() const;
355 nsPopupLevel PopupLevel() { return mPopupLevel; }
357 virtual LayoutDeviceIntSize ClientToWindowSize(
358 const LayoutDeviceIntSize& aClientSize) override {
359 return aClientSize;
362 // return true if this is a popup widget with a native titlebar
363 bool IsPopupWithTitleBar() const {
364 return (mWindowType == eWindowType_popup &&
365 mBorderStyle != eBorderStyle_default &&
366 mBorderStyle & eBorderStyle_title);
369 virtual void ReparentNativeWidget(nsIWidget* aNewParent) override {}
371 virtual const SizeConstraints GetSizeConstraints() override;
372 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
374 virtual void StartAsyncScrollbarDrag(
375 const AsyncDragMetrics& aDragMetrics) override;
377 virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
378 const ScrollableLayerGuid& aGuid) override;
380 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
383 * Use this when GetLayerManager() returns a BasicLayerManager
384 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
385 * layer manager to temporarily render into aTarget.
387 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
388 * |aRotation| is the "virtual rotation" to apply when rendering to
389 * the target. When |aRotation| is ROTATION_0,
390 * |aNaturalWidgetBounds| is not used.
392 class AutoLayerManagerSetup {
393 public:
394 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
395 BufferMode aDoubleBuffering,
396 ScreenRotation aRotation = mozilla::ROTATION_0);
397 ~AutoLayerManagerSetup();
399 private:
400 nsBaseWidget* mWidget;
401 RefPtr<BasicLayerManager> mLayerManager;
403 friend class AutoLayerManagerSetup;
405 virtual bool ShouldUseOffMainThreadCompositing();
407 static nsIRollupListener* GetActiveRollupListener();
409 void Shutdown();
411 void QuitIME();
413 #if defined(XP_WIN)
414 uint64_t CreateScrollCaptureContainer() override;
415 #endif
417 // These functions should be called at the start and end of a "live" widget
418 // resize (i.e. when the window contents are repainting during the resize,
419 // such as when the user drags a window border). It will suppress the
420 // displayport during the live resize to avoid unneccessary overpainting.
421 void NotifyLiveResizeStarted();
422 void NotifyLiveResizeStopped();
424 #if defined(MOZ_WIDGET_ANDROID)
425 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
426 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
427 const CSSToScreenScale& aZoom) override{};
428 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
429 bool aNeedsYFlip) override{};
430 #endif
432 protected:
433 // These are methods for CompositorWidgetWrapper, and should only be
434 // accessed from that class. Derived widgets can choose which methods to
435 // implement, or none if supporting out-of-process compositing.
436 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
437 return true;
439 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
440 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
441 return nullptr;
443 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
444 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
445 LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
446 return StartRemoteDrawing();
448 virtual void EndRemoteDrawing() {}
449 virtual void EndRemoteDrawingInRegion(
450 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
451 EndRemoteDrawing();
453 virtual void CleanupRemoteDrawing() {}
454 virtual void CleanupWindowEffects() {}
455 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
456 return true;
458 virtual uint32_t GetGLFrameBufferFormat();
459 virtual bool CompositorInitiallyPaused() { return false; }
461 protected:
462 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
463 nsIFile** aResult);
464 virtual void OnDestroy();
465 void BaseCreate(nsIWidget* aParent, nsWidgetInitData* aInitData);
467 virtual void ConfigureAPZCTreeManager();
468 virtual void ConfigureAPZControllerThread();
469 virtual already_AddRefed<GeckoContentController>
470 CreateRootContentController();
472 // Dispatch an event that has already been routed through APZ.
473 nsEventStatus ProcessUntransformedAPZEvent(
474 mozilla::WidgetInputEvent* aEvent,
475 const mozilla::layers::APZEventResult& aApzResult);
477 const LayoutDeviceIntRegion RegionFromArray(
478 const nsTArray<LayoutDeviceIntRect>& aRects);
479 void ArrayFromRegion(const LayoutDeviceIntRegion& aRegion,
480 nsTArray<LayoutDeviceIntRect>& aRects);
482 virtual nsresult SynthesizeNativeKeyEvent(
483 int32_t aNativeKeyboardLayout, int32_t aNativeKeyCode,
484 uint32_t aModifierFlags, const nsAString& aCharacters,
485 const nsAString& aUnmodifiedCharacters, nsIObserver* aObserver) override {
486 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
487 return NS_ERROR_UNEXPECTED;
490 virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
491 uint32_t aNativeMessage,
492 uint32_t aModifierFlags,
493 nsIObserver* aObserver) override {
494 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
495 return NS_ERROR_UNEXPECTED;
498 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
499 nsIObserver* aObserver) override {
500 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
501 return NS_ERROR_UNEXPECTED;
504 virtual nsresult SynthesizeNativeMouseScrollEvent(
505 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
506 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
507 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
508 mozilla::widget::AutoObserverNotifier notifier(aObserver,
509 "mousescrollevent");
510 return NS_ERROR_UNEXPECTED;
513 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
514 TouchPointerState aPointerState,
515 LayoutDeviceIntPoint aPoint,
516 double aPointerPressure,
517 uint32_t aPointerOrientation,
518 nsIObserver* aObserver) override {
519 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
520 return NS_ERROR_UNEXPECTED;
524 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
525 * has non-native input transaction. Otherwise, returns nullptr.
527 void* GetPseudoIMEContext();
529 protected:
530 // Utility to check if an array of clip rects is equal to our
531 // internally stored clip rect array mClipRects.
532 bool IsWindowClipRegionEqual(const nsTArray<LayoutDeviceIntRect>& aRects);
534 // Stores the clip rectangles in aRects into mClipRects.
535 void StoreWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects);
537 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
538 return nsIWidget::CreateChildWindow();
541 LayerManager* CreateBasicLayerManager();
543 nsPopupType PopupType() const { return mPopupType; }
545 bool HasRemoteContent() const { return mHasRemoteContent; }
547 void NotifyRollupGeometryChange() {
548 // XULPopupManager isn't interested in this notification, so only
549 // send it if gRollupListener is set.
550 if (gRollupListener) {
551 gRollupListener->NotifyGeometryChange();
556 * Apply the current size constraints to the given size.
558 * @param aWidth width to constrain
559 * @param aHeight height to constrain
561 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) {
562 SizeConstraints c = GetSizeConstraints();
563 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
564 *aHeight =
565 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
568 virtual CompositorBridgeChild* GetRemoteRenderer() override;
570 virtual void ClearCachedWebrenderResources() override;
573 * Notify the widget that this window is being used with OMTC.
575 virtual void WindowUsesOMTC() {}
576 virtual void RegisterTouchWindow() {}
578 mozilla::dom::Document* GetDocument() const;
580 void EnsureTextEventDispatcher();
582 // Notify the compositor that a device reset has occurred.
583 void OnRenderingDeviceReset();
585 bool UseAPZ();
587 bool AllowWebRenderForThisWindow();
590 * For widgets that support synthesizing native touch events, this function
591 * can be used to manage the current state of synthetic pointers. Each widget
592 * must maintain its own MultiTouchInput instance and pass it in as the state,
593 * along with the desired parameters for the changes. This function returns
594 * a new MultiTouchInput object that is ready to be dispatched.
596 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
597 mozilla::MultiTouchInput* aState, uint32_t aTime,
598 mozilla::TimeStamp aTimeStamp, uint32_t aPointerId,
599 TouchPointerState aPointerState, LayoutDeviceIntPoint aPoint,
600 double aPointerPressure, uint32_t aPointerOrientation);
603 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
604 * or directly to gecko (if APZ is not enabled). This function must only
605 * be called from the main thread, and if APZ is enabled, that must also be
606 * the APZ controller thread.
608 void DispatchTouchInput(mozilla::MultiTouchInput& aInput);
611 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
612 * or directly to gecko (if APZ is not enabled). This function must only
613 * be called from the main thread, and if APZ is enabled, that must also be
614 * the APZ controller thread.
616 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
617 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
619 #if defined(XP_WIN)
620 void UpdateScrollCapture() override;
623 * To be overridden by derived classes to return a snapshot that can be used
624 * during scrolling. Returning null means we won't update the container.
625 * @return an already AddRefed SourceSurface containing the snapshot
627 virtual already_AddRefed<SourceSurface> CreateScrollSnapshot() {
628 return nullptr;
632 * Used by derived classes to create a fallback scroll image.
633 * @param aSnapshotDrawTarget DrawTarget to fill with fallback image.
635 void DefaultFillScrollCapture(DrawTarget* aSnapshotDrawTarget);
637 RefPtr<ImageContainer> mScrollCaptureContainer;
638 #endif
640 protected:
641 // Returns whether compositing should use an external surface size.
642 virtual bool UseExternalCompositingSurface() const { return false; }
645 * Starts the OMTC compositor destruction sequence.
647 * When this function returns, the compositor should not be
648 * able to access the opengl context anymore.
649 * It is safe to call it several times if platform implementations
650 * require the compositor to be destroyed before ~nsBaseWidget is
651 * reached (This is the case with gtk2 for instance).
653 virtual void DestroyCompositor();
654 void DestroyLayerManager();
655 void ReleaseContentController();
656 void RevokeTransactionIdAllocator();
658 void FreeShutdownObserver();
660 nsIWidgetListener* mWidgetListener;
661 nsIWidgetListener* mAttachedWidgetListener;
662 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
663 RefPtr<LayerManager> mLayerManager;
664 RefPtr<CompositorSession> mCompositorSession;
665 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
667 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
668 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
670 RefPtr<IAPZCTreeManager> mAPZC;
671 RefPtr<GeckoContentController> mRootContentController;
672 RefPtr<APZEventState> mAPZEventState;
673 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback;
674 RefPtr<WidgetShutdownObserver> mShutdownObserver;
675 RefPtr<TextEventDispatcher> mTextEventDispatcher;
676 nsCursor mCursor;
677 nsBorderStyle mBorderStyle;
678 LayoutDeviceIntRect mBounds;
679 LayoutDeviceIntRect* mOriginalBounds;
680 // When this pointer is null, the widget is not clipped
681 mozilla::UniquePtr<LayoutDeviceIntRect[]> mClipRects;
682 uint32_t mClipRectCount;
683 nsSizeMode mSizeMode;
684 bool mIsTiled;
685 nsPopupLevel mPopupLevel;
686 nsPopupType mPopupType;
687 SizeConstraints mSizeConstraints;
688 bool mHasRemoteContent;
689 bool mFissionWindow;
691 bool mUpdateCursor;
692 bool mUseAttachedEvents;
693 bool mIMEHasFocus;
694 bool mIMEHasQuit;
695 bool mIsFullyOccluded;
696 static nsIRollupListener* gRollupListener;
698 struct InitialZoomConstraints {
699 InitialZoomConstraints(const uint32_t& aPresShellID,
700 const ScrollableLayerGuid::ViewID& aViewID,
701 const ZoomConstraints& aConstraints)
702 : mPresShellID(aPresShellID),
703 mViewID(aViewID),
704 mConstraints(aConstraints) {}
706 uint32_t mPresShellID;
707 ScrollableLayerGuid::ViewID mViewID;
708 ZoomConstraints mConstraints;
711 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
713 // This points to the resize listeners who have been notified that a live
714 // resize is in progress. This should always be empty when a live-resize is
715 // not in progress.
716 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
718 #ifdef DEBUG
719 protected:
720 static nsAutoString debug_GuiEventToString(
721 mozilla::WidgetGUIEvent* aGuiEvent);
722 static bool debug_WantPaintFlashing();
724 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
725 const LayoutDeviceIntRect* aRect,
726 const char* aWidgetName, int32_t aWindowID);
728 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
729 mozilla::WidgetGUIEvent* aGuiEvent,
730 const char* aWidgetName, int32_t aWindowID);
732 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
733 const nsIntRegion& aPaintEvent,
734 const char* aWidgetName, int32_t aWindowID);
736 static bool debug_GetCachedBoolPref(const char* aPrefName);
737 #endif
739 private:
740 already_AddRefed<LayerManager> CreateCompositorSession(
741 int aWidth, int aHeight, mozilla::layers::CompositorOptions* aOptionsOut);
744 #endif // nsBaseWidget_h__