Backed out changeset 3732f69b6d81 (bug 843019) for mochitest-bc failures.
[gecko.git] / widget / nsIWidget.h
blob865f345c92d2cf1b68ce0e3830f0bec9dc55b202
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 "nsISupports.h"
10 #include "nsColor.h"
11 #include "nsRect.h"
12 #include "nsStringGlue.h"
14 #include "nsCOMPtr.h"
15 #include "nsWidgetInitData.h"
16 #include "nsTArray.h"
17 #include "nsXULAppAPI.h"
18 #include "mozilla/EventForwards.h"
19 #include "mozilla/layers/LayersTypes.h"
20 #include "mozilla/RefPtr.h"
21 #include "Units.h"
23 // forward declarations
24 class nsFontMetrics;
25 class nsRenderingContext;
26 class nsDeviceContext;
27 struct nsFont;
28 class nsIRollupListener;
29 class imgIContainer;
30 class gfxASurface;
31 class nsIContent;
32 class ViewWrapper;
33 class nsIWidgetListener;
34 class nsIntRegion;
36 namespace mozilla {
37 namespace dom {
38 class TabChild;
40 namespace layers {
41 class Composer2D;
42 class CompositorChild;
43 class LayerManager;
44 class PLayerTransactionChild;
46 namespace gfx {
47 class DrawTarget;
51 /**
52 * Callback function that processes events.
54 * The argument is actually a subtype (subclass) of nsEvent which carries
55 * platform specific information about the event. Platform specific code
56 * knows how to deal with it.
58 * The return value determines whether or not the default action should take
59 * place.
61 typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
63 // Hide the native window system's real window type so as to avoid
64 // including native window system types and APIs. This is necessary
65 // to ensure cross-platform code.
66 typedef void* nsNativeWidget;
68 /**
69 * Flags for the getNativeData function.
70 * See getNativeData()
72 #define NS_NATIVE_WINDOW 0
73 #define NS_NATIVE_GRAPHIC 1
74 #define NS_NATIVE_TMP_WINDOW 2
75 #define NS_NATIVE_WIDGET 3
76 #define NS_NATIVE_DISPLAY 4
77 #define NS_NATIVE_REGION 5
78 #define NS_NATIVE_OFFSETX 6
79 #define NS_NATIVE_OFFSETY 7
80 #define NS_NATIVE_PLUGIN_PORT 8
81 #define NS_NATIVE_SCREEN 9
82 // The toplevel GtkWidget containing this nsIWidget:
83 #define NS_NATIVE_SHELLWIDGET 10
84 // Has to match to NPNVnetscapeWindow, and shareable across processes
85 // HWND on Windows and XID on X11
86 #define NS_NATIVE_SHAREABLE_WINDOW 11
87 #ifdef XP_MACOSX
88 #define NS_NATIVE_PLUGIN_PORT_QD 100
89 #define NS_NATIVE_PLUGIN_PORT_CG 101
90 #endif
91 #ifdef XP_WIN
92 #define NS_NATIVE_TSF_THREAD_MGR 100
93 #define NS_NATIVE_TSF_CATEGORY_MGR 101
94 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
95 #define NS_NATIVE_ICOREWINDOW 103 // winrt specific
96 #endif
98 #define NS_IWIDGET_IID \
99 { 0x1ebdb596, 0x0f90, 0x4f02, \
100 { 0x97, 0x07, 0x4e, 0xc1, 0x16, 0xcd, 0x54, 0xf6 } }
103 * Window shadow styles
104 * Also used for the -moz-window-shadow CSS property
107 #define NS_STYLE_WINDOW_SHADOW_NONE 0
108 #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
109 #define NS_STYLE_WINDOW_SHADOW_MENU 2
110 #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3
111 #define NS_STYLE_WINDOW_SHADOW_SHEET 4
114 * Transparency modes
117 enum nsTransparencyMode {
118 eTransparencyOpaque = 0, // Fully opaque
119 eTransparencyTransparent, // Parts of the window may be transparent
120 eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass effect applied
121 eTransparencyBorderlessGlass // As above, but without a border around the opaque areas when there would otherwise be one with eTransparencyGlass
125 * Cursor types.
128 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
129 eCursor_standard,
130 ///(system is busy, usually rendered as a hourglass or watch)
131 eCursor_wait,
132 ///(Selecting something, usually rendered as an IBeam)
133 eCursor_select,
134 ///(can hyper-link, usually rendered as a human hand)
135 eCursor_hyperlink,
136 ///(north/south/west/east edge sizing)
137 eCursor_n_resize,
138 eCursor_s_resize,
139 eCursor_w_resize,
140 eCursor_e_resize,
141 ///(corner sizing)
142 eCursor_nw_resize,
143 eCursor_se_resize,
144 eCursor_ne_resize,
145 eCursor_sw_resize,
146 eCursor_crosshair,
147 eCursor_move,
148 eCursor_help,
149 eCursor_copy, // CSS3
150 eCursor_alias,
151 eCursor_context_menu,
152 eCursor_cell,
153 eCursor_grab,
154 eCursor_grabbing,
155 eCursor_spinning,
156 eCursor_zoom_in,
157 eCursor_zoom_out,
158 eCursor_not_allowed,
159 eCursor_col_resize,
160 eCursor_row_resize,
161 eCursor_no_drop,
162 eCursor_vertical_text,
163 eCursor_all_scroll,
164 eCursor_nesw_resize,
165 eCursor_nwse_resize,
166 eCursor_ns_resize,
167 eCursor_ew_resize,
168 eCursor_none,
169 // This one better be the last one in this list.
170 eCursorCount
173 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
174 eZPlacementBottom = 0, // bottom of the window stack
175 eZPlacementBelow, // just below another widget
176 eZPlacementTop // top of the window stack
180 * Before the OS goes to sleep, this topic is notified.
182 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
185 * After the OS wakes up, this topic is notified.
187 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
190 * Before the OS suspends the current process, this topic is notified. Some
191 * OS will kill processes that are suspended instead of resuming them.
192 * For that reason this topic may be useful to safely close down resources.
194 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
197 * After the current process resumes from being suspended, this topic is
198 * notified.
200 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
203 * Preference for receiving IME updates
205 * If mWantUpdates is not NOTIFY_NOTHING, nsTextStateManager will observe text
206 * change and/or selection change and call nsIWidget::NotifyIMEOfTextChange()
207 * and/or nsIWidget::NotifyIME(NOTIFY_IME_OF_SELECTION_CHANGE).
208 * Please note that the text change observing cost is very expensive especially
209 * on an HTML editor has focus.
210 * If the IME implementation on a particular platform doesn't care about
211 * NotifyIMEOfTextChange() and/or NotifyIME(NOTIFY_IME_OF_SELECTION_CHANGE),
212 * they should set mWantUpdates to NOTIFY_NOTHING to avoid the cost.
214 * If mWantHints is true, PuppetWidget will forward the content of text fields
215 * to the chrome process to be cached. This way we return the cached content
216 * during query events. (see comments in bug 583976). This only makes sense
217 * for IME implementations that do use query events, otherwise there's a
218 * significant overhead. Platforms that don't use query events should set
219 * mWantHints to false.
221 struct nsIMEUpdatePreference {
223 typedef int8_t Notifications;
225 enum
227 NOTIFY_NOTHING = 0x0000,
228 NOTIFY_SELECTION_CHANGE = 0x0001,
229 NOTIFY_TEXT_CHANGE = 0x0002
232 nsIMEUpdatePreference()
233 : mWantUpdates(NOTIFY_NOTHING), mWantHints(false)
236 nsIMEUpdatePreference(Notifications aWantUpdates, bool aWantHints)
237 : mWantUpdates(aWantUpdates), mWantHints(aWantHints)
241 Notifications mWantUpdates;
242 bool mWantHints;
247 * Contains IMEStatus plus information about the current
248 * input context that the IME can use as hints if desired.
251 namespace mozilla {
252 namespace widget {
254 struct IMEState {
256 * IME enabled states, the mEnabled value of
257 * SetInputContext()/GetInputContext() should be one value of following
258 * values.
260 * WARNING: If you change these values, you also need to edit:
261 * nsIDOMWindowUtils.idl
262 * nsContentUtils::GetWidgetStatusFromIMEStatus
264 enum Enabled {
266 * 'Disabled' means the user cannot use IME. So, the IME open state should
267 * be 'closed' during 'disabled'.
269 DISABLED,
271 * 'Enabled' means the user can use IME.
273 ENABLED,
275 * 'Password' state is a special case for the password editors.
276 * E.g., on mac, the password editors should disable the non-Roman
277 * keyboard layouts at getting focus. Thus, the password editor may have
278 * special rules on some platforms.
280 PASSWORD,
282 * This state is used when a plugin is focused.
283 * When a plug-in is focused content, we should send native events
284 * directly. Because we don't process some native events, but they may
285 * be needed by the plug-in.
287 PLUGIN
289 Enabled mEnabled;
292 * IME open states the mOpen value of SetInputContext() should be one value of
293 * OPEN, CLOSE or DONT_CHANGE_OPEN_STATE. GetInputContext() should return
294 * OPEN, CLOSE or OPEN_STATE_NOT_SUPPORTED.
296 enum Open {
298 * 'Unsupported' means the platform cannot return actual IME open state.
299 * This value is used only by GetInputContext().
301 OPEN_STATE_NOT_SUPPORTED,
303 * 'Don't change' means the widget shouldn't change IME open state when
304 * SetInputContext() is called.
306 DONT_CHANGE_OPEN_STATE = OPEN_STATE_NOT_SUPPORTED,
308 * 'Open' means that IME should compose in its primary language (or latest
309 * input mode except direct ASCII character input mode). Even if IME is
310 * opened by this value, users should be able to close IME by theirselves.
311 * Web contents can specify this value by |ime-mode: active;|.
313 OPEN,
315 * 'Closed' means that IME shouldn't handle key events (or should handle
316 * as ASCII character inputs on mobile device). Even if IME is closed by
317 * this value, users should be able to open IME by theirselves.
318 * Web contents can specify this value by |ime-mode: inactive;|.
320 CLOSED
322 Open mOpen;
324 IMEState() : mEnabled(ENABLED), mOpen(DONT_CHANGE_OPEN_STATE) { }
326 IMEState(Enabled aEnabled, Open aOpen = DONT_CHANGE_OPEN_STATE) :
327 mEnabled(aEnabled), mOpen(aOpen)
332 struct InputContext {
333 InputContext() : mNativeIMEContext(nullptr) {}
335 bool IsPasswordEditor() const
337 return mHTMLInputType.LowerCaseEqualsLiteral("password");
340 IMEState mIMEState;
342 /* The type of the input if the input is a html input field */
343 nsString mHTMLInputType;
345 /* The type of the inputmode */
346 nsString mHTMLInputInputmode;
348 /* A hint for the action that is performed when the input is submitted */
349 nsString mActionHint;
351 /* Native IME context for the widget. This doesn't come from the argument of
352 SetInputContext(). If there is only one context in the process, this may
353 be nullptr. */
354 void* mNativeIMEContext;
357 struct InputContextAction {
359 * mCause indicates what action causes calling nsIWidget::SetInputContext().
360 * It must be one of following values.
362 enum Cause {
363 // The cause is unknown but originated from content. Focus might have been
364 // changed by content script.
365 CAUSE_UNKNOWN,
366 // The cause is unknown but originated from chrome. Focus might have been
367 // changed by chrome script.
368 CAUSE_UNKNOWN_CHROME,
369 // The cause is user's keyboard operation.
370 CAUSE_KEY,
371 // The cause is user's mouse operation.
372 CAUSE_MOUSE
374 Cause mCause;
377 * mFocusChange indicates what happened for focus.
379 enum FocusChange {
380 FOCUS_NOT_CHANGED,
381 // A content got focus.
382 GOT_FOCUS,
383 // Focused content lost focus.
384 LOST_FOCUS,
385 // Menu got pseudo focus that means focused content isn't changed but
386 // keyboard events will be handled by menu.
387 MENU_GOT_PSEUDO_FOCUS,
388 // Menu lost pseudo focus that means focused content will handle keyboard
389 // events.
390 MENU_LOST_PSEUDO_FOCUS
392 FocusChange mFocusChange;
394 bool ContentGotFocusByTrustedCause() const {
395 return (mFocusChange == GOT_FOCUS &&
396 mCause != CAUSE_UNKNOWN);
399 bool UserMightRequestOpenVKB() const {
400 return (mFocusChange == FOCUS_NOT_CHANGED &&
401 mCause == CAUSE_MOUSE);
404 InputContextAction() :
405 mCause(CAUSE_UNKNOWN), mFocusChange(FOCUS_NOT_CHANGED)
409 InputContextAction(Cause aCause,
410 FocusChange aFocusChange = FOCUS_NOT_CHANGED) :
411 mCause(aCause), mFocusChange(aFocusChange)
417 * Size constraints for setting the minimum and maximum size of a widget.
418 * Values are in device pixels.
420 struct SizeConstraints {
421 SizeConstraints()
422 : mMaxSize(NS_MAXSIZE, NS_MAXSIZE)
426 SizeConstraints(nsIntSize aMinSize,
427 nsIntSize aMaxSize)
428 : mMinSize(aMinSize),
429 mMaxSize(aMaxSize)
433 nsIntSize mMinSize;
434 nsIntSize mMaxSize;
437 // NotificationToIME is shared by nsIMEStateManager and TextComposition.
438 enum NotificationToIME {
439 // XXX We should replace NOTIFY_IME_OF_CURSOR_POS_CHANGED with
440 // NOTIFY_IME_OF_SELECTION_CHANGE later.
441 NOTIFY_IME_OF_CURSOR_POS_CHANGED,
442 // An editable content is getting focus
443 NOTIFY_IME_OF_FOCUS,
444 // An editable content is losing focus
445 NOTIFY_IME_OF_BLUR,
446 // Selection in the focused editable content is changed
447 NOTIFY_IME_OF_SELECTION_CHANGE,
448 REQUEST_TO_COMMIT_COMPOSITION,
449 REQUEST_TO_CANCEL_COMPOSITION
452 } // namespace widget
453 } // namespace mozilla
456 * The base class for all the widgets. It provides the interface for
457 * all basic and necessary functionality.
459 class nsIWidget : public nsISupports {
460 protected:
461 typedef mozilla::dom::TabChild TabChild;
463 public:
464 typedef mozilla::layers::Composer2D Composer2D;
465 typedef mozilla::layers::CompositorChild CompositorChild;
466 typedef mozilla::layers::LayerManager LayerManager;
467 typedef mozilla::layers::LayersBackend LayersBackend;
468 typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild;
469 typedef mozilla::widget::NotificationToIME NotificationToIME;
470 typedef mozilla::widget::IMEState IMEState;
471 typedef mozilla::widget::InputContext InputContext;
472 typedef mozilla::widget::InputContextAction InputContextAction;
473 typedef mozilla::widget::SizeConstraints SizeConstraints;
475 // Used in UpdateThemeGeometries.
476 struct ThemeGeometry {
477 // The -moz-appearance value for the themed widget
478 uint8_t mWidgetType;
479 // The device-pixel rect within the window for the themed widget
480 nsIntRect mRect;
482 ThemeGeometry(uint8_t aWidgetType, const nsIntRect& aRect)
483 : mWidgetType(aWidgetType)
484 , mRect(aRect)
488 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
490 nsIWidget()
491 : mLastChild(nullptr)
492 , mPrevSibling(nullptr)
493 , mOnDestroyCalled(false)
498 * Create and initialize a widget.
500 * All the arguments can be NULL in which case a top level window
501 * with size 0 is created. The event callback function has to be
502 * provided only if the caller wants to deal with the events this
503 * widget receives. The event callback is basically a preprocess
504 * hook called synchronously. The return value determines whether
505 * the event goes to the default window procedure or it is hidden
506 * to the os. The assumption is that if the event handler returns
507 * false the widget does not see the event. The widget should not
508 * automatically clear the window to the background color. The
509 * calling code must handle paint messages and clear the background
510 * itself.
512 * In practice at least one of aParent and aNativeParent will be null. If
513 * both are null the widget isn't parented (e.g. context menus or
514 * independent top level windows).
516 * The dimensions given in aRect are specified in the parent's
517 * coordinate system, or for parentless widgets such as top-level
518 * windows, in global CSS pixels.
520 * @param aParent parent nsIWidget
521 * @param aNativeParent native parent widget
522 * @param aRect the widget dimension
523 * @param aContext
524 * @param aInitData data that is used for widget initialization
527 NS_IMETHOD Create(nsIWidget *aParent,
528 nsNativeWidget aNativeParent,
529 const nsIntRect &aRect,
530 nsDeviceContext *aContext,
531 nsWidgetInitData *aInitData = nullptr) = 0;
534 * Allocate, initialize, and return a widget that is a child of
535 * |this|. The returned widget (if nonnull) has gone through the
536 * equivalent of CreateInstance(widgetCID) + Create(...).
538 * |CreateChild()| lets widget backends decide whether to parent
539 * the new child widget to this, nonnatively parent it, or both.
540 * This interface exists to support the PuppetWidget backend,
541 * which is entirely non-native. All other params are the same as
542 * for |Create()|.
544 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
545 * |nsIWidget*| this, not its native widget (if it exists), when
546 * calling |Create()|. This is a timid hack around poorly
547 * understood code, and shouldn't be used in new code.
549 virtual already_AddRefed<nsIWidget>
550 CreateChild(const nsIntRect &aRect,
551 nsDeviceContext *aContext,
552 nsWidgetInitData *aInitData = nullptr,
553 bool aForceUseIWidgetParent = false) = 0;
556 * Attach to a top level widget.
558 * In cases where a top level chrome widget is being used as a content
559 * container, attach a secondary listener and update the device
560 * context. The primary widget listener will continue to be called for
561 * notifications relating to the top-level window, whereas other
562 * notifications such as painting and events will instead be called via
563 * the attached listener. SetAttachedWidgetListener should be used to
564 * assign the attached listener.
566 * aUseAttachedEvents if true, events are sent to the attached listener
567 * instead of the normal listener.
568 * aContext The new device context for the view
570 NS_IMETHOD AttachViewToTopLevel(bool aUseAttachedEvents,
571 nsDeviceContext *aContext) = 0;
574 * Accessor functions to get and set the attached listener. Used by
575 * nsView in connection with AttachViewToTopLevel above.
577 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
578 virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
581 * Accessor functions to get and set the listener which handles various
582 * actions for the widget.
584 //@{
585 virtual nsIWidgetListener* GetWidgetListener() = 0;
586 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
587 //@}
590 * Close and destroy the internal native window.
591 * This method does not delete the widget.
594 NS_IMETHOD Destroy(void) = 0;
597 * Destroyed() returns true if Destroy() has been called already.
598 * Otherwise, false.
600 bool Destroyed() const { return mOnDestroyCalled; }
604 * Reparent a widget
606 * Change the widget's parent. Null parents are allowed.
608 * @param aNewParent new parent
610 NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
612 NS_IMETHOD RegisterTouchWindow() = 0;
613 NS_IMETHOD UnregisterTouchWindow() = 0;
616 * Return the parent Widget of this Widget or nullptr if this is a
617 * top level window
619 * @return the parent widget or nullptr if it does not have a parent
622 virtual nsIWidget* GetParent(void) = 0;
625 * Return the top level Widget of this Widget
627 * @return the top level widget
629 virtual nsIWidget* GetTopLevelWidget() = 0;
632 * Return the top (non-sheet) parent of this Widget if it's a sheet,
633 * or nullptr if this isn't a sheet (or some other error occurred).
634 * Sheets are only supported on some platforms (currently only OS X).
636 * @return the top (non-sheet) parent widget or nullptr
639 virtual nsIWidget* GetSheetWindowParent(void) = 0;
642 * Return the physical DPI of the screen containing the window ...
643 * the number of device pixels per inch.
645 virtual float GetDPI() = 0;
648 * Return the default scale factor for the window. This is the
649 * default number of device pixels per CSS pixel to use. This should
650 * depend on OS/platform settings such as the Mac's "UI scale factor"
651 * or Windows' "font DPI". This will take into account Gecko preferences
652 * overriding the system setting.
654 mozilla::CSSToLayoutDeviceScale GetDefaultScale();
657 * Return the Gecko override of the system default scale, if any;
658 * returns <= 0.0 if the system scale should be used as-is.
659 * nsIWidget::GetDefaultScale() [above] takes this into account.
660 * It is exposed here so that code that wants to check for a
661 * default-scale override without having a widget on hand can
662 * easily access the same value.
663 * Note that any scale override is a browser-wide value, whereas
664 * the default GetDefaultScale value (when no override is present)
665 * may vary between widgets (or screens).
667 static double DefaultScaleOverride();
670 * Return the first child of this widget. Will return null if
671 * there are no children.
673 nsIWidget* GetFirstChild() const {
674 return mFirstChild;
678 * Return the last child of this widget. Will return null if
679 * there are no children.
681 nsIWidget* GetLastChild() const {
682 return mLastChild;
686 * Return the next sibling of this widget
688 nsIWidget* GetNextSibling() const {
689 return mNextSibling;
693 * Set the next sibling of this widget
695 void SetNextSibling(nsIWidget* aSibling) {
696 mNextSibling = aSibling;
700 * Return the previous sibling of this widget
702 nsIWidget* GetPrevSibling() const {
703 return mPrevSibling;
707 * Set the previous sibling of this widget
709 void SetPrevSibling(nsIWidget* aSibling) {
710 mPrevSibling = aSibling;
714 * Show or hide this widget
716 * @param aState true to show the Widget, false to hide it
719 NS_IMETHOD Show(bool aState) = 0;
722 * Make the window modal
725 NS_IMETHOD SetModal(bool aModal) = 0;
728 * Returns whether the window is visible
731 virtual bool IsVisible() const = 0;
734 * Perform platform-dependent sanity check on a potential window position.
735 * This is guaranteed to work only for top-level windows.
737 * @param aAllowSlop: if true, allow the window to slop offscreen;
738 * the window should be partially visible. if false,
739 * force the entire window onscreen (or at least
740 * the upper-left corner, if it's too large).
741 * @param aX in: an x position expressed in screen coordinates.
742 * out: the x position constrained to fit on the screen(s).
743 * @param aY in: an y position expressed in screen coordinates.
744 * out: the y position constrained to fit on the screen(s).
745 * @return vapid success indication. but see also the parameters.
748 NS_IMETHOD ConstrainPosition(bool aAllowSlop,
749 int32_t *aX,
750 int32_t *aY) = 0;
753 * NOTE:
755 * For a top-level window widget, the "parent's coordinate system" is the
756 * "global" display pixel coordinate space, *not* device pixels (which
757 * may be inconsistent between multiple screens, at least in the Mac OS
758 * case with mixed hi-dpi and lo-dpi displays). This applies to all the
759 * following Move and Resize widget APIs.
761 * The display-/device-pixel distinction becomes important for (at least)
762 * Mac OS X with Hi-DPI (retina) displays, and Windows when the UI scale
763 * factor is set to other than 100%.
765 * The Move and Resize methods take floating-point parameters, rather than
766 * integer ones. This is important when manipulating top-level widgets,
767 * where the coordinate system may not be an integral multiple of the
768 * device-pixel space.
772 * Move this widget.
774 * Coordinates refer to the top-left of the widget. For toplevel windows
775 * with decorations, this is the top-left of the titlebar and frame .
777 * @param aX the new x position expressed in the parent's coordinate system
778 * @param aY the new y position expressed in the parent's coordinate system
781 NS_IMETHOD Move(double aX, double aY) = 0;
784 * Reposition this widget so that the client area has the given offset.
786 * @param aX the new x offset of the client area expressed as an
787 * offset from the origin of the client area of the parent
788 * widget (for root widgets and popup widgets it is in
789 * screen coordinates)
790 * @param aY the new y offset of the client area expressed as an
791 * offset from the origin of the client area of the parent
792 * widget (for root widgets and popup widgets it is in
793 * screen coordinates)
796 NS_IMETHOD MoveClient(double aX, double aY) = 0;
799 * Resize this widget. Any size constraints set for the window by a
800 * previous call to SetSizeConstraints will be applied.
802 * @param aWidth the new width expressed in the parent's coordinate system
803 * @param aHeight the new height expressed in the parent's coordinate system
804 * @param aRepaint whether the widget should be repainted
807 NS_IMETHOD Resize(double aWidth,
808 double aHeight,
809 bool aRepaint) = 0;
812 * Move or resize this widget. Any size constraints set for the window by
813 * a previous call to SetSizeConstraints will be applied.
815 * @param aX the new x position expressed in the parent's coordinate system
816 * @param aY the new y position expressed in the parent's coordinate system
817 * @param aWidth the new width expressed in the parent's coordinate system
818 * @param aHeight the new height expressed in the parent's coordinate system
819 * @param aRepaint whether the widget should be repainted if the size changes
822 NS_IMETHOD Resize(double aX,
823 double aY,
824 double aWidth,
825 double aHeight,
826 bool aRepaint) = 0;
829 * Resize the widget so that the inner client area has the given size.
831 * @param aWidth the new width of the client area.
832 * @param aHeight the new height of the client area.
833 * @param aRepaint whether the widget should be repainted
836 NS_IMETHOD ResizeClient(double aWidth,
837 double aHeight,
838 bool aRepaint) = 0;
841 * Resize and reposition the widget so tht inner client area has the given
842 * offset and size.
844 * @param aX the new x offset of the client area expressed as an
845 * offset from the origin of the client area of the parent
846 * widget (for root widgets and popup widgets it is in
847 * screen coordinates)
848 * @param aY the new y offset of the client area expressed as an
849 * offset from the origin of the client area of the parent
850 * widget (for root widgets and popup widgets it is in
851 * screen coordinates)
852 * @param aWidth the new width of the client area.
853 * @param aHeight the new height of the client area.
854 * @param aRepaint whether the widget should be repainted
857 NS_IMETHOD ResizeClient(double aX,
858 double aY,
859 double aWidth,
860 double aHeight,
861 bool aRepaint) = 0;
864 * Sets the widget's z-index.
866 NS_IMETHOD SetZIndex(int32_t aZIndex) = 0;
869 * Gets the widget's z-index.
871 NS_IMETHOD GetZIndex(int32_t* aZIndex) = 0;
874 * Position this widget just behind the given widget. (Used to
875 * control z-order for top-level widgets. Get/SetZIndex by contrast
876 * control z-order for child widgets of other widgets.)
877 * @param aPlacement top, bottom, or below a widget
878 * (if top or bottom, param aWidget is ignored)
879 * @param aWidget widget to place this widget behind
880 * (only if aPlacement is eZPlacementBelow).
881 * null is equivalent to aPlacement of eZPlacementTop
882 * @param aActivate true to activate the widget after placing it
884 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
885 nsIWidget *aWidget, bool aActivate) = 0;
888 * Minimize, maximize or normalize the window size.
889 * Takes a value from nsSizeMode (see nsIWidgetListener.h)
891 NS_IMETHOD SetSizeMode(int32_t aMode) = 0;
894 * Return size mode (minimized, maximized, normalized).
895 * Returns a value from nsSizeMode (see nsIWidgetListener.h)
897 virtual int32_t SizeMode() = 0;
900 * Enable or disable this Widget
902 * @param aState true to enable the Widget, false to disable it.
905 NS_IMETHOD Enable(bool aState) = 0;
908 * Ask whether the widget is enabled
910 virtual bool IsEnabled() const = 0;
913 * Request activation of this window or give focus to this widget.
915 * @param aRaise If true, this function requests activation of this
916 * widget's toplevel window.
917 * If false, the appropriate toplevel window (which in
918 * the case of popups may not be this widget's toplevel
919 * window) is already active.
921 NS_IMETHOD SetFocus(bool aRaise = false) = 0;
924 * Get this widget's outside dimensions relative to its parent widget. For
925 * popup widgets the returned rect is in screen coordinates and not
926 * relative to its parent widget.
928 * @param aRect On return it holds the x, y, width and height of
929 * this widget.
931 NS_IMETHOD GetBounds(nsIntRect &aRect) = 0;
934 * Get this widget's outside dimensions in global coordinates. This
935 * includes any title bar on the window.
937 * @param aRect On return it holds the x, y, width and height of
938 * this widget.
940 NS_IMETHOD GetScreenBounds(nsIntRect &aRect) = 0;
943 * Get this widget's client area bounds, if the window has a 3D border
944 * appearance this returns the area inside the border. The position is the
945 * position of the client area relative to the client area of the parent
946 * widget (for root widgets and popup widgets it is in screen coordinates).
948 * @param aRect On return it holds the x. y, width and height of
949 * the client area of this widget.
951 NS_IMETHOD GetClientBounds(nsIntRect &aRect) = 0;
954 * Get the non-client area dimensions of the window.
957 NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) = 0;
960 * Sets the non-client area dimensions of the window. Pass -1 to restore
961 * the system default frame size for that border. Pass zero to remove
962 * a border, or pass a specific value adjust a border. Units are in
963 * pixels. (DPI dependent)
965 * Platform notes:
966 * Windows: shrinking top non-client height will remove application
967 * icon and window title text. Glass desktops will refuse to set
968 * dimensions between zero and size < system default.
971 NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0;
974 * Get the client offset from the window origin.
976 * @return the x and y of the offset.
979 virtual nsIntPoint GetClientOffset() = 0;
982 * Get the foreground color for this widget
984 * @return this widget's foreground color
987 virtual nscolor GetForegroundColor(void) = 0;
990 * Set the foreground color for this widget
992 * @param aColor the new foreground color
996 NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
999 * Get the background color for this widget
1001 * @return this widget's background color
1005 virtual nscolor GetBackgroundColor(void) = 0;
1008 * Set the background color for this widget
1010 * @param aColor the new background color
1014 NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
1017 * Get the cursor for this widget.
1019 * @return this widget's cursor.
1022 virtual nsCursor GetCursor(void) = 0;
1025 * Set the cursor for this widget
1027 * @param aCursor the new cursor for this widget
1030 NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
1033 * Sets an image as the cursor for this widget.
1035 * @param aCursor the cursor to set
1036 * @param aX the X coordinate of the hotspot (from left).
1037 * @param aY the Y coordinate of the hotspot (from top).
1038 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
1039 * supported
1041 NS_IMETHOD SetCursor(imgIContainer* aCursor,
1042 uint32_t aHotspotX, uint32_t aHotspotY) = 0;
1044 /**
1045 * Get the window type of this widget
1047 * @param aWindowType the window type of the widget
1049 NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
1052 * Set the transparency mode of the top-level window containing this widget.
1053 * So, e.g., if you call this on the widget for an IFRAME, the top level
1054 * browser window containing the IFRAME actually gets set. Be careful.
1056 * This can fail if the platform doesn't support
1057 * transparency/glass. By default widgets are not
1058 * transparent. This will also fail if the toplevel window is not
1059 * a Mozilla window, e.g., if the widget is in an embedded
1060 * context.
1062 * After transparency/glass has been enabled, the initial alpha channel
1063 * value for all pixels is 1, i.e., opaque.
1064 * If the window is resized then the alpha channel values for
1065 * all pixels are reset to 1.
1066 * Pixel RGB color values are already premultiplied with alpha channel values.
1068 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
1071 * Get the transparency mode of the top-level window that contains this
1072 * widget.
1074 virtual nsTransparencyMode GetTransparencyMode() = 0;
1077 * This represents a command to set the bounds and clip region of
1078 * a child widget.
1080 struct Configuration {
1081 nsIWidget* mChild;
1082 nsIntRect mBounds;
1083 nsTArray<nsIntRect> mClipRegion;
1087 * Sets the clip region of each mChild (which must actually be a child
1088 * of this widget) to the union of the pixel rects given in
1089 * mClipRegion, all relative to the top-left of the child
1090 * widget. Clip regions are not implemented on all platforms and only
1091 * need to actually work for children that are plugins.
1093 * Also sets the bounds of each child to mBounds.
1095 * This will invalidate areas of the children that have changed, but
1096 * does not need to invalidate any part of this widget.
1098 * Children should be moved in the order given; the array is
1099 * sorted so to minimize unnecessary invalidation if children are
1100 * moved in that order.
1102 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
1105 * Appends to aRects the rectangles constituting this widget's clip
1106 * region. If this widget is not clipped, appends a single rectangle
1107 * (0, 0, bounds.width, bounds.height).
1109 virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects) = 0;
1112 * Set the shadow style of the window.
1114 * Ignored on child widgets and on non-Mac platforms.
1116 NS_IMETHOD SetWindowShadowStyle(int32_t aStyle) = 0;
1119 * On Mac OS X, this method shows or hides the pill button in the titlebar
1120 * that's used to collapse the toolbar.
1122 * Ignored on child widgets and on non-Mac platforms.
1124 virtual void SetShowsToolbarButton(bool aShow) = 0;
1127 * On Mac OS X Lion, this method shows or hides the full screen button in
1128 * the titlebar that handles native full screen mode.
1130 * Ignored on child widgets, non-Mac platforms, & pre-Lion Mac.
1132 virtual void SetShowsFullScreenButton(bool aShow) = 0;
1134 enum WindowAnimationType {
1135 eGenericWindowAnimation,
1136 eDocumentWindowAnimation
1140 * Sets the kind of top-level window animation this widget should have. On
1141 * Mac OS X, this causes a particular kind of animation to be shown when the
1142 * window is first made visible.
1144 * Ignored on child widgets and on non-Mac platforms.
1146 virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
1148 /**
1149 * Hide window chrome (borders, buttons) for this widget.
1152 NS_IMETHOD HideWindowChrome(bool aShouldHide) = 0;
1155 * Put the toplevel window into or out of fullscreen mode.
1158 NS_IMETHOD MakeFullScreen(bool aFullScreen) = 0;
1161 * Invalidate a specified rect for a widget so that it will be repainted
1162 * later.
1164 NS_IMETHOD Invalidate(const nsIntRect & aRect) = 0;
1166 enum LayerManagerPersistence
1168 LAYER_MANAGER_CURRENT = 0,
1169 LAYER_MANAGER_PERSISTENT
1173 * Return the widget's LayerManager. The layer tree for that
1174 * LayerManager is what gets rendered to the widget.
1176 * @param aAllowRetaining an outparam that states whether the returned
1177 * layer manager should be used for retained layers
1179 inline LayerManager* GetLayerManager(bool* aAllowRetaining = nullptr)
1181 return GetLayerManager(nullptr, mozilla::layers::LAYERS_NONE,
1182 LAYER_MANAGER_CURRENT, aAllowRetaining);
1185 inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence,
1186 bool* aAllowRetaining = nullptr)
1188 return GetLayerManager(nullptr, mozilla::layers::LAYERS_NONE,
1189 aPersistence, aAllowRetaining);
1193 * Like GetLayerManager(), but prefers creating a layer manager of
1194 * type |aBackendHint| instead of what would normally be created.
1195 * LAYERS_NONE means "no hint".
1197 virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager,
1198 LayersBackend aBackendHint,
1199 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
1200 bool* aAllowRetaining = nullptr) = 0;
1203 * Called before each layer manager transaction to allow any preparation
1204 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1206 * Always called on the main thread.
1208 virtual void PrepareWindowEffects() = 0;
1211 * Called when shutting down the LayerManager to clean-up any cached resources.
1213 * Always called from the compositing thread, which may be the main-thread if
1214 * OMTC is not enabled.
1216 virtual void CleanupWindowEffects() = 0;
1218 virtual void PreRender(LayerManager* aManager) = 0;
1219 virtual void PostRender(LayerManager* aManager) = 0;
1222 * Called before the LayerManager draws the layer tree.
1224 * Always called from the compositing thread, which may be the main-thread if
1225 * OMTC is not enabled.
1227 virtual void DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect) = 0;
1230 * Called after the LayerManager draws the layer tree
1232 * Always called from the compositing thread, which may be the main-thread if
1233 * OMTC is not enabled.
1235 virtual void DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) = 0;
1238 * Return a DrawTarget for the window which can be composited into.
1240 * Called by BasicCompositor on the compositor thread for OMTC drawing
1241 * before each composition.
1243 virtual mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing() = 0;
1246 * Ensure that what was painted into the DrawTarget returned from
1247 * StartRemoteDrawing reaches the screen.
1249 * Called by BasicCompositor on the compositor thread for OMTC drawing
1250 * after each composition.
1252 virtual void EndRemoteDrawing() = 0;
1255 * Clean up any resources used by Start/EndRemoteDrawing.
1257 * Called by BasicCompositor on the compositor thread for OMTC drawing
1258 * when the compositor is destroyed.
1260 virtual void CleanupRemoteDrawing() = 0;
1263 * Called when Gecko knows which themed widgets exist in this window.
1264 * The passed array contains an entry for every themed widget of the right
1265 * type (currently only NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR and
1266 * NS_THEME_TOOLBAR) within the window, except for themed widgets which are
1267 * transformed or have effects applied to them (e.g. CSS opacity or
1268 * filters).
1269 * This could sometimes be called during display list construction
1270 * outside of painting.
1271 * If called during painting, it will be called before we actually
1272 * paint anything.
1274 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1277 * Informs the widget about the region of the window that is opaque.
1279 * @param aOpaqueRegion the region of the window that is opaque.
1281 virtual void UpdateOpaqueRegion(const nsIntRegion &aOpaqueRegion) {}
1283 /**
1284 * Internal methods
1287 //@{
1288 virtual void AddChild(nsIWidget* aChild) = 0;
1289 virtual void RemoveChild(nsIWidget* aChild) = 0;
1290 virtual void* GetNativeData(uint32_t aDataType) = 0;
1291 virtual void FreeNativeData(void * data, uint32_t aDataType) = 0;//~~~
1293 // GetDeviceContext returns a weak pointer to this widget's device context
1294 virtual nsDeviceContext* GetDeviceContext() = 0;
1296 //@}
1299 * Set the widget's title.
1300 * Must be called after Create.
1302 * @param aTitle string displayed as the title of the widget
1305 NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
1308 * Set the widget's icon.
1309 * Must be called after Create.
1311 * @param anIconSpec string specifying the icon to use; convention is to pass
1312 * a resource: URL from which a platform-dependent resource
1313 * file name will be constructed
1316 NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
1319 * Return this widget's origin in screen coordinates.
1321 * @return screen coordinates stored in the x,y members
1324 virtual nsIntPoint WidgetToScreenOffset() = 0;
1327 * Given the specified client size, return the corresponding window size,
1328 * which includes the area for the borders and titlebar. This method
1329 * should work even when the window is not yet visible.
1331 virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) = 0;
1334 * Dispatches an event to the widget
1337 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
1340 * Enables the dropping of files to a widget (XXX this is temporary)
1343 NS_IMETHOD EnableDragDrop(bool aEnable) = 0;
1346 * Enables/Disables system mouse capture.
1347 * @param aCapture true enables mouse capture, false disables mouse capture
1350 NS_IMETHOD CaptureMouse(bool aCapture) = 0;
1353 * Classify the window for the window manager. Mostly for X11.
1355 NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0;
1358 * Enables/Disables system capture of any and all events that would cause a
1359 * popup to be rolled up. aListener should be set to a non-null value for
1360 * any popups that are not managed by the popup manager.
1361 * @param aDoCapture true enables capture, false disables capture
1364 NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture) = 0;
1367 * Bring this window to the user's attention. This is intended to be a more
1368 * gentle notification than popping the window to the top or putting up an
1369 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1370 * the Mac. The notification should be suppressed if the window is already
1371 * in the foreground and should be dismissed when the user brings this window
1372 * to the foreground.
1373 * @param aCycleCount Maximum number of times to animate the window per system
1374 * conventions. If set to -1, cycles indefinitely until
1375 * window is brought into the foreground.
1377 NS_IMETHOD GetAttention(int32_t aCycleCount) = 0;
1380 * Ask whether there user input events pending. All input events are
1381 * included, including those not targeted at this nsIwidget instance.
1383 virtual bool HasPendingInputEvent() = 0;
1386 * Set the background color of the window titlebar for this widget. On Mac,
1387 * for example, this will remove the grey gradient and bottom border and
1388 * instead show a single, solid color.
1390 * Ignored on any platform that does not support it. Ignored by widgets that
1391 * do not represent windows.
1393 * @param aColor The color to set the title bar background to. Alpha values
1394 * other than fully transparent (0) are respected if possible
1395 * on the platform. An alpha of 0 will cause the window to
1396 * draw with the default style for the platform.
1398 * @param aActive Whether the color should be applied to active or inactive
1399 * windows.
1401 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive) = 0;
1404 * If set to true, the window will draw its contents into the titlebar
1405 * instead of below it.
1407 * Ignored on any platform that does not support it. Ignored by widgets that
1408 * do not represent windows.
1409 * May result in a resize event, so should only be called from places where
1410 * reflow and painting is allowed.
1412 * @param aState Whether drawing into the titlebar should be activated.
1414 virtual void SetDrawsInTitlebar(bool aState) = 0;
1417 * Determine whether the widget shows a resize widget. If it does,
1418 * aResizerRect returns the resizer's rect.
1420 * Returns false on any platform that does not support it.
1422 * @param aResizerRect The resizer's rect in device pixels.
1423 * @return Whether a resize widget is shown.
1425 virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0;
1428 * Get the Thebes surface associated with this widget.
1430 virtual gfxASurface *GetThebesSurface() = 0;
1433 * Return the popup that was last rolled up, or null if there isn't one.
1435 virtual nsIContent* GetLastRollup() = 0;
1438 * Begin a window resizing drag, based on the event passed in.
1440 NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical) = 0;
1443 * Begin a window moving drag, based on the event passed in.
1445 NS_IMETHOD BeginMoveDrag(nsMouseEvent* aEvent) = 0;
1447 enum Modifiers {
1448 CAPS_LOCK = 0x01, // when CapsLock is active
1449 NUM_LOCK = 0x02, // when NumLock is active
1450 SHIFT_L = 0x0100,
1451 SHIFT_R = 0x0200,
1452 CTRL_L = 0x0400,
1453 CTRL_R = 0x0800,
1454 ALT_L = 0x1000, // includes Option
1455 ALT_R = 0x2000,
1456 COMMAND_L = 0x4000,
1457 COMMAND_R = 0x8000,
1458 HELP = 0x10000,
1459 FUNCTION = 0x100000,
1460 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1463 * Utility method intended for testing. Dispatches native key events
1464 * to this widget to simulate the press and release of a key.
1465 * @param aNativeKeyboardLayout a *platform-specific* constant.
1466 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1467 * On Windows, it is converted to a hex string and passed to
1468 * LoadKeyboardLayout, see
1469 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1470 * @param aNativeKeyCode a *platform-specific* keycode.
1471 * On Windows, this is the virtual key code.
1472 * @param aModifiers some combination of the above 'Modifiers' flags;
1473 * not all flags will apply to all platforms. Mac ignores the _R
1474 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1475 * FUNCTION.
1476 * @param aCharacters characters that the OS would decide to generate
1477 * from the event. On Windows, this is the charCode passed by
1478 * WM_CHAR.
1479 * @param aUnmodifiedCharacters characters that the OS would decide
1480 * to generate from the event if modifier keys (other than shift)
1481 * were assumed inactive. Needed on Mac, ignored on Windows.
1482 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1483 * layout is not supported and the event was not fired
1485 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
1486 int32_t aNativeKeyCode,
1487 uint32_t aModifierFlags,
1488 const nsAString& aCharacters,
1489 const nsAString& aUnmodifiedCharacters) = 0;
1492 * Utility method intended for testing. Dispatches native mouse events
1493 * may even move the mouse cursor. On Mac the events are guaranteed to
1494 * be sent to the window containing this widget, but on Windows they'll go
1495 * to whatever's topmost on the screen at that position, so for
1496 * cross-platform testing ensure that your window is at the top of the
1497 * z-order.
1498 * @param aPoint screen location of the mouse, in device
1499 * pixels, with origin at the top left
1500 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
1501 * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
1502 * @param aModifierFlags *platform-specific* modifier flags (ignored
1503 * on Windows)
1505 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
1506 uint32_t aNativeMessage,
1507 uint32_t aModifierFlags) = 0;
1510 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native message.
1511 * aPoint is location in device pixels to which the mouse pointer moves to.
1513 virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) = 0;
1516 * Utility method intended for testing. Dispatching native mouse scroll
1517 * events may move the mouse cursor.
1519 * @param aPoint Mouse cursor position in screen coordinates.
1520 * In device pixels, the origin at the top left of
1521 * the primary display.
1522 * @param aNativeMessage Platform native message.
1523 * @param aDeltaX The delta value for X direction. If the native
1524 * message doesn't indicate X direction scrolling,
1525 * this may be ignored.
1526 * @param aDeltaY The delta value for Y direction. If the native
1527 * message doesn't indicate Y direction scrolling,
1528 * this may be ignored.
1529 * @param aDeltaZ The delta value for Z direction. If the native
1530 * message doesn't indicate Z direction scrolling,
1531 * this may be ignored.
1532 * @param aModifierFlags Must be values of Modifiers, or zero.
1533 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1534 * document.
1536 virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint,
1537 uint32_t aNativeMessage,
1538 double aDeltaX,
1539 double aDeltaY,
1540 double aDeltaZ,
1541 uint32_t aModifierFlags,
1542 uint32_t aAdditionalFlags) = 0;
1545 * Activates a native menu item at the position specified by the index
1546 * string. The index string is a string of positive integers separated
1547 * by the "|" (pipe) character. The last integer in the string represents
1548 * the item index in a submenu located using the integers preceding it.
1550 * Example: 1|0|4
1551 * In this string, the first integer represents the top-level submenu
1552 * in the native menu bar. Since the integer is 1, it is the second submeu
1553 * in the native menu bar. Within that, the first item (index 0) is a
1554 * submenu, and we want to activate the 5th item within that submenu.
1556 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1559 * This is used for native menu system testing.
1561 * Updates a native menu at the position specified by the index string.
1562 * The index string is a string of positive integers separated by the "|"
1563 * (pipe) character.
1565 * Example: 1|0|4
1566 * In this string, the first integer represents the top-level submenu
1567 * in the native menu bar. Since the integer is 1, it is the second submeu
1568 * in the native menu bar. Within that, the first item (index 0) is a
1569 * submenu, and we want to update submenu at index 4 within that submenu.
1571 * If this is called with an empty string it forces a full reload of the
1572 * menu system.
1574 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1577 * Notify IME of the specified notification.
1579 NS_IMETHOD NotifyIME(NotificationToIME aNotification) = 0;
1582 * Notifies the input context changes.
1584 NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
1585 const InputContextAction& aAction) = 0;
1588 * Get current input context.
1590 NS_IMETHOD_(InputContext) GetInputContext() = 0;
1593 * Set layers acceleration to 'True' or 'False'
1595 NS_IMETHOD SetLayersAcceleration(bool aEnabled) = 0;
1598 * Get toggled key states.
1599 * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or
1600 * NS_VK_SCROLL_LOCK.
1601 * aLEDState is the result for current LED state of the key.
1602 * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
1603 * If the platform doesn't support the LED state (or we cannot get the
1604 * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
1606 NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) = 0;
1609 * Text content of the focused node has changed
1610 * aStart is the starting offset of the change
1611 * aOldEnd is the ending offset of the change
1612 * aNewEnd is the caret offset after the change
1614 NS_IMETHOD NotifyIMEOfTextChange(uint32_t aStart,
1615 uint32_t aOldEnd,
1616 uint32_t aNewEnd) = 0;
1619 * Retrieves preference for IME updates
1621 virtual nsIMEUpdatePreference GetIMEUpdatePreference() = 0;
1624 * Call this method when a dialog is opened which has a default button.
1625 * The button's rectangle should be supplied in aButtonRect.
1627 NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) = 0;
1630 * Compute the overridden system mouse scroll speed on the root content of
1631 * web pages. The widget may set the same value as aOriginalDelta. E.g.,
1632 * when the system scrolling settings were customized, widget can respect
1633 * the will of the user.
1635 * This is called only when the mouse wheel event scrolls the root content
1636 * of the web pages by line. In other words, this isn't called when the
1637 * mouse wheel event is used for zoom, page scroll and other special
1638 * actions. And also this isn't called when the user doesn't use the
1639 * system wheel speed settings.
1641 * @param aOriginalDeltaX The X delta value of the current mouse wheel
1642 * scrolling event.
1643 * @param aOriginalDeltaX The Y delta value of the current mouse wheel
1644 * scrolling event.
1645 * @param aOverriddenDeltaX The overridden mouse scrolling speed along X
1646 * axis. This value may be same as aOriginalDeltaX.
1647 * @param aOverriddenDeltaY The overridden mouse scrolling speed along Y
1648 * axis. This value may be same as aOriginalDeltaY.
1650 NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
1651 double aOriginalDeltaY,
1652 double& aOverriddenDeltaX,
1653 double& aOverriddenDeltaY) = 0;
1656 * Return true if this process shouldn't use platform widgets, and
1657 * so should use PuppetWidgets instead. If this returns true, the
1658 * result of creating and using a platform widget is undefined,
1659 * and likely to end in crashes or other buggy behavior.
1661 static bool
1662 UsePuppetWidgets()
1664 return XRE_GetProcessType() == GeckoProcessType_Content;
1668 * Allocate and return a "puppet widget" that doesn't directly
1669 * correlate to a platform widget; platform events and data must
1670 * be fed to it. Currently used in content processes. NULL is
1671 * returned if puppet widgets aren't supported in this build
1672 * config, on this platform, or for this process type.
1674 * This function is called "Create" to match CreateInstance().
1675 * The returned widget must still be nsIWidget::Create()d.
1677 static already_AddRefed<nsIWidget>
1678 CreatePuppetWidget(TabChild* aTabChild);
1681 * Reparent this widget's native widget.
1682 * @param aNewParent the native widget of aNewParent is the new native
1683 * parent widget
1685 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0;
1688 * Return the internal format of the default framebuffer for this
1689 * widget.
1691 virtual uint32_t GetGLFrameBufferFormat() { return 0; /*GL_NONE*/ }
1694 * Return true if widget has it's own GL context
1696 virtual bool HasGLContext() { return false; }
1699 * Returns true to indicate that this widget paints an opaque background
1700 * that we want to be visible under the page, so layout should not force
1701 * a default background.
1703 virtual bool WidgetPaintsBackground() { return false; }
1705 virtual bool NeedsPaint() {
1706 if (!IsVisible()) {
1707 return false;
1709 nsIntRect bounds;
1710 nsresult rv = GetBounds(bounds);
1711 NS_ENSURE_SUCCESS(rv, false);
1712 return !bounds.IsEmpty();
1716 * Get the natural bounds of this widget. This method is only
1717 * meaningful for widgets for which Gecko implements screen
1718 * rotation natively. When this is the case, GetBounds() returns
1719 * the widget bounds taking rotation into account, and
1720 * GetNaturalBounds() returns the bounds *not* taking rotation
1721 * into account.
1723 * No code outside of the composition pipeline should know or care
1724 * about this. If you're not an agent of the compositor, you
1725 * probably shouldn't call this method.
1727 virtual nsIntRect GetNaturalBounds() {
1728 nsIntRect bounds;
1729 GetBounds(bounds);
1730 return bounds;
1734 * Set size constraints on the window size such that it is never less than
1735 * the specified minimum size and never larger than the specified maximum
1736 * size. The size constraints are sizes of the outer rectangle including
1737 * the window frame and title bar. Use 0 for an unconstrained minimum size
1738 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1739 * does not necessarily change the size of a window to conform to this size,
1740 * thus Resize should be called afterwards.
1742 * @param aConstraints: the size constraints in device pixels
1744 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
1747 * Return the size constraints currently observed by the widget.
1749 * @return the constraints in device pixels
1751 virtual const SizeConstraints& GetSizeConstraints() const = 0;
1754 * If this is owned by a TabChild, return that. Otherwise return
1755 * null.
1757 virtual TabChild* GetOwningTabChild() { return nullptr; }
1760 * If this isn't directly compositing to its window surface,
1761 * return the compositor which is doing that on our behalf.
1763 virtual CompositorChild* GetRemoteRenderer()
1764 { return nullptr; }
1767 * If this widget has a more efficient composer available for its
1768 * native framebuffer, return it.
1770 * This can be called from a non-main thread, but that thread must
1771 * hold a strong reference to this.
1773 virtual Composer2D* GetComposer2D()
1774 { return nullptr; }
1777 * Some platforms (only cocoa right now) round widget coordinates to the
1778 * nearest even pixels (see bug 892994), this function allows us to
1779 * determine how widget coordinates will be rounded.
1781 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
1783 protected:
1785 * Like GetDefaultScale, but taking into account only the system settings
1786 * and ignoring Gecko preferences.
1788 virtual double GetDefaultScaleInternal() { return 1.0; }
1790 // keep the list of children. We also keep track of our siblings.
1791 // The ownership model is as follows: parent holds a strong ref to
1792 // the first element of the list, and each element holds a strong
1793 // ref to the next element in the list. The prevsibling and
1794 // lastchild pointers are weak, which is fine as long as they are
1795 // maintained properly.
1796 nsCOMPtr<nsIWidget> mFirstChild;
1797 nsIWidget* mLastChild;
1798 nsCOMPtr<nsIWidget> mNextSibling;
1799 nsIWidget* mPrevSibling;
1800 // When Destroy() is called, the sub class should set this true.
1801 bool mOnDestroyCalled;
1804 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
1806 #endif // nsIWidget_h__