Bug 1700051: part 51) Const-qualify `mozInlineSpellStatus::mCreatedRange`. r=smaug
[gecko.git] / widget / nsIWidget.h
blob85b7e3e1818e6e984cc3dee3793d5c211b3bac54
1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsIWidget_h__
7 #define nsIWidget_h__
9 #include <cmath>
10 #include <cstdint>
11 #include "ErrorList.h"
12 #include "Units.h"
13 #include "mozilla/AlreadyAddRefed.h"
14 #include "mozilla/Assertions.h"
15 #include "mozilla/Attributes.h"
16 #include "mozilla/EventForwards.h"
17 #include "mozilla/Maybe.h"
18 #include "mozilla/RefPtr.h"
19 #include "mozilla/TimeStamp.h"
20 #include "mozilla/UniquePtr.h"
21 #include "mozilla/gfx/Matrix.h"
22 #include "mozilla/gfx/Rect.h"
23 #include "mozilla/layers/LayersTypes.h"
24 #include "mozilla/layers/ScrollableLayerGuid.h"
25 #include "mozilla/layers/ZoomConstraints.h"
26 #include "mozilla/widget/IMEData.h"
27 #include "nsCOMPtr.h"
28 #include "nsColor.h"
29 #include "nsDebug.h"
30 #include "nsID.h"
31 #include "nsIObserver.h"
32 #include "nsISupports.h"
33 #include "nsITheme.h"
34 #include "nsITimer.h"
35 #include "nsIWidgetListener.h"
36 #include "nsRect.h"
37 #include "nsSize.h"
38 #include "nsStringFwd.h"
39 #include "nsTArray.h"
40 #include "nsTHashMap.h"
41 #include "nsWidgetInitData.h"
42 #include "nsXULAppAPI.h"
44 #ifdef MOZ_IS_GCC
45 # include "VsyncSource.h"
46 #endif
48 // forward declarations
49 class nsIBidiKeyboard;
50 class nsIRollupListener;
51 class imgIContainer;
52 class nsIContent;
53 class ViewWrapper;
54 class nsIScreen;
55 class nsIRunnable;
56 class nsUint64HashKey;
58 namespace mozilla {
59 class NativeEventData;
60 class WidgetGUIEvent;
61 class WidgetInputEvent;
62 class WidgetKeyboardEvent;
63 struct FontRange;
65 enum class StyleWindowShadow : uint8_t;
67 #if defined(MOZ_WIDGET_ANDROID)
68 namespace ipc {
69 class Shmem;
71 #endif // defined(MOZ_WIDGET_ANDROID)
72 namespace dom {
73 class BrowserChild;
74 enum class CallerType : uint32_t;
75 } // namespace dom
76 namespace layers {
77 class AsyncDragMetrics;
78 class Compositor;
79 class CompositorBridgeChild;
80 struct FrameMetrics;
81 class LayerManager;
82 class LayerManagerComposite;
83 class PLayerTransactionChild;
84 class WebRenderBridgeChild;
85 } // namespace layers
86 namespace gfx {
87 class VsyncSource;
88 } // namespace gfx
89 namespace widget {
90 class TextEventDispatcher;
91 class TextEventDispatcherListener;
92 class CompositorWidget;
93 class CompositorWidgetInitData;
94 } // namespace widget
95 namespace wr {
96 class DisplayListBuilder;
97 class IpcResourceUpdateQueue;
98 enum class RenderRoot : uint8_t;
99 } // namespace wr
100 } // namespace mozilla
103 * Callback function that processes events.
105 * The argument is actually a subtype (subclass) of WidgetEvent which carries
106 * platform specific information about the event. Platform specific code
107 * knows how to deal with it.
109 * The return value determines whether or not the default action should take
110 * place.
112 typedef nsEventStatus (*EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent);
114 // Hide the native window system's real window type so as to avoid
115 // including native window system types and APIs. This is necessary
116 // to ensure cross-platform code.
117 typedef void* nsNativeWidget;
120 * Flags for the GetNativeData and SetNativeData functions
122 #define NS_NATIVE_WINDOW 0
123 #define NS_NATIVE_GRAPHIC 1
124 #define NS_NATIVE_TMP_WINDOW 2
125 #define NS_NATIVE_WIDGET 3
126 #define NS_NATIVE_DISPLAY 4
127 #define NS_NATIVE_REGION 5
128 #define NS_NATIVE_OFFSETX 6
129 #define NS_NATIVE_OFFSETY 7
130 #define NS_NATIVE_PLUGIN_PORT 8
131 #define NS_NATIVE_SCREEN 9
132 // The toplevel GtkWidget containing this nsIWidget:
133 #define NS_NATIVE_SHELLWIDGET 10
134 #define NS_NATIVE_OPENGL_CONTEXT 12
135 // See RegisterPluginWindowForRemoteUpdates
136 #define NS_NATIVE_PLUGIN_ID 13
137 // This is available only with GetNativeData() in parent process. Anybody
138 // shouldn't access this pointer as a valid pointer since the result may be
139 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
140 // an identifier of distinguishing a text composition is caused by which native
141 // IME context. Note that the result is only valid in the process. So,
142 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
143 #define NS_RAW_NATIVE_IME_CONTEXT 14
144 #define NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID 15
145 #ifdef XP_MACOSX
146 # define NS_NATIVE_PLUGIN_PORT_QD 100
147 # define NS_NATIVE_PLUGIN_PORT_CG 101
148 #endif
149 #ifdef XP_WIN
150 # define NS_NATIVE_TSF_THREAD_MGR 100
151 # define NS_NATIVE_TSF_CATEGORY_MGR 101
152 # define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
153 # define NS_NATIVE_ICOREWINDOW 103 // winrt specific
154 #endif
155 #if defined(MOZ_WIDGET_GTK)
156 // set/get nsPluginNativeWindowGtk, e10s specific
157 # define NS_NATIVE_PLUGIN_OBJECT_PTR 104
158 # define NS_NATIVE_EGL_WINDOW 106
159 #endif
160 #ifdef MOZ_WIDGET_ANDROID
161 # define NS_JAVA_SURFACE 100
162 # define NS_PRESENTATION_WINDOW 101
163 # define NS_PRESENTATION_SURFACE 102
164 #endif
166 #define MOZ_WIDGET_MAX_SIZE 16384
167 #define MOZ_WIDGET_INVALID_SCALE 0.0
169 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
170 #define NS_IWIDGET_IID \
172 0x06396bf6, 0x2dd8, 0x45e5, { \
173 0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80 \
178 * Transparency modes
181 enum nsTransparencyMode {
182 eTransparencyOpaque = 0, // Fully opaque
183 eTransparencyTransparent, // Parts of the window may be transparent
184 eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass
185 // effect applied
186 eTransparencyBorderlessGlass // As above, but without a border around the
187 // opaque areas when there would otherwise be
188 // one with eTransparencyGlass
189 // If you add to the end here, you must update the serialization code in
190 // WidgetMessageUtils.h
194 * Cursor types.
197 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
198 eCursor_standard,
199 ///(system is busy, usually rendered as a hourglass or watch)
200 eCursor_wait,
201 ///(Selecting something, usually rendered as an IBeam)
202 eCursor_select,
203 ///(can hyper-link, usually rendered as a human hand)
204 eCursor_hyperlink,
205 ///(north/south/west/east edge sizing)
206 eCursor_n_resize,
207 eCursor_s_resize,
208 eCursor_w_resize,
209 eCursor_e_resize,
210 ///(corner sizing)
211 eCursor_nw_resize,
212 eCursor_se_resize,
213 eCursor_ne_resize,
214 eCursor_sw_resize,
215 eCursor_crosshair,
216 eCursor_move,
217 eCursor_help,
218 eCursor_copy, // CSS3
219 eCursor_alias,
220 eCursor_context_menu,
221 eCursor_cell,
222 eCursor_grab,
223 eCursor_grabbing,
224 eCursor_spinning,
225 eCursor_zoom_in,
226 eCursor_zoom_out,
227 eCursor_not_allowed,
228 eCursor_col_resize,
229 eCursor_row_resize,
230 eCursor_no_drop,
231 eCursor_vertical_text,
232 eCursor_all_scroll,
233 eCursor_nesw_resize,
234 eCursor_nwse_resize,
235 eCursor_ns_resize,
236 eCursor_ew_resize,
237 eCursor_none,
238 // This one is used for array sizing, and so better be the last
239 // one in this list...
240 eCursorCount,
242 // ...except for this one.
243 eCursorInvalid = eCursorCount + 1
246 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
247 eZPlacementBottom = 0, // bottom of the window stack
248 eZPlacementBelow, // just below another widget
249 eZPlacementTop // top of the window stack
253 * Before the OS goes to sleep, this topic is notified.
255 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
258 * After the OS wakes up, this topic is notified.
260 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
263 * Before the OS suspends the current process, this topic is notified. Some
264 * OS will kill processes that are suspended instead of resuming them.
265 * For that reason this topic may be useful to safely close down resources.
267 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
270 * After the current process resumes from being suspended, this topic is
271 * notified.
273 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
276 * When an app(-shell) is activated by the OS, this topic is notified.
277 * Currently, this only happens on Mac OSX.
279 #define NS_WIDGET_MAC_APP_ACTIVATE_OBSERVER_TOPIC "mac_app_activate"
281 namespace mozilla {
282 namespace widget {
285 * Size constraints for setting the minimum and maximum size of a widget.
286 * Values are in device pixels.
288 struct SizeConstraints {
289 SizeConstraints()
290 : mMaxSize(MOZ_WIDGET_MAX_SIZE, MOZ_WIDGET_MAX_SIZE),
291 mScale(MOZ_WIDGET_INVALID_SCALE) {}
293 SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize,
294 mozilla::LayoutDeviceIntSize aMaxSize,
295 mozilla::DesktopToLayoutDeviceScale aScale)
296 : mMinSize(aMinSize), mMaxSize(aMaxSize), mScale(aScale) {
297 if (mMaxSize.width > MOZ_WIDGET_MAX_SIZE) {
298 mMaxSize.width = MOZ_WIDGET_MAX_SIZE;
300 if (mMaxSize.height > MOZ_WIDGET_MAX_SIZE) {
301 mMaxSize.height = MOZ_WIDGET_MAX_SIZE;
305 mozilla::LayoutDeviceIntSize mMinSize;
306 mozilla::LayoutDeviceIntSize mMaxSize;
309 * The scale used to convert from desktop to device dimensions.
310 * MOZ_WIDGET_INVALID_SCALE if the value is not known.
312 * Bug 1701109 is filed to revisit adding of 'mScale' and deal
313 * with multi-monitor scaling issues in more complete way across
314 * all widget implementations.
316 mozilla::DesktopToLayoutDeviceScale mScale;
319 struct AutoObserverNotifier {
320 AutoObserverNotifier(nsIObserver* aObserver, const char* aTopic)
321 : mObserver(aObserver), mTopic(aTopic) {}
323 void SkipNotification() { mObserver = nullptr; }
325 uint64_t SaveObserver() {
326 if (!mObserver) {
327 return 0;
329 uint64_t observerId = ++sObserverId;
330 sSavedObservers.InsertOrUpdate(observerId, mObserver);
331 SkipNotification();
332 return observerId;
335 ~AutoObserverNotifier() {
336 if (mObserver) {
337 mObserver->Observe(nullptr, mTopic, nullptr);
341 static void NotifySavedObserver(const uint64_t& aObserverId,
342 const char* aTopic) {
343 nsCOMPtr<nsIObserver> observer = sSavedObservers.Get(aObserverId);
344 if (!observer) {
345 MOZ_ASSERT(aObserverId == 0,
346 "We should always find a saved observer for nonzero IDs");
347 return;
350 sSavedObservers.Remove(aObserverId);
351 observer->Observe(nullptr, aTopic, nullptr);
354 private:
355 nsCOMPtr<nsIObserver> mObserver;
356 const char* mTopic;
358 private:
359 static uint64_t sObserverId;
360 static nsTHashMap<uint64_t, nsCOMPtr<nsIObserver>> sSavedObservers;
363 } // namespace widget
364 } // namespace mozilla
367 * The base class for all the widgets. It provides the interface for
368 * all basic and necessary functionality.
370 class nsIWidget : public nsISupports {
371 protected:
372 typedef mozilla::dom::BrowserChild BrowserChild;
374 public:
375 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
376 typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics;
377 typedef mozilla::layers::FrameMetrics FrameMetrics;
378 typedef mozilla::layers::LayerManager LayerManager;
379 typedef mozilla::layers::LayerManagerComposite LayerManagerComposite;
380 typedef mozilla::layers::LayersBackend LayersBackend;
381 typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild;
382 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
383 typedef mozilla::layers::ZoomConstraints ZoomConstraints;
384 typedef mozilla::widget::IMEEnabled IMEEnabled;
385 typedef mozilla::widget::IMEMessage IMEMessage;
386 typedef mozilla::widget::IMENotification IMENotification;
387 typedef mozilla::widget::IMENotificationRequests IMENotificationRequests;
388 typedef mozilla::widget::IMEState IMEState;
389 typedef mozilla::widget::InputContext InputContext;
390 typedef mozilla::widget::InputContextAction InputContextAction;
391 typedef mozilla::widget::NativeIMEContext NativeIMEContext;
392 typedef mozilla::widget::SizeConstraints SizeConstraints;
393 typedef mozilla::widget::TextEventDispatcher TextEventDispatcher;
394 typedef mozilla::widget::TextEventDispatcherListener
395 TextEventDispatcherListener;
396 typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin;
397 typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
398 typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
399 typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
400 typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
401 typedef mozilla::ScreenIntPoint ScreenIntPoint;
402 typedef mozilla::ScreenIntMargin ScreenIntMargin;
403 typedef mozilla::ScreenIntSize ScreenIntSize;
404 typedef mozilla::ScreenPoint ScreenPoint;
405 typedef mozilla::CSSToScreenScale CSSToScreenScale;
406 typedef mozilla::DesktopIntRect DesktopIntRect;
407 typedef mozilla::DesktopPoint DesktopPoint;
408 typedef mozilla::DesktopRect DesktopRect;
409 typedef mozilla::DesktopSize DesktopSize;
410 typedef mozilla::CSSPoint CSSPoint;
411 typedef mozilla::CSSRect CSSRect;
413 // Used in UpdateThemeGeometries.
414 struct ThemeGeometry {
415 // The ThemeGeometryType value for the themed widget, see
416 // nsITheme::ThemeGeometryTypeForWidget.
417 nsITheme::ThemeGeometryType mType;
418 // The device-pixel rect within the window for the themed widget
419 LayoutDeviceIntRect mRect;
421 ThemeGeometry(nsITheme::ThemeGeometryType aType,
422 const LayoutDeviceIntRect& aRect)
423 : mType(aType), mRect(aRect) {}
426 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
428 nsIWidget()
429 : mLastChild(nullptr),
430 mPrevSibling(nullptr),
431 mOnDestroyCalled(false),
432 mWindowType(eWindowType_child),
433 mZIndex(0)
436 ClearNativeTouchSequence(nullptr);
440 * Create and initialize a widget.
442 * All the arguments can be null in which case a top level window
443 * with size 0 is created. The event callback function has to be
444 * provided only if the caller wants to deal with the events this
445 * widget receives. The event callback is basically a preprocess
446 * hook called synchronously. The return value determines whether
447 * the event goes to the default window procedure or it is hidden
448 * to the os. The assumption is that if the event handler returns
449 * false the widget does not see the event. The widget should not
450 * automatically clear the window to the background color. The
451 * calling code must handle paint messages and clear the background
452 * itself.
454 * In practice at least one of aParent and aNativeParent will be null. If
455 * both are null the widget isn't parented (e.g. context menus or
456 * independent top level windows).
458 * The dimensions given in aRect are specified in the parent's
459 * device coordinate system.
460 * This must not be called for parentless widgets such as top-level
461 * windows, which use the desktop pixel coordinate system; a separate
462 * method is provided for these.
464 * @param aParent parent nsIWidget
465 * @param aNativeParent native parent widget
466 * @param aRect the widget dimension
467 * @param aInitData data that is used for widget initialization
470 [[nodiscard]] virtual nsresult Create(
471 nsIWidget* aParent, nsNativeWidget aNativeParent,
472 const LayoutDeviceIntRect& aRect,
473 nsWidgetInitData* aInitData = nullptr) = 0;
476 * As above, but with aRect specified in DesktopPixel units (for top-level
477 * widgets).
478 * Default implementation just converts aRect to device pixels and calls
479 * through to device-pixel Create, but platforms may override this if the
480 * mapping is not straightforward or the native platform needs to use the
481 * desktop pixel values directly.
483 [[nodiscard]] virtual nsresult Create(nsIWidget* aParent,
484 nsNativeWidget aNativeParent,
485 const DesktopIntRect& aRect,
486 nsWidgetInitData* aInitData = nullptr) {
487 LayoutDeviceIntRect devPixRect =
488 RoundedToInt(aRect * GetDesktopToDeviceScale());
489 return Create(aParent, aNativeParent, devPixRect, aInitData);
493 * Allocate, initialize, and return a widget that is a child of
494 * |this|. The returned widget (if nonnull) has gone through the
495 * equivalent of CreateInstance(widgetCID) + Create(...).
497 * |CreateChild()| lets widget backends decide whether to parent
498 * the new child widget to this, nonnatively parent it, or both.
499 * This interface exists to support the PuppetWidget backend,
500 * which is entirely non-native. All other params are the same as
501 * for |Create()|.
503 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
504 * |nsIWidget*| this, not its native widget (if it exists), when
505 * calling |Create()|. This is a timid hack around poorly
506 * understood code, and shouldn't be used in new code.
508 virtual already_AddRefed<nsIWidget> CreateChild(
509 const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData = nullptr,
510 bool aForceUseIWidgetParent = false) = 0;
513 * Attach to a top level widget.
515 * In cases where a top level chrome widget is being used as a content
516 * container, attach a secondary listener and update the device
517 * context. The primary widget listener will continue to be called for
518 * notifications relating to the top-level window, whereas other
519 * notifications such as painting and events will instead be called via
520 * the attached listener. SetAttachedWidgetListener should be used to
521 * assign the attached listener.
523 * aUseAttachedEvents if true, events are sent to the attached listener
524 * instead of the normal listener.
526 virtual void AttachViewToTopLevel(bool aUseAttachedEvents) = 0;
529 * Accessor functions to get and set the attached listener. Used by
530 * nsView in connection with AttachViewToTopLevel above.
532 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
533 virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
534 virtual void SetPreviouslyAttachedWidgetListener(
535 nsIWidgetListener* aListener) = 0;
536 virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() = 0;
539 * Accessor functions to get and set the listener which handles various
540 * actions for the widget.
542 //@{
543 virtual nsIWidgetListener* GetWidgetListener() = 0;
544 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
545 //@}
548 * Close and destroy the internal native window.
549 * This method does not delete the widget.
552 virtual void Destroy() = 0;
555 * Destroyed() returns true if Destroy() has been called already.
556 * Otherwise, false.
558 bool Destroyed() const { return mOnDestroyCalled; }
561 * Reparent a widget
563 * Change the widget's parent. Null parents are allowed.
565 * @param aNewParent new parent
567 virtual void SetParent(nsIWidget* aNewParent) = 0;
570 * Return the parent Widget of this Widget or nullptr if this is a
571 * top level window
573 * @return the parent widget or nullptr if it does not have a parent
576 virtual nsIWidget* GetParent(void) = 0;
579 * Return the top level Widget of this Widget
581 * @return the top level widget
583 virtual nsIWidget* GetTopLevelWidget() = 0;
586 * Return the top (non-sheet) parent of this Widget if it's a sheet,
587 * or nullptr if this isn't a sheet (or some other error occurred).
588 * Sheets are only supported on some platforms (currently only macOS).
590 * @return the top (non-sheet) parent widget or nullptr
593 virtual nsIWidget* GetSheetWindowParent(void) = 0;
596 * Return the physical DPI of the screen containing the window ...
597 * the number of device pixels per inch.
599 virtual float GetDPI() = 0;
602 * Return the scaling factor between device pixels and the platform-
603 * dependent "desktop pixels" used to manage window positions on a
604 * potentially multi-screen, mixed-resolution desktop.
606 virtual mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() = 0;
609 * Return the scaling factor between device pixels and the platform-
610 * dependent "desktop pixels" by looking up the screen by the position
611 * of the widget.
613 virtual mozilla::DesktopToLayoutDeviceScale
614 GetDesktopToDeviceScaleByScreen() = 0;
617 * Return the default scale factor for the window. This is the
618 * default number of device pixels per CSS pixel to use. This should
619 * depend on OS/platform settings such as the Mac's "UI scale factor"
620 * or Windows' "font DPI". This will take into account Gecko preferences
621 * overriding the system setting.
623 mozilla::CSSToLayoutDeviceScale GetDefaultScale();
626 * Return the first child of this widget. Will return null if
627 * there are no children.
629 nsIWidget* GetFirstChild() const { return mFirstChild; }
632 * Return the last child of this widget. Will return null if
633 * there are no children.
635 nsIWidget* GetLastChild() const { return mLastChild; }
638 * Return the next sibling of this widget
640 nsIWidget* GetNextSibling() const { return mNextSibling; }
643 * Set the next sibling of this widget
645 void SetNextSibling(nsIWidget* aSibling) { mNextSibling = aSibling; }
648 * Return the previous sibling of this widget
650 nsIWidget* GetPrevSibling() const { return mPrevSibling; }
653 * Set the previous sibling of this widget
655 void SetPrevSibling(nsIWidget* aSibling) { mPrevSibling = aSibling; }
658 * Show or hide this widget
660 * @param aState true to show the Widget, false to hide it
663 virtual void Show(bool aState) = 0;
666 * Whether or not a widget must be recreated after being hidden to show
667 * again properly.
669 virtual bool NeedsRecreateToReshow() { return false; }
672 * Make the window modal.
674 virtual void SetModal(bool aModal) = 0;
677 * Make the non-modal window opened by modal window fake-modal, that will
678 * call SetFakeModal(false) on destroy on Cocoa.
680 virtual void SetFakeModal(bool aModal) { SetModal(aModal); }
683 * Are we app modal. Currently only implemented on Cocoa.
685 virtual bool IsRunningAppModal() { return false; }
688 * The maximum number of simultaneous touch contacts supported by the device.
689 * In the case of devices with multiple digitizers (e.g. multiple touch
690 * screens), the value will be the maximum of the set of maximum supported
691 * contacts by each individual digitizer.
693 virtual uint32_t GetMaxTouchPoints() const = 0;
696 * Returns whether the window is visible
699 virtual bool IsVisible() const = 0;
702 * Perform platform-dependent sanity check on a potential window position.
703 * This is guaranteed to work only for top-level windows.
705 * @param aAllowSlop: if true, allow the window to slop offscreen;
706 * the window should be partially visible. if false,
707 * force the entire window onscreen (or at least
708 * the upper-left corner, if it's too large).
709 * @param aX in: an x position expressed in screen coordinates.
710 * out: the x position constrained to fit on the screen(s).
711 * @param aY in: an y position expressed in screen coordinates.
712 * out: the y position constrained to fit on the screen(s).
715 virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, int32_t* aY) = 0;
718 * NOTE:
720 * For a top-level window widget, the "parent's coordinate system" is the
721 * "global" display pixel coordinate space, *not* device pixels (which
722 * may be inconsistent between multiple screens, at least in the Mac OS
723 * case with mixed hi-dpi and lo-dpi displays). This applies to all the
724 * following Move and Resize widget APIs.
726 * The display-/device-pixel distinction becomes important for (at least)
727 * macOS with Hi-DPI (retina) displays, and Windows when the UI scale factor
728 * is set to other than 100%.
730 * The Move and Resize methods take floating-point parameters, rather than
731 * integer ones. This is important when manipulating top-level widgets,
732 * where the coordinate system may not be an integral multiple of the
733 * device-pixel space.
737 * Move this widget.
739 * Coordinates refer to the top-left of the widget. For toplevel windows
740 * with decorations, this is the top-left of the titlebar and frame .
742 * @param aX the new x position expressed in the parent's coordinate system
743 * @param aY the new y position expressed in the parent's coordinate system
746 virtual void Move(double aX, double aY) = 0;
749 * Reposition this widget so that the client area has the given offset.
751 * @param aOffset the new offset of the client area expressed as an
752 * offset from the origin of the client area of the parent
753 * widget (for root widgets and popup widgets it is in
754 * screen coordinates)
756 virtual void MoveClient(const DesktopPoint& aOffset) = 0;
759 * Resize this widget. Any size constraints set for the window by a
760 * previous call to SetSizeConstraints will be applied.
762 * @param aWidth the new width expressed in the parent's coordinate system
763 * @param aHeight the new height expressed in the parent's coordinate
764 * system
765 * @param aRepaint whether the widget should be repainted
767 virtual void Resize(double aWidth, double aHeight, bool aRepaint) = 0;
770 * Lock the aspect ratio of a Window
772 * @param aShouldLock bool
775 virtual void LockAspectRatio(bool aShouldLock){};
778 * Move or resize this widget. Any size constraints set for the window by
779 * a previous call to SetSizeConstraints will be applied.
781 * @param aX the new x position expressed in the parent's coordinate
782 * system
783 * @param aY the new y position expressed in the parent's coordinate
784 * system
785 * @param aWidth the new width expressed in the parent's coordinate system
786 * @param aHeight the new height expressed in the parent's coordinate
787 * system
788 * @param aRepaint whether the widget should be repainted if the size
789 * changes
792 virtual void Resize(double aX, double aY, double aWidth, double aHeight,
793 bool aRepaint) = 0;
795 virtual mozilla::Maybe<bool> IsResizingNativeWidget() {
796 return mozilla::Nothing();
800 * Resize the widget so that the inner client area has the given size.
802 * @param aSize the new size of the client area.
803 * @param aRepaint whether the widget should be repainted
805 virtual void ResizeClient(const DesktopSize& aSize, bool aRepaint) = 0;
808 * Resize and reposition the widget so tht inner client area has the given
809 * offset and size.
811 * @param aRect the new offset and size of the client area. The offset is
812 * expressed as an offset from the origin of the client area
813 * of the parent widget (for root widgets and popup widgets it
814 * is in screen coordinates).
815 * @param aRepaint whether the widget should be repainted
817 virtual void ResizeClient(const DesktopRect& aRect, bool aRepaint) = 0;
820 * Sets the widget's z-index.
822 virtual void SetZIndex(int32_t aZIndex) = 0;
825 * Gets the widget's z-index.
827 int32_t GetZIndex() { return mZIndex; }
830 * Position this widget just behind the given widget. (Used to
831 * control z-order for top-level widgets. Get/SetZIndex by contrast
832 * control z-order for child widgets of other widgets.)
833 * @param aPlacement top, bottom, or below a widget
834 * (if top or bottom, param aWidget is ignored)
835 * @param aWidget widget to place this widget behind
836 * (only if aPlacement is eZPlacementBelow).
837 * null is equivalent to aPlacement of eZPlacementTop
838 * @param aActivate true to activate the widget after placing it
840 virtual void PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
841 nsIWidget* aWidget, bool aActivate) = 0;
844 * Minimize, maximize or normalize the window size.
845 * Takes a value from nsSizeMode (see nsIWidgetListener.h)
847 virtual void SetSizeMode(nsSizeMode aMode) = 0;
849 virtual void GetWorkspaceID(nsAString& workspaceID) = 0;
851 virtual void MoveToWorkspace(const nsAString& workspaceID) = 0;
854 * Suppress animations that are applied to a window by OS.
856 virtual void SuppressAnimation(bool aSuppress) {}
859 * Return size mode (minimized, maximized, normalized).
860 * Returns a value from nsSizeMode (see nsIWidgetListener.h)
862 virtual nsSizeMode SizeMode() = 0;
865 * Ask whether the window is tiled.
867 virtual bool IsTiled() const = 0;
870 * Ask wether the widget is fully occluded
872 virtual bool IsFullyOccluded() const = 0;
875 * Enable or disable this Widget
877 * @param aState true to enable the Widget, false to disable it.
879 virtual void Enable(bool aState) = 0;
882 * Ask whether the widget is enabled
884 virtual bool IsEnabled() const = 0;
887 * Whether we should request activation of this widget's toplevel window.
889 enum class Raise {
891 Yes,
895 * Request activation of this window or give focus to this widget.
897 virtual void SetFocus(Raise, mozilla::dom::CallerType aCallerType) = 0;
900 * Get this widget's outside dimensions relative to its parent widget. For
901 * popup widgets the returned rect is in screen coordinates and not
902 * relative to its parent widget.
904 * @return the x, y, width and height of this widget.
906 virtual LayoutDeviceIntRect GetBounds() = 0;
909 * Get this widget's outside dimensions in device coordinates. This
910 * includes any title bar on the window.
912 * @return the x, y, width and height of this widget.
914 virtual LayoutDeviceIntRect GetScreenBounds() = 0;
917 * Similar to GetScreenBounds except that this function will always
918 * get the size when the widget is in the nsSizeMode_Normal size mode
919 * even if the current size mode is not nsSizeMode_Normal.
920 * This method will fail if the size mode is not nsSizeMode_Normal and
921 * the platform doesn't have the ability.
922 * This method will always succeed if the current size mode is
923 * nsSizeMode_Normal.
925 * @param aRect On return it holds the x, y, width and height of
926 * this widget.
928 [[nodiscard]] virtual nsresult GetRestoredBounds(
929 LayoutDeviceIntRect& aRect) = 0;
932 * Get this widget's client area bounds, if the window has a 3D border
933 * appearance this returns the area inside the border. The position is the
934 * position of the client area relative to the client area of the parent
935 * widget (for root widgets and popup widgets it is in screen coordinates).
937 * @return the x, y, width and height of the client area of this widget.
939 virtual LayoutDeviceIntRect GetClientBounds() = 0;
942 * Sets the non-client area dimensions of the window. Pass -1 to restore
943 * the system default frame size for that border. Pass zero to remove
944 * a border, or pass a specific value adjust a border. Units are in
945 * pixels. (DPI dependent)
947 * Platform notes:
948 * Windows: shrinking top non-client height will remove application
949 * icon and window title text. Glass desktops will refuse to set
950 * dimensions between zero and size < system default.
952 virtual nsresult SetNonClientMargins(LayoutDeviceIntMargin& aMargins) = 0;
955 * Get the client offset from the window origin.
957 * @return the x and y of the offset.
959 virtual LayoutDeviceIntPoint GetClientOffset() = 0;
962 * Equivalent to GetClientBounds but only returns the size.
964 virtual LayoutDeviceIntSize GetClientSize() {
965 // Depending on the backend, overloading this method may be useful if
966 // requesting the client offset is expensive.
967 return GetClientBounds().Size();
971 * Set the background color for this widget
973 * @param aColor the new background color
977 virtual void SetBackgroundColor(const nscolor& aColor) {}
980 * If a cursor type is currently cached locally for this widget, clear the
981 * cached cursor to force an update on the next SetCursor call.
984 virtual void ClearCachedCursor() = 0;
986 struct Cursor {
987 // The system cursor chosen by the page. This is used if there's no custom
988 // cursor, or if we fail to use the custom cursor in some way (if the image
989 // fails to load, for example).
990 nsCursor mDefaultCursor = eCursor_standard;
991 // May be null, to represent no custom cursor image.
992 nsCOMPtr<imgIContainer> mContainer;
993 uint32_t mHotspotX = 0;
994 uint32_t mHotspotY = 0;
995 float mResolution = 1.0f;
997 bool IsCustom() const { return !!mContainer; }
999 bool operator==(const Cursor& aOther) const {
1000 return mDefaultCursor == aOther.mDefaultCursor &&
1001 mContainer.get() == aOther.mContainer.get() &&
1002 mHotspotX == aOther.mHotspotX && mHotspotY == aOther.mHotspotY &&
1003 mResolution == aOther.mResolution;
1006 bool operator!=(const Cursor& aOther) { return !(*this == aOther); }
1010 * Sets the cursor for this widget.
1012 virtual void SetCursor(const Cursor&) = 0;
1014 static nsIntSize CustomCursorSize(const Cursor&);
1017 * Get the window type of this widget.
1019 nsWindowType WindowType() { return mWindowType; }
1022 * Determines if this widget is one of the three types of plugin widgets.
1024 bool IsPlugin() {
1025 return mWindowType == eWindowType_plugin ||
1026 mWindowType == eWindowType_plugin_ipc_chrome ||
1027 mWindowType == eWindowType_plugin_ipc_content;
1031 * Set the transparency mode of the top-level window containing this widget.
1032 * So, e.g., if you call this on the widget for an IFRAME, the top level
1033 * browser window containing the IFRAME actually gets set. Be careful.
1035 * This can fail if the platform doesn't support
1036 * transparency/glass. By default widgets are not
1037 * transparent. This will also fail if the toplevel window is not
1038 * a Mozilla window, e.g., if the widget is in an embedded
1039 * context.
1041 * After transparency/glass has been enabled, the initial alpha channel
1042 * value for all pixels is 1, i.e., opaque.
1043 * If the window is resized then the alpha channel values for
1044 * all pixels are reset to 1.
1045 * Pixel RGB color values are already premultiplied with alpha channel values.
1047 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
1050 * Get the transparency mode of the top-level window that contains this
1051 * widget.
1053 virtual nsTransparencyMode GetTransparencyMode() = 0;
1056 * This represents a command to set the bounds and clip region of
1057 * a child widget.
1059 struct Configuration {
1060 nsCOMPtr<nsIWidget> mChild;
1061 uintptr_t mWindowID; // e10s specific, the unique plugin port id
1062 bool mVisible; // e10s specific, widget visibility
1063 LayoutDeviceIntRect mBounds;
1064 CopyableTArray<LayoutDeviceIntRect> mClipRegion;
1068 * Sets the clip region of each mChild (which must actually be a child
1069 * of this widget) to the union of the pixel rects given in
1070 * mClipRegion, all relative to the top-left of the child
1071 * widget. Clip regions are not implemented on all platforms and only
1072 * need to actually work for children that are plugins.
1074 * Also sets the bounds of each child to mBounds.
1076 * This will invalidate areas of the children that have changed, but
1077 * does not need to invalidate any part of this widget.
1079 * Children should be moved in the order given; the array is
1080 * sorted so to minimize unnecessary invalidation if children are
1081 * moved in that order.
1083 virtual nsresult ConfigureChildren(
1084 const nsTArray<Configuration>& aConfigurations) = 0;
1085 virtual nsresult SetWindowClipRegion(
1086 const nsTArray<LayoutDeviceIntRect>& aRects,
1087 bool aIntersectWithExisting) = 0;
1090 * Appends to aRects the rectangles constituting this widget's clip
1091 * region. If this widget is not clipped, appends a single rectangle
1092 * (0, 0, bounds.width, bounds.height).
1094 virtual void GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects) = 0;
1097 * Register or unregister native plugin widgets which receive Configuration
1098 * data from the content process via the compositor.
1100 * Lookups are used by the main thread via the compositor to lookup widgets
1101 * based on a unique window id. On Windows and Linux this is the
1102 * NS_NATIVE_PLUGIN_PORT (hwnd/XID). This tracking maintains a reference to
1103 * widgets held. Consumers are responsible for removing widgets from this
1104 * list.
1106 virtual void RegisterPluginWindowForRemoteUpdates() = 0;
1107 virtual void UnregisterPluginWindowForRemoteUpdates() = 0;
1108 static nsIWidget* LookupRegisteredPluginWindow(uintptr_t aWindowID);
1111 * Iterates across the list of registered plugin widgets and updates thier
1112 * visibility based on which plugins are included in the 'visible' list.
1114 * The compositor knows little about tabs, but it does know which plugin
1115 * widgets are currently included in the visible layer tree. It calls this
1116 * helper to hide widgets it knows nothing about.
1118 static void UpdateRegisteredPluginWindowVisibility(
1119 uintptr_t aOwnerWidget, nsTArray<uintptr_t>& aPluginIds);
1121 #if defined(XP_WIN)
1123 * Iterates over the list of registered plugins and for any that are owned
1124 * by aOwnerWidget and visible it takes a snapshot.
1126 * @param aOwnerWidget only captures visible widgets owned by this
1128 static void CaptureRegisteredPlugins(uintptr_t aOwnerWidget);
1131 * Take a scroll capture for this widget if possible.
1133 virtual void UpdateScrollCapture() = 0;
1136 * Creates an async ImageContainer to hold scroll capture images that can be
1137 * used if the plugin is hidden during scroll.
1138 * @return the async container ID of the created ImageContainer.
1140 virtual uint64_t CreateScrollCaptureContainer() = 0;
1141 #endif
1144 * Set the shadow style of the window.
1146 * Ignored on child widgets and on non-Mac platforms.
1148 virtual void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle) = 0;
1151 * Set the opacity of the window.
1152 * Values need to be between 0.0f (invisible) and 1.0f (fully opaque).
1154 * Ignored on child widgets and on non-Mac platforms.
1156 virtual void SetWindowOpacity(float aOpacity) {}
1159 * Set the transform of the window. Values are in device pixels,
1160 * the origin is the top left corner of the window.
1162 * Ignored on child widgets and on non-Mac platforms.
1164 virtual void SetWindowTransform(const mozilla::gfx::Matrix& aTransform) {}
1167 * Set whether the window should ignore mouse events or not.
1169 * This is only used on popup windows.
1171 virtual void SetWindowMouseTransparent(bool aIsTransparent) {}
1174 * On macOS, this method shows or hides the pill button in the titlebar
1175 * that's used to collapse the toolbar.
1177 * Ignored on child widgets and on non-Mac platforms.
1179 virtual void SetShowsToolbarButton(bool aShow) = 0;
1182 * On macOS, this method determines whether we tell cocoa that the window
1183 * supports native full screen. If we do so, and another window is in
1184 * native full screen, this window will also appear in native full screen.
1186 * We generally only want to do this for primary application windows.
1188 * Ignored on child widgets and on non-Mac platforms.
1190 virtual void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) = 0;
1192 enum WindowAnimationType {
1193 eGenericWindowAnimation,
1194 eDocumentWindowAnimation
1198 * Sets the kind of top-level window animation this widget should have. On
1199 * macOS, this causes a particular kind of animation to be shown when the
1200 * window is first made visible.
1202 * Ignored on child widgets and on non-Mac platforms.
1204 virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
1207 * Specifies whether the window title should be drawn even if the window
1208 * contents extend into the titlebar. Ignored on windows that don't draw
1209 * in the titlebar. Only implemented on macOS.
1211 virtual void SetDrawsTitle(bool aDrawTitle) {}
1214 * These values are used to communicate the expected window apperance via
1215 * SetWindowAppearance (see function comment below for more info):
1216 * eSystem: Use the system default window appearance, which can be light or
1217 * dark.
1218 * eLight: Use the light window appearance, regardless of the current system
1219 * window appearance.
1220 * eDark: Use the dark window appearance, regardless of the current system
1221 * window appearance.
1223 enum WindowAppearance { eSystem, eLight, eDark };
1226 * Allows overriding the window's light/dark appearance. This is used for
1227 * windows whose light/dark look can differ from the system-wide look, and
1228 * allows the window decorations to better match the window contents, for
1229 * example ensuring sufficient contrast for the window buttons. The window
1230 * appearance affects the look of the window frame, window buttons, titlebars
1231 * and vibrant sidebars, and various -moz-default-appearance types.
1233 * Ignored on non-Mac platforms.
1235 virtual void SetWindowAppearance(WindowAppearance aAppearance) {}
1238 * Hide window chrome (borders, buttons) for this widget.
1241 virtual void HideWindowChrome(bool aShouldHide) = 0;
1243 enum FullscreenTransitionStage {
1244 eBeforeFullscreenToggle,
1245 eAfterFullscreenToggle
1249 * Prepares for fullscreen transition and returns whether the widget
1250 * supports fullscreen transition. If this method returns false,
1251 * PerformFullscreenTransition() must never be called. Otherwise,
1252 * caller should call that method twice with "before" and "after"
1253 * stages respectively in order. In the latter case, this method may
1254 * return some data via aData pointer. Caller must pass that data to
1255 * PerformFullscreenTransition() if any, and caller is responsible
1256 * for releasing that data.
1258 virtual bool PrepareForFullscreenTransition(nsISupports** aData) = 0;
1261 * Performs fullscreen transition. This method returns immediately,
1262 * and will post aCallback to the main thread when the transition
1263 * finishes.
1265 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
1266 uint16_t aDuration,
1267 nsISupports* aData,
1268 nsIRunnable* aCallback) = 0;
1271 * Perform any actions needed after the fullscreen transition has ended.
1273 virtual void CleanupFullscreenTransition() = 0;
1276 * Return the screen the widget is in, or null if we don't know.
1278 virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
1281 * Put the toplevel window into or out of fullscreen mode.
1282 * If aTargetScreen is given, attempt to go fullscreen on that screen,
1283 * if possible. (If not, it behaves as if aTargetScreen is null.)
1284 * If !aFullScreen, aTargetScreen is ignored.
1285 * aTargetScreen support is currently only implemented on Windows.
1287 * @return NS_OK if the widget is setup properly for fullscreen and
1288 * FullscreenChanged callback has been or will be called. If other
1289 * value is returned, the caller should continue the change itself.
1291 virtual nsresult MakeFullScreen(bool aFullScreen,
1292 nsIScreen* aTargetScreen = nullptr) = 0;
1295 * Same as MakeFullScreen, except that, on systems which natively
1296 * support fullscreen transition, calling this method explicitly
1297 * requests that behavior.
1298 * It is currently only supported on macOS 10.7+.
1300 virtual nsresult MakeFullScreenWithNativeTransition(
1301 bool aFullScreen, nsIScreen* aTargetScreen = nullptr) {
1302 return MakeFullScreen(aFullScreen, aTargetScreen);
1306 * Invalidate a specified rect for a widget so that it will be repainted
1307 * later.
1309 virtual void Invalidate(const LayoutDeviceIntRect& aRect) = 0;
1311 enum LayerManagerPersistence {
1312 LAYER_MANAGER_CURRENT = 0,
1313 LAYER_MANAGER_PERSISTENT
1317 * Return the widget's LayerManager. The layer tree for that
1318 * LayerManager is what gets rendered to the widget.
1320 inline LayerManager* GetLayerManager() {
1321 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1322 LAYER_MANAGER_CURRENT);
1325 inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence) {
1326 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1327 aPersistence);
1331 * Like GetLayerManager(), but prefers creating a layer manager of
1332 * type |aBackendHint| instead of what would normally be created.
1333 * LayersBackend::LAYERS_NONE means "no hint".
1335 virtual LayerManager* GetLayerManager(
1336 PLayerTransactionChild* aShadowManager, LayersBackend aBackendHint,
1337 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) = 0;
1340 * Called before each layer manager transaction to allow any preparation
1341 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1343 * Always called on the main thread.
1345 virtual void PrepareWindowEffects() = 0;
1348 * Called on the main thread at the end of WebRender display list building.
1350 virtual void AddWindowOverlayWebRenderCommands(
1351 mozilla::layers::WebRenderBridgeChild* aWrBridge,
1352 mozilla::wr::DisplayListBuilder& aBuilder,
1353 mozilla::wr::IpcResourceUpdateQueue& aResources) {}
1356 * Called when Gecko knows which themed widgets exist in this window.
1357 * The passed array contains an entry for every themed widget of the right
1358 * type (currently only StyleAppearance::Toolbar) within the window, except
1359 * for themed widgets which are transformed or have effects applied to them
1360 * (e.g. CSS opacity or filters).
1361 * This could sometimes be called during display list construction
1362 * outside of painting.
1363 * If called during painting, it will be called before we actually
1364 * paint anything.
1366 virtual void UpdateThemeGeometries(
1367 const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1370 * Informs the widget about the region of the window that is opaque.
1372 * @param aOpaqueRegion the region of the window that is opaque.
1374 virtual void UpdateOpaqueRegion(const LayoutDeviceIntRegion& aOpaqueRegion) {}
1377 * Informs the widget about the region of the window that is draggable.
1379 virtual void UpdateWindowDraggingRegion(
1380 const LayoutDeviceIntRegion& aRegion) {}
1383 * Tells the widget whether the given input block results in a swipe.
1384 * Should be called in response to a WidgetWheelEvent that has
1385 * mFlags.mCanTriggerSwipe set on it.
1387 virtual void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) {}
1390 * Internal methods
1393 //@{
1394 virtual void AddChild(nsIWidget* aChild) = 0;
1395 virtual void RemoveChild(nsIWidget* aChild) = 0;
1396 virtual void* GetNativeData(uint32_t aDataType) = 0;
1397 virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) = 0;
1398 virtual void FreeNativeData(void* data, uint32_t aDataType) = 0; //~~~
1400 //@}
1403 * Set the widget's title.
1404 * Must be called after Create.
1406 * @param aTitle string displayed as the title of the widget
1408 virtual nsresult SetTitle(const nsAString& aTitle) = 0;
1411 * Set the widget's icon.
1412 * Must be called after Create.
1414 * @param aIconSpec string specifying the icon to use; convention is to
1415 * pass a resource: URL from which a platform-dependent
1416 * resource file name will be constructed
1418 virtual void SetIcon(const nsAString& aIconSpec) = 0;
1421 * Return this widget's origin in screen coordinates.
1423 * @return screen coordinates stored in the x,y members
1425 virtual LayoutDeviceIntPoint WidgetToScreenOffset() = 0;
1428 * The same as WidgetToScreenOffset(), except in the case of
1429 * PuppetWidget where this method omits the chrome offset.
1431 virtual LayoutDeviceIntPoint TopLevelWidgetToScreenOffset() {
1432 return WidgetToScreenOffset();
1436 * For a PuppetWidget, returns the transform from the coordinate
1437 * space of the PuppetWidget to the coordinate space of the
1438 * top-level native widget.
1440 * Identity transform in other cases.
1442 virtual mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
1443 WidgetToTopLevelWidgetTransform() {
1444 return mozilla::LayoutDeviceToLayoutDeviceMatrix4x4();
1448 * Given the specified client size, return the corresponding window size,
1449 * which includes the area for the borders and titlebar. This method
1450 * should work even when the window is not yet visible.
1452 virtual LayoutDeviceIntSize ClientToWindowSize(
1453 const LayoutDeviceIntSize& aClientSize) = 0;
1456 * Dispatches an event to the widget
1458 virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* event,
1459 nsEventStatus& aStatus) = 0;
1462 * Dispatches an event to APZ only.
1463 * No-op in the child process.
1465 virtual void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) = 0;
1467 // A structure that groups the statuses from APZ dispatch and content
1468 // dispatch.
1469 struct ContentAndAPZEventStatus {
1470 // Either of these may not be set if the event was not dispatched
1471 // to APZ or to content.
1472 nsEventStatus mApzStatus = nsEventStatus_eIgnore;
1473 nsEventStatus mContentStatus = nsEventStatus_eIgnore;
1477 * Dispatches an event that must be handled by APZ first, when APZ is
1478 * enabled. If invoked in the child process, it is forwarded to the
1479 * parent process synchronously.
1481 virtual ContentAndAPZEventStatus DispatchInputEvent(
1482 mozilla::WidgetInputEvent* aEvent) = 0;
1485 * Confirm an APZ-aware event target. This should be used when APZ will
1486 * not need a layers update to process the event.
1488 virtual void SetConfirmedTargetAPZC(
1489 uint64_t aInputBlockId,
1490 const nsTArray<ScrollableLayerGuid>& aTargets) const = 0;
1493 * Returns true if APZ is in use, false otherwise.
1495 virtual bool AsyncPanZoomEnabled() const = 0;
1498 * Enables the dropping of files to a widget.
1500 virtual void EnableDragDrop(bool aEnable) = 0;
1501 virtual nsresult AsyncEnableDragDrop(bool aEnable) = 0;
1504 * Enables/Disables system mouse capture.
1505 * @param aCapture true enables mouse capture, false disables mouse capture
1508 virtual void CaptureMouse(bool aCapture) = 0;
1511 * Classify the window for the window manager. Mostly for X11.
1513 virtual void SetWindowClass(const nsAString& xulWinType) = 0;
1516 * Enables/Disables system capture of any and all events that would cause a
1517 * popup to be rolled up. aListener should be set to a non-null value for
1518 * any popups that are not managed by the popup manager.
1519 * @param aDoCapture true enables capture, false disables capture
1522 virtual void CaptureRollupEvents(nsIRollupListener* aListener,
1523 bool aDoCapture) = 0;
1526 * Bring this window to the user's attention. This is intended to be a more
1527 * gentle notification than popping the window to the top or putting up an
1528 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1529 * the Mac. The notification should be suppressed if the window is already
1530 * in the foreground and should be dismissed when the user brings this window
1531 * to the foreground.
1532 * @param aCycleCount Maximum number of times to animate the window per system
1533 * conventions. If set to -1, cycles indefinitely until
1534 * window is brought into the foreground.
1536 [[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) = 0;
1539 * Ask whether there user input events pending. All input events are
1540 * included, including those not targeted at this nsIwidget instance.
1542 virtual bool HasPendingInputEvent() = 0;
1545 * If set to true, the window will draw its contents into the titlebar
1546 * instead of below it.
1548 * Ignored on any platform that does not support it. Ignored by widgets that
1549 * do not represent windows.
1550 * May result in a resize event, so should only be called from places where
1551 * reflow and painting is allowed.
1553 * @param aState Whether drawing into the titlebar should be activated.
1555 virtual void SetDrawsInTitlebar(bool aState) = 0;
1558 * Determine whether the widget shows a resize widget. If it does,
1559 * aResizerRect returns the resizer's rect.
1561 * Returns false on any platform that does not support it.
1563 * @param aResizerRect The resizer's rect in device pixels.
1564 * @return Whether a resize widget is shown.
1566 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) = 0;
1569 * Begin a window resizing drag, based on the event passed in.
1571 [[nodiscard]] virtual nsresult BeginResizeDrag(
1572 mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal,
1573 int32_t aVertical) = 0;
1575 // TODO: Make this an enum class with MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS or
1576 // EnumSet class.
1577 enum Modifiers : uint32_t {
1578 NO_MODIFIERS = 0x00000000,
1579 CAPS_LOCK = 0x00000001, // when CapsLock is active
1580 NUM_LOCK = 0x00000002, // when NumLock is active
1581 SHIFT_L = 0x00000100,
1582 SHIFT_R = 0x00000200,
1583 CTRL_L = 0x00000400,
1584 CTRL_R = 0x00000800,
1585 ALT_L = 0x00001000, // includes Option
1586 ALT_R = 0x00002000,
1587 COMMAND_L = 0x00004000,
1588 COMMAND_R = 0x00008000,
1589 HELP = 0x00010000,
1590 ALTGRAPH = 0x00020000, // AltGr key on Windows. This emulates
1591 // AltRight key behavior of keyboard
1592 // layouts which maps AltGr to AltRight
1593 // key.
1594 FUNCTION = 0x00100000,
1595 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1598 * Utility method intended for testing. Dispatches native key events
1599 * to this widget to simulate the press and release of a key.
1600 * @param aNativeKeyboardLayout a *platform-specific* constant.
1601 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1602 * On Windows, it is converted to a hex string and passed to
1603 * LoadKeyboardLayout, see
1604 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1605 * @param aNativeKeyCode a *platform-specific* keycode.
1606 * On Windows, this is the virtual key code.
1607 * @param aModifiers some combination of the above 'Modifiers' flags;
1608 * not all flags will apply to all platforms. Mac ignores the _R
1609 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1610 * FUNCTION.
1611 * @param aCharacters characters that the OS would decide to generate
1612 * from the event. On Windows, this is the charCode passed by
1613 * WM_CHAR.
1614 * @param aUnmodifiedCharacters characters that the OS would decide
1615 * to generate from the event if modifier keys (other than shift)
1616 * were assumed inactive. Needed on Mac, ignored on Windows.
1617 * @param aObserver the observer that will get notified once the events
1618 * have been dispatched.
1619 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1620 * layout is not supported and the event was not fired
1622 virtual nsresult SynthesizeNativeKeyEvent(
1623 int32_t aNativeKeyboardLayout, int32_t aNativeKeyCode,
1624 uint32_t aModifierFlags, const nsAString& aCharacters,
1625 const nsAString& aUnmodifiedCharacters, nsIObserver* aObserver) = 0;
1628 * Utility method intended for testing. Dispatches native mouse events
1629 * may even move the mouse cursor. On Mac the events are guaranteed to
1630 * be sent to the window containing this widget, but on Windows they'll go
1631 * to whatever's topmost on the screen at that position, so for
1632 * cross-platform testing ensure that your window is at the top of the
1633 * z-order.
1634 * @param aPoint screen location of the mouse, in device
1635 * pixels, with origin at the top left
1636 * @param aNativeMessage abstract native message.
1637 * @param aButton Mouse button defined by DOM UI Events.
1638 * @param aModifierFlags Some values of nsIWidget::Modifiers.
1639 * FYI: On Windows, Android and Headless widget on all
1640 * platroms, this hasn't been handled yet.
1641 * @param aObserver the observer that will get notified once the events
1642 * have been dispatched.
1644 enum class NativeMouseMessage : uint32_t {
1645 ButtonDown, // button down
1646 ButtonUp, // button up
1647 Move, // mouse cursor move
1648 EnterWindow, // mouse cursor comes into a window
1649 LeaveWindow, // mouse cursor leaves from a window
1651 virtual nsresult SynthesizeNativeMouseEvent(
1652 LayoutDeviceIntPoint aPoint, NativeMouseMessage aNativeMessage,
1653 mozilla::MouseButton aButton, nsIWidget::Modifiers aModifierFlags,
1654 nsIObserver* aObserver) = 0;
1657 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native
1658 * message. aPoint is location in device pixels to which the mouse pointer
1659 * moves to.
1660 * @param aObserver the observer that will get notified once the events
1661 * have been dispatched.
1663 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
1664 nsIObserver* aObserver) = 0;
1667 * Utility method intended for testing. Dispatching native mouse scroll
1668 * events may move the mouse cursor.
1670 * @param aPoint Mouse cursor position in screen coordinates.
1671 * In device pixels, the origin at the top left of
1672 * the primary display.
1673 * @param aNativeMessage Platform native message.
1674 * @param aDeltaX The delta value for X direction. If the native
1675 * message doesn't indicate X direction scrolling,
1676 * this may be ignored.
1677 * @param aDeltaY The delta value for Y direction. If the native
1678 * message doesn't indicate Y direction scrolling,
1679 * this may be ignored.
1680 * @param aDeltaZ The delta value for Z direction. If the native
1681 * message doesn't indicate Z direction scrolling,
1682 * this may be ignored.
1683 * @param aModifierFlags Must be values of Modifiers, or zero.
1684 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1685 * document.
1686 * @param aObserver The observer that will get notified once the
1687 * events have been dispatched.
1689 virtual nsresult SynthesizeNativeMouseScrollEvent(
1690 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
1691 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
1692 uint32_t aAdditionalFlags, nsIObserver* aObserver) = 0;
1695 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1696 * touch states in nsIDOMWindowUtils.idl.
1698 enum TouchPointerState {
1699 // The pointer is in a hover state above the digitizer
1700 TOUCH_HOVER = (1 << 0),
1701 // The pointer is in contact with the digitizer
1702 TOUCH_CONTACT = (1 << 1),
1703 // The pointer has been removed from the digitizer detection area
1704 TOUCH_REMOVE = (1 << 2),
1705 // The pointer has been canceled. Will cancel any pending os level
1706 // gestures that would triggered as a result of completion of the
1707 // input sequence. This may not cancel moz platform related events
1708 // that might get tirggered by input already delivered.
1709 TOUCH_CANCEL = (1 << 3),
1711 // ALL_BITS used for validity checking during IPC serialization
1712 ALL_BITS = (1 << 4) - 1
1715 * TouchpadPinchPhase states for SynthesizeNativeTouchPadPinch. Match
1716 * Phase states in nsIDOMWindowUtils.idl.
1718 enum TouchpadPinchPhase { PHASE_BEGIN = 0, PHASE_UPDATE = 1, PHASE_END = 2 };
1720 * Create a new or update an existing touch pointer on the digitizer.
1721 * To trigger os level gestures, individual touch points should
1722 * transition through a complete set of touch states which should be
1723 * sent as individual messages.
1725 * @param aPointerId The touch point id to create or update.
1726 * @param aPointerState one or more of the touch states listed above
1727 * @param aPoint coords of this event
1728 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1729 * @param aOrientation 0 -> 359 degree value indicating the
1730 * orientation of the pointer. Use 90 for normal taps.
1731 * @param aObserver The observer that will get notified once the events
1732 * have been dispatched.
1734 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
1735 TouchPointerState aPointerState,
1736 LayoutDeviceIntPoint aPoint,
1737 double aPointerPressure,
1738 uint32_t aPointerOrientation,
1739 nsIObserver* aObserver) = 0;
1741 * See nsIDOMWindowUtils.sendNativeTouchpadPinch().
1743 virtual nsresult SynthesizeNativeTouchPadPinch(TouchpadPinchPhase aEventPhase,
1744 float aScale,
1745 LayoutDeviceIntPoint aPoint,
1746 int32_t aModifierFlags) = 0;
1749 * Helper for simulating a simple tap event with one touch point. When
1750 * aLongTap is true, simulates a native long tap with a duration equal to
1751 * ui.click_hold_context_menus.delay. This pref is compatible with the
1752 * apzc long tap duration. Defaults to 1.5 seconds.
1753 * @param aObserver The observer that will get notified once the events
1754 * have been dispatched.
1756 virtual nsresult SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
1757 bool aLongTap,
1758 nsIObserver* aObserver);
1760 virtual nsresult SynthesizeNativePenInput(
1761 uint32_t aPointerId, TouchPointerState aPointerState,
1762 LayoutDeviceIntPoint aPoint, double aPressure, uint32_t aRotation,
1763 int32_t aTiltX, int32_t aTiltY, nsIObserver* aObserver) = 0;
1766 * Cancels all active simulated touch input points and pending long taps.
1767 * Native widgets should track existing points such that they can clear the
1768 * digitizer state when this call is made.
1769 * @param aObserver The observer that will get notified once the touch
1770 * sequence has been cleared.
1772 virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver);
1775 * Send a native event as if the user double tapped the touchpad with two
1776 * fingers.
1778 virtual nsresult SynthesizeNativeTouchpadDoubleTap(
1779 LayoutDeviceIntPoint aPoint, uint32_t aModifierFlags) = 0;
1781 virtual void StartAsyncScrollbarDrag(
1782 const AsyncDragMetrics& aDragMetrics) = 0;
1785 * Notify APZ to start autoscrolling.
1786 * @param aAnchorLocation the location of the autoscroll anchor
1787 * @param aGuid identifies the scroll frame to be autoscrolled
1788 * @return true if APZ has been successfully notified
1790 virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
1791 const ScrollableLayerGuid& aGuid) = 0;
1794 * Notify APZ to stop autoscrolling.
1795 * @param aGuid identifies the scroll frame which is being autoscrolled.
1797 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) = 0;
1799 // If this widget supports out-of-process compositing, it can override
1800 // this method to provide additional information to the compositor.
1801 virtual void GetCompositorWidgetInitData(
1802 mozilla::widget::CompositorWidgetInitData* aInitData) {}
1805 * Setter/Getter of the system font setting for testing.
1807 virtual nsresult SetSystemFont(const nsCString& aFontName) {
1808 return NS_ERROR_NOT_IMPLEMENTED;
1810 virtual nsresult GetSystemFont(nsCString& aFontName) {
1811 return NS_ERROR_NOT_IMPLEMENTED;
1814 // Get rectangle of the screen where the window is placed.
1815 // It's used to detect popup overflow under Wayland because
1816 // Screenmanager does not work under it.
1817 #ifdef MOZ_WAYLAND
1818 virtual nsresult GetScreenRect(LayoutDeviceIntRect* aRect) {
1819 return NS_ERROR_NOT_IMPLEMENTED;
1821 virtual nsRect GetPreferredPopupRect() {
1822 NS_WARNING("GetPreferredPopupRect implemented only for wayland");
1823 return nsRect(0, 0, 0, 0);
1825 virtual void FlushPreferredPopupRect() {
1826 NS_WARNING("FlushPreferredPopupRect implemented only for wayland");
1827 return;
1830 #endif
1833 * If this widget uses native pointer lock instead of warp-to-center
1834 * (currently only GTK on Wayland), these methods provide access to that
1835 * functionality.
1837 virtual void SetNativePointerLockCenter(
1838 const LayoutDeviceIntPoint& aLockCenter) {}
1839 virtual void LockNativePointer() {}
1840 virtual void UnlockNativePointer() {}
1843 * Get safe area insets except to cutout.
1844 * See https://drafts.csswg.org/css-env-1/#safe-area-insets.
1846 virtual mozilla::ScreenIntMargin GetSafeAreaInsets() const {
1847 return mozilla::ScreenIntMargin();
1850 private:
1851 class LongTapInfo {
1852 public:
1853 LongTapInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
1854 mozilla::TimeDuration aDuration, nsIObserver* aObserver)
1855 : mPointerId(aPointerId),
1856 mPosition(aPoint),
1857 mDuration(aDuration),
1858 mObserver(aObserver),
1859 mStamp(mozilla::TimeStamp::Now()) {}
1861 int32_t mPointerId;
1862 LayoutDeviceIntPoint mPosition;
1863 mozilla::TimeDuration mDuration;
1864 nsCOMPtr<nsIObserver> mObserver;
1865 mozilla::TimeStamp mStamp;
1868 static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure);
1870 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboardContentProcess();
1871 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboardInner();
1873 mozilla::UniquePtr<LongTapInfo> mLongTapTouchPoint;
1874 nsCOMPtr<nsITimer> mLongTapTimer;
1875 static int32_t sPointerIdCounter;
1877 public:
1879 * If key events have not been handled by content or XBL handlers, they can
1880 * be offered to the system (for custom application shortcuts set in system
1881 * preferences, for example).
1883 virtual void PostHandleKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
1886 * Activates a native menu item at the position specified by the index
1887 * string. The index string is a string of positive integers separated
1888 * by the "|" (pipe) character. The last integer in the string represents
1889 * the item index in a submenu located using the integers preceding it.
1891 * Example: 1|0|4
1892 * In this string, the first integer represents the top-level submenu
1893 * in the native menu bar. Since the integer is 1, it is the second submeu
1894 * in the native menu bar. Within that, the first item (index 0) is a
1895 * submenu, and we want to activate the 5th item within that submenu.
1897 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1900 * This is used for native menu system testing.
1902 * Updates a native menu at the position specified by the index string.
1903 * The index string is a string of positive integers separated by the "|"
1904 * (pipe) character.
1906 * Example: 1|0|4
1907 * In this string, the first integer represents the top-level submenu
1908 * in the native menu bar. Since the integer is 1, it is the second submeu
1909 * in the native menu bar. Within that, the first item (index 0) is a
1910 * submenu, and we want to update submenu at index 4 within that submenu.
1912 * If this is called with an empty string it forces a full reload of the
1913 * menu system.
1915 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1918 * This is used for testing macOS service menu code.
1920 * @param aResult - the current text selection. Is empty if no selection.
1921 * @return nsresult - whether or not aResult was assigned the selected text.
1923 [[nodiscard]] virtual nsresult GetSelectionAsPlaintext(nsAString& aResult) {
1924 return NS_ERROR_NOT_IMPLEMENTED;
1928 * Notify IME of the specified notification.
1930 * @return If the notification is mouse button event and it's consumed by
1931 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1933 virtual nsresult NotifyIME(const IMENotification& aIMENotification) = 0;
1936 * MaybeDispatchInitialFocusEvent will dispatch a focus event after creation
1937 * of the widget, in the event that we were not able to observe and respond to
1938 * the initial focus event. This is necessary for the early skeleton UI
1939 * window, which is displayed and receives its initial focus event before we
1940 * can actually respond to it.
1942 virtual void MaybeDispatchInitialFocusEvent() {}
1945 * Notifies the input context changes.
1947 virtual void SetInputContext(const InputContext& aContext,
1948 const InputContextAction& aAction) = 0;
1951 * Get current input context.
1953 virtual InputContext GetInputContext() = 0;
1956 * Get native IME context. This is different from GetNativeData() with
1957 * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
1958 * process.
1960 virtual NativeIMEContext GetNativeIMEContext() = 0;
1963 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1964 * native (OS-level) event for it. This method allows tests to simulate
1965 * keystrokes that trigger native key bindings (which require a native
1966 * event).
1968 [[nodiscard]] virtual nsresult AttachNativeKeyEvent(
1969 mozilla::WidgetKeyboardEvent& aEvent) = 0;
1972 * Retrieve edit commands when the key combination of aEvent is used
1973 * in platform native applications.
1975 enum NativeKeyBindingsType : uint8_t {
1976 NativeKeyBindingsForSingleLineEditor,
1977 NativeKeyBindingsForMultiLineEditor,
1978 NativeKeyBindingsForRichTextEditor
1980 MOZ_CAN_RUN_SCRIPT virtual bool GetEditCommands(
1981 NativeKeyBindingsType aType, const mozilla::WidgetKeyboardEvent& aEvent,
1982 nsTArray<mozilla::CommandInt>& aCommands);
1985 * Retrieves a reference to notification requests of IME. Note that the
1986 * reference is valid while the nsIWidget instance is alive. So, if you
1987 * need to store the reference for a long time, you need to grab the widget
1988 * instance too.
1990 const IMENotificationRequests& IMENotificationRequestsRef();
1993 * Call this method when a dialog is opened which has a default button.
1994 * The button's rectangle should be supplied in aButtonRect.
1996 [[nodiscard]] virtual nsresult OnDefaultButtonLoaded(
1997 const LayoutDeviceIntRect& aButtonRect) = 0;
2000 * Return true if this process shouldn't use platform widgets, and
2001 * so should use PuppetWidgets instead. If this returns true, the
2002 * result of creating and using a platform widget is undefined,
2003 * and likely to end in crashes or other buggy behavior.
2005 static bool UsePuppetWidgets() { return XRE_IsContentProcess(); }
2007 static already_AddRefed<nsIWidget> CreateTopLevelWindow();
2009 static already_AddRefed<nsIWidget> CreateChildWindow();
2012 * Allocate and return a "puppet widget" that doesn't directly
2013 * correlate to a platform widget; platform events and data must
2014 * be fed to it. Currently used in content processes. NULL is
2015 * returned if puppet widgets aren't supported in this build
2016 * config, on this platform, or for this process type.
2018 * This function is called "Create" to match CreateInstance().
2019 * The returned widget must still be nsIWidget::Create()d.
2021 static already_AddRefed<nsIWidget> CreatePuppetWidget(
2022 BrowserChild* aBrowserChild);
2024 static already_AddRefed<nsIWidget> CreateHeadlessWidget();
2027 * Reparent this widget's native widget.
2028 * @param aNewParent the native widget of aNewParent is the new native
2029 * parent widget
2031 virtual void ReparentNativeWidget(nsIWidget* aNewParent) = 0;
2034 * Return true if widget has it's own GL context
2036 virtual bool HasGLContext() { return false; }
2039 * Returns true to indicate that this widget paints an opaque background
2040 * that we want to be visible under the page, so layout should not force
2041 * a default background.
2043 virtual bool WidgetPaintsBackground() { return false; }
2045 virtual bool NeedsPaint() { return IsVisible() && !GetBounds().IsEmpty(); }
2048 * Get the natural bounds of this widget. This method is only
2049 * meaningful for widgets for which Gecko implements screen
2050 * rotation natively. When this is the case, GetBounds() returns
2051 * the widget bounds taking rotation into account, and
2052 * GetNaturalBounds() returns the bounds *not* taking rotation
2053 * into account.
2055 * No code outside of the composition pipeline should know or care
2056 * about this. If you're not an agent of the compositor, you
2057 * probably shouldn't call this method.
2059 virtual LayoutDeviceIntRect GetNaturalBounds() { return GetBounds(); }
2062 * Set size constraints on the window size such that it is never less than
2063 * the specified minimum size and never larger than the specified maximum
2064 * size. The size constraints are sizes of the outer rectangle including
2065 * the window frame and title bar. Use 0 for an unconstrained minimum size
2066 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
2067 * does not necessarily change the size of a window to conform to this size,
2068 * thus Resize should be called afterwards.
2070 * @param aConstraints: the size constraints in device pixels
2072 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
2075 * Return the size constraints currently observed by the widget.
2077 * @return the constraints in device pixels
2079 virtual const SizeConstraints GetSizeConstraints() = 0;
2082 * If this is owned by a BrowserChild, return that. Otherwise return
2083 * null.
2085 virtual BrowserChild* GetOwningBrowserChild() { return nullptr; }
2088 * If this isn't directly compositing to its window surface,
2089 * return the compositor which is doing that on our behalf.
2091 virtual CompositorBridgeChild* GetRemoteRenderer() { return nullptr; }
2094 * Clear WebRender resources
2096 virtual void ClearCachedWebrenderResources() {}
2099 * If this widget has its own vsync source, return it, otherwise return
2100 * nullptr. An example of such local source would be Wayland frame callbacks.
2102 virtual RefPtr<mozilla::gfx::VsyncSource> GetVsyncSource() { return nullptr; }
2105 * Returns true if the widget requires synchronous repaints on resize,
2106 * false otherwise.
2108 virtual bool SynchronouslyRepaintOnResize() { return true; }
2111 * Some platforms (only cocoa right now) round widget coordinates to the
2112 * nearest even pixels (see bug 892994), this function allows us to
2113 * determine how widget coordinates will be rounded.
2115 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
2117 virtual void UpdateZoomConstraints(
2118 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
2119 const mozilla::Maybe<ZoomConstraints>& aConstraints){};
2122 * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
2123 * widget. Note that this never returns nullptr.
2125 virtual TextEventDispatcher* GetTextEventDispatcher() = 0;
2128 * GetNativeTextEventDispatcherListener() returns a
2129 * TextEventDispatcherListener instance which is used when the widget
2130 * instance handles native IME and/or keyboard events.
2132 virtual TextEventDispatcherListener*
2133 GetNativeTextEventDispatcherListener() = 0;
2135 virtual void ZoomToRect(const uint32_t& aPresShellId,
2136 const ScrollableLayerGuid::ViewID& aViewId,
2137 const CSSRect& aRect, const uint32_t& aFlags) = 0;
2140 * LookUpDictionary shows the dictionary for the word around current point.
2142 * @param aText the word to look up dictiorary.
2143 * @param aFontRangeArray text decoration of aText
2144 * @param aIsVertical true if the word is vertical layout
2145 * @param aPoint top-left point of aText
2147 virtual void LookUpDictionary(
2148 const nsAString& aText,
2149 const nsTArray<mozilla::FontRange>& aFontRangeArray,
2150 const bool aIsVertical, const LayoutDeviceIntPoint& aPoint) {}
2152 virtual void RequestFxrOutput() {
2153 MOZ_ASSERT(false, "This function should only execute in Windows");
2156 #if defined(MOZ_WIDGET_ANDROID)
2158 * RecvToolbarAnimatorMessageFromCompositor receive message from compositor
2159 * thread.
2161 * @param aMessage message being sent to Android UI thread.
2163 virtual void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage) = 0;
2166 * UpdateRootFrameMetrics steady state frame metrics send from compositor
2167 * thread
2169 * @param aScrollOffset page scroll offset value in screen pixels.
2170 * @param aZoom current page zoom.
2172 virtual void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
2173 const CSSToScreenScale& aZoom) = 0;
2176 * RecvScreenPixels Buffer containing the pixel from the frame buffer. Used
2177 * for android robocop tests.
2179 * @param aMem shared memory containing the frame buffer pixels.
2180 * @param aSize size of the buffer in screen pixels.
2182 virtual void RecvScreenPixels(mozilla::ipc::Shmem&& aMem,
2183 const ScreenIntSize& aSize,
2184 bool aNeedsYFlip) = 0;
2186 virtual void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight) {}
2187 virtual mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const {
2188 return 0;
2190 #endif
2192 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboard();
2195 * Like GetDefaultScale, but taking into account only the system settings
2196 * and ignoring Gecko preferences.
2198 virtual double GetDefaultScaleInternal() { return 1.0; }
2200 protected:
2201 // keep the list of children. We also keep track of our siblings.
2202 // The ownership model is as follows: parent holds a strong ref to
2203 // the first element of the list, and each element holds a strong
2204 // ref to the next element in the list. The prevsibling and
2205 // lastchild pointers are weak, which is fine as long as they are
2206 // maintained properly.
2207 nsCOMPtr<nsIWidget> mFirstChild;
2208 nsIWidget* MOZ_NON_OWNING_REF mLastChild;
2209 nsCOMPtr<nsIWidget> mNextSibling;
2210 nsIWidget* MOZ_NON_OWNING_REF mPrevSibling;
2211 // When Destroy() is called, the sub class should set this true.
2212 bool mOnDestroyCalled;
2213 nsWindowType mWindowType;
2214 int32_t mZIndex;
2217 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
2219 #endif // nsIWidget_h__