Bug 1684463 - [devtools] Part 1: Shorten the _createAttribute function by refactoring...
[gecko.git] / widget / nsIWidget.h
blob54358da41c0eb0eacfbc123032e6764a5e40b87d
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/dom/BindingDeclarations.h"
22 #include "mozilla/gfx/Matrix.h"
23 #include "mozilla/gfx/Rect.h"
24 #include "mozilla/layers/LayersTypes.h"
25 #include "mozilla/layers/ScrollableLayerGuid.h"
26 #include "mozilla/layers/ZoomConstraints.h"
27 #include "mozilla/widget/IMEData.h"
28 #include "nsCOMPtr.h"
29 #include "nsColor.h"
30 #include "nsDataHashtable.h"
31 #include "nsDebug.h"
32 #include "nsID.h"
33 #include "nsIObserver.h"
34 #include "nsISupports.h"
35 #include "nsITheme.h"
36 #include "nsITimer.h"
37 #include "nsIWidgetListener.h"
38 #include "nsRect.h"
39 #include "nsSize.h"
40 #include "nsStringFwd.h"
41 #include "nsTArray.h"
42 #include "nsWidgetInitData.h"
43 #include "nsXULAppAPI.h"
45 #ifdef MOZ_IS_GCC
46 # include "VsyncSource.h"
47 #endif
49 // forward declarations
50 class nsIBidiKeyboard;
51 class nsIRollupListener;
52 class imgIContainer;
53 class nsIContent;
54 class ViewWrapper;
55 class nsIScreen;
56 class nsIRunnable;
57 class nsIKeyEventInPluginCallback;
58 class nsUint64HashKey;
60 namespace mozilla {
61 class NativeEventData;
62 class WidgetGUIEvent;
63 class WidgetInputEvent;
64 class WidgetKeyboardEvent;
65 struct FontRange;
67 enum class StyleWindowShadow : uint8_t;
69 #if defined(MOZ_WIDGET_ANDROID)
70 namespace ipc {
71 class Shmem;
73 #endif // defined(MOZ_WIDGET_ANDROID)
74 namespace dom {
75 class BrowserChild;
76 } // namespace dom
77 namespace plugins {
78 class PluginWidgetChild;
79 } // namespace plugins
80 namespace layers {
81 class AsyncDragMetrics;
82 class Compositor;
83 class CompositorBridgeChild;
84 struct FrameMetrics;
85 class LayerManager;
86 class LayerManagerComposite;
87 class PLayerTransactionChild;
88 class WebRenderBridgeChild;
89 } // namespace layers
90 namespace gfx {
91 class VsyncSource;
92 } // namespace gfx
93 namespace widget {
94 class TextEventDispatcher;
95 class TextEventDispatcherListener;
96 class CompositorWidget;
97 class CompositorWidgetInitData;
98 } // namespace widget
99 namespace wr {
100 class DisplayListBuilder;
101 class IpcResourceUpdateQueue;
102 enum class RenderRoot : uint8_t;
103 } // namespace wr
104 } // namespace mozilla
107 * Callback function that processes events.
109 * The argument is actually a subtype (subclass) of WidgetEvent which carries
110 * platform specific information about the event. Platform specific code
111 * knows how to deal with it.
113 * The return value determines whether or not the default action should take
114 * place.
116 typedef nsEventStatus (*EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent);
118 // Hide the native window system's real window type so as to avoid
119 // including native window system types and APIs. This is necessary
120 // to ensure cross-platform code.
121 typedef void* nsNativeWidget;
124 * Flags for the GetNativeData and SetNativeData functions
126 #define NS_NATIVE_WINDOW 0
127 #define NS_NATIVE_GRAPHIC 1
128 #define NS_NATIVE_TMP_WINDOW 2
129 #define NS_NATIVE_WIDGET 3
130 #define NS_NATIVE_DISPLAY 4
131 #define NS_NATIVE_REGION 5
132 #define NS_NATIVE_OFFSETX 6
133 #define NS_NATIVE_OFFSETY 7
134 #define NS_NATIVE_PLUGIN_PORT 8
135 #define NS_NATIVE_SCREEN 9
136 // The toplevel GtkWidget containing this nsIWidget:
137 #define NS_NATIVE_SHELLWIDGET 10
138 // Has to match to NPNVnetscapeWindow, and shareable across processes
139 // HWND on Windows and XID on X11
140 #define NS_NATIVE_SHAREABLE_WINDOW 11
141 #define NS_NATIVE_OPENGL_CONTEXT 12
142 // See RegisterPluginWindowForRemoteUpdates
143 #define NS_NATIVE_PLUGIN_ID 13
144 // This is available only with GetNativeData() in parent process. Anybody
145 // shouldn't access this pointer as a valid pointer since the result may be
146 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
147 // an identifier of distinguishing a text composition is caused by which native
148 // IME context. Note that the result is only valid in the process. So,
149 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
150 #define NS_RAW_NATIVE_IME_CONTEXT 14
151 #define NS_NATIVE_WINDOW_WEBRTC_DEVICE_ID 15
152 #ifdef XP_MACOSX
153 # define NS_NATIVE_PLUGIN_PORT_QD 100
154 # define NS_NATIVE_PLUGIN_PORT_CG 101
155 #endif
156 #ifdef XP_WIN
157 # define NS_NATIVE_TSF_THREAD_MGR 100
158 # define NS_NATIVE_TSF_CATEGORY_MGR 101
159 # define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
160 # define NS_NATIVE_ICOREWINDOW 103 // winrt specific
161 # define NS_NATIVE_CHILD_WINDOW 104
162 # define NS_NATIVE_CHILD_OF_SHAREABLE_WINDOW 105
163 #endif
164 #if defined(MOZ_WIDGET_GTK)
165 // set/get nsPluginNativeWindowGtk, e10s specific
166 # define NS_NATIVE_PLUGIN_OBJECT_PTR 104
167 # define NS_NATIVE_EGL_WINDOW 106
168 #endif
169 #ifdef MOZ_WIDGET_ANDROID
170 # define NS_JAVA_SURFACE 100
171 # define NS_PRESENTATION_WINDOW 101
172 # define NS_PRESENTATION_SURFACE 102
173 #endif
175 #define MOZ_WIDGET_MAX_SIZE 16384
177 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
178 #define NS_IWIDGET_IID \
180 0x06396bf6, 0x2dd8, 0x45e5, { \
181 0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80 \
186 * Transparency modes
189 enum nsTransparencyMode {
190 eTransparencyOpaque = 0, // Fully opaque
191 eTransparencyTransparent, // Parts of the window may be transparent
192 eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass
193 // effect applied
194 eTransparencyBorderlessGlass // As above, but without a border around the
195 // opaque areas when there would otherwise be
196 // one with eTransparencyGlass
197 // If you add to the end here, you must update the serialization code in
198 // WidgetMessageUtils.h
202 * Cursor types.
205 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
206 eCursor_standard,
207 ///(system is busy, usually rendered as a hourglass or watch)
208 eCursor_wait,
209 ///(Selecting something, usually rendered as an IBeam)
210 eCursor_select,
211 ///(can hyper-link, usually rendered as a human hand)
212 eCursor_hyperlink,
213 ///(north/south/west/east edge sizing)
214 eCursor_n_resize,
215 eCursor_s_resize,
216 eCursor_w_resize,
217 eCursor_e_resize,
218 ///(corner sizing)
219 eCursor_nw_resize,
220 eCursor_se_resize,
221 eCursor_ne_resize,
222 eCursor_sw_resize,
223 eCursor_crosshair,
224 eCursor_move,
225 eCursor_help,
226 eCursor_copy, // CSS3
227 eCursor_alias,
228 eCursor_context_menu,
229 eCursor_cell,
230 eCursor_grab,
231 eCursor_grabbing,
232 eCursor_spinning,
233 eCursor_zoom_in,
234 eCursor_zoom_out,
235 eCursor_not_allowed,
236 eCursor_col_resize,
237 eCursor_row_resize,
238 eCursor_no_drop,
239 eCursor_vertical_text,
240 eCursor_all_scroll,
241 eCursor_nesw_resize,
242 eCursor_nwse_resize,
243 eCursor_ns_resize,
244 eCursor_ew_resize,
245 eCursor_none,
246 // This one is used for array sizing, and so better be the last
247 // one in this list...
248 eCursorCount,
250 // ...except for this one.
251 eCursorInvalid = eCursorCount + 1
254 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
255 eZPlacementBottom = 0, // bottom of the window stack
256 eZPlacementBelow, // just below another widget
257 eZPlacementTop // top of the window stack
261 * Before the OS goes to sleep, this topic is notified.
263 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
266 * After the OS wakes up, this topic is notified.
268 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
271 * Before the OS suspends the current process, this topic is notified. Some
272 * OS will kill processes that are suspended instead of resuming them.
273 * For that reason this topic may be useful to safely close down resources.
275 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
278 * After the current process resumes from being suspended, this topic is
279 * notified.
281 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
284 * When an app(-shell) is activated by the OS, this topic is notified.
285 * Currently, this only happens on Mac OSX.
287 #define NS_WIDGET_MAC_APP_ACTIVATE_OBSERVER_TOPIC "mac_app_activate"
289 namespace mozilla {
290 namespace widget {
293 * Size constraints for setting the minimum and maximum size of a widget.
294 * Values are in device pixels.
296 struct SizeConstraints {
297 SizeConstraints() : mMaxSize(MOZ_WIDGET_MAX_SIZE, MOZ_WIDGET_MAX_SIZE) {}
299 SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize,
300 mozilla::LayoutDeviceIntSize aMaxSize)
301 : mMinSize(aMinSize), mMaxSize(aMaxSize) {
302 if (mMaxSize.width > MOZ_WIDGET_MAX_SIZE) {
303 mMaxSize.width = MOZ_WIDGET_MAX_SIZE;
305 if (mMaxSize.height > MOZ_WIDGET_MAX_SIZE) {
306 mMaxSize.height = MOZ_WIDGET_MAX_SIZE;
310 mozilla::LayoutDeviceIntSize mMinSize;
311 mozilla::LayoutDeviceIntSize mMaxSize;
314 struct AutoObserverNotifier {
315 AutoObserverNotifier(nsIObserver* aObserver, const char* aTopic)
316 : mObserver(aObserver), mTopic(aTopic) {}
318 void SkipNotification() { mObserver = nullptr; }
320 uint64_t SaveObserver() {
321 if (!mObserver) {
322 return 0;
324 uint64_t observerId = ++sObserverId;
325 sSavedObservers.Put(observerId, mObserver);
326 SkipNotification();
327 return observerId;
330 ~AutoObserverNotifier() {
331 if (mObserver) {
332 mObserver->Observe(nullptr, mTopic, nullptr);
336 static void NotifySavedObserver(const uint64_t& aObserverId,
337 const char* aTopic) {
338 nsCOMPtr<nsIObserver> observer = sSavedObservers.Get(aObserverId);
339 if (!observer) {
340 MOZ_ASSERT(aObserverId == 0,
341 "We should always find a saved observer for nonzero IDs");
342 return;
345 sSavedObservers.Remove(aObserverId);
346 observer->Observe(nullptr, aTopic, nullptr);
349 private:
350 nsCOMPtr<nsIObserver> mObserver;
351 const char* mTopic;
353 private:
354 static uint64_t sObserverId;
355 static nsDataHashtable<nsUint64HashKey, nsCOMPtr<nsIObserver>>
356 sSavedObservers;
359 } // namespace widget
360 } // namespace mozilla
363 * The base class for all the widgets. It provides the interface for
364 * all basic and necessary functionality.
366 class nsIWidget : public nsISupports {
367 protected:
368 typedef mozilla::dom::BrowserChild BrowserChild;
370 public:
371 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
372 typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics;
373 typedef mozilla::layers::FrameMetrics FrameMetrics;
374 typedef mozilla::layers::LayerManager LayerManager;
375 typedef mozilla::layers::LayerManagerComposite LayerManagerComposite;
376 typedef mozilla::layers::LayersBackend LayersBackend;
377 typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild;
378 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
379 typedef mozilla::layers::ZoomConstraints ZoomConstraints;
380 typedef mozilla::widget::IMEEnabled IMEEnabled;
381 typedef mozilla::widget::IMEMessage IMEMessage;
382 typedef mozilla::widget::IMENotification IMENotification;
383 typedef mozilla::widget::IMENotificationRequests IMENotificationRequests;
384 typedef mozilla::widget::IMEState IMEState;
385 typedef mozilla::widget::InputContext InputContext;
386 typedef mozilla::widget::InputContextAction InputContextAction;
387 typedef mozilla::widget::NativeIMEContext NativeIMEContext;
388 typedef mozilla::widget::SizeConstraints SizeConstraints;
389 typedef mozilla::widget::TextEventDispatcher TextEventDispatcher;
390 typedef mozilla::widget::TextEventDispatcherListener
391 TextEventDispatcherListener;
392 typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin;
393 typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
394 typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
395 typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
396 typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
397 typedef mozilla::ScreenIntPoint ScreenIntPoint;
398 typedef mozilla::ScreenIntMargin ScreenIntMargin;
399 typedef mozilla::ScreenIntSize ScreenIntSize;
400 typedef mozilla::ScreenPoint ScreenPoint;
401 typedef mozilla::CSSToScreenScale CSSToScreenScale;
402 typedef mozilla::DesktopIntRect DesktopIntRect;
403 typedef mozilla::DesktopPoint DesktopPoint;
404 typedef mozilla::DesktopRect DesktopRect;
405 typedef mozilla::DesktopSize DesktopSize;
406 typedef mozilla::CSSPoint CSSPoint;
407 typedef mozilla::CSSRect CSSRect;
409 // Used in UpdateThemeGeometries.
410 struct ThemeGeometry {
411 // The ThemeGeometryType value for the themed widget, see
412 // nsITheme::ThemeGeometryTypeForWidget.
413 nsITheme::ThemeGeometryType mType;
414 // The device-pixel rect within the window for the themed widget
415 LayoutDeviceIntRect mRect;
417 ThemeGeometry(nsITheme::ThemeGeometryType aType,
418 const LayoutDeviceIntRect& aRect)
419 : mType(aType), mRect(aRect) {}
422 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
424 nsIWidget()
425 : mLastChild(nullptr),
426 mPrevSibling(nullptr),
427 mOnDestroyCalled(false),
428 mWindowType(eWindowType_child),
429 mZIndex(0)
432 ClearNativeTouchSequence(nullptr);
436 * Create and initialize a widget.
438 * All the arguments can be null in which case a top level window
439 * with size 0 is created. The event callback function has to be
440 * provided only if the caller wants to deal with the events this
441 * widget receives. The event callback is basically a preprocess
442 * hook called synchronously. The return value determines whether
443 * the event goes to the default window procedure or it is hidden
444 * to the os. The assumption is that if the event handler returns
445 * false the widget does not see the event. The widget should not
446 * automatically clear the window to the background color. The
447 * calling code must handle paint messages and clear the background
448 * itself.
450 * In practice at least one of aParent and aNativeParent will be null. If
451 * both are null the widget isn't parented (e.g. context menus or
452 * independent top level windows).
454 * The dimensions given in aRect are specified in the parent's
455 * device coordinate system.
456 * This must not be called for parentless widgets such as top-level
457 * windows, which use the desktop pixel coordinate system; a separate
458 * method is provided for these.
460 * @param aParent parent nsIWidget
461 * @param aNativeParent native parent widget
462 * @param aRect the widget dimension
463 * @param aInitData data that is used for widget initialization
466 [[nodiscard]] virtual nsresult Create(
467 nsIWidget* aParent, nsNativeWidget aNativeParent,
468 const LayoutDeviceIntRect& aRect,
469 nsWidgetInitData* aInitData = nullptr) = 0;
472 * As above, but with aRect specified in DesktopPixel units (for top-level
473 * widgets).
474 * Default implementation just converts aRect to device pixels and calls
475 * through to device-pixel Create, but platforms may override this if the
476 * mapping is not straightforward or the native platform needs to use the
477 * desktop pixel values directly.
479 [[nodiscard]] virtual nsresult Create(nsIWidget* aParent,
480 nsNativeWidget aNativeParent,
481 const DesktopIntRect& aRect,
482 nsWidgetInitData* aInitData = nullptr) {
483 LayoutDeviceIntRect devPixRect =
484 RoundedToInt(aRect * GetDesktopToDeviceScale());
485 return Create(aParent, aNativeParent, devPixRect, aInitData);
489 * Allocate, initialize, and return a widget that is a child of
490 * |this|. The returned widget (if nonnull) has gone through the
491 * equivalent of CreateInstance(widgetCID) + Create(...).
493 * |CreateChild()| lets widget backends decide whether to parent
494 * the new child widget to this, nonnatively parent it, or both.
495 * This interface exists to support the PuppetWidget backend,
496 * which is entirely non-native. All other params are the same as
497 * for |Create()|.
499 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
500 * |nsIWidget*| this, not its native widget (if it exists), when
501 * calling |Create()|. This is a timid hack around poorly
502 * understood code, and shouldn't be used in new code.
504 virtual already_AddRefed<nsIWidget> CreateChild(
505 const LayoutDeviceIntRect& aRect, nsWidgetInitData* aInitData = nullptr,
506 bool aForceUseIWidgetParent = false) = 0;
509 * Attach to a top level widget.
511 * In cases where a top level chrome widget is being used as a content
512 * container, attach a secondary listener and update the device
513 * context. The primary widget listener will continue to be called for
514 * notifications relating to the top-level window, whereas other
515 * notifications such as painting and events will instead be called via
516 * the attached listener. SetAttachedWidgetListener should be used to
517 * assign the attached listener.
519 * aUseAttachedEvents if true, events are sent to the attached listener
520 * instead of the normal listener.
522 virtual void AttachViewToTopLevel(bool aUseAttachedEvents) = 0;
525 * Accessor functions to get and set the attached listener. Used by
526 * nsView in connection with AttachViewToTopLevel above.
528 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
529 virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
530 virtual void SetPreviouslyAttachedWidgetListener(
531 nsIWidgetListener* aListener) = 0;
532 virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() = 0;
535 * Accessor functions to get and set the listener which handles various
536 * actions for the widget.
538 //@{
539 virtual nsIWidgetListener* GetWidgetListener() = 0;
540 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
541 //@}
544 * Close and destroy the internal native window.
545 * This method does not delete the widget.
548 virtual void Destroy() = 0;
551 * Destroyed() returns true if Destroy() has been called already.
552 * Otherwise, false.
554 bool Destroyed() const { return mOnDestroyCalled; }
557 * Reparent a widget
559 * Change the widget's parent. Null parents are allowed.
561 * @param aNewParent new parent
563 virtual void SetParent(nsIWidget* aNewParent) = 0;
566 * Return the parent Widget of this Widget or nullptr if this is a
567 * top level window
569 * @return the parent widget or nullptr if it does not have a parent
572 virtual nsIWidget* GetParent(void) = 0;
575 * Return the top level Widget of this Widget
577 * @return the top level widget
579 virtual nsIWidget* GetTopLevelWidget() = 0;
582 * Return the top (non-sheet) parent of this Widget if it's a sheet,
583 * or nullptr if this isn't a sheet (or some other error occurred).
584 * Sheets are only supported on some platforms (currently only OS X).
586 * @return the top (non-sheet) parent widget or nullptr
589 virtual nsIWidget* GetSheetWindowParent(void) = 0;
592 * Return the physical DPI of the screen containing the window ...
593 * the number of device pixels per inch.
595 virtual float GetDPI() = 0;
598 * Return the scaling factor between device pixels and the platform-
599 * dependent "desktop pixels" used to manage window positions on a
600 * potentially multi-screen, mixed-resolution desktop.
602 virtual mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() = 0;
605 * Return the scaling factor between device pixels and the platform-
606 * dependent "desktop pixels" by looking up the screen by the position
607 * of the widget.
609 virtual mozilla::DesktopToLayoutDeviceScale
610 GetDesktopToDeviceScaleByScreen() = 0;
613 * Return the default scale factor for the window. This is the
614 * default number of device pixels per CSS pixel to use. This should
615 * depend on OS/platform settings such as the Mac's "UI scale factor"
616 * or Windows' "font DPI". This will take into account Gecko preferences
617 * overriding the system setting.
619 mozilla::CSSToLayoutDeviceScale GetDefaultScale();
622 * Return the first child of this widget. Will return null if
623 * there are no children.
625 nsIWidget* GetFirstChild() const { return mFirstChild; }
628 * Return the last child of this widget. Will return null if
629 * there are no children.
631 nsIWidget* GetLastChild() const { return mLastChild; }
634 * Return the next sibling of this widget
636 nsIWidget* GetNextSibling() const { return mNextSibling; }
639 * Set the next sibling of this widget
641 void SetNextSibling(nsIWidget* aSibling) { mNextSibling = aSibling; }
644 * Return the previous sibling of this widget
646 nsIWidget* GetPrevSibling() const { return mPrevSibling; }
649 * Set the previous sibling of this widget
651 void SetPrevSibling(nsIWidget* aSibling) { mPrevSibling = aSibling; }
654 * Show or hide this widget
656 * @param aState true to show the Widget, false to hide it
659 virtual void Show(bool aState) = 0;
662 * Whether or not a widget must be recreated after being hidden to show
663 * again properly.
665 virtual bool NeedsRecreateToReshow() { return false; }
668 * Make the window modal.
670 virtual void SetModal(bool aModal) = 0;
673 * Make the non-modal window opened by modal window fake-modal, that will
674 * call SetFakeModal(false) on destroy on Cocoa.
676 virtual void SetFakeModal(bool aModal) { SetModal(aModal); }
679 * Are we app modal. Currently only implemented on Cocoa.
681 virtual bool IsRunningAppModal() { return false; }
684 * The maximum number of simultaneous touch contacts supported by the device.
685 * In the case of devices with multiple digitizers (e.g. multiple touch
686 * screens), the value will be the maximum of the set of maximum supported
687 * contacts by each individual digitizer.
689 virtual uint32_t GetMaxTouchPoints() const = 0;
692 * Returns whether the window is visible
695 virtual bool IsVisible() const = 0;
698 * Perform platform-dependent sanity check on a potential window position.
699 * This is guaranteed to work only for top-level windows.
701 * @param aAllowSlop: if true, allow the window to slop offscreen;
702 * the window should be partially visible. if false,
703 * force the entire window onscreen (or at least
704 * the upper-left corner, if it's too large).
705 * @param aX in: an x position expressed in screen coordinates.
706 * out: the x position constrained to fit on the screen(s).
707 * @param aY in: an y position expressed in screen coordinates.
708 * out: the y position constrained to fit on the screen(s).
711 virtual void ConstrainPosition(bool aAllowSlop, int32_t* aX, int32_t* aY) = 0;
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 * Mac OS X with Hi-DPI (retina) displays, and Windows when the UI scale
724 * factor 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(LayoutDeviceIntMargin& aMargins) = 0;
951 * Get the client offset from the window origin.
953 * @return the x and y of the offset.
955 virtual LayoutDeviceIntPoint GetClientOffset() = 0;
958 * Equivalent to GetClientBounds but only returns the size.
960 virtual LayoutDeviceIntSize GetClientSize() {
961 // Depending on the backend, overloading this method may be useful if
962 // requesting the client offset is expensive.
963 return GetClientBounds().Size();
967 * Set the background color for this widget
969 * @param aColor the new background color
973 virtual void SetBackgroundColor(const nscolor& aColor) {}
976 * If a cursor type is currently cached locally for this widget, clear the
977 * cached cursor to force an update on the next SetCursor call.
980 virtual void ClearCachedCursor() = 0;
983 * Sets the cursor cursor for this widget.
985 * @param aDefaultCursor the default cursor to be set
986 * @param aCursorImage a custom cursor, maybe null.
987 * @param aX the X coordinate of the hotspot for aCursorImage (from left).
988 * @param aY the Y coordinate of the hotspot for aCursorImage (from top).
990 virtual void SetCursor(nsCursor aDefaultCursor, imgIContainer* aCursorImage,
991 uint32_t aHotspotX, uint32_t aHotspotY) = 0;
994 * Get the window type of this widget.
996 nsWindowType WindowType() { return mWindowType; }
999 * Determines if this widget is one of the three types of plugin widgets.
1001 bool IsPlugin() {
1002 return mWindowType == eWindowType_plugin ||
1003 mWindowType == eWindowType_plugin_ipc_chrome ||
1004 mWindowType == eWindowType_plugin_ipc_content;
1008 * Set the transparency mode of the top-level window containing this widget.
1009 * So, e.g., if you call this on the widget for an IFRAME, the top level
1010 * browser window containing the IFRAME actually gets set. Be careful.
1012 * This can fail if the platform doesn't support
1013 * transparency/glass. By default widgets are not
1014 * transparent. This will also fail if the toplevel window is not
1015 * a Mozilla window, e.g., if the widget is in an embedded
1016 * context.
1018 * After transparency/glass has been enabled, the initial alpha channel
1019 * value for all pixels is 1, i.e., opaque.
1020 * If the window is resized then the alpha channel values for
1021 * all pixels are reset to 1.
1022 * Pixel RGB color values are already premultiplied with alpha channel values.
1024 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
1027 * Get the transparency mode of the top-level window that contains this
1028 * widget.
1030 virtual nsTransparencyMode GetTransparencyMode() = 0;
1033 * This represents a command to set the bounds and clip region of
1034 * a child widget.
1036 struct Configuration {
1037 nsCOMPtr<nsIWidget> mChild;
1038 uintptr_t mWindowID; // e10s specific, the unique plugin port id
1039 bool mVisible; // e10s specific, widget visibility
1040 LayoutDeviceIntRect mBounds;
1041 CopyableTArray<LayoutDeviceIntRect> mClipRegion;
1045 * Sets the clip region of each mChild (which must actually be a child
1046 * of this widget) to the union of the pixel rects given in
1047 * mClipRegion, all relative to the top-left of the child
1048 * widget. Clip regions are not implemented on all platforms and only
1049 * need to actually work for children that are plugins.
1051 * Also sets the bounds of each child to mBounds.
1053 * This will invalidate areas of the children that have changed, but
1054 * does not need to invalidate any part of this widget.
1056 * Children should be moved in the order given; the array is
1057 * sorted so to minimize unnecessary invalidation if children are
1058 * moved in that order.
1060 virtual nsresult ConfigureChildren(
1061 const nsTArray<Configuration>& aConfigurations) = 0;
1062 virtual nsresult SetWindowClipRegion(
1063 const nsTArray<LayoutDeviceIntRect>& aRects,
1064 bool aIntersectWithExisting) = 0;
1067 * Appends to aRects the rectangles constituting this widget's clip
1068 * region. If this widget is not clipped, appends a single rectangle
1069 * (0, 0, bounds.width, bounds.height).
1071 virtual void GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects) = 0;
1074 * Register or unregister native plugin widgets which receive Configuration
1075 * data from the content process via the compositor.
1077 * Lookups are used by the main thread via the compositor to lookup widgets
1078 * based on a unique window id. On Windows and Linux this is the
1079 * NS_NATIVE_PLUGIN_PORT (hwnd/XID). This tracking maintains a reference to
1080 * widgets held. Consumers are responsible for removing widgets from this
1081 * list.
1083 virtual void RegisterPluginWindowForRemoteUpdates() = 0;
1084 virtual void UnregisterPluginWindowForRemoteUpdates() = 0;
1085 static nsIWidget* LookupRegisteredPluginWindow(uintptr_t aWindowID);
1088 * Iterates across the list of registered plugin widgets and updates thier
1089 * visibility based on which plugins are included in the 'visible' list.
1091 * The compositor knows little about tabs, but it does know which plugin
1092 * widgets are currently included in the visible layer tree. It calls this
1093 * helper to hide widgets it knows nothing about.
1095 static void UpdateRegisteredPluginWindowVisibility(
1096 uintptr_t aOwnerWidget, nsTArray<uintptr_t>& aPluginIds);
1098 #if defined(XP_WIN)
1100 * Iterates over the list of registered plugins and for any that are owned
1101 * by aOwnerWidget and visible it takes a snapshot.
1103 * @param aOwnerWidget only captures visible widgets owned by this
1105 static void CaptureRegisteredPlugins(uintptr_t aOwnerWidget);
1108 * Take a scroll capture for this widget if possible.
1110 virtual void UpdateScrollCapture() = 0;
1113 * Creates an async ImageContainer to hold scroll capture images that can be
1114 * used if the plugin is hidden during scroll.
1115 * @return the async container ID of the created ImageContainer.
1117 virtual uint64_t CreateScrollCaptureContainer() = 0;
1118 #endif
1121 * Set the shadow style of the window.
1123 * Ignored on child widgets and on non-Mac platforms.
1125 virtual void SetWindowShadowStyle(mozilla::StyleWindowShadow aStyle) = 0;
1128 * Set the opacity of the window.
1129 * Values need to be between 0.0f (invisible) and 1.0f (fully opaque).
1131 * Ignored on child widgets and on non-Mac platforms.
1133 virtual void SetWindowOpacity(float aOpacity) {}
1136 * Set the transform of the window. Values are in device pixels,
1137 * the origin is the top left corner of the window.
1139 * Ignored on child widgets and on non-Mac platforms.
1141 virtual void SetWindowTransform(const mozilla::gfx::Matrix& aTransform) {}
1144 * Set whether the window should ignore mouse events or not.
1146 * This is only used on popup windows.
1148 virtual void SetWindowMouseTransparent(bool aIsTransparent) {}
1151 * On Mac OS X, this method shows or hides the pill button in the titlebar
1152 * that's used to collapse the toolbar.
1154 * Ignored on child widgets and on non-Mac platforms.
1156 virtual void SetShowsToolbarButton(bool aShow) = 0;
1159 * On macOS, this method determines whether we tell cocoa that the window
1160 * supports native full screen. If we do so, and another window is in
1161 * native full screen, this window will also appear in native full screen.
1163 * We generally only want to do this for primary application windows.
1165 * Ignored on child widgets and on non-Mac platforms.
1167 virtual void SetSupportsNativeFullscreen(bool aSupportsNativeFullscreen) = 0;
1169 enum WindowAnimationType {
1170 eGenericWindowAnimation,
1171 eDocumentWindowAnimation
1175 * Sets the kind of top-level window animation this widget should have. On
1176 * Mac OS X, this causes a particular kind of animation to be shown when the
1177 * window is first made visible.
1179 * Ignored on child widgets and on non-Mac platforms.
1181 virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
1184 * Specifies whether the window title should be drawn even if the window
1185 * contents extend into the titlebar. Ignored on windows that don't draw
1186 * in the titlebar. Only implemented on OS X.
1188 virtual void SetDrawsTitle(bool aDrawTitle) {}
1191 * Indicates whether the widget should attempt to make titlebar controls
1192 * easier to see on dark titlebar backgrounds.
1194 virtual void SetUseBrightTitlebarForeground(bool aBrightForeground) {}
1197 * Hide window chrome (borders, buttons) for this widget.
1200 virtual void HideWindowChrome(bool aShouldHide) = 0;
1202 enum FullscreenTransitionStage {
1203 eBeforeFullscreenToggle,
1204 eAfterFullscreenToggle
1208 * Prepares for fullscreen transition and returns whether the widget
1209 * supports fullscreen transition. If this method returns false,
1210 * PerformFullscreenTransition() must never be called. Otherwise,
1211 * caller should call that method twice with "before" and "after"
1212 * stages respectively in order. In the latter case, this method may
1213 * return some data via aData pointer. Caller must pass that data to
1214 * PerformFullscreenTransition() if any, and caller is responsible
1215 * for releasing that data.
1217 virtual bool PrepareForFullscreenTransition(nsISupports** aData) = 0;
1220 * Performs fullscreen transition. This method returns immediately,
1221 * and will post aCallback to the main thread when the transition
1222 * finishes.
1224 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
1225 uint16_t aDuration,
1226 nsISupports* aData,
1227 nsIRunnable* aCallback) = 0;
1230 * Perform any actions needed after the fullscreen transition has ended.
1232 virtual void CleanupFullscreenTransition() = 0;
1235 * Return the screen the widget is in, or null if we don't know.
1237 virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
1240 * Put the toplevel window into or out of fullscreen mode.
1241 * If aTargetScreen is given, attempt to go fullscreen on that screen,
1242 * if possible. (If not, it behaves as if aTargetScreen is null.)
1243 * If !aFullScreen, aTargetScreen is ignored.
1244 * aTargetScreen support is currently only implemented on Windows.
1246 * @return NS_OK if the widget is setup properly for fullscreen and
1247 * FullscreenChanged callback has been or will be called. If other
1248 * value is returned, the caller should continue the change itself.
1250 virtual nsresult MakeFullScreen(bool aFullScreen,
1251 nsIScreen* aTargetScreen = nullptr) = 0;
1254 * Same as MakeFullScreen, except that, on systems which natively
1255 * support fullscreen transition, calling this method explicitly
1256 * requests that behavior.
1257 * It is currently only supported on OS X 10.7+.
1259 virtual nsresult MakeFullScreenWithNativeTransition(
1260 bool aFullScreen, nsIScreen* aTargetScreen = nullptr) {
1261 return MakeFullScreen(aFullScreen, aTargetScreen);
1265 * Invalidate a specified rect for a widget so that it will be repainted
1266 * later.
1268 virtual void Invalidate(const LayoutDeviceIntRect& aRect) = 0;
1270 enum LayerManagerPersistence {
1271 LAYER_MANAGER_CURRENT = 0,
1272 LAYER_MANAGER_PERSISTENT
1276 * Return the widget's LayerManager. The layer tree for that
1277 * LayerManager is what gets rendered to the widget.
1279 inline LayerManager* GetLayerManager() {
1280 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1281 LAYER_MANAGER_CURRENT);
1284 inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence) {
1285 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1286 aPersistence);
1290 * Like GetLayerManager(), but prefers creating a layer manager of
1291 * type |aBackendHint| instead of what would normally be created.
1292 * LayersBackend::LAYERS_NONE means "no hint".
1294 virtual LayerManager* GetLayerManager(
1295 PLayerTransactionChild* aShadowManager, LayersBackend aBackendHint,
1296 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) = 0;
1299 * Called before each layer manager transaction to allow any preparation
1300 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1302 * Always called on the main thread.
1304 virtual void PrepareWindowEffects() = 0;
1307 * Called on the main thread at the end of WebRender display list building.
1309 virtual void AddWindowOverlayWebRenderCommands(
1310 mozilla::layers::WebRenderBridgeChild* aWrBridge,
1311 mozilla::wr::DisplayListBuilder& aBuilder,
1312 mozilla::wr::IpcResourceUpdateQueue& aResources) {}
1315 * Called when Gecko knows which themed widgets exist in this window.
1316 * The passed array contains an entry for every themed widget of the right
1317 * type (currently only StyleAppearance::Toolbar) within the window, except
1318 * for themed widgets which are transformed or have effects applied to them
1319 * (e.g. CSS opacity or filters).
1320 * This could sometimes be called during display list construction
1321 * outside of painting.
1322 * If called during painting, it will be called before we actually
1323 * paint anything.
1325 virtual void UpdateThemeGeometries(
1326 const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1329 * Informs the widget about the region of the window that is opaque.
1331 * @param aOpaqueRegion the region of the window that is opaque.
1333 virtual void UpdateOpaqueRegion(const LayoutDeviceIntRegion& aOpaqueRegion) {}
1336 * Informs the widget about the region of the window that is draggable.
1338 virtual void UpdateWindowDraggingRegion(
1339 const LayoutDeviceIntRegion& aRegion) {}
1342 * Tells the widget whether the given input block results in a swipe.
1343 * Should be called in response to a WidgetWheelEvent that has
1344 * mFlags.mCanTriggerSwipe set on it.
1346 virtual void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) {}
1349 * Internal methods
1352 //@{
1353 virtual void AddChild(nsIWidget* aChild) = 0;
1354 virtual void RemoveChild(nsIWidget* aChild) = 0;
1355 virtual void* GetNativeData(uint32_t aDataType) = 0;
1356 virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) = 0;
1357 virtual void FreeNativeData(void* data, uint32_t aDataType) = 0; //~~~
1359 //@}
1362 * Set the widget's title.
1363 * Must be called after Create.
1365 * @param aTitle string displayed as the title of the widget
1367 virtual nsresult SetTitle(const nsAString& aTitle) = 0;
1370 * Set the widget's icon.
1371 * Must be called after Create.
1373 * @param aIconSpec string specifying the icon to use; convention is to
1374 * pass a resource: URL from which a platform-dependent
1375 * resource file name will be constructed
1377 virtual void SetIcon(const nsAString& aIconSpec) = 0;
1380 * Return this widget's origin in screen coordinates.
1382 * @return screen coordinates stored in the x,y members
1384 virtual LayoutDeviceIntPoint WidgetToScreenOffset() = 0;
1387 * The same as WidgetToScreenOffset(), except in the case of
1388 * PuppetWidget where this method omits the chrome offset.
1390 virtual LayoutDeviceIntPoint TopLevelWidgetToScreenOffset() {
1391 return WidgetToScreenOffset();
1395 * For a PuppetWidget, returns the transform from the coordinate
1396 * space of the PuppetWidget to the coordinate space of the
1397 * top-level native widget.
1399 * Identity transform in other cases.
1401 virtual mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
1402 WidgetToTopLevelWidgetTransform() {
1403 return mozilla::LayoutDeviceToLayoutDeviceMatrix4x4();
1407 * Given the specified client size, return the corresponding window size,
1408 * which includes the area for the borders and titlebar. This method
1409 * should work even when the window is not yet visible.
1411 virtual LayoutDeviceIntSize ClientToWindowSize(
1412 const LayoutDeviceIntSize& aClientSize) = 0;
1415 * Dispatches an event to the widget
1417 virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* event,
1418 nsEventStatus& aStatus) = 0;
1421 * Dispatches an event to APZ only.
1422 * No-op in the child process.
1424 virtual void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) = 0;
1427 * Dispatches an event that must be handled by APZ first, when APZ is
1428 * enabled. If invoked in the child process, it is forwarded to the
1429 * parent process synchronously.
1431 virtual nsEventStatus DispatchInputEvent(
1432 mozilla::WidgetInputEvent* aEvent) = 0;
1435 * Confirm an APZ-aware event target. This should be used when APZ will
1436 * not need a layers update to process the event.
1438 virtual void SetConfirmedTargetAPZC(
1439 uint64_t aInputBlockId,
1440 const nsTArray<ScrollableLayerGuid>& aTargets) const = 0;
1443 * Returns true if APZ is in use, false otherwise.
1445 virtual bool AsyncPanZoomEnabled() const = 0;
1448 * Enables the dropping of files to a widget.
1450 virtual void EnableDragDrop(bool aEnable) = 0;
1451 virtual nsresult AsyncEnableDragDrop(bool aEnable) = 0;
1454 * Enables/Disables system mouse capture.
1455 * @param aCapture true enables mouse capture, false disables mouse capture
1458 virtual void CaptureMouse(bool aCapture) = 0;
1461 * Classify the window for the window manager. Mostly for X11.
1463 virtual void SetWindowClass(const nsAString& xulWinType) = 0;
1466 * Enables/Disables system capture of any and all events that would cause a
1467 * popup to be rolled up. aListener should be set to a non-null value for
1468 * any popups that are not managed by the popup manager.
1469 * @param aDoCapture true enables capture, false disables capture
1472 virtual void CaptureRollupEvents(nsIRollupListener* aListener,
1473 bool aDoCapture) = 0;
1476 * Bring this window to the user's attention. This is intended to be a more
1477 * gentle notification than popping the window to the top or putting up an
1478 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1479 * the Mac. The notification should be suppressed if the window is already
1480 * in the foreground and should be dismissed when the user brings this window
1481 * to the foreground.
1482 * @param aCycleCount Maximum number of times to animate the window per system
1483 * conventions. If set to -1, cycles indefinitely until
1484 * window is brought into the foreground.
1486 [[nodiscard]] virtual nsresult GetAttention(int32_t aCycleCount) = 0;
1489 * Ask whether there user input events pending. All input events are
1490 * included, including those not targeted at this nsIwidget instance.
1492 virtual bool HasPendingInputEvent() = 0;
1495 * If set to true, the window will draw its contents into the titlebar
1496 * instead of below it.
1498 * Ignored on any platform that does not support it. Ignored by widgets that
1499 * do not represent windows.
1500 * May result in a resize event, so should only be called from places where
1501 * reflow and painting is allowed.
1503 * @param aState Whether drawing into the titlebar should be activated.
1505 virtual void SetDrawsInTitlebar(bool aState) = 0;
1508 * Determine whether the widget shows a resize widget. If it does,
1509 * aResizerRect returns the resizer's rect.
1511 * Returns false on any platform that does not support it.
1513 * @param aResizerRect The resizer's rect in device pixels.
1514 * @return Whether a resize widget is shown.
1516 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) = 0;
1519 * Begin a window resizing drag, based on the event passed in.
1521 [[nodiscard]] virtual nsresult BeginResizeDrag(
1522 mozilla::WidgetGUIEvent* aEvent, int32_t aHorizontal,
1523 int32_t aVertical) = 0;
1525 enum Modifiers {
1526 CAPS_LOCK = 0x00000001, // when CapsLock is active
1527 NUM_LOCK = 0x00000002, // when NumLock is active
1528 SHIFT_L = 0x00000100,
1529 SHIFT_R = 0x00000200,
1530 CTRL_L = 0x00000400,
1531 CTRL_R = 0x00000800,
1532 ALT_L = 0x00001000, // includes Option
1533 ALT_R = 0x00002000,
1534 COMMAND_L = 0x00004000,
1535 COMMAND_R = 0x00008000,
1536 HELP = 0x00010000,
1537 ALTGRAPH = 0x00020000, // AltGr key on Windows. This emulates
1538 // AltRight key behavior of keyboard
1539 // layouts which maps AltGr to AltRight
1540 // key.
1541 FUNCTION = 0x00100000,
1542 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1545 * Utility method intended for testing. Dispatches native key events
1546 * to this widget to simulate the press and release of a key.
1547 * @param aNativeKeyboardLayout a *platform-specific* constant.
1548 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1549 * On Windows, it is converted to a hex string and passed to
1550 * LoadKeyboardLayout, see
1551 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1552 * @param aNativeKeyCode a *platform-specific* keycode.
1553 * On Windows, this is the virtual key code.
1554 * @param aModifiers some combination of the above 'Modifiers' flags;
1555 * not all flags will apply to all platforms. Mac ignores the _R
1556 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1557 * FUNCTION.
1558 * @param aCharacters characters that the OS would decide to generate
1559 * from the event. On Windows, this is the charCode passed by
1560 * WM_CHAR.
1561 * @param aUnmodifiedCharacters characters that the OS would decide
1562 * to generate from the event if modifier keys (other than shift)
1563 * were assumed inactive. Needed on Mac, ignored on Windows.
1564 * @param aObserver the observer that will get notified once the events
1565 * have been dispatched.
1566 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1567 * layout is not supported and the event was not fired
1569 virtual nsresult SynthesizeNativeKeyEvent(
1570 int32_t aNativeKeyboardLayout, int32_t aNativeKeyCode,
1571 uint32_t aModifierFlags, const nsAString& aCharacters,
1572 const nsAString& aUnmodifiedCharacters, nsIObserver* aObserver) = 0;
1575 * Utility method intended for testing. Dispatches native mouse events
1576 * may even move the mouse cursor. On Mac the events are guaranteed to
1577 * be sent to the window containing this widget, but on Windows they'll go
1578 * to whatever's topmost on the screen at that position, so for
1579 * cross-platform testing ensure that your window is at the top of the
1580 * z-order.
1581 * @param aPoint screen location of the mouse, in device
1582 * pixels, with origin at the top left
1583 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
1584 * NSEventTypeMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN
1585 * etc)
1586 * @param aModifierFlags *platform-specific* modifier flags (ignored
1587 * on Windows)
1588 * @param aObserver the observer that will get notified once the events
1589 * have been dispatched.
1591 virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
1592 uint32_t aNativeMessage,
1593 uint32_t aModifierFlags,
1594 nsIObserver* aObserver) = 0;
1597 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native
1598 * message. aPoint is location in device pixels to which the mouse pointer
1599 * moves to.
1600 * @param aObserver the observer that will get notified once the events
1601 * have been dispatched.
1603 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
1604 nsIObserver* aObserver) = 0;
1607 * Utility method intended for testing. Dispatching native mouse scroll
1608 * events may move the mouse cursor.
1610 * @param aPoint Mouse cursor position in screen coordinates.
1611 * In device pixels, the origin at the top left of
1612 * the primary display.
1613 * @param aNativeMessage Platform native message.
1614 * @param aDeltaX The delta value for X direction. If the native
1615 * message doesn't indicate X direction scrolling,
1616 * this may be ignored.
1617 * @param aDeltaY The delta value for Y direction. If the native
1618 * message doesn't indicate Y direction scrolling,
1619 * this may be ignored.
1620 * @param aDeltaZ The delta value for Z direction. If the native
1621 * message doesn't indicate Z direction scrolling,
1622 * this may be ignored.
1623 * @param aModifierFlags Must be values of Modifiers, or zero.
1624 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1625 * document.
1626 * @param aObserver The observer that will get notified once the
1627 * events have been dispatched.
1629 virtual nsresult SynthesizeNativeMouseScrollEvent(
1630 LayoutDeviceIntPoint aPoint, uint32_t aNativeMessage, double aDeltaX,
1631 double aDeltaY, double aDeltaZ, uint32_t aModifierFlags,
1632 uint32_t aAdditionalFlags, nsIObserver* aObserver) = 0;
1635 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1636 * touch states in nsIDOMWindowUtils.idl.
1638 enum TouchPointerState {
1639 // The pointer is in a hover state above the digitizer
1640 TOUCH_HOVER = (1 << 0),
1641 // The pointer is in contact with the digitizer
1642 TOUCH_CONTACT = (1 << 1),
1643 // The pointer has been removed from the digitizer detection area
1644 TOUCH_REMOVE = (1 << 2),
1645 // The pointer has been canceled. Will cancel any pending os level
1646 // gestures that would triggered as a result of completion of the
1647 // input sequence. This may not cancel moz platform related events
1648 // that might get tirggered by input already delivered.
1649 TOUCH_CANCEL = (1 << 3),
1651 // ALL_BITS used for validity checking during IPC serialization
1652 ALL_BITS = (1 << 4) - 1
1656 * Create a new or update an existing touch pointer on the digitizer.
1657 * To trigger os level gestures, individual touch points should
1658 * transition through a complete set of touch states which should be
1659 * sent as individual messages.
1661 * @param aPointerId The touch point id to create or update.
1662 * @param aPointerState one or more of the touch states listed above
1663 * @param aPoint coords of this event
1664 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1665 * @param aOrientation 0 -> 359 degree value indicating the
1666 * orientation of the pointer. Use 90 for normal taps.
1667 * @param aObserver The observer that will get notified once the events
1668 * have been dispatched.
1670 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
1671 TouchPointerState aPointerState,
1672 LayoutDeviceIntPoint aPoint,
1673 double aPointerPressure,
1674 uint32_t aPointerOrientation,
1675 nsIObserver* aObserver) = 0;
1678 * Helper for simulating a simple tap event with one touch point. When
1679 * aLongTap is true, simulates a native long tap with a duration equal to
1680 * ui.click_hold_context_menus.delay. This pref is compatible with the
1681 * apzc long tap duration. Defaults to 1.5 seconds.
1682 * @param aObserver The observer that will get notified once the events
1683 * have been dispatched.
1685 virtual nsresult SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
1686 bool aLongTap,
1687 nsIObserver* aObserver);
1690 * Cancels all active simulated touch input points and pending long taps.
1691 * Native widgets should track existing points such that they can clear the
1692 * digitizer state when this call is made.
1693 * @param aObserver The observer that will get notified once the touch
1694 * sequence has been cleared.
1696 virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver);
1698 virtual void StartAsyncScrollbarDrag(
1699 const AsyncDragMetrics& aDragMetrics) = 0;
1702 * Notify APZ to start autoscrolling.
1703 * @param aAnchorLocation the location of the autoscroll anchor
1704 * @param aGuid identifies the scroll frame to be autoscrolled
1705 * @return true if APZ has been successfully notified
1707 virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
1708 const ScrollableLayerGuid& aGuid) = 0;
1711 * Notify APZ to stop autoscrolling.
1712 * @param aGuid identifies the scroll frame which is being autoscrolled.
1714 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) = 0;
1716 // If this widget supports out-of-process compositing, it can override
1717 // this method to provide additional information to the compositor.
1718 virtual void GetCompositorWidgetInitData(
1719 mozilla::widget::CompositorWidgetInitData* aInitData) {}
1722 * Setter/Getter of the system font setting for testing.
1724 virtual nsresult SetSystemFont(const nsCString& aFontName) {
1725 return NS_ERROR_NOT_IMPLEMENTED;
1727 virtual nsresult GetSystemFont(nsCString& aFontName) {
1728 return NS_ERROR_NOT_IMPLEMENTED;
1731 // Get rectangle of the screen where the window is placed.
1732 // It's used to detect popup overflow under Wayland because
1733 // Screenmanager does not work under it.
1734 #ifdef MOZ_WAYLAND
1735 virtual nsresult GetScreenRect(LayoutDeviceIntRect* aRect) {
1736 return NS_ERROR_NOT_IMPLEMENTED;
1738 virtual nsRect GetPreferredPopupRect() {
1739 NS_WARNING("GetPreferredPopupRect implemented only for wayland");
1740 return nsRect(0, 0, 0, 0);
1742 virtual void FlushPreferredPopupRect() {
1743 NS_WARNING("FlushPreferredPopupRect implemented only for wayland");
1744 return;
1747 #endif
1750 * Get safe area insets except to cutout.
1751 * See https://drafts.csswg.org/css-env-1/#safe-area-insets.
1753 virtual mozilla::ScreenIntMargin GetSafeAreaInsets() const {
1754 return mozilla::ScreenIntMargin();
1757 private:
1758 class LongTapInfo {
1759 public:
1760 LongTapInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
1761 mozilla::TimeDuration aDuration, nsIObserver* aObserver)
1762 : mPointerId(aPointerId),
1763 mPosition(aPoint),
1764 mDuration(aDuration),
1765 mObserver(aObserver),
1766 mStamp(mozilla::TimeStamp::Now()) {}
1768 int32_t mPointerId;
1769 LayoutDeviceIntPoint mPosition;
1770 mozilla::TimeDuration mDuration;
1771 nsCOMPtr<nsIObserver> mObserver;
1772 mozilla::TimeStamp mStamp;
1775 static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure);
1777 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboardContentProcess();
1778 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboardInner();
1780 mozilla::UniquePtr<LongTapInfo> mLongTapTouchPoint;
1781 nsCOMPtr<nsITimer> mLongTapTimer;
1782 static int32_t sPointerIdCounter;
1784 public:
1786 * If key events have not been handled by content or XBL handlers, they can
1787 * be offered to the system (for custom application shortcuts set in system
1788 * preferences, for example).
1790 virtual void PostHandleKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
1793 * Activates a native menu item at the position specified by the index
1794 * string. The index string is a string of positive integers separated
1795 * by the "|" (pipe) character. The last integer in the string represents
1796 * the item index in a submenu located using the integers preceding it.
1798 * Example: 1|0|4
1799 * In this string, the first integer represents the top-level submenu
1800 * in the native menu bar. Since the integer is 1, it is the second submeu
1801 * in the native menu bar. Within that, the first item (index 0) is a
1802 * submenu, and we want to activate the 5th item within that submenu.
1804 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1807 * This is used for native menu system testing.
1809 * Updates a native menu at the position specified by the index string.
1810 * The index string is a string of positive integers separated by the "|"
1811 * (pipe) character.
1813 * Example: 1|0|4
1814 * In this string, the first integer represents the top-level submenu
1815 * in the native menu bar. Since the integer is 1, it is the second submeu
1816 * in the native menu bar. Within that, the first item (index 0) is a
1817 * submenu, and we want to update submenu at index 4 within that submenu.
1819 * If this is called with an empty string it forces a full reload of the
1820 * menu system.
1822 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1825 * This is used for testing macOS service menu code.
1827 * @param aResult - the current text selection. Is empty if no selection.
1828 * @return nsresult - whether or not aResult was assigned the selected text.
1830 [[nodiscard]] virtual nsresult GetSelectionAsPlaintext(nsAString& aResult) {
1831 return NS_ERROR_NOT_IMPLEMENTED;
1835 * Notify IME of the specified notification.
1837 * @return If the notification is mouse button event and it's consumed by
1838 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1840 virtual nsresult NotifyIME(const IMENotification& aIMENotification) = 0;
1843 * MaybeDispatchInitialFocusEvent will dispatch a focus event after creation
1844 * of the widget, in the event that we were not able to observe and respond to
1845 * the initial focus event. This is necessary for the early skeleton UI
1846 * window, which is displayed and receives its initial focus event before we
1847 * can actually respond to it.
1849 virtual void MaybeDispatchInitialFocusEvent() {}
1852 * Notifies the input context changes.
1854 virtual void SetInputContext(const InputContext& aContext,
1855 const InputContextAction& aAction) = 0;
1858 * Get current input context.
1860 virtual InputContext GetInputContext() = 0;
1863 * Get native IME context. This is different from GetNativeData() with
1864 * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
1865 * process.
1867 virtual NativeIMEContext GetNativeIMEContext() = 0;
1870 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1871 * native (OS-level) event for it. This method allows tests to simulate
1872 * keystrokes that trigger native key bindings (which require a native
1873 * event).
1875 [[nodiscard]] virtual nsresult AttachNativeKeyEvent(
1876 mozilla::WidgetKeyboardEvent& aEvent) = 0;
1879 * Retrieve edit commands when the key combination of aEvent is used
1880 * in platform native applications.
1882 enum NativeKeyBindingsType : uint8_t {
1883 NativeKeyBindingsForSingleLineEditor,
1884 NativeKeyBindingsForMultiLineEditor,
1885 NativeKeyBindingsForRichTextEditor
1887 virtual bool GetEditCommands(NativeKeyBindingsType aType,
1888 const mozilla::WidgetKeyboardEvent& aEvent,
1889 nsTArray<mozilla::CommandInt>& aCommands);
1892 * Retrieves a reference to notification requests of IME. Note that the
1893 * reference is valid while the nsIWidget instance is alive. So, if you
1894 * need to store the reference for a long time, you need to grab the widget
1895 * instance too.
1897 const IMENotificationRequests& IMENotificationRequestsRef();
1900 * Call this method when a dialog is opened which has a default button.
1901 * The button's rectangle should be supplied in aButtonRect.
1903 [[nodiscard]] virtual nsresult OnDefaultButtonLoaded(
1904 const LayoutDeviceIntRect& aButtonRect) = 0;
1907 * Return true if this process shouldn't use platform widgets, and
1908 * so should use PuppetWidgets instead. If this returns true, the
1909 * result of creating and using a platform widget is undefined,
1910 * and likely to end in crashes or other buggy behavior.
1912 static bool UsePuppetWidgets() { return XRE_IsContentProcess(); }
1914 static already_AddRefed<nsIWidget> CreateTopLevelWindow();
1916 static already_AddRefed<nsIWidget> CreateChildWindow();
1919 * Allocate and return a "puppet widget" that doesn't directly
1920 * correlate to a platform widget; platform events and data must
1921 * be fed to it. Currently used in content processes. NULL is
1922 * returned if puppet widgets aren't supported in this build
1923 * config, on this platform, or for this process type.
1925 * This function is called "Create" to match CreateInstance().
1926 * The returned widget must still be nsIWidget::Create()d.
1928 static already_AddRefed<nsIWidget> CreatePuppetWidget(
1929 BrowserChild* aBrowserChild);
1931 static already_AddRefed<nsIWidget> CreateHeadlessWidget();
1934 * Allocate and return a "plugin proxy widget", a subclass of PuppetWidget
1935 * used in wrapping a PPluginWidget connection for remote widgets. Note
1936 * this call creates the base object, it does not create the widget. Use
1937 * nsIWidget's Create to do this.
1939 static already_AddRefed<nsIWidget> CreatePluginProxyWidget(
1940 BrowserChild* aBrowserChild, mozilla::plugins::PluginWidgetChild* aActor);
1943 * Reparent this widget's native widget.
1944 * @param aNewParent the native widget of aNewParent is the new native
1945 * parent widget
1947 virtual void ReparentNativeWidget(nsIWidget* aNewParent) = 0;
1950 * Return true if widget has it's own GL context
1952 virtual bool HasGLContext() { return false; }
1955 * Returns true to indicate that this widget paints an opaque background
1956 * that we want to be visible under the page, so layout should not force
1957 * a default background.
1959 virtual bool WidgetPaintsBackground() { return false; }
1961 virtual bool NeedsPaint() { return IsVisible() && !GetBounds().IsEmpty(); }
1964 * Get the natural bounds of this widget. This method is only
1965 * meaningful for widgets for which Gecko implements screen
1966 * rotation natively. When this is the case, GetBounds() returns
1967 * the widget bounds taking rotation into account, and
1968 * GetNaturalBounds() returns the bounds *not* taking rotation
1969 * into account.
1971 * No code outside of the composition pipeline should know or care
1972 * about this. If you're not an agent of the compositor, you
1973 * probably shouldn't call this method.
1975 virtual LayoutDeviceIntRect GetNaturalBounds() { return GetBounds(); }
1978 * Set size constraints on the window size such that it is never less than
1979 * the specified minimum size and never larger than the specified maximum
1980 * size. The size constraints are sizes of the outer rectangle including
1981 * the window frame and title bar. Use 0 for an unconstrained minimum size
1982 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1983 * does not necessarily change the size of a window to conform to this size,
1984 * thus Resize should be called afterwards.
1986 * @param aConstraints: the size constraints in device pixels
1988 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
1991 * Return the size constraints currently observed by the widget.
1993 * @return the constraints in device pixels
1995 virtual const SizeConstraints GetSizeConstraints() = 0;
1998 * If this is owned by a BrowserChild, return that. Otherwise return
1999 * null.
2001 virtual BrowserChild* GetOwningBrowserChild() { return nullptr; }
2004 * If this isn't directly compositing to its window surface,
2005 * return the compositor which is doing that on our behalf.
2007 virtual CompositorBridgeChild* GetRemoteRenderer() { return nullptr; }
2010 * Clear WebRender resources
2012 virtual void ClearCachedWebrenderResources() {}
2015 * If this widget has its own vsync source, return it, otherwise return
2016 * nullptr. An example of such local source would be Wayland frame callbacks.
2018 virtual RefPtr<mozilla::gfx::VsyncSource> GetVsyncSource() { return nullptr; }
2021 * Returns true if the widget requires synchronous repaints on resize,
2022 * false otherwise.
2024 virtual bool SynchronouslyRepaintOnResize() { return true; }
2027 * Some platforms (only cocoa right now) round widget coordinates to the
2028 * nearest even pixels (see bug 892994), this function allows us to
2029 * determine how widget coordinates will be rounded.
2031 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
2033 virtual void UpdateZoomConstraints(
2034 const uint32_t& aPresShellId, const ScrollableLayerGuid::ViewID& aViewId,
2035 const mozilla::Maybe<ZoomConstraints>& aConstraints){};
2038 * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
2039 * widget. Note that this never returns nullptr.
2041 virtual TextEventDispatcher* GetTextEventDispatcher() = 0;
2044 * GetNativeTextEventDispatcherListener() returns a
2045 * TextEventDispatcherListener instance which is used when the widget
2046 * instance handles native IME and/or keyboard events.
2048 virtual TextEventDispatcherListener*
2049 GetNativeTextEventDispatcherListener() = 0;
2051 virtual void ZoomToRect(const uint32_t& aPresShellId,
2052 const ScrollableLayerGuid::ViewID& aViewId,
2053 const CSSRect& aRect, const uint32_t& aFlags) = 0;
2056 * OnWindowedPluginKeyEvent() is called when native key event is
2057 * received in the focused plugin process directly in PluginInstanceChild.
2059 * @param aKeyEventData The native key event data. The actual type
2060 * copied into NativeEventData depends on the
2061 * caller. Please check PluginInstanceChild.
2062 * @param aCallback Callback interface. When this returns
2063 * NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY,
2064 * the event handler has to call this callback.
2065 * Otherwise, the caller should do that instead.
2066 * @return NS_ERROR_* if this fails to handle the event.
2067 * NS_SUCCESS_EVENT_CONSUMED if the key event is
2068 * consumed.
2069 * NS_OK if the key event isn't consumed.
2070 * NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY if the
2071 * key event will be handled asynchronously.
2073 virtual nsresult OnWindowedPluginKeyEvent(
2074 const mozilla::NativeEventData& aKeyEventData,
2075 nsIKeyEventInPluginCallback* aCallback);
2078 * LookUpDictionary shows the dictionary for the word around current point.
2080 * @param aText the word to look up dictiorary.
2081 * @param aFontRangeArray text decoration of aText
2082 * @param aIsVertical true if the word is vertical layout
2083 * @param aPoint top-left point of aText
2085 virtual void LookUpDictionary(
2086 const nsAString& aText,
2087 const nsTArray<mozilla::FontRange>& aFontRangeArray,
2088 const bool aIsVertical, const LayoutDeviceIntPoint& aPoint) {}
2090 virtual void RequestFxrOutput() {
2091 MOZ_ASSERT(false, "This function should only execute in Windows");
2094 #if defined(MOZ_WIDGET_ANDROID)
2096 * RecvToolbarAnimatorMessageFromCompositor receive message from compositor
2097 * thread.
2099 * @param aMessage message being sent to Android UI thread.
2101 virtual void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage) = 0;
2104 * UpdateRootFrameMetrics steady state frame metrics send from compositor
2105 * thread
2107 * @param aScrollOffset page scroll offset value in screen pixels.
2108 * @param aZoom current page zoom.
2110 virtual void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset,
2111 const CSSToScreenScale& aZoom) = 0;
2114 * RecvScreenPixels Buffer containing the pixel from the frame buffer. Used
2115 * for android robocop tests.
2117 * @param aMem shared memory containing the frame buffer pixels.
2118 * @param aSize size of the buffer in screen pixels.
2120 virtual void RecvScreenPixels(mozilla::ipc::Shmem&& aMem,
2121 const ScreenIntSize& aSize,
2122 bool aNeedsYFlip) = 0;
2124 virtual void UpdateDynamicToolbarMaxHeight(mozilla::ScreenIntCoord aHeight) {}
2125 virtual mozilla::ScreenIntCoord GetDynamicToolbarMaxHeight() const {
2126 return 0;
2128 #endif
2130 static already_AddRefed<nsIBidiKeyboard> CreateBidiKeyboard();
2133 * Like GetDefaultScale, but taking into account only the system settings
2134 * and ignoring Gecko preferences.
2136 virtual double GetDefaultScaleInternal() { return 1.0; }
2138 protected:
2139 // keep the list of children. We also keep track of our siblings.
2140 // The ownership model is as follows: parent holds a strong ref to
2141 // the first element of the list, and each element holds a strong
2142 // ref to the next element in the list. The prevsibling and
2143 // lastchild pointers are weak, which is fine as long as they are
2144 // maintained properly.
2145 nsCOMPtr<nsIWidget> mFirstChild;
2146 nsIWidget* MOZ_NON_OWNING_REF mLastChild;
2147 nsCOMPtr<nsIWidget> mNextSibling;
2148 nsIWidget* MOZ_NON_OWNING_REF mPrevSibling;
2149 // When Destroy() is called, the sub class should set this true.
2150 bool mOnDestroyCalled;
2151 nsWindowType mWindowType;
2152 int32_t mZIndex;
2155 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
2157 #endif // nsIWidget_h__