Bug 1487655 [wpt PR 12775] - [css-properties-values-api] Typify CSSStyleValue.parse...
[gecko.git] / widget / nsBaseWidget.h
blob947424ca2390d27db632a8e6af91768f3b45dac2
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 "nsRect.h"
17 #include "nsIWidget.h"
18 #include "nsWidgetsCID.h"
19 #include "nsIFile.h"
20 #include "nsString.h"
21 #include "nsCOMPtr.h"
22 #include "nsIRollupListener.h"
23 #include "nsIObserver.h"
24 #include "nsIWidgetListener.h"
25 #include "nsPIDOMWindow.h"
26 #include "nsWeakReference.h"
27 #include <algorithm>
29 #if defined(XP_WIN)
30 // Scroll capture constants
31 const uint32_t kScrollCaptureFillColor = 0xFFa0a0a0; // gray
32 const mozilla::gfx::SurfaceFormat kScrollCaptureFormat =
33 mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32;
34 #endif
36 class nsIContent;
37 class gfxContext;
39 namespace mozilla {
40 class CompositorVsyncDispatcher;
41 class LiveResizeListener;
43 #ifdef ACCESSIBILITY
44 namespace a11y {
45 class Accessible;
47 #endif
49 namespace gfx {
50 class DrawTarget;
51 class SourceSurface;
52 } // namespace gfx
54 namespace layers {
55 class BasicLayerManager;
56 class CompositorBridgeChild;
57 class CompositorBridgeParent;
58 class IAPZCTreeManager;
59 class GeckoContentController;
60 class APZEventState;
61 class CompositorSession;
62 class ImageContainer;
63 struct ScrollableLayerGuid;
64 class RemoteCompositorSession;
65 } // namespace layers
67 namespace widget {
68 class CompositorWidgetDelegate;
69 class InProcessCompositorWidget;
70 class WidgetRenderingContext;
71 } // namespace widget
73 class CompositorVsyncDispatcher;
74 } // namespace mozilla
76 namespace base {
77 class Thread;
78 } // namespace base
80 // Windows specific constant indicating the maximum number of touch points the
81 // inject api will allow. This also sets the maximum numerical value for touch
82 // ids we can use when injecting touch points on Windows.
83 #define TOUCH_INJECT_MAX_POINTS 256
85 class nsBaseWidget;
87 // Helper class used in shutting down gfx related code.
88 class WidgetShutdownObserver final : public nsIObserver
90 ~WidgetShutdownObserver();
92 public:
93 explicit WidgetShutdownObserver(nsBaseWidget* aWidget);
95 NS_DECL_ISUPPORTS
96 NS_DECL_NSIOBSERVER
98 void Register();
99 void Unregister();
101 nsBaseWidget *mWidget;
102 bool mRegistered;
106 * Common widget implementation used as base class for native
107 * or crossplatform implementations of Widgets.
108 * All cross-platform behavior that all widgets need to implement
109 * should be placed in this class.
110 * (Note: widget implementations are not required to use this
111 * class, but it gives them a head start.)
114 class nsBaseWidget : public nsIWidget, public nsSupportsWeakReference
116 friend class DispatchWheelEventOnMainThread;
117 friend class mozilla::widget::InProcessCompositorWidget;
118 friend class mozilla::layers::RemoteCompositorSession;
120 protected:
121 typedef base::Thread Thread;
122 typedef mozilla::gfx::DrawTarget DrawTarget;
123 typedef mozilla::gfx::SourceSurface SourceSurface;
124 typedef mozilla::layers::BasicLayerManager BasicLayerManager;
125 typedef mozilla::layers::BufferMode BufferMode;
126 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
127 typedef mozilla::layers::CompositorBridgeParent CompositorBridgeParent;
128 typedef mozilla::layers::IAPZCTreeManager IAPZCTreeManager;
129 typedef mozilla::layers::GeckoContentController GeckoContentController;
130 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
131 typedef mozilla::layers::APZEventState APZEventState;
132 typedef mozilla::layers::SetAllowedTouchBehaviorCallback SetAllowedTouchBehaviorCallback;
133 typedef mozilla::CSSIntRect CSSIntRect;
134 typedef mozilla::CSSRect CSSRect;
135 typedef mozilla::ScreenRotation ScreenRotation;
136 typedef mozilla::widget::CompositorWidgetDelegate CompositorWidgetDelegate;
137 typedef mozilla::layers::CompositorSession CompositorSession;
138 typedef mozilla::layers::ImageContainer ImageContainer;
140 virtual ~nsBaseWidget();
142 public:
143 nsBaseWidget();
145 NS_DECL_ISUPPORTS
147 // nsIWidget interface
148 virtual void CaptureMouse(bool aCapture) override {}
149 virtual void CaptureRollupEvents(nsIRollupListener* aListener,
150 bool aDoCapture) override {}
151 virtual nsIWidgetListener* GetWidgetListener() override;
152 virtual void SetWidgetListener(nsIWidgetListener* alistener) override;
153 virtual void Destroy() override;
154 virtual void SetParent(nsIWidget* aNewParent) override {};
155 virtual nsIWidget* GetParent(void) override;
156 virtual nsIWidget* GetTopLevelWidget() override;
157 virtual nsIWidget* GetSheetWindowParent(void) override;
158 virtual float GetDPI() override;
159 virtual void AddChild(nsIWidget* aChild) override;
160 virtual void RemoveChild(nsIWidget* aChild) override;
162 void SetZIndex(int32_t aZIndex) override;
163 virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
164 nsIWidget *aWidget, bool aActivate)
165 override {}
167 virtual void SetSizeMode(nsSizeMode aMode) override;
168 virtual nsSizeMode SizeMode() override
170 return mSizeMode;
173 virtual bool IsFullyOccluded() const override
175 return mIsFullyOccluded;
178 virtual void SetCursor(nsCursor aCursor) override;
179 virtual nsresult SetCursor(imgIContainer* aCursor,
180 uint32_t aHotspotX, uint32_t aHotspotY) override;
181 virtual void ClearCachedCursor() override { mUpdateCursor = true; }
182 virtual void SetTransparencyMode(nsTransparencyMode aMode) override;
183 virtual nsTransparencyMode GetTransparencyMode() override;
184 virtual void GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects) override;
185 virtual void SetWindowShadowStyle(int32_t aStyle) override {}
186 virtual void SetShowsToolbarButton(bool aShow) override {}
187 virtual void SetShowsFullScreenButton(bool aShow) override {}
188 virtual void SetWindowAnimationType(WindowAnimationType aType) override {}
189 virtual void HideWindowChrome(bool aShouldHide) override {}
190 virtual bool PrepareForFullscreenTransition(nsISupports** aData) override { return false; }
191 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
192 uint16_t aDuration,
193 nsISupports* aData,
194 nsIRunnable* aCallback) override;
195 virtual void CleanupFullscreenTransition() override {};
196 virtual already_AddRefed<nsIScreen> GetWidgetScreen() override;
197 virtual nsresult MakeFullScreen(bool aFullScreen,
198 nsIScreen* aScreen = nullptr) override;
199 void InfallibleMakeFullScreen(bool aFullScreen,
200 nsIScreen* aScreen = nullptr);
202 virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager = nullptr,
203 LayersBackend aBackendHint = mozilla::layers::LayersBackend::LAYERS_NONE,
204 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) override;
206 // A remote compositor session tied to this window has been lost and IPC
207 // messages will no longer work. The widget must clean up any lingering
208 // resources and possibly schedule another paint.
210 // A reference to the session object is held until this function has
211 // returned.
212 void NotifyCompositorSessionLost(mozilla::layers::CompositorSession* aSession);
214 already_AddRefed<mozilla::CompositorVsyncDispatcher> GetCompositorVsyncDispatcher();
215 void CreateCompositorVsyncDispatcher();
216 virtual void CreateCompositor();
217 virtual void CreateCompositor(int aWidth, int aHeight);
218 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate* delegate) {}
219 virtual void PrepareWindowEffects() override {}
220 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
221 virtual void SetModal(bool aModal) override {}
222 virtual uint32_t GetMaxTouchPoints() const override;
223 virtual void SetWindowClass(const nsAString& xulWinType)
224 override {}
225 virtual nsresult SetWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects, bool aIntersectWithExisting) override;
226 // Return whether this widget interprets parameters to Move and Resize APIs
227 // as "desktop pixels" rather than "device pixels", and therefore
228 // applies its GetDefaultScale() value to them before using them as mBounds
229 // etc (which are always stored in device pixels).
230 // Note that APIs that -get- the widget's position/size/bounds, rather than
231 // -setting- them (i.e. moving or resizing the widget) will always return
232 // values in the widget's device pixels.
233 bool BoundsUseDesktopPixels() const {
234 return mWindowType <= eWindowType_popup;
236 // Default implementation, to be overridden by platforms where desktop coords
237 // are virtualized and may not correspond to device pixels on the screen.
238 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
239 return mozilla::DesktopToLayoutDeviceScale(1.0);
241 virtual void ConstrainPosition(bool aAllowSlop,
242 int32_t *aX,
243 int32_t *aY) override {}
244 virtual void MoveClient(double aX, double aY) override;
245 virtual void ResizeClient(double aWidth, double aHeight, bool aRepaint) override;
246 virtual void ResizeClient(double aX, double aY, double aWidth, double aHeight, bool aRepaint) override;
247 virtual LayoutDeviceIntRect GetBounds() override;
248 virtual LayoutDeviceIntRect GetClientBounds() override;
249 virtual LayoutDeviceIntRect GetScreenBounds() override;
250 virtual MOZ_MUST_USE nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
251 virtual nsresult SetNonClientMargins(LayoutDeviceIntMargin& aMargins) override;
252 virtual LayoutDeviceIntPoint GetClientOffset() override;
253 virtual void EnableDragDrop(bool aEnable) override {};
254 virtual nsresult AsyncEnableDragDrop(bool aEnable) override;
255 virtual MOZ_MUST_USE nsresult
256 GetAttention(int32_t aCycleCount) override
257 { return NS_OK; }
258 virtual bool HasPendingInputEvent() override;
259 virtual void SetIcon(const nsAString &aIconSpec) override {}
260 virtual void SetDrawsInTitlebar(bool aState) override {}
261 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
262 virtual void FreeNativeData(void * data, uint32_t aDataType) override {}
263 virtual MOZ_MUST_USE nsresult
264 BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
265 int32_t aHorizontal,
266 int32_t aVertical) override
267 { return NS_ERROR_NOT_IMPLEMENTED; }
268 virtual MOZ_MUST_USE nsresult
269 BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) override
270 { return NS_ERROR_NOT_IMPLEMENTED; }
271 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override { return NS_ERROR_NOT_IMPLEMENTED; }
272 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override { return NS_ERROR_NOT_IMPLEMENTED; }
273 nsresult NotifyIME(const IMENotification& aIMENotification)
274 final;
275 virtual MOZ_MUST_USE nsresult
276 StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
277 int32_t aPanelX, int32_t aPanelY,
278 nsString& aCommitted) override
279 { return NS_ERROR_NOT_IMPLEMENTED; }
280 virtual void SetPluginFocused(bool& aFocused) override {}
281 virtual void SetCandidateWindowForPlugin(
282 const mozilla::widget::CandidateWindowPosition&
283 aPosition) override
285 virtual void DefaultProcOfPluginEvent(
286 const mozilla::WidgetPluginEvent& aEvent) override
288 virtual MOZ_MUST_USE nsresult AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) override { return NS_ERROR_NOT_IMPLEMENTED; }
289 bool ComputeShouldAccelerate();
290 virtual bool WidgetTypeSupportsAcceleration() { return true; }
291 virtual MOZ_MUST_USE nsresult OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) override { return NS_ERROR_NOT_IMPLEMENTED; }
292 virtual already_AddRefed<nsIWidget>
293 CreateChild(const LayoutDeviceIntRect& aRect,
294 nsWidgetInitData* aInitData = nullptr,
295 bool aForceUseIWidgetParent = false) override;
296 virtual void AttachViewToTopLevel(bool aUseAttachedEvents) override;
297 virtual nsIWidgetListener* GetAttachedWidgetListener() override;
298 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
299 virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
300 virtual void SetPreviouslyAttachedWidgetListener(nsIWidgetListener* aListener) override;
301 virtual NativeIMEContext GetNativeIMEContext() override;
302 TextEventDispatcher* GetTextEventDispatcher() final;
303 virtual TextEventDispatcherListener*
304 GetNativeTextEventDispatcherListener() override;
305 virtual void ZoomToRect(const uint32_t& aPresShellId,
306 const FrameMetrics::ViewID& aViewId,
307 const CSSRect& aRect,
308 const uint32_t& aFlags) override;
309 // Dispatch an event that must be first be routed through APZ.
310 nsEventStatus DispatchInputEvent(mozilla::WidgetInputEvent* aEvent) override;
311 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
313 void SetConfirmedTargetAPZC(uint64_t aInputBlockId,
314 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
316 void UpdateZoomConstraints(const uint32_t& aPresShellId,
317 const FrameMetrics::ViewID& aViewId,
318 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
320 bool AsyncPanZoomEnabled() const override;
322 typedef void (nsIPresShell::*NotificationFunc)(void);
323 void NotifyPresShell(NotificationFunc aNotificationFunc);
325 void NotifyWindowDestroyed();
326 void NotifySizeMoveDone();
327 void NotifyWindowMoved(int32_t aX, int32_t aY);
329 // Register plugin windows for remote updates from the compositor
330 virtual void RegisterPluginWindowForRemoteUpdates() override;
331 virtual void UnregisterPluginWindowForRemoteUpdates() override;
333 virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) override {};
335 // Should be called by derived implementations to notify on system color and
336 // theme changes.
337 void NotifySysColorChanged();
338 void NotifyThemeChanged();
339 void NotifyUIStateChanged(UIStateChangeType aShowAccelerators,
340 UIStateChangeType aShowFocusRings);
342 #ifdef ACCESSIBILITY
343 // Get the accessible for the window.
344 mozilla::a11y::Accessible* GetRootAccessible();
345 #endif
347 // Return true if this is a simple widget (that is typically not worth
348 // accelerating)
349 bool IsSmallPopup() const;
351 nsPopupLevel PopupLevel() { return mPopupLevel; }
353 virtual LayoutDeviceIntSize
354 ClientToWindowSize(const LayoutDeviceIntSize& aClientSize) override
356 return aClientSize;
359 // return true if this is a popup widget with a native titlebar
360 bool IsPopupWithTitleBar() const
362 return (mWindowType == eWindowType_popup &&
363 mBorderStyle != eBorderStyle_default &&
364 mBorderStyle & eBorderStyle_title);
367 virtual void ReparentNativeWidget(nsIWidget* aNewParent) override {}
369 virtual const SizeConstraints GetSizeConstraints() override;
370 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) override;
372 virtual void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
374 virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
375 const ScrollableLayerGuid& aGuid) override;
377 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
380 * Use this when GetLayerManager() returns a BasicLayerManager
381 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
382 * layer manager to temporarily render into aTarget.
384 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
385 * |aRotation| is the "virtual rotation" to apply when rendering to
386 * the target. When |aRotation| is ROTATION_0,
387 * |aNaturalWidgetBounds| is not used.
389 class AutoLayerManagerSetup {
390 public:
391 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
392 BufferMode aDoubleBuffering,
393 ScreenRotation aRotation = mozilla::ROTATION_0);
394 ~AutoLayerManagerSetup();
395 private:
396 nsBaseWidget* mWidget;
397 RefPtr<BasicLayerManager> mLayerManager;
399 friend class AutoLayerManagerSetup;
401 virtual bool ShouldUseOffMainThreadCompositing();
403 static nsIRollupListener* GetActiveRollupListener();
405 void Shutdown();
407 #if defined(XP_WIN)
408 uint64_t CreateScrollCaptureContainer() override;
409 #endif
411 // These functions should be called at the start and end of a "live" widget
412 // resize (i.e. when the window contents are repainting during the resize,
413 // such as when the user drags a window border). It will suppress the
414 // displayport during the live resize to avoid unneccessary overpainting.
415 void NotifyLiveResizeStarted();
416 void NotifyLiveResizeStopped();
418 #if defined(MOZ_WIDGET_ANDROID)
419 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override {};
420 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset, const CSSToScreenScale& aZoom) override {};
421 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize) override {};
422 #endif
425 * Whether context menus should only appear on mouseup instead of mousedown,
426 * on OSes where they normally appear on mousedown (macOS, *nix).
428 static bool ShowContextMenuAfterMouseUp();
430 protected:
431 // These are methods for CompositorWidgetWrapper, and should only be
432 // accessed from that class. Derived widgets can choose which methods to
433 // implement, or none if supporting out-of-process compositing.
434 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
435 return true;
437 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext)
439 virtual void DrawWindowUnderlay(mozilla::widget::WidgetRenderingContext* aContext,
440 LayoutDeviceIntRect aRect)
442 virtual void DrawWindowOverlay(mozilla::widget::WidgetRenderingContext* aContext,
443 LayoutDeviceIntRect aRect)
445 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
446 virtual already_AddRefed<DrawTarget>
447 StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode)
449 return StartRemoteDrawing();
451 virtual void EndRemoteDrawing()
453 virtual void EndRemoteDrawingInRegion(DrawTarget* aDrawTarget,
454 LayoutDeviceIntRegion& aInvalidRegion)
456 EndRemoteDrawing();
458 virtual void CleanupRemoteDrawing()
460 virtual void CleanupWindowEffects()
462 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
463 return true;
465 virtual uint32_t GetGLFrameBufferFormat();
467 protected:
468 void ResolveIconName(const nsAString &aIconName,
469 const nsAString &aIconSuffix,
470 nsIFile **aResult);
471 virtual void OnDestroy();
472 void BaseCreate(nsIWidget *aParent,
473 nsWidgetInitData* aInitData);
475 virtual void ConfigureAPZCTreeManager();
476 virtual void ConfigureAPZControllerThread();
477 virtual already_AddRefed<GeckoContentController> CreateRootContentController();
479 // Dispatch an event that has already been routed through APZ.
480 nsEventStatus ProcessUntransformedAPZEvent(mozilla::WidgetInputEvent* aEvent,
481 const ScrollableLayerGuid& aGuid,
482 uint64_t aInputBlockId,
483 nsEventStatus aApzResponse);
485 const LayoutDeviceIntRegion RegionFromArray(const nsTArray<LayoutDeviceIntRect>& aRects);
486 void ArrayFromRegion(const LayoutDeviceIntRegion& aRegion,
487 nsTArray<LayoutDeviceIntRect>& aRects);
489 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
490 int32_t aNativeKeyCode,
491 uint32_t aModifierFlags,
492 const nsAString& aCharacters,
493 const nsAString& aUnmodifiedCharacters,
494 nsIObserver* aObserver) override
496 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
497 return NS_ERROR_UNEXPECTED;
500 virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
501 uint32_t aNativeMessage,
502 uint32_t aModifierFlags,
503 nsIObserver* aObserver) override
505 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
506 return NS_ERROR_UNEXPECTED;
509 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
510 nsIObserver* aObserver) override
512 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
513 return NS_ERROR_UNEXPECTED;
516 virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint,
517 uint32_t aNativeMessage,
518 double aDeltaX,
519 double aDeltaY,
520 double aDeltaZ,
521 uint32_t aModifierFlags,
522 uint32_t aAdditionalFlags,
523 nsIObserver* aObserver) override
525 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mousescrollevent");
526 return NS_ERROR_UNEXPECTED;
529 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
530 TouchPointerState aPointerState,
531 LayoutDeviceIntPoint aPoint,
532 double aPointerPressure,
533 uint32_t aPointerOrientation,
534 nsIObserver* aObserver) override
536 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
537 return NS_ERROR_UNEXPECTED;
541 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
542 * has non-native input transaction. Otherwise, returns nullptr.
544 void* GetPseudoIMEContext();
546 protected:
547 // Utility to check if an array of clip rects is equal to our
548 // internally stored clip rect array mClipRects.
549 bool IsWindowClipRegionEqual(const nsTArray<LayoutDeviceIntRect>& aRects);
551 // Stores the clip rectangles in aRects into mClipRects.
552 void StoreWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects);
554 virtual already_AddRefed<nsIWidget>
555 AllocateChildPopupWidget()
557 return nsIWidget::CreateChildWindow();
560 LayerManager* CreateBasicLayerManager();
562 nsPopupType PopupType() const { return mPopupType; }
564 bool HasRemoteContent() const { return mHasRemoteContent; }
566 void NotifyRollupGeometryChange()
568 // XULPopupManager isn't interested in this notification, so only
569 // send it if gRollupListener is set.
570 if (gRollupListener) {
571 gRollupListener->NotifyGeometryChange();
576 * Apply the current size constraints to the given size.
578 * @param aWidth width to constrain
579 * @param aHeight height to constrain
581 void ConstrainSize(int32_t* aWidth, int32_t* aHeight)
583 SizeConstraints c = GetSizeConstraints();
584 *aWidth = std::max(c.mMinSize.width,
585 std::min(c.mMaxSize.width, *aWidth));
586 *aHeight = std::max(c.mMinSize.height,
587 std::min(c.mMaxSize.height, *aHeight));
590 virtual CompositorBridgeChild* GetRemoteRenderer() override;
593 * Notify the widget that this window is being used with OMTC.
595 virtual void WindowUsesOMTC() {}
596 virtual void RegisterTouchWindow() {}
598 nsIDocument* GetDocument() const;
600 void EnsureTextEventDispatcher();
602 // Notify the compositor that a device reset has occurred.
603 void OnRenderingDeviceReset();
605 bool UseAPZ();
607 bool AllowWebRenderForThisWindow();
610 * For widgets that support synthesizing native touch events, this function
611 * can be used to manage the current state of synthetic pointers. Each widget
612 * must maintain its own MultiTouchInput instance and pass it in as the state,
613 * along with the desired parameters for the changes. This function returns
614 * a new MultiTouchInput object that is ready to be dispatched.
616 mozilla::MultiTouchInput
617 UpdateSynthesizedTouchState(mozilla::MultiTouchInput* aState,
618 uint32_t aTime,
619 mozilla::TimeStamp aTimeStamp,
620 uint32_t aPointerId,
621 TouchPointerState aPointerState,
622 LayoutDeviceIntPoint aPoint,
623 double aPointerPressure,
624 uint32_t aPointerOrientation);
627 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
628 * or directly to gecko (if APZ is not enabled). This function must only
629 * be called from the main thread, and if APZ is enabled, that must also be
630 * the APZ controller thread.
632 void DispatchTouchInput(mozilla::MultiTouchInput& aInput);
634 #if defined(XP_WIN)
635 void UpdateScrollCapture() override;
638 * To be overridden by derived classes to return a snapshot that can be used
639 * during scrolling. Returning null means we won't update the container.
640 * @return an already AddRefed SourceSurface containing the snapshot
642 virtual already_AddRefed<SourceSurface> CreateScrollSnapshot()
644 return nullptr;
648 * Used by derived classes to create a fallback scroll image.
649 * @param aSnapshotDrawTarget DrawTarget to fill with fallback image.
651 void DefaultFillScrollCapture(DrawTarget* aSnapshotDrawTarget);
653 RefPtr<ImageContainer> mScrollCaptureContainer;
654 #endif
656 protected:
657 // Returns whether compositing should use an external surface size.
658 virtual bool UseExternalCompositingSurface() const {
659 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();
678 nsIWidgetListener* mWidgetListener;
679 nsIWidgetListener* mAttachedWidgetListener;
680 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
681 RefPtr<LayerManager> mLayerManager;
682 RefPtr<CompositorSession> mCompositorSession;
683 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
685 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
686 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
688 RefPtr<IAPZCTreeManager> mAPZC;
689 RefPtr<GeckoContentController> mRootContentController;
690 RefPtr<APZEventState> mAPZEventState;
691 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback;
692 RefPtr<WidgetShutdownObserver> mShutdownObserver;
693 RefPtr<TextEventDispatcher> mTextEventDispatcher;
694 nsCursor mCursor;
695 nsBorderStyle mBorderStyle;
696 LayoutDeviceIntRect mBounds;
697 LayoutDeviceIntRect* mOriginalBounds;
698 // When this pointer is null, the widget is not clipped
699 mozilla::UniquePtr<LayoutDeviceIntRect[]> mClipRects;
700 uint32_t mClipRectCount;
701 nsSizeMode mSizeMode;
702 nsPopupLevel mPopupLevel;
703 nsPopupType mPopupType;
704 SizeConstraints mSizeConstraints;
705 bool mHasRemoteContent;
707 bool mUpdateCursor;
708 bool mUseAttachedEvents;
709 bool mIMEHasFocus;
710 bool mIsFullyOccluded;
711 static nsIRollupListener* gRollupListener;
713 struct InitialZoomConstraints {
714 InitialZoomConstraints(const uint32_t& aPresShellID,
715 const FrameMetrics::ViewID& aViewID,
716 const ZoomConstraints& aConstraints)
717 : mPresShellID(aPresShellID), mViewID(aViewID), mConstraints(aConstraints)
721 uint32_t mPresShellID;
722 FrameMetrics::ViewID mViewID;
723 ZoomConstraints mConstraints;
726 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
728 // This points to the resize listeners who have been notified that a live
729 // resize is in progress. This should always be empty when a live-resize is
730 // not in progress.
731 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
733 #ifdef DEBUG
734 protected:
735 static nsAutoString debug_GuiEventToString(mozilla::WidgetGUIEvent* aGuiEvent);
736 static bool debug_WantPaintFlashing();
738 static void debug_DumpInvalidate(FILE* aFileOut,
739 nsIWidget* aWidget,
740 const LayoutDeviceIntRect* aRect,
741 const char* aWidgetName,
742 int32_t aWindowID);
744 static void debug_DumpEvent(FILE* aFileOut,
745 nsIWidget* aWidget,
746 mozilla::WidgetGUIEvent* aGuiEvent,
747 const char* aWidgetName,
748 int32_t aWindowID);
750 static void debug_DumpPaintEvent(FILE * aFileOut,
751 nsIWidget * aWidget,
752 const nsIntRegion & aPaintEvent,
753 const char * aWidgetName,
754 int32_t aWindowID);
756 static bool debug_GetCachedBoolPref(const char* aPrefName);
757 #endif
759 private:
760 already_AddRefed<LayerManager>
761 CreateCompositorSession(int aWidth, int aHeight,
762 mozilla::layers::CompositorOptions* aOptionsOut);
765 #endif // nsBaseWidget_h__