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