Backed out 13 changesets (bug 1640839) for causing bustage on Element.cpp CLOSED...
[gecko.git] / widget / nsBaseWidget.h
blobb16d25ee7c8e7f3f123cdedaeb62c731d2fb648e
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 SetCustomCursorAllowed(bool) override;
191 void ClearCachedCursor() final {
192 mCursor = {};
193 mUpdateCursor = true;
195 void SetTransparencyMode(TransparencyMode aMode) override;
196 TransparencyMode GetTransparencyMode() override;
197 void SetWindowShadowStyle(mozilla::WindowShadow) override {}
198 void SetShowsToolbarButton(bool aShow) override {}
199 void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) override {}
200 void SetWindowAnimationType(WindowAnimationType aType) override {}
201 void HideWindowChrome(bool aShouldHide) override {}
202 bool PrepareForFullscreenTransition(nsISupports** aData) override {
203 return false;
205 void PerformFullscreenTransition(FullscreenTransitionStage aStage,
206 uint16_t aDuration, nsISupports* aData,
207 nsIRunnable* aCallback) override;
208 void CleanupFullscreenTransition() override {}
209 already_AddRefed<Screen> GetWidgetScreen() override;
210 nsresult MakeFullScreen(bool aFullScreen) override;
211 void InfallibleMakeFullScreen(bool aFullScreen);
213 WindowRenderer* GetWindowRenderer() override;
214 bool HasWindowRenderer() const final { return !!mWindowRenderer; }
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. Callers should hold a reference to the widget, since this
222 // function could deallocate the widget if it is unparented.
223 virtual void NotifyCompositorSessionLost(
224 mozilla::layers::CompositorSession* aSession);
226 already_AddRefed<mozilla::CompositorVsyncDispatcher>
227 GetCompositorVsyncDispatcher();
228 virtual void CreateCompositorVsyncDispatcher();
229 virtual void CreateCompositor();
230 virtual void CreateCompositor(int aWidth, int aHeight);
231 virtual void SetCompositorWidgetDelegate(CompositorWidgetDelegate*) {}
232 void PrepareWindowEffects() override {}
233 void UpdateThemeGeometries(
234 const nsTArray<ThemeGeometry>& aThemeGeometries) override {}
235 void SetModal(bool aModal) override {}
236 uint32_t GetMaxTouchPoints() const override;
237 void SetWindowClass(const nsAString& xulWinType, const nsAString& xulWinClass,
238 const nsAString& xulWinName) override {}
239 // Return whether this widget interprets parameters to Move and Resize APIs
240 // as "desktop pixels" rather than "device pixels", and therefore
241 // applies its GetDefaultScale() value to them before using them as mBounds
242 // etc (which are always stored in device pixels).
243 // Note that APIs that -get- the widget's position/size/bounds, rather than
244 // -setting- them (i.e. moving or resizing the widget) will always return
245 // values in the widget's device pixels.
246 bool BoundsUseDesktopPixels() const {
247 return mWindowType <= WindowType::Popup;
249 // Default implementation, to be overridden by platforms where desktop coords
250 // are virtualized and may not correspond to device pixels on the screen.
251 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() override {
252 return mozilla::DesktopToLayoutDeviceScale(1.0);
254 mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScaleByScreen()
255 override;
257 void ConstrainPosition(DesktopIntPoint&) override {}
258 void MoveClient(const DesktopPoint& aOffset) override;
259 void ResizeClient(const DesktopSize& aSize, bool aRepaint) override;
260 void ResizeClient(const DesktopRect& aRect, bool aRepaint) override;
261 LayoutDeviceIntRect GetBounds() override;
262 LayoutDeviceIntRect GetClientBounds() override;
263 LayoutDeviceIntRect GetScreenBounds() override;
264 [[nodiscard]] nsresult GetRestoredBounds(LayoutDeviceIntRect& aRect) override;
265 nsresult SetNonClientMargins(const LayoutDeviceIntMargin&) override;
266 LayoutDeviceIntPoint GetClientOffset() override;
267 void EnableDragDrop(bool aEnable) override{};
268 nsresult AsyncEnableDragDrop(bool aEnable) override;
269 void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin) override;
270 [[nodiscard]] nsresult GetAttention(int32_t aCycleCount) override {
271 return NS_OK;
273 bool HasPendingInputEvent() override;
274 void SetIcon(const nsAString& aIconSpec) override {}
275 bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) override;
276 void FreeNativeData(void* data, uint32_t aDataType) override {}
277 nsresult ActivateNativeMenuItemAt(const nsAString& indexString) override {
278 return NS_ERROR_NOT_IMPLEMENTED;
280 nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) override {
281 return NS_ERROR_NOT_IMPLEMENTED;
283 nsresult NotifyIME(const IMENotification& aIMENotification) final;
284 [[nodiscard]] nsresult AttachNativeKeyEvent(
285 mozilla::WidgetKeyboardEvent& aEvent) override {
286 return NS_ERROR_NOT_IMPLEMENTED;
288 bool ComputeShouldAccelerate();
289 virtual bool WidgetTypeSupportsAcceleration() { return true; }
290 [[nodiscard]] nsresult OnDefaultButtonLoaded(
291 const LayoutDeviceIntRect& aButtonRect) override {
292 return NS_ERROR_NOT_IMPLEMENTED;
294 already_AddRefed<nsIWidget> CreateChild(
295 const LayoutDeviceIntRect& aRect, InitData* aInitData = nullptr,
296 bool aForceUseIWidgetParent = false) override;
297 void AttachViewToTopLevel(bool aUseAttachedEvents) override;
298 nsIWidgetListener* GetAttachedWidgetListener() const override;
299 void SetAttachedWidgetListener(nsIWidgetListener* aListener) override;
300 nsIWidgetListener* GetPreviouslyAttachedWidgetListener() override;
301 void SetPreviouslyAttachedWidgetListener(nsIWidgetListener*) override;
302 NativeIMEContext GetNativeIMEContext() override;
303 TextEventDispatcher* GetTextEventDispatcher() final;
304 TextEventDispatcherListener* GetNativeTextEventDispatcherListener() override;
305 void ZoomToRect(const uint32_t& aPresShellId,
306 const ScrollableLayerGuid::ViewID& aViewId,
307 const CSSRect& aRect, const uint32_t& aFlags) override;
309 // Dispatch an event that must be first be routed through APZ.
310 ContentAndAPZEventStatus DispatchInputEvent(
311 mozilla::WidgetInputEvent* aEvent) override;
312 void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) override;
314 bool DispatchWindowEvent(mozilla::WidgetGUIEvent& event) override;
316 void SetConfirmedTargetAPZC(
317 uint64_t aInputBlockId,
318 const nsTArray<ScrollableLayerGuid>& aTargets) const override;
320 void UpdateZoomConstraints(
321 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
322 const mozilla::Maybe<ZoomConstraints>& aConstraints) override;
324 bool AsyncPanZoomEnabled() const override;
326 void SwipeFinished() override;
327 void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) override;
328 void TrackScrollEventAsSwipe(const mozilla::PanGestureInput& aSwipeStartEvent,
329 uint32_t aAllowedDirections,
330 uint64_t aInputBlockId);
331 struct SwipeInfo {
332 bool wantsSwipe;
333 uint32_t allowedDirections;
335 SwipeInfo SendMayStartSwipe(const mozilla::PanGestureInput& aSwipeStartEvent);
336 // Returns a WidgetWheelEvent which needs to be handled by APZ regardless of
337 // whether |aPanInput| event was used for SwipeTracker or not.
338 mozilla::WidgetWheelEvent MayStartSwipeForAPZ(
339 const mozilla::PanGestureInput& aPanInput,
340 const mozilla::layers::APZEventResult& aApzResult);
342 // Returns true if |aPanInput| event was used for SwipeTracker, false
343 // otherwise.
344 bool MayStartSwipeForNonAPZ(const mozilla::PanGestureInput& aPanInput);
346 void NotifyWindowDestroyed();
347 void NotifySizeMoveDone();
349 using ByMoveToRect = nsIWidgetListener::ByMoveToRect;
350 void NotifyWindowMoved(int32_t aX, int32_t aY,
351 ByMoveToRect = ByMoveToRect::No);
353 // Should be called by derived implementations to notify on system color and
354 // theme changes.
355 void NotifyThemeChanged(mozilla::widget::ThemeChangeKind);
357 void NotifyAPZOfDPIChange();
359 #ifdef ACCESSIBILITY
360 // Get the accessible for the window.
361 mozilla::a11y::LocalAccessible* GetRootAccessible();
362 #endif
364 // Return true if this is a simple widget (that is typically not worth
365 // accelerating)
366 bool IsSmallPopup() const;
368 PopupLevel GetPopupLevel() { return mPopupLevel; }
370 // return true if this is a popup widget with a native titlebar
371 bool IsPopupWithTitleBar() const {
372 return (mWindowType == WindowType::Popup &&
373 mBorderStyle != BorderStyle::Default &&
374 mBorderStyle & BorderStyle::Title);
377 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
379 const SizeConstraints GetSizeConstraints() override;
380 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
382 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
384 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
385 const ScrollableLayerGuid& aGuid) override;
387 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
389 mozilla::layers::LayersId GetRootLayerTreeId() override;
392 * Use this when GetLayerManager() returns a BasicLayerManager
393 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
394 * layer manager to temporarily render into aTarget.
396 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
397 * |aRotation| is the "virtual rotation" to apply when rendering to
398 * the target. When |aRotation| is ROTATION_0,
399 * |aNaturalWidgetBounds| is not used.
401 class AutoLayerManagerSetup {
402 public:
403 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
404 BufferMode aDoubleBuffering);
405 ~AutoLayerManagerSetup();
407 private:
408 nsBaseWidget* mWidget;
409 mozilla::FallbackRenderer* mRenderer = nullptr;
411 friend class AutoLayerManagerSetup;
413 virtual bool ShouldUseOffMainThreadCompositing();
415 static nsIRollupListener* GetActiveRollupListener();
417 void Shutdown();
419 void QuitIME();
421 // These functions should be called at the start and end of a "live" widget
422 // resize (i.e. when the window contents are repainting during the resize,
423 // such as when the user drags a window border). It will suppress the
424 // displayport during the live resize to avoid unneccessary overpainting.
425 void NotifyLiveResizeStarted();
426 void NotifyLiveResizeStopped();
428 #if defined(MOZ_WIDGET_ANDROID)
429 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
430 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
431 const CSSToScreenScale& aZoom) override{};
432 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
433 bool aNeedsYFlip) override{};
434 #endif
436 virtual void LocalesChanged() {}
438 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
440 protected:
441 // These are methods for CompositorWidgetWrapper, and should only be
442 // accessed from that class. Derived widgets can choose which methods to
443 // implement, or none if supporting out-of-process compositing.
444 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
445 return true;
447 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
448 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
449 return nullptr;
451 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
452 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
453 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
454 return StartRemoteDrawing();
456 virtual void EndRemoteDrawing() {}
457 virtual void EndRemoteDrawingInRegion(
458 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
459 EndRemoteDrawing();
461 virtual void CleanupRemoteDrawing() {}
462 virtual void CleanupWindowEffects() {}
463 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
464 return true;
466 virtual uint32_t GetGLFrameBufferFormat();
467 virtual bool CompositorInitiallyPaused() { return false; }
469 protected:
470 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
471 nsIFile** aResult);
472 virtual void OnDestroy();
473 void BaseCreate(nsIWidget* aParent, InitData* aInitData);
475 virtual void ConfigureAPZCTreeManager();
476 virtual void ConfigureAPZControllerThread();
477 virtual already_AddRefed<GeckoContentController>
478 CreateRootContentController();
480 // Dispatch an event that has already been routed through APZ.
481 nsEventStatus ProcessUntransformedAPZEvent(
482 mozilla::WidgetInputEvent* aEvent,
483 const mozilla::layers::APZEventResult& aApzResult);
485 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
486 int32_t aNativeKeyCode,
487 uint32_t aModifierFlags,
488 const nsAString& aCharacters,
489 const nsAString& aUnmodifiedCharacters,
490 nsIObserver* aObserver) override {
491 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
492 return NS_ERROR_UNEXPECTED;
495 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
496 NativeMouseMessage aNativeMessage,
497 mozilla::MouseButton aButton,
498 nsIWidget::Modifiers aModifierFlags,
499 nsIObserver* aObserver) override {
500 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
501 return NS_ERROR_UNEXPECTED;
504 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
505 nsIObserver* aObserver) override {
506 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
507 return NS_ERROR_UNEXPECTED;
510 nsresult SynthesizeNativeMouseScrollEvent(
511 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
512 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
513 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
514 mozilla::widget::AutoObserverNotifier notifier(aObserver,
515 "mousescrollevent");
516 return NS_ERROR_UNEXPECTED;
519 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
520 TouchPointerState aPointerState,
521 LayoutDeviceIntPoint aPoint,
522 double aPointerPressure,
523 uint32_t aPointerOrientation,
524 nsIObserver* aObserver) override {
525 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
526 return NS_ERROR_UNEXPECTED;
529 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
530 float aScale,
531 LayoutDeviceIntPoint aPoint,
532 int32_t aModifierFlags) override {
533 MOZ_RELEASE_ASSERT(
534 false, "This method is not implemented on the current platform");
535 return NS_ERROR_UNEXPECTED;
538 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
539 TouchPointerState aPointerState,
540 LayoutDeviceIntPoint aPoint,
541 double aPressure, uint32_t aRotation,
542 int32_t aTiltX, int32_t aTiltY,
543 int32_t aButton,
544 nsIObserver* aObserver) override {
545 MOZ_RELEASE_ASSERT(
546 false, "This method is not implemented on the current platform");
547 return NS_ERROR_UNEXPECTED;
550 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
551 uint32_t aModifierFlags) override {
552 MOZ_RELEASE_ASSERT(
553 false, "This method is not implemented on the current platform");
554 return NS_ERROR_UNEXPECTED;
557 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
558 LayoutDeviceIntPoint aPoint,
559 double aDeltaX, double aDeltaY,
560 int32_t aModifierFlags,
561 nsIObserver* aObserver) override {
562 MOZ_RELEASE_ASSERT(
563 false, "This method is not implemented on the current platform");
564 return NS_ERROR_UNEXPECTED;
568 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
569 * has non-native input transaction. Otherwise, returns nullptr.
571 void* GetPseudoIMEContext();
573 protected:
574 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
575 return nsIWidget::CreateChildWindow();
578 WindowRenderer* CreateFallbackRenderer();
580 PopupType GetPopupType() const { return mPopupType; }
582 bool HasRemoteContent() const { return mHasRemoteContent; }
585 * Apply the current size constraints to the given size.
587 * @param aWidth width to constrain
588 * @param aHeight height to constrain
590 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
591 SizeConstraints c = GetSizeConstraints();
592 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
593 *aHeight =
594 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
597 CompositorBridgeChild* GetRemoteRenderer() override;
599 void ClearCachedWebrenderResources() override;
601 void ClearWebrenderAnimationResources() override;
603 bool SetNeedFastSnaphot() override;
606 * Notify the widget that this window is being used with OMTC.
608 virtual void WindowUsesOMTC() {}
609 virtual void RegisterTouchWindow() {}
611 mozilla::dom::Document* GetDocument() const;
613 void EnsureTextEventDispatcher();
615 // Notify the compositor that a device reset has occurred.
616 void OnRenderingDeviceReset();
618 bool UseAPZ();
620 bool AllowWebRenderForThisWindow();
623 * For widgets that support synthesizing native touch events, this function
624 * can be used to manage the current state of synthetic pointers. Each widget
625 * must maintain its own MultiTouchInput instance and pass it in as the state,
626 * along with the desired parameters for the changes. This function returns
627 * a new MultiTouchInput object that is ready to be dispatched.
629 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
630 mozilla::MultiTouchInput* aState, mozilla::TimeStamp aTimeStamp,
631 uint32_t aPointerId, TouchPointerState aPointerState,
632 LayoutDeviceIntPoint aPoint, double aPointerPressure,
633 uint32_t aPointerOrientation);
636 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
637 * or directly to gecko (if APZ is not enabled). This function must only
638 * be called from the main thread, and if APZ is enabled, that must also be
639 * the APZ controller thread.
641 void DispatchTouchInput(
642 mozilla::MultiTouchInput& aInput,
643 uint16_t aInputSource =
644 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
647 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
648 * or directly to gecko (if APZ is not enabled). This function must only
649 * be called from the main thread, and if APZ is enabled, that must also be
650 * the APZ controller thread.
652 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
653 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
655 static bool ConvertStatus(nsEventStatus aStatus) {
656 return aStatus == nsEventStatus_eConsumeNoDefault;
659 protected:
660 // Returns whether compositing should use an external surface size.
661 virtual bool UseExternalCompositingSurface() const { return false; }
664 * Starts the OMTC compositor destruction sequence.
666 * When this function returns, the compositor should not be
667 * able to access the opengl context anymore.
668 * It is safe to call it several times if platform implementations
669 * require the compositor to be destroyed before ~nsBaseWidget is
670 * reached (This is the case with gtk2 for instance).
672 virtual void DestroyCompositor();
673 void DestroyLayerManager();
674 void ReleaseContentController();
675 void RevokeTransactionIdAllocator();
677 void FreeShutdownObserver();
678 void FreeLocalesChangedObserver();
680 bool IsPIPWindow() const { return mIsPIPWindow; };
682 nsIWidgetListener* mWidgetListener;
683 nsIWidgetListener* mAttachedWidgetListener;
684 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
685 RefPtr<WindowRenderer> mWindowRenderer;
686 RefPtr<CompositorSession> mCompositorSession;
687 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
689 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
690 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
692 RefPtr<IAPZCTreeManager> mAPZC;
693 RefPtr<GeckoContentController> mRootContentController;
694 RefPtr<APZEventState> mAPZEventState;
695 RefPtr<WidgetShutdownObserver> mShutdownObserver;
696 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
697 RefPtr<TextEventDispatcher> mTextEventDispatcher;
698 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
699 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
700 Cursor mCursor;
701 bool mCustomCursorAllowed = true;
702 BorderStyle mBorderStyle;
703 LayoutDeviceIntRect mBounds;
704 bool mIsTiled;
705 PopupLevel mPopupLevel;
706 PopupType mPopupType;
707 SizeConstraints mSizeConstraints;
708 bool mHasRemoteContent;
710 struct FullscreenSavedState {
711 DesktopRect windowRect;
712 DesktopRect screenRect;
714 mozilla::Maybe<FullscreenSavedState> mSavedBounds;
716 bool mUpdateCursor;
717 bool mUseAttachedEvents;
718 bool mIMEHasFocus;
719 bool mIMEHasQuit;
720 bool mIsFullyOccluded;
721 bool mNeedFastSnaphot;
722 // This flag is only used when APZ is off. It indicates that the current pan
723 // gesture was processed as a swipe. Sometimes the swipe animation can finish
724 // before momentum events of the pan gesture have stopped firing, so this
725 // flag tells us that we shouldn't allow the remaining events to cause
726 // scrolling. It is reset to false once a new gesture starts (as indicated by
727 // a PANGESTURE_(MAY)START event).
728 bool mCurrentPanGestureBelongsToSwipe;
730 // It's PictureInPicture window.
731 bool mIsPIPWindow : 1;
733 struct InitialZoomConstraints {
734 InitialZoomConstraints(const uint32_t& aPresShellID,
735 const ScrollableLayerGuid::ViewID& aViewID,
736 const ZoomConstraints& aConstraints)
737 : mPresShellID(aPresShellID),
738 mViewID(aViewID),
739 mConstraints(aConstraints) {}
741 uint32_t mPresShellID;
742 ScrollableLayerGuid::ViewID mViewID;
743 ZoomConstraints mConstraints;
746 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
748 // This points to the resize listeners who have been notified that a live
749 // resize is in progress. This should always be empty when a live-resize is
750 // not in progress.
751 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
753 #ifdef DEBUG
754 protected:
755 static nsAutoString debug_GuiEventToString(
756 mozilla::WidgetGUIEvent* aGuiEvent);
758 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
759 const LayoutDeviceIntRect* aRect,
760 const char* aWidgetName, int32_t aWindowID);
762 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
763 mozilla::WidgetGUIEvent* aGuiEvent,
764 const char* aWidgetName, int32_t aWindowID);
766 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
767 const nsIntRegion& aPaintEvent,
768 const char* aWidgetName, int32_t aWindowID);
770 static bool debug_GetCachedBoolPref(const char* aPrefName);
771 #endif
773 private:
774 already_AddRefed<mozilla::layers::WebRenderLayerManager>
775 CreateCompositorSession(int aWidth, int aHeight,
776 mozilla::layers::CompositorOptions* aOptionsOut);
779 #endif // nsBaseWidget_h__