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 "ErrorList.h"
14 #include "mozilla/AlreadyAddRefed.h"
15 #include "mozilla/Assertions.h"
16 #include "mozilla/Attributes.h"
17 #include "mozilla/EventForwards.h"
18 #include "mozilla/Maybe.h"
19 #include "mozilla/RefPtr.h"
20 #include "mozilla/TimeStamp.h"
21 #include "mozilla/UniquePtr.h"
22 #include "mozilla/gfx/Matrix.h"
23 #include "mozilla/gfx/Rect.h"
24 #include "mozilla/layers/LayersTypes.h"
25 #include "mozilla/layers/ScrollableLayerGuid.h"
26 #include "mozilla/layers/ZoomConstraints.h"
27 #include "mozilla/image/Resolution.h"
28 #include "mozilla/widget/IMEData.h"
33 #include "nsIObserver.h"
34 #include "nsISupports.h"
37 #include "nsIWidgetListener.h"
40 #include "nsStringFwd.h"
42 #include "nsTHashMap.h"
43 #include "nsWidgetInitData.h"
44 #include "nsXULAppAPI.h"
46 // forward declarations
47 class nsIBidiKeyboard
;
48 class nsIRollupListener
;
56 enum class NativeKeyBindingsType
: uint8_t;
57 class VsyncDispatcher
;
59 class WidgetInputEvent
;
60 class WidgetKeyboardEvent
;
63 enum class StyleWindowShadow
: uint8_t;
64 enum class ColorScheme
: uint8_t;
66 #if defined(MOZ_WIDGET_ANDROID)
70 #endif // defined(MOZ_WIDGET_ANDROID)
73 enum class CallerType
: uint32_t;
77 class AsyncDragMetrics
;
79 class CompositorBridgeChild
;
82 class WebRenderBridgeChild
;
85 class TextEventDispatcher
;
86 class TextEventDispatcherListener
;
87 class CompositorWidget
;
88 class CompositorWidgetInitData
;
91 class DisplayListBuilder
;
92 class IpcResourceUpdateQueue
;
93 enum class RenderRoot
: uint8_t;
95 } // namespace mozilla
98 * Callback function that processes events.
100 * The argument is actually a subtype (subclass) of WidgetEvent which carries
101 * platform specific information about the event. Platform specific code
102 * knows how to deal with it.
104 * The return value determines whether or not the default action should take
107 typedef nsEventStatus (*EVENT_CALLBACK
)(mozilla::WidgetGUIEvent
* aEvent
);
109 // Hide the native window system's real window type so as to avoid
110 // including native window system types and APIs. This is necessary
111 // to ensure cross-platform code.
112 typedef void* nsNativeWidget
;
115 * Flags for the GetNativeData and SetNativeData functions
117 #define NS_NATIVE_WINDOW 0
118 #define NS_NATIVE_GRAPHIC 1
119 #define NS_NATIVE_TMP_WINDOW 2
120 #define NS_NATIVE_WIDGET 3
121 #define NS_NATIVE_DISPLAY 4
122 #define NS_NATIVE_REGION 5
123 #define NS_NATIVE_OFFSETX 6
124 #define NS_NATIVE_OFFSETY 7
125 #define NS_NATIVE_SCREEN 9
126 // The toplevel GtkWidget containing this nsIWidget:
127 #define NS_NATIVE_SHELLWIDGET 10
128 #define NS_NATIVE_OPENGL_CONTEXT 12
129 // This is available only with GetNativeData() in parent process. Anybody
130 // shouldn't access this pointer as a valid pointer since the result may be
131 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
132 // an identifier of distinguishing a text composition is caused by which native
133 // IME context. Note that the result is only valid in the process. So,
134 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
135 #define NS_RAW_NATIVE_IME_CONTEXT 14
136 #define NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID 15
138 # define NS_NATIVE_TSF_THREAD_MGR 100
139 # define NS_NATIVE_TSF_CATEGORY_MGR 101
140 # define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
141 # define NS_NATIVE_ICOREWINDOW 103 // winrt specific
143 #if defined(MOZ_WIDGET_GTK)
144 # define NS_NATIVE_EGL_WINDOW 106
146 #ifdef MOZ_WIDGET_ANDROID
147 # define NS_JAVA_SURFACE 100
150 #define MOZ_WIDGET_MAX_SIZE 16384
151 #define MOZ_WIDGET_INVALID_SCALE 0.0
153 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
154 #define NS_IWIDGET_IID \
156 0x06396bf6, 0x2dd8, 0x45e5, { \
157 0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80 \
165 enum nsTransparencyMode
{
166 eTransparencyOpaque
= 0, // Fully opaque
167 eTransparencyTransparent
, // Parts of the window may be transparent
168 eTransparencyGlass
, // Transparent parts of the window have Vista AeroGlass
170 eTransparencyBorderlessGlass
// As above, but without a border around the
171 // opaque areas when there would otherwise be
172 // one with eTransparencyGlass
173 // If you add to the end here, you must update the serialization code in
174 // WidgetMessageUtils.h
181 enum nsCursor
{ ///(normal cursor, usually rendered as an arrow)
183 ///(system is busy, usually rendered as a hourglass or watch)
185 ///(Selecting something, usually rendered as an IBeam)
187 ///(can hyper-link, usually rendered as a human hand)
189 ///(north/south/west/east edge sizing)
202 eCursor_copy
, // CSS3
204 eCursor_context_menu
,
215 eCursor_vertical_text
,
222 // This one is used for array sizing, and so better be the last
223 // one in this list...
226 // ...except for this one.
227 eCursorInvalid
= eCursorCount
+ 1
230 enum nsTopLevelWidgetZPlacement
{ // for PlaceBehind()
231 eZPlacementBottom
= 0, // bottom of the window stack
232 eZPlacementBelow
, // just below another widget
233 eZPlacementTop
// top of the window stack
237 * Before the OS goes to sleep, this topic is notified.
239 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
242 * After the OS wakes up, this topic is notified.
244 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
247 * Before the OS suspends the current process, this topic is notified. Some
248 * OS will kill processes that are suspended instead of resuming them.
249 * For that reason this topic may be useful to safely close down resources.
251 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
254 * After the current process resumes from being suspended, this topic is
257 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
260 * When an app(-shell) is activated by the OS, this topic is notified.
261 * Currently, this only happens on Mac OSX.
263 #define NS_WIDGET_MAC_APP_ACTIVATE_OBSERVER_TOPIC "mac_app_activate"
269 * Size constraints for setting the minimum and maximum size of a widget.
270 * Values are in device pixels.
272 struct SizeConstraints
{
274 : mMaxSize(MOZ_WIDGET_MAX_SIZE
, MOZ_WIDGET_MAX_SIZE
),
275 mScale(MOZ_WIDGET_INVALID_SCALE
) {}
277 SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize
,
278 mozilla::LayoutDeviceIntSize aMaxSize
,
279 mozilla::DesktopToLayoutDeviceScale aScale
)
280 : mMinSize(aMinSize
), mMaxSize(aMaxSize
), mScale(aScale
) {
281 if (mMaxSize
.width
> MOZ_WIDGET_MAX_SIZE
) {
282 mMaxSize
.width
= MOZ_WIDGET_MAX_SIZE
;
284 if (mMaxSize
.height
> MOZ_WIDGET_MAX_SIZE
) {
285 mMaxSize
.height
= MOZ_WIDGET_MAX_SIZE
;
289 mozilla::LayoutDeviceIntSize mMinSize
;
290 mozilla::LayoutDeviceIntSize mMaxSize
;
293 * The scale used to convert from desktop to device dimensions.
294 * MOZ_WIDGET_INVALID_SCALE if the value is not known.
296 * Bug 1701109 is filed to revisit adding of 'mScale' and deal
297 * with multi-monitor scaling issues in more complete way across
298 * all widget implementations.
300 mozilla::DesktopToLayoutDeviceScale mScale
;
303 struct AutoObserverNotifier
{
304 AutoObserverNotifier(nsIObserver
* aObserver
, const char* aTopic
)
305 : mObserver(aObserver
), mTopic(aTopic
) {}
307 void SkipNotification() { mObserver
= nullptr; }
309 uint64_t SaveObserver() {
313 uint64_t observerId
= ++sObserverId
;
314 sSavedObservers
.InsertOrUpdate(observerId
, mObserver
);
319 ~AutoObserverNotifier() {
321 mObserver
->Observe(nullptr, mTopic
, nullptr);
325 static void NotifySavedObserver(const uint64_t& aObserverId
,
326 const char* aTopic
) {
327 nsCOMPtr
<nsIObserver
> observer
= sSavedObservers
.Get(aObserverId
);
329 MOZ_ASSERT(aObserverId
== 0,
330 "We should always find a saved observer for nonzero IDs");
334 sSavedObservers
.Remove(aObserverId
);
335 observer
->Observe(nullptr, aTopic
, nullptr);
339 nsCOMPtr
<nsIObserver
> mObserver
;
343 static uint64_t sObserverId
;
344 static nsTHashMap
<uint64_t, nsCOMPtr
<nsIObserver
>> sSavedObservers
;
347 } // namespace widget
348 } // namespace mozilla
351 * The base class for all the widgets. It provides the interface for
352 * all basic and necessary functionality.
354 class nsIWidget
: public nsISupports
{
356 typedef mozilla::dom::BrowserChild BrowserChild
;
359 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild
;
360 typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics
;
361 typedef mozilla::layers::FrameMetrics FrameMetrics
;
362 typedef mozilla::layers::LayerManager LayerManager
;
363 typedef mozilla::WindowRenderer WindowRenderer
;
364 typedef mozilla::layers::LayersBackend LayersBackend
;
365 typedef mozilla::layers::LayersId LayersId
;
366 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid
;
367 typedef mozilla::layers::ZoomConstraints ZoomConstraints
;
368 typedef mozilla::widget::IMEEnabled IMEEnabled
;
369 typedef mozilla::widget::IMEMessage IMEMessage
;
370 typedef mozilla::widget::IMENotification IMENotification
;
371 typedef mozilla::widget::IMENotificationRequests IMENotificationRequests
;
372 typedef mozilla::widget::IMEState IMEState
;
373 typedef mozilla::widget::InputContext InputContext
;
374 typedef mozilla::widget::InputContextAction InputContextAction
;
375 typedef mozilla::widget::NativeIMEContext NativeIMEContext
;
376 typedef mozilla::widget::SizeConstraints SizeConstraints
;
377 typedef mozilla::widget::TextEventDispatcher TextEventDispatcher
;
378 typedef mozilla::widget::TextEventDispatcherListener
379 TextEventDispatcherListener
;
380 typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin
;
381 typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint
;
382 typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect
;
383 typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion
;
384 typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize
;
385 typedef mozilla::ScreenIntPoint ScreenIntPoint
;
386 typedef mozilla::ScreenIntMargin ScreenIntMargin
;
387 typedef mozilla::ScreenIntSize ScreenIntSize
;
388 typedef mozilla::ScreenPoint ScreenPoint
;
389 typedef mozilla::CSSToScreenScale CSSToScreenScale
;
390 typedef mozilla::DesktopIntRect DesktopIntRect
;
391 typedef mozilla::DesktopPoint DesktopPoint
;
392 typedef mozilla::DesktopRect DesktopRect
;
393 typedef mozilla::DesktopSize DesktopSize
;
394 typedef mozilla::CSSPoint CSSPoint
;
395 typedef mozilla::CSSRect CSSRect
;
397 enum class WindowButtonType
{
404 // Used in UpdateThemeGeometries.
405 struct ThemeGeometry
{
406 // The ThemeGeometryType value for the themed widget, see
407 // nsITheme::ThemeGeometryTypeForWidget.
408 nsITheme::ThemeGeometryType mType
;
409 // The device-pixel rect within the window for the themed widget
410 LayoutDeviceIntRect mRect
;
412 ThemeGeometry(nsITheme::ThemeGeometryType aType
,
413 const LayoutDeviceIntRect
& aRect
)
414 : mType(aType
), mRect(aRect
) {}
417 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID
)
420 : mLastChild(nullptr),
421 mPrevSibling(nullptr),
422 mOnDestroyCalled(false),
423 mWindowType(eWindowType_child
),
427 ClearNativeTouchSequence(nullptr);
431 * Create and initialize a widget.
433 * All the arguments can be null in which case a top level window
434 * with size 0 is created. The event callback function has to be
435 * provided only if the caller wants to deal with the events this
436 * widget receives. The event callback is basically a preprocess
437 * hook called synchronously. The return value determines whether
438 * the event goes to the default window procedure or it is hidden
439 * to the os. The assumption is that if the event handler returns
440 * false the widget does not see the event. The widget should not
441 * automatically clear the window to the background color. The
442 * calling code must handle paint messages and clear the background
445 * In practice at least one of aParent and aNativeParent will be null. If
446 * both are null the widget isn't parented (e.g. context menus or
447 * independent top level windows).
449 * The dimensions given in aRect are specified in the parent's
450 * device coordinate system.
451 * This must not be called for parentless widgets such as top-level
452 * windows, which use the desktop pixel coordinate system; a separate
453 * method is provided for these.
455 * @param aParent parent nsIWidget
456 * @param aNativeParent native parent widget
457 * @param aRect the widget dimension
458 * @param aInitData data that is used for widget initialization
461 [[nodiscard
]] virtual nsresult
Create(
462 nsIWidget
* aParent
, nsNativeWidget aNativeParent
,
463 const LayoutDeviceIntRect
& aRect
,
464 nsWidgetInitData
* aInitData
= nullptr) = 0;
467 * As above, but with aRect specified in DesktopPixel units (for top-level
469 * Default implementation just converts aRect to device pixels and calls
470 * through to device-pixel Create, but platforms may override this if the
471 * mapping is not straightforward or the native platform needs to use the
472 * desktop pixel values directly.
474 [[nodiscard
]] virtual nsresult
Create(nsIWidget
* aParent
,
475 nsNativeWidget aNativeParent
,
476 const DesktopIntRect
& aRect
,
477 nsWidgetInitData
* aInitData
= nullptr) {
478 LayoutDeviceIntRect devPixRect
=
479 RoundedToInt(aRect
* GetDesktopToDeviceScale());
480 return Create(aParent
, aNativeParent
, devPixRect
, aInitData
);
484 * Allocate, initialize, and return a widget that is a child of
485 * |this|. The returned widget (if nonnull) has gone through the
486 * equivalent of CreateInstance(widgetCID) + Create(...).
488 * |CreateChild()| lets widget backends decide whether to parent
489 * the new child widget to this, nonnatively parent it, or both.
490 * This interface exists to support the PuppetWidget backend,
491 * which is entirely non-native. All other params are the same as
494 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
495 * |nsIWidget*| this, not its native widget (if it exists), when
496 * calling |Create()|. This is a timid hack around poorly
497 * understood code, and shouldn't be used in new code.
499 virtual already_AddRefed
<nsIWidget
> CreateChild(
500 const LayoutDeviceIntRect
& aRect
, nsWidgetInitData
* aInitData
= nullptr,
501 bool aForceUseIWidgetParent
= false) = 0;
504 * Attach to a top level widget.
506 * In cases where a top level chrome widget is being used as a content
507 * container, attach a secondary listener and update the device
508 * context. The primary widget listener will continue to be called for
509 * notifications relating to the top-level window, whereas other
510 * notifications such as painting and events will instead be called via
511 * the attached listener. SetAttachedWidgetListener should be used to
512 * assign the attached listener.
514 * aUseAttachedEvents if true, events are sent to the attached listener
515 * instead of the normal listener.
517 virtual void AttachViewToTopLevel(bool aUseAttachedEvents
) = 0;
520 * Accessor functions to get and set the attached listener. Used by
521 * nsView in connection with AttachViewToTopLevel above.
523 virtual void SetAttachedWidgetListener(nsIWidgetListener
* aListener
) = 0;
524 virtual nsIWidgetListener
* GetAttachedWidgetListener() const = 0;
525 virtual void SetPreviouslyAttachedWidgetListener(
526 nsIWidgetListener
* aListener
) = 0;
527 virtual nsIWidgetListener
* GetPreviouslyAttachedWidgetListener() = 0;
530 * Notifies the root widget of a non-blank paint.
532 virtual void DidGetNonBlankPaint() {}
535 * Accessor functions to get and set the listener which handles various
536 * actions for the widget.
539 virtual nsIWidgetListener
* GetWidgetListener() const = 0;
540 virtual void SetWidgetListener(nsIWidgetListener
* alistener
) = 0;
544 * Close and destroy the internal native window.
545 * This method does not delete the widget.
548 virtual void Destroy() = 0;
551 * Destroyed() returns true if Destroy() has been called already.
554 bool Destroyed() const { return mOnDestroyCalled
; }
559 * Change the widget's parent. Null parents are allowed.
561 * @param aNewParent new parent
563 virtual void SetParent(nsIWidget
* aNewParent
) = 0;
566 * Return the parent Widget of this Widget or nullptr if this is a
569 * @return the parent widget or nullptr if it does not have a parent
572 virtual nsIWidget
* GetParent(void) = 0;
575 * Return the top level Widget of this Widget
577 * @return the top level widget
579 virtual nsIWidget
* GetTopLevelWidget() = 0;
582 * Return the top (non-sheet) parent of this Widget if it's a sheet,
583 * or nullptr if this isn't a sheet (or some other error occurred).
584 * Sheets are only supported on some platforms (currently only macOS).
586 * @return the top (non-sheet) parent widget or nullptr
589 virtual nsIWidget
* GetSheetWindowParent(void) = 0;
592 * Return the physical DPI of the screen containing the window ...
593 * the number of device pixels per inch.
595 virtual float GetDPI() = 0;
598 * Return the scaling factor between device pixels and the platform-
599 * dependent "desktop pixels" used to manage window positions on a
600 * potentially multi-screen, mixed-resolution desktop.
602 virtual mozilla::DesktopToLayoutDeviceScale
GetDesktopToDeviceScale() = 0;
605 * Return the scaling factor between device pixels and the platform-
606 * dependent "desktop pixels" by looking up the screen by the position
609 virtual mozilla::DesktopToLayoutDeviceScale
610 GetDesktopToDeviceScaleByScreen() = 0;
613 * Return the default scale factor for the window. This is the
614 * default number of device pixels per CSS pixel to use. This should
615 * depend on OS/platform settings such as the Mac's "UI scale factor"
616 * or Windows' "font DPI". This will take into account Gecko preferences
617 * overriding the system setting.
619 mozilla::CSSToLayoutDeviceScale
GetDefaultScale();
622 * Return the first child of this widget. Will return null if
623 * there are no children.
625 nsIWidget
* GetFirstChild() const { return mFirstChild
; }
628 * Return the last child of this widget. Will return null if
629 * there are no children.
631 nsIWidget
* GetLastChild() const { return mLastChild
; }
634 * Return the next sibling of this widget
636 nsIWidget
* GetNextSibling() const { return mNextSibling
; }
639 * Set the next sibling of this widget
641 void SetNextSibling(nsIWidget
* aSibling
) { mNextSibling
= aSibling
; }
644 * Return the previous sibling of this widget
646 nsIWidget
* GetPrevSibling() const { return mPrevSibling
; }
649 * Set the previous sibling of this widget
651 void SetPrevSibling(nsIWidget
* aSibling
) { mPrevSibling
= aSibling
; }
654 * Show or hide this widget
656 * @param aState true to show the Widget, false to hide it
659 virtual void Show(bool aState
) = 0;
662 * Whether or not a widget must be recreated after being hidden to show
665 virtual bool NeedsRecreateToReshow() { return false; }
668 * Make the window modal.
670 virtual void SetModal(bool aModal
) = 0;
673 * Make the non-modal window opened by modal window fake-modal, that will
674 * call SetFakeModal(false) on destroy on Cocoa.
676 virtual void SetFakeModal(bool aModal
) { SetModal(aModal
); }
679 * Are we app modal. Currently only implemented on Cocoa.
681 virtual bool IsRunningAppModal() { return false; }
684 * The maximum number of simultaneous touch contacts supported by the device.
685 * In the case of devices with multiple digitizers (e.g. multiple touch
686 * screens), the value will be the maximum of the set of maximum supported
687 * contacts by each individual digitizer.
689 virtual uint32_t GetMaxTouchPoints() const = 0;
692 * Returns whether the window is visible
695 virtual bool IsVisible() const = 0;
698 * Perform platform-dependent sanity check on a potential window position.
699 * This is guaranteed to work only for top-level windows.
701 * @param aAllowSlop: if true, allow the window to slop offscreen;
702 * the window should be partially visible. if false,
703 * force the entire window onscreen (or at least
704 * the upper-left corner, if it's too large).
705 * @param aX in: an x position expressed in screen coordinates.
706 * out: the x position constrained to fit on the screen(s).
707 * @param aY in: an y position expressed in screen coordinates.
708 * out: the y position constrained to fit on the screen(s).
711 virtual void ConstrainPosition(bool aAllowSlop
, int32_t* aX
, int32_t* aY
) = 0;
716 * For a top-level window widget, the "parent's coordinate system" is the
717 * "global" display pixel coordinate space, *not* device pixels (which
718 * may be inconsistent between multiple screens, at least in the Mac OS
719 * case with mixed hi-dpi and lo-dpi displays). This applies to all the
720 * following Move and Resize widget APIs.
722 * The display-/device-pixel distinction becomes important for (at least)
723 * macOS with Hi-DPI (retina) displays, and Windows when the UI scale factor
724 * is set to other than 100%.
726 * The Move and Resize methods take floating-point parameters, rather than
727 * integer ones. This is important when manipulating top-level widgets,
728 * where the coordinate system may not be an integral multiple of the
729 * device-pixel space.
735 * Coordinates refer to the top-left of the widget. For toplevel windows
736 * with decorations, this is the top-left of the titlebar and frame .
738 * @param aX the new x position expressed in the parent's coordinate system
739 * @param aY the new y position expressed in the parent's coordinate system
742 virtual void Move(double aX
, double aY
) = 0;
745 * Reposition this widget so that the client area has the given offset.
747 * @param aOffset the new offset of the client area expressed as an
748 * offset from the origin of the client area of the parent
749 * widget (for root widgets and popup widgets it is in
750 * screen coordinates)
752 virtual void MoveClient(const DesktopPoint
& aOffset
) = 0;
755 * Resize this widget. Any size constraints set for the window by a
756 * previous call to SetSizeConstraints will be applied.
758 * @param aWidth the new width expressed in the parent's coordinate system
759 * @param aHeight the new height expressed in the parent's coordinate
761 * @param aRepaint whether the widget should be repainted
763 virtual void Resize(double aWidth
, double aHeight
, bool aRepaint
) = 0;
766 * Lock the aspect ratio of a Window
768 * @param aShouldLock bool
771 virtual void LockAspectRatio(bool aShouldLock
){};
774 * Move or resize this widget. Any size constraints set for the window by
775 * a previous call to SetSizeConstraints will be applied.
777 * @param aX the new x position expressed in the parent's coordinate
779 * @param aY the new y position expressed in the parent's coordinate
781 * @param aWidth the new width expressed in the parent's coordinate system
782 * @param aHeight the new height expressed in the parent's coordinate
784 * @param aRepaint whether the widget should be repainted if the size
788 virtual void Resize(double aX
, double aY
, double aWidth
, double aHeight
,
791 virtual mozilla::Maybe
<bool> IsResizingNativeWidget() {
792 return mozilla::Nothing();
796 * Resize the widget so that the inner client area has the given size.
798 * @param aSize the new size of the client area.
799 * @param aRepaint whether the widget should be repainted
801 virtual void ResizeClient(const DesktopSize
& aSize
, bool aRepaint
) = 0;
804 * Resize and reposition the widget so tht inner client area has the given
807 * @param aRect the new offset and size of the client area. The offset is
808 * expressed as an offset from the origin of the client area
809 * of the parent widget (for root widgets and popup widgets it
810 * is in screen coordinates).
811 * @param aRepaint whether the widget should be repainted
813 virtual void ResizeClient(const DesktopRect
& aRect
, bool aRepaint
) = 0;
816 * Sets the widget's z-index.
818 virtual void SetZIndex(int32_t aZIndex
) = 0;
821 * Gets the widget's z-index.
823 int32_t GetZIndex() { return mZIndex
; }
826 * Position this widget just behind the given widget. (Used to
827 * control z-order for top-level widgets. Get/SetZIndex by contrast
828 * control z-order for child widgets of other widgets.)
829 * @param aPlacement top, bottom, or below a widget
830 * (if top or bottom, param aWidget is ignored)
831 * @param aWidget widget to place this widget behind
832 * (only if aPlacement is eZPlacementBelow).
833 * null is equivalent to aPlacement of eZPlacementTop
834 * @param aActivate true to activate the widget after placing it
836 virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement
,
837 nsIWidget
* aWidget
, bool aActivate
) = 0;
840 * Minimize, maximize or normalize the window size.
841 * Takes a value from nsSizeMode (see nsIWidgetListener.h)
843 virtual void SetSizeMode(nsSizeMode aMode
) = 0;
845 virtual void GetWorkspaceID(nsAString
& workspaceID
) = 0;
847 virtual void MoveToWorkspace(const nsAString
& workspaceID
) = 0;
850 * Suppress animations that are applied to a window by OS.
852 virtual void SuppressAnimation(bool aSuppress
) {}
855 * Return size mode (minimized, maximized, normalized).
856 * Returns a value from nsSizeMode (see nsIWidgetListener.h)
858 virtual nsSizeMode
SizeMode() = 0;
861 * Ask whether the window is tiled.
863 virtual bool IsTiled() const = 0;
866 * Ask wether the widget is fully occluded
868 virtual bool IsFullyOccluded() const = 0;
871 * Enable or disable this Widget
873 * @param aState true to enable the Widget, false to disable it.
875 virtual void Enable(bool aState
) = 0;
878 * Ask whether the widget is enabled
880 virtual bool IsEnabled() const = 0;
883 * Whether we should request activation of this widget's toplevel window.
891 * Request activation of this window or give focus to this widget.
893 virtual void SetFocus(Raise
, mozilla::dom::CallerType aCallerType
) = 0;
896 * Get this widget's outside dimensions relative to its parent widget. For
897 * popup widgets the returned rect is in screen coordinates and not
898 * relative to its parent widget.
900 * @return the x, y, width and height of this widget.
902 virtual LayoutDeviceIntRect
GetBounds() = 0;
905 * Get this widget's outside dimensions in device coordinates. This
906 * includes any title bar on the window.
908 * @return the x, y, width and height of this widget.
910 virtual LayoutDeviceIntRect
GetScreenBounds() = 0;
913 * Similar to GetScreenBounds except that this function will always
914 * get the size when the widget is in the nsSizeMode_Normal size mode
915 * even if the current size mode is not nsSizeMode_Normal.
916 * This method will fail if the size mode is not nsSizeMode_Normal and
917 * the platform doesn't have the ability.
918 * This method will always succeed if the current size mode is
921 * @param aRect On return it holds the x, y, width and height of
924 [[nodiscard
]] virtual nsresult
GetRestoredBounds(
925 LayoutDeviceIntRect
& aRect
) = 0;
928 * Get this widget's client area bounds, if the window has a 3D border
929 * appearance this returns the area inside the border. The position is the
930 * position of the client area relative to the client area of the parent
931 * widget (for root widgets and popup widgets it is in screen coordinates).
933 * @return the x, y, width and height of the client area of this widget.
935 virtual LayoutDeviceIntRect
GetClientBounds() = 0;
938 * Sets the non-client area dimensions of the window. Pass -1 to restore
939 * the system default frame size for that border. Pass zero to remove
940 * a border, or pass a specific value adjust a border. Units are in
941 * pixels. (DPI dependent)
944 * Windows: shrinking top non-client height will remove application
945 * icon and window title text. Glass desktops will refuse to set
946 * dimensions between zero and size < system default.
948 virtual nsresult
SetNonClientMargins(LayoutDeviceIntMargin
& aMargins
) = 0;
951 * Sets the region around the edges of the window that can be dragged to
952 * resize the window. All four sides of the window will get the same margin.
954 virtual void SetResizeMargin(mozilla::LayoutDeviceIntCoord aResizeMargin
) = 0;
956 * Get the client offset from the window origin.
958 * @return the x and y of the offset.
960 virtual LayoutDeviceIntPoint
GetClientOffset() = 0;
963 * Equivalent to GetClientBounds but only returns the size.
965 virtual LayoutDeviceIntSize
GetClientSize() {
966 // Depending on the backend, overloading this method may be useful if
967 // requesting the client offset is expensive.
968 return GetClientBounds().Size();
972 * Set the background color for this widget
974 * @param aColor the new background color
978 virtual void SetBackgroundColor(const nscolor
& aColor
) {}
981 * If a cursor type is currently cached locally for this widget, clear the
982 * cached cursor to force an update on the next SetCursor call.
985 virtual void ClearCachedCursor() = 0;
988 // The system cursor chosen by the page. This is used if there's no custom
989 // cursor, or if we fail to use the custom cursor in some way (if the image
990 // fails to load, for example).
991 nsCursor mDefaultCursor
= eCursor_standard
;
992 // May be null, to represent no custom cursor image.
993 nsCOMPtr
<imgIContainer
> mContainer
;
994 uint32_t mHotspotX
= 0;
995 uint32_t mHotspotY
= 0;
996 mozilla::ImageResolution mResolution
;
998 bool IsCustom() const { return !!mContainer
; }
1000 bool operator==(const Cursor
& aOther
) const {
1001 return mDefaultCursor
== aOther
.mDefaultCursor
&&
1002 mContainer
.get() == aOther
.mContainer
.get() &&
1003 mHotspotX
== aOther
.mHotspotX
&& mHotspotY
== aOther
.mHotspotY
&&
1004 mResolution
== aOther
.mResolution
;
1007 bool operator!=(const Cursor
& aOther
) const { return !(*this == aOther
); }
1011 * Sets the cursor for this widget.
1013 virtual void SetCursor(const Cursor
&) = 0;
1015 static nsIntSize
CustomCursorSize(const Cursor
&);
1018 * Get the window type of this widget.
1020 nsWindowType
WindowType() { return mWindowType
; }
1023 * Set the transparency mode of the top-level window containing this widget.
1024 * So, e.g., if you call this on the widget for an IFRAME, the top level
1025 * browser window containing the IFRAME actually gets set. Be careful.
1027 * This can fail if the platform doesn't support
1028 * transparency/glass. By default widgets are not
1029 * transparent. This will also fail if the toplevel window is not
1030 * a Mozilla window, e.g., if the widget is in an embedded
1033 * After transparency/glass has been enabled, the initial alpha channel
1034 * value for all pixels is 1, i.e., opaque.
1035 * If the window is resized then the alpha channel values for
1036 * all pixels are reset to 1.
1037 * Pixel RGB color values are already premultiplied with alpha channel values.
1039 virtual void SetTransparencyMode(nsTransparencyMode aMode
) = 0;
1042 * Get the transparency mode of the top-level window that contains this
1045 virtual nsTransparencyMode
GetTransparencyMode() = 0;
1048 * Set the shadow style of the window.
1050 * Ignored on child widgets and on non-Mac platforms.
1052 virtual void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle
) = 0;
1055 * Set the opacity of the window.
1056 * Values need to be between 0.0f (invisible) and 1.0f (fully opaque).
1058 * Ignored on child widgets and on non-Mac platforms.
1060 virtual void SetWindowOpacity(float aOpacity
) {}
1063 * Set the transform of the window. Values are in device pixels,
1064 * the origin is the top left corner of the window.
1066 * Ignored on child widgets and on non-Mac platforms.
1068 virtual void SetWindowTransform(const mozilla::gfx::Matrix
& aTransform
) {}
1071 * Set the preferred color-scheme for the widget.
1072 * Ignored on non-Mac platforms.
1074 virtual void SetColorScheme(const mozilla::Maybe
<mozilla::ColorScheme
>&) {}
1077 * Set whether the window should ignore mouse events or not, and if it should
1078 * not, what input margin should it use.
1080 * This is only used on popup windows. The margin is only implemented on
1083 struct InputRegion
{
1084 bool mFullyTransparent
= false;
1085 mozilla::LayoutDeviceIntCoord mMargin
= 0;
1087 virtual void SetInputRegion(const InputRegion
&) {}
1090 * On macOS, this method shows or hides the pill button in the titlebar
1091 * that's used to collapse the toolbar.
1093 * Ignored on child widgets and on non-Mac platforms.
1095 virtual void SetShowsToolbarButton(bool aShow
) = 0;
1098 * On macOS, this method determines whether we tell cocoa that the window
1099 * supports native full screen. If we do so, and another window is in
1100 * native full screen, this window will also appear in native full screen.
1102 * We generally only want to do this for primary application windows.
1104 * Ignored on child widgets and on non-Mac platforms.
1106 virtual void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen
) = 0;
1108 enum WindowAnimationType
{
1109 eGenericWindowAnimation
,
1110 eDocumentWindowAnimation
1114 * Sets the kind of top-level window animation this widget should have. On
1115 * macOS, this causes a particular kind of animation to be shown when the
1116 * window is first made visible.
1118 * Ignored on child widgets and on non-Mac platforms.
1120 virtual void SetWindowAnimationType(WindowAnimationType aType
) = 0;
1123 * Specifies whether the window title should be drawn even if the window
1124 * contents extend into the titlebar. Ignored on windows that don't draw
1125 * in the titlebar. Only implemented on macOS.
1127 virtual void SetDrawsTitle(bool aDrawTitle
) {}
1130 * Hide window chrome (borders, buttons) for this widget.
1133 virtual void HideWindowChrome(bool aShouldHide
) = 0;
1135 enum FullscreenTransitionStage
{
1136 eBeforeFullscreenToggle
,
1137 eAfterFullscreenToggle
1141 * Prepares for fullscreen transition and returns whether the widget
1142 * supports fullscreen transition. If this method returns false,
1143 * PerformFullscreenTransition() must never be called. Otherwise,
1144 * caller should call that method twice with "before" and "after"
1145 * stages respectively in order. In the latter case, this method may
1146 * return some data via aData pointer. Caller must pass that data to
1147 * PerformFullscreenTransition() if any, and caller is responsible
1148 * for releasing that data.
1150 virtual bool PrepareForFullscreenTransition(nsISupports
** aData
) = 0;
1153 * Performs fullscreen transition. This method returns immediately,
1154 * and will post aCallback to the main thread when the transition
1157 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage
,
1160 nsIRunnable
* aCallback
) = 0;
1163 * Perform any actions needed after the fullscreen transition has ended.
1165 virtual void CleanupFullscreenTransition() = 0;
1168 * Return the screen the widget is in, or null if we don't know.
1170 virtual already_AddRefed
<nsIScreen
> GetWidgetScreen() = 0;
1173 * Put the toplevel window into or out of fullscreen mode.
1175 * @return NS_OK if the widget is setup properly for fullscreen and
1176 * FullscreenChanged callback has been or will be called. If other
1177 * value is returned, the caller should continue the change itself.
1179 virtual nsresult
MakeFullScreen(bool aFullScreen
) = 0;
1182 * Same as MakeFullScreen, except that, on systems which natively
1183 * support fullscreen transition, calling this method explicitly
1184 * requests that behavior.
1185 * It is currently only supported on macOS 10.7+.
1187 virtual nsresult
MakeFullScreenWithNativeTransition(bool aFullScreen
) {
1188 return MakeFullScreen(aFullScreen
);
1192 * Invalidate a specified rect for a widget so that it will be repainted
1195 virtual void Invalidate(const LayoutDeviceIntRect
& aRect
) = 0;
1197 enum LayerManagerPersistence
{
1198 LAYER_MANAGER_CURRENT
= 0,
1199 LAYER_MANAGER_PERSISTENT
1203 * Return the widget's LayerManager. The layer tree for that LayerManager is
1204 * what gets rendered to the widget.
1206 * Note that this tries to create a renderer if it doesn't exist.
1208 virtual WindowRenderer
* GetWindowRenderer() = 0;
1211 * Returns whether there's an existing window renderer.
1213 virtual bool HasWindowRenderer() const = 0;
1216 * Called before each layer manager transaction to allow any preparation
1217 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1219 * Always called on the main thread.
1221 virtual void PrepareWindowEffects() = 0;
1224 * Called on the main thread at the end of WebRender display list building.
1226 virtual void AddWindowOverlayWebRenderCommands(
1227 mozilla::layers::WebRenderBridgeChild
* aWrBridge
,
1228 mozilla::wr::DisplayListBuilder
& aBuilder
,
1229 mozilla::wr::IpcResourceUpdateQueue
& aResources
) {}
1232 * Called when Gecko knows which themed widgets exist in this window.
1233 * The passed array contains an entry for every themed widget of the right
1234 * type (currently only StyleAppearance::Toolbar) within the window, except
1235 * for themed widgets which are transformed or have effects applied to them
1236 * (e.g. CSS opacity or filters).
1237 * This could sometimes be called during display list construction
1238 * outside of painting.
1239 * If called during painting, it will be called before we actually
1242 virtual void UpdateThemeGeometries(
1243 const nsTArray
<ThemeGeometry
>& aThemeGeometries
) = 0;
1246 * Informs the widget about the region of the window that is opaque.
1248 * @param aOpaqueRegion the region of the window that is opaque.
1250 virtual void UpdateOpaqueRegion(const LayoutDeviceIntRegion
& aOpaqueRegion
) {}
1253 * Informs the widget about the region of the window that is draggable.
1255 virtual void UpdateWindowDraggingRegion(
1256 const LayoutDeviceIntRegion
& aRegion
) {}
1259 * Tells the widget whether the given input block results in a swipe.
1260 * Should be called in response to a WidgetWheelEvent that has
1261 * mFlags.mCanTriggerSwipe set on it.
1263 virtual void ReportSwipeStarted(uint64_t aInputBlockId
, bool aStartSwipe
) {}
1270 virtual void AddChild(nsIWidget
* aChild
) = 0;
1271 virtual void RemoveChild(nsIWidget
* aChild
) = 0;
1272 virtual void* GetNativeData(uint32_t aDataType
) = 0;
1273 virtual void SetNativeData(uint32_t aDataType
, uintptr_t aVal
) = 0;
1274 virtual void FreeNativeData(void* data
, uint32_t aDataType
) = 0; //~~~
1279 * Set the widget's title.
1280 * Must be called after Create.
1282 * @param aTitle string displayed as the title of the widget
1284 virtual nsresult
SetTitle(const nsAString
& aTitle
) = 0;
1287 * Set the widget's icon.
1288 * Must be called after Create.
1290 * @param aIconSpec string specifying the icon to use; convention is to
1291 * pass a resource: URL from which a platform-dependent
1292 * resource file name will be constructed
1294 virtual void SetIcon(const nsAString
& aIconSpec
) = 0;
1297 * Return this widget's origin in screen coordinates.
1299 * @return screen coordinates stored in the x,y members
1301 virtual LayoutDeviceIntPoint
WidgetToScreenOffset() = 0;
1304 * The same as WidgetToScreenOffset(), except in the case of
1305 * PuppetWidget where this method omits the chrome offset.
1307 virtual LayoutDeviceIntPoint
TopLevelWidgetToScreenOffset() {
1308 return WidgetToScreenOffset();
1312 * For a PuppetWidget, returns the transform from the coordinate
1313 * space of the PuppetWidget to the coordinate space of the
1314 * top-level native widget.
1316 * Identity transform in other cases.
1318 virtual mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
1319 WidgetToTopLevelWidgetTransform() {
1320 return mozilla::LayoutDeviceToLayoutDeviceMatrix4x4();
1323 mozilla::LayoutDeviceIntPoint
WidgetToTopLevelWidgetOffset() {
1324 return mozilla::LayoutDeviceIntPoint::Round(
1325 WidgetToTopLevelWidgetTransform().TransformPoint(
1326 mozilla::LayoutDevicePoint()));
1330 * Given the specified client size, return the corresponding window size,
1331 * which includes the area for the borders and titlebar. This method
1332 * should work even when the window is not yet visible.
1334 virtual LayoutDeviceIntSize
ClientToWindowSize(
1335 const LayoutDeviceIntSize
& aClientSize
) = 0;
1338 * Dispatches an event to the widget
1340 virtual nsresult
DispatchEvent(mozilla::WidgetGUIEvent
* event
,
1341 nsEventStatus
& aStatus
) = 0;
1344 * Dispatches an event to APZ only.
1345 * No-op in the child process.
1347 virtual void DispatchEventToAPZOnly(mozilla::WidgetInputEvent
* aEvent
) = 0;
1350 * Dispatch a gecko event for this widget.
1351 * Returns true if it's consumed. Otherwise, false.
1353 virtual bool DispatchWindowEvent(mozilla::WidgetGUIEvent
& event
) = 0;
1355 // A structure that groups the statuses from APZ dispatch and content
1357 struct ContentAndAPZEventStatus
{
1358 // Either of these may not be set if the event was not dispatched
1359 // to APZ or to content.
1360 nsEventStatus mApzStatus
= nsEventStatus_eIgnore
;
1361 nsEventStatus mContentStatus
= nsEventStatus_eIgnore
;
1365 * Dispatches an event that must be handled by APZ first, when APZ is
1366 * enabled. If invoked in the child process, it is forwarded to the
1367 * parent process synchronously.
1369 virtual ContentAndAPZEventStatus
DispatchInputEvent(
1370 mozilla::WidgetInputEvent
* aEvent
) = 0;
1373 * Confirm an APZ-aware event target. This should be used when APZ will
1374 * not need a layers update to process the event.
1376 virtual void SetConfirmedTargetAPZC(
1377 uint64_t aInputBlockId
,
1378 const nsTArray
<ScrollableLayerGuid
>& aTargets
) const = 0;
1381 * Returns true if APZ is in use, false otherwise.
1383 virtual bool AsyncPanZoomEnabled() const = 0;
1387 virtual void SwipeFinished() = 0;
1390 * Enables the dropping of files to a widget.
1392 virtual void EnableDragDrop(bool aEnable
) = 0;
1393 virtual nsresult
AsyncEnableDragDrop(bool aEnable
) = 0;
1396 * Enables/Disables system mouse capture.
1397 * @param aCapture true enables mouse capture, false disables mouse capture
1400 virtual void CaptureMouse(bool aCapture
) = 0;
1403 * Classify the window for the window manager. Mostly for X11.
1405 virtual void SetWindowClass(const nsAString
& xulWinType
) = 0;
1408 * Enables/Disables system capture of any and all events that would cause a
1409 * popup to be rolled up. aListener should be set to a non-null value for
1410 * any popups that are not managed by the popup manager.
1411 * @param aDoCapture true enables capture, false disables capture
1414 virtual void CaptureRollupEvents(nsIRollupListener
* aListener
,
1415 bool aDoCapture
) = 0;
1418 * Bring this window to the user's attention. This is intended to be a more
1419 * gentle notification than popping the window to the top or putting up an
1420 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1421 * the Mac. The notification should be suppressed if the window is already
1422 * in the foreground and should be dismissed when the user brings this window
1423 * to the foreground.
1424 * @param aCycleCount Maximum number of times to animate the window per system
1425 * conventions. If set to -1, cycles indefinitely until
1426 * window is brought into the foreground.
1428 [[nodiscard
]] virtual nsresult
GetAttention(int32_t aCycleCount
) = 0;
1431 * Ask whether there user input events pending. All input events are
1432 * included, including those not targeted at this nsIwidget instance.
1434 virtual bool HasPendingInputEvent() = 0;
1437 * If set to true, the window will draw its contents into the titlebar
1438 * instead of below it.
1440 * Ignored on any platform that does not support it. Ignored by widgets that
1441 * do not represent windows.
1442 * May result in a resize event, so should only be called from places where
1443 * reflow and painting is allowed.
1445 * @param aState Whether drawing into the titlebar should be activated.
1447 virtual void SetDrawsInTitlebar(bool aState
) = 0;
1450 * Determine whether the widget shows a resize widget. If it does,
1451 * aResizerRect returns the resizer's rect.
1453 * Returns false on any platform that does not support it.
1455 * @param aResizerRect The resizer's rect in device pixels.
1456 * @return Whether a resize widget is shown.
1458 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect
* aResizerRect
) = 0;
1461 * Begin a window resizing drag, based on the event passed in.
1463 [[nodiscard
]] virtual nsresult
BeginResizeDrag(
1464 mozilla::WidgetGUIEvent
* aEvent
, int32_t aHorizontal
,
1465 int32_t aVertical
) = 0;
1467 // TODO: Make this an enum class with MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS or
1469 enum Modifiers
: uint32_t {
1470 NO_MODIFIERS
= 0x00000000,
1471 CAPS_LOCK
= 0x00000001, // when CapsLock is active
1472 NUM_LOCK
= 0x00000002, // when NumLock is active
1473 SHIFT_L
= 0x00000100,
1474 SHIFT_R
= 0x00000200,
1475 CTRL_L
= 0x00000400,
1476 CTRL_R
= 0x00000800,
1477 ALT_L
= 0x00001000, // includes Option
1479 COMMAND_L
= 0x00004000,
1480 COMMAND_R
= 0x00008000,
1482 ALTGRAPH
= 0x00020000, // AltGr key on Windows. This emulates
1483 // AltRight key behavior of keyboard
1484 // layouts which maps AltGr to AltRight
1486 FUNCTION
= 0x00100000,
1487 NUMERIC_KEY_PAD
= 0x01000000 // when the key is coming from the keypad
1490 * Utility method intended for testing. Dispatches native key events
1491 * to this widget to simulate the press and release of a key.
1492 * @param aNativeKeyboardLayout a *platform-specific* constant.
1493 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1494 * On Windows, it is converted to a hex string and passed to
1495 * LoadKeyboardLayout, see
1496 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1497 * @param aNativeKeyCode a *platform-specific* keycode.
1498 * On Windows, this is the virtual key code.
1499 * @param aModifiers some combination of the above 'Modifiers' flags;
1500 * not all flags will apply to all platforms. Mac ignores the _R
1501 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1503 * @param aCharacters characters that the OS would decide to generate
1504 * from the event. On Windows, this is the charCode passed by
1506 * @param aUnmodifiedCharacters characters that the OS would decide
1507 * to generate from the event if modifier keys (other than shift)
1508 * were assumed inactive. Needed on Mac, ignored on Windows.
1509 * @param aObserver the observer that will get notified once the events
1510 * have been dispatched.
1511 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1512 * layout is not supported and the event was not fired
1514 virtual nsresult
SynthesizeNativeKeyEvent(
1515 int32_t aNativeKeyboardLayout
, int32_t aNativeKeyCode
,
1516 uint32_t aModifierFlags
, const nsAString
& aCharacters
,
1517 const nsAString
& aUnmodifiedCharacters
, nsIObserver
* aObserver
) = 0;
1520 * Utility method intended for testing. Dispatches native mouse events
1521 * may even move the mouse cursor. On Mac the events are guaranteed to
1522 * be sent to the window containing this widget, but on Windows they'll go
1523 * to whatever's topmost on the screen at that position, so for
1524 * cross-platform testing ensure that your window is at the top of the
1526 * @param aPoint screen location of the mouse, in device
1527 * pixels, with origin at the top left
1528 * @param aNativeMessage abstract native message.
1529 * @param aButton Mouse button defined by DOM UI Events.
1530 * @param aModifierFlags Some values of nsIWidget::Modifiers.
1531 * FYI: On Windows, Android and Headless widget on all
1532 * platroms, this hasn't been handled yet.
1533 * @param aObserver the observer that will get notified once the events
1534 * have been dispatched.
1536 enum class NativeMouseMessage
: uint32_t {
1537 ButtonDown
, // button down
1538 ButtonUp
, // button up
1539 Move
, // mouse cursor move
1540 EnterWindow
, // mouse cursor comes into a window
1541 LeaveWindow
, // mouse cursor leaves from a window
1543 virtual nsresult
SynthesizeNativeMouseEvent(
1544 LayoutDeviceIntPoint aPoint
, NativeMouseMessage aNativeMessage
,
1545 mozilla::MouseButton aButton
, nsIWidget::Modifiers aModifierFlags
,
1546 nsIObserver
* aObserver
) = 0;
1549 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native
1550 * message. aPoint is location in device pixels to which the mouse pointer
1552 * @param aObserver the observer that will get notified once the events
1553 * have been dispatched.
1555 virtual nsresult
SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint
,
1556 nsIObserver
* aObserver
) = 0;
1559 * Utility method intended for testing. Dispatching native mouse scroll
1560 * events may move the mouse cursor.
1562 * @param aPoint Mouse cursor position in screen coordinates.
1563 * In device pixels, the origin at the top left of
1564 * the primary display.
1565 * @param aNativeMessage Platform native message.
1566 * @param aDeltaX The delta value for X direction. If the native
1567 * message doesn't indicate X direction scrolling,
1568 * this may be ignored.
1569 * @param aDeltaY The delta value for Y direction. If the native
1570 * message doesn't indicate Y direction scrolling,
1571 * this may be ignored.
1572 * @param aDeltaZ The delta value for Z direction. If the native
1573 * message doesn't indicate Z direction scrolling,
1574 * this may be ignored.
1575 * @param aModifierFlags Must be values of Modifiers, or zero.
1576 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1578 * @param aObserver The observer that will get notified once the
1579 * events have been dispatched.
1581 virtual nsresult
SynthesizeNativeMouseScrollEvent(
1582 LayoutDeviceIntPoint aPoint
, uint32_t aNativeMessage
, double aDeltaX
,
1583 double aDeltaY
, double aDeltaZ
, uint32_t aModifierFlags
,
1584 uint32_t aAdditionalFlags
, nsIObserver
* aObserver
) = 0;
1587 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1588 * touch states in nsIDOMWindowUtils.idl.
1590 enum TouchPointerState
{
1591 // The pointer is in a hover state above the digitizer
1592 TOUCH_HOVER
= (1 << 0),
1593 // The pointer is in contact with the digitizer
1594 TOUCH_CONTACT
= (1 << 1),
1595 // The pointer has been removed from the digitizer detection area
1596 TOUCH_REMOVE
= (1 << 2),
1597 // The pointer has been canceled. Will cancel any pending os level
1598 // gestures that would triggered as a result of completion of the
1599 // input sequence. This may not cancel moz platform related events
1600 // that might get tirggered by input already delivered.
1601 TOUCH_CANCEL
= (1 << 3),
1603 // ALL_BITS used for validity checking during IPC serialization
1604 ALL_BITS
= (1 << 4) - 1
1607 * TouchpadGesturePhase states for SynthesizeNativeTouchPadPinch and
1608 * SynthesizeNativeTouchpadPan. Match phase states in nsIDOMWindowUtils.idl.
1610 enum TouchpadGesturePhase
{
1616 * Create a new or update an existing touch pointer on the digitizer.
1617 * To trigger os level gestures, individual touch points should
1618 * transition through a complete set of touch states which should be
1619 * sent as individual messages.
1621 * @param aPointerId The touch point id to create or update.
1622 * @param aPointerState one or more of the touch states listed above
1623 * @param aPoint coords of this event
1624 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1625 * @param aOrientation 0 -> 359 degree value indicating the
1626 * orientation of the pointer. Use 90 for normal taps.
1627 * @param aObserver The observer that will get notified once the events
1628 * have been dispatched.
1630 virtual nsresult
SynthesizeNativeTouchPoint(uint32_t aPointerId
,
1631 TouchPointerState aPointerState
,
1632 LayoutDeviceIntPoint aPoint
,
1633 double aPointerPressure
,
1634 uint32_t aPointerOrientation
,
1635 nsIObserver
* aObserver
) = 0;
1637 * See nsIDOMWindowUtils.sendNativeTouchpadPinch().
1639 virtual nsresult
SynthesizeNativeTouchPadPinch(
1640 TouchpadGesturePhase aEventPhase
, float aScale
,
1641 LayoutDeviceIntPoint aPoint
, int32_t aModifierFlags
) = 0;
1644 * Helper for simulating a simple tap event with one touch point. When
1645 * aLongTap is true, simulates a native long tap with a duration equal to
1646 * ui.click_hold_context_menus.delay. This pref is compatible with the
1647 * apzc long tap duration. Defaults to 1.5 seconds.
1648 * @param aObserver The observer that will get notified once the events
1649 * have been dispatched.
1651 virtual nsresult
SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint
,
1653 nsIObserver
* aObserver
);
1655 virtual nsresult
SynthesizeNativePenInput(uint32_t aPointerId
,
1656 TouchPointerState aPointerState
,
1657 LayoutDeviceIntPoint aPoint
,
1659 uint32_t aRotation
, int32_t aTiltX
,
1660 int32_t aTiltY
, int32_t aButton
,
1661 nsIObserver
* aObserver
) = 0;
1664 * Cancels all active simulated touch input points and pending long taps.
1665 * Native widgets should track existing points such that they can clear the
1666 * digitizer state when this call is made.
1667 * @param aObserver The observer that will get notified once the touch
1668 * sequence has been cleared.
1670 virtual nsresult
ClearNativeTouchSequence(nsIObserver
* aObserver
);
1673 * Send a native event as if the user double tapped the touchpad with two
1676 virtual nsresult
SynthesizeNativeTouchpadDoubleTap(
1677 LayoutDeviceIntPoint aPoint
, uint32_t aModifierFlags
) = 0;
1680 * See nsIDOMWindowUtils.sendNativeTouchpadPan().
1682 virtual nsresult
SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase
,
1683 LayoutDeviceIntPoint aPoint
,
1684 double aDeltaX
, double aDeltaY
,
1685 int32_t aModifierFlags
,
1686 nsIObserver
* aObserver
) = 0;
1688 virtual void StartAsyncScrollbarDrag(
1689 const AsyncDragMetrics
& aDragMetrics
) = 0;
1692 * Notify APZ to start autoscrolling.
1693 * @param aAnchorLocation the location of the autoscroll anchor
1694 * @param aGuid identifies the scroll frame to be autoscrolled
1695 * @return true if APZ has been successfully notified
1697 virtual bool StartAsyncAutoscroll(const ScreenPoint
& aAnchorLocation
,
1698 const ScrollableLayerGuid
& aGuid
) = 0;
1701 * Notify APZ to stop autoscrolling.
1702 * @param aGuid identifies the scroll frame which is being autoscrolled.
1704 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid
& aGuid
) = 0;
1706 virtual LayersId
GetRootLayerTreeId() = 0;
1708 // If this widget supports out-of-process compositing, it can override
1709 // this method to provide additional information to the compositor.
1710 virtual void GetCompositorWidgetInitData(
1711 mozilla::widget::CompositorWidgetInitData
* aInitData
) {}
1714 * Setter/Getter of the system font setting for testing.
1716 virtual nsresult
SetSystemFont(const nsCString
& aFontName
) {
1717 return NS_ERROR_NOT_IMPLEMENTED
;
1719 virtual nsresult
GetSystemFont(nsCString
& aFontName
) {
1720 return NS_ERROR_NOT_IMPLEMENTED
;
1724 * Wayland specific routines.
1726 virtual LayoutDeviceIntSize
GetMoveToRectPopupSize() const {
1727 NS_WARNING("GetLayoutPopupRect implemented only for wayland");
1728 return LayoutDeviceIntSize();
1732 * If this widget uses native pointer lock instead of warp-to-center
1733 * (currently only GTK on Wayland), these methods provide access to that
1736 virtual void SetNativePointerLockCenter(
1737 const LayoutDeviceIntPoint
& aLockCenter
) {}
1738 virtual void LockNativePointer() {}
1739 virtual void UnlockNativePointer() {}
1742 * Get safe area insets except to cutout.
1743 * See https://drafts.csswg.org/css-env-1/#safe-area-insets.
1745 virtual mozilla::ScreenIntMargin
GetSafeAreaInsets() const {
1746 return mozilla::ScreenIntMargin();
1752 LongTapInfo(int32_t aPointerId
, LayoutDeviceIntPoint
& aPoint
,
1753 mozilla::TimeDuration aDuration
, nsIObserver
* aObserver
)
1754 : mPointerId(aPointerId
),
1756 mDuration(aDuration
),
1757 mObserver(aObserver
),
1758 mStamp(mozilla::TimeStamp::Now()) {}
1761 LayoutDeviceIntPoint mPosition
;
1762 mozilla::TimeDuration mDuration
;
1763 nsCOMPtr
<nsIObserver
> mObserver
;
1764 mozilla::TimeStamp mStamp
;
1767 static void OnLongTapTimerCallback(nsITimer
* aTimer
, void* aClosure
);
1769 static already_AddRefed
<nsIBidiKeyboard
> CreateBidiKeyboardContentProcess();
1770 static already_AddRefed
<nsIBidiKeyboard
> CreateBidiKeyboardInner();
1772 mozilla::UniquePtr
<LongTapInfo
> mLongTapTouchPoint
;
1773 nsCOMPtr
<nsITimer
> mLongTapTimer
;
1774 static int32_t sPointerIdCounter
;
1778 * If key events have not been handled by content or XBL handlers, they can
1779 * be offered to the system (for custom application shortcuts set in system
1780 * preferences, for example).
1782 virtual void PostHandleKeyEvent(mozilla::WidgetKeyboardEvent
* aEvent
);
1785 * Activates a native menu item at the position specified by the index
1786 * string. The index string is a string of positive integers separated
1787 * by the "|" (pipe) character. The last integer in the string represents
1788 * the item index in a submenu located using the integers preceding it.
1791 * In this string, the first integer represents the top-level submenu
1792 * in the native menu bar. Since the integer is 1, it is the second submeu
1793 * in the native menu bar. Within that, the first item (index 0) is a
1794 * submenu, and we want to activate the 5th item within that submenu.
1796 virtual nsresult
ActivateNativeMenuItemAt(const nsAString
& indexString
) = 0;
1799 * This is used for native menu system testing.
1801 * Updates a native menu at the position specified by the index string.
1802 * The index string is a string of positive integers separated by the "|"
1806 * In this string, the first integer represents the top-level submenu
1807 * in the native menu bar. Since the integer is 1, it is the second submeu
1808 * in the native menu bar. Within that, the first item (index 0) is a
1809 * submenu, and we want to update submenu at index 4 within that submenu.
1811 * If this is called with an empty string it forces a full reload of the
1814 virtual nsresult
ForceUpdateNativeMenuAt(const nsAString
& indexString
) = 0;
1817 * This is used for testing macOS service menu code.
1819 * @param aResult - the current text selection. Is empty if no selection.
1820 * @return nsresult - whether or not aResult was assigned the selected text.
1822 [[nodiscard
]] virtual nsresult
GetSelectionAsPlaintext(nsAString
& aResult
) {
1823 return NS_ERROR_NOT_IMPLEMENTED
;
1827 * Notify IME of the specified notification.
1829 * @return If the notification is mouse button event and it's consumed by
1830 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1832 virtual nsresult
NotifyIME(const IMENotification
& aIMENotification
) = 0;
1835 * MaybeDispatchInitialFocusEvent will dispatch a focus event after creation
1836 * of the widget, in the event that we were not able to observe and respond to
1837 * the initial focus event. This is necessary for the early skeleton UI
1838 * window, which is displayed and receives its initial focus event before we
1839 * can actually respond to it.
1841 virtual void MaybeDispatchInitialFocusEvent() {}
1844 * Notifies the input context changes.
1846 virtual void SetInputContext(const InputContext
& aContext
,
1847 const InputContextAction
& aAction
) = 0;
1850 * Get current input context.
1852 virtual InputContext
GetInputContext() = 0;
1855 * Get native IME context. This is different from GetNativeData() with
1856 * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
1859 virtual NativeIMEContext
GetNativeIMEContext() = 0;
1862 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1863 * native (OS-level) event for it. This method allows tests to simulate
1864 * keystrokes that trigger native key bindings (which require a native
1867 [[nodiscard
]] virtual nsresult
AttachNativeKeyEvent(
1868 mozilla::WidgetKeyboardEvent
& aEvent
) = 0;
1871 * Retrieve edit commands when the key combination of aEvent is used
1872 * in platform native applications.
1874 MOZ_CAN_RUN_SCRIPT
virtual bool GetEditCommands(
1875 mozilla::NativeKeyBindingsType aType
,
1876 const mozilla::WidgetKeyboardEvent
& aEvent
,
1877 nsTArray
<mozilla::CommandInt
>& aCommands
);
1880 * Retrieves a reference to notification requests of IME. Note that the
1881 * reference is valid while the nsIWidget instance is alive. So, if you
1882 * need to store the reference for a long time, you need to grab the widget
1885 const IMENotificationRequests
& IMENotificationRequestsRef();
1888 * Call this method when a dialog is opened which has a default button.
1889 * The button's rectangle should be supplied in aButtonRect.
1891 [[nodiscard
]] virtual nsresult
OnDefaultButtonLoaded(
1892 const LayoutDeviceIntRect
& aButtonRect
) = 0;
1895 * Return true if this process shouldn't use platform widgets, and
1896 * so should use PuppetWidgets instead. If this returns true, the
1897 * result of creating and using a platform widget is undefined,
1898 * and likely to end in crashes or other buggy behavior.
1900 static bool UsePuppetWidgets() { return XRE_IsContentProcess(); }
1902 static already_AddRefed
<nsIWidget
> CreateTopLevelWindow();
1904 static already_AddRefed
<nsIWidget
> CreateChildWindow();
1907 * Allocate and return a "puppet widget" that doesn't directly
1908 * correlate to a platform widget; platform events and data must
1909 * be fed to it. Currently used in content processes. NULL is
1910 * returned if puppet widgets aren't supported in this build
1911 * config, on this platform, or for this process type.
1913 * This function is called "Create" to match CreateInstance().
1914 * The returned widget must still be nsIWidget::Create()d.
1916 static already_AddRefed
<nsIWidget
> CreatePuppetWidget(
1917 BrowserChild
* aBrowserChild
);
1919 static already_AddRefed
<nsIWidget
> CreateHeadlessWidget();
1922 * Reparent this widget's native widget.
1923 * @param aNewParent the native widget of aNewParent is the new native
1926 virtual void ReparentNativeWidget(nsIWidget
* aNewParent
) = 0;
1929 * Return true if widget has it's own GL context
1931 virtual bool HasGLContext() { return false; }
1934 * Returns true to indicate that this widget paints an opaque background
1935 * that we want to be visible under the page, so layout should not force
1936 * a default background.
1938 virtual bool WidgetPaintsBackground() { return false; }
1940 virtual bool NeedsPaint() { return IsVisible() && !GetBounds().IsEmpty(); }
1943 * Get the natural bounds of this widget. This method is only
1944 * meaningful for widgets for which Gecko implements screen
1945 * rotation natively. When this is the case, GetBounds() returns
1946 * the widget bounds taking rotation into account, and
1947 * GetNaturalBounds() returns the bounds *not* taking rotation
1950 * No code outside of the composition pipeline should know or care
1951 * about this. If you're not an agent of the compositor, you
1952 * probably shouldn't call this method.
1954 virtual LayoutDeviceIntRect
GetNaturalBounds() { return GetBounds(); }
1957 * Set size constraints on the window size such that it is never less than
1958 * the specified minimum size and never larger than the specified maximum
1959 * size. The size constraints are sizes of the outer rectangle including
1960 * the window frame and title bar. Use 0 for an unconstrained minimum size
1961 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1962 * does not necessarily change the size of a window to conform to this size,
1963 * thus Resize should be called afterwards.
1965 * @param aConstraints: the size constraints in device pixels
1967 virtual void SetSizeConstraints(const SizeConstraints
& aConstraints
) = 0;
1970 * Return the size constraints currently observed by the widget.
1972 * @return the constraints in device pixels
1974 virtual const SizeConstraints
GetSizeConstraints() = 0;
1977 * Apply the current size constraints to the given size.
1979 * @param aWidth width to constrain
1980 * @param aHeight height to constrain
1982 virtual void ConstrainSize(int32_t* aWidth
, int32_t* aHeight
) = 0;
1985 * If this is owned by a BrowserChild, return that. Otherwise return
1988 virtual BrowserChild
* GetOwningBrowserChild() { return nullptr; }
1991 * If this isn't directly compositing to its window surface,
1992 * return the compositor which is doing that on our behalf.
1994 virtual CompositorBridgeChild
* GetRemoteRenderer() { return nullptr; }
1997 * Clear WebRender resources
1999 virtual void ClearCachedWebrenderResources() {}
2002 * Clear WebRender animation resources
2004 virtual void ClearWebrenderAnimationResources() {}
2007 * Request fast snapshot at RenderCompositor of WebRender.
2008 * Since readback of Windows DirectComposition is very slow.
2010 virtual bool SetNeedFastSnaphot() { return false; }
2013 * If this widget has its own vsync dispatcher, return it, otherwise return
2014 * nullptr. An example of such a local vsync dispatcher would be Wayland frame
2017 virtual RefPtr
<mozilla::VsyncDispatcher
> GetVsyncDispatcher();
2020 * Returns true if the widget requires synchronous repaints on resize,
2023 virtual bool SynchronouslyRepaintOnResize() { return true; }
2026 * Some platforms (only cocoa right now) round widget coordinates to the
2027 * nearest even pixels (see bug 892994), this function allows us to
2028 * determine how widget coordinates will be rounded.
2030 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
2032 virtual void UpdateZoomConstraints(
2033 const uint32_t& aPresShellId
, const ScrollableLayerGuid::ViewID
& aViewId
,
2034 const mozilla::Maybe
<ZoomConstraints
>& aConstraints
){};
2037 * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
2038 * widget. Note that this never returns nullptr.
2040 virtual TextEventDispatcher
* GetTextEventDispatcher() = 0;
2043 * GetNativeTextEventDispatcherListener() returns a
2044 * TextEventDispatcherListener instance which is used when the widget
2045 * instance handles native IME and/or keyboard events.
2047 virtual TextEventDispatcherListener
*
2048 GetNativeTextEventDispatcherListener() = 0;
2050 virtual void ZoomToRect(const uint32_t& aPresShellId
,
2051 const ScrollableLayerGuid::ViewID
& aViewId
,
2052 const CSSRect
& aRect
, const uint32_t& aFlags
) = 0;
2055 * LookUpDictionary shows the dictionary for the word around current point.
2057 * @param aText the word to look up dictiorary.
2058 * @param aFontRangeArray text decoration of aText
2059 * @param aIsVertical true if the word is vertical layout
2060 * @param aPoint top-left point of aText
2062 virtual void LookUpDictionary(
2063 const nsAString
& aText
,
2064 const nsTArray
<mozilla::FontRange
>& aFontRangeArray
,
2065 const bool aIsVertical
, const LayoutDeviceIntPoint
& aPoint
) {}
2067 virtual void RequestFxrOutput() {
2068 MOZ_ASSERT(false, "This function should only execute in Windows");
2071 #if defined(MOZ_WIDGET_ANDROID)
2073 * RecvToolbarAnimatorMessageFromCompositor receive message from compositor
2076 * @param aMessage message being sent to Android UI thread.
2078 virtual void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage
) = 0;
2081 * UpdateRootFrameMetrics steady state frame metrics send from compositor
2084 * @param aScrollOffset page scroll offset value in screen pixels.
2085 * @param aZoom current page zoom.
2087 virtual void UpdateRootFrameMetrics(const ScreenPoint
& aScrollOffset
,
2088 const CSSToScreenScale
& aZoom
) = 0;
2091 * RecvScreenPixels Buffer containing the pixel from the frame buffer. Used
2092 * for android robocop tests.
2094 * @param aMem shared memory containing the frame buffer pixels.
2095 * @param aSize size of the buffer in screen pixels.
2097 virtual void RecvScreenPixels(mozilla::ipc::Shmem
&& aMem
,
2098 const ScreenIntSize
& aSize
,
2099 bool aNeedsYFlip
) = 0;
2101 virtual void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight
) {}
2102 virtual mozilla::ScreenIntCoord
GetDynamicToolbarMaxHeight() const {
2107 static already_AddRefed
<nsIBidiKeyboard
> CreateBidiKeyboard();
2110 * Like GetDefaultScale, but taking into account only the system settings
2111 * and ignoring Gecko preferences.
2113 virtual double GetDefaultScaleInternal() { return 1.0; }
2116 * Layout uses this to alert the widget to the client rect representing
2117 * the window maximize button. An empty rect indicates there is no
2118 * maximize button (for example, in fullscreen). This is only implemented
2121 virtual void SetWindowButtonRect(WindowButtonType aButtonType
,
2122 const LayoutDeviceIntRect
& aClientRect
) {}
2125 virtual nsresult
SetHiDPIMode(bool aHiDPI
) {
2126 return NS_ERROR_NOT_IMPLEMENTED
;
2128 virtual nsresult
RestoreHiDPIMode() { return NS_ERROR_NOT_IMPLEMENTED
; }
2132 // keep the list of children. We also keep track of our siblings.
2133 // The ownership model is as follows: parent holds a strong ref to
2134 // the first element of the list, and each element holds a strong
2135 // ref to the next element in the list. The prevsibling and
2136 // lastchild pointers are weak, which is fine as long as they are
2137 // maintained properly.
2138 nsCOMPtr
<nsIWidget
> mFirstChild
;
2139 nsIWidget
* MOZ_NON_OWNING_REF mLastChild
;
2140 nsCOMPtr
<nsIWidget
> mNextSibling
;
2141 nsIWidget
* MOZ_NON_OWNING_REF mPrevSibling
;
2142 // When Destroy() is called, the sub class should set this true.
2143 bool mOnDestroyCalled
;
2144 nsWindowType mWindowType
;
2148 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget
, NS_IWIDGET_IID
)
2150 #endif // nsIWidget_h__