bug 818009 - canActivate: only click-to-play-type plugins are valid r=jaws
[gecko.git] / widget / nsIWidget.h
blob8467ff0594a9b90c96fb6e891fed32786bcfb461
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 "nsCoord.h"
12 #include "nsRect.h"
13 #include "nsPoint.h"
14 #include "nsStringGlue.h"
16 #include "prthread.h"
17 #include "nsEvent.h"
18 #include "nsCOMPtr.h"
19 #include "nsITheme.h"
20 #include "nsNativeWidget.h"
21 #include "nsWidgetInitData.h"
22 #include "nsTArray.h"
23 #include "nsXULAppAPI.h"
24 #include "LayersTypes.h"
26 // forward declarations
27 class nsFontMetrics;
28 class nsRenderingContext;
29 class nsDeviceContext;
30 struct nsFont;
31 class nsIRollupListener;
32 class nsGUIEvent;
33 class imgIContainer;
34 class gfxASurface;
35 class nsIContent;
36 class ViewWrapper;
37 class nsIWidgetListener;
38 class nsIntRegion;
40 namespace mozilla {
41 namespace dom {
42 class TabChild;
44 namespace layers {
45 class Composer2D;
46 class CompositorChild;
47 class LayerManager;
48 class PLayersChild;
52 /**
53 * Callback function that processes events.
55 * The argument is actually a subtype (subclass) of nsEvent which carries
56 * platform specific information about the event. Platform specific code
57 * knows how to deal with it.
59 * The return value determines whether or not the default action should take
60 * place.
62 typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
64 /**
65 * Flags for the getNativeData function.
66 * See getNativeData()
68 #define NS_NATIVE_WINDOW 0
69 #define NS_NATIVE_GRAPHIC 1
70 #define NS_NATIVE_TMP_WINDOW 2
71 #define NS_NATIVE_WIDGET 3
72 #define NS_NATIVE_DISPLAY 4
73 #define NS_NATIVE_REGION 5
74 #define NS_NATIVE_OFFSETX 6
75 #define NS_NATIVE_OFFSETY 7
76 #define NS_NATIVE_PLUGIN_PORT 8
77 #define NS_NATIVE_SCREEN 9
78 // The toplevel GtkWidget containing this nsIWidget:
79 #define NS_NATIVE_SHELLWIDGET 10
80 // Has to match to NPNVnetscapeWindow, and shareable across processes
81 // HWND on Windows and XID on X11
82 #define NS_NATIVE_SHAREABLE_WINDOW 11
83 #ifdef XP_MACOSX
84 #define NS_NATIVE_PLUGIN_PORT_QD 100
85 #define NS_NATIVE_PLUGIN_PORT_CG 101
86 #endif
87 #ifdef XP_WIN
88 #define NS_NATIVE_TSF_THREAD_MGR 100
89 #define NS_NATIVE_TSF_CATEGORY_MGR 101
90 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
91 #define NS_NATIVE_ICOREWINDOW 103 // winrt specific
92 #endif
94 #define NS_IWIDGET_IID \
95 { 0xdb9b0931, 0xebf9, 0x4e0d, \
96 { 0xb2, 0x0a, 0xf7, 0x5f, 0xcb, 0x17, 0xe6, 0xe1 } }
99 * Window shadow styles
100 * Also used for the -moz-window-shadow CSS property
103 #define NS_STYLE_WINDOW_SHADOW_NONE 0
104 #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
105 #define NS_STYLE_WINDOW_SHADOW_MENU 2
106 #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3
107 #define NS_STYLE_WINDOW_SHADOW_SHEET 4
110 * Cursor types.
113 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
114 eCursor_standard,
115 ///(system is busy, usually rendered as a hourglass or watch)
116 eCursor_wait,
117 ///(Selecting something, usually rendered as an IBeam)
118 eCursor_select,
119 ///(can hyper-link, usually rendered as a human hand)
120 eCursor_hyperlink,
121 ///(north/south/west/east edge sizing)
122 eCursor_n_resize,
123 eCursor_s_resize,
124 eCursor_w_resize,
125 eCursor_e_resize,
126 ///(corner sizing)
127 eCursor_nw_resize,
128 eCursor_se_resize,
129 eCursor_ne_resize,
130 eCursor_sw_resize,
131 eCursor_crosshair,
132 eCursor_move,
133 eCursor_help,
134 eCursor_copy, // CSS3
135 eCursor_alias,
136 eCursor_context_menu,
137 eCursor_cell,
138 eCursor_grab,
139 eCursor_grabbing,
140 eCursor_spinning,
141 eCursor_zoom_in,
142 eCursor_zoom_out,
143 eCursor_not_allowed,
144 eCursor_col_resize,
145 eCursor_row_resize,
146 eCursor_no_drop,
147 eCursor_vertical_text,
148 eCursor_all_scroll,
149 eCursor_nesw_resize,
150 eCursor_nwse_resize,
151 eCursor_ns_resize,
152 eCursor_ew_resize,
153 eCursor_none,
154 // This one better be the last one in this list.
155 eCursorCount
158 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
159 eZPlacementBottom = 0, // bottom of the window stack
160 eZPlacementBelow, // just below another widget
161 eZPlacementTop // top of the window stack
165 * Before the OS goes to sleep, this topic is notified.
167 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
170 * After the OS wakes up, this topic is notified.
172 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
175 * Before the OS suspends the current process, this topic is notified. Some
176 * OS will kill processes that are suspended instead of resuming them.
177 * For that reason this topic may be useful to safely close down resources.
179 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
182 * After the current process resumes from being suspended, this topic is
183 * notified.
185 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
188 * Preference for receiving IME updates
190 * If mWantUpdates is true, nsTextStateManager will observe text change and
191 * selection change and call nsIWidget::OnIMETextChange() and
192 * nsIWidget::OnIMESelectionChange(). The observing cost is very expensive.
193 * If the IME implementation on a particular platform doesn't care about
194 * OnIMETextChange and OnIMESelectionChange, they should set mWantUpdates to
195 * false to avoid the cost.
197 * If mWantHints is true, PuppetWidget will forward the content of text fields
198 * to the chrome process to be cached. This way we return the cached content
199 * during query events. (see comments in bug 583976). This only makes sense
200 * for IME implementations that do use query events, otherwise there's a
201 * significant overhead. Platforms that don't use query events should set
202 * mWantHints to false.
204 struct nsIMEUpdatePreference {
206 nsIMEUpdatePreference()
207 : mWantUpdates(false), mWantHints(false)
210 nsIMEUpdatePreference(bool aWantUpdates, bool aWantHints)
211 : mWantUpdates(aWantUpdates), mWantHints(aWantHints)
214 bool mWantUpdates;
215 bool mWantHints;
220 * Contains IMEStatus plus information about the current
221 * input context that the IME can use as hints if desired.
224 namespace mozilla {
225 namespace widget {
227 struct IMEState {
229 * IME enabled states, the mEnabled value of
230 * SetInputContext()/GetInputContext() should be one value of following
231 * values.
233 * WARNING: If you change these values, you also need to edit:
234 * nsIDOMWindowUtils.idl
235 * nsContentUtils::GetWidgetStatusFromIMEStatus
237 enum Enabled {
239 * 'Disabled' means the user cannot use IME. So, the IME open state should
240 * be 'closed' during 'disabled'.
242 DISABLED,
244 * 'Enabled' means the user can use IME.
246 ENABLED,
248 * 'Password' state is a special case for the password editors.
249 * E.g., on mac, the password editors should disable the non-Roman
250 * keyboard layouts at getting focus. Thus, the password editor may have
251 * special rules on some platforms.
253 PASSWORD,
255 * This state is used when a plugin is focused.
256 * When a plug-in is focused content, we should send native events
257 * directly. Because we don't process some native events, but they may
258 * be needed by the plug-in.
260 PLUGIN
262 Enabled mEnabled;
265 * IME open states the mOpen value of SetInputContext() should be one value of
266 * OPEN, CLOSE or DONT_CHANGE_OPEN_STATE. GetInputContext() should return
267 * OPEN, CLOSE or OPEN_STATE_NOT_SUPPORTED.
269 enum Open {
271 * 'Unsupported' means the platform cannot return actual IME open state.
272 * This value is used only by GetInputContext().
274 OPEN_STATE_NOT_SUPPORTED,
276 * 'Don't change' means the widget shouldn't change IME open state when
277 * SetInputContext() is called.
279 DONT_CHANGE_OPEN_STATE = OPEN_STATE_NOT_SUPPORTED,
281 * 'Open' means that IME should compose in its primary language (or latest
282 * input mode except direct ASCII character input mode). Even if IME is
283 * opened by this value, users should be able to close IME by theirselves.
284 * Web contents can specify this value by |ime-mode: active;|.
286 OPEN,
288 * 'Closed' means that IME shouldn't handle key events (or should handle
289 * as ASCII character inputs on mobile device). Even if IME is closed by
290 * this value, users should be able to open IME by theirselves.
291 * Web contents can specify this value by |ime-mode: inactive;|.
293 CLOSED
295 Open mOpen;
297 IMEState() : mEnabled(ENABLED), mOpen(DONT_CHANGE_OPEN_STATE) { }
299 IMEState(Enabled aEnabled, Open aOpen = DONT_CHANGE_OPEN_STATE) :
300 mEnabled(aEnabled), mOpen(aOpen)
305 struct InputContext {
306 InputContext() : mNativeIMEContext(nullptr) {}
308 IMEState mIMEState;
310 /* The type of the input if the input is a html input field */
311 nsString mHTMLInputType;
313 /* The type of the inputmode */
314 nsString mHTMLInputInputmode;
316 /* A hint for the action that is performed when the input is submitted */
317 nsString mActionHint;
319 /* Native IME context for the widget. This doesn't come from the argument of
320 SetInputContext(). If there is only one context in the process, this may
321 be nullptr. */
322 void* mNativeIMEContext;
325 struct InputContextAction {
327 * mCause indicates what action causes calling nsIWidget::SetInputContext().
328 * It must be one of following values.
330 enum Cause {
331 // The cause is unknown but originated from content. Focus might have been
332 // changed by content script.
333 CAUSE_UNKNOWN,
334 // The cause is unknown but originated from chrome. Focus might have been
335 // changed by chrome script.
336 CAUSE_UNKNOWN_CHROME,
337 // The cause is user's keyboard operation.
338 CAUSE_KEY,
339 // The cause is user's mouse operation.
340 CAUSE_MOUSE
342 Cause mCause;
345 * mFocusChange indicates what happened for focus.
347 enum FocusChange {
348 FOCUS_NOT_CHANGED,
349 // A content got focus.
350 GOT_FOCUS,
351 // Focused content lost focus.
352 LOST_FOCUS,
353 // Menu got pseudo focus that means focused content isn't changed but
354 // keyboard events will be handled by menu.
355 MENU_GOT_PSEUDO_FOCUS,
356 // Menu lost pseudo focus that means focused content will handle keyboard
357 // events.
358 MENU_LOST_PSEUDO_FOCUS
360 FocusChange mFocusChange;
362 bool ContentGotFocusByTrustedCause() const {
363 return (mFocusChange == GOT_FOCUS &&
364 mCause != CAUSE_UNKNOWN);
367 bool UserMightRequestOpenVKB() const {
368 return (mFocusChange == FOCUS_NOT_CHANGED &&
369 mCause == CAUSE_MOUSE);
372 InputContextAction() :
373 mCause(CAUSE_UNKNOWN), mFocusChange(FOCUS_NOT_CHANGED)
377 InputContextAction(Cause aCause,
378 FocusChange aFocusChange = FOCUS_NOT_CHANGED) :
379 mCause(aCause), mFocusChange(aFocusChange)
385 * Size constraints for setting the minimum and maximum size of a widget.
386 * Values are in device pixels.
388 struct SizeConstraints {
389 SizeConstraints()
390 : mMaxSize(NS_MAXSIZE, NS_MAXSIZE)
394 SizeConstraints(nsIntSize aMinSize,
395 nsIntSize aMaxSize)
396 : mMinSize(aMinSize),
397 mMaxSize(aMaxSize)
401 nsIntSize mMinSize;
402 nsIntSize mMaxSize;
405 } // namespace widget
406 } // namespace mozilla
409 * The base class for all the widgets. It provides the interface for
410 * all basic and necessary functionality.
412 class nsIWidget : public nsISupports {
413 protected:
414 typedef mozilla::dom::TabChild TabChild;
416 public:
417 typedef mozilla::layers::Composer2D Composer2D;
418 typedef mozilla::layers::CompositorChild CompositorChild;
419 typedef mozilla::layers::LayerManager LayerManager;
420 typedef mozilla::layers::LayersBackend LayersBackend;
421 typedef mozilla::layers::PLayersChild PLayersChild;
422 typedef mozilla::widget::IMEState IMEState;
423 typedef mozilla::widget::InputContext InputContext;
424 typedef mozilla::widget::InputContextAction InputContextAction;
425 typedef mozilla::widget::SizeConstraints SizeConstraints;
427 // Used in UpdateThemeGeometries.
428 struct ThemeGeometry {
429 // The -moz-appearance value for the themed widget
430 uint8_t mWidgetType;
431 // The device-pixel rect within the window for the themed widget
432 nsIntRect mRect;
434 ThemeGeometry(uint8_t aWidgetType, const nsIntRect& aRect)
435 : mWidgetType(aWidgetType)
436 , mRect(aRect)
440 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
442 nsIWidget()
443 : mLastChild(nullptr)
444 , mPrevSibling(nullptr)
445 , mOnDestroyCalled(false)
450 * Create and initialize a widget.
452 * All the arguments can be NULL in which case a top level window
453 * with size 0 is created. The event callback function has to be
454 * provided only if the caller wants to deal with the events this
455 * widget receives. The event callback is basically a preprocess
456 * hook called synchronously. The return value determines whether
457 * the event goes to the default window procedure or it is hidden
458 * to the os. The assumption is that if the event handler returns
459 * false the widget does not see the event. The widget should not
460 * automatically clear the window to the background color. The
461 * calling code must handle paint messages and clear the background
462 * itself.
464 * In practice at least one of aParent and aNativeParent will be null. If
465 * both are null the widget isn't parented (e.g. context menus or
466 * independent top level windows).
468 * The dimensions given in aRect are specified in the parent's
469 * coordinate system, or for parentless widgets such as top-level
470 * windows, in global CSS pixels.
472 * @param aParent parent nsIWidget
473 * @param aNativeParent native parent widget
474 * @param aRect the widget dimension
475 * @param aContext
476 * @param aInitData data that is used for widget initialization
479 NS_IMETHOD Create(nsIWidget *aParent,
480 nsNativeWidget aNativeParent,
481 const nsIntRect &aRect,
482 nsDeviceContext *aContext,
483 nsWidgetInitData *aInitData = nullptr) = 0;
486 * Allocate, initialize, and return a widget that is a child of
487 * |this|. The returned widget (if nonnull) has gone through the
488 * equivalent of CreateInstance(widgetCID) + Create(...).
490 * |CreateChild()| lets widget backends decide whether to parent
491 * the new child widget to this, nonnatively parent it, or both.
492 * This interface exists to support the PuppetWidget backend,
493 * which is entirely non-native. All other params are the same as
494 * for |Create()|.
496 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
497 * |nsIWidget*| this, not its native widget (if it exists), when
498 * calling |Create()|. This is a timid hack around poorly
499 * understood code, and shouldn't be used in new code.
501 virtual already_AddRefed<nsIWidget>
502 CreateChild(const nsIntRect &aRect,
503 nsDeviceContext *aContext,
504 nsWidgetInitData *aInitData = nullptr,
505 bool aForceUseIWidgetParent = false) = 0;
508 * Attach to a top level widget.
510 * In cases where a top level chrome widget is being used as a content
511 * container, attach a secondary listener and update the device
512 * context. The primary widget listener will continue to be called for
513 * notifications relating to the top-level window, whereas other
514 * notifications such as painting and events will instead be called via
515 * the attached listener. SetAttachedWidgetListener should be used to
516 * assign the attached listener.
518 * aUseAttachedEvents if true, events are sent to the attached listener
519 * instead of the normal listener.
520 * aContext The new device context for the view
522 NS_IMETHOD AttachViewToTopLevel(bool aUseAttachedEvents,
523 nsDeviceContext *aContext) = 0;
526 * Accessor functions to get and set the attached listener. Used by
527 * nsIView in connection with AttachViewToTopLevel above.
529 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
530 virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
533 * Accessor functions to get and set the listener which handles various
534 * actions for the widget.
536 //@{
537 virtual nsIWidgetListener* GetWidgetListener() = 0;
538 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
539 //@}
542 * Close and destroy the internal native window.
543 * This method does not delete the widget.
546 NS_IMETHOD Destroy(void) = 0;
549 * Destroyed() returns true if Destroy() has been called already.
550 * Otherwise, false.
552 bool Destroyed() const { return mOnDestroyCalled; }
556 * Reparent a widget
558 * Change the widget's parent. Null parents are allowed.
560 * @param aNewParent new parent
562 NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
564 NS_IMETHOD RegisterTouchWindow() = 0;
565 NS_IMETHOD UnregisterTouchWindow() = 0;
568 * Return the parent Widget of this Widget or nullptr if this is a
569 * top level window
571 * @return the parent widget or nullptr if it does not have a parent
574 virtual nsIWidget* GetParent(void) = 0;
577 * Return the top level Widget of this Widget
579 * @return the top level widget
581 virtual nsIWidget* GetTopLevelWidget() = 0;
584 * Return the top (non-sheet) parent of this Widget if it's a sheet,
585 * or nullptr if this isn't a sheet (or some other error occurred).
586 * Sheets are only supported on some platforms (currently only OS X).
588 * @return the top (non-sheet) parent widget or nullptr
591 virtual nsIWidget* GetSheetWindowParent(void) = 0;
594 * Return the physical DPI of the screen containing the window ...
595 * the number of device pixels per inch.
597 virtual float GetDPI() = 0;
600 * Return the default scale factor for the window. This is the
601 * default number of device pixels per CSS pixel to use. This should
602 * depend on OS/platform settings such as the Mac's "UI scale factor"
603 * or Windows' "font DPI". This will take into account Gecko preferences
604 * overriding the system setting.
606 double GetDefaultScale();
609 * Return the first child of this widget. Will return null if
610 * there are no children.
612 nsIWidget* GetFirstChild() const {
613 return mFirstChild;
617 * Return the last child of this widget. Will return null if
618 * there are no children.
620 nsIWidget* GetLastChild() const {
621 return mLastChild;
625 * Return the next sibling of this widget
627 nsIWidget* GetNextSibling() const {
628 return mNextSibling;
632 * Set the next sibling of this widget
634 void SetNextSibling(nsIWidget* aSibling) {
635 mNextSibling = aSibling;
639 * Return the previous sibling of this widget
641 nsIWidget* GetPrevSibling() const {
642 return mPrevSibling;
646 * Set the previous sibling of this widget
648 void SetPrevSibling(nsIWidget* aSibling) {
649 mPrevSibling = aSibling;
653 * Show or hide this widget
655 * @param aState true to show the Widget, false to hide it
658 NS_IMETHOD Show(bool aState) = 0;
661 * Make the window modal
664 NS_IMETHOD SetModal(bool aModal) = 0;
667 * Returns whether the window is visible
670 virtual bool IsVisible() const = 0;
673 * Perform platform-dependent sanity check on a potential window position.
674 * This is guaranteed to work only for top-level windows.
676 * @param aAllowSlop: if true, allow the window to slop offscreen;
677 * the window should be partially visible. if false,
678 * force the entire window onscreen (or at least
679 * the upper-left corner, if it's too large).
680 * @param aX in: an x position expressed in screen coordinates.
681 * out: the x position constrained to fit on the screen(s).
682 * @param aY in: an y position expressed in screen coordinates.
683 * out: the y position constrained to fit on the screen(s).
684 * @return vapid success indication. but see also the parameters.
687 NS_IMETHOD ConstrainPosition(bool aAllowSlop,
688 int32_t *aX,
689 int32_t *aY) = 0;
692 * Move this widget.
694 * Coordinates refer to the top-left of the widget. For toplevel windows
695 * with decorations, this is the top-left of the titlebar and frame .
697 * @param aX the new x position expressed in the parent's coordinate system
698 * @param aY the new y position expressed in the parent's coordinate system
701 NS_IMETHOD Move(int32_t aX, int32_t aY) = 0;
704 * Reposition this widget so that the client area has the given offset.
706 * @param aX the new x offset of the client area expressed as an
707 * offset from the origin of the client area of the parent
708 * widget (for root widgets and popup widgets it is in
709 * screen coordinates)
710 * @param aY the new y offset of the client area expressed as an
711 * offset from the origin of the client area of the parent
712 * widget (for root widgets and popup widgets it is in
713 * screen coordinates)
716 NS_IMETHOD MoveClient(int32_t aX, int32_t aY) = 0;
719 * Resize this widget. Any size constraints set for the window by a
720 * previous call to SetSizeConstraints will be applied.
722 * @param aWidth the new width expressed in the parent's coordinate system
723 * @param aHeight the new height expressed in the parent's coordinate system
724 * @param aRepaint whether the widget should be repainted
727 NS_IMETHOD Resize(int32_t aWidth,
728 int32_t aHeight,
729 bool aRepaint) = 0;
732 * Move or resize this widget. Any size constraints set for the window by
733 * a previous call to SetSizeConstraints will be applied.
735 * @param aX the new x position expressed in the parent's coordinate system
736 * @param aY the new y position expressed in the parent's coordinate system
737 * @param aWidth the new width expressed in the parent's coordinate system
738 * @param aHeight the new height expressed in the parent's coordinate system
739 * @param aRepaint whether the widget should be repainted if the size changes
742 NS_IMETHOD Resize(int32_t aX,
743 int32_t aY,
744 int32_t aWidth,
745 int32_t aHeight,
746 bool aRepaint) = 0;
749 * Resize the widget so that the inner client area has the given size.
751 * @param aWidth the new width of the client area.
752 * @param aHeight the new height of the client area.
753 * @param aRepaint whether the widget should be repainted
756 NS_IMETHOD ResizeClient(int32_t aWidth,
757 int32_t aHeight,
758 bool aRepaint) = 0;
761 * Resize and reposition the widget so tht inner client area has the given
762 * offset and size.
764 * @param aX the new x offset of the client area expressed as an
765 * offset from the origin of the client area of the parent
766 * widget (for root widgets and popup widgets it is in
767 * screen coordinates)
768 * @param aY the new y offset of the client area expressed as an
769 * offset from the origin of the client area of the parent
770 * widget (for root widgets and popup widgets it is in
771 * screen coordinates)
772 * @param aWidth the new width of the client area.
773 * @param aHeight the new height of the client area.
774 * @param aRepaint whether the widget should be repainted
777 NS_IMETHOD ResizeClient(int32_t aX,
778 int32_t aY,
779 int32_t aWidth,
780 int32_t aHeight,
781 bool aRepaint) = 0;
784 * Sets the widget's z-index.
786 NS_IMETHOD SetZIndex(int32_t aZIndex) = 0;
789 * Gets the widget's z-index.
791 NS_IMETHOD GetZIndex(int32_t* aZIndex) = 0;
794 * Position this widget just behind the given widget. (Used to
795 * control z-order for top-level widgets. Get/SetZIndex by contrast
796 * control z-order for child widgets of other widgets.)
797 * @param aPlacement top, bottom, or below a widget
798 * (if top or bottom, param aWidget is ignored)
799 * @param aWidget widget to place this widget behind
800 * (only if aPlacement is eZPlacementBelow).
801 * null is equivalent to aPlacement of eZPlacementTop
802 * @param aActivate true to activate the widget after placing it
804 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
805 nsIWidget *aWidget, bool aActivate) = 0;
808 * Minimize, maximize or normalize the window size.
809 * Takes a value from nsSizeMode (see nsGUIEvent.h)
811 NS_IMETHOD SetSizeMode(int32_t aMode) = 0;
814 * Return size mode (minimized, maximized, normalized).
815 * Returns a value from nsSizeMode (see nsGUIEvent.h)
817 NS_IMETHOD GetSizeMode(int32_t* aMode) = 0;
820 * Enable or disable this Widget
822 * @param aState true to enable the Widget, false to disable it.
825 NS_IMETHOD Enable(bool aState) = 0;
828 * Ask whether the widget is enabled
830 virtual bool IsEnabled() const = 0;
833 * Request activation of this window or give focus to this widget.
835 * @param aRaise If true, this function requests activation of this
836 * widget's toplevel window.
837 * If false, the appropriate toplevel window (which in
838 * the case of popups may not be this widget's toplevel
839 * window) is already active.
841 NS_IMETHOD SetFocus(bool aRaise = false) = 0;
844 * Get this widget's outside dimensions relative to its parent widget. For
845 * popup widgets the returned rect is in screen coordinates and not
846 * relative to its parent widget.
848 * @param aRect On return it holds the x, y, width and height of
849 * this widget.
851 NS_IMETHOD GetBounds(nsIntRect &aRect) = 0;
854 * Get this widget's outside dimensions in global coordinates. This
855 * includes any title bar on the window.
857 * @param aRect On return it holds the x, y, width and height of
858 * this widget.
860 NS_IMETHOD GetScreenBounds(nsIntRect &aRect) = 0;
863 * Get this widget's client area bounds, if the window has a 3D border
864 * appearance this returns the area inside the border. The position is the
865 * position of the client area relative to the client area of the parent
866 * widget (for root widgets and popup widgets it is in screen coordinates).
868 * @param aRect On return it holds the x. y, width and height of
869 * the client area of this widget.
871 NS_IMETHOD GetClientBounds(nsIntRect &aRect) = 0;
874 * Get the non-client area dimensions of the window.
877 NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) = 0;
880 * Sets the non-client area dimensions of the window. Pass -1 to restore
881 * the system default frame size for that border. Pass zero to remove
882 * a border, or pass a specific value adjust a border. Units are in
883 * pixels. (DPI dependent)
885 * Platform notes:
886 * Windows: shrinking top non-client height will remove application
887 * icon and window title text. Glass desktops will refuse to set
888 * dimensions between zero and size < system default.
891 NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0;
894 * Get the client offset from the window origin.
896 * @return the x and y of the offset.
899 virtual nsIntPoint GetClientOffset() = 0;
902 * Get the foreground color for this widget
904 * @return this widget's foreground color
907 virtual nscolor GetForegroundColor(void) = 0;
910 * Set the foreground color for this widget
912 * @param aColor the new foreground color
916 NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
919 * Get the background color for this widget
921 * @return this widget's background color
925 virtual nscolor GetBackgroundColor(void) = 0;
928 * Set the background color for this widget
930 * @param aColor the new background color
934 NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
937 * Get the cursor for this widget.
939 * @return this widget's cursor.
942 virtual nsCursor GetCursor(void) = 0;
945 * Set the cursor for this widget
947 * @param aCursor the new cursor for this widget
950 NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
953 * Sets an image as the cursor for this widget.
955 * @param aCursor the cursor to set
956 * @param aX the X coordinate of the hotspot (from left).
957 * @param aY the Y coordinate of the hotspot (from top).
958 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
959 * supported
961 NS_IMETHOD SetCursor(imgIContainer* aCursor,
962 uint32_t aHotspotX, uint32_t aHotspotY) = 0;
964 /**
965 * Get the window type of this widget
967 * @param aWindowType the window type of the widget
969 NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
972 * Set the transparency mode of the top-level window containing this widget.
973 * So, e.g., if you call this on the widget for an IFRAME, the top level
974 * browser window containing the IFRAME actually gets set. Be careful.
976 * This can fail if the platform doesn't support
977 * transparency/glass. By default widgets are not
978 * transparent. This will also fail if the toplevel window is not
979 * a Mozilla window, e.g., if the widget is in an embedded
980 * context.
982 * After transparency/glass has been enabled, the initial alpha channel
983 * value for all pixels is 1, i.e., opaque.
984 * If the window is resized then the alpha channel values for
985 * all pixels are reset to 1.
986 * Pixel RGB color values are already premultiplied with alpha channel values.
988 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
991 * Get the transparency mode of the top-level window that contains this
992 * widget.
994 virtual nsTransparencyMode GetTransparencyMode() = 0;
997 * This represents a command to set the bounds and clip region of
998 * a child widget.
1000 struct Configuration {
1001 nsIWidget* mChild;
1002 nsIntRect mBounds;
1003 nsTArray<nsIntRect> mClipRegion;
1007 * Sets the clip region of each mChild (which must actually be a child
1008 * of this widget) to the union of the pixel rects given in
1009 * mClipRegion, all relative to the top-left of the child
1010 * widget. Clip regions are not implemented on all platforms and only
1011 * need to actually work for children that are plugins.
1013 * Also sets the bounds of each child to mBounds.
1015 * This will invalidate areas of the children that have changed, but
1016 * does not need to invalidate any part of this widget.
1018 * Children should be moved in the order given; the array is
1019 * sorted so to minimize unnecessary invalidation if children are
1020 * moved in that order.
1022 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
1025 * Appends to aRects the rectangles constituting this widget's clip
1026 * region. If this widget is not clipped, appends a single rectangle
1027 * (0, 0, bounds.width, bounds.height).
1029 virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects) = 0;
1032 * Set the shadow style of the window.
1034 * Ignored on child widgets and on non-Mac platforms.
1036 NS_IMETHOD SetWindowShadowStyle(int32_t aStyle) = 0;
1039 * On Mac OS X, this method shows or hides the pill button in the titlebar
1040 * that's used to collapse the toolbar.
1042 * Ignored on child widgets and on non-Mac platforms.
1044 virtual void SetShowsToolbarButton(bool aShow) = 0;
1047 * On Mac OS X Lion, this method shows or hides the full screen button in
1048 * the titlebar that handles native full screen mode.
1050 * Ignored on child widgets, non-Mac platforms, & pre-Lion Mac.
1052 virtual void SetShowsFullScreenButton(bool aShow) = 0;
1054 enum WindowAnimationType {
1055 eGenericWindowAnimation,
1056 eDocumentWindowAnimation
1060 * Sets the kind of top-level window animation this widget should have. On
1061 * Mac OS X, this causes a particular kind of animation to be shown when the
1062 * window is first made visible.
1064 * Ignored on child widgets and on non-Mac platforms.
1066 virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
1068 /**
1069 * Hide window chrome (borders, buttons) for this widget.
1072 NS_IMETHOD HideWindowChrome(bool aShouldHide) = 0;
1075 * Put the toplevel window into or out of fullscreen mode.
1078 NS_IMETHOD MakeFullScreen(bool aFullScreen) = 0;
1081 * Invalidate a specified rect for a widget so that it will be repainted
1082 * later.
1084 NS_IMETHOD Invalidate(const nsIntRect & aRect) = 0;
1086 enum LayerManagerPersistence
1088 LAYER_MANAGER_CURRENT = 0,
1089 LAYER_MANAGER_PERSISTENT
1093 * Return the widget's LayerManager. The layer tree for that
1094 * LayerManager is what gets rendered to the widget.
1096 * @param aAllowRetaining an outparam that states whether the returned
1097 * layer manager should be used for retained layers
1099 inline LayerManager* GetLayerManager(bool* aAllowRetaining = nullptr)
1101 return GetLayerManager(nullptr, mozilla::layers::LAYERS_NONE,
1102 LAYER_MANAGER_CURRENT, aAllowRetaining);
1105 inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence,
1106 bool* aAllowRetaining = nullptr)
1108 return GetLayerManager(nullptr, mozilla::layers::LAYERS_NONE,
1109 aPersistence, aAllowRetaining);
1113 * Like GetLayerManager(), but prefers creating a layer manager of
1114 * type |aBackendHint| instead of what would normally be created.
1115 * LAYERS_NONE means "no hint".
1117 virtual LayerManager* GetLayerManager(PLayersChild* aShadowManager,
1118 LayersBackend aBackendHint,
1119 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
1120 bool* aAllowRetaining = nullptr) = 0;
1123 * Called before the LayerManager draws the layer tree.
1125 * @param aManager The drawing LayerManager.
1126 * @param aWidgetRect The current widget rect that is being drawn.
1128 virtual void DrawWindowUnderlay(LayerManager* aManager, nsIntRect aRect) = 0;
1131 * Called after the LayerManager draws the layer tree
1133 * @param aManager The drawing LayerManager.
1134 * @param aRect Current widget rect that is being drawn.
1136 virtual void DrawWindowOverlay(LayerManager* aManager, nsIntRect aRect) = 0;
1139 * Called when Gecko knows which themed widgets exist in this window.
1140 * The passed array contains an entry for every themed widget of the right
1141 * type (currently only NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR and
1142 * NS_THEME_TOOLBAR) within the window, except for themed widgets which are
1143 * transformed or have effects applied to them (e.g. CSS opacity or
1144 * filters).
1145 * This could sometimes be called during display list construction
1146 * outside of painting.
1147 * If called during painting, it will be called before we actually
1148 * paint anything.
1150 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1153 * Informs the widget about the region of the window that is opaque.
1155 * @param aOpaqueRegion the region of the window that is opaque.
1157 virtual void UpdateOpaqueRegion(const nsIntRegion &aOpaqueRegion) {}
1159 /**
1160 * Internal methods
1163 //@{
1164 virtual void AddChild(nsIWidget* aChild) = 0;
1165 virtual void RemoveChild(nsIWidget* aChild) = 0;
1166 virtual void* GetNativeData(uint32_t aDataType) = 0;
1167 virtual void FreeNativeData(void * data, uint32_t aDataType) = 0;//~~~
1169 // GetDeviceContext returns a weak pointer to this widget's device context
1170 virtual nsDeviceContext* GetDeviceContext() = 0;
1172 //@}
1175 * Set the widget's title.
1176 * Must be called after Create.
1178 * @param aTitle string displayed as the title of the widget
1181 NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
1184 * Set the widget's icon.
1185 * Must be called after Create.
1187 * @param anIconSpec string specifying the icon to use; convention is to pass
1188 * a resource: URL from which a platform-dependent resource
1189 * file name will be constructed
1192 NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
1195 * Return this widget's origin in screen coordinates.
1197 * @return screen coordinates stored in the x,y members
1200 virtual nsIntPoint WidgetToScreenOffset() = 0;
1203 * Given the specified client size, return the corresponding window size,
1204 * which includes the area for the borders and titlebar. This method
1205 * should work even when the window is not yet visible.
1207 virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) = 0;
1210 * Dispatches an event to the widget
1213 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
1216 * Enables the dropping of files to a widget (XXX this is temporary)
1219 NS_IMETHOD EnableDragDrop(bool aEnable) = 0;
1222 * Enables/Disables system mouse capture.
1223 * @param aCapture true enables mouse capture, false disables mouse capture
1226 NS_IMETHOD CaptureMouse(bool aCapture) = 0;
1229 * Classify the window for the window manager. Mostly for X11.
1231 NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0;
1234 * Enables/Disables system capture of any and all events that would cause a
1235 * popup to be rolled up. aListener should be set to a non-null value for
1236 * any popups that are not managed by the popup manager.
1237 * @param aDoCapture true enables capture, false disables capture
1240 NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture) = 0;
1243 * Bring this window to the user's attention. This is intended to be a more
1244 * gentle notification than popping the window to the top or putting up an
1245 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1246 * the Mac. The notification should be suppressed if the window is already
1247 * in the foreground and should be dismissed when the user brings this window
1248 * to the foreground.
1249 * @param aCycleCount Maximum number of times to animate the window per system
1250 * conventions. If set to -1, cycles indefinitely until
1251 * window is brought into the foreground.
1253 NS_IMETHOD GetAttention(int32_t aCycleCount) = 0;
1256 * Ask whether there user input events pending. All input events are
1257 * included, including those not targeted at this nsIwidget instance.
1259 virtual bool HasPendingInputEvent() = 0;
1262 * Called when when we need to begin secure keyboard input, such as when a password field
1263 * gets focus.
1265 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
1266 * for one widget at a time.
1268 NS_IMETHOD BeginSecureKeyboardInput() = 0;
1271 * Called when when we need to end secure keyboard input, such as when a password field
1272 * loses focus.
1274 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
1275 * for one widget at a time.
1277 NS_IMETHOD EndSecureKeyboardInput() = 0;
1280 * Set the background color of the window titlebar for this widget. On Mac,
1281 * for example, this will remove the grey gradient and bottom border and
1282 * instead show a single, solid color.
1284 * Ignored on any platform that does not support it. Ignored by widgets that
1285 * do not represent windows.
1287 * @param aColor The color to set the title bar background to. Alpha values
1288 * other than fully transparent (0) are respected if possible
1289 * on the platform. An alpha of 0 will cause the window to
1290 * draw with the default style for the platform.
1292 * @param aActive Whether the color should be applied to active or inactive
1293 * windows.
1295 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive) = 0;
1298 * If set to true, the window will draw its contents into the titlebar
1299 * instead of below it.
1301 * Ignored on any platform that does not support it. Ignored by widgets that
1302 * do not represent windows.
1303 * May result in a resize event, so should only be called from places where
1304 * reflow and painting is allowed.
1306 * @param aState Whether drawing into the titlebar should be activated.
1308 virtual void SetDrawsInTitlebar(bool aState) = 0;
1311 * Determine whether the widget shows a resize widget. If it does,
1312 * aResizerRect returns the resizer's rect.
1314 * Returns false on any platform that does not support it.
1316 * @param aResizerRect The resizer's rect in device pixels.
1317 * @return Whether a resize widget is shown.
1319 virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0;
1322 * Get the Thebes surface associated with this widget.
1324 virtual gfxASurface *GetThebesSurface() = 0;
1327 * Return the popup that was last rolled up, or null if there isn't one.
1329 virtual nsIContent* GetLastRollup() = 0;
1332 * Begin a window resizing drag, based on the event passed in.
1334 NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, int32_t aHorizontal, int32_t aVertical) = 0;
1337 * Begin a window moving drag, based on the event passed in.
1339 NS_IMETHOD BeginMoveDrag(nsMouseEvent* aEvent) = 0;
1341 enum Modifiers {
1342 CAPS_LOCK = 0x01, // when CapsLock is active
1343 NUM_LOCK = 0x02, // when NumLock is active
1344 SHIFT_L = 0x0100,
1345 SHIFT_R = 0x0200,
1346 CTRL_L = 0x0400,
1347 CTRL_R = 0x0800,
1348 ALT_L = 0x1000, // includes Option
1349 ALT_R = 0x2000,
1350 COMMAND_L = 0x4000,
1351 COMMAND_R = 0x8000,
1352 HELP = 0x10000,
1353 FUNCTION = 0x100000,
1354 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1357 * Utility method intended for testing. Dispatches native key events
1358 * to this widget to simulate the press and release of a key.
1359 * @param aNativeKeyboardLayout a *platform-specific* constant.
1360 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1361 * On Windows, it is converted to a hex string and passed to
1362 * LoadKeyboardLayout, see
1363 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1364 * @param aNativeKeyCode a *platform-specific* keycode.
1365 * On Windows, this is the virtual key code.
1366 * @param aModifiers some combination of the above 'Modifiers' flags;
1367 * not all flags will apply to all platforms. Mac ignores the _R
1368 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1369 * FUNCTION.
1370 * @param aCharacters characters that the OS would decide to generate
1371 * from the event. On Windows, this is the charCode passed by
1372 * WM_CHAR.
1373 * @param aUnmodifiedCharacters characters that the OS would decide
1374 * to generate from the event if modifier keys (other than shift)
1375 * were assumed inactive. Needed on Mac, ignored on Windows.
1376 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1377 * layout is not supported and the event was not fired
1379 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
1380 int32_t aNativeKeyCode,
1381 uint32_t aModifierFlags,
1382 const nsAString& aCharacters,
1383 const nsAString& aUnmodifiedCharacters) = 0;
1386 * Utility method intended for testing. Dispatches native mouse events
1387 * may even move the mouse cursor. On Mac the events are guaranteed to
1388 * be sent to the window containing this widget, but on Windows they'll go
1389 * to whatever's topmost on the screen at that position, so for
1390 * cross-platform testing ensure that your window is at the top of the
1391 * z-order.
1392 * @param aPoint screen location of the mouse, in device
1393 * pixels, with origin at the top left
1394 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
1395 * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
1396 * @param aModifierFlags *platform-specific* modifier flags (ignored
1397 * on Windows)
1399 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
1400 uint32_t aNativeMessage,
1401 uint32_t aModifierFlags) = 0;
1404 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native message.
1405 * aPoint is location in device pixels to which the mouse pointer moves to.
1407 virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) = 0;
1410 * Utility method intended for testing. Dispatching native mouse scroll
1411 * events may move the mouse cursor.
1413 * @param aPoint Mouse cursor position in screen coordinates.
1414 * In device pixels, the origin at the top left of
1415 * the primary display.
1416 * @param aNativeMessage Platform native message.
1417 * @param aDeltaX The delta value for X direction. If the native
1418 * message doesn't indicate X direction scrolling,
1419 * this may be ignored.
1420 * @param aDeltaY The delta value for Y direction. If the native
1421 * message doesn't indicate Y direction scrolling,
1422 * this may be ignored.
1423 * @param aDeltaZ The delta value for Z direction. If the native
1424 * message doesn't indicate Z direction scrolling,
1425 * this may be ignored.
1426 * @param aModifierFlags Must be values of Modifiers, or zero.
1427 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1428 * document.
1430 virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint,
1431 uint32_t aNativeMessage,
1432 double aDeltaX,
1433 double aDeltaY,
1434 double aDeltaZ,
1435 uint32_t aModifierFlags,
1436 uint32_t aAdditionalFlags) = 0;
1439 * Activates a native menu item at the position specified by the index
1440 * string. The index string is a string of positive integers separated
1441 * by the "|" (pipe) character. The last integer in the string represents
1442 * the item index in a submenu located using the integers preceding it.
1444 * Example: 1|0|4
1445 * In this string, the first integer represents the top-level submenu
1446 * in the native menu bar. Since the integer is 1, it is the second submeu
1447 * in the native menu bar. Within that, the first item (index 0) is a
1448 * submenu, and we want to activate the 5th item within that submenu.
1450 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1453 * This is used for native menu system testing.
1455 * Updates a native menu at the position specified by the index string.
1456 * The index string is a string of positive integers separated by the "|"
1457 * (pipe) character.
1459 * Example: 1|0|4
1460 * In this string, the first integer represents the top-level submenu
1461 * in the native menu bar. Since the integer is 1, it is the second submeu
1462 * in the native menu bar. Within that, the first item (index 0) is a
1463 * submenu, and we want to update submenu at index 4 within that submenu.
1465 * If this is called with an empty string it forces a full reload of the
1466 * menu system.
1468 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1471 * Force Input Method Editor to commit the uncommitted input
1473 NS_IMETHOD ResetInputState()=0;
1476 * Following methods relates to IME 'Opened'/'Closed' state.
1477 * 'Opened' means the user can input any character. I.e., users can input Japanese
1478 * and other characters. The user can change the state to 'Closed'.
1479 * 'Closed' means the user can input ASCII characters only. This is the same as a
1480 * non-IME environment. The user can change the state to 'Opened'.
1481 * For more information is here.
1482 * http://bugzilla.mozilla.org/show_bug.cgi?id=16940#c48
1486 * Destruct and don't commit the IME composition string.
1488 NS_IMETHOD CancelIMEComposition() = 0;
1491 * Notifies the input context changes.
1493 NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
1494 const InputContextAction& aAction) = 0;
1497 * Get current input context.
1499 NS_IMETHOD_(InputContext) GetInputContext() = 0;
1502 * Set layers acceleration to 'True' or 'False'
1504 NS_IMETHOD SetLayersAcceleration(bool aEnabled) = 0;
1507 * Get toggled key states.
1508 * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or
1509 * NS_VK_SCROLL_LOCK.
1510 * aLEDState is the result for current LED state of the key.
1511 * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
1512 * If the platform doesn't support the LED state (or we cannot get the
1513 * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
1515 NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) = 0;
1518 * An editable node (i.e. input/textarea/design mode document)
1519 * is receiving or giving up focus
1520 * aFocus is true if node is receiving focus
1521 * aFocus is false if node is giving up focus (blur)
1523 NS_IMETHOD OnIMEFocusChange(bool aFocus) = 0;
1526 * Text content of the focused node has changed
1527 * aStart is the starting offset of the change
1528 * aOldEnd is the ending offset of the change
1529 * aNewEnd is the caret offset after the change
1531 NS_IMETHOD OnIMETextChange(uint32_t aStart,
1532 uint32_t aOldEnd,
1533 uint32_t aNewEnd) = 0;
1536 * Selection has changed in the focused node
1538 NS_IMETHOD OnIMESelectionChange(void) = 0;
1541 * Retrieves preference for IME updates
1543 virtual nsIMEUpdatePreference GetIMEUpdatePreference() = 0;
1546 * Call this method when a dialog is opened which has a default button.
1547 * The button's rectangle should be supplied in aButtonRect.
1549 NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) = 0;
1552 * Compute the overridden system mouse scroll speed on the root content of
1553 * web pages. The widget may set the same value as aOriginalDelta. E.g.,
1554 * when the system scrolling settings were customized, widget can respect
1555 * the will of the user.
1557 * This is called only when the mouse wheel event scrolls the root content
1558 * of the web pages by line. In other words, this isn't called when the
1559 * mouse wheel event is used for zoom, page scroll and other special
1560 * actions. And also this isn't called when the user doesn't use the
1561 * system wheel speed settings.
1563 * @param aOriginalDelta The delta value of the current mouse wheel
1564 * scrolling event.
1565 * @param aIsHorizontal If TRUE, the scrolling direction is horizontal.
1566 * Otherwise, it's vertical.
1567 * @param aOverriddenDelta The overridden mouse scrolling speed. This value
1568 * may be same as aOriginalDelta.
1570 NS_IMETHOD OverrideSystemMouseScrollSpeed(int32_t aOriginalDelta,
1571 bool aIsHorizontal,
1572 int32_t &aOverriddenDelta) = 0;
1575 * Return true if this process shouldn't use platform widgets, and
1576 * so should use PuppetWidgets instead. If this returns true, the
1577 * result of creating and using a platform widget is undefined,
1578 * and likely to end in crashes or other buggy behavior.
1580 static bool
1581 UsePuppetWidgets()
1583 return XRE_GetProcessType() == GeckoProcessType_Content;
1587 * Allocate and return a "puppet widget" that doesn't directly
1588 * correlate to a platform widget; platform events and data must
1589 * be fed to it. Currently used in content processes. NULL is
1590 * returned if puppet widgets aren't supported in this build
1591 * config, on this platform, or for this process type.
1593 * This function is called "Create" to match CreateInstance().
1594 * The returned widget must still be nsIWidget::Create()d.
1596 static already_AddRefed<nsIWidget>
1597 CreatePuppetWidget(TabChild* aTabChild);
1600 * Reparent this widget's native widget.
1601 * @param aNewParent the native widget of aNewParent is the new native
1602 * parent widget
1604 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0;
1607 * Return the internal format of the default framebuffer for this
1608 * widget.
1610 virtual uint32_t GetGLFrameBufferFormat() { return 0; /*GL_NONE*/ }
1613 * Return true if widget has it's own GL context
1615 virtual bool HasGLContext() { return false; }
1618 * Returns true to indicate that this widget paints an opaque background
1619 * that we want to be visible under the page, so layout should not force
1620 * a default background.
1622 virtual bool WidgetPaintsBackground() { return false; }
1624 virtual bool NeedsPaint() {
1625 return true;
1628 * Get the natural bounds of this widget. This method is only
1629 * meaningful for widgets for which Gecko implements screen
1630 * rotation natively. When this is the case, GetBounds() returns
1631 * the widget bounds taking rotation into account, and
1632 * GetNaturalBounds() returns the bounds *not* taking rotation
1633 * into account.
1635 * No code outside of the composition pipeline should know or care
1636 * about this. If you're not an agent of the compositor, you
1637 * probably shouldn't call this method.
1639 virtual nsIntRect GetNaturalBounds() {
1640 nsIntRect bounds;
1641 GetBounds(bounds);
1642 return bounds;
1646 * Set size constraints on the window size such that it is never less than
1647 * the specified minimum size and never larger than the specified maximum
1648 * size. The size constraints are sizes of the outer rectangle including
1649 * the window frame and title bar. Use 0 for an unconstrained minimum size
1650 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
1651 * does not necessarily change the size of a window to conform to this size,
1652 * thus Resize should be called afterwards.
1654 * @param aConstraints: the size constraints in device pixels
1656 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
1659 * Return the size constraints currently observed by the widget.
1661 * @return the constraints in device pixels
1663 virtual const SizeConstraints& GetSizeConstraints() const = 0;
1666 * If this is owned by a TabChild, return that. Otherwise return
1667 * null.
1669 virtual TabChild* GetOwningTabChild() { return nullptr; }
1672 * If this isn't directly compositing to its window surface,
1673 * return the compositor which is doing that on our behalf.
1675 virtual CompositorChild* GetRemoteRenderer()
1676 { return nullptr; }
1679 * If this widget has a more efficient composer available for its
1680 * native framebuffer, return it.
1682 * This can be called from a non-main thread, but that thread must
1683 * hold a strong reference to this.
1685 virtual Composer2D* GetComposer2D()
1686 { return nullptr; }
1688 protected:
1690 * Like GetDefaultScale, but taking into account only the system settings
1691 * and ignoring Gecko preferences.
1693 virtual double GetDefaultScaleInternal() { return 1.0; }
1695 // keep the list of children. We also keep track of our siblings.
1696 // The ownership model is as follows: parent holds a strong ref to
1697 // the first element of the list, and each element holds a strong
1698 // ref to the next element in the list. The prevsibling and
1699 // lastchild pointers are weak, which is fine as long as they are
1700 // maintained properly.
1701 nsCOMPtr<nsIWidget> mFirstChild;
1702 nsIWidget* mLastChild;
1703 nsCOMPtr<nsIWidget> mNextSibling;
1704 nsIWidget* mPrevSibling;
1705 // When Destroy() is called, the sub class should set this true.
1706 bool mOnDestroyCalled;
1709 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
1711 #endif // nsIWidget_h__