Bug 1444460 [wpt PR 9948] - gyroscope: Rename LocalCoordinateSystem to GyroscopeLocal...
[gecko.git] / widget / nsIWidget.h
blobc5e9eba0131f0d700d888358026e0184fe31cab6
1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "mozilla/UniquePtr.h"
10 #include "nsISupports.h"
11 #include "nsColor.h"
12 #include "nsRect.h"
13 #include "nsString.h"
15 #include "nsCOMPtr.h"
16 #include "nsWidgetInitData.h"
17 #include "nsTArray.h"
18 #include "nsITheme.h"
19 #include "nsITimer.h"
20 #include "nsRegionFwd.h"
21 #include "nsStyleConsts.h"
22 #include "nsXULAppAPI.h"
23 #include "mozilla/Maybe.h"
24 #include "mozilla/EventForwards.h"
25 #include "mozilla/layers/LayersTypes.h"
26 #include "mozilla/RefPtr.h"
27 #include "mozilla/TimeStamp.h"
28 #include "mozilla/gfx/Point.h"
29 #include "mozilla/widget/IMEData.h"
30 #include "nsDataHashtable.h"
31 #include "nsIObserver.h"
32 #include "nsIWidgetListener.h"
33 #include "FrameMetrics.h"
34 #include "Units.h"
36 // forward declarations
37 class nsIRollupListener;
38 class imgIContainer;
39 class nsIContent;
40 class ViewWrapper;
41 class nsIScreen;
42 class nsIRunnable;
43 class nsIKeyEventInPluginCallback;
45 namespace mozilla {
46 #if defined(MOZ_WIDGET_ANDROID)
47 namespace ipc {
48 class Shmem;
50 #endif // defined(MOZ_WIDGET_ANDROID)
51 namespace dom {
52 class TabChild;
53 } // namespace dom
54 namespace plugins {
55 class PluginWidgetChild;
56 } // namespace plugins
57 namespace layers {
58 class AsyncDragMetrics;
59 class Compositor;
60 class CompositorBridgeChild;
61 class LayerManager;
62 class LayerManagerComposite;
63 class PLayerTransactionChild;
64 class WebRenderBridgeChild;
65 struct ScrollableLayerGuid;
66 } // namespace layers
67 namespace gfx {
68 class DrawTarget;
69 class SourceSurface;
70 } // namespace gfx
71 namespace widget {
72 class TextEventDispatcher;
73 class TextEventDispatcherListener;
74 class CompositorWidget;
75 class CompositorWidgetInitData;
76 } // namespace widget
77 namespace wr {
78 class DisplayListBuilder;
79 class IpcResourceUpdateQueue;
80 } // namespace wr
81 } // namespace mozilla
83 /**
84 * Callback function that processes events.
86 * The argument is actually a subtype (subclass) of WidgetEvent which carries
87 * platform specific information about the event. Platform specific code
88 * knows how to deal with it.
90 * The return value determines whether or not the default action should take
91 * place.
93 typedef nsEventStatus (* EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent);
95 // Hide the native window system's real window type so as to avoid
96 // including native window system types and APIs. This is necessary
97 // to ensure cross-platform code.
98 typedef void* nsNativeWidget;
101 * Flags for the GetNativeData and SetNativeData functions
103 #define NS_NATIVE_WINDOW 0
104 #define NS_NATIVE_GRAPHIC 1
105 #define NS_NATIVE_TMP_WINDOW 2
106 #define NS_NATIVE_WIDGET 3
107 #define NS_NATIVE_DISPLAY 4
108 #define NS_NATIVE_REGION 5
109 #define NS_NATIVE_OFFSETX 6
110 #define NS_NATIVE_OFFSETY 7
111 #define NS_NATIVE_PLUGIN_PORT 8
112 #define NS_NATIVE_SCREEN 9
113 // The toplevel GtkWidget containing this nsIWidget:
114 #define NS_NATIVE_SHELLWIDGET 10
115 // Has to match to NPNVnetscapeWindow, and shareable across processes
116 // HWND on Windows and XID on X11
117 #define NS_NATIVE_SHAREABLE_WINDOW 11
118 #define NS_NATIVE_OPENGL_CONTEXT 12
119 // See RegisterPluginWindowForRemoteUpdates
120 #define NS_NATIVE_PLUGIN_ID 13
121 // This is available only with GetNativeData() in parent process. Anybody
122 // shouldn't access this pointer as a valid pointer since the result may be
123 // special value like NS_ONLY_ONE_NATIVE_IME_CONTEXT. So, the result is just
124 // an identifier of distinguishing a text composition is caused by which native
125 // IME context. Note that the result is only valid in the process. So,
126 // XP code should use nsIWidget::GetNativeIMEContext() instead of using this.
127 #define NS_RAW_NATIVE_IME_CONTEXT 14
128 #ifdef XP_MACOSX
129 #define NS_NATIVE_PLUGIN_PORT_QD 100
130 #define NS_NATIVE_PLUGIN_PORT_CG 101
131 #endif
132 #ifdef XP_WIN
133 #define NS_NATIVE_TSF_THREAD_MGR 100
134 #define NS_NATIVE_TSF_CATEGORY_MGR 101
135 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
136 #define NS_NATIVE_ICOREWINDOW 103 // winrt specific
137 #define NS_NATIVE_CHILD_WINDOW 104
138 #define NS_NATIVE_CHILD_OF_SHAREABLE_WINDOW 105
139 #endif
140 #if defined(MOZ_WIDGET_GTK)
141 // set/get nsPluginNativeWindowGtk, e10s specific
142 #define NS_NATIVE_PLUGIN_OBJECT_PTR 104
143 #ifdef MOZ_X11
144 #define NS_NATIVE_COMPOSITOR_DISPLAY 105
145 #endif // MOZ_X11
146 #endif
147 #ifdef MOZ_WIDGET_ANDROID
148 #define NS_JAVA_SURFACE 100
149 #define NS_PRESENTATION_WINDOW 101
150 #define NS_PRESENTATION_SURFACE 102
151 #endif
153 // Must be kept in sync with xpcom/rust/xpcom/src/interfaces/nonidl.rs
154 #define NS_IWIDGET_IID \
155 { 0x06396bf6, 0x2dd8, 0x45e5, \
156 { 0xac, 0x45, 0x75, 0x26, 0x53, 0xb1, 0xc9, 0x80 } }
160 * Transparency modes
163 enum nsTransparencyMode {
164 eTransparencyOpaque = 0, // Fully opaque
165 eTransparencyTransparent, // Parts of the window may be transparent
166 eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass effect applied
167 eTransparencyBorderlessGlass // As above, but without a border around the opaque areas when there would otherwise be one with eTransparencyGlass
171 * Cursor types.
174 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
175 eCursor_standard,
176 ///(system is busy, usually rendered as a hourglass or watch)
177 eCursor_wait,
178 ///(Selecting something, usually rendered as an IBeam)
179 eCursor_select,
180 ///(can hyper-link, usually rendered as a human hand)
181 eCursor_hyperlink,
182 ///(north/south/west/east edge sizing)
183 eCursor_n_resize,
184 eCursor_s_resize,
185 eCursor_w_resize,
186 eCursor_e_resize,
187 ///(corner sizing)
188 eCursor_nw_resize,
189 eCursor_se_resize,
190 eCursor_ne_resize,
191 eCursor_sw_resize,
192 eCursor_crosshair,
193 eCursor_move,
194 eCursor_help,
195 eCursor_copy, // CSS3
196 eCursor_alias,
197 eCursor_context_menu,
198 eCursor_cell,
199 eCursor_grab,
200 eCursor_grabbing,
201 eCursor_spinning,
202 eCursor_zoom_in,
203 eCursor_zoom_out,
204 eCursor_not_allowed,
205 eCursor_col_resize,
206 eCursor_row_resize,
207 eCursor_no_drop,
208 eCursor_vertical_text,
209 eCursor_all_scroll,
210 eCursor_nesw_resize,
211 eCursor_nwse_resize,
212 eCursor_ns_resize,
213 eCursor_ew_resize,
214 eCursor_none,
215 // This one is used for array sizing, and so better be the last
216 // one in this list...
217 eCursorCount,
219 // ...except for this one.
220 eCursorInvalid = eCursorCount + 1
223 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
224 eZPlacementBottom = 0, // bottom of the window stack
225 eZPlacementBelow, // just below another widget
226 eZPlacementTop // top of the window stack
230 * Before the OS goes to sleep, this topic is notified.
232 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
235 * After the OS wakes up, this topic is notified.
237 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
240 * Before the OS suspends the current process, this topic is notified. Some
241 * OS will kill processes that are suspended instead of resuming them.
242 * For that reason this topic may be useful to safely close down resources.
244 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
247 * After the current process resumes from being suspended, this topic is
248 * notified.
250 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
252 namespace mozilla {
253 namespace widget {
256 * Size constraints for setting the minimum and maximum size of a widget.
257 * Values are in device pixels.
259 struct SizeConstraints {
260 SizeConstraints()
261 : mMaxSize(NS_MAXSIZE, NS_MAXSIZE)
265 SizeConstraints(mozilla::LayoutDeviceIntSize aMinSize,
266 mozilla::LayoutDeviceIntSize aMaxSize)
267 : mMinSize(aMinSize),
268 mMaxSize(aMaxSize)
272 mozilla::LayoutDeviceIntSize mMinSize;
273 mozilla::LayoutDeviceIntSize mMaxSize;
276 struct AutoObserverNotifier {
277 AutoObserverNotifier(nsIObserver* aObserver,
278 const char* aTopic)
279 : mObserver(aObserver)
280 , mTopic(aTopic)
284 void SkipNotification()
286 mObserver = nullptr;
289 uint64_t SaveObserver()
291 if (!mObserver) {
292 return 0;
294 uint64_t observerId = ++sObserverId;
295 sSavedObservers.Put(observerId, mObserver);
296 SkipNotification();
297 return observerId;
300 ~AutoObserverNotifier()
302 if (mObserver) {
303 mObserver->Observe(nullptr, mTopic, nullptr);
307 static void NotifySavedObserver(const uint64_t& aObserverId,
308 const char* aTopic)
310 nsCOMPtr<nsIObserver> observer = sSavedObservers.Get(aObserverId);
311 if (!observer) {
312 MOZ_ASSERT(aObserverId == 0, "We should always find a saved observer for nonzero IDs");
313 return;
316 sSavedObservers.Remove(aObserverId);
317 observer->Observe(nullptr, aTopic, nullptr);
320 private:
321 nsCOMPtr<nsIObserver> mObserver;
322 const char* mTopic;
324 private:
325 static uint64_t sObserverId;
326 static nsDataHashtable<nsUint64HashKey, nsCOMPtr<nsIObserver>> sSavedObservers;
329 } // namespace widget
330 } // namespace mozilla
333 * The base class for all the widgets. It provides the interface for
334 * all basic and necessary functionality.
336 class nsIWidget : public nsISupports
338 protected:
339 typedef mozilla::dom::TabChild TabChild;
341 public:
342 typedef mozilla::layers::CompositorBridgeChild CompositorBridgeChild;
343 typedef mozilla::layers::AsyncDragMetrics AsyncDragMetrics;
344 typedef mozilla::layers::FrameMetrics FrameMetrics;
345 typedef mozilla::layers::LayerManager LayerManager;
346 typedef mozilla::layers::LayerManagerComposite LayerManagerComposite;
347 typedef mozilla::layers::LayersBackend LayersBackend;
348 typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild;
349 typedef mozilla::layers::ScrollableLayerGuid ScrollableLayerGuid;
350 typedef mozilla::layers::ZoomConstraints ZoomConstraints;
351 typedef mozilla::widget::IMEMessage IMEMessage;
352 typedef mozilla::widget::IMENotification IMENotification;
353 typedef mozilla::widget::IMENotificationRequests IMENotificationRequests;
354 typedef mozilla::widget::IMEState IMEState;
355 typedef mozilla::widget::InputContext InputContext;
356 typedef mozilla::widget::InputContextAction InputContextAction;
357 typedef mozilla::widget::NativeIMEContext NativeIMEContext;
358 typedef mozilla::widget::SizeConstraints SizeConstraints;
359 typedef mozilla::widget::TextEventDispatcher TextEventDispatcher;
360 typedef mozilla::widget::TextEventDispatcherListener
361 TextEventDispatcherListener;
362 typedef mozilla::LayoutDeviceIntMargin LayoutDeviceIntMargin;
363 typedef mozilla::LayoutDeviceIntPoint LayoutDeviceIntPoint;
364 typedef mozilla::LayoutDeviceIntRect LayoutDeviceIntRect;
365 typedef mozilla::LayoutDeviceIntRegion LayoutDeviceIntRegion;
366 typedef mozilla::LayoutDeviceIntSize LayoutDeviceIntSize;
367 typedef mozilla::ScreenIntPoint ScreenIntPoint;
368 typedef mozilla::ScreenIntSize ScreenIntSize;
369 typedef mozilla::ScreenPoint ScreenPoint;
370 typedef mozilla::CSSToScreenScale CSSToScreenScale;
371 typedef mozilla::DesktopIntRect DesktopIntRect;
372 typedef mozilla::CSSPoint CSSPoint;
373 typedef mozilla::CSSRect CSSRect;
375 // Used in UpdateThemeGeometries.
376 struct ThemeGeometry {
377 // The ThemeGeometryType value for the themed widget, see
378 // nsITheme::ThemeGeometryTypeForWidget.
379 nsITheme::ThemeGeometryType mType;
380 // The device-pixel rect within the window for the themed widget
381 LayoutDeviceIntRect mRect;
383 ThemeGeometry(nsITheme::ThemeGeometryType aType,
384 const LayoutDeviceIntRect& aRect)
385 : mType(aType)
386 , mRect(aRect)
390 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
392 nsIWidget()
393 : mLastChild(nullptr)
394 , mPrevSibling(nullptr)
395 , mOnDestroyCalled(false)
396 , mWindowType(eWindowType_child)
397 , mZIndex(0)
400 ClearNativeTouchSequence(nullptr);
405 * Create and initialize a widget.
407 * All the arguments can be null in which case a top level window
408 * with size 0 is created. The event callback function has to be
409 * provided only if the caller wants to deal with the events this
410 * widget receives. The event callback is basically a preprocess
411 * hook called synchronously. The return value determines whether
412 * the event goes to the default window procedure or it is hidden
413 * to the os. The assumption is that if the event handler returns
414 * false the widget does not see the event. The widget should not
415 * automatically clear the window to the background color. The
416 * calling code must handle paint messages and clear the background
417 * itself.
419 * In practice at least one of aParent and aNativeParent will be null. If
420 * both are null the widget isn't parented (e.g. context menus or
421 * independent top level windows).
423 * The dimensions given in aRect are specified in the parent's
424 * device coordinate system.
425 * This must not be called for parentless widgets such as top-level
426 * windows, which use the desktop pixel coordinate system; a separate
427 * method is provided for these.
429 * @param aParent parent nsIWidget
430 * @param aNativeParent native parent widget
431 * @param aRect the widget dimension
432 * @param aInitData data that is used for widget initialization
435 virtual MOZ_MUST_USE nsresult
436 Create(nsIWidget* aParent,
437 nsNativeWidget aNativeParent,
438 const LayoutDeviceIntRect& aRect,
439 nsWidgetInitData* aInitData = nullptr) = 0;
442 * As above, but with aRect specified in DesktopPixel units (for top-level
443 * widgets).
444 * Default implementation just converts aRect to device pixels and calls
445 * through to device-pixel Create, but platforms may override this if the
446 * mapping is not straightforward or the native platform needs to use the
447 * desktop pixel values directly.
449 virtual MOZ_MUST_USE nsresult
450 Create(nsIWidget* aParent,
451 nsNativeWidget aNativeParent,
452 const DesktopIntRect& aRect,
453 nsWidgetInitData* aInitData = nullptr)
455 LayoutDeviceIntRect devPixRect =
456 RoundedToInt(aRect * GetDesktopToDeviceScale());
457 return Create(aParent, aNativeParent, devPixRect, aInitData);
461 * Allocate, initialize, and return a widget that is a child of
462 * |this|. The returned widget (if nonnull) has gone through the
463 * equivalent of CreateInstance(widgetCID) + Create(...).
465 * |CreateChild()| lets widget backends decide whether to parent
466 * the new child widget to this, nonnatively parent it, or both.
467 * This interface exists to support the PuppetWidget backend,
468 * which is entirely non-native. All other params are the same as
469 * for |Create()|.
471 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
472 * |nsIWidget*| this, not its native widget (if it exists), when
473 * calling |Create()|. This is a timid hack around poorly
474 * understood code, and shouldn't be used in new code.
476 virtual already_AddRefed<nsIWidget>
477 CreateChild(const LayoutDeviceIntRect& aRect,
478 nsWidgetInitData* aInitData = nullptr,
479 bool aForceUseIWidgetParent = false) = 0;
482 * Attach to a top level widget.
484 * In cases where a top level chrome widget is being used as a content
485 * container, attach a secondary listener and update the device
486 * context. The primary widget listener will continue to be called for
487 * notifications relating to the top-level window, whereas other
488 * notifications such as painting and events will instead be called via
489 * the attached listener. SetAttachedWidgetListener should be used to
490 * assign the attached listener.
492 * aUseAttachedEvents if true, events are sent to the attached listener
493 * instead of the normal listener.
495 virtual void AttachViewToTopLevel(bool aUseAttachedEvents) = 0;
498 * Accessor functions to get and set the attached listener. Used by
499 * nsView in connection with AttachViewToTopLevel above.
501 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
502 virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
503 virtual void SetPreviouslyAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
504 virtual nsIWidgetListener* GetPreviouslyAttachedWidgetListener() = 0;
507 * Accessor functions to get and set the listener which handles various
508 * actions for the widget.
510 //@{
511 virtual nsIWidgetListener* GetWidgetListener() = 0;
512 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
513 //@}
516 * Close and destroy the internal native window.
517 * This method does not delete the widget.
520 virtual void Destroy() = 0;
523 * Destroyed() returns true if Destroy() has been called already.
524 * Otherwise, false.
526 bool Destroyed() const { return mOnDestroyCalled; }
530 * Reparent a widget
532 * Change the widget's parent. Null parents are allowed.
534 * @param aNewParent new parent
536 virtual void SetParent(nsIWidget* aNewParent) = 0;
539 * Return the parent Widget of this Widget or nullptr if this is a
540 * top level window
542 * @return the parent widget or nullptr if it does not have a parent
545 virtual nsIWidget* GetParent(void) = 0;
548 * Return the top level Widget of this Widget
550 * @return the top level widget
552 virtual nsIWidget* GetTopLevelWidget() = 0;
555 * Return the top (non-sheet) parent of this Widget if it's a sheet,
556 * or nullptr if this isn't a sheet (or some other error occurred).
557 * Sheets are only supported on some platforms (currently only OS X).
559 * @return the top (non-sheet) parent widget or nullptr
562 virtual nsIWidget* GetSheetWindowParent(void) = 0;
565 * Return the physical DPI of the screen containing the window ...
566 * the number of device pixels per inch.
568 virtual float GetDPI() = 0;
571 * Return the scaling factor between device pixels and the platform-
572 * dependent "desktop pixels" used to manage window positions on a
573 * potentially multi-screen, mixed-resolution desktop.
575 virtual mozilla::DesktopToLayoutDeviceScale GetDesktopToDeviceScale() = 0;
578 * Return the default scale factor for the window. This is the
579 * default number of device pixels per CSS pixel to use. This should
580 * depend on OS/platform settings such as the Mac's "UI scale factor"
581 * or Windows' "font DPI". This will take into account Gecko preferences
582 * overriding the system setting.
584 mozilla::CSSToLayoutDeviceScale GetDefaultScale();
587 * Return the Gecko override of the system default scale, if any;
588 * returns <= 0.0 if the system scale should be used as-is.
589 * nsIWidget::GetDefaultScale() [above] takes this into account.
590 * It is exposed here so that code that wants to check for a
591 * default-scale override without having a widget on hand can
592 * easily access the same value.
593 * Note that any scale override is a browser-wide value, whereas
594 * the default GetDefaultScale value (when no override is present)
595 * may vary between widgets (or screens).
597 static double DefaultScaleOverride();
600 * Return the first child of this widget. Will return null if
601 * there are no children.
603 nsIWidget* GetFirstChild() const {
604 return mFirstChild;
608 * Return the last child of this widget. Will return null if
609 * there are no children.
611 nsIWidget* GetLastChild() const {
612 return mLastChild;
616 * Return the next sibling of this widget
618 nsIWidget* GetNextSibling() const {
619 return mNextSibling;
623 * Set the next sibling of this widget
625 void SetNextSibling(nsIWidget* aSibling) {
626 mNextSibling = aSibling;
630 * Return the previous sibling of this widget
632 nsIWidget* GetPrevSibling() const {
633 return mPrevSibling;
637 * Set the previous sibling of this widget
639 void SetPrevSibling(nsIWidget* aSibling) {
640 mPrevSibling = aSibling;
644 * Show or hide this widget
646 * @param aState true to show the Widget, false to hide it
649 virtual void Show(bool aState) = 0;
652 * Make the window modal.
654 virtual void SetModal(bool aModal) = 0;
657 * Make the non-modal window opened by modal window fake-modal, that will
658 * call SetFakeModal(false) on destroy on Cocoa.
660 virtual void SetFakeModal(bool aModal)
662 SetModal(aModal);
666 * Are we app modal. Currently only implemented on Cocoa.
668 virtual bool IsRunningAppModal()
670 return false;
674 * The maximum number of simultaneous touch contacts supported by the device.
675 * In the case of devices with multiple digitizers (e.g. multiple touch screens),
676 * the value will be the maximum of the set of maximum supported contacts by
677 * each individual digitizer.
679 virtual uint32_t GetMaxTouchPoints() const = 0;
682 * Returns whether the window is visible
685 virtual bool IsVisible() const = 0;
688 * Perform platform-dependent sanity check on a potential window position.
689 * This is guaranteed to work only for top-level windows.
691 * @param aAllowSlop: if true, allow the window to slop offscreen;
692 * the window should be partially visible. if false,
693 * force the entire window onscreen (or at least
694 * the upper-left corner, if it's too large).
695 * @param aX in: an x position expressed in screen coordinates.
696 * out: the x position constrained to fit on the screen(s).
697 * @param aY in: an y position expressed in screen coordinates.
698 * out: the y position constrained to fit on the screen(s).
701 virtual void ConstrainPosition(bool aAllowSlop,
702 int32_t *aX,
703 int32_t *aY) = 0;
706 * NOTE:
708 * For a top-level window widget, the "parent's coordinate system" is the
709 * "global" display pixel coordinate space, *not* device pixels (which
710 * may be inconsistent between multiple screens, at least in the Mac OS
711 * case with mixed hi-dpi and lo-dpi displays). This applies to all the
712 * following Move and Resize widget APIs.
714 * The display-/device-pixel distinction becomes important for (at least)
715 * Mac OS X with Hi-DPI (retina) displays, and Windows when the UI scale
716 * factor is set to other than 100%.
718 * The Move and Resize methods take floating-point parameters, rather than
719 * integer ones. This is important when manipulating top-level widgets,
720 * where the coordinate system may not be an integral multiple of the
721 * device-pixel space.
725 * Move this widget.
727 * Coordinates refer to the top-left of the widget. For toplevel windows
728 * with decorations, this is the top-left of the titlebar and frame .
730 * @param aX the new x position expressed in the parent's coordinate system
731 * @param aY the new y position expressed in the parent's coordinate system
734 virtual void Move(double aX, double aY) = 0;
737 * Reposition this widget so that the client area has the given offset.
739 * @param aX the new x offset of the client area expressed as an
740 * offset from the origin of the client area of the parent
741 * widget (for root widgets and popup widgets it is in
742 * screen coordinates)
743 * @param aY the new y offset of the client area expressed as an
744 * offset from the origin of the client area of the parent
745 * widget (for root widgets and popup widgets it is in
746 * screen coordinates)
748 virtual void MoveClient(double aX, double aY) = 0;
751 * Resize this widget. Any size constraints set for the window by a
752 * previous call to SetSizeConstraints will be applied.
754 * @param aWidth the new width expressed in the parent's coordinate system
755 * @param aHeight the new height expressed in the parent's coordinate system
756 * @param aRepaint whether the widget should be repainted
758 virtual void Resize(double aWidth,
759 double aHeight,
760 bool aRepaint) = 0;
763 * Move or resize this widget. Any size constraints set for the window by
764 * a previous call to SetSizeConstraints will be applied.
766 * @param aX the new x position expressed in the parent's coordinate system
767 * @param aY the new y position expressed in the parent's coordinate system
768 * @param aWidth the new width expressed in the parent's coordinate system
769 * @param aHeight the new height expressed in the parent's coordinate system
770 * @param aRepaint whether the widget should be repainted if the size changes
773 virtual void Resize(double aX,
774 double aY,
775 double aWidth,
776 double aHeight,
777 bool aRepaint) = 0;
780 * Resize the widget so that the inner client area has the given size.
782 * @param aWidth the new width of the client area.
783 * @param aHeight the new height of the client area.
784 * @param aRepaint whether the widget should be repainted
786 virtual void ResizeClient(double aWidth,
787 double aHeight,
788 bool aRepaint) = 0;
791 * Resize and reposition the widget so tht inner client area has the given
792 * offset and size.
794 * @param aX the new x offset of the client area expressed as an
795 * offset from the origin of the client area of the parent
796 * widget (for root widgets and popup widgets it is in
797 * screen coordinates)
798 * @param aY the new y offset of the client area expressed as an
799 * offset from the origin of the client area of the parent
800 * widget (for root widgets and popup widgets it is in
801 * screen coordinates)
802 * @param aWidth the new width of the client area.
803 * @param aHeight the new height of the client area.
804 * @param aRepaint whether the widget should be repainted
806 virtual void ResizeClient(double aX,
807 double aY,
808 double aWidth,
809 double aHeight,
810 bool aRepaint) = 0;
813 * Sets the widget's z-index.
815 virtual void SetZIndex(int32_t aZIndex) = 0;
818 * Gets the widget's z-index.
820 int32_t GetZIndex()
822 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;
846 * Suppress animations that are applied to a window by OS.
848 virtual void SuppressAnimation(bool aSuppress) {}
851 * Return size mode (minimized, maximized, normalized).
852 * Returns a value from nsSizeMode (see nsIWidgetListener.h)
854 virtual nsSizeMode SizeMode() = 0;
857 * Ask wether the widget is fully occluded
859 virtual bool IsFullyOccluded() const = 0;
862 * Enable or disable this Widget
864 * @param aState true to enable the Widget, false to disable it.
866 virtual void Enable(bool aState) = 0;
869 * Ask whether the widget is enabled
871 virtual bool IsEnabled() const = 0;
874 * Request activation of this window or give focus to this widget.
876 * @param aRaise If true, this function requests activation of this
877 * widget's toplevel window.
878 * If false, the appropriate toplevel window (which in
879 * the case of popups may not be this widget's toplevel
880 * window) is already active.
882 virtual nsresult SetFocus(bool aRaise = false) = 0;
885 * Get this widget's outside dimensions relative to its parent widget. For
886 * popup widgets the returned rect is in screen coordinates and not
887 * relative to its parent widget.
889 * @return the x, y, width and height of this widget.
891 virtual LayoutDeviceIntRect GetBounds() = 0;
894 * Get this widget's outside dimensions in device coordinates. This
895 * includes any title bar on the window.
897 * @return the x, y, width and height of this widget.
899 virtual LayoutDeviceIntRect GetScreenBounds() = 0;
902 * Similar to GetScreenBounds except that this function will always
903 * get the size when the widget is in the nsSizeMode_Normal size mode
904 * even if the current size mode is not nsSizeMode_Normal.
905 * This method will fail if the size mode is not nsSizeMode_Normal and
906 * the platform doesn't have the ability.
907 * This method will always succeed if the current size mode is
908 * nsSizeMode_Normal.
910 * @param aRect On return it holds the x, y, width and height of
911 * this widget.
913 virtual MOZ_MUST_USE nsresult
914 GetRestoredBounds(LayoutDeviceIntRect& aRect) = 0;
917 * Get this widget's client area bounds, if the window has a 3D border
918 * appearance this returns the area inside the border. The position is the
919 * position of the client area relative to the client area of the parent
920 * widget (for root widgets and popup widgets it is in screen coordinates).
922 * @return the x, y, width and height of the client area of this widget.
924 virtual LayoutDeviceIntRect GetClientBounds() = 0;
927 * Sets the non-client area dimensions of the window. Pass -1 to restore
928 * the system default frame size for that border. Pass zero to remove
929 * a border, or pass a specific value adjust a border. Units are in
930 * pixels. (DPI dependent)
932 * Platform notes:
933 * Windows: shrinking top non-client height will remove application
934 * icon and window title text. Glass desktops will refuse to set
935 * dimensions between zero and size < system default.
937 virtual nsresult SetNonClientMargins(LayoutDeviceIntMargin& aMargins) = 0;
940 * Get the client offset from the window origin.
942 * @return the x and y of the offset.
944 virtual LayoutDeviceIntPoint GetClientOffset() = 0;
947 * Equivalent to GetClientBounds but only returns the size.
949 virtual LayoutDeviceIntSize GetClientSize() {
950 // Depending on the backend, overloading this method may be useful if
951 // requesting the client offset is expensive.
952 return GetClientBounds().Size();
956 * Set the background color for this widget
958 * @param aColor the new background color
962 virtual void SetBackgroundColor(const nscolor &aColor) { }
965 * Set the cursor for this widget
967 * @param aCursor the new cursor for this widget
969 virtual void SetCursor(nsCursor aCursor) = 0;
972 * If a cursor type is currently cached locally for this widget, clear the
973 * cached cursor to force an update on the next SetCursor call.
976 virtual void ClearCachedCursor() = 0;
979 * Sets an image as the cursor for this widget.
981 * @param aCursor the cursor to set
982 * @param aX the X coordinate of the hotspot (from left).
983 * @param aY the Y coordinate of the hotspot (from top).
984 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
985 * supported
987 virtual nsresult SetCursor(imgIContainer* aCursor,
988 uint32_t aHotspotX, uint32_t aHotspotY) = 0;
991 * Get the window type of this widget.
993 nsWindowType WindowType() { return mWindowType; }
996 * Determines if this widget is one of the three types of plugin widgets.
998 bool IsPlugin() {
999 return mWindowType == eWindowType_plugin ||
1000 mWindowType == eWindowType_plugin_ipc_chrome ||
1001 mWindowType == eWindowType_plugin_ipc_content;
1005 * Set the transparency mode of the top-level window containing this widget.
1006 * So, e.g., if you call this on the widget for an IFRAME, the top level
1007 * browser window containing the IFRAME actually gets set. Be careful.
1009 * This can fail if the platform doesn't support
1010 * transparency/glass. By default widgets are not
1011 * transparent. This will also fail if the toplevel window is not
1012 * a Mozilla window, e.g., if the widget is in an embedded
1013 * context.
1015 * After transparency/glass has been enabled, the initial alpha channel
1016 * value for all pixels is 1, i.e., opaque.
1017 * If the window is resized then the alpha channel values for
1018 * all pixels are reset to 1.
1019 * Pixel RGB color values are already premultiplied with alpha channel values.
1021 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
1024 * Get the transparency mode of the top-level window that contains this
1025 * widget.
1027 virtual nsTransparencyMode GetTransparencyMode() = 0;
1030 * This represents a command to set the bounds and clip region of
1031 * a child widget.
1033 struct Configuration {
1034 nsCOMPtr<nsIWidget> mChild;
1035 uintptr_t mWindowID; // e10s specific, the unique plugin port id
1036 bool mVisible; // e10s specific, widget visibility
1037 LayoutDeviceIntRect mBounds;
1038 nsTArray<LayoutDeviceIntRect> mClipRegion;
1042 * Sets the clip region of each mChild (which must actually be a child
1043 * of this widget) to the union of the pixel rects given in
1044 * mClipRegion, all relative to the top-left of the child
1045 * widget. Clip regions are not implemented on all platforms and only
1046 * need to actually work for children that are plugins.
1048 * Also sets the bounds of each child to mBounds.
1050 * This will invalidate areas of the children that have changed, but
1051 * does not need to invalidate any part of this widget.
1053 * Children should be moved in the order given; the array is
1054 * sorted so to minimize unnecessary invalidation if children are
1055 * moved in that order.
1057 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
1058 virtual nsresult SetWindowClipRegion(const nsTArray<LayoutDeviceIntRect>& aRects,
1059 bool aIntersectWithExisting) = 0;
1062 * Appends to aRects the rectangles constituting this widget's clip
1063 * region. If this widget is not clipped, appends a single rectangle
1064 * (0, 0, bounds.width, bounds.height).
1066 virtual void GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects) = 0;
1069 * Register or unregister native plugin widgets which receive Configuration
1070 * data from the content process via the compositor.
1072 * Lookups are used by the main thread via the compositor to lookup widgets
1073 * based on a unique window id. On Windows and Linux this is the
1074 * NS_NATIVE_PLUGIN_PORT (hwnd/XID). This tracking maintains a reference to
1075 * widgets held. Consumers are responsible for removing widgets from this
1076 * list.
1078 virtual void RegisterPluginWindowForRemoteUpdates() = 0;
1079 virtual void UnregisterPluginWindowForRemoteUpdates() = 0;
1080 static nsIWidget* LookupRegisteredPluginWindow(uintptr_t aWindowID);
1083 * Iterates across the list of registered plugin widgets and updates thier
1084 * visibility based on which plugins are included in the 'visible' list.
1086 * The compositor knows little about tabs, but it does know which plugin
1087 * widgets are currently included in the visible layer tree. It calls this
1088 * helper to hide widgets it knows nothing about.
1090 static void UpdateRegisteredPluginWindowVisibility(uintptr_t aOwnerWidget,
1091 nsTArray<uintptr_t>& aPluginIds);
1093 #if defined(XP_WIN)
1095 * Iterates over the list of registered plugins and for any that are owned
1096 * by aOwnerWidget and visible it takes a snapshot.
1098 * @param aOwnerWidget only captures visible widgets owned by this
1100 static void CaptureRegisteredPlugins(uintptr_t aOwnerWidget);
1103 * Take a scroll capture for this widget if possible.
1105 virtual void UpdateScrollCapture() = 0;
1108 * Creates an async ImageContainer to hold scroll capture images that can be
1109 * used if the plugin is hidden during scroll.
1110 * @return the async container ID of the created ImageContainer.
1112 virtual uint64_t CreateScrollCaptureContainer() = 0;
1113 #endif
1116 * Set the shadow style of the window.
1118 * Ignored on child widgets and on non-Mac platforms.
1120 virtual void SetWindowShadowStyle(int32_t aStyle) = 0;
1123 * Set the opacity of the window.
1124 * Values need to be between 0.0f (invisible) and 1.0f (fully opaque).
1126 * Ignored on child widgets and on non-Mac platforms.
1128 virtual void SetWindowOpacity(float aOpacity) {}
1131 * Set the transform of the window. Values are in device pixels,
1132 * the origin is the top left corner of the window.
1134 * Ignored on child widgets and on non-Mac platforms.
1136 virtual void SetWindowTransform(const mozilla::gfx::Matrix& aTransform) {}
1139 * On Mac OS X, this method shows or hides the pill button in the titlebar
1140 * that's used to collapse the toolbar.
1142 * Ignored on child widgets and on non-Mac platforms.
1144 virtual void SetShowsToolbarButton(bool aShow) = 0;
1147 * On Mac OS X Lion, this method shows or hides the full screen button in
1148 * the titlebar that handles native full screen mode.
1150 * Ignored on child widgets, non-Mac platforms, & pre-Lion Mac.
1152 virtual void SetShowsFullScreenButton(bool aShow) = 0;
1154 enum WindowAnimationType {
1155 eGenericWindowAnimation,
1156 eDocumentWindowAnimation
1160 * Sets the kind of top-level window animation this widget should have. On
1161 * Mac OS X, this causes a particular kind of animation to be shown when the
1162 * window is first made visible.
1164 * Ignored on child widgets and on non-Mac platforms.
1166 virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
1169 * Specifies whether the window title should be drawn even if the window
1170 * contents extend into the titlebar. Ignored on windows that don't draw
1171 * in the titlebar. Only implemented on OS X.
1173 virtual void SetDrawsTitle(bool aDrawTitle) {}
1176 * Indicates whether the widget should attempt to make titlebar controls
1177 * easier to see on dark titlebar backgrounds.
1179 virtual void SetUseBrightTitlebarForeground(bool aBrightForeground) {}
1182 * Hide window chrome (borders, buttons) for this widget.
1185 virtual void HideWindowChrome(bool aShouldHide) = 0;
1187 enum FullscreenTransitionStage
1189 eBeforeFullscreenToggle,
1190 eAfterFullscreenToggle
1194 * Prepares for fullscreen transition and returns whether the widget
1195 * supports fullscreen transition. If this method returns false,
1196 * PerformFullscreenTransition() must never be called. Otherwise,
1197 * caller should call that method twice with "before" and "after"
1198 * stages respectively in order. In the latter case, this method may
1199 * return some data via aData pointer. Caller must pass that data to
1200 * PerformFullscreenTransition() if any, and caller is responsible
1201 * for releasing that data.
1203 virtual bool PrepareForFullscreenTransition(nsISupports** aData) = 0;
1206 * Performs fullscreen transition. This method returns immediately,
1207 * and will post aCallback to the main thread when the transition
1208 * finishes.
1210 virtual void PerformFullscreenTransition(FullscreenTransitionStage aStage,
1211 uint16_t aDuration,
1212 nsISupports* aData,
1213 nsIRunnable* aCallback) = 0;
1216 * Return the screen the widget is in, or null if we don't know.
1218 virtual already_AddRefed<nsIScreen> GetWidgetScreen() = 0;
1221 * Put the toplevel window into or out of fullscreen mode.
1222 * If aTargetScreen is given, attempt to go fullscreen on that screen,
1223 * if possible. (If not, it behaves as if aTargetScreen is null.)
1224 * If !aFullScreen, aTargetScreen is ignored.
1225 * aTargetScreen support is currently only implemented on Windows.
1227 * @return NS_OK if the widget is setup properly for fullscreen and
1228 * FullscreenChanged callback has been or will be called. If other
1229 * value is returned, the caller should continue the change itself.
1231 virtual nsresult MakeFullScreen(bool aFullScreen,
1232 nsIScreen* aTargetScreen = nullptr) = 0;
1235 * Same as MakeFullScreen, except that, on systems which natively
1236 * support fullscreen transition, calling this method explicitly
1237 * requests that behavior.
1238 * It is currently only supported on OS X 10.7+.
1240 virtual nsresult MakeFullScreenWithNativeTransition(
1241 bool aFullScreen, nsIScreen* aTargetScreen = nullptr)
1243 return MakeFullScreen(aFullScreen, aTargetScreen);
1247 * Invalidate a specified rect for a widget so that it will be repainted
1248 * later.
1250 virtual void Invalidate(const LayoutDeviceIntRect& aRect) = 0;
1252 enum LayerManagerPersistence
1254 LAYER_MANAGER_CURRENT = 0,
1255 LAYER_MANAGER_PERSISTENT
1259 * Return the widget's LayerManager. The layer tree for that
1260 * LayerManager is what gets rendered to the widget.
1262 inline LayerManager* GetLayerManager()
1264 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1265 LAYER_MANAGER_CURRENT);
1268 inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence)
1270 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1271 aPersistence);
1275 * Like GetLayerManager(), but prefers creating a layer manager of
1276 * type |aBackendHint| instead of what would normally be created.
1277 * LayersBackend::LAYERS_NONE means "no hint".
1279 virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager,
1280 LayersBackend aBackendHint,
1281 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT) = 0;
1284 * Called before each layer manager transaction to allow any preparation
1285 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1287 * Always called on the main thread.
1289 virtual void PrepareWindowEffects() = 0;
1292 * Called on the main thread at the end of WebRender display list building.
1294 virtual void AddWindowOverlayWebRenderCommands(mozilla::layers::WebRenderBridgeChild* aWrBridge,
1295 mozilla::wr::DisplayListBuilder& aBuilder,
1296 mozilla::wr::IpcResourceUpdateQueue& aResources) {}
1299 * Called when Gecko knows which themed widgets exist in this window.
1300 * The passed array contains an entry for every themed widget of the right
1301 * type (currently only NS_THEME_TOOLBAR) within the window, except for
1302 * themed widgets which are transformed or have effects applied to them
1303 * (e.g. CSS opacity or filters).
1304 * This could sometimes be called during display list construction
1305 * outside of painting.
1306 * If called during painting, it will be called before we actually
1307 * paint anything.
1309 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1312 * Informs the widget about the region of the window that is opaque.
1314 * @param aOpaqueRegion the region of the window that is opaque.
1316 virtual void UpdateOpaqueRegion(const LayoutDeviceIntRegion& aOpaqueRegion) {}
1319 * Informs the widget about the region of the window that is draggable.
1321 virtual void UpdateWindowDraggingRegion(const LayoutDeviceIntRegion& aRegion) {}
1324 * Tells the widget whether the given input block results in a swipe.
1325 * Should be called in response to a WidgetWheelEvent that has
1326 * mFlags.mCanTriggerSwipe set on it.
1328 virtual void ReportSwipeStarted(uint64_t aInputBlockId, bool aStartSwipe) {}
1331 * Internal methods
1334 //@{
1335 virtual void AddChild(nsIWidget* aChild) = 0;
1336 virtual void RemoveChild(nsIWidget* aChild) = 0;
1337 virtual void* GetNativeData(uint32_t aDataType) = 0;
1338 virtual void SetNativeData(uint32_t aDataType, uintptr_t aVal) = 0;
1339 virtual void FreeNativeData(void * data, uint32_t aDataType) = 0;//~~~
1341 //@}
1344 * Set the widget's title.
1345 * Must be called after Create.
1347 * @param aTitle string displayed as the title of the widget
1349 virtual nsresult SetTitle(const nsAString& aTitle) = 0;
1352 * Set the widget's icon.
1353 * Must be called after Create.
1355 * @param aIconSpec string specifying the icon to use; convention is to
1356 * pass a resource: URL from which a platform-dependent
1357 * resource file name will be constructed
1359 virtual void SetIcon(const nsAString& aIconSpec) = 0;
1362 * Return this widget's origin in screen coordinates.
1364 * @return screen coordinates stored in the x,y members
1366 virtual LayoutDeviceIntPoint WidgetToScreenOffset() = 0;
1369 * Given the specified client size, return the corresponding window size,
1370 * which includes the area for the borders and titlebar. This method
1371 * should work even when the window is not yet visible.
1373 virtual LayoutDeviceIntSize ClientToWindowSize(
1374 const LayoutDeviceIntSize& aClientSize) = 0;
1377 * Dispatches an event to the widget
1379 virtual nsresult DispatchEvent(mozilla::WidgetGUIEvent* event,
1380 nsEventStatus & aStatus) = 0;
1383 * Dispatches an event to APZ only.
1384 * No-op in the child process.
1386 virtual void DispatchEventToAPZOnly(mozilla::WidgetInputEvent* aEvent) = 0;
1389 * Dispatches an event that must be handled by APZ first, when APZ is
1390 * enabled. If invoked in the child process, it is forwarded to the
1391 * parent process synchronously.
1393 virtual nsEventStatus DispatchInputEvent(mozilla::WidgetInputEvent* aEvent) = 0;
1396 * Confirm an APZ-aware event target. This should be used when APZ will
1397 * not need a layers update to process the event.
1399 virtual void SetConfirmedTargetAPZC(uint64_t aInputBlockId,
1400 const nsTArray<ScrollableLayerGuid>& aTargets) const = 0;
1403 * Returns true if APZ is in use, false otherwise.
1405 virtual bool AsyncPanZoomEnabled() const = 0;
1408 * Enables the dropping of files to a widget.
1410 virtual void EnableDragDrop(bool aEnable) = 0;
1411 virtual nsresult AsyncEnableDragDrop(bool aEnable) = 0;
1414 * Enables/Disables system mouse capture.
1415 * @param aCapture true enables mouse capture, false disables mouse capture
1418 virtual void CaptureMouse(bool aCapture) = 0;
1421 * Classify the window for the window manager. Mostly for X11.
1423 virtual void SetWindowClass(const nsAString& xulWinType) = 0;
1426 * Enables/Disables system capture of any and all events that would cause a
1427 * popup to be rolled up. aListener should be set to a non-null value for
1428 * any popups that are not managed by the popup manager.
1429 * @param aDoCapture true enables capture, false disables capture
1432 virtual void CaptureRollupEvents(nsIRollupListener* aListener,
1433 bool aDoCapture) = 0;
1436 * Bring this window to the user's attention. This is intended to be a more
1437 * gentle notification than popping the window to the top or putting up an
1438 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1439 * the Mac. The notification should be suppressed if the window is already
1440 * in the foreground and should be dismissed when the user brings this window
1441 * to the foreground.
1442 * @param aCycleCount Maximum number of times to animate the window per system
1443 * conventions. If set to -1, cycles indefinitely until
1444 * window is brought into the foreground.
1446 virtual MOZ_MUST_USE nsresult GetAttention(int32_t aCycleCount) = 0;
1449 * Ask whether there user input events pending. All input events are
1450 * included, including those not targeted at this nsIwidget instance.
1452 virtual bool HasPendingInputEvent() = 0;
1455 * If set to true, the window will draw its contents into the titlebar
1456 * instead of below it.
1458 * Ignored on any platform that does not support it. Ignored by widgets that
1459 * do not represent windows.
1460 * May result in a resize event, so should only be called from places where
1461 * reflow and painting is allowed.
1463 * @param aState Whether drawing into the titlebar should be activated.
1465 virtual void SetDrawsInTitlebar(bool aState) = 0;
1468 * Determine whether the widget shows a resize widget. If it does,
1469 * aResizerRect returns the resizer's rect.
1471 * Returns false on any platform that does not support it.
1473 * @param aResizerRect The resizer's rect in device pixels.
1474 * @return Whether a resize widget is shown.
1476 virtual bool ShowsResizeIndicator(LayoutDeviceIntRect* aResizerRect) = 0;
1479 * Begin a window resizing drag, based on the event passed in.
1481 virtual MOZ_MUST_USE nsresult
1482 BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
1483 int32_t aHorizontal,
1484 int32_t aVertical) = 0;
1487 * Begin a window moving drag, based on the event passed in.
1489 virtual MOZ_MUST_USE nsresult
1490 BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) = 0;
1492 enum Modifiers {
1493 CAPS_LOCK = 0x01, // when CapsLock is active
1494 NUM_LOCK = 0x02, // when NumLock is active
1495 SHIFT_L = 0x0100,
1496 SHIFT_R = 0x0200,
1497 CTRL_L = 0x0400,
1498 CTRL_R = 0x0800,
1499 ALT_L = 0x1000, // includes Option
1500 ALT_R = 0x2000,
1501 COMMAND_L = 0x4000,
1502 COMMAND_R = 0x8000,
1503 HELP = 0x10000,
1504 FUNCTION = 0x100000,
1505 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1508 * Utility method intended for testing. Dispatches native key events
1509 * to this widget to simulate the press and release of a key.
1510 * @param aNativeKeyboardLayout a *platform-specific* constant.
1511 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1512 * On Windows, it is converted to a hex string and passed to
1513 * LoadKeyboardLayout, see
1514 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1515 * @param aNativeKeyCode a *platform-specific* keycode.
1516 * On Windows, this is the virtual key code.
1517 * @param aModifiers some combination of the above 'Modifiers' flags;
1518 * not all flags will apply to all platforms. Mac ignores the _R
1519 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1520 * FUNCTION.
1521 * @param aCharacters characters that the OS would decide to generate
1522 * from the event. On Windows, this is the charCode passed by
1523 * WM_CHAR.
1524 * @param aUnmodifiedCharacters characters that the OS would decide
1525 * to generate from the event if modifier keys (other than shift)
1526 * were assumed inactive. Needed on Mac, ignored on Windows.
1527 * @param aObserver the observer that will get notified once the events
1528 * have been dispatched.
1529 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1530 * layout is not supported and the event was not fired
1532 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
1533 int32_t aNativeKeyCode,
1534 uint32_t aModifierFlags,
1535 const nsAString& aCharacters,
1536 const nsAString& aUnmodifiedCharacters,
1537 nsIObserver* aObserver) = 0;
1540 * Utility method intended for testing. Dispatches native mouse events
1541 * may even move the mouse cursor. On Mac the events are guaranteed to
1542 * be sent to the window containing this widget, but on Windows they'll go
1543 * to whatever's topmost on the screen at that position, so for
1544 * cross-platform testing ensure that your window is at the top of the
1545 * z-order.
1546 * @param aPoint screen location of the mouse, in device
1547 * pixels, with origin at the top left
1548 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
1549 * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
1550 * @param aModifierFlags *platform-specific* modifier flags (ignored
1551 * on Windows)
1552 * @param aObserver the observer that will get notified once the events
1553 * have been dispatched.
1555 virtual nsresult SynthesizeNativeMouseEvent(LayoutDeviceIntPoint aPoint,
1556 uint32_t aNativeMessage,
1557 uint32_t aModifierFlags,
1558 nsIObserver* aObserver) = 0;
1561 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native message.
1562 * aPoint is location in device pixels to which the mouse pointer moves to.
1563 * @param aObserver the observer that will get notified once the events
1564 * have been dispatched.
1566 virtual nsresult SynthesizeNativeMouseMove(LayoutDeviceIntPoint aPoint,
1567 nsIObserver* aObserver) = 0;
1570 * Utility method intended for testing. Dispatching native mouse scroll
1571 * events may move the mouse cursor.
1573 * @param aPoint Mouse cursor position in screen coordinates.
1574 * In device pixels, the origin at the top left of
1575 * the primary display.
1576 * @param aNativeMessage Platform native message.
1577 * @param aDeltaX The delta value for X direction. If the native
1578 * message doesn't indicate X direction scrolling,
1579 * this may be ignored.
1580 * @param aDeltaY The delta value for Y direction. If the native
1581 * message doesn't indicate Y direction scrolling,
1582 * this may be ignored.
1583 * @param aDeltaZ The delta value for Z direction. If the native
1584 * message doesn't indicate Z direction scrolling,
1585 * this may be ignored.
1586 * @param aModifierFlags Must be values of Modifiers, or zero.
1587 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1588 * document.
1589 * @param aObserver The observer that will get notified once the
1590 * events have been dispatched.
1592 virtual nsresult SynthesizeNativeMouseScrollEvent(LayoutDeviceIntPoint aPoint,
1593 uint32_t aNativeMessage,
1594 double aDeltaX,
1595 double aDeltaY,
1596 double aDeltaZ,
1597 uint32_t aModifierFlags,
1598 uint32_t aAdditionalFlags,
1599 nsIObserver* aObserver) = 0;
1602 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1603 * touch states in nsIDOMWindowUtils.idl.
1605 enum TouchPointerState {
1606 // The pointer is in a hover state above the digitizer
1607 TOUCH_HOVER = (1 << 0),
1608 // The pointer is in contact with the digitizer
1609 TOUCH_CONTACT = (1 << 1),
1610 // The pointer has been removed from the digitizer detection area
1611 TOUCH_REMOVE = (1 << 2),
1612 // The pointer has been canceled. Will cancel any pending os level
1613 // gestures that would triggered as a result of completion of the
1614 // input sequence. This may not cancel moz platform related events
1615 // that might get tirggered by input already delivered.
1616 TOUCH_CANCEL = (1 << 3),
1618 // ALL_BITS used for validity checking during IPC serialization
1619 ALL_BITS = (1 << 4) - 1
1623 * Create a new or update an existing touch pointer on the digitizer.
1624 * To trigger os level gestures, individual touch points should
1625 * transition through a complete set of touch states which should be
1626 * sent as individual messages.
1628 * @param aPointerId The touch point id to create or update.
1629 * @param aPointerState one or more of the touch states listed above
1630 * @param aPoint coords of this event
1631 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1632 * @param aOrientation 0 -> 359 degree value indicating the
1633 * orientation of the pointer. Use 90 for normal taps.
1634 * @param aObserver The observer that will get notified once the events
1635 * have been dispatched.
1637 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
1638 TouchPointerState aPointerState,
1639 LayoutDeviceIntPoint aPoint,
1640 double aPointerPressure,
1641 uint32_t aPointerOrientation,
1642 nsIObserver* aObserver) = 0;
1645 * Helper for simulating a simple tap event with one touch point. When
1646 * aLongTap is true, simulates a native long tap with a duration equal to
1647 * ui.click_hold_context_menus.delay. This pref is compatible with the
1648 * apzc long tap duration. Defaults to 1.5 seconds.
1649 * @param aObserver The observer that will get notified once the events
1650 * have been dispatched.
1652 virtual nsresult SynthesizeNativeTouchTap(LayoutDeviceIntPoint aPoint,
1653 bool aLongTap,
1654 nsIObserver* aObserver);
1657 * Cancels all active simulated touch input points and pending long taps.
1658 * Native widgets should track existing points such that they can clear the
1659 * digitizer state when this call is made.
1660 * @param aObserver The observer that will get notified once the touch
1661 * sequence has been cleared.
1663 virtual nsresult ClearNativeTouchSequence(nsIObserver* aObserver);
1665 virtual void StartAsyncScrollbarDrag(const AsyncDragMetrics& aDragMetrics) = 0;
1668 * Notify APZ to start autoscrolling.
1669 * @param aAnchorLocation the location of the autoscroll anchor
1670 * @param aGuid identifies the scroll frame to be autoscrolled
1671 * @return true if APZ has been successfully notified
1673 virtual bool StartAsyncAutoscroll(const ScreenPoint& aAnchorLocation,
1674 const ScrollableLayerGuid& aGuid) = 0;
1677 * Notify APZ to stop autoscrolling.
1678 * @param aGuid identifies the scroll frame which is being autoscrolled.
1680 virtual void StopAsyncAutoscroll(const ScrollableLayerGuid& aGuid) = 0;
1682 // If this widget supports out-of-process compositing, it can override
1683 // this method to provide additional information to the compositor.
1684 virtual void GetCompositorWidgetInitData(mozilla::widget::CompositorWidgetInitData* aInitData)
1687 private:
1688 class LongTapInfo
1690 public:
1691 LongTapInfo(int32_t aPointerId, LayoutDeviceIntPoint& aPoint,
1692 mozilla::TimeDuration aDuration,
1693 nsIObserver* aObserver) :
1694 mPointerId(aPointerId),
1695 mPosition(aPoint),
1696 mDuration(aDuration),
1697 mObserver(aObserver),
1698 mStamp(mozilla::TimeStamp::Now())
1702 int32_t mPointerId;
1703 LayoutDeviceIntPoint mPosition;
1704 mozilla::TimeDuration mDuration;
1705 nsCOMPtr<nsIObserver> mObserver;
1706 mozilla::TimeStamp mStamp;
1709 static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure);
1711 mozilla::UniquePtr<LongTapInfo> mLongTapTouchPoint;
1712 nsCOMPtr<nsITimer> mLongTapTimer;
1713 static int32_t sPointerIdCounter;
1715 public:
1717 * If key events have not been handled by content or XBL handlers, they can
1718 * be offered to the system (for custom application shortcuts set in system
1719 * preferences, for example).
1721 virtual void
1722 PostHandleKeyEvent(mozilla::WidgetKeyboardEvent* aEvent);
1725 * Activates a native menu item at the position specified by the index
1726 * string. The index string is a string of positive integers separated
1727 * by the "|" (pipe) character. The last integer in the string represents
1728 * the item index in a submenu located using the integers preceding it.
1730 * Example: 1|0|4
1731 * In this string, the first integer represents the top-level submenu
1732 * in the native menu bar. Since the integer is 1, it is the second submeu
1733 * in the native menu bar. Within that, the first item (index 0) is a
1734 * submenu, and we want to activate the 5th item within that submenu.
1736 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1739 * This is used for native menu system testing.
1741 * Updates a native menu at the position specified by the index string.
1742 * The index string is a string of positive integers separated by the "|"
1743 * (pipe) character.
1745 * Example: 1|0|4
1746 * In this string, the first integer represents the top-level submenu
1747 * in the native menu bar. Since the integer is 1, it is the second submeu
1748 * in the native menu bar. Within that, the first item (index 0) is a
1749 * submenu, and we want to update submenu at index 4 within that submenu.
1751 * If this is called with an empty string it forces a full reload of the
1752 * menu system.
1754 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1757 * This is used for testing macOS service menu code.
1759 * @param aResult - the current text selection. Is empty if no selection.
1760 * @return nsresult - whether or not aResult was assigned the selected text.
1762 virtual MOZ_MUST_USE nsresult
1763 GetSelectionAsPlaintext(nsAString& aResult)
1765 return NS_ERROR_NOT_IMPLEMENTED;
1769 * Notify IME of the specified notification.
1771 * @return If the notification is mouse button event and it's consumed by
1772 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1774 virtual nsresult NotifyIME(const IMENotification& aIMENotification) = 0;
1777 * Start plugin IME. If this results in a string getting committed, the
1778 * result is in aCommitted (otherwise aCommitted is empty).
1780 * aKeyboardEvent The event with which plugin IME is to be started
1781 * panelX and panelY Location in screen coordinates of the IME input panel
1782 * (should be just under the plugin)
1783 * aCommitted The string committed during IME -- otherwise empty
1785 virtual MOZ_MUST_USE nsresult
1786 StartPluginIME(const mozilla::WidgetKeyboardEvent& aKeyboardEvent,
1787 int32_t aPanelX, int32_t aPanelY,
1788 nsString& aCommitted) = 0;
1791 * Tells the widget whether or not a plugin (inside the widget) has the
1792 * keyboard focus. Should be sent when the keyboard focus changes too or
1793 * from a plugin.
1795 * aFocused Whether or not a plugin is focused
1797 virtual void SetPluginFocused(bool& aFocused) = 0;
1800 * Tell the plugin has focus. It is unnecessary to use IPC
1802 bool PluginHasFocus()
1804 return GetInputContext().mIMEState.mEnabled == IMEState::PLUGIN;
1808 * Set IME candidate window position by windowless plugin.
1810 virtual void SetCandidateWindowForPlugin(
1811 const mozilla::widget::CandidateWindowPosition& aPosition) = 0;
1814 * Handle default action when PluginEvent isn't handled
1816 virtual void DefaultProcOfPluginEvent(
1817 const mozilla::WidgetPluginEvent& aEvent) = 0;
1820 * Notifies the input context changes.
1822 virtual void SetInputContext(const InputContext& aContext,
1823 const InputContextAction& aAction) = 0;
1826 * Get current input context.
1828 virtual InputContext GetInputContext() = 0;
1831 * Get native IME context. This is different from GetNativeData() with
1832 * NS_RAW_NATIVE_IME_CONTEXT, the result is unique even if in a remote
1833 * process.
1835 virtual NativeIMEContext GetNativeIMEContext();
1838 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1839 * native (OS-level) event for it. This method allows tests to simulate
1840 * keystrokes that trigger native key bindings (which require a native
1841 * event).
1843 virtual MOZ_MUST_USE nsresult
1844 AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) = 0;
1847 * Retrieve edit commands when the key combination of aEvent is used
1848 * in platform native applications.
1850 enum NativeKeyBindingsType : uint8_t
1852 NativeKeyBindingsForSingleLineEditor,
1853 NativeKeyBindingsForMultiLineEditor,
1854 NativeKeyBindingsForRichTextEditor
1856 virtual void GetEditCommands(NativeKeyBindingsType aType,
1857 const mozilla::WidgetKeyboardEvent& aEvent,
1858 nsTArray<mozilla::CommandInt>& aCommands);
1861 * Retrieves a reference to notification requests of IME. Note that the
1862 * reference is valid while the nsIWidget instance is alive. So, if you
1863 * need to store the reference for a long time, you need to grab the widget
1864 * instance too.
1866 const IMENotificationRequests& IMENotificationRequestsRef();
1869 * Call this method when a dialog is opened which has a default button.
1870 * The button's rectangle should be supplied in aButtonRect.
1872 virtual MOZ_MUST_USE nsresult
1873 OnDefaultButtonLoaded(const LayoutDeviceIntRect& aButtonRect) = 0;
1876 * Return true if this process shouldn't use platform widgets, and
1877 * so should use PuppetWidgets instead. If this returns true, the
1878 * result of creating and using a platform widget is undefined,
1879 * and likely to end in crashes or other buggy behavior.
1881 static bool
1882 UsePuppetWidgets()
1884 return XRE_IsContentProcess();
1888 * Allocate and return a "puppet widget" that doesn't directly
1889 * correlate to a platform widget; platform events and data must
1890 * be fed to it. Currently used in content processes. NULL is
1891 * returned if puppet widgets aren't supported in this build
1892 * config, on this platform, or for this process type.
1894 * This function is called "Create" to match CreateInstance().
1895 * The returned widget must still be nsIWidget::Create()d.
1897 static already_AddRefed<nsIWidget>
1898 CreatePuppetWidget(TabChild* aTabChild);
1900 static already_AddRefed<nsIWidget>
1901 CreateHeadlessWidget();
1904 * Allocate and return a "plugin proxy widget", a subclass of PuppetWidget
1905 * used in wrapping a PPluginWidget connection for remote widgets. Note
1906 * this call creates the base object, it does not create the widget. Use
1907 * nsIWidget's Create to do this.
1909 static already_AddRefed<nsIWidget>
1910 CreatePluginProxyWidget(TabChild* aTabChild,
1911 mozilla::plugins::PluginWidgetChild* aActor);
1914 * Reparent this widget's native widget.
1915 * @param aNewParent the native widget of aNewParent is the new native
1916 * parent widget
1918 virtual void ReparentNativeWidget(nsIWidget* aNewParent) = 0;
1921 * Return true if widget has it's own GL context
1923 virtual bool HasGLContext() { return false; }
1926 * Returns true to indicate that this widget paints an opaque background
1927 * that we want to be visible under the page, so layout should not force
1928 * a default background.
1930 virtual bool WidgetPaintsBackground() { return false; }
1932 virtual bool NeedsPaint() {
1933 return IsVisible() && !GetBounds().IsEmpty();
1937 * Get the natural bounds of this widget. This method is only
1938 * meaningful for widgets for which Gecko implements screen
1939 * rotation natively. When this is the case, GetBounds() returns
1940 * the widget bounds taking rotation into account, and
1941 * GetNaturalBounds() returns the bounds *not* taking rotation
1942 * into account.
1944 * No code outside of the composition pipeline should know or care
1945 * about this. If you're not an agent of the compositor, you
1946 * probably shouldn't call this method.
1948 virtual LayoutDeviceIntRect GetNaturalBounds() {
1949 return GetBounds();
1953 * Set size constraints on the window size such that it is never less than
1954 * the specified minimum size and never larger than the specified maximum
1955 * size. The size constraints are sizes of the outer rectangle including
1956 * the window frame and title bar. Use 0 for an unconstrained minimum size
1957 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1958 * does not necessarily change the size of a window to conform to this size,
1959 * thus Resize should be called afterwards.
1961 * @param aConstraints: the size constraints in device pixels
1963 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
1966 * Return the size constraints currently observed by the widget.
1968 * @return the constraints in device pixels
1970 virtual const SizeConstraints GetSizeConstraints() = 0;
1973 * If this is owned by a TabChild, return that. Otherwise return
1974 * null.
1976 virtual TabChild* GetOwningTabChild() { return nullptr; }
1979 * If this isn't directly compositing to its window surface,
1980 * return the compositor which is doing that on our behalf.
1982 virtual CompositorBridgeChild* GetRemoteRenderer()
1983 { return nullptr; }
1986 * Returns true if the widget requires synchronous repaints on resize,
1987 * false otherwise.
1989 virtual bool SynchronouslyRepaintOnResize()
1990 { return true; }
1993 * Some platforms (only cocoa right now) round widget coordinates to the
1994 * nearest even pixels (see bug 892994), this function allows us to
1995 * determine how widget coordinates will be rounded.
1997 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
1999 virtual void UpdateZoomConstraints(const uint32_t& aPresShellId,
2000 const FrameMetrics::ViewID& aViewId,
2001 const mozilla::Maybe<ZoomConstraints>& aConstraints) {};
2004 * GetTextEventDispatcher() returns TextEventDispatcher belonging to the
2005 * widget. Note that this never returns nullptr.
2007 virtual TextEventDispatcher* GetTextEventDispatcher() = 0;
2010 * GetNativeTextEventDispatcherListener() returns a
2011 * TextEventDispatcherListener instance which is used when the widget
2012 * instance handles native IME and/or keyboard events.
2014 virtual TextEventDispatcherListener*
2015 GetNativeTextEventDispatcherListener() = 0;
2017 virtual void ZoomToRect(const uint32_t& aPresShellId,
2018 const FrameMetrics::ViewID& aViewId,
2019 const CSSRect& aRect,
2020 const uint32_t& aFlags) = 0;
2023 * OnWindowedPluginKeyEvent() is called when native key event is
2024 * received in the focused plugin process directly in PluginInstanceChild.
2026 * @param aKeyEventData The native key event data. The actual type
2027 * copied into NativeEventData depends on the
2028 * caller. Please check PluginInstanceChild.
2029 * @param aCallback Callback interface. When this returns
2030 * NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY,
2031 * the event handler has to call this callback.
2032 * Otherwise, the caller should do that instead.
2033 * @return NS_ERROR_* if this fails to handle the event.
2034 * NS_SUCCESS_EVENT_CONSUMED if the key event is
2035 * consumed.
2036 * NS_OK if the key event isn't consumed.
2037 * NS_SUCCESS_EVENT_HANDLED_ASYNCHRONOUSLY if the
2038 * key event will be handled asynchronously.
2040 virtual nsresult OnWindowedPluginKeyEvent(
2041 const mozilla::NativeEventData& aKeyEventData,
2042 nsIKeyEventInPluginCallback* aCallback);
2046 * LookUpDictionary shows the dictionary for the word around current point.
2048 * @param aText the word to look up dictiorary.
2049 * @param aFontRangeArray text decoration of aText
2050 * @param aIsVertical true if the word is vertical layout
2051 * @param aPoint top-left point of aText
2053 virtual void LookUpDictionary(
2054 const nsAString& aText,
2055 const nsTArray<mozilla::FontRange>& aFontRangeArray,
2056 const bool aIsVertical,
2057 const LayoutDeviceIntPoint& aPoint)
2060 #if defined(MOZ_WIDGET_ANDROID)
2062 * RecvToolbarAnimatorMessageFromCompositor receive message from compositor thread.
2064 * @param aMessage message being sent to Android UI thread.
2066 virtual void RecvToolbarAnimatorMessageFromCompositor(int32_t aMessage) = 0;
2069 * UpdateRootFrameMetrics steady state frame metrics send from compositor thread
2071 * @param aScrollOffset page scroll offset value in screen pixels.
2072 * @param aZoom current page zoom.
2074 virtual void UpdateRootFrameMetrics(const ScreenPoint& aScrollOffset, const CSSToScreenScale& aZoom) = 0;
2077 * RecvScreenPixels Buffer containing the pixel from the frame buffer. Used for android robocop tests.
2079 * @param aMem shared memory containing the frame buffer pixels.
2080 * @param aSize size of the buffer in screen pixels.
2082 virtual void RecvScreenPixels(mozilla::ipc::Shmem&& aMem, const ScreenIntSize& aSize) = 0;
2083 #endif
2085 protected:
2087 * Like GetDefaultScale, but taking into account only the system settings
2088 * and ignoring Gecko preferences.
2090 virtual double GetDefaultScaleInternal() { return 1.0; }
2092 // keep the list of children. We also keep track of our siblings.
2093 // The ownership model is as follows: parent holds a strong ref to
2094 // the first element of the list, and each element holds a strong
2095 // ref to the next element in the list. The prevsibling and
2096 // lastchild pointers are weak, which is fine as long as they are
2097 // maintained properly.
2098 nsCOMPtr<nsIWidget> mFirstChild;
2099 nsIWidget* MOZ_NON_OWNING_REF mLastChild;
2100 nsCOMPtr<nsIWidget> mNextSibling;
2101 nsIWidget* MOZ_NON_OWNING_REF mPrevSibling;
2102 // When Destroy() is called, the sub class should set this true.
2103 bool mOnDestroyCalled;
2104 nsWindowType mWindowType;
2105 int32_t mZIndex;
2108 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
2110 #endif // nsIWidget_h__