Backed out 2 changesets (bug 1875412) for causing failures on browser_startup_content...
[gecko.git] / widget / nsBaseWidget.h
blob8b6e8ad0eb2944a4a6cc0393df6fc31994065347
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 #ifdef ACCESSIBILITY
358 // Get the accessible for the window.
359 mozilla::a11y::LocalAccessible* GetRootAccessible();
360 #endif
362 // Return true if this is a simple widget (that is typically not worth
363 // accelerating)
364 bool IsSmallPopup() const;
366 PopupLevel GetPopupLevel() { return mPopupLevel; }
368 // return true if this is a popup widget with a native titlebar
369 bool IsPopupWithTitleBar() const {
370 return (mWindowType == WindowType::Popup &&
371 mBorderStyle != BorderStyle::Default &&
372 mBorderStyle & BorderStyle::Title);
375 void ReparentNativeWidget(nsIWidget* aNewParent) override {}
377 const SizeConstraints GetSizeConstraints() override;
378 void SetSizeConstraints(const SizeConstraints& aConstraints) override;
380 void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) override;
382 bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
383 const ScrollableLayerGuid& aGuid) override;
385 void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) override;
387 mozilla::layers::LayersId GetRootLayerTreeId() override;
390 * Use this when GetLayerManager() returns a BasicLayerManager
391 * (nsBaseWidget::GetLayerManager() does). This sets up the widget's
392 * layer manager to temporarily render into aTarget.
394 * |aNaturalWidgetBounds| is the un-rotated bounds of |aWidget|.
395 * |aRotation| is the "virtual rotation" to apply when rendering to
396 * the target. When |aRotation| is ROTATION_0,
397 * |aNaturalWidgetBounds| is not used.
399 class AutoLayerManagerSetup {
400 public:
401 AutoLayerManagerSetup(nsBaseWidget* aWidget, gfxContext* aTarget,
402 BufferMode aDoubleBuffering);
403 ~AutoLayerManagerSetup();
405 private:
406 nsBaseWidget* mWidget;
407 mozilla::FallbackRenderer* mRenderer = nullptr;
409 friend class AutoLayerManagerSetup;
411 virtual bool ShouldUseOffMainThreadCompositing();
413 static nsIRollupListener* GetActiveRollupListener();
415 void Shutdown();
417 void QuitIME();
419 // These functions should be called at the start and end of a "live" widget
420 // resize (i.e. when the window contents are repainting during the resize,
421 // such as when the user drags a window border). It will suppress the
422 // displayport during the live resize to avoid unneccessary overpainting.
423 void NotifyLiveResizeStarted();
424 void NotifyLiveResizeStopped();
426 #if defined(MOZ_WIDGET_ANDROID)
427 void RecvToolbarAnimatorMessageFromCompositor(int32_t) override{};
428 void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
429 const CSSToScreenScale& aZoom) override{};
430 void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize,
431 bool aNeedsYFlip) override{};
432 #endif
434 virtual void LocalesChanged() {}
436 virtual void NotifyOcclusionState(mozilla::widget::OcclusionState aState) {}
438 protected:
439 // These are methods for CompositorWidgetWrapper, and should only be
440 // accessed from that class. Derived widgets can choose which methods to
441 // implement, or none if supporting out-of-process compositing.
442 virtual bool PreRender(mozilla::widget::WidgetRenderingContext* aContext) {
443 return true;
445 virtual void PostRender(mozilla::widget::WidgetRenderingContext* aContext) {}
446 virtual RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() {
447 return nullptr;
449 virtual already_AddRefed<DrawTarget> StartRemoteDrawing();
450 virtual already_AddRefed<DrawTarget> StartRemoteDrawingInRegion(
451 const LayoutDeviceIntRegion& aInvalidRegion, BufferMode* aBufferMode) {
452 return StartRemoteDrawing();
454 virtual void EndRemoteDrawing() {}
455 virtual void EndRemoteDrawingInRegion(
456 DrawTarget* aDrawTarget, const LayoutDeviceIntRegion& aInvalidRegion) {
457 EndRemoteDrawing();
459 virtual void CleanupRemoteDrawing() {}
460 virtual void CleanupWindowEffects() {}
461 virtual bool InitCompositor(mozilla::layers::Compositor* aCompositor) {
462 return true;
464 virtual uint32_t GetGLFrameBufferFormat();
465 virtual bool CompositorInitiallyPaused() { return false; }
467 protected:
468 void ResolveIconName(const nsAString& aIconName, const nsAString& aIconSuffix,
469 nsIFile** aResult);
470 virtual void OnDestroy();
471 void BaseCreate(nsIWidget* aParent, InitData* aInitData);
473 virtual void ConfigureAPZCTreeManager();
474 virtual void ConfigureAPZControllerThread();
475 virtual already_AddRefed<GeckoContentController>
476 CreateRootContentController();
478 // Dispatch an event that has already been routed through APZ.
479 nsEventStatus ProcessUntransformedAPZEvent(
480 mozilla::WidgetInputEvent* aEvent,
481 const mozilla::layers::APZEventResult& aApzResult);
483 nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
484 int32_t aNativeKeyCode,
485 uint32_t aModifierFlags,
486 const nsAString& aCharacters,
487 const nsAString& aUnmodifiedCharacters,
488 nsIObserver* aObserver) override {
489 mozilla::widget::AutoObserverNotifier notifier(aObserver, "keyevent");
490 return NS_ERROR_UNEXPECTED;
493 nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
494 NativeMouseMessage aNativeMessage,
495 mozilla::MouseButton aButton,
496 nsIWidget::Modifiers aModifierFlags,
497 nsIObserver* aObserver) override {
498 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
499 return NS_ERROR_UNEXPECTED;
502 nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
503 nsIObserver* aObserver) override {
504 mozilla::widget::AutoObserverNotifier notifier(aObserver, "mouseevent");
505 return NS_ERROR_UNEXPECTED;
508 nsresult SynthesizeNativeMouseScrollEvent(
509 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
510 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
511 uint32_t aAdditionalFlags, nsIObserver* aObserver) override {
512 mozilla::widget::AutoObserverNotifier notifier(aObserver,
513 "mousescrollevent");
514 return NS_ERROR_UNEXPECTED;
517 nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
518 TouchPointerState aPointerState,
519 LayoutDeviceIntPoint aPoint,
520 double aPointerPressure,
521 uint32_t aPointerOrientation,
522 nsIObserver* aObserver) override {
523 mozilla::widget::AutoObserverNotifier notifier(aObserver, "touchpoint");
524 return NS_ERROR_UNEXPECTED;
527 nsresult SynthesizeNativeTouchPadPinch(TouchpadGesturePhase aEventPhase,
528 float aScale,
529 LayoutDeviceIntPoint aPoint,
530 int32_t aModifierFlags) override {
531 MOZ_RELEASE_ASSERT(
532 false, "This method is not implemented on the current platform");
533 return NS_ERROR_UNEXPECTED;
536 nsresult SynthesizeNativePenInput(uint32_t aPointerId,
537 TouchPointerState aPointerState,
538 LayoutDeviceIntPoint aPoint,
539 double aPressure, uint32_t aRotation,
540 int32_t aTiltX, int32_t aTiltY,
541 int32_t aButton,
542 nsIObserver* aObserver) override {
543 MOZ_RELEASE_ASSERT(
544 false, "This method is not implemented on the current platform");
545 return NS_ERROR_UNEXPECTED;
548 nsresult SynthesizeNativeTouchpadDoubleTap(LayoutDeviceIntPoint aPoint,
549 uint32_t aModifierFlags) override {
550 MOZ_RELEASE_ASSERT(
551 false, "This method is not implemented on the current platform");
552 return NS_ERROR_UNEXPECTED;
555 nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
556 LayoutDeviceIntPoint aPoint,
557 double aDeltaX, double aDeltaY,
558 int32_t aModifierFlags,
559 nsIObserver* aObserver) override {
560 MOZ_RELEASE_ASSERT(
561 false, "This method is not implemented on the current platform");
562 return NS_ERROR_UNEXPECTED;
566 * GetPseudoIMEContext() returns pseudo IME context when TextEventDispatcher
567 * has non-native input transaction. Otherwise, returns nullptr.
569 void* GetPseudoIMEContext();
571 protected:
572 virtual already_AddRefed<nsIWidget> AllocateChildPopupWidget() {
573 return nsIWidget::CreateChildWindow();
576 WindowRenderer* CreateFallbackRenderer();
578 PopupType GetPopupType() const { return mPopupType; }
580 bool HasRemoteContent() const { return mHasRemoteContent; }
583 * Apply the current size constraints to the given size.
585 * @param aWidth width to constrain
586 * @param aHeight height to constrain
588 void ConstrainSize(int32_t* aWidth, int32_t* aHeight) override {
589 SizeConstraints c = GetSizeConstraints();
590 *aWidth = std::max(c.mMinSize.width, std::min(c.mMaxSize.width, *aWidth));
591 *aHeight =
592 std::max(c.mMinSize.height, std::min(c.mMaxSize.height, *aHeight));
595 CompositorBridgeChild* GetRemoteRenderer() override;
597 void ClearCachedWebrenderResources() override;
599 void ClearWebrenderAnimationResources() override;
601 bool SetNeedFastSnaphot() override;
604 * Notify the widget that this window is being used with OMTC.
606 virtual void WindowUsesOMTC() {}
607 virtual void RegisterTouchWindow() {}
609 mozilla::dom::Document* GetDocument() const;
611 void EnsureTextEventDispatcher();
613 // Notify the compositor that a device reset has occurred.
614 void OnRenderingDeviceReset();
616 bool UseAPZ();
618 bool AllowWebRenderForThisWindow();
621 * For widgets that support synthesizing native touch events, this function
622 * can be used to manage the current state of synthetic pointers. Each widget
623 * must maintain its own MultiTouchInput instance and pass it in as the state,
624 * along with the desired parameters for the changes. This function returns
625 * a new MultiTouchInput object that is ready to be dispatched.
627 mozilla::MultiTouchInput UpdateSynthesizedTouchState(
628 mozilla::MultiTouchInput* aState, mozilla::TimeStamp aTimeStamp,
629 uint32_t aPointerId, TouchPointerState aPointerState,
630 LayoutDeviceIntPoint aPoint, double aPointerPressure,
631 uint32_t aPointerOrientation);
634 * Dispatch the given MultiTouchInput through APZ to Gecko (if APZ is enabled)
635 * or directly to gecko (if APZ is not enabled). This function must only
636 * be called from the main thread, and if APZ is enabled, that must also be
637 * the APZ controller thread.
639 void DispatchTouchInput(
640 mozilla::MultiTouchInput& aInput,
641 uint16_t aInputSource =
642 mozilla::dom::MouseEvent_Binding::MOZ_SOURCE_TOUCH);
645 * Dispatch the given PanGestureInput through APZ to Gecko (if APZ is enabled)
646 * or directly to gecko (if APZ is not enabled). This function must only
647 * be called from the main thread, and if APZ is enabled, that must also be
648 * the APZ controller thread.
650 void DispatchPanGestureInput(mozilla::PanGestureInput& aInput);
651 void DispatchPinchGestureInput(mozilla::PinchGestureInput& aInput);
653 static bool ConvertStatus(nsEventStatus aStatus) {
654 return aStatus == nsEventStatus_eConsumeNoDefault;
657 protected:
658 // Returns whether compositing should use an external surface size.
659 virtual bool UseExternalCompositingSurface() const { return false; }
662 * Starts the OMTC compositor destruction sequence.
664 * When this function returns, the compositor should not be
665 * able to access the opengl context anymore.
666 * It is safe to call it several times if platform implementations
667 * require the compositor to be destroyed before ~nsBaseWidget is
668 * reached (This is the case with gtk2 for instance).
670 virtual void DestroyCompositor();
671 void DestroyLayerManager();
672 void ReleaseContentController();
673 void RevokeTransactionIdAllocator();
675 void FreeShutdownObserver();
676 void FreeLocalesChangedObserver();
678 bool IsPIPWindow() const { return mIsPIPWindow; };
680 nsIWidgetListener* mWidgetListener;
681 nsIWidgetListener* mAttachedWidgetListener;
682 nsIWidgetListener* mPreviouslyAttachedWidgetListener;
683 RefPtr<WindowRenderer> mWindowRenderer;
684 RefPtr<CompositorSession> mCompositorSession;
685 RefPtr<CompositorBridgeChild> mCompositorBridgeChild;
687 mozilla::UniquePtr<mozilla::Mutex> mCompositorVsyncDispatcherLock;
688 RefPtr<mozilla::CompositorVsyncDispatcher> mCompositorVsyncDispatcher;
690 RefPtr<IAPZCTreeManager> mAPZC;
691 RefPtr<GeckoContentController> mRootContentController;
692 RefPtr<APZEventState> mAPZEventState;
693 RefPtr<WidgetShutdownObserver> mShutdownObserver;
694 RefPtr<LocalesChangedObserver> mLocalesChangedObserver;
695 RefPtr<TextEventDispatcher> mTextEventDispatcher;
696 RefPtr<mozilla::SwipeTracker> mSwipeTracker;
697 mozilla::UniquePtr<mozilla::SwipeEventQueue> mSwipeEventQueue;
698 Cursor mCursor;
699 bool mCustomCursorAllowed = true;
700 BorderStyle mBorderStyle;
701 LayoutDeviceIntRect mBounds;
702 bool mIsTiled;
703 PopupLevel mPopupLevel;
704 PopupType mPopupType;
705 SizeConstraints mSizeConstraints;
706 bool mHasRemoteContent;
708 struct FullscreenSavedState {
709 DesktopRect windowRect;
710 DesktopRect screenRect;
712 mozilla::Maybe<FullscreenSavedState> mSavedBounds;
714 bool mUpdateCursor;
715 bool mUseAttachedEvents;
716 bool mIMEHasFocus;
717 bool mIMEHasQuit;
718 bool mIsFullyOccluded;
719 bool mNeedFastSnaphot;
720 // This flag is only used when APZ is off. It indicates that the current pan
721 // gesture was processed as a swipe. Sometimes the swipe animation can finish
722 // before momentum events of the pan gesture have stopped firing, so this
723 // flag tells us that we shouldn't allow the remaining events to cause
724 // scrolling. It is reset to false once a new gesture starts (as indicated by
725 // a PANGESTURE_(MAY)START event).
726 bool mCurrentPanGestureBelongsToSwipe;
728 // It's PictureInPicture window.
729 bool mIsPIPWindow : 1;
731 struct InitialZoomConstraints {
732 InitialZoomConstraints(const uint32_t& aPresShellID,
733 const ScrollableLayerGuid::ViewID& aViewID,
734 const ZoomConstraints& aConstraints)
735 : mPresShellID(aPresShellID),
736 mViewID(aViewID),
737 mConstraints(aConstraints) {}
739 uint32_t mPresShellID;
740 ScrollableLayerGuid::ViewID mViewID;
741 ZoomConstraints mConstraints;
744 mozilla::Maybe<InitialZoomConstraints> mInitialZoomConstraints;
746 // This points to the resize listeners who have been notified that a live
747 // resize is in progress. This should always be empty when a live-resize is
748 // not in progress.
749 nsTArray<RefPtr<mozilla::LiveResizeListener>> mLiveResizeListeners;
751 #ifdef DEBUG
752 protected:
753 static nsAutoString debug_GuiEventToString(
754 mozilla::WidgetGUIEvent* aGuiEvent);
756 static void debug_DumpInvalidate(FILE* aFileOut, nsIWidget* aWidget,
757 const LayoutDeviceIntRect* aRect,
758 const char* aWidgetName, int32_t aWindowID);
760 static void debug_DumpEvent(FILE* aFileOut, nsIWidget* aWidget,
761 mozilla::WidgetGUIEvent* aGuiEvent,
762 const char* aWidgetName, int32_t aWindowID);
764 static void debug_DumpPaintEvent(FILE* aFileOut, nsIWidget* aWidget,
765 const nsIntRegion& aPaintEvent,
766 const char* aWidgetName, int32_t aWindowID);
768 static bool debug_GetCachedBoolPref(const char* aPrefName);
769 #endif
771 private:
772 already_AddRefed<mozilla::layers::WebRenderLayerManager>
773 CreateCompositorSession(int aWidth, int aHeight,
774 mozilla::layers::CompositorOptions* aOptionsOut);
777 #endif // nsBaseWidget_h__