1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
12 #include "imgIContainer.h"
13 #include "ErrorList.h"
15 #include "mozilla/AlreadyAddRefed.h"
16 #include "mozilla/Assertions.h"
17 #include "mozilla/Attributes.h"
18 #include "mozilla/EventForwards.h"
19 #include "mozilla/Maybe.h"
20 #include "mozilla/RefPtr.h"
21 #include "mozilla/TimeStamp.h"
22 #include "mozilla/UniquePtr.h"
23 #include "mozilla/gfx/Matrix.h"
24 #include "mozilla/gfx/Rect.h"
25 #include "mozilla/layers/LayersTypes.h"
26 #include "mozilla/layers/ScrollableLayerGuid.h"
27 #include "mozilla/layers/ZoomConstraints.h"
28 #include "mozilla/image/Resolution.h"
29 #include "mozilla/widget/IMEData.h"
34 #include "nsIObserver.h"
35 #include "nsISupports.h"
38 #include "nsIWidgetListener.h"
41 #include "nsStringFwd.h"
43 #include "nsTHashMap.h"
44 #include "mozilla/widget/InitData.h"
45 #include "nsXULAppAPI.h"
47 // forward declarations
48 class nsIBidiKeyboard
;
49 class nsIRollupListener
;
55 enum class NativeKeyBindingsType
: uint8_t;
56 class VsyncDispatcher
;
58 class WidgetInputEvent
;
59 class WidgetKeyboardEvent
;
61 enum class ColorScheme
: uint8_t;
62 enum class WindowButtonType
: uint8_t;
64 enum class WindowShadow
: uint8_t {
71 #if defined(MOZ_WIDGET_ANDROID)
75 #endif // defined(MOZ_WIDGET_ANDROID)
78 enum class CallerType
: uint32_t;
82 class AsyncDragMetrics
;
84 class CompositorBridgeChild
;
87 class WebRenderBridgeChild
;
90 class TextEventDispatcher
;
91 class TextEventDispatcherListener
;
92 class CompositorWidget
;
93 class CompositorWidgetInitData
;
97 class DisplayListBuilder
;
98 class IpcResourceUpdateQueue
;
99 enum class RenderRoot
: uint8_t;
101 } // namespace mozilla
104 * Callback function that processes events.
106 * The argument is actually a subtype (subclass) of WidgetEvent which carries
107 * platform specific information about the event. Platform specific code
108 * knows how to deal with it.
110 * The return value determines whether or not the default action should take
113 typedef nsEventStatus (*EVENT_CALLBACK
)(mozilla::WidgetGUIEvent
* aEvent
);
115 // Hide the native window system's real window type so as to avoid
116 // including native window system types and APIs. This is necessary
117 // to ensure cross-platform code.
118 typedef void* nsNativeWidget
;
121 * Values for the GetNativeData function
123 #define NS_NATIVE_WINDOW 0
124 #define NS_NATIVE_GRAPHIC 1
125 #define NS_NATIVE_WIDGET 3
126 #define NS_NATIVE_REGION 5
127 #define NS_NATIVE_OFFSETX 6
128 #define NS_NATIVE_OFFSETY 7
129 #define NS_NATIVE_SCREEN 9
130 // The toplevel GtkWidget containing this nsIWidget:
131 #define NS_NATIVE_SHELLWIDGET 10
132 #define NS_NATIVE_OPENGL_CONTEXT 12
133 // This is available only with GetNativeData() in parent process. Anybody
134 // shouldn't access this pointer as a valid pointer since the result may be
135 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
136 // an identifier of distinguishing a text composition is caused by which native
137 // IME context. Note that the result is only valid in the process. So,
138 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
139 #define NS_RAW_NATIVE_IME_CONTEXT 14
140 #define NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID 15
142 # define NS_NATIVE_TSF_THREAD_MGR 100
143 # define NS_NATIVE_TSF_CATEGORY_MGR 101
144 # define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
145 # define NS_NATIVE_ICOREWINDOW 103 // winrt specific
147 #if defined(MOZ_WIDGET_GTK)
148 # define NS_NATIVE_EGL_WINDOW 106
150 #ifdef MOZ_WIDGET_ANDROID
151 # define NS_JAVA_SURFACE 100
154 #define MOZ_WIDGET_MAX_SIZE 16384
155 #define MOZ_WIDGET_INVALID_SCALE 0.0
157 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
158 #define NS_IWIDGET_IID \
159 {0x06396bf6, 0x2dd8, 0x45e5, {0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80}}
165 enum nsCursor
{ ///(normal cursor, usually rendered as an arrow)
167 ///(system is busy, usually rendered as a hourglass or watch)
169 ///(Selecting something, usually rendered as an IBeam)
171 ///(can hyper-link, usually rendered as a human hand)
173 ///(north/south/west/east edge sizing)
186 eCursor_copy
, // CSS3
188 eCursor_context_menu
,
199 eCursor_vertical_text
,
206 // This one is used for array sizing, and so better be the last
207 // one in this list...
210 // ...except for this one.
211 eCursorInvalid
= eCursorCount
+ 1
215 * Before the OS goes to sleep, this topic is notified.
217 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
220 * After the OS wakes up, this topic is notified.
222 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
225 * Before the OS suspends the current process, this topic is notified. Some
226 * OS will kill processes that are suspended instead of resuming them.
227 * For that reason this topic may be useful to safely close down resources.
229 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
232 * After the current process resumes from being suspended, this topic is
235 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
238 * When an app(-shell) is activated by the OS, this topic is notified.
239 * Currently, this only happens on Mac OSX.
241 #define NS_WIDGET_MAC_APP_ACTIVATE_OBSERVER_TOPIC "mac_app_activate"
243 namespace mozilla::widget
{
246 * Size constraints for setting the minimum and maximum size of a widget.
247 * Values are in device pixels.
249 struct SizeConstraints
{
251 : mMaxSize(MOZ_WIDGET_MAX_SIZE
, MOZ_WIDGET_MAX_SIZE
),
252 mScale(MOZ_WIDGET_INVALID_SCALE
) {}
254 SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize
,
255 mozilla::LayoutDeviceIntSize aMaxSize
,
256 mozilla::DesktopToLayoutDeviceScale aScale
)
257 : mMinSize(aMinSize
), mMaxSize(aMaxSize
), mScale(aScale
) {
258 if (mMaxSize
.width
> MOZ_WIDGET_MAX_SIZE
) {
259 mMaxSize
.width
= MOZ_WIDGET_MAX_SIZE
;
261 if (mMaxSize
.height
> MOZ_WIDGET_MAX_SIZE
) {
262 mMaxSize
.height
= MOZ_WIDGET_MAX_SIZE
;
266 mozilla::LayoutDeviceIntSize mMinSize
;
267 mozilla::LayoutDeviceIntSize mMaxSize
;
270 * The scale used to convert from desktop to device dimensions.
271 * MOZ_WIDGET_INVALID_SCALE if the value is not known.
273 * Bug 1701109 is filed to revisit adding of 'mScale' and deal
274 * with multi-monitor scaling issues in more complete way across
275 * all widget implementations.
277 mozilla::DesktopToLayoutDeviceScale mScale
;
280 struct AutoObserverNotifier
{
281 AutoObserverNotifier(nsIObserver
* aObserver
, const char* aTopic
)
282 : mObserver(aObserver
), mTopic(aTopic
) {}
284 void SkipNotification() { mObserver
= nullptr; }
286 uint64_t SaveObserver() {
290 uint64_t observerId
= ++sObserverId
;
291 sSavedObservers
.InsertOrUpdate(observerId
, mObserver
);
296 ~AutoObserverNotifier() {
298 mObserver
->Observe(nullptr, mTopic
, nullptr);
302 static void NotifySavedObserver(const uint64_t& aObserverId
,
303 const char* aTopic
) {
304 nsCOMPtr
<nsIObserver
> observer
= sSavedObservers
.Get(aObserverId
);
306 MOZ_ASSERT(aObserverId
== 0,
307 "We should always find a saved observer for nonzero IDs");
311 sSavedObservers
.Remove(aObserverId
);
312 observer
->Observe(nullptr, aTopic
, nullptr);
316 nsCOMPtr
<nsIObserver
> mObserver
;
320 static uint64_t sObserverId
;
321 static nsTHashMap
<uint64_t, nsCOMPtr
<nsIObserver
>> sSavedObservers
;
324 } // namespace mozilla::widget
327 * The base class for all the widgets. It provides the interface for
328 * all basic and necessary functionality.
330 class nsIWidget
: public nsISupports
{
332 friend class nsBaseWidget
;
333 typedef mozilla::dom::BrowserChild BrowserChild
;
336 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild
;
337 typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics
;
338 typedef mozilla::layers::FrameMetrics FrameMetrics
;
339 typedef mozilla::layers::LayerManager LayerManager
;
340 typedef mozilla::WindowRenderer WindowRenderer
;
341 typedef mozilla::layers::LayersBackend LayersBackend
;
342 typedef mozilla::layers::LayersId LayersId
;
343 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid
;
344 typedef mozilla::layers::ZoomConstraints ZoomConstraints
;
345 typedef mozilla::widget::IMEEnabled IMEEnabled
;
346 typedef mozilla::widget::IMEMessage IMEMessage
;
347 typedef mozilla::widget::IMENotification IMENotification
;
348 typedef mozilla::widget::IMENotificationRequests IMENotificationRequests
;
349 typedef mozilla::widget::IMEState IMEState
;
350 typedef mozilla::widget::InputContext InputContext
;
351 typedef mozilla::widget::InputContextAction InputContextAction
;
352 typedef mozilla::widget::NativeIMEContext NativeIMEContext
;
353 typedef mozilla::widget::SizeConstraints SizeConstraints
;
354 typedef mozilla::widget::TextEventDispatcher TextEventDispatcher
;
355 typedef mozilla::widget::TextEventDispatcherListener
356 TextEventDispatcherListener
;
357 typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin
;
358 typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint
;
359 typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect
;
360 typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion
;
361 typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize
;
362 typedef mozilla::ScreenIntPoint ScreenIntPoint
;
363 typedef mozilla::ScreenIntMargin ScreenIntMargin
;
364 typedef mozilla::ScreenIntSize ScreenIntSize
;
365 typedef mozilla::ScreenPoint ScreenPoint
;
366 typedef mozilla::CSSToScreenScale CSSToScreenScale
;
367 typedef mozilla::DesktopIntRect DesktopIntRect
;
368 typedef mozilla::DesktopPoint DesktopPoint
;
369 typedef mozilla::DesktopIntPoint DesktopIntPoint
;
370 typedef mozilla::DesktopRect DesktopRect
;
371 typedef mozilla::DesktopSize DesktopSize
;
372 typedef mozilla::CSSPoint CSSPoint
;
373 typedef mozilla::CSSRect CSSRect
;
375 using InitData
= mozilla::widget::InitData
;
376 using WindowType
= mozilla::widget::WindowType
;
377 using PopupType
= mozilla::widget::PopupType
;
378 using PopupLevel
= mozilla::widget::PopupLevel
;
379 using BorderStyle
= mozilla::widget::BorderStyle
;
380 using TransparencyMode
= mozilla::widget::TransparencyMode
;
381 using Screen
= mozilla::widget::Screen
;
383 // Used in UpdateThemeGeometries.
384 struct ThemeGeometry
{
385 // The ThemeGeometryType value for the themed widget, see
386 // nsITheme::ThemeGeometryTypeForWidget.
387 nsITheme::ThemeGeometryType mType
;
388 // The device-pixel rect within the window for the themed widget
389 LayoutDeviceIntRect mRect
;
391 ThemeGeometry(nsITheme::ThemeGeometryType aType
,
392 const LayoutDeviceIntRect
& aRect
)
393 : mType(aType
), mRect(aRect
) {}
396 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID
)
398 nsIWidget() = default;
401 * Create and initialize a widget.
403 * All the arguments can be null in which case a top level window
404 * with size 0 is created. The event callback function has to be
405 * provided only if the caller wants to deal with the events this
406 * widget receives. The event callback is basically a preprocess
407 * hook called synchronously. The return value determines whether
408 * the event goes to the default window procedure or it is hidden
409 * to the os. The assumption is that if the event handler returns
410 * false the widget does not see the event. The widget should not
411 * automatically clear the window to the background color. The
412 * calling code must handle paint messages and clear the background
415 * If aParent is null, the widget isn't parented (e.g. context menus or
416 * independent top level windows).
418 * The dimensions given in aRect are specified in the parent's
419 * device coordinate system.
420 * This must not be called for parentless widgets such as top-level
421 * windows, which use the desktop pixel coordinate system; a separate
422 * method is provided for these.
424 * @param aParent parent nsIWidget
425 * @param aRect the widget dimension
426 * @param aInitData data that is used for widget initialization
429 [[nodiscard
]] virtual nsresult
Create(nsIWidget
* aParent
,
430 const LayoutDeviceIntRect
& aRect
,
431 InitData
* = nullptr) = 0;
434 * As above, but with aRect specified in DesktopPixel units (for top-level
436 * Default implementation just converts aRect to device pixels and calls
437 * through to device-pixel Create, but platforms may override this if the
438 * mapping is not straightforward or the native platform needs to use the
439 * desktop pixel values directly.
441 [[nodiscard
]] virtual nsresult
Create(nsIWidget
* aParent
,
442 const DesktopIntRect
& aRect
,
443 InitData
* aInitData
= nullptr) {
444 LayoutDeviceIntRect devPixRect
=
445 RoundedToInt(aRect
* GetDesktopToDeviceScale());
446 return Create(aParent
, devPixRect
, aInitData
);
450 * Allocate, initialize, and return a widget that is a child of
451 * |this|. The returned widget (if nonnull) has gone through the
452 * equivalent of CreateInstance(widgetCID) + Create(...).
454 * |CreateChild()| lets widget backends decide whether to parent
455 * the new child widget to this, nonnatively parent it, or both.
456 * This interface exists to support the PuppetWidget backend,
457 * which is entirely non-native. All other params are the same as
460 virtual already_AddRefed
<nsIWidget
> CreateChild(
461 const LayoutDeviceIntRect
& aRect
, InitData
&) = 0;
464 * Attach to a top level widget.
466 * In cases where a top level chrome widget is being used as a content
467 * container, attach a secondary listener and update the device
468 * context. The primary widget listener will continue to be called for
469 * notifications relating to the top-level window, whereas other
470 * notifications such as painting and events will instead be called via
471 * the attached listener. SetAttachedWidgetListener should be used to
472 * assign the attached listener.
474 * aUseAttachedEvents if true, events are sent to the attached listener
475 * instead of the normal listener.
477 virtual void AttachViewToTopLevel(bool aUseAttachedEvents
) = 0;
480 * Accessor functions to get and set the attached listener. Used by
481 * nsView in connection with AttachViewToTopLevel above.
483 virtual void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) = 0;
484 virtual nsIWidgetListener
* GetAttachedWidgetListener() const = 0;
485 virtual void SetPreviouslyAttachedWidgetListener(
486 nsIWidgetListener
* aListener
) = 0;
487 virtual nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() = 0;
490 * Notifies the root widget of a non-blank paint.
492 virtual void DidGetNonBlankPaint() {}
495 * Accessor functions to get and set the listener which handles various
496 * actions for the widget.
499 virtual nsIWidgetListener
* GetWidgetListener() const = 0;
500 virtual void SetWidgetListener(nsIWidgetListener
* alistener
) = 0;
504 * Close and destroy the internal native window.
505 * This method does not delete the widget.
508 virtual void Destroy() = 0;
511 * Destroyed() returns true if Destroy() has been called already.
514 bool Destroyed() const { return mOnDestroyCalled
; }
516 /** Clear the widget's parent. */
520 * Return the parent Widget of this Widget or nullptr if this is a
523 * @return the parent widget or nullptr if it does not have a parent
526 nsIWidget
* GetParent() const { return mParent
; }
528 /** Gets called when mParent is cleared. */
529 virtual void DidClearParent(nsIWidget
* aOldParent
) {}
532 * Return the top level Widget of this Widget
534 * @return the closest top level widget, as in IsTopLevelWidget().
536 nsIWidget
* GetTopLevelWidget();
537 bool IsTopLevelWidget() const {
538 return mWindowType
== WindowType::TopLevel
||
539 mWindowType
== WindowType::Dialog
||
540 mWindowType
== WindowType::Invisible
;
544 * Return the physical DPI of the screen containing the window ...
545 * the number of device pixels per inch.
547 virtual float GetDPI() = 0;
550 * Fallback DPI for when there's no widget available.
552 static float GetFallbackDPI();
555 * Return the scaling factor between device pixels and the platform-
556 * dependent "desktop pixels" used to manage window positions on a
557 * potentially multi-screen, mixed-resolution desktop.
559 virtual mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() = 0;
562 * Return the scaling factor between device pixels and the platform-
563 * dependent "desktop pixels" by looking up the screen by the position
566 virtual mozilla::DesktopToLayoutDeviceScale
567 GetDesktopToDeviceScaleByScreen() = 0;
570 * Return the default scale factor for the window. This is the
571 * default number of device pixels per CSS pixel to use. This should
572 * depend on OS/platform settings such as the Mac's "UI scale factor"
573 * or Windows' "font DPI". This will take into account Gecko preferences
574 * overriding the system setting.
576 mozilla::CSSToLayoutDeviceScale
GetDefaultScale();
579 * Fallback default scale for when there's no widget available.
581 static mozilla::CSSToLayoutDeviceScale
GetFallbackDefaultScale();
584 * Return the first child of this widget. Will return null if
585 * there are no children.
587 nsIWidget
* GetFirstChild() const { return mFirstChild
; }
590 * Return the last child of this widget. Will return null if
591 * there are no children.
593 nsIWidget
* GetLastChild() const { return mLastChild
; }
596 * Return the next sibling of this widget
598 nsIWidget
* GetNextSibling() const { return mNextSibling
; }
601 * Set the next sibling of this widget
603 void SetNextSibling(nsIWidget
* aSibling
) { mNextSibling
= aSibling
; }
606 * Return the previous sibling of this widget
608 nsIWidget
* GetPrevSibling() const { return mPrevSibling
; }
611 * Set the previous sibling of this widget
613 void SetPrevSibling(nsIWidget
* aSibling
) { mPrevSibling
= aSibling
; }
616 * Show or hide this widget
618 * @param aState true to show the Widget, false to hide it
621 virtual void Show(bool aState
) = 0;
624 * Whether or not a widget must be recreated after being hidden to show
627 virtual bool NeedsRecreateToReshow() { return false; }
630 * Make the window modal.
632 virtual void SetModal(bool aModal
) = 0;
635 * Are we app modal. Currently only implemented on Cocoa.
637 virtual bool IsRunningAppModal() { return false; }
640 * The maximum number of simultaneous touch contacts supported by the device.
641 * In the case of devices with multiple digitizers (e.g. multiple touch
642 * screens), the value will be the maximum of the set of maximum supported
643 * contacts by each individual digitizer.
645 virtual uint32_t GetMaxTouchPoints() const = 0;
648 * Returns whether the window is visible
651 virtual bool IsVisible() const = 0;
654 * Returns whether the window has allocated resources so
655 * we can paint into it.
656 * Recently it's used on Linux/Gtk where we should not paint
657 * to invisible window.
659 virtual bool IsMapped() const { return true; }
662 * Perform platform-dependent sanity check on a potential window position.
663 * This is guaranteed to work only for top-level windows.
665 virtual void ConstrainPosition(DesktopIntPoint
&) = 0;
670 * For a top-level window widget, the "parent's coordinate system" is the
671 * "global" display pixel coordinate space, *not* device pixels (which
672 * may be inconsistent between multiple screens, at least in the Mac OS
673 * case with mixed hi-dpi and lo-dpi displays). This applies to all the
674 * following Move and Resize widget APIs.
676 * The display-/device-pixel distinction becomes important for (at least)
677 * macOS with Hi-DPI (retina) displays, and Windows when the UI scale factor
678 * is set to other than 100%.
680 * The Move and Resize methods take floating-point parameters, rather than
681 * integer ones. This is important when manipulating top-level widgets,
682 * where the coordinate system may not be an integral multiple of the
683 * device-pixel space.
689 * Coordinates refer to the top-left of the widget. For toplevel windows
690 * with decorations, this is the top-left of the titlebar and frame .
692 * @param aX the new x position expressed in the parent's coordinate system
693 * @param aY the new y position expressed in the parent's coordinate system
696 virtual void Move(double aX
, double aY
) = 0;
699 * Reposition this widget so that the client area has the given offset.
701 * @param aOffset the new offset of the client area expressed as an
702 * offset from the origin of the client area of the parent
703 * widget (for root widgets and popup widgets it is in
704 * screen coordinates)
706 virtual void MoveClient(const DesktopPoint
& aOffset
) = 0;
709 * Resize this widget. Any size constraints set for the window by a
710 * previous call to SetSizeConstraints will be applied.
712 * @param aWidth the new width expressed in the parent's coordinate system
713 * @param aHeight the new height expressed in the parent's coordinate
715 * @param aRepaint whether the widget should be repainted
717 virtual void Resize(double aWidth
, double aHeight
, bool aRepaint
) = 0;
720 * Lock the aspect ratio of a Window
722 * @param aShouldLock bool
725 virtual void LockAspectRatio(bool aShouldLock
) {};
728 * Move or resize this widget. Any size constraints set for the window by
729 * a previous call to SetSizeConstraints will be applied.
731 * @param aX the new x position expressed in the parent's coordinate
733 * @param aY the new y position expressed in the parent's coordinate
735 * @param aWidth the new width expressed in the parent's coordinate system
736 * @param aHeight the new height expressed in the parent's coordinate
738 * @param aRepaint whether the widget should be repainted if the size
742 virtual void Resize(double aX
, double aY
, double aWidth
, double aHeight
,
746 * Resize the widget so that the inner client area has the given size.
748 * @param aSize the new size of the client area.
749 * @param aRepaint whether the widget should be repainted
751 virtual void ResizeClient(const DesktopSize
& aSize
, bool aRepaint
) = 0;
754 * Resize and reposition the widget so tht inner client area has the given
757 * @param aRect the new offset and size of the client area. The offset is
758 * expressed as an offset from the origin of the client area
759 * of the parent widget (for root widgets and popup widgets it
760 * is in screen coordinates).
761 * @param aRepaint whether the widget should be repainted
763 virtual void ResizeClient(const DesktopRect
& aRect
, bool aRepaint
) = 0;
766 * Minimize, maximize or normalize the window size.
767 * Takes a value from nsSizeMode (see nsIWidgetListener.h)
769 virtual void SetSizeMode(nsSizeMode aMode
) = 0;
771 virtual void GetWorkspaceID(nsAString
& workspaceID
) = 0;
773 virtual void MoveToWorkspace(const nsAString
& workspaceID
) = 0;
776 * Suppress animations that are applied to a window by OS.
778 virtual void SuppressAnimation(bool aSuppress
) {}
780 /** Sets windows-specific mica backdrop on this widget. */
781 virtual void SetMicaBackdrop(bool) {}
784 * Return size mode (minimized, maximized, normalized).
785 * Returns a value from nsSizeMode (see nsIWidgetListener.h)
787 virtual nsSizeMode
SizeMode() = 0;
790 * Ask whether the window is tiled.
792 virtual bool IsTiled() const = 0;
795 * Ask wether the widget is fully occluded
797 virtual bool IsFullyOccluded() const = 0;
800 * Enable or disable this Widget
802 * @param aState true to enable the Widget, false to disable it.
804 virtual void Enable(bool aState
) = 0;
807 * Ask whether the widget is enabled
809 virtual bool IsEnabled() const = 0;
812 * Whether we should request activation of this widget's toplevel window.
820 * Request activation of this window or give focus to this widget.
822 virtual void SetFocus(Raise
, mozilla::dom::CallerType aCallerType
) = 0;
825 * Get this widget's outside dimensions relative to its parent widget. For
826 * popup widgets the returned rect is in screen coordinates and not
827 * relative to its parent widget.
829 * @return the x, y, width and height of this widget.
831 virtual LayoutDeviceIntRect
GetBounds() = 0;
834 * Get this widget's outside dimensions in device coordinates. This
835 * includes any title bar on the window.
837 * @return the x, y, width and height of this widget.
839 virtual LayoutDeviceIntRect
GetScreenBounds() = 0;
842 * Similar to GetScreenBounds except that this function will always
843 * get the size when the widget is in the nsSizeMode_Normal size mode
844 * even if the current size mode is not nsSizeMode_Normal.
845 * This method will fail if the size mode is not nsSizeMode_Normal and
846 * the platform doesn't have the ability.
847 * This method will always succeed if the current size mode is
850 * @param aRect On return it holds the x, y, width and height of
853 [[nodiscard
]] virtual nsresult
GetRestoredBounds(
854 LayoutDeviceIntRect
& aRect
) = 0;
857 * Get this widget's client area bounds, if the window has a 3D border
858 * appearance this returns the area inside the border. The position is the
859 * position of the client area relative to the client area of the parent
860 * widget (for root widgets and popup widgets it is in screen coordinates).
862 * @return the x, y, width and height of the client area of this widget.
864 virtual LayoutDeviceIntRect
GetClientBounds() = 0;
866 /** Whether to extend the client area into the titlebar. */
867 virtual void SetCustomTitlebar(bool) {}
870 * Sets the region around the edges of the window that can be dragged to
871 * resize the window. All four sides of the window will get the same margin.
873 virtual void SetResizeMargin(mozilla::LayoutDeviceIntCoord
) {}
876 * Get the client offset from the window origin.
878 * @return the x and y of the offset.
880 virtual LayoutDeviceIntPoint
GetClientOffset() = 0;
883 * Returns the slop from the screen edges in device pixels.
884 * @see Window.screenEdgeSlop{X,Y}
886 virtual LayoutDeviceIntPoint
GetScreenEdgeSlop() { return {}; }
889 * Equivalent to GetClientBounds but only returns the size.
891 virtual LayoutDeviceIntSize
GetClientSize() {
892 // Depending on the backend, overloading this method may be useful if
893 // requesting the client offset is expensive.
894 return GetClientBounds().Size();
898 * Set the native background color for this widget.
900 * Deprecated. Currently only implemented for iOS. (See bug 1901896.)
902 * @param aColor the new background color
905 virtual void SetBackgroundColor(const nscolor
& aColor
) {}
908 * If a cursor type is currently cached locally for this widget, clear the
909 * cached cursor to force an update on the next SetCursor call.
912 virtual void ClearCachedCursor() = 0;
915 // The system cursor chosen by the page. This is used if there's no custom
916 // cursor, or if we fail to use the custom cursor in some way (if the image
917 // fails to load, for example).
918 nsCursor mDefaultCursor
= eCursor_standard
;
919 // May be null, to represent no custom cursor image.
920 nsCOMPtr
<imgIContainer
> mContainer
;
921 uint32_t mHotspotX
= 0;
922 uint32_t mHotspotY
= 0;
923 mozilla::ImageResolution mResolution
;
925 bool IsCustom() const { return !!mContainer
; }
927 bool operator==(const Cursor
& aOther
) const {
928 return mDefaultCursor
== aOther
.mDefaultCursor
&&
929 mContainer
.get() == aOther
.mContainer
.get() &&
930 mHotspotX
== aOther
.mHotspotX
&& mHotspotY
== aOther
.mHotspotY
&&
931 mResolution
== aOther
.mResolution
;
934 bool operator!=(const Cursor
& aOther
) const { return !(*this == aOther
); }
938 * Sets the cursor for this widget.
940 virtual void SetCursor(const Cursor
&) = 0;
942 virtual void SetCustomCursorAllowed(bool) = 0;
944 static nsIntSize
CustomCursorSize(const Cursor
&);
947 * Get the window type of this widget.
949 WindowType
GetWindowType() const { return mWindowType
; }
952 * Set the transparency mode of the top-level window containing this widget.
953 * So, e.g., if you call this on the widget for an IFRAME, the top level
954 * browser window containing the IFRAME actually gets set. Be careful.
956 * This can fail if the platform doesn't support
957 * transparency/glass. By default widgets are not
958 * transparent. This will also fail if the toplevel window is not
959 * a Mozilla window, e.g., if the widget is in an embedded
962 * After transparency/glass has been enabled, the initial alpha channel
963 * value for all pixels is 1, i.e., opaque.
964 * If the window is resized then the alpha channel values for
965 * all pixels are reset to 1.
966 * Pixel RGB color values are already premultiplied with alpha channel values.
968 virtual void SetTransparencyMode(TransparencyMode aMode
) = 0;
971 * Get the transparency mode of the top-level window that contains this
974 virtual TransparencyMode
GetTransparencyMode() = 0;
977 * Set the shadow style of the window.
979 * Ignored on child widgets and on non-Mac platforms.
981 virtual void SetWindowShadowStyle(mozilla::WindowShadow aStyle
) = 0;
984 * Set the opacity of the window.
985 * Values need to be between 0.0f (invisible) and 1.0f (fully opaque).
987 * Ignored on child widgets and on non-Mac platforms.
989 virtual void SetWindowOpacity(float aOpacity
) {}
992 * Set the transform of the window. Values are in device pixels,
993 * the origin is the top left corner of the window.
995 * Ignored on child widgets and on non-Mac platforms.
997 virtual void SetWindowTransform(const mozilla::gfx::Matrix
& aTransform
) {}
1000 * Set the preferred color-scheme for the widget. Nothing() means system
1001 * default. Implemented on Windows and macOS.
1003 virtual void SetColorScheme(const mozilla::Maybe
<mozilla::ColorScheme
>&) {}
1006 * Set whether the window should ignore mouse events or not, and if it should
1007 * not, what input margin should it use.
1009 * This is only used on popup windows. The margin is only implemented on
1012 struct InputRegion
{
1013 bool mFullyTransparent
= false;
1014 mozilla::LayoutDeviceIntCoord mMargin
= 0;
1016 virtual void SetInputRegion(const InputRegion
&) {}
1019 * On macOS, this method shows or hides the pill button in the titlebar
1020 * that's used to collapse the toolbar.
1022 * Ignored on child widgets and on non-Mac platforms.
1024 virtual void SetShowsToolbarButton(bool aShow
) = 0;
1027 * On macOS, this method determines whether we tell cocoa that the window
1028 * supports native full screen. If we do so, and another window is in
1029 * native full screen, this window will also appear in native full screen.
1031 * We generally only want to do this for primary application windows.
1033 * Ignored on child widgets and on non-Mac platforms.
1035 virtual void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen
) = 0;
1037 enum WindowAnimationType
{
1038 eGenericWindowAnimation
,
1039 eDocumentWindowAnimation
1043 * Sets the kind of top-level window animation this widget should have. On
1044 * macOS, this causes a particular kind of animation to be shown when the
1045 * window is first made visible.
1047 * Ignored on child widgets and on non-Mac platforms.
1049 virtual void SetWindowAnimationType(WindowAnimationType aType
) = 0;
1052 * Specifies whether the window title should be drawn even if the window
1053 * contents extend into the titlebar. Ignored on windows that don't draw
1054 * in the titlebar. Only implemented on macOS.
1056 virtual void SetDrawsTitle(bool aDrawTitle
) {}
1059 * Hide window chrome (borders, buttons) for this widget.
1062 virtual void HideWindowChrome(bool aShouldHide
) = 0;
1064 enum FullscreenTransitionStage
{
1065 eBeforeFullscreenToggle
,
1066 eAfterFullscreenToggle
1070 * Prepares for fullscreen transition and returns whether the widget
1071 * supports fullscreen transition. If this method returns false,
1072 * PerformFullscreenTransition() must never be called. Otherwise,
1073 * caller should call that method twice with "before" and "after"
1074 * stages respectively in order. In the latter case, this method may
1075 * return some data via aData pointer. Caller must pass that data to
1076 * PerformFullscreenTransition() if any, and caller is responsible
1077 * for releasing that data.
1079 virtual bool PrepareForFullscreenTransition(nsISupports
** aData
) = 0;
1082 * Performs fullscreen transition. This method returns immediately,
1083 * and will post aCallback to the main thread when the transition
1086 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
1089 nsIRunnable
* aCallback
) = 0;
1092 * Perform any actions needed after the fullscreen transition has ended.
1094 virtual void CleanupFullscreenTransition() = 0;
1097 * Return the screen the widget is in, or null if we don't know.
1099 virtual already_AddRefed
<Screen
> GetWidgetScreen() = 0;
1102 * Put the toplevel window into or out of fullscreen mode.
1104 * @return NS_OK if the widget is setup properly for fullscreen and
1105 * FullscreenChanged callback has been or will be called. If other
1106 * value is returned, the caller should continue the change itself.
1108 virtual nsresult
MakeFullScreen(bool aFullScreen
) = 0;
1111 * Same as MakeFullScreen, except that, on systems which natively
1112 * support fullscreen transition, calling this method explicitly
1113 * requests that behavior.
1114 * It is currently only supported on macOS 10.7+.
1116 virtual nsresult
MakeFullScreenWithNativeTransition(bool aFullScreen
) {
1117 return MakeFullScreen(aFullScreen
);
1121 * Invalidate a specified rect for a widget so that it will be repainted
1124 virtual void Invalidate(const LayoutDeviceIntRect
& aRect
) = 0;
1126 enum LayerManagerPersistence
{
1127 LAYER_MANAGER_CURRENT
= 0,
1128 LAYER_MANAGER_PERSISTENT
1132 * Return the widget's LayerManager. The layer tree for that LayerManager is
1133 * what gets rendered to the widget.
1135 * Note that this tries to create a renderer if it doesn't exist.
1137 virtual WindowRenderer
* GetWindowRenderer() = 0;
1140 * Returns whether there's an existing window renderer.
1142 virtual bool HasWindowRenderer() const = 0;
1145 * Called before each layer manager transaction to allow any preparation
1146 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1148 * Always called on the main thread.
1150 virtual void PrepareWindowEffects() = 0;
1153 * Called when Gecko knows which themed widgets exist in this window.
1154 * The passed array contains an entry for every themed widget of the right
1155 * type (currently only StyleAppearance::Toolbar) within the window, except
1156 * for themed widgets which are transformed or have effects applied to them
1157 * (e.g. CSS opacity or filters).
1158 * This could sometimes be called during display list construction
1159 * outside of painting.
1160 * If called during painting, it will be called before we actually
1163 virtual void UpdateThemeGeometries(
1164 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) = 0;
1167 * Informs the widget about the region of the window that is opaque.
1169 * @param aOpaqueRegion the region of the window that is opaque.
1171 virtual void UpdateOpaqueRegion(const LayoutDeviceIntRegion
& aOpaqueRegion
) {}
1172 virtual LayoutDeviceIntRegion
GetOpaqueRegionForTesting() const { return {}; }
1175 * Informs the widget about the region of the window that is draggable.
1177 virtual void UpdateWindowDraggingRegion(
1178 const LayoutDeviceIntRegion
& aRegion
) {}
1181 * Tells the widget whether the given input block results in a swipe.
1182 * Should be called in response to a WidgetWheelEvent that has
1183 * mFlags.mCanTriggerSwipe set on it.
1185 virtual void ReportSwipeStarted(uint64_t aInputBlockId
, bool aStartSwipe
) {}
1190 virtual void* GetNativeData(uint32_t aDataType
) = 0;
1191 virtual void FreeNativeData(void* data
, uint32_t aDataType
) = 0; //~~~
1194 void AddToChildList(nsIWidget
* aChild
);
1195 void RemoveFromChildList(nsIWidget
* aChild
);
1196 void RemoveAllChildren();
1200 * Set the widget's title.
1201 * Must be called after Create.
1203 * @param aTitle string displayed as the title of the widget
1205 virtual nsresult
SetTitle(const nsAString
& aTitle
) = 0;
1208 * Set the widget's icon.
1209 * Must be called after Create.
1211 * @param aIconSpec string specifying the icon to use; convention is to
1212 * pass a resource: URL from which a platform-dependent
1213 * resource file name will be constructed
1215 virtual void SetIcon(const nsAString
& aIconSpec
) = 0;
1218 * Return this widget's origin in screen coordinates.
1220 * @return screen coordinates stored in the x,y members
1222 virtual LayoutDeviceIntPoint
WidgetToScreenOffset() = 0;
1225 * The same as WidgetToScreenOffset(), except in the case of
1226 * PuppetWidget where this method omits the chrome offset.
1228 virtual LayoutDeviceIntPoint
TopLevelWidgetToScreenOffset() {
1229 return WidgetToScreenOffset();
1233 * For a PuppetWidget, returns the transform from the coordinate
1234 * space of the PuppetWidget to the coordinate space of the
1235 * top-level native widget.
1237 * Identity transform in other cases.
1239 virtual mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
1240 WidgetToTopLevelWidgetTransform() {
1241 return mozilla::LayoutDeviceToLayoutDeviceMatrix4x4();
1244 mozilla::LayoutDeviceIntPoint
WidgetToTopLevelWidgetOffset() {
1245 return mozilla::LayoutDeviceIntPoint::Round(
1246 WidgetToTopLevelWidgetTransform().TransformPoint(
1247 mozilla::LayoutDevicePoint()));
1251 * Returns the margins that are applied to go from client sizes to window
1252 * sizes (which includes window borders and titlebar).
1253 * This method should work even when the window is not yet visible.
1255 virtual LayoutDeviceIntMargin
ClientToWindowMargin() { return {}; }
1257 LayoutDeviceIntSize
ClientToWindowSizeDifference();
1260 * Dispatches an event to the widget
1262 virtual nsresult
DispatchEvent(mozilla::WidgetGUIEvent
* event
,
1263 nsEventStatus
& aStatus
) = 0;
1266 * Dispatches an event to APZ only.
1267 * No-op in the child process.
1269 virtual void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) = 0;
1272 * Dispatch a gecko event for this widget.
1273 * Returns true if it's consumed. Otherwise, false.
1275 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent
& event
) = 0;
1277 // A structure that groups the statuses from APZ dispatch and content
1279 struct ContentAndAPZEventStatus
{
1280 // Either of these may not be set if the event was not dispatched
1281 // to APZ or to content.
1282 nsEventStatus mApzStatus
= nsEventStatus_eIgnore
;
1283 nsEventStatus mContentStatus
= nsEventStatus_eIgnore
;
1287 * Dispatches an event that must be handled by APZ first, when APZ is
1288 * enabled. If invoked in the child process, it is forwarded to the
1289 * parent process synchronously.
1291 virtual ContentAndAPZEventStatus
DispatchInputEvent(
1292 mozilla::WidgetInputEvent
* aEvent
) = 0;
1295 * Confirm an APZ-aware event target. This should be used when APZ will
1296 * not need a layers update to process the event.
1298 virtual void SetConfirmedTargetAPZC(
1299 uint64_t aInputBlockId
,
1300 const nsTArray
<ScrollableLayerGuid
>& aTargets
) const = 0;
1303 * Returns true if APZ is in use, false otherwise.
1305 virtual bool AsyncPanZoomEnabled() const = 0;
1309 virtual void SwipeFinished() = 0;
1312 * Enables the dropping of files to a widget.
1314 virtual void EnableDragDrop(bool aEnable
) = 0;
1315 virtual nsresult
AsyncEnableDragDrop(bool aEnable
) = 0;
1318 * Classify the window for the window manager. Mostly for X11.
1320 * @param xulWinType The window type. Characters other than [A-Za-z0-9_-] are
1321 * converted to '_'. Anything before the first colon is
1322 * assigned to name, anything after it to role. If there's
1323 * no colon, assign the whole thing to both role and name.
1325 * @param xulWinClass The window class. If set, overrides the normal value.
1326 * Otherwise, the program class it used.
1328 * @param xulWinName The window name. If set, overrides the value specified in
1329 * window type. Otherwise, name from window type is used.
1332 virtual void SetWindowClass(const nsAString
& xulWinType
,
1333 const nsAString
& xulWinClass
,
1334 const nsAString
& xulWinName
) = 0;
1336 virtual void SetIsEarlyBlankWindow(bool) {}
1339 * Enables/Disables system capture of any and all events that would cause a
1340 * popup to be rolled up. aListener should be set to a non-null value for
1341 * any popups that are not managed by the popup manager.
1342 * @param aDoCapture true enables capture, false disables capture
1345 virtual void CaptureRollupEvents(bool aDoCapture
) = 0;
1348 * Bring this window to the user's attention. This is intended to be a more
1349 * gentle notification than popping the window to the top or putting up an
1350 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1351 * the Mac. The notification should be suppressed if the window is already
1352 * in the foreground and should be dismissed when the user brings this window
1353 * to the foreground.
1354 * @param aCycleCount Maximum number of times to animate the window per system
1355 * conventions. If set to -1, cycles indefinitely until
1356 * window is brought into the foreground.
1358 [[nodiscard
]] virtual nsresult
GetAttention(int32_t aCycleCount
) = 0;
1361 * Ask whether there user input events pending. All input events are
1362 * included, including those not targeted at this nsIwidget instance.
1364 virtual bool HasPendingInputEvent() = 0;
1367 * Determine whether the widget shows a resize widget. If it does,
1368 * aResizerRect returns the resizer's rect.
1370 * Returns false on any platform that does not support it.
1372 * @param aResizerRect The resizer's rect in device pixels.
1373 * @return Whether a resize widget is shown.
1375 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) = 0;
1377 // TODO: Make this an enum class with MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS or
1379 enum Modifiers
: uint32_t {
1380 NO_MODIFIERS
= 0x00000000,
1381 CAPS_LOCK
= 0x00000001, // when CapsLock is active
1382 NUM_LOCK
= 0x00000002, // when NumLock is active
1383 SHIFT_L
= 0x00000100,
1384 SHIFT_R
= 0x00000200,
1385 CTRL_L
= 0x00000400,
1386 CTRL_R
= 0x00000800,
1387 ALT_L
= 0x00001000, // includes Option
1389 COMMAND_L
= 0x00004000,
1390 COMMAND_R
= 0x00008000,
1392 ALTGRAPH
= 0x00020000, // AltGr key on Windows. This emulates
1393 // AltRight key behavior of keyboard
1394 // layouts which maps AltGr to AltRight
1396 FUNCTION
= 0x00100000,
1397 NUMERIC_KEY_PAD
= 0x01000000 // when the key is coming from the keypad
1400 * Utility method intended for testing. Dispatches native key events
1401 * to this widget to simulate the press and release of a key.
1402 * @param aNativeKeyboardLayout a *platform-specific* constant.
1403 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1404 * On Windows, it is converted to a hex string and passed to
1405 * LoadKeyboardLayout, see
1406 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1407 * @param aNativeKeyCode a *platform-specific* keycode.
1408 * On Windows, this is the virtual key code.
1409 * @param aModifiers some combination of the above 'Modifiers' flags;
1410 * not all flags will apply to all platforms. Mac ignores the _R
1411 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1413 * @param aCharacters characters that the OS would decide to generate
1414 * from the event. On Windows, this is the charCode passed by
1416 * @param aUnmodifiedCharacters characters that the OS would decide
1417 * to generate from the event if modifier keys (other than shift)
1418 * were assumed inactive. Needed on Mac, ignored on Windows.
1419 * @param aObserver the observer that will get notified once the events
1420 * have been dispatched.
1421 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1422 * layout is not supported and the event was not fired
1424 virtual nsresult
SynthesizeNativeKeyEvent(
1425 int32_t aNativeKeyboardLayout
, int32_t aNativeKeyCode
,
1426 uint32_t aModifierFlags
, const nsAString
& aCharacters
,
1427 const nsAString
& aUnmodifiedCharacters
, nsIObserver
* aObserver
) = 0;
1430 * Utility method intended for testing. Dispatches native mouse events
1431 * may even move the mouse cursor. On Mac the events are guaranteed to
1432 * be sent to the window containing this widget, but on Windows they'll go
1433 * to whatever's topmost on the screen at that position, so for
1434 * cross-platform testing ensure that your window is at the top of the
1436 * @param aPoint screen location of the mouse, in device
1437 * pixels, with origin at the top left
1438 * @param aNativeMessage abstract native message.
1439 * @param aButton Mouse button defined by DOM UI Events.
1440 * @param aModifierFlags Some values of nsIWidget::Modifiers.
1441 * FYI: On Windows, Android and Headless widget on all
1442 * platroms, this hasn't been handled yet.
1443 * @param aObserver the observer that will get notified once the events
1444 * have been dispatched.
1446 enum class NativeMouseMessage
: uint32_t {
1447 ButtonDown
, // button down
1448 ButtonUp
, // button up
1449 Move
, // mouse cursor move
1450 EnterWindow
, // mouse cursor comes into a window
1451 LeaveWindow
, // mouse cursor leaves from a window
1453 virtual nsresult
SynthesizeNativeMouseEvent(
1454 LayoutDeviceIntPoint aPoint
, NativeMouseMessage aNativeMessage
,
1455 mozilla::MouseButton aButton
, nsIWidget::Modifiers aModifierFlags
,
1456 nsIObserver
* aObserver
) = 0;
1459 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native
1460 * message. aPoint is location in device pixels to which the mouse pointer
1462 * @param aObserver the observer that will get notified once the events
1463 * have been dispatched.
1465 virtual nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
1466 nsIObserver
* aObserver
) = 0;
1469 * Utility method intended for testing. Dispatching native mouse scroll
1470 * events may move the mouse cursor.
1472 * @param aPoint Mouse cursor position in screen coordinates.
1473 * In device pixels, the origin at the top left of
1474 * the primary display.
1475 * @param aNativeMessage Platform native message.
1476 * @param aDeltaX The delta value for X direction. If the native
1477 * message doesn't indicate X direction scrolling,
1478 * this may be ignored.
1479 * @param aDeltaY The delta value for Y direction. If the native
1480 * message doesn't indicate Y direction scrolling,
1481 * this may be ignored.
1482 * @param aDeltaZ The delta value for Z direction. If the native
1483 * message doesn't indicate Z direction scrolling,
1484 * this may be ignored.
1485 * @param aModifierFlags Must be values of Modifiers, or zero.
1486 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1488 * @param aObserver The observer that will get notified once the
1489 * events have been dispatched.
1491 virtual nsresult
SynthesizeNativeMouseScrollEvent(
1492 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
1493 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
1494 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) = 0;
1497 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1498 * touch states in nsIDOMWindowUtils.idl.
1500 enum TouchPointerState
{
1501 // The pointer is in a hover state above the digitizer
1502 TOUCH_HOVER
= (1 << 0),
1503 // The pointer is in contact with the digitizer
1504 TOUCH_CONTACT
= (1 << 1),
1505 // The pointer has been removed from the digitizer detection area
1506 TOUCH_REMOVE
= (1 << 2),
1507 // The pointer has been canceled. Will cancel any pending os level
1508 // gestures that would triggered as a result of completion of the
1509 // input sequence. This may not cancel moz platform related events
1510 // that might get tirggered by input already delivered.
1511 TOUCH_CANCEL
= (1 << 3),
1513 // ALL_BITS used for validity checking during IPC serialization
1514 ALL_BITS
= (1 << 4) - 1
1517 * TouchpadGesturePhase states for SynthesizeNativeTouchPadPinch and
1518 * SynthesizeNativeTouchpadPan. Match phase states in nsIDOMWindowUtils.idl.
1520 enum TouchpadGesturePhase
{
1526 * Create a new or update an existing touch pointer on the digitizer.
1527 * To trigger os level gestures, individual touch points should
1528 * transition through a complete set of touch states which should be
1529 * sent as individual messages.
1531 * @param aPointerId The touch point id to create or update.
1532 * @param aPointerState one or more of the touch states listed above
1533 * @param aPoint coords of this event
1534 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1535 * @param aOrientation 0 -> 359 degree value indicating the
1536 * orientation of the pointer. Use 90 for normal taps.
1537 * @param aObserver The observer that will get notified once the events
1538 * have been dispatched.
1540 virtual nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
1541 TouchPointerState aPointerState
,
1542 LayoutDeviceIntPoint aPoint
,
1543 double aPointerPressure
,
1544 uint32_t aPointerOrientation
,
1545 nsIObserver
* aObserver
) = 0;
1547 * See nsIDOMWindowUtils.sendNativeTouchpadPinch().
1549 virtual nsresult
SynthesizeNativeTouchPadPinch(
1550 TouchpadGesturePhase aEventPhase
, float aScale
,
1551 LayoutDeviceIntPoint aPoint
, int32_t aModifierFlags
) = 0;
1554 * Helper for simulating a simple tap event with one touch point. When
1555 * aLongTap is true, simulates a native long tap with a duration equal to
1556 * ui.click_hold_context_menus.delay. This pref is compatible with the
1557 * apzc long tap duration. Defaults to 1.5 seconds.
1558 * @param aObserver The observer that will get notified once the events
1559 * have been dispatched.
1561 virtual nsresult
SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint
,
1563 nsIObserver
* aObserver
);
1565 virtual nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
1566 TouchPointerState aPointerState
,
1567 LayoutDeviceIntPoint aPoint
,
1569 uint32_t aRotation
, int32_t aTiltX
,
1570 int32_t aTiltY
, int32_t aButton
,
1571 nsIObserver
* aObserver
) = 0;
1574 * Cancels all active simulated touch input points and pending long taps.
1575 * Native widgets should track existing points such that they can clear the
1576 * digitizer state when this call is made.
1577 * @param aObserver The observer that will get notified once the touch
1578 * sequence has been cleared.
1580 virtual nsresult
ClearNativeTouchSequence(nsIObserver
* aObserver
);
1583 * Send a native event as if the user double tapped the touchpad with two
1586 virtual nsresult
SynthesizeNativeTouchpadDoubleTap(
1587 LayoutDeviceIntPoint aPoint
, uint32_t aModifierFlags
) = 0;
1590 * See nsIDOMWindowUtils.sendNativeTouchpadPan().
1592 virtual nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
1593 LayoutDeviceIntPoint aPoint
,
1594 double aDeltaX
, double aDeltaY
,
1595 int32_t aModifierFlags
,
1596 nsIObserver
* aObserver
) = 0;
1598 virtual void StartAsyncScrollbarDrag(
1599 const AsyncDragMetrics
& aDragMetrics
) = 0;
1602 * Notify APZ to start autoscrolling.
1603 * @param aAnchorLocation the location of the autoscroll anchor
1604 * @param aGuid identifies the scroll frame to be autoscrolled
1605 * @return true if APZ has been successfully notified
1607 virtual bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
1608 const ScrollableLayerGuid
& aGuid
) = 0;
1611 * Notify APZ to stop autoscrolling.
1612 * @param aGuid identifies the scroll frame which is being autoscrolled.
1614 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) = 0;
1616 virtual LayersId
GetRootLayerTreeId() = 0;
1618 // If this widget supports out-of-process compositing, it can override
1619 // this method to provide additional information to the compositor.
1620 virtual void GetCompositorWidgetInitData(
1621 mozilla::widget::CompositorWidgetInitData
* aInitData
) {}
1624 * Setter/Getter of the system font setting for testing.
1626 virtual nsresult
SetSystemFont(const nsCString
& aFontName
) {
1627 return NS_ERROR_NOT_IMPLEMENTED
;
1629 virtual nsresult
GetSystemFont(nsCString
& aFontName
) {
1630 return NS_ERROR_NOT_IMPLEMENTED
;
1634 * Wayland specific routines.
1636 virtual LayoutDeviceIntSize
GetMoveToRectPopupSize() const {
1637 NS_WARNING("GetLayoutPopupRect implemented only for wayland");
1638 return LayoutDeviceIntSize();
1642 * If this widget uses native pointer lock instead of warp-to-center
1643 * (currently only GTK on Wayland), these methods provide access to that
1646 virtual void SetNativePointerLockCenter(
1647 const LayoutDeviceIntPoint
& aLockCenter
) {}
1648 virtual void LockNativePointer() {}
1649 virtual void UnlockNativePointer() {}
1652 * Get safe area insets except to cutout.
1653 * See https://drafts.csswg.org/css-env-1/#safe-area-insets.
1655 virtual mozilla::LayoutDeviceIntMargin
GetSafeAreaInsets() const {
1656 return mozilla::LayoutDeviceIntMargin();
1662 LongTapInfo(int32_t aPointerId
, LayoutDeviceIntPoint
& aPoint
,
1663 mozilla::TimeDuration aDuration
, nsIObserver
* aObserver
)
1664 : mPointerId(aPointerId
),
1666 mDuration(aDuration
),
1667 mObserver(aObserver
),
1668 mStamp(mozilla::TimeStamp::Now()) {}
1671 LayoutDeviceIntPoint mPosition
;
1672 mozilla::TimeDuration mDuration
;
1673 nsCOMPtr
<nsIObserver
> mObserver
;
1674 mozilla::TimeStamp mStamp
;
1677 static void OnLongTapTimerCallback(nsITimer
* aTimer
, void* aClosure
);
1679 static already_AddRefed
<nsIBidiKeyboard
> CreateBidiKeyboardContentProcess();
1680 static already_AddRefed
<nsIBidiKeyboard
> CreateBidiKeyboardInner();
1682 mozilla::UniquePtr
<LongTapInfo
> mLongTapTouchPoint
;
1683 nsCOMPtr
<nsITimer
> mLongTapTimer
;
1684 static int32_t sPointerIdCounter
;
1688 * If key events have not been handled by content or XBL handlers, they can
1689 * be offered to the system (for custom application shortcuts set in system
1690 * preferences, for example).
1692 virtual void PostHandleKeyEvent(mozilla::WidgetKeyboardEvent
* aEvent
);
1695 * Activates a native menu item at the position specified by the index
1696 * string. The index string is a string of positive integers separated
1697 * by the "|" (pipe) character. The last integer in the string represents
1698 * the item index in a submenu located using the integers preceding it.
1701 * In this string, the first integer represents the top-level submenu
1702 * in the native menu bar. Since the integer is 1, it is the second submeu
1703 * in the native menu bar. Within that, the first item (index 0) is a
1704 * submenu, and we want to activate the 5th item within that submenu.
1706 virtual nsresult
ActivateNativeMenuItemAt(const nsAString
& indexString
) = 0;
1709 * This is used for native menu system testing.
1711 * Updates a native menu at the position specified by the index string.
1712 * The index string is a string of positive integers separated by the "|"
1716 * In this string, the first integer represents the top-level submenu
1717 * in the native menu bar. Since the integer is 1, it is the second submeu
1718 * in the native menu bar. Within that, the first item (index 0) is a
1719 * submenu, and we want to update submenu at index 4 within that submenu.
1721 * If this is called with an empty string it forces a full reload of the
1724 virtual nsresult
ForceUpdateNativeMenuAt(const nsAString
& indexString
) = 0;
1727 * This is used for testing macOS service menu code.
1729 * @param aResult - the current text selection. Is empty if no selection.
1730 * @return nsresult - whether or not aResult was assigned the selected text.
1732 [[nodiscard
]] virtual nsresult
GetSelectionAsPlaintext(nsAString
& aResult
) {
1733 return NS_ERROR_NOT_IMPLEMENTED
;
1737 * Notify IME of the specified notification.
1739 * @return If the notification is mouse button event and it's consumed by
1740 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1742 virtual nsresult
NotifyIME(const IMENotification
& aIMENotification
) = 0;
1745 * MaybeDispatchInitialFocusEvent will dispatch a focus event after creation
1746 * of the widget, in the event that we were not able to observe and respond to
1747 * the initial focus event. This is necessary for the early skeleton UI
1748 * window, which is displayed and receives its initial focus event before we
1749 * can actually respond to it.
1751 virtual void MaybeDispatchInitialFocusEvent() {}
1754 * Notifies the input context changes.
1756 virtual void SetInputContext(const InputContext
& aContext
,
1757 const InputContextAction
& aAction
) = 0;
1760 * Get current input context.
1762 virtual InputContext
GetInputContext() = 0;
1765 * Get native IME context. This is different from GetNativeData() with
1766 * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
1769 virtual NativeIMEContext
GetNativeIMEContext() = 0;
1772 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1773 * native (OS-level) event for it. This method allows tests to simulate
1774 * keystrokes that trigger native key bindings (which require a native
1777 [[nodiscard
]] virtual nsresult
AttachNativeKeyEvent(
1778 mozilla::WidgetKeyboardEvent
& aEvent
) = 0;
1781 * Retrieve edit commands when the key combination of aEvent is used
1782 * in platform native applications.
1784 MOZ_CAN_RUN_SCRIPT
virtual bool GetEditCommands(
1785 mozilla::NativeKeyBindingsType aType
,
1786 const mozilla::WidgetKeyboardEvent
& aEvent
,
1787 nsTArray
<mozilla::CommandInt
>& aCommands
);
1790 * Retrieves a reference to notification requests of IME. Note that the
1791 * reference is valid while the nsIWidget instance is alive. So, if you
1792 * need to store the reference for a long time, you need to grab the widget
1795 const IMENotificationRequests
& IMENotificationRequestsRef();
1798 * Call this method when a dialog is opened which has a default button.
1799 * The button's rectangle should be supplied in aButtonRect.
1801 [[nodiscard
]] virtual nsresult
OnDefaultButtonLoaded(
1802 const LayoutDeviceIntRect
& aButtonRect
) = 0;
1805 * Return true if this process shouldn't use platform widgets, and
1806 * so should use PuppetWidgets instead. If this returns true, the
1807 * result of creating and using a platform widget is undefined,
1808 * and likely to end in crashes or other buggy behavior.
1810 static bool UsePuppetWidgets() { return XRE_IsContentProcess(); }
1812 static already_AddRefed
<nsIWidget
> CreateTopLevelWindow();
1814 static already_AddRefed
<nsIWidget
> CreateChildWindow();
1817 * Allocate and return a "puppet widget" that doesn't directly
1818 * correlate to a platform widget; platform events and data must
1819 * be fed to it. Currently used in content processes. NULL is
1820 * returned if puppet widgets aren't supported in this build
1821 * config, on this platform, or for this process type.
1823 * This function is called "Create" to match CreateInstance().
1824 * The returned widget must still be nsIWidget::Create()d.
1826 static already_AddRefed
<nsIWidget
> CreatePuppetWidget(
1827 BrowserChild
* aBrowserChild
);
1829 static already_AddRefed
<nsIWidget
> CreateHeadlessWidget();
1832 * Return true if widget has it's own GL context
1834 virtual bool HasGLContext() { return false; }
1837 * Returns true to indicate that this widget paints an opaque background
1838 * that we want to be visible under the page, so layout should not force
1839 * a default background.
1841 virtual bool WidgetPaintsBackground() { return false; }
1843 virtual bool NeedsPaint() { return IsVisible() && !GetBounds().IsEmpty(); }
1846 * Get the natural bounds of this widget. This method is only
1847 * meaningful for widgets for which Gecko implements screen
1848 * rotation natively. When this is the case, GetBounds() returns
1849 * the widget bounds taking rotation into account, and
1850 * GetNaturalBounds() returns the bounds *not* taking rotation
1853 * No code outside of the composition pipeline should know or care
1854 * about this. If you're not an agent of the compositor, you
1855 * probably shouldn't call this method.
1857 virtual LayoutDeviceIntRect
GetNaturalBounds() { return GetBounds(); }
1860 * Set size constraints on the window size such that it is never less than
1861 * the specified minimum size and never larger than the specified maximum
1862 * size. The size constraints are sizes of the outer rectangle including
1863 * the window frame and title bar. Use 0 for an unconstrained minimum size
1864 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1865 * does not necessarily change the size of a window to conform to this size,
1866 * thus Resize should be called afterwards.
1868 * @param aConstraints: the size constraints in device pixels
1870 virtual void SetSizeConstraints(const SizeConstraints
& aConstraints
) = 0;
1873 * Return the size constraints currently observed by the widget.
1875 * @return the constraints in device pixels
1877 virtual const SizeConstraints
GetSizeConstraints() = 0;
1880 * Apply the current size constraints to the given size.
1882 * @param aWidth width to constrain
1883 * @param aHeight height to constrain
1885 virtual void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) = 0;
1888 * If this is owned by a BrowserChild, return that. Otherwise return
1891 virtual BrowserChild
* GetOwningBrowserChild() { return nullptr; }
1894 * Returns the layersId for this widget.
1896 virtual LayersId
GetLayersId() const = 0;
1899 * If this isn't directly compositing to its window surface,
1900 * return the compositor which is doing that on our behalf.
1902 virtual CompositorBridgeChild
* GetRemoteRenderer() { return nullptr; }
1905 * If there is a remote renderer, pause or resume it.
1907 virtual void PauseOrResumeCompositor(bool aPause
);
1910 * Clear WebRender resources
1912 virtual void ClearCachedWebrenderResources() {}
1915 * Clear WebRender animation resources
1917 virtual void ClearWebrenderAnimationResources() {}
1920 * Request fast snapshot at RenderCompositor of WebRender.
1921 * Since readback of Windows DirectComposition is very slow.
1923 virtual bool SetNeedFastSnaphot() { return false; }
1926 * If this widget has its own vsync dispatcher, return it, otherwise return
1927 * nullptr. An example of such a local vsync dispatcher would be Wayland frame
1930 virtual RefPtr
<mozilla::VsyncDispatcher
> GetVsyncDispatcher();
1933 * Returns true if the widget requires synchronous repaints on resize,
1936 virtual bool SynchronouslyRepaintOnResize() { return true; }
1939 * Some platforms (only cocoa right now) round widget coordinates to the
1940 * nearest even pixels (see bug 892994), this function allows us to
1941 * determine how widget coordinates will be rounded.
1943 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
1945 virtual void UpdateZoomConstraints(
1946 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
1947 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
) {};
1950 * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
1951 * widget. Note that this never returns nullptr.
1953 virtual TextEventDispatcher
* GetTextEventDispatcher() = 0;
1956 * GetNativeTextEventDispatcherListener() returns a
1957 * TextEventDispatcherListener instance which is used when the widget
1958 * instance handles native IME and/or keyboard events.
1960 virtual TextEventDispatcherListener
*
1961 GetNativeTextEventDispatcherListener() = 0;
1964 * Trigger an animation to zoom to the given |aRect|.
1965 * |aRect| should be relative to the layout viewport of the widget's root
1968 virtual void ZoomToRect(const uint32_t& aPresShellId
,
1969 const ScrollableLayerGuid::ViewID
& aViewId
,
1970 const CSSRect
& aRect
, const uint32_t& aFlags
) = 0;
1973 * LookUpDictionary shows the dictionary for the word around current point.
1975 * @param aText the word to look up dictiorary.
1976 * @param aFontRangeArray text decoration of aText
1977 * @param aIsVertical true if the word is vertical layout
1978 * @param aPoint top-left point of aText
1980 virtual void LookUpDictionary(
1981 const nsAString
& aText
,
1982 const nsTArray
<mozilla::FontRange
>& aFontRangeArray
,
1983 const bool aIsVertical
, const LayoutDeviceIntPoint
& aPoint
) {}
1985 virtual void RequestFxrOutput() {
1986 MOZ_ASSERT(false, "This function should only execute in Windows");
1989 #if defined(MOZ_WIDGET_ANDROID)
1991 * RecvToolbarAnimatorMessageFromCompositor receive message from compositor
1994 * @param aMessage message being sent to Android UI thread.
1996 virtual void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage
) = 0;
1999 * UpdateRootFrameMetrics steady state frame metrics send from compositor
2002 * @param aScrollOffset page scroll offset value in screen pixels.
2003 * @param aZoom current page zoom.
2005 virtual void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
2006 const CSSToScreenScale
& aZoom
) = 0;
2009 * RecvScreenPixels Buffer containing the pixel from the frame buffer. Used
2010 * for android robocop tests.
2012 * @param aMem shared memory containing the frame buffer pixels.
2013 * @param aSize size of the buffer in screen pixels.
2015 virtual void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
,
2016 const ScreenIntSize
& aSize
,
2017 bool aNeedsYFlip
) = 0;
2019 virtual void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight
) {}
2020 virtual mozilla::ScreenIntCoord
GetDynamicToolbarMaxHeight() const {
2025 static already_AddRefed
<nsIBidiKeyboard
> CreateBidiKeyboard();
2028 * Like GetDefaultScale, but taking into account only the system settings
2029 * and ignoring Gecko preferences.
2031 virtual double GetDefaultScaleInternal() { return 1.0; }
2033 // On a given platform, we might have three kinds of widgets:
2034 // In the parent process, we might have native, puppet, or headless widgets.
2035 // In child processes, we only have Puppet widgets.
2036 enum class WidgetType
: uint8_t {
2041 bool IsPuppetWidget() const { return mWidgetType
== WidgetType::Puppet
; }
2043 using WindowButtonType
= mozilla::WindowButtonType
;
2046 * Layout uses this to alert the widget to the client rect representing
2047 * the window maximize button. An empty rect indicates there is no
2048 * maximize button (for example, in fullscreen). This is only implemented
2051 virtual void SetWindowButtonRect(WindowButtonType aButtonType
,
2052 const LayoutDeviceIntRect
& aClientRect
) {}
2055 virtual nsresult
SetHiDPIMode(bool aHiDPI
) {
2056 return NS_ERROR_NOT_IMPLEMENTED
;
2058 virtual nsresult
RestoreHiDPIMode() { return NS_ERROR_NOT_IMPLEMENTED
; }
2062 // keep the list of children. We also keep track of our siblings.
2063 // The ownership model is as follows: parent holds a strong ref to
2064 // the first element of the list, and each element holds a strong
2065 // ref to the next element in the list. The prevsibling and
2066 // lastchild pointers are weak, which is fine as long as they are
2067 // maintained properly.
2068 nsCOMPtr
<nsIWidget
> mFirstChild
;
2069 nsIWidget
* MOZ_NON_OWNING_REF mLastChild
= nullptr;
2070 nsCOMPtr
<nsIWidget
> mNextSibling
;
2071 nsIWidget
* MOZ_NON_OWNING_REF mPrevSibling
= nullptr;
2073 nsIWidget
* MOZ_NON_OWNING_REF mParent
= nullptr;
2074 // When Destroy() is called, the sub class should set this true.
2075 bool mOnDestroyCalled
= false;
2076 WindowType mWindowType
= WindowType::Child
;
2077 WidgetType mWidgetType
= WidgetType::Native
;
2080 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget
, NS_IWIDGET_IID
)
2082 #endif // nsIWidget_h__