Bug 1755481: correct documentation of `nsIClipboard::getData`. r=mccr8
[gecko.git] / widget / nsBaseWidget.h
blob55014e4d9551065b2bb9be4a2293ac4854ac8963
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 NS_DECL_THREADSAFE_ISUPPORTS
164 // nsIWidget interface
165 void CaptureMouse(bool aCapture) override {}
166 void CaptureRollupEvents(nsIRollupListener* aListener,
167 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 SetSizeMode(nsSizeMode aMode) override;
184 nsSizeMode SizeMode() override { return mSizeMode; }
185 void GetWorkspaceID(nsAString& workspaceID) override;
186 void MoveToWorkspace(const nsAString& workspaceID) override;
187 bool IsTiled() const override { return mIsTiled; }
189 bool IsFullyOccluded() const override { return mIsFullyOccluded; }
191 void SetCursor(const Cursor&) override;
192 void ClearCachedCursor() final {
193 mCursor = {};
194 mUpdateCursor = true;
196 void SetTransparencyMode(nsTransparencyMode aMode) override;
197 nsTransparencyMode GetTransparencyMode() override;
198 void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle) override {}
199 void SetShowsToolbarButton(bool aShow) override {}
200 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) override {}
201 void SetWindowAnimationType(WindowAnimationType aType) override {}
202 void HideWindowChrome(bool aShouldHide) override {}
203 bool PrepareForFullscreenTransition(nsISupports** aData) override {
204 return false;
206 void PerformFullscreenTransition(FullscreenTransitionStage aStage,
207 uint16_t aDuration, nsISupports* aData,
208 nsIRunnable* aCallback) override;
209 void CleanupFullscreenTransition() override {}
210 already_AddRefed<nsIScreen> GetWidgetScreen() override;
211 nsresult MakeFullScreen(bool aFullScreen) override;
212 void InfallibleMakeFullScreen(bool aFullScreen);
214 WindowRenderer* GetWindowRenderer() override;
216 // A remote compositor session tied to this window has been lost and IPC
217 // messages will no longer work. The widget must clean up any lingering
218 // resources and possibly schedule another paint.
220 // A reference to the session object is held until this function has
221 // returned.
222 virtual void NotifyCompositorSessionLost(
223 mozilla::layers::CompositorSession* aSession);
225 already_AddRefed<mozilla::CompositorVsyncDispatcher>
226 GetCompositorVsyncDispatcher();
227 virtual void CreateCompositorVsyncDispatcher();
228 virtual void CreateCompositor();
229 virtual void CreateCompositor(int aWidth, int aHeight);
230 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate*) {}
231 void PrepareWindowEffects() override {}
232 void UpdateThemeGeometries(
233 const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
234 void SetModal(bool aModal) override {}
235 uint32_t GetMaxTouchPoints() const override;
236 void SetWindowClass(const nsAString& xulWinType) 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 <= eWindowType_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(LayoutDeviceIntMargin& aMargins) override;
264 LayoutDeviceIntPoint GetClientOffset() override;
265 void EnableDragDrop(bool aEnable) override{};
266 nsresult AsyncEnableDragDrop(bool aEnable) override;
267 [[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override {
268 return NS_OK;
270 bool HasPendingInputEvent() override;
271 void SetIcon(const nsAString& aIconSpec) override {}
272 void SetDrawsInTitlebar(bool aState) override {}
273 bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
274 void FreeNativeData(void* data, uint32_t aDataType) override {}
275 [[nodiscard]] nsresult BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
276 int32_t aHorizontal,
277 int32_t aVertical) override {
278 return NS_ERROR_NOT_IMPLEMENTED;
280 nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override {
281 return NS_ERROR_NOT_IMPLEMENTED;
283 nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override {
284 return NS_ERROR_NOT_IMPLEMENTED;
286 nsresult NotifyIME(const IMENotification& aIMENotification) final;
287 [[nodiscard]] nsresult AttachNativeKeyEvent(
288 mozilla::WidgetKeyboardEvent& aEvent) override {
289 return NS_ERROR_NOT_IMPLEMENTED;
291 bool ComputeShouldAccelerate();
292 virtual bool WidgetTypeSupportsAcceleration() { return true; }
293 [[nodiscard]] nsresult OnDefaultButtonLoaded(
294 const LayoutDeviceIntRect& aButtonRect) override {
295 return NS_ERROR_NOT_IMPLEMENTED;
297 already_AddRefed<nsIWidget> CreateChild(
298 const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData = nullptr,
299 bool aForceUseIWidgetParent = false) override;
300 void AttachViewToTopLevel(bool aUseAttachedEvents) override;
301 nsIWidgetListener* GetAttachedWidgetListener() const override;
302 void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
303 nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
304 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener*) override;
305 NativeIMEContext GetNativeIMEContext() override;
306 TextEventDispatcher* GetTextEventDispatcher() final;
307 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
308 void ZoomToRect(const uint32_t& aPresShellId,
309 const ScrollableLayerGuid::ViewID& aViewId,
310 const CSSRect& aRect, const uint32_t& aFlags) override;
312 // Dispatch an event that must be first be routed through APZ.
313 ContentAndAPZEventStatus DispatchInputEvent(
314 mozilla::WidgetInputEvent* aEvent) override;
315 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
317 bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event) override;
319 void SetConfirmedTargetAPZC(
320 uint64_t aInputBlockId,
321 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
323 void UpdateZoomConstraints(
324 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
325 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
327 bool AsyncPanZoomEnabled() const override;
329 void SwipeFinished() override;
330 void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
331 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
332 uint32_t aAllowedDirections);
333 struct SwipeInfo {
334 bool wantsSwipe;
335 uint32_t allowedDirections;
337 SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
338 enum class CanTriggerSwipe : bool {
339 No = false,
340 Yes = true,
342 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
343 // whether |aPanInput| event was used for SwipeTracker or not.
344 mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
345 const mozilla::PanGestureInput& aPanInput,
346 const mozilla::layers::APZEventResult& aApzResult,
347 CanTriggerSwipe aCanTriggerSwipe);
349 // Returns true if |aPanInput| event was used for SwipeTracker, false
350 // otherwise.
351 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput,
352 CanTriggerSwipe aCanTriggerSwipe);
354 void NotifyWindowDestroyed();
355 void NotifySizeMoveDone();
356 void NotifyWindowMoved(int32_t aX, int32_t aY);
358 void SetNativeData(uint32_t aDataType, uintptr_t aVal) override {}
360 // Should be called by derived implementations to notify on system color and
361 // theme changes.
362 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
363 void NotifyUIStateChanged(UIStateChangeType aShowFocusRings);
365 #ifdef ACCESSIBILITY
366 // Get the accessible for the window.
367 mozilla::a11y::LocalAccessible* GetRootAccessible();
368 #endif
370 // Return true if this is a simple widget (that is typically not worth
371 // accelerating)
372 bool IsSmallPopup() const;
374 nsPopupLevel PopupLevel() { return mPopupLevel; }
376 LayoutDeviceIntSize ClientToWindowSize(
377 const LayoutDeviceIntSize& aClientSize) override {
378 return aClientSize;
381 // return true if this is a popup widget with a native titlebar
382 bool IsPopupWithTitleBar() const {
383 return (mWindowType == eWindowType_popup &&
384 mBorderStyle != eBorderStyle_default &&
385 mBorderStyle & eBorderStyle_title);
388 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
390 const SizeConstraints GetSizeConstraints() override;
391 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
393 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
395 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
396 const ScrollableLayerGuid& aGuid) override;
398 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
400 mozilla::layers::LayersId GetRootLayerTreeId() override;
403 * Use this when GetLayerManager() returns a BasicLayerManager
404 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
405 * layer manager to temporarily render into aTarget.
407 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
408 * |aRotation| is the "virtual rotation" to apply when rendering to
409 * the target. When |aRotation| is ROTATION_0,
410 * |aNaturalWidgetBounds| is not used.
412 class AutoLayerManagerSetup {
413 public:
414 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
415 BufferMode aDoubleBuffering);
416 ~AutoLayerManagerSetup();
418 private:
419 nsBaseWidget* mWidget;
420 mozilla::FallbackRenderer* mRenderer = nullptr;
422 friend class AutoLayerManagerSetup;
424 virtual bool ShouldUseOffMainThreadCompositing();
426 static nsIRollupListener* GetActiveRollupListener();
428 void Shutdown();
430 void QuitIME();
432 // These functions should be called at the start and end of a "live" widget
433 // resize (i.e. when the window contents are repainting during the resize,
434 // such as when the user drags a window border). It will suppress the
435 // displayport during the live resize to avoid unneccessary overpainting.
436 void NotifyLiveResizeStarted();
437 void NotifyLiveResizeStopped();
439 #if defined(MOZ_WIDGET_ANDROID)
440 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
441 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
442 const CSSToScreenScale& aZoom) override{};
443 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
444 bool aNeedsYFlip) override{};
445 #endif
447 virtual void LocalesChanged() {}
449 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
451 protected:
452 // These are methods for CompositorWidgetWrapper, and should only be
453 // accessed from that class. Derived widgets can choose which methods to
454 // implement, or none if supporting out-of-process compositing.
455 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
456 return true;
458 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
459 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
460 return nullptr;
462 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
463 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
464 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
465 return StartRemoteDrawing();
467 virtual void EndRemoteDrawing() {}
468 virtual void EndRemoteDrawingInRegion(
469 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
470 EndRemoteDrawing();
472 virtual void CleanupRemoteDrawing() {}
473 virtual void CleanupWindowEffects() {}
474 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
475 return true;
477 virtual uint32_t GetGLFrameBufferFormat();
478 virtual bool CompositorInitiallyPaused() { return false; }
480 protected:
481 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
482 nsIFile** aResult);
483 virtual void OnDestroy();
484 void BaseCreate(nsIWidget* aParent, nsWidgetInitData* aInitData);
486 virtual void ConfigureAPZCTreeManager();
487 virtual void ConfigureAPZControllerThread();
488 virtual already_AddRefed<GeckoContentController>
489 CreateRootContentController();
491 // Dispatch an event that has already been routed through APZ.
492 nsEventStatus ProcessUntransformedAPZEvent(
493 mozilla::WidgetInputEvent* aEvent,
494 const mozilla::layers::APZEventResult& aApzResult);
496 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
497 int32_t aNativeKeyCode,
498 uint32_t aModifierFlags,
499 const nsAString& aCharacters,
500 const nsAString& aUnmodifiedCharacters,
501 nsIObserver* aObserver) override {
502 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
503 return NS_ERROR_UNEXPECTED;
506 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
507 NativeMouseMessage aNativeMessage,
508 mozilla::MouseButton aButton,
509 nsIWidget::Modifiers aModifierFlags,
510 nsIObserver* aObserver) override {
511 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
512 return NS_ERROR_UNEXPECTED;
515 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
516 nsIObserver* aObserver) override {
517 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
518 return NS_ERROR_UNEXPECTED;
521 nsresult SynthesizeNativeMouseScrollEvent(
522 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
523 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
524 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
525 mozilla::widget::AutoObserverNotifier notifier(aObserver,
526 "mousescrollevent");
527 return NS_ERROR_UNEXPECTED;
530 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
531 TouchPointerState aPointerState,
532 LayoutDeviceIntPoint aPoint,
533 double aPointerPressure,
534 uint32_t aPointerOrientation,
535 nsIObserver* aObserver) override {
536 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
537 return NS_ERROR_UNEXPECTED;
540 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
541 float aScale,
542 LayoutDeviceIntPoint aPoint,
543 int32_t aModifierFlags) override {
544 MOZ_RELEASE_ASSERT(
545 false, "This method is not implemented on the current platform");
546 return NS_ERROR_UNEXPECTED;
549 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
550 TouchPointerState aPointerState,
551 LayoutDeviceIntPoint aPoint,
552 double aPressure, uint32_t aRotation,
553 int32_t aTiltX, int32_t aTiltY,
554 int32_t aButton,
555 nsIObserver* aObserver) override {
556 MOZ_RELEASE_ASSERT(
557 false, "This method is not implemented on the current platform");
558 return NS_ERROR_UNEXPECTED;
561 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
562 uint32_t aModifierFlags) override {
563 MOZ_RELEASE_ASSERT(
564 false, "This method is not implemented on the current platform");
565 return NS_ERROR_UNEXPECTED;
568 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
569 LayoutDeviceIntPoint aPoint,
570 double aDeltaX, double aDeltaY,
571 int32_t aModifierFlags) override {
572 MOZ_RELEASE_ASSERT(
573 false, "This method is not implemented on the current platform");
574 return NS_ERROR_UNEXPECTED;
578 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
579 * has non-native input transaction. Otherwise, returns nullptr.
581 void* GetPseudoIMEContext();
583 protected:
584 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
585 return nsIWidget::CreateChildWindow();
588 WindowRenderer* CreateFallbackRenderer();
590 nsPopupType PopupType() const { return mPopupType; }
592 bool HasRemoteContent() const { return mHasRemoteContent; }
594 void NotifyRollupGeometryChange() {
595 // XULPopupManager isn't interested in this notification, so only
596 // send it if gRollupListener is set.
597 if (gRollupListener) {
598 gRollupListener->NotifyGeometryChange();
603 * Apply the current size constraints to the given size.
605 * @param aWidth width to constrain
606 * @param aHeight height to constrain
608 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
609 SizeConstraints c = GetSizeConstraints();
610 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
611 *aHeight =
612 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
615 CompositorBridgeChild* GetRemoteRenderer() override;
617 void ClearCachedWebrenderResources() override;
620 * Notify the widget that this window is being used with OMTC.
622 virtual void WindowUsesOMTC() {}
623 virtual void RegisterTouchWindow() {}
625 mozilla::dom::Document* GetDocument() const;
627 void EnsureTextEventDispatcher();
629 // Notify the compositor that a device reset has occurred.
630 void OnRenderingDeviceReset();
632 bool UseAPZ();
634 bool AllowWebRenderForThisWindow();
637 * For widgets that support synthesizing native touch events, this function
638 * can be used to manage the current state of synthetic pointers. Each widget
639 * must maintain its own MultiTouchInput instance and pass it in as the state,
640 * along with the desired parameters for the changes. This function returns
641 * a new MultiTouchInput object that is ready to be dispatched.
643 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
644 mozilla::MultiTouchInput* aState, uint32_t aTime,
645 mozilla::TimeStamp aTimeStamp, uint32_t aPointerId,
646 TouchPointerState aPointerState, LayoutDeviceIntPoint aPoint,
647 double aPointerPressure, uint32_t aPointerOrientation);
650 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
651 * or directly to gecko (if APZ is not enabled). This function must only
652 * be called from the main thread, and if APZ is enabled, that must also be
653 * the APZ controller thread.
655 void DispatchTouchInput(
656 mozilla::MultiTouchInput& aInput,
657 uint16_t aInputSource =
658 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
661 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
662 * or directly to gecko (if APZ is not enabled). This function must only
663 * be called from the main thread, and if APZ is enabled, that must also be
664 * the APZ controller thread.
666 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
667 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
669 static bool ConvertStatus(nsEventStatus aStatus) {
670 return aStatus == nsEventStatus_eConsumeNoDefault;
673 protected:
674 // Returns whether compositing should use an external surface size.
675 virtual bool UseExternalCompositingSurface() const { return false; }
678 * Starts the OMTC compositor destruction sequence.
680 * When this function returns, the compositor should not be
681 * able to access the opengl context anymore.
682 * It is safe to call it several times if platform implementations
683 * require the compositor to be destroyed before ~nsBaseWidget is
684 * reached (This is the case with gtk2 for instance).
686 virtual void DestroyCompositor();
687 void DestroyLayerManager();
688 void ReleaseContentController();
689 void RevokeTransactionIdAllocator();
691 void FreeShutdownObserver();
692 void FreeLocalesChangedObserver();
694 nsIWidgetListener* mWidgetListener;
695 nsIWidgetListener* mAttachedWidgetListener;
696 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
697 RefPtr<WindowRenderer> mWindowRenderer;
698 RefPtr<CompositorSession> mCompositorSession;
699 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
701 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
702 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
704 RefPtr<IAPZCTreeManager> mAPZC;
705 RefPtr<GeckoContentController> mRootContentController;
706 RefPtr<APZEventState> mAPZEventState;
707 RefPtr<WidgetShutdownObserver> mShutdownObserver;
708 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
709 RefPtr<TextEventDispatcher> mTextEventDispatcher;
710 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
711 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
712 Cursor mCursor;
713 nsBorderStyle mBorderStyle;
714 LayoutDeviceIntRect mBounds;
715 LayoutDeviceIntRect* mOriginalBounds;
716 nsSizeMode mSizeMode;
717 bool mIsTiled;
718 nsPopupLevel mPopupLevel;
719 nsPopupType mPopupType;
720 SizeConstraints mSizeConstraints;
721 bool mHasRemoteContent;
722 bool mFissionWindow;
724 bool mUpdateCursor;
725 bool mUseAttachedEvents;
726 bool mIMEHasFocus;
727 bool mIMEHasQuit;
728 bool mIsFullyOccluded;
729 // This flag is only used when APZ is off. It indicates that the current pan
730 // gesture was processed as a swipe. Sometimes the swipe animation can finish
731 // before momentum events of the pan gesture have stopped firing, so this
732 // flag tells us that we shouldn't allow the remaining events to cause
733 // scrolling. It is reset to false once a new gesture starts (as indicated by
734 // a PANGESTURE_(MAY)START event).
735 bool mCurrentPanGestureBelongsToSwipe;
737 static nsIRollupListener* gRollupListener;
739 struct InitialZoomConstraints {
740 InitialZoomConstraints(const uint32_t& aPresShellID,
741 const ScrollableLayerGuid::ViewID& aViewID,
742 const ZoomConstraints& aConstraints)
743 : mPresShellID(aPresShellID),
744 mViewID(aViewID),
745 mConstraints(aConstraints) {}
747 uint32_t mPresShellID;
748 ScrollableLayerGuid::ViewID mViewID;
749 ZoomConstraints mConstraints;
752 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
754 // This points to the resize listeners who have been notified that a live
755 // resize is in progress. This should always be empty when a live-resize is
756 // not in progress.
757 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
759 #ifdef DEBUG
760 protected:
761 static nsAutoString debug_GuiEventToString(
762 mozilla::WidgetGUIEvent* aGuiEvent);
764 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
765 const LayoutDeviceIntRect* aRect,
766 const char* aWidgetName, int32_t aWindowID);
768 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
769 mozilla::WidgetGUIEvent* aGuiEvent,
770 const char* aWidgetName, int32_t aWindowID);
772 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
773 const nsIntRegion& aPaintEvent,
774 const char* aWidgetName, int32_t aWindowID);
776 static bool debug_GetCachedBoolPref(const char* aPrefName);
777 #endif
779 private:
780 already_AddRefed<mozilla::layers::WebRenderLayerManager>
781 CreateCompositorSession(int aWidth, int aHeight,
782 mozilla::layers::CompositorOptions* aOptionsOut);
785 #endif // nsBaseWidget_h__