Bug 1830741 - Add tests for mach try perf comparators. r=perftest-reviewers,Alexandru...
[gecko.git] / widget / nsIWidget.h
blob6ea57c2bb793481808956dfe5c4ef3354b229b90
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/. */
7 #ifndef nsIWidget_h__
8 #define nsIWidget_h__
10 #include <cmath>
11 #include <cstdint>
12 #include "imgIContainer.h"
13 #include "ErrorList.h"
14 #include "Units.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"
30 #include "nsCOMPtr.h"
31 #include "nsColor.h"
32 #include "nsDebug.h"
33 #include "nsID.h"
34 #include "nsIObserver.h"
35 #include "nsISupports.h"
36 #include "nsITheme.h"
37 #include "nsITimer.h"
38 #include "nsIWidgetListener.h"
39 #include "nsRect.h"
40 #include "nsSize.h"
41 #include "nsStringFwd.h"
42 #include "nsTArray.h"
43 #include "nsTHashMap.h"
44 #include "mozilla/widget/InitData.h"
45 #include "nsXULAppAPI.h"
47 // forward declarations
48 class nsIBidiKeyboard;
49 class nsIRollupListener;
50 class nsIContent;
51 class ViewWrapper;
52 class nsIRunnable;
54 namespace mozilla {
55 enum class NativeKeyBindingsType : uint8_t;
56 class VsyncDispatcher;
57 class WidgetGUIEvent;
58 class WidgetInputEvent;
59 class WidgetKeyboardEvent;
60 struct FontRange;
62 enum class StyleWindowShadow : uint8_t;
63 enum class ColorScheme : uint8_t;
64 enum class WindowButtonType : uint8_t;
66 #if defined(MOZ_WIDGET_ANDROID)
67 namespace ipc {
68 class Shmem;
70 #endif // defined(MOZ_WIDGET_ANDROID)
71 namespace dom {
72 class BrowserChild;
73 enum class CallerType : uint32_t;
74 } // namespace dom
75 class WindowRenderer;
76 namespace layers {
77 class AsyncDragMetrics;
78 class Compositor;
79 class CompositorBridgeChild;
80 struct FrameMetrics;
81 class LayerManager;
82 class WebRenderBridgeChild;
83 } // namespace layers
84 namespace widget {
85 class TextEventDispatcher;
86 class TextEventDispatcherListener;
87 class CompositorWidget;
88 class CompositorWidgetInitData;
89 class Screen;
90 } // namespace widget
91 namespace wr {
92 class DisplayListBuilder;
93 class IpcResourceUpdateQueue;
94 enum class RenderRoot : uint8_t;
95 } // namespace wr
96 } // namespace mozilla
98 /**
99 * Callback function that processes events.
101 * The argument is actually a subtype (subclass) of WidgetEvent which carries
102 * platform specific information about the event. Platform specific code
103 * knows how to deal with it.
105 * The return value determines whether or not the default action should take
106 * place.
108 typedef nsEventStatus (*EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent);
110 // Hide the native window system's real window type so as to avoid
111 // including native window system types and APIs. This is necessary
112 // to ensure cross-platform code.
113 typedef void* nsNativeWidget;
116 * Values for the GetNativeData function
118 #define NS_NATIVE_WINDOW 0
119 #define NS_NATIVE_GRAPHIC 1
120 #define NS_NATIVE_WIDGET 3
121 #define NS_NATIVE_REGION 5
122 #define NS_NATIVE_OFFSETX 6
123 #define NS_NATIVE_OFFSETY 7
124 #define NS_NATIVE_SCREEN 9
125 // The toplevel GtkWidget containing this nsIWidget:
126 #define NS_NATIVE_SHELLWIDGET 10
127 #define NS_NATIVE_OPENGL_CONTEXT 12
128 // This is available only with GetNativeData() in parent process. Anybody
129 // shouldn't access this pointer as a valid pointer since the result may be
130 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
131 // an identifier of distinguishing a text composition is caused by which native
132 // IME context. Note that the result is only valid in the process. So,
133 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
134 #define NS_RAW_NATIVE_IME_CONTEXT 14
135 #define NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID 15
136 #ifdef XP_WIN
137 # define NS_NATIVE_TSF_THREAD_MGR 100
138 # define NS_NATIVE_TSF_CATEGORY_MGR 101
139 # define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
140 # define NS_NATIVE_ICOREWINDOW 103 // winrt specific
141 #endif
142 #if defined(MOZ_WIDGET_GTK)
143 # define NS_NATIVE_EGL_WINDOW 106
144 #endif
145 #ifdef MOZ_WIDGET_ANDROID
146 # define NS_JAVA_SURFACE 100
147 #endif
149 #define MOZ_WIDGET_MAX_SIZE 16384
150 #define MOZ_WIDGET_INVALID_SCALE 0.0
152 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
153 #define NS_IWIDGET_IID \
155 0x06396bf6, 0x2dd8, 0x45e5, { \
156 0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80 \
161 * Cursor types.
164 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
165 eCursor_standard,
166 ///(system is busy, usually rendered as a hourglass or watch)
167 eCursor_wait,
168 ///(Selecting something, usually rendered as an IBeam)
169 eCursor_select,
170 ///(can hyper-link, usually rendered as a human hand)
171 eCursor_hyperlink,
172 ///(north/south/west/east edge sizing)
173 eCursor_n_resize,
174 eCursor_s_resize,
175 eCursor_w_resize,
176 eCursor_e_resize,
177 ///(corner sizing)
178 eCursor_nw_resize,
179 eCursor_se_resize,
180 eCursor_ne_resize,
181 eCursor_sw_resize,
182 eCursor_crosshair,
183 eCursor_move,
184 eCursor_help,
185 eCursor_copy, // CSS3
186 eCursor_alias,
187 eCursor_context_menu,
188 eCursor_cell,
189 eCursor_grab,
190 eCursor_grabbing,
191 eCursor_spinning,
192 eCursor_zoom_in,
193 eCursor_zoom_out,
194 eCursor_not_allowed,
195 eCursor_col_resize,
196 eCursor_row_resize,
197 eCursor_no_drop,
198 eCursor_vertical_text,
199 eCursor_all_scroll,
200 eCursor_nesw_resize,
201 eCursor_nwse_resize,
202 eCursor_ns_resize,
203 eCursor_ew_resize,
204 eCursor_none,
205 // This one is used for array sizing, and so better be the last
206 // one in this list...
207 eCursorCount,
209 // ...except for this one.
210 eCursorInvalid = eCursorCount + 1
213 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
214 eZPlacementBottom = 0, // bottom of the window stack
215 eZPlacementBelow, // just below another widget
216 eZPlacementTop // top of the window stack
220 * Before the OS goes to sleep, this topic is notified.
222 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
225 * After the OS wakes up, this topic is notified.
227 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
230 * Before the OS suspends the current process, this topic is notified. Some
231 * OS will kill processes that are suspended instead of resuming them.
232 * For that reason this topic may be useful to safely close down resources.
234 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
237 * After the current process resumes from being suspended, this topic is
238 * notified.
240 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
243 * When an app(-shell) is activated by the OS, this topic is notified.
244 * Currently, this only happens on Mac OSX.
246 #define NS_WIDGET_MAC_APP_ACTIVATE_OBSERVER_TOPIC "mac_app_activate"
248 namespace mozilla::widget {
251 * Size constraints for setting the minimum and maximum size of a widget.
252 * Values are in device pixels.
254 struct SizeConstraints {
255 SizeConstraints()
256 : mMaxSize(MOZ_WIDGET_MAX_SIZE, MOZ_WIDGET_MAX_SIZE),
257 mScale(MOZ_WIDGET_INVALID_SCALE) {}
259 SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize,
260 mozilla::LayoutDeviceIntSize aMaxSize,
261 mozilla::DesktopToLayoutDeviceScale aScale)
262 : mMinSize(aMinSize), mMaxSize(aMaxSize), mScale(aScale) {
263 if (mMaxSize.width > MOZ_WIDGET_MAX_SIZE) {
264 mMaxSize.width = MOZ_WIDGET_MAX_SIZE;
266 if (mMaxSize.height > MOZ_WIDGET_MAX_SIZE) {
267 mMaxSize.height = MOZ_WIDGET_MAX_SIZE;
271 mozilla::LayoutDeviceIntSize mMinSize;
272 mozilla::LayoutDeviceIntSize mMaxSize;
275 * The scale used to convert from desktop to device dimensions.
276 * MOZ_WIDGET_INVALID_SCALE if the value is not known.
278 * Bug 1701109 is filed to revisit adding of 'mScale' and deal
279 * with multi-monitor scaling issues in more complete way across
280 * all widget implementations.
282 mozilla::DesktopToLayoutDeviceScale mScale;
285 struct AutoObserverNotifier {
286 AutoObserverNotifier(nsIObserver* aObserver, const char* aTopic)
287 : mObserver(aObserver), mTopic(aTopic) {}
289 void SkipNotification() { mObserver = nullptr; }
291 uint64_t SaveObserver() {
292 if (!mObserver) {
293 return 0;
295 uint64_t observerId = ++sObserverId;
296 sSavedObservers.InsertOrUpdate(observerId, mObserver);
297 SkipNotification();
298 return observerId;
301 ~AutoObserverNotifier() {
302 if (mObserver) {
303 mObserver->Observe(nullptr, mTopic, nullptr);
307 static void NotifySavedObserver(const uint64_t& aObserverId,
308 const char* aTopic) {
309 nsCOMPtr<nsIObserver> observer = sSavedObservers.Get(aObserverId);
310 if (!observer) {
311 MOZ_ASSERT(aObserverId == 0,
312 "We should always find a saved observer for nonzero IDs");
313 return;
316 sSavedObservers.Remove(aObserverId);
317 observer->Observe(nullptr, aTopic, nullptr);
320 private:
321 nsCOMPtr<nsIObserver> mObserver;
322 const char* mTopic;
324 private:
325 static uint64_t sObserverId;
326 static nsTHashMap<uint64_t, nsCOMPtr<nsIObserver>> sSavedObservers;
329 } // namespace mozilla::widget
332 * The base class for all the widgets. It provides the interface for
333 * all basic and necessary functionality.
335 class nsIWidget : public nsISupports {
336 protected:
337 typedef mozilla::dom::BrowserChild BrowserChild;
339 public:
340 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
341 typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics;
342 typedef mozilla::layers::FrameMetrics FrameMetrics;
343 typedef mozilla::layers::LayerManager LayerManager;
344 typedef mozilla::WindowRenderer WindowRenderer;
345 typedef mozilla::layers::LayersBackend LayersBackend;
346 typedef mozilla::layers::LayersId LayersId;
347 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
348 typedef mozilla::layers::ZoomConstraints ZoomConstraints;
349 typedef mozilla::widget::IMEEnabled IMEEnabled;
350 typedef mozilla::widget::IMEMessage IMEMessage;
351 typedef mozilla::widget::IMENotification IMENotification;
352 typedef mozilla::widget::IMENotificationRequests IMENotificationRequests;
353 typedef mozilla::widget::IMEState IMEState;
354 typedef mozilla::widget::InputContext InputContext;
355 typedef mozilla::widget::InputContextAction InputContextAction;
356 typedef mozilla::widget::NativeIMEContext NativeIMEContext;
357 typedef mozilla::widget::SizeConstraints SizeConstraints;
358 typedef mozilla::widget::TextEventDispatcher TextEventDispatcher;
359 typedef mozilla::widget::TextEventDispatcherListener
360 TextEventDispatcherListener;
361 typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin;
362 typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
363 typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
364 typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
365 typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
366 typedef mozilla::ScreenIntPoint ScreenIntPoint;
367 typedef mozilla::ScreenIntMargin ScreenIntMargin;
368 typedef mozilla::ScreenIntSize ScreenIntSize;
369 typedef mozilla::ScreenPoint ScreenPoint;
370 typedef mozilla::CSSToScreenScale CSSToScreenScale;
371 typedef mozilla::DesktopIntRect DesktopIntRect;
372 typedef mozilla::DesktopPoint DesktopPoint;
373 typedef mozilla::DesktopRect DesktopRect;
374 typedef mozilla::DesktopSize DesktopSize;
375 typedef mozilla::CSSPoint CSSPoint;
376 typedef mozilla::CSSRect CSSRect;
378 using InitData = mozilla::widget::InitData;
379 using WindowType = mozilla::widget::WindowType;
380 using PopupType = mozilla::widget::PopupType;
381 using PopupLevel = mozilla::widget::PopupLevel;
382 using BorderStyle = mozilla::widget::BorderStyle;
383 using TransparencyMode = mozilla::widget::TransparencyMode;
384 using Screen = mozilla::widget::Screen;
386 // Used in UpdateThemeGeometries.
387 struct ThemeGeometry {
388 // The ThemeGeometryType value for the themed widget, see
389 // nsITheme::ThemeGeometryTypeForWidget.
390 nsITheme::ThemeGeometryType mType;
391 // The device-pixel rect within the window for the themed widget
392 LayoutDeviceIntRect mRect;
394 ThemeGeometry(nsITheme::ThemeGeometryType aType,
395 const LayoutDeviceIntRect& aRect)
396 : mType(aType), mRect(aRect) {}
399 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
401 nsIWidget()
402 : mLastChild(nullptr),
403 mPrevSibling(nullptr),
404 mOnDestroyCalled(false),
405 mWindowType(WindowType::Child),
406 mZIndex(0)
409 ClearNativeTouchSequence(nullptr);
413 * Create and initialize a widget.
415 * All the arguments can be null in which case a top level window
416 * with size 0 is created. The event callback function has to be
417 * provided only if the caller wants to deal with the events this
418 * widget receives. The event callback is basically a preprocess
419 * hook called synchronously. The return value determines whether
420 * the event goes to the default window procedure or it is hidden
421 * to the os. The assumption is that if the event handler returns
422 * false the widget does not see the event. The widget should not
423 * automatically clear the window to the background color. The
424 * calling code must handle paint messages and clear the background
425 * itself.
427 * In practice at least one of aParent and aNativeParent will be null. If
428 * both are null the widget isn't parented (e.g. context menus or
429 * independent top level windows).
431 * The dimensions given in aRect are specified in the parent's
432 * device coordinate system.
433 * This must not be called for parentless widgets such as top-level
434 * windows, which use the desktop pixel coordinate system; a separate
435 * method is provided for these.
437 * @param aParent parent nsIWidget
438 * @param aNativeParent native parent widget
439 * @param aRect the widget dimension
440 * @param aInitData data that is used for widget initialization
443 [[nodiscard]] virtual nsresult Create(nsIWidget* aParent,
444 nsNativeWidget aNativeParent,
445 const LayoutDeviceIntRect& aRect,
446 InitData* = nullptr) = 0;
449 * As above, but with aRect specified in DesktopPixel units (for top-level
450 * widgets).
451 * Default implementation just converts aRect to device pixels and calls
452 * through to device-pixel Create, but platforms may override this if the
453 * mapping is not straightforward or the native platform needs to use the
454 * desktop pixel values directly.
456 [[nodiscard]] virtual nsresult Create(nsIWidget* aParent,
457 nsNativeWidget aNativeParent,
458 const DesktopIntRect& aRect,
459 InitData* aInitData = nullptr) {
460 LayoutDeviceIntRect devPixRect =
461 RoundedToInt(aRect * GetDesktopToDeviceScale());
462 return Create(aParent, aNativeParent, devPixRect, aInitData);
466 * Allocate, initialize, and return a widget that is a child of
467 * |this|. The returned widget (if nonnull) has gone through the
468 * equivalent of CreateInstance(widgetCID) + Create(...).
470 * |CreateChild()| lets widget backends decide whether to parent
471 * the new child widget to this, nonnatively parent it, or both.
472 * This interface exists to support the PuppetWidget backend,
473 * which is entirely non-native. All other params are the same as
474 * for |Create()|.
476 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
477 * |nsIWidget*| this, not its native widget (if it exists), when
478 * calling |Create()|. This is a timid hack around poorly
479 * understood code, and shouldn't be used in new code.
481 virtual already_AddRefed<nsIWidget> CreateChild(
482 const LayoutDeviceIntRect& aRect, InitData* = nullptr,
483 bool aForceUseIWidgetParent = false) = 0;
486 * Attach to a top level widget.
488 * In cases where a top level chrome widget is being used as a content
489 * container, attach a secondary listener and update the device
490 * context. The primary widget listener will continue to be called for
491 * notifications relating to the top-level window, whereas other
492 * notifications such as painting and events will instead be called via
493 * the attached listener. SetAttachedWidgetListener should be used to
494 * assign the attached listener.
496 * aUseAttachedEvents if true, events are sent to the attached listener
497 * instead of the normal listener.
499 virtual void AttachViewToTopLevel(bool aUseAttachedEvents) = 0;
502 * Accessor functions to get and set the attached listener. Used by
503 * nsView in connection with AttachViewToTopLevel above.
505 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
506 virtual nsIWidgetListener* GetAttachedWidgetListener() const = 0;
507 virtual void SetPreviouslyAttachedWidgetListener(
508 nsIWidgetListener* aListener) = 0;
509 virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() = 0;
512 * Notifies the root widget of a non-blank paint.
514 virtual void DidGetNonBlankPaint() {}
517 * Accessor functions to get and set the listener which handles various
518 * actions for the widget.
520 //@{
521 virtual nsIWidgetListener* GetWidgetListener() const = 0;
522 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
523 //@}
526 * Close and destroy the internal native window.
527 * This method does not delete the widget.
530 virtual void Destroy() = 0;
533 * Destroyed() returns true if Destroy() has been called already.
534 * Otherwise, false.
536 bool Destroyed() const { return mOnDestroyCalled; }
539 * Reparent a widget
541 * Change the widget's parent. Null parents are allowed.
543 * @param aNewParent new parent
545 virtual void SetParent(nsIWidget* aNewParent) = 0;
548 * Return the parent Widget of this Widget or nullptr if this is a
549 * top level window
551 * @return the parent widget or nullptr if it does not have a parent
554 virtual nsIWidget* GetParent(void) = 0;
557 * Return the top level Widget of this Widget
559 * @return the top level widget
561 virtual nsIWidget* GetTopLevelWidget() = 0;
564 * Return the top (non-sheet) parent of this Widget if it's a sheet,
565 * or nullptr if this isn't a sheet (or some other error occurred).
566 * Sheets are only supported on some platforms (currently only macOS).
568 * @return the top (non-sheet) parent widget or nullptr
571 virtual nsIWidget* GetSheetWindowParent(void) = 0;
574 * Return the physical DPI of the screen containing the window ...
575 * the number of device pixels per inch.
577 virtual float GetDPI() = 0;
580 * Fallback DPI for when there's no widget available.
582 static float GetFallbackDPI();
585 * Return the scaling factor between device pixels and the platform-
586 * dependent "desktop pixels" used to manage window positions on a
587 * potentially multi-screen, mixed-resolution desktop.
589 virtual mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() = 0;
592 * Return the scaling factor between device pixels and the platform-
593 * dependent "desktop pixels" by looking up the screen by the position
594 * of the widget.
596 virtual mozilla::DesktopToLayoutDeviceScale
597 GetDesktopToDeviceScaleByScreen() = 0;
600 * Return the default scale factor for the window. This is the
601 * default number of device pixels per CSS pixel to use. This should
602 * depend on OS/platform settings such as the Mac's "UI scale factor"
603 * or Windows' "font DPI". This will take into account Gecko preferences
604 * overriding the system setting.
606 mozilla::CSSToLayoutDeviceScale GetDefaultScale();
609 * Fallback default scale for when there's no widget available.
611 static mozilla::CSSToLayoutDeviceScale GetFallbackDefaultScale();
614 * Return the first child of this widget. Will return null if
615 * there are no children.
617 nsIWidget* GetFirstChild() const { return mFirstChild; }
620 * Return the last child of this widget. Will return null if
621 * there are no children.
623 nsIWidget* GetLastChild() const { return mLastChild; }
626 * Return the next sibling of this widget
628 nsIWidget* GetNextSibling() const { return mNextSibling; }
631 * Set the next sibling of this widget
633 void SetNextSibling(nsIWidget* aSibling) { mNextSibling = aSibling; }
636 * Return the previous sibling of this widget
638 nsIWidget* GetPrevSibling() const { return mPrevSibling; }
641 * Set the previous sibling of this widget
643 void SetPrevSibling(nsIWidget* aSibling) { mPrevSibling = aSibling; }
646 * Show or hide this widget
648 * @param aState true to show the Widget, false to hide it
651 virtual void Show(bool aState) = 0;
654 * Whether or not a widget must be recreated after being hidden to show
655 * again properly.
657 virtual bool NeedsRecreateToReshow() { return false; }
660 * Make the window modal.
662 virtual void SetModal(bool aModal) = 0;
665 * Make the non-modal window opened by modal window fake-modal, that will
666 * call SetFakeModal(false) on destroy on Cocoa.
668 virtual void SetFakeModal(bool aModal) { SetModal(aModal); }
671 * Are we app modal. Currently only implemented on Cocoa.
673 virtual bool IsRunningAppModal() { return false; }
676 * The maximum number of simultaneous touch contacts supported by the device.
677 * In the case of devices with multiple digitizers (e.g. multiple touch
678 * screens), the value will be the maximum of the set of maximum supported
679 * contacts by each individual digitizer.
681 virtual uint32_t GetMaxTouchPoints() const = 0;
684 * Returns whether the window is visible
687 virtual bool IsVisible() const = 0;
690 * Returns whether the window has allocated resources so
691 * we can paint into it.
692 * Recently it's used on Linux/Gtk where we should not paint
693 * to invisible window.
695 virtual bool IsMapped() const { return true; }
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;
714 * NOTE:
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.
733 * Move this widget.
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
760 * system
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
778 * system
779 * @param aY the new y position expressed in the parent's coordinate
780 * system
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
783 * system
784 * @param aRepaint whether the widget should be repainted if the size
785 * changes
788 virtual void Resize(double aX, double aY, double aWidth, double aHeight,
789 bool aRepaint) = 0;
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
805 * offset and size.
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.
885 enum class Raise {
887 Yes,
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
919 * nsSizeMode_Normal.
921 * @param aRect On return it holds the x, y, width and height of
922 * this widget.
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)
943 * Platform notes:
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(const LayoutDeviceIntMargin&) = 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;
987 struct Cursor {
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 WindowType GetWindowType() const { 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
1031 * context.
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(TransparencyMode aMode) = 0;
1042 * Get the transparency mode of the top-level window that contains this
1043 * widget.
1045 virtual TransparencyMode 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
1081 * Linux.
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
1155 * finishes.
1157 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
1158 uint16_t aDuration,
1159 nsISupports* aData,
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<Screen> 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
1193 * later.
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
1240 * paint anything.
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) {}
1266 * Internal methods
1269 //@{
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 FreeNativeData(void* data, uint32_t aDataType) = 0; //~~~
1275 //@}
1278 * Set the widget's title.
1279 * Must be called after Create.
1281 * @param aTitle string displayed as the title of the widget
1283 virtual nsresult SetTitle(const nsAString& aTitle) = 0;
1286 * Set the widget's icon.
1287 * Must be called after Create.
1289 * @param aIconSpec string specifying the icon to use; convention is to
1290 * pass a resource: URL from which a platform-dependent
1291 * resource file name will be constructed
1293 virtual void SetIcon(const nsAString& aIconSpec) = 0;
1296 * Return this widget's origin in screen coordinates.
1298 * @return screen coordinates stored in the x,y members
1300 virtual LayoutDeviceIntPoint WidgetToScreenOffset() = 0;
1303 * The same as WidgetToScreenOffset(), except in the case of
1304 * PuppetWidget where this method omits the chrome offset.
1306 virtual LayoutDeviceIntPoint TopLevelWidgetToScreenOffset() {
1307 return WidgetToScreenOffset();
1311 * For a PuppetWidget, returns the transform from the coordinate
1312 * space of the PuppetWidget to the coordinate space of the
1313 * top-level native widget.
1315 * Identity transform in other cases.
1317 virtual mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
1318 WidgetToTopLevelWidgetTransform() {
1319 return mozilla::LayoutDeviceToLayoutDeviceMatrix4x4();
1322 mozilla::LayoutDeviceIntPoint WidgetToTopLevelWidgetOffset() {
1323 return mozilla::LayoutDeviceIntPoint::Round(
1324 WidgetToTopLevelWidgetTransform().TransformPoint(
1325 mozilla::LayoutDevicePoint()));
1329 * Returns the margins that are applied to go from client sizes to window
1330 * sizes (which includes window borders and titlebar).
1331 * This method should work even when the window is not yet visible.
1333 virtual LayoutDeviceIntMargin ClientToWindowMargin() { return {}; }
1335 LayoutDeviceIntSize ClientToWindowSizeDifference();
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
1356 // dispatch.
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 * Classify the window for the window manager. Mostly for X11.
1398 * @param xulWinType The window type. Characters other than [A-Za-z0-9_-] are
1399 * converted to '_'. Anything before the first colon is
1400 * assigned to name, anything after it to role. If there's
1401 * no colon, assign the whole thing to both role and name.
1403 * @param xulWinClass The window class. If set, overrides the normal value.
1404 * Otherwise, the program class it used.
1406 * @param xulWinName The window name. If set, overrides the value specified in
1407 * window type. Otherwise, name from window type is used.
1410 virtual void SetWindowClass(const nsAString& xulWinType,
1411 const nsAString& xulWinClass,
1412 const nsAString& xulWinName) = 0;
1415 * Enables/Disables system capture of any and all events that would cause a
1416 * popup to be rolled up. aListener should be set to a non-null value for
1417 * any popups that are not managed by the popup manager.
1418 * @param aDoCapture true enables capture, false disables capture
1421 virtual void CaptureRollupEvents(bool aDoCapture) = 0;
1424 * Bring this window to the user's attention. This is intended to be a more
1425 * gentle notification than popping the window to the top or putting up an
1426 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1427 * the Mac. The notification should be suppressed if the window is already
1428 * in the foreground and should be dismissed when the user brings this window
1429 * to the foreground.
1430 * @param aCycleCount Maximum number of times to animate the window per system
1431 * conventions. If set to -1, cycles indefinitely until
1432 * window is brought into the foreground.
1434 [[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) = 0;
1437 * Ask whether there user input events pending. All input events are
1438 * included, including those not targeted at this nsIwidget instance.
1440 virtual bool HasPendingInputEvent() = 0;
1443 * If set to true, the window will draw its contents into the titlebar
1444 * instead of below it.
1446 * Ignored on any platform that does not support it. Ignored by widgets that
1447 * do not represent windows.
1448 * May result in a resize event, so should only be called from places where
1449 * reflow and painting is allowed.
1451 * @param aState Whether drawing into the titlebar should be activated.
1453 virtual void SetDrawsInTitlebar(bool aState) = 0;
1456 * Determine whether the widget shows a resize widget. If it does,
1457 * aResizerRect returns the resizer's rect.
1459 * Returns false on any platform that does not support it.
1461 * @param aResizerRect The resizer's rect in device pixels.
1462 * @return Whether a resize widget is shown.
1464 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) = 0;
1466 // TODO: Make this an enum class with MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS or
1467 // EnumSet class.
1468 enum Modifiers : uint32_t {
1469 NO_MODIFIERS = 0x00000000,
1470 CAPS_LOCK = 0x00000001, // when CapsLock is active
1471 NUM_LOCK = 0x00000002, // when NumLock is active
1472 SHIFT_L = 0x00000100,
1473 SHIFT_R = 0x00000200,
1474 CTRL_L = 0x00000400,
1475 CTRL_R = 0x00000800,
1476 ALT_L = 0x00001000, // includes Option
1477 ALT_R = 0x00002000,
1478 COMMAND_L = 0x00004000,
1479 COMMAND_R = 0x00008000,
1480 HELP = 0x00010000,
1481 ALTGRAPH = 0x00020000, // AltGr key on Windows. This emulates
1482 // AltRight key behavior of keyboard
1483 // layouts which maps AltGr to AltRight
1484 // key.
1485 FUNCTION = 0x00100000,
1486 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1489 * Utility method intended for testing. Dispatches native key events
1490 * to this widget to simulate the press and release of a key.
1491 * @param aNativeKeyboardLayout a *platform-specific* constant.
1492 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1493 * On Windows, it is converted to a hex string and passed to
1494 * LoadKeyboardLayout, see
1495 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1496 * @param aNativeKeyCode a *platform-specific* keycode.
1497 * On Windows, this is the virtual key code.
1498 * @param aModifiers some combination of the above 'Modifiers' flags;
1499 * not all flags will apply to all platforms. Mac ignores the _R
1500 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1501 * FUNCTION.
1502 * @param aCharacters characters that the OS would decide to generate
1503 * from the event. On Windows, this is the charCode passed by
1504 * WM_CHAR.
1505 * @param aUnmodifiedCharacters characters that the OS would decide
1506 * to generate from the event if modifier keys (other than shift)
1507 * were assumed inactive. Needed on Mac, ignored on Windows.
1508 * @param aObserver the observer that will get notified once the events
1509 * have been dispatched.
1510 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1511 * layout is not supported and the event was not fired
1513 virtual nsresult SynthesizeNativeKeyEvent(
1514 int32_t aNativeKeyboardLayout, int32_t aNativeKeyCode,
1515 uint32_t aModifierFlags, const nsAString& aCharacters,
1516 const nsAString& aUnmodifiedCharacters, nsIObserver* aObserver) = 0;
1519 * Utility method intended for testing. Dispatches native mouse events
1520 * may even move the mouse cursor. On Mac the events are guaranteed to
1521 * be sent to the window containing this widget, but on Windows they'll go
1522 * to whatever's topmost on the screen at that position, so for
1523 * cross-platform testing ensure that your window is at the top of the
1524 * z-order.
1525 * @param aPoint screen location of the mouse, in device
1526 * pixels, with origin at the top left
1527 * @param aNativeMessage abstract native message.
1528 * @param aButton Mouse button defined by DOM UI Events.
1529 * @param aModifierFlags Some values of nsIWidget::Modifiers.
1530 * FYI: On Windows, Android and Headless widget on all
1531 * platroms, this hasn't been handled yet.
1532 * @param aObserver the observer that will get notified once the events
1533 * have been dispatched.
1535 enum class NativeMouseMessage : uint32_t {
1536 ButtonDown, // button down
1537 ButtonUp, // button up
1538 Move, // mouse cursor move
1539 EnterWindow, // mouse cursor comes into a window
1540 LeaveWindow, // mouse cursor leaves from a window
1542 virtual nsresult SynthesizeNativeMouseEvent(
1543 LayoutDeviceIntPoint aPoint, NativeMouseMessage aNativeMessage,
1544 mozilla::MouseButton aButton, nsIWidget::Modifiers aModifierFlags,
1545 nsIObserver* aObserver) = 0;
1548 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native
1549 * message. aPoint is location in device pixels to which the mouse pointer
1550 * moves to.
1551 * @param aObserver the observer that will get notified once the events
1552 * have been dispatched.
1554 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
1555 nsIObserver* aObserver) = 0;
1558 * Utility method intended for testing. Dispatching native mouse scroll
1559 * events may move the mouse cursor.
1561 * @param aPoint Mouse cursor position in screen coordinates.
1562 * In device pixels, the origin at the top left of
1563 * the primary display.
1564 * @param aNativeMessage Platform native message.
1565 * @param aDeltaX The delta value for X direction. If the native
1566 * message doesn't indicate X direction scrolling,
1567 * this may be ignored.
1568 * @param aDeltaY The delta value for Y direction. If the native
1569 * message doesn't indicate Y direction scrolling,
1570 * this may be ignored.
1571 * @param aDeltaZ The delta value for Z direction. If the native
1572 * message doesn't indicate Z direction scrolling,
1573 * this may be ignored.
1574 * @param aModifierFlags Must be values of Modifiers, or zero.
1575 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1576 * document.
1577 * @param aObserver The observer that will get notified once the
1578 * events have been dispatched.
1580 virtual nsresult SynthesizeNativeMouseScrollEvent(
1581 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
1582 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
1583 uint32_t aAdditionalFlags, nsIObserver* aObserver) = 0;
1586 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1587 * touch states in nsIDOMWindowUtils.idl.
1589 enum TouchPointerState {
1590 // The pointer is in a hover state above the digitizer
1591 TOUCH_HOVER = (1 << 0),
1592 // The pointer is in contact with the digitizer
1593 TOUCH_CONTACT = (1 << 1),
1594 // The pointer has been removed from the digitizer detection area
1595 TOUCH_REMOVE = (1 << 2),
1596 // The pointer has been canceled. Will cancel any pending os level
1597 // gestures that would triggered as a result of completion of the
1598 // input sequence. This may not cancel moz platform related events
1599 // that might get tirggered by input already delivered.
1600 TOUCH_CANCEL = (1 << 3),
1602 // ALL_BITS used for validity checking during IPC serialization
1603 ALL_BITS = (1 << 4) - 1
1606 * TouchpadGesturePhase states for SynthesizeNativeTouchPadPinch and
1607 * SynthesizeNativeTouchpadPan. Match phase states in nsIDOMWindowUtils.idl.
1609 enum TouchpadGesturePhase {
1610 PHASE_BEGIN = 0,
1611 PHASE_UPDATE = 1,
1612 PHASE_END = 2
1615 * Create a new or update an existing touch pointer on the digitizer.
1616 * To trigger os level gestures, individual touch points should
1617 * transition through a complete set of touch states which should be
1618 * sent as individual messages.
1620 * @param aPointerId The touch point id to create or update.
1621 * @param aPointerState one or more of the touch states listed above
1622 * @param aPoint coords of this event
1623 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1624 * @param aOrientation 0 -> 359 degree value indicating the
1625 * orientation of the pointer. Use 90 for normal taps.
1626 * @param aObserver The observer that will get notified once the events
1627 * have been dispatched.
1629 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
1630 TouchPointerState aPointerState,
1631 LayoutDeviceIntPoint aPoint,
1632 double aPointerPressure,
1633 uint32_t aPointerOrientation,
1634 nsIObserver* aObserver) = 0;
1636 * See nsIDOMWindowUtils.sendNativeTouchpadPinch().
1638 virtual nsresult SynthesizeNativeTouchPadPinch(
1639 TouchpadGesturePhase aEventPhase, float aScale,
1640 LayoutDeviceIntPoint aPoint, int32_t aModifierFlags) = 0;
1643 * Helper for simulating a simple tap event with one touch point. When
1644 * aLongTap is true, simulates a native long tap with a duration equal to
1645 * ui.click_hold_context_menus.delay. This pref is compatible with the
1646 * apzc long tap duration. Defaults to 1.5 seconds.
1647 * @param aObserver The observer that will get notified once the events
1648 * have been dispatched.
1650 virtual nsresult SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
1651 bool aLongTap,
1652 nsIObserver* aObserver);
1654 virtual nsresult SynthesizeNativePenInput(uint32_t aPointerId,
1655 TouchPointerState aPointerState,
1656 LayoutDeviceIntPoint aPoint,
1657 double aPressure,
1658 uint32_t aRotation, int32_t aTiltX,
1659 int32_t aTiltY, int32_t aButton,
1660 nsIObserver* aObserver) = 0;
1663 * Cancels all active simulated touch input points and pending long taps.
1664 * Native widgets should track existing points such that they can clear the
1665 * digitizer state when this call is made.
1666 * @param aObserver The observer that will get notified once the touch
1667 * sequence has been cleared.
1669 virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver);
1672 * Send a native event as if the user double tapped the touchpad with two
1673 * fingers.
1675 virtual nsresult SynthesizeNativeTouchpadDoubleTap(
1676 LayoutDeviceIntPoint aPoint, uint32_t aModifierFlags) = 0;
1679 * See nsIDOMWindowUtils.sendNativeTouchpadPan().
1681 virtual nsresult SynthesizeNativeTouchpadPan(TouchpadGesturePhase aEventPhase,
1682 LayoutDeviceIntPoint aPoint,
1683 double aDeltaX, double aDeltaY,
1684 int32_t aModifierFlags,
1685 nsIObserver* aObserver) = 0;
1687 virtual void StartAsyncScrollbarDrag(
1688 const AsyncDragMetrics& aDragMetrics) = 0;
1691 * Notify APZ to start autoscrolling.
1692 * @param aAnchorLocation the location of the autoscroll anchor
1693 * @param aGuid identifies the scroll frame to be autoscrolled
1694 * @return true if APZ has been successfully notified
1696 virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
1697 const ScrollableLayerGuid& aGuid) = 0;
1700 * Notify APZ to stop autoscrolling.
1701 * @param aGuid identifies the scroll frame which is being autoscrolled.
1703 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) = 0;
1705 virtual LayersId GetRootLayerTreeId() = 0;
1707 // If this widget supports out-of-process compositing, it can override
1708 // this method to provide additional information to the compositor.
1709 virtual void GetCompositorWidgetInitData(
1710 mozilla::widget::CompositorWidgetInitData* aInitData) {}
1713 * Setter/Getter of the system font setting for testing.
1715 virtual nsresult SetSystemFont(const nsCString& aFontName) {
1716 return NS_ERROR_NOT_IMPLEMENTED;
1718 virtual nsresult GetSystemFont(nsCString& aFontName) {
1719 return NS_ERROR_NOT_IMPLEMENTED;
1723 * Wayland specific routines.
1725 virtual LayoutDeviceIntSize GetMoveToRectPopupSize() const {
1726 NS_WARNING("GetLayoutPopupRect implemented only for wayland");
1727 return LayoutDeviceIntSize();
1731 * If this widget uses native pointer lock instead of warp-to-center
1732 * (currently only GTK on Wayland), these methods provide access to that
1733 * functionality.
1735 virtual void SetNativePointerLockCenter(
1736 const LayoutDeviceIntPoint& aLockCenter) {}
1737 virtual void LockNativePointer() {}
1738 virtual void UnlockNativePointer() {}
1741 * Get safe area insets except to cutout.
1742 * See https://drafts.csswg.org/css-env-1/#safe-area-insets.
1744 virtual mozilla::ScreenIntMargin GetSafeAreaInsets() const {
1745 return mozilla::ScreenIntMargin();
1748 private:
1749 class LongTapInfo {
1750 public:
1751 LongTapInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
1752 mozilla::TimeDuration aDuration, nsIObserver* aObserver)
1753 : mPointerId(aPointerId),
1754 mPosition(aPoint),
1755 mDuration(aDuration),
1756 mObserver(aObserver),
1757 mStamp(mozilla::TimeStamp::Now()) {}
1759 int32_t mPointerId;
1760 LayoutDeviceIntPoint mPosition;
1761 mozilla::TimeDuration mDuration;
1762 nsCOMPtr<nsIObserver> mObserver;
1763 mozilla::TimeStamp mStamp;
1766 static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure);
1768 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboardContentProcess();
1769 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboardInner();
1771 mozilla::UniquePtr<LongTapInfo> mLongTapTouchPoint;
1772 nsCOMPtr<nsITimer> mLongTapTimer;
1773 static int32_t sPointerIdCounter;
1775 public:
1777 * If key events have not been handled by content or XBL handlers, they can
1778 * be offered to the system (for custom application shortcuts set in system
1779 * preferences, for example).
1781 virtual void PostHandleKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
1784 * Activates a native menu item at the position specified by the index
1785 * string. The index string is a string of positive integers separated
1786 * by the "|" (pipe) character. The last integer in the string represents
1787 * the item index in a submenu located using the integers preceding it.
1789 * Example: 1|0|4
1790 * In this string, the first integer represents the top-level submenu
1791 * in the native menu bar. Since the integer is 1, it is the second submeu
1792 * in the native menu bar. Within that, the first item (index 0) is a
1793 * submenu, and we want to activate the 5th item within that submenu.
1795 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1798 * This is used for native menu system testing.
1800 * Updates a native menu at the position specified by the index string.
1801 * The index string is a string of positive integers separated by the "|"
1802 * (pipe) character.
1804 * Example: 1|0|4
1805 * In this string, the first integer represents the top-level submenu
1806 * in the native menu bar. Since the integer is 1, it is the second submeu
1807 * in the native menu bar. Within that, the first item (index 0) is a
1808 * submenu, and we want to update submenu at index 4 within that submenu.
1810 * If this is called with an empty string it forces a full reload of the
1811 * menu system.
1813 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1816 * This is used for testing macOS service menu code.
1818 * @param aResult - the current text selection. Is empty if no selection.
1819 * @return nsresult - whether or not aResult was assigned the selected text.
1821 [[nodiscard]] virtual nsresult GetSelectionAsPlaintext(nsAString& aResult) {
1822 return NS_ERROR_NOT_IMPLEMENTED;
1826 * Notify IME of the specified notification.
1828 * @return If the notification is mouse button event and it's consumed by
1829 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1831 virtual nsresult NotifyIME(const IMENotification& aIMENotification) = 0;
1834 * MaybeDispatchInitialFocusEvent will dispatch a focus event after creation
1835 * of the widget, in the event that we were not able to observe and respond to
1836 * the initial focus event. This is necessary for the early skeleton UI
1837 * window, which is displayed and receives its initial focus event before we
1838 * can actually respond to it.
1840 virtual void MaybeDispatchInitialFocusEvent() {}
1843 * Notifies the input context changes.
1845 virtual void SetInputContext(const InputContext& aContext,
1846 const InputContextAction& aAction) = 0;
1849 * Get current input context.
1851 virtual InputContext GetInputContext() = 0;
1854 * Get native IME context. This is different from GetNativeData() with
1855 * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
1856 * process.
1858 virtual NativeIMEContext GetNativeIMEContext() = 0;
1861 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1862 * native (OS-level) event for it. This method allows tests to simulate
1863 * keystrokes that trigger native key bindings (which require a native
1864 * event).
1866 [[nodiscard]] virtual nsresult AttachNativeKeyEvent(
1867 mozilla::WidgetKeyboardEvent& aEvent) = 0;
1870 * Retrieve edit commands when the key combination of aEvent is used
1871 * in platform native applications.
1873 MOZ_CAN_RUN_SCRIPT virtual bool GetEditCommands(
1874 mozilla::NativeKeyBindingsType aType,
1875 const mozilla::WidgetKeyboardEvent& aEvent,
1876 nsTArray<mozilla::CommandInt>& aCommands);
1879 * Retrieves a reference to notification requests of IME. Note that the
1880 * reference is valid while the nsIWidget instance is alive. So, if you
1881 * need to store the reference for a long time, you need to grab the widget
1882 * instance too.
1884 const IMENotificationRequests& IMENotificationRequestsRef();
1887 * Call this method when a dialog is opened which has a default button.
1888 * The button's rectangle should be supplied in aButtonRect.
1890 [[nodiscard]] virtual nsresult OnDefaultButtonLoaded(
1891 const LayoutDeviceIntRect& aButtonRect) = 0;
1894 * Return true if this process shouldn't use platform widgets, and
1895 * so should use PuppetWidgets instead. If this returns true, the
1896 * result of creating and using a platform widget is undefined,
1897 * and likely to end in crashes or other buggy behavior.
1899 static bool UsePuppetWidgets() { return XRE_IsContentProcess(); }
1901 static already_AddRefed<nsIWidget> CreateTopLevelWindow();
1903 static already_AddRefed<nsIWidget> CreateChildWindow();
1906 * Allocate and return a "puppet widget" that doesn't directly
1907 * correlate to a platform widget; platform events and data must
1908 * be fed to it. Currently used in content processes. NULL is
1909 * returned if puppet widgets aren't supported in this build
1910 * config, on this platform, or for this process type.
1912 * This function is called "Create" to match CreateInstance().
1913 * The returned widget must still be nsIWidget::Create()d.
1915 static already_AddRefed<nsIWidget> CreatePuppetWidget(
1916 BrowserChild* aBrowserChild);
1918 static already_AddRefed<nsIWidget> CreateHeadlessWidget();
1921 * Reparent this widget's native widget.
1922 * @param aNewParent the native widget of aNewParent is the new native
1923 * parent widget
1925 virtual void ReparentNativeWidget(nsIWidget* aNewParent) = 0;
1928 * Return true if widget has it's own GL context
1930 virtual bool HasGLContext() { return false; }
1933 * Returns true to indicate that this widget paints an opaque background
1934 * that we want to be visible under the page, so layout should not force
1935 * a default background.
1937 virtual bool WidgetPaintsBackground() { return false; }
1939 virtual bool NeedsPaint() { return IsVisible() && !GetBounds().IsEmpty(); }
1942 * Get the natural bounds of this widget. This method is only
1943 * meaningful for widgets for which Gecko implements screen
1944 * rotation natively. When this is the case, GetBounds() returns
1945 * the widget bounds taking rotation into account, and
1946 * GetNaturalBounds() returns the bounds *not* taking rotation
1947 * into account.
1949 * No code outside of the composition pipeline should know or care
1950 * about this. If you're not an agent of the compositor, you
1951 * probably shouldn't call this method.
1953 virtual LayoutDeviceIntRect GetNaturalBounds() { return GetBounds(); }
1956 * Set size constraints on the window size such that it is never less than
1957 * the specified minimum size and never larger than the specified maximum
1958 * size. The size constraints are sizes of the outer rectangle including
1959 * the window frame and title bar. Use 0 for an unconstrained minimum size
1960 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1961 * does not necessarily change the size of a window to conform to this size,
1962 * thus Resize should be called afterwards.
1964 * @param aConstraints: the size constraints in device pixels
1966 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
1969 * Return the size constraints currently observed by the widget.
1971 * @return the constraints in device pixels
1973 virtual const SizeConstraints GetSizeConstraints() = 0;
1976 * Apply the current size constraints to the given size.
1978 * @param aWidth width to constrain
1979 * @param aHeight height to constrain
1981 virtual void ConstrainSize(int32_t* aWidth, int32_t* aHeight) = 0;
1984 * If this is owned by a BrowserChild, return that. Otherwise return
1985 * null.
1987 virtual BrowserChild* GetOwningBrowserChild() { return nullptr; }
1990 * If this isn't directly compositing to its window surface,
1991 * return the compositor which is doing that on our behalf.
1993 virtual CompositorBridgeChild* GetRemoteRenderer() { return nullptr; }
1996 * If there is a remote renderer, pause or resume it.
1998 virtual void PauseOrResumeCompositor(bool aPause);
2001 * Clear WebRender resources
2003 virtual void ClearCachedWebrenderResources() {}
2006 * Clear WebRender animation resources
2008 virtual void ClearWebrenderAnimationResources() {}
2011 * Request fast snapshot at RenderCompositor of WebRender.
2012 * Since readback of Windows DirectComposition is very slow.
2014 virtual bool SetNeedFastSnaphot() { return false; }
2017 * If this widget has its own vsync dispatcher, return it, otherwise return
2018 * nullptr. An example of such a local vsync dispatcher would be Wayland frame
2019 * callbacks.
2021 virtual RefPtr<mozilla::VsyncDispatcher> GetVsyncDispatcher();
2024 * Returns true if the widget requires synchronous repaints on resize,
2025 * false otherwise.
2027 virtual bool SynchronouslyRepaintOnResize() { return true; }
2030 * Some platforms (only cocoa right now) round widget coordinates to the
2031 * nearest even pixels (see bug 892994), this function allows us to
2032 * determine how widget coordinates will be rounded.
2034 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
2036 virtual void UpdateZoomConstraints(
2037 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
2038 const mozilla::Maybe<ZoomConstraints>& aConstraints){};
2041 * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
2042 * widget. Note that this never returns nullptr.
2044 virtual TextEventDispatcher* GetTextEventDispatcher() = 0;
2047 * GetNativeTextEventDispatcherListener() returns a
2048 * TextEventDispatcherListener instance which is used when the widget
2049 * instance handles native IME and/or keyboard events.
2051 virtual TextEventDispatcherListener*
2052 GetNativeTextEventDispatcherListener() = 0;
2054 virtual void ZoomToRect(const uint32_t& aPresShellId,
2055 const ScrollableLayerGuid::ViewID& aViewId,
2056 const CSSRect& aRect, const uint32_t& aFlags) = 0;
2059 * LookUpDictionary shows the dictionary for the word around current point.
2061 * @param aText the word to look up dictiorary.
2062 * @param aFontRangeArray text decoration of aText
2063 * @param aIsVertical true if the word is vertical layout
2064 * @param aPoint top-left point of aText
2066 virtual void LookUpDictionary(
2067 const nsAString& aText,
2068 const nsTArray<mozilla::FontRange>& aFontRangeArray,
2069 const bool aIsVertical, const LayoutDeviceIntPoint& aPoint) {}
2071 virtual void RequestFxrOutput() {
2072 MOZ_ASSERT(false, "This function should only execute in Windows");
2075 #if defined(MOZ_WIDGET_ANDROID)
2077 * RecvToolbarAnimatorMessageFromCompositor receive message from compositor
2078 * thread.
2080 * @param aMessage message being sent to Android UI thread.
2082 virtual void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage) = 0;
2085 * UpdateRootFrameMetrics steady state frame metrics send from compositor
2086 * thread
2088 * @param aScrollOffset page scroll offset value in screen pixels.
2089 * @param aZoom current page zoom.
2091 virtual void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
2092 const CSSToScreenScale& aZoom) = 0;
2095 * RecvScreenPixels Buffer containing the pixel from the frame buffer. Used
2096 * for android robocop tests.
2098 * @param aMem shared memory containing the frame buffer pixels.
2099 * @param aSize size of the buffer in screen pixels.
2101 virtual void RecvScreenPixels(mozilla::ipc::Shmem&& aMem,
2102 const ScreenIntSize& aSize,
2103 bool aNeedsYFlip) = 0;
2105 virtual void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight) {}
2106 virtual mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const {
2107 return 0;
2109 #endif
2111 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboard();
2114 * Like GetDefaultScale, but taking into account only the system settings
2115 * and ignoring Gecko preferences.
2117 virtual double GetDefaultScaleInternal() { return 1.0; }
2119 using WindowButtonType = mozilla::WindowButtonType;
2122 * Layout uses this to alert the widget to the client rect representing
2123 * the window maximize button. An empty rect indicates there is no
2124 * maximize button (for example, in fullscreen). This is only implemented
2125 * on Windows.
2127 virtual void SetWindowButtonRect(WindowButtonType aButtonType,
2128 const LayoutDeviceIntRect& aClientRect) {}
2130 #ifdef DEBUG
2131 virtual nsresult SetHiDPIMode(bool aHiDPI) {
2132 return NS_ERROR_NOT_IMPLEMENTED;
2134 virtual nsresult RestoreHiDPIMode() { return NS_ERROR_NOT_IMPLEMENTED; }
2135 #endif
2137 protected:
2138 // keep the list of children. We also keep track of our siblings.
2139 // The ownership model is as follows: parent holds a strong ref to
2140 // the first element of the list, and each element holds a strong
2141 // ref to the next element in the list. The prevsibling and
2142 // lastchild pointers are weak, which is fine as long as they are
2143 // maintained properly.
2144 nsCOMPtr<nsIWidget> mFirstChild;
2145 nsIWidget* MOZ_NON_OWNING_REF mLastChild;
2146 nsCOMPtr<nsIWidget> mNextSibling;
2147 nsIWidget* MOZ_NON_OWNING_REF mPrevSibling;
2148 // When Destroy() is called, the sub class should set this true.
2149 bool mOnDestroyCalled;
2150 WindowType mWindowType;
2151 int32_t mZIndex;
2154 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
2156 #endif // nsIWidget_h__