Bumping manifests a=b2g-bump
[gecko.git] / widget / nsIWidget.h
blob1f760207cb7136e55f41a1676ad5db968e7c7072
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 "nsAutoPtr.h"
16 #include "nsWidgetInitData.h"
17 #include "nsTArray.h"
18 #include "nsITimer.h"
19 #include "nsXULAppAPI.h"
20 #include "mozilla/EventForwards.h"
21 #include "mozilla/layers/LayersTypes.h"
22 #include "mozilla/RefPtr.h"
23 #include "mozilla/TimeStamp.h"
24 #include "Units.h"
26 // forward declarations
27 class nsFontMetrics;
28 class nsRenderingContext;
29 class nsDeviceContext;
30 struct nsFont;
31 class nsIRollupListener;
32 class imgIContainer;
33 class nsIContent;
34 class ViewWrapper;
35 class nsIWidgetListener;
36 class nsIntRegion;
38 namespace mozilla {
39 namespace dom {
40 class TabChild;
42 namespace layers {
43 class Composer2D;
44 class CompositorChild;
45 class LayerManager;
46 class LayerManagerComposite;
47 class PLayerTransactionChild;
49 namespace gfx {
50 class DrawTarget;
54 /**
55 * Callback function that processes events.
57 * The argument is actually a subtype (subclass) of WidgetEvent which carries
58 * platform specific information about the event. Platform specific code
59 * knows how to deal with it.
61 * The return value determines whether or not the default action should take
62 * place.
64 typedef nsEventStatus (* EVENT_CALLBACK)(mozilla::WidgetGUIEvent* aEvent);
66 // Hide the native window system's real window type so as to avoid
67 // including native window system types and APIs. This is necessary
68 // to ensure cross-platform code.
69 typedef void* nsNativeWidget;
71 /**
72 * Flags for the getNativeData function.
73 * See getNativeData()
75 #define NS_NATIVE_WINDOW 0
76 #define NS_NATIVE_GRAPHIC 1
77 #define NS_NATIVE_TMP_WINDOW 2
78 #define NS_NATIVE_WIDGET 3
79 #define NS_NATIVE_DISPLAY 4
80 #define NS_NATIVE_REGION 5
81 #define NS_NATIVE_OFFSETX 6
82 #define NS_NATIVE_OFFSETY 7
83 #define NS_NATIVE_PLUGIN_PORT 8
84 #define NS_NATIVE_SCREEN 9
85 // The toplevel GtkWidget containing this nsIWidget:
86 #define NS_NATIVE_SHELLWIDGET 10
87 // Has to match to NPNVnetscapeWindow, and shareable across processes
88 // HWND on Windows and XID on X11
89 #define NS_NATIVE_SHAREABLE_WINDOW 11
90 #ifdef XP_MACOSX
91 #define NS_NATIVE_PLUGIN_PORT_QD 100
92 #define NS_NATIVE_PLUGIN_PORT_CG 101
93 #endif
94 #ifdef XP_WIN
95 #define NS_NATIVE_TSF_THREAD_MGR 100
96 #define NS_NATIVE_TSF_CATEGORY_MGR 101
97 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
98 #define NS_NATIVE_ICOREWINDOW 103 // winrt specific
99 #endif
101 #define NS_IWIDGET_IID \
102 { 0x5b27abd6, 0x9e53, 0x4a0a, \
103 { 0x86, 0xf, 0x77, 0x5c, 0xc5, 0x69, 0x35, 0xf } };
106 * Window shadow styles
107 * Also used for the -moz-window-shadow CSS property
110 #define NS_STYLE_WINDOW_SHADOW_NONE 0
111 #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
112 #define NS_STYLE_WINDOW_SHADOW_MENU 2
113 #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3
114 #define NS_STYLE_WINDOW_SHADOW_SHEET 4
117 * Transparency modes
120 enum nsTransparencyMode {
121 eTransparencyOpaque = 0, // Fully opaque
122 eTransparencyTransparent, // Parts of the window may be transparent
123 eTransparencyGlass, // Transparent parts of the window have Vista AeroGlass effect applied
124 eTransparencyBorderlessGlass // As above, but without a border around the opaque areas when there would otherwise be one with eTransparencyGlass
128 * Cursor types.
131 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
132 eCursor_standard,
133 ///(system is busy, usually rendered as a hourglass or watch)
134 eCursor_wait,
135 ///(Selecting something, usually rendered as an IBeam)
136 eCursor_select,
137 ///(can hyper-link, usually rendered as a human hand)
138 eCursor_hyperlink,
139 ///(north/south/west/east edge sizing)
140 eCursor_n_resize,
141 eCursor_s_resize,
142 eCursor_w_resize,
143 eCursor_e_resize,
144 ///(corner sizing)
145 eCursor_nw_resize,
146 eCursor_se_resize,
147 eCursor_ne_resize,
148 eCursor_sw_resize,
149 eCursor_crosshair,
150 eCursor_move,
151 eCursor_help,
152 eCursor_copy, // CSS3
153 eCursor_alias,
154 eCursor_context_menu,
155 eCursor_cell,
156 eCursor_grab,
157 eCursor_grabbing,
158 eCursor_spinning,
159 eCursor_zoom_in,
160 eCursor_zoom_out,
161 eCursor_not_allowed,
162 eCursor_col_resize,
163 eCursor_row_resize,
164 eCursor_no_drop,
165 eCursor_vertical_text,
166 eCursor_all_scroll,
167 eCursor_nesw_resize,
168 eCursor_nwse_resize,
169 eCursor_ns_resize,
170 eCursor_ew_resize,
171 eCursor_none,
172 // This one better be the last one in this list.
173 eCursorCount
176 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
177 eZPlacementBottom = 0, // bottom of the window stack
178 eZPlacementBelow, // just below another widget
179 eZPlacementTop // top of the window stack
183 * Before the OS goes to sleep, this topic is notified.
185 #define NS_WIDGET_SLEEP_OBSERVER_TOPIC "sleep_notification"
188 * After the OS wakes up, this topic is notified.
190 #define NS_WIDGET_WAKE_OBSERVER_TOPIC "wake_notification"
193 * Before the OS suspends the current process, this topic is notified. Some
194 * OS will kill processes that are suspended instead of resuming them.
195 * For that reason this topic may be useful to safely close down resources.
197 #define NS_WIDGET_SUSPEND_PROCESS_OBSERVER_TOPIC "suspend_process_notification"
200 * After the current process resumes from being suspended, this topic is
201 * notified.
203 #define NS_WIDGET_RESUME_PROCESS_OBSERVER_TOPIC "resume_process_notification"
206 * Preference for receiving IME updates
208 * If mWantUpdates is not NOTIFY_NOTHING, nsTextStateManager will observe text
209 * change and/or selection change and call nsIWidget::NotifyIME() with
210 * NOTIFY_IME_OF_SELECTION_CHANGE and/or NOTIFY_IME_OF_TEXT_CHANGE.
211 * Please note that the text change observing cost is very expensive especially
212 * on an HTML editor has focus.
213 * If the IME implementation on a particular platform doesn't care about
214 * NOTIFY_IME_OF_SELECTION_CHANGE and/or NOTIFY_IME_OF_TEXT_CHANGE,
215 * they should set mWantUpdates to NOTIFY_NOTHING to avoid the cost.
216 * If the IME implementation needs notifications even while our process is
217 * deactive, it should also set NOTIFY_DURING_DEACTIVE.
219 struct nsIMEUpdatePreference {
221 typedef uint8_t Notifications;
223 enum MOZ_ENUM_TYPE(Notifications)
225 NOTIFY_NOTHING = 0,
226 NOTIFY_SELECTION_CHANGE = 1 << 0,
227 NOTIFY_TEXT_CHANGE = 1 << 1,
228 NOTIFY_POSITION_CHANGE = 1 << 2,
229 // NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR is used when mouse button is pressed
230 // or released on a character in the focused editor. The notification is
231 // notified to IME as a mouse event. If it's consumed by IME, NotifyIME()
232 // returns NS_SUCCESS_EVENT_CONSUMED. Otherwise, it returns NS_OK if it's
233 // handled without any error.
234 NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR = 1 << 3,
235 // Following values indicate when widget needs or doesn't need notification.
236 NOTIFY_CHANGES_CAUSED_BY_COMPOSITION = 1 << 6,
237 // NOTE: NOTIFY_DURING_DEACTIVE isn't supported in environments where two
238 // or more compositions are possible. E.g., Mac and Linux (GTK).
239 NOTIFY_DURING_DEACTIVE = 1 << 7,
240 // Changes are notified in following conditions if the instance is
241 // just constructed. If some platforms don't need change notifications
242 // in some of following conditions, the platform should remove following
243 // flags before returing the instance from nsIWidget::GetUpdatePreference().
244 DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES =
245 NOTIFY_CHANGES_CAUSED_BY_COMPOSITION
248 nsIMEUpdatePreference()
249 : mWantUpdates(DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES)
253 explicit nsIMEUpdatePreference(Notifications aWantUpdates)
254 : mWantUpdates(aWantUpdates | DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES)
258 void DontNotifyChangesCausedByComposition()
260 mWantUpdates &= ~DEFAULT_CONDITIONS_OF_NOTIFYING_CHANGES;
263 bool WantSelectionChange() const
265 return !!(mWantUpdates & NOTIFY_SELECTION_CHANGE);
268 bool WantTextChange() const
270 return !!(mWantUpdates & NOTIFY_TEXT_CHANGE);
273 bool WantPositionChanged() const
275 return !!(mWantUpdates & NOTIFY_POSITION_CHANGE);
278 bool WantChanges() const
280 return WantSelectionChange() || WantTextChange();
283 bool WantMouseButtonEventOnChar() const
285 return !!(mWantUpdates & NOTIFY_MOUSE_BUTTON_EVENT_ON_CHAR);
288 bool WantChangesCausedByComposition() const
290 return WantChanges() &&
291 !!(mWantUpdates & NOTIFY_CHANGES_CAUSED_BY_COMPOSITION);
294 bool WantDuringDeactive() const
296 return !!(mWantUpdates & NOTIFY_DURING_DEACTIVE);
299 Notifications mWantUpdates;
304 * Contains IMEStatus plus information about the current
305 * input context that the IME can use as hints if desired.
308 namespace mozilla {
309 namespace widget {
311 struct IMEState {
313 * IME enabled states, the mEnabled value of
314 * SetInputContext()/GetInputContext() should be one value of following
315 * values.
317 * WARNING: If you change these values, you also need to edit:
318 * nsIDOMWindowUtils.idl
319 * nsContentUtils::GetWidgetStatusFromIMEStatus
321 enum Enabled {
323 * 'Disabled' means the user cannot use IME. So, the IME open state should
324 * be 'closed' during 'disabled'.
326 DISABLED,
328 * 'Enabled' means the user can use IME.
330 ENABLED,
332 * 'Password' state is a special case for the password editors.
333 * E.g., on mac, the password editors should disable the non-Roman
334 * keyboard layouts at getting focus. Thus, the password editor may have
335 * special rules on some platforms.
337 PASSWORD,
339 * This state is used when a plugin is focused.
340 * When a plug-in is focused content, we should send native events
341 * directly. Because we don't process some native events, but they may
342 * be needed by the plug-in.
344 PLUGIN
346 Enabled mEnabled;
349 * IME open states the mOpen value of SetInputContext() should be one value of
350 * OPEN, CLOSE or DONT_CHANGE_OPEN_STATE. GetInputContext() should return
351 * OPEN, CLOSE or OPEN_STATE_NOT_SUPPORTED.
353 enum Open {
355 * 'Unsupported' means the platform cannot return actual IME open state.
356 * This value is used only by GetInputContext().
358 OPEN_STATE_NOT_SUPPORTED,
360 * 'Don't change' means the widget shouldn't change IME open state when
361 * SetInputContext() is called.
363 DONT_CHANGE_OPEN_STATE = OPEN_STATE_NOT_SUPPORTED,
365 * 'Open' means that IME should compose in its primary language (or latest
366 * input mode except direct ASCII character input mode). Even if IME is
367 * opened by this value, users should be able to close IME by theirselves.
368 * Web contents can specify this value by |ime-mode: active;|.
370 OPEN,
372 * 'Closed' means that IME shouldn't handle key events (or should handle
373 * as ASCII character inputs on mobile device). Even if IME is closed by
374 * this value, users should be able to open IME by theirselves.
375 * Web contents can specify this value by |ime-mode: inactive;|.
377 CLOSED
379 Open mOpen;
381 IMEState() : mEnabled(ENABLED), mOpen(DONT_CHANGE_OPEN_STATE) { }
383 explicit IMEState(Enabled aEnabled, Open aOpen = DONT_CHANGE_OPEN_STATE) :
384 mEnabled(aEnabled), mOpen(aOpen)
388 bool IsEditable() const
390 return mEnabled == ENABLED || mEnabled == PASSWORD;
394 struct InputContext {
395 InputContext() : mNativeIMEContext(nullptr) {}
397 bool IsPasswordEditor() const
399 return mHTMLInputType.LowerCaseEqualsLiteral("password");
402 IMEState mIMEState;
404 /* The type of the input if the input is a html input field */
405 nsString mHTMLInputType;
407 /* The type of the inputmode */
408 nsString mHTMLInputInputmode;
410 /* A hint for the action that is performed when the input is submitted */
411 nsString mActionHint;
413 /* Native IME context for the widget. This doesn't come from the argument of
414 SetInputContext(). If there is only one context in the process, this may
415 be nullptr. */
416 void* mNativeIMEContext;
419 struct InputContextAction {
421 * mCause indicates what action causes calling nsIWidget::SetInputContext().
422 * It must be one of following values.
424 enum Cause {
425 // The cause is unknown but originated from content. Focus might have been
426 // changed by content script.
427 CAUSE_UNKNOWN,
428 // The cause is unknown but originated from chrome. Focus might have been
429 // changed by chrome script.
430 CAUSE_UNKNOWN_CHROME,
431 // The cause is user's keyboard operation.
432 CAUSE_KEY,
433 // The cause is user's mouse operation.
434 CAUSE_MOUSE
436 Cause mCause;
439 * mFocusChange indicates what happened for focus.
441 enum FocusChange {
442 FOCUS_NOT_CHANGED,
443 // A content got focus.
444 GOT_FOCUS,
445 // Focused content lost focus.
446 LOST_FOCUS,
447 // Menu got pseudo focus that means focused content isn't changed but
448 // keyboard events will be handled by menu.
449 MENU_GOT_PSEUDO_FOCUS,
450 // Menu lost pseudo focus that means focused content will handle keyboard
451 // events.
452 MENU_LOST_PSEUDO_FOCUS
454 FocusChange mFocusChange;
456 bool ContentGotFocusByTrustedCause() const {
457 return (mFocusChange == GOT_FOCUS &&
458 mCause != CAUSE_UNKNOWN);
461 bool UserMightRequestOpenVKB() const {
462 return (mFocusChange == FOCUS_NOT_CHANGED &&
463 mCause == CAUSE_MOUSE);
466 InputContextAction() :
467 mCause(CAUSE_UNKNOWN), mFocusChange(FOCUS_NOT_CHANGED)
471 explicit InputContextAction(Cause aCause,
472 FocusChange aFocusChange = FOCUS_NOT_CHANGED) :
473 mCause(aCause), mFocusChange(aFocusChange)
479 * Size constraints for setting the minimum and maximum size of a widget.
480 * Values are in device pixels.
482 struct SizeConstraints {
483 SizeConstraints()
484 : mMaxSize(NS_MAXSIZE, NS_MAXSIZE)
488 SizeConstraints(nsIntSize aMinSize,
489 nsIntSize aMaxSize)
490 : mMinSize(aMinSize),
491 mMaxSize(aMaxSize)
495 nsIntSize mMinSize;
496 nsIntSize mMaxSize;
499 // IMEMessage is shared by IMEStateManager and TextComposition.
500 // Update values in GeckoEditable.java if you make changes here.
501 // XXX Negative values are used in Android...
502 enum IMEMessage MOZ_ENUM_TYPE(int8_t)
504 // XXX We should replace NOTIFY_IME_OF_CURSOR_POS_CHANGED with
505 // NOTIFY_IME_OF_SELECTION_CHANGE later.
506 NOTIFY_IME_OF_CURSOR_POS_CHANGED,
507 // An editable content is getting focus
508 NOTIFY_IME_OF_FOCUS,
509 // An editable content is losing focus
510 NOTIFY_IME_OF_BLUR,
511 // Selection in the focused editable content is changed
512 NOTIFY_IME_OF_SELECTION_CHANGE,
513 // Text in the focused editable content is changed
514 NOTIFY_IME_OF_TEXT_CHANGE,
515 // Composition string has been updated
516 NOTIFY_IME_OF_COMPOSITION_UPDATE,
517 // Position or size of focused element may be changed.
518 NOTIFY_IME_OF_POSITION_CHANGE,
519 // Mouse button event is fired on a character in focused editor
520 NOTIFY_IME_OF_MOUSE_BUTTON_EVENT,
521 // Request to commit current composition to IME
522 // (some platforms may not support)
523 REQUEST_TO_COMMIT_COMPOSITION,
524 // Request to cancel current composition to IME
525 // (some platforms may not support)
526 REQUEST_TO_CANCEL_COMPOSITION
529 struct IMENotification
531 MOZ_IMPLICIT IMENotification(IMEMessage aMessage)
532 : mMessage(aMessage)
534 switch (aMessage) {
535 case NOTIFY_IME_OF_SELECTION_CHANGE:
536 mSelectionChangeData.mCausedByComposition = false;
537 break;
538 case NOTIFY_IME_OF_TEXT_CHANGE:
539 mTextChangeData.mStartOffset = 0;
540 mTextChangeData.mOldEndOffset = 0;
541 mTextChangeData.mNewEndOffset = 0;
542 mTextChangeData.mCausedByComposition = false;
543 break;
544 case NOTIFY_IME_OF_MOUSE_BUTTON_EVENT:
545 mMouseButtonEventData.mEventMessage = 0;
546 mMouseButtonEventData.mOffset = UINT32_MAX;
547 mMouseButtonEventData.mCursorPos.Set(nsIntPoint(0, 0));
548 mMouseButtonEventData.mCharRect.Set(nsIntRect(0, 0, 0, 0));
549 mMouseButtonEventData.mButton = -1;
550 mMouseButtonEventData.mButtons = 0;
551 mMouseButtonEventData.mModifiers = 0;
552 default:
553 break;
557 IMEMessage mMessage;
559 union
561 // NOTIFY_IME_OF_SELECTION_CHANGE specific data
562 struct
564 bool mCausedByComposition;
565 } mSelectionChangeData;
567 // NOTIFY_IME_OF_TEXT_CHANGE specific data
568 struct
570 uint32_t mStartOffset;
571 uint32_t mOldEndOffset;
572 uint32_t mNewEndOffset;
574 bool mCausedByComposition;
576 uint32_t OldLength() const { return mOldEndOffset - mStartOffset; }
577 uint32_t NewLength() const { return mNewEndOffset - mStartOffset; }
578 int32_t AdditionalLength() const
580 return static_cast<int32_t>(mNewEndOffset - mOldEndOffset);
582 bool IsInInt32Range() const
584 return mStartOffset <= INT32_MAX &&
585 mOldEndOffset <= INT32_MAX &&
586 mNewEndOffset <= INT32_MAX;
588 } mTextChangeData;
590 // NOTIFY_IME_OF_MOUSE_BUTTON_EVENT specific data
591 struct
593 // The value of WidgetEvent::message
594 uint32_t mEventMessage;
595 // Character offset from the start of the focused editor under the cursor
596 uint32_t mOffset;
597 // Cursor position in pixels relative to the widget
598 struct
600 int32_t mX;
601 int32_t mY;
603 void Set(const nsIntPoint& aPoint)
605 mX = aPoint.x;
606 mY = aPoint.y;
608 nsIntPoint AsIntPoint() const
610 return nsIntPoint(mX, mY);
612 } mCursorPos;
613 // Character rect in pixels under the cursor relative to the widget
614 struct
616 int32_t mX;
617 int32_t mY;
618 int32_t mWidth;
619 int32_t mHeight;
621 void Set(const nsIntRect& aRect)
623 mX = aRect.x;
624 mY = aRect.y;
625 mWidth = aRect.width;
626 mHeight = aRect.height;
628 nsIntRect AsIntRect() const
630 return nsIntRect(mX, mY, mWidth, mHeight);
632 } mCharRect;
633 // The value of WidgetMouseEventBase::button and buttons
634 int16_t mButton;
635 int16_t mButtons;
636 // The value of WidgetInputEvent::modifiers
637 Modifiers mModifiers;
638 } mMouseButtonEventData;
641 bool IsCausedByComposition() const
643 switch (mMessage) {
644 case NOTIFY_IME_OF_SELECTION_CHANGE:
645 return mSelectionChangeData.mCausedByComposition;
646 case NOTIFY_IME_OF_TEXT_CHANGE:
647 return mTextChangeData.mCausedByComposition;
648 default:
649 return false;
653 private:
654 IMENotification();
657 } // namespace widget
658 } // namespace mozilla
661 * The base class for all the widgets. It provides the interface for
662 * all basic and necessary functionality.
664 class nsIWidget : public nsISupports {
665 protected:
666 typedef mozilla::dom::TabChild TabChild;
668 public:
669 typedef mozilla::layers::Composer2D Composer2D;
670 typedef mozilla::layers::CompositorChild CompositorChild;
671 typedef mozilla::layers::LayerManager LayerManager;
672 typedef mozilla::layers::LayerManagerComposite LayerManagerComposite;
673 typedef mozilla::layers::LayersBackend LayersBackend;
674 typedef mozilla::layers::PLayerTransactionChild PLayerTransactionChild;
675 typedef mozilla::widget::IMEMessage IMEMessage;
676 typedef mozilla::widget::IMENotification IMENotification;
677 typedef mozilla::widget::IMEState IMEState;
678 typedef mozilla::widget::InputContext InputContext;
679 typedef mozilla::widget::InputContextAction InputContextAction;
680 typedef mozilla::widget::SizeConstraints SizeConstraints;
682 // Used in UpdateThemeGeometries.
683 struct ThemeGeometry {
684 // The -moz-appearance value for the themed widget
685 uint8_t mWidgetType;
686 // The device-pixel rect within the window for the themed widget
687 nsIntRect mRect;
689 ThemeGeometry(uint8_t aWidgetType, const nsIntRect& aRect)
690 : mWidgetType(aWidgetType)
691 , mRect(aRect)
695 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
697 nsIWidget()
698 : mLastChild(nullptr)
699 , mPrevSibling(nullptr)
700 , mOnDestroyCalled(false)
701 , mWindowType(eWindowType_child)
702 , mZIndex(0)
705 ClearNativeTouchSequence();
710 * Create and initialize a widget.
712 * All the arguments can be null in which case a top level window
713 * with size 0 is created. The event callback function has to be
714 * provided only if the caller wants to deal with the events this
715 * widget receives. The event callback is basically a preprocess
716 * hook called synchronously. The return value determines whether
717 * the event goes to the default window procedure or it is hidden
718 * to the os. The assumption is that if the event handler returns
719 * false the widget does not see the event. The widget should not
720 * automatically clear the window to the background color. The
721 * calling code must handle paint messages and clear the background
722 * itself.
724 * In practice at least one of aParent and aNativeParent will be null. If
725 * both are null the widget isn't parented (e.g. context menus or
726 * independent top level windows).
728 * The dimensions given in aRect are specified in the parent's
729 * coordinate system, or for parentless widgets such as top-level
730 * windows, in global CSS pixels.
732 * @param aParent parent nsIWidget
733 * @param aNativeParent native parent widget
734 * @param aRect the widget dimension
735 * @param aContext
736 * @param aInitData data that is used for widget initialization
739 NS_IMETHOD Create(nsIWidget *aParent,
740 nsNativeWidget aNativeParent,
741 const nsIntRect &aRect,
742 nsDeviceContext *aContext,
743 nsWidgetInitData *aInitData = nullptr) = 0;
746 * Allocate, initialize, and return a widget that is a child of
747 * |this|. The returned widget (if nonnull) has gone through the
748 * equivalent of CreateInstance(widgetCID) + Create(...).
750 * |CreateChild()| lets widget backends decide whether to parent
751 * the new child widget to this, nonnatively parent it, or both.
752 * This interface exists to support the PuppetWidget backend,
753 * which is entirely non-native. All other params are the same as
754 * for |Create()|.
756 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
757 * |nsIWidget*| this, not its native widget (if it exists), when
758 * calling |Create()|. This is a timid hack around poorly
759 * understood code, and shouldn't be used in new code.
761 virtual already_AddRefed<nsIWidget>
762 CreateChild(const nsIntRect &aRect,
763 nsDeviceContext *aContext,
764 nsWidgetInitData *aInitData = nullptr,
765 bool aForceUseIWidgetParent = false) = 0;
768 * Attach to a top level widget.
770 * In cases where a top level chrome widget is being used as a content
771 * container, attach a secondary listener and update the device
772 * context. The primary widget listener will continue to be called for
773 * notifications relating to the top-level window, whereas other
774 * notifications such as painting and events will instead be called via
775 * the attached listener. SetAttachedWidgetListener should be used to
776 * assign the attached listener.
778 * aUseAttachedEvents if true, events are sent to the attached listener
779 * instead of the normal listener.
780 * aContext The new device context for the view
782 NS_IMETHOD AttachViewToTopLevel(bool aUseAttachedEvents,
783 nsDeviceContext *aContext) = 0;
786 * Accessor functions to get and set the attached listener. Used by
787 * nsView in connection with AttachViewToTopLevel above.
789 virtual void SetAttachedWidgetListener(nsIWidgetListener* aListener) = 0;
790 virtual nsIWidgetListener* GetAttachedWidgetListener() = 0;
793 * Accessor functions to get and set the listener which handles various
794 * actions for the widget.
796 //@{
797 virtual nsIWidgetListener* GetWidgetListener() = 0;
798 virtual void SetWidgetListener(nsIWidgetListener* alistener) = 0;
799 //@}
802 * Close and destroy the internal native window.
803 * This method does not delete the widget.
806 NS_IMETHOD Destroy(void) = 0;
809 * Destroyed() returns true if Destroy() has been called already.
810 * Otherwise, false.
812 bool Destroyed() const { return mOnDestroyCalled; }
816 * Reparent a widget
818 * Change the widget's parent. Null parents are allowed.
820 * @param aNewParent new parent
822 NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
824 NS_IMETHOD RegisterTouchWindow() = 0;
825 NS_IMETHOD UnregisterTouchWindow() = 0;
828 * Return the parent Widget of this Widget or nullptr if this is a
829 * top level window
831 * @return the parent widget or nullptr if it does not have a parent
834 virtual nsIWidget* GetParent(void) = 0;
837 * Return the top level Widget of this Widget
839 * @return the top level widget
841 virtual nsIWidget* GetTopLevelWidget() = 0;
844 * Return the top (non-sheet) parent of this Widget if it's a sheet,
845 * or nullptr if this isn't a sheet (or some other error occurred).
846 * Sheets are only supported on some platforms (currently only OS X).
848 * @return the top (non-sheet) parent widget or nullptr
851 virtual nsIWidget* GetSheetWindowParent(void) = 0;
854 * Return the physical DPI of the screen containing the window ...
855 * the number of device pixels per inch.
857 virtual float GetDPI() = 0;
860 * Return the default scale factor for the window. This is the
861 * default number of device pixels per CSS pixel to use. This should
862 * depend on OS/platform settings such as the Mac's "UI scale factor"
863 * or Windows' "font DPI". This will take into account Gecko preferences
864 * overriding the system setting.
866 mozilla::CSSToLayoutDeviceScale GetDefaultScale();
869 * Return the Gecko override of the system default scale, if any;
870 * returns <= 0.0 if the system scale should be used as-is.
871 * nsIWidget::GetDefaultScale() [above] takes this into account.
872 * It is exposed here so that code that wants to check for a
873 * default-scale override without having a widget on hand can
874 * easily access the same value.
875 * Note that any scale override is a browser-wide value, whereas
876 * the default GetDefaultScale value (when no override is present)
877 * may vary between widgets (or screens).
879 static double DefaultScaleOverride();
882 * Return the first child of this widget. Will return null if
883 * there are no children.
885 nsIWidget* GetFirstChild() const {
886 return mFirstChild;
890 * Return the last child of this widget. Will return null if
891 * there are no children.
893 nsIWidget* GetLastChild() const {
894 return mLastChild;
898 * Return the next sibling of this widget
900 nsIWidget* GetNextSibling() const {
901 return mNextSibling;
905 * Set the next sibling of this widget
907 void SetNextSibling(nsIWidget* aSibling) {
908 mNextSibling = aSibling;
912 * Return the previous sibling of this widget
914 nsIWidget* GetPrevSibling() const {
915 return mPrevSibling;
919 * Set the previous sibling of this widget
921 void SetPrevSibling(nsIWidget* aSibling) {
922 mPrevSibling = aSibling;
926 * Show or hide this widget
928 * @param aState true to show the Widget, false to hide it
931 NS_IMETHOD Show(bool aState) = 0;
934 * Make the window modal
937 NS_IMETHOD SetModal(bool aModal) = 0;
940 * The maximum number of simultaneous touch contacts supported by the device.
941 * In the case of devices with multiple digitizers (e.g. multiple touch screens),
942 * the value will be the maximum of the set of maximum supported contacts by
943 * each individual digitizer.
945 virtual uint32_t GetMaxTouchPoints() const = 0;
948 * Returns whether the window is visible
951 virtual bool IsVisible() const = 0;
954 * Perform platform-dependent sanity check on a potential window position.
955 * This is guaranteed to work only for top-level windows.
957 * @param aAllowSlop: if true, allow the window to slop offscreen;
958 * the window should be partially visible. if false,
959 * force the entire window onscreen (or at least
960 * the upper-left corner, if it's too large).
961 * @param aX in: an x position expressed in screen coordinates.
962 * out: the x position constrained to fit on the screen(s).
963 * @param aY in: an y position expressed in screen coordinates.
964 * out: the y position constrained to fit on the screen(s).
965 * @return vapid success indication. but see also the parameters.
968 NS_IMETHOD ConstrainPosition(bool aAllowSlop,
969 int32_t *aX,
970 int32_t *aY) = 0;
973 * NOTE:
975 * For a top-level window widget, the "parent's coordinate system" is the
976 * "global" display pixel coordinate space, *not* device pixels (which
977 * may be inconsistent between multiple screens, at least in the Mac OS
978 * case with mixed hi-dpi and lo-dpi displays). This applies to all the
979 * following Move and Resize widget APIs.
981 * The display-/device-pixel distinction becomes important for (at least)
982 * Mac OS X with Hi-DPI (retina) displays, and Windows when the UI scale
983 * factor is set to other than 100%.
985 * The Move and Resize methods take floating-point parameters, rather than
986 * integer ones. This is important when manipulating top-level widgets,
987 * where the coordinate system may not be an integral multiple of the
988 * device-pixel space.
992 * Move this widget.
994 * Coordinates refer to the top-left of the widget. For toplevel windows
995 * with decorations, this is the top-left of the titlebar and frame .
997 * @param aX the new x position expressed in the parent's coordinate system
998 * @param aY the new y position expressed in the parent's coordinate system
1001 NS_IMETHOD Move(double aX, double aY) = 0;
1004 * Reposition this widget so that the client area has the given offset.
1006 * @param aX the new x offset of the client area expressed as an
1007 * offset from the origin of the client area of the parent
1008 * widget (for root widgets and popup widgets it is in
1009 * screen coordinates)
1010 * @param aY the new y offset of the client area expressed as an
1011 * offset from the origin of the client area of the parent
1012 * widget (for root widgets and popup widgets it is in
1013 * screen coordinates)
1016 NS_IMETHOD MoveClient(double aX, double aY) = 0;
1019 * Resize this widget. Any size constraints set for the window by a
1020 * previous call to SetSizeConstraints will be applied.
1022 * @param aWidth the new width expressed in the parent's coordinate system
1023 * @param aHeight the new height expressed in the parent's coordinate system
1024 * @param aRepaint whether the widget should be repainted
1027 NS_IMETHOD Resize(double aWidth,
1028 double aHeight,
1029 bool aRepaint) = 0;
1032 * Move or resize this widget. Any size constraints set for the window by
1033 * a previous call to SetSizeConstraints will be applied.
1035 * @param aX the new x position expressed in the parent's coordinate system
1036 * @param aY the new y position expressed in the parent's coordinate system
1037 * @param aWidth the new width expressed in the parent's coordinate system
1038 * @param aHeight the new height expressed in the parent's coordinate system
1039 * @param aRepaint whether the widget should be repainted if the size changes
1042 NS_IMETHOD Resize(double aX,
1043 double aY,
1044 double aWidth,
1045 double aHeight,
1046 bool aRepaint) = 0;
1049 * Resize the widget so that the inner client area has the given size.
1051 * @param aWidth the new width of the client area.
1052 * @param aHeight the new height of the client area.
1053 * @param aRepaint whether the widget should be repainted
1056 NS_IMETHOD ResizeClient(double aWidth,
1057 double aHeight,
1058 bool aRepaint) = 0;
1061 * Resize and reposition the widget so tht inner client area has the given
1062 * offset and size.
1064 * @param aX the new x offset of the client area expressed as an
1065 * offset from the origin of the client area of the parent
1066 * widget (for root widgets and popup widgets it is in
1067 * screen coordinates)
1068 * @param aY the new y offset of the client area expressed as an
1069 * offset from the origin of the client area of the parent
1070 * widget (for root widgets and popup widgets it is in
1071 * screen coordinates)
1072 * @param aWidth the new width of the client area.
1073 * @param aHeight the new height of the client area.
1074 * @param aRepaint whether the widget should be repainted
1077 NS_IMETHOD ResizeClient(double aX,
1078 double aY,
1079 double aWidth,
1080 double aHeight,
1081 bool aRepaint) = 0;
1084 * Sets the widget's z-index.
1086 virtual void SetZIndex(int32_t aZIndex) = 0;
1089 * Gets the widget's z-index.
1091 int32_t GetZIndex()
1093 return mZIndex;
1097 * Position this widget just behind the given widget. (Used to
1098 * control z-order for top-level widgets. Get/SetZIndex by contrast
1099 * control z-order for child widgets of other widgets.)
1100 * @param aPlacement top, bottom, or below a widget
1101 * (if top or bottom, param aWidget is ignored)
1102 * @param aWidget widget to place this widget behind
1103 * (only if aPlacement is eZPlacementBelow).
1104 * null is equivalent to aPlacement of eZPlacementTop
1105 * @param aActivate true to activate the widget after placing it
1107 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
1108 nsIWidget *aWidget, bool aActivate) = 0;
1111 * Minimize, maximize or normalize the window size.
1112 * Takes a value from nsSizeMode (see nsIWidgetListener.h)
1114 NS_IMETHOD SetSizeMode(int32_t aMode) = 0;
1117 * Return size mode (minimized, maximized, normalized).
1118 * Returns a value from nsSizeMode (see nsIWidgetListener.h)
1120 virtual int32_t SizeMode() = 0;
1123 * Enable or disable this Widget
1125 * @param aState true to enable the Widget, false to disable it.
1128 NS_IMETHOD Enable(bool aState) = 0;
1131 * Ask whether the widget is enabled
1133 virtual bool IsEnabled() const = 0;
1136 * Request activation of this window or give focus to this widget.
1138 * @param aRaise If true, this function requests activation of this
1139 * widget's toplevel window.
1140 * If false, the appropriate toplevel window (which in
1141 * the case of popups may not be this widget's toplevel
1142 * window) is already active.
1144 NS_IMETHOD SetFocus(bool aRaise = false) = 0;
1147 * Get this widget's outside dimensions relative to its parent widget. For
1148 * popup widgets the returned rect is in screen coordinates and not
1149 * relative to its parent widget.
1151 * @param aRect On return it holds the x, y, width and height of
1152 * this widget.
1154 NS_IMETHOD GetBounds(nsIntRect &aRect) = 0;
1157 * Get this widget's outside dimensions in global coordinates. This
1158 * includes any title bar on the window.
1160 * @param aRect On return it holds the x, y, width and height of
1161 * this widget.
1163 NS_IMETHOD GetScreenBounds(nsIntRect &aRect) = 0;
1166 * Similar to GetScreenBounds except that this function will always
1167 * get the size when the widget is in the nsSizeMode_Normal size mode
1168 * even if the current size mode is not nsSizeMode_Normal.
1169 * This method will fail if the size mode is not nsSizeMode_Normal and
1170 * the platform doesn't have the ability.
1171 * This method will always succeed if the current size mode is
1172 * nsSizeMode_Normal.
1174 * @param aRect On return it holds the x, y, width and height of
1175 * this widget.
1177 NS_IMETHOD GetRestoredBounds(nsIntRect &aRect) = 0;
1180 * Get this widget's client area bounds, if the window has a 3D border
1181 * appearance this returns the area inside the border. The position is the
1182 * position of the client area relative to the client area of the parent
1183 * widget (for root widgets and popup widgets it is in screen coordinates).
1185 * @param aRect On return it holds the x. y, width and height of
1186 * the client area of this widget.
1188 NS_IMETHOD GetClientBounds(nsIntRect &aRect) = 0;
1191 * Get the non-client area dimensions of the window.
1194 NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) = 0;
1197 * Sets the non-client area dimensions of the window. Pass -1 to restore
1198 * the system default frame size for that border. Pass zero to remove
1199 * a border, or pass a specific value adjust a border. Units are in
1200 * pixels. (DPI dependent)
1202 * Platform notes:
1203 * Windows: shrinking top non-client height will remove application
1204 * icon and window title text. Glass desktops will refuse to set
1205 * dimensions between zero and size < system default.
1208 NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0;
1211 * Get the client offset from the window origin.
1213 * @return the x and y of the offset.
1216 virtual nsIntPoint GetClientOffset() = 0;
1219 * Set the background color for this widget
1221 * @param aColor the new background color
1225 virtual void SetBackgroundColor(const nscolor &aColor) { }
1228 * Get the cursor for this widget.
1230 * @return this widget's cursor.
1233 virtual nsCursor GetCursor(void) = 0;
1236 * Set the cursor for this widget
1238 * @param aCursor the new cursor for this widget
1241 NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
1244 * If a cursor type is currently cached locally for this widget, clear the
1245 * cached cursor to force an update on the next SetCursor call.
1248 virtual void ClearCachedCursor() = 0;
1251 * Sets an image as the cursor for this widget.
1253 * @param aCursor the cursor to set
1254 * @param aX the X coordinate of the hotspot (from left).
1255 * @param aY the Y coordinate of the hotspot (from top).
1256 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
1257 * supported
1259 NS_IMETHOD SetCursor(imgIContainer* aCursor,
1260 uint32_t aHotspotX, uint32_t aHotspotY) = 0;
1262 /**
1263 * Get the window type of this widget.
1265 nsWindowType WindowType() { return mWindowType; }
1268 * Set the transparency mode of the top-level window containing this widget.
1269 * So, e.g., if you call this on the widget for an IFRAME, the top level
1270 * browser window containing the IFRAME actually gets set. Be careful.
1272 * This can fail if the platform doesn't support
1273 * transparency/glass. By default widgets are not
1274 * transparent. This will also fail if the toplevel window is not
1275 * a Mozilla window, e.g., if the widget is in an embedded
1276 * context.
1278 * After transparency/glass has been enabled, the initial alpha channel
1279 * value for all pixels is 1, i.e., opaque.
1280 * If the window is resized then the alpha channel values for
1281 * all pixels are reset to 1.
1282 * Pixel RGB color values are already premultiplied with alpha channel values.
1284 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
1287 * Get the transparency mode of the top-level window that contains this
1288 * widget.
1290 virtual nsTransparencyMode GetTransparencyMode() = 0;
1293 * This represents a command to set the bounds and clip region of
1294 * a child widget.
1296 struct Configuration {
1297 nsIWidget* mChild;
1298 nsIntRect mBounds;
1299 nsTArray<nsIntRect> mClipRegion;
1303 * Sets the clip region of each mChild (which must actually be a child
1304 * of this widget) to the union of the pixel rects given in
1305 * mClipRegion, all relative to the top-left of the child
1306 * widget. Clip regions are not implemented on all platforms and only
1307 * need to actually work for children that are plugins.
1309 * Also sets the bounds of each child to mBounds.
1311 * This will invalidate areas of the children that have changed, but
1312 * does not need to invalidate any part of this widget.
1314 * Children should be moved in the order given; the array is
1315 * sorted so to minimize unnecessary invalidation if children are
1316 * moved in that order.
1318 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
1321 * Appends to aRects the rectangles constituting this widget's clip
1322 * region. If this widget is not clipped, appends a single rectangle
1323 * (0, 0, bounds.width, bounds.height).
1325 virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects) = 0;
1328 * Set the shadow style of the window.
1330 * Ignored on child widgets and on non-Mac platforms.
1332 NS_IMETHOD SetWindowShadowStyle(int32_t aStyle) = 0;
1335 * On Mac OS X, this method shows or hides the pill button in the titlebar
1336 * that's used to collapse the toolbar.
1338 * Ignored on child widgets and on non-Mac platforms.
1340 virtual void SetShowsToolbarButton(bool aShow) = 0;
1343 * On Mac OS X Lion, this method shows or hides the full screen button in
1344 * the titlebar that handles native full screen mode.
1346 * Ignored on child widgets, non-Mac platforms, & pre-Lion Mac.
1348 virtual void SetShowsFullScreenButton(bool aShow) = 0;
1350 enum WindowAnimationType {
1351 eGenericWindowAnimation,
1352 eDocumentWindowAnimation
1356 * Sets the kind of top-level window animation this widget should have. On
1357 * Mac OS X, this causes a particular kind of animation to be shown when the
1358 * window is first made visible.
1360 * Ignored on child widgets and on non-Mac platforms.
1362 virtual void SetWindowAnimationType(WindowAnimationType aType) = 0;
1365 * Specifies whether the window title should be drawn even if the window
1366 * contents extend into the titlebar. Ignored on windows that don't draw
1367 * in the titlebar. Only implemented on OS X.
1369 virtual void SetDrawsTitle(bool aDrawTitle) {}
1371 /**
1372 * Hide window chrome (borders, buttons) for this widget.
1375 NS_IMETHOD HideWindowChrome(bool aShouldHide) = 0;
1378 * Put the toplevel window into or out of fullscreen mode.
1381 NS_IMETHOD MakeFullScreen(bool aFullScreen) = 0;
1384 * Invalidate a specified rect for a widget so that it will be repainted
1385 * later.
1387 NS_IMETHOD Invalidate(const nsIntRect & aRect) = 0;
1389 enum LayerManagerPersistence
1391 LAYER_MANAGER_CURRENT = 0,
1392 LAYER_MANAGER_PERSISTENT
1396 * Return the widget's LayerManager. The layer tree for that
1397 * LayerManager is what gets rendered to the widget.
1399 * @param aAllowRetaining an outparam that states whether the returned
1400 * layer manager should be used for retained layers
1402 inline LayerManager* GetLayerManager(bool* aAllowRetaining = nullptr)
1404 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1405 LAYER_MANAGER_CURRENT, aAllowRetaining);
1408 inline LayerManager* GetLayerManager(LayerManagerPersistence aPersistence,
1409 bool* aAllowRetaining = nullptr)
1411 return GetLayerManager(nullptr, mozilla::layers::LayersBackend::LAYERS_NONE,
1412 aPersistence, aAllowRetaining);
1416 * Like GetLayerManager(), but prefers creating a layer manager of
1417 * type |aBackendHint| instead of what would normally be created.
1418 * LayersBackend::LAYERS_NONE means "no hint".
1420 virtual LayerManager* GetLayerManager(PLayerTransactionChild* aShadowManager,
1421 LayersBackend aBackendHint,
1422 LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
1423 bool* aAllowRetaining = nullptr) = 0;
1426 * Called before each layer manager transaction to allow any preparation
1427 * for DrawWindowUnderlay/Overlay that needs to be on the main thread.
1429 * Always called on the main thread.
1431 virtual void PrepareWindowEffects() = 0;
1434 * Called when shutting down the LayerManager to clean-up any cached resources.
1436 * Always called from the compositing thread, which may be the main-thread if
1437 * OMTC is not enabled.
1439 virtual void CleanupWindowEffects() = 0;
1442 * Called before rendering using OMTC. Returns false when the widget is
1443 * not ready to be rendered (for example while the window is closed).
1445 * Always called from the compositing thread, which may be the main-thread if
1446 * OMTC is not enabled.
1448 virtual bool PreRender(LayerManagerComposite* aManager) = 0;
1451 * Called after rendering using OMTC. Not called when rendering was
1452 * cancelled by a negative return value from PreRender.
1454 * Always called from the compositing thread, which may be the main-thread if
1455 * OMTC is not enabled.
1457 virtual void PostRender(LayerManagerComposite* aManager) = 0;
1460 * Called before the LayerManager draws the layer tree.
1462 * Always called from the compositing thread.
1464 virtual void DrawWindowUnderlay(LayerManagerComposite* aManager, nsIntRect aRect) = 0;
1467 * Called after the LayerManager draws the layer tree
1469 * Always called from the compositing thread.
1471 virtual void DrawWindowOverlay(LayerManagerComposite* aManager, nsIntRect aRect) = 0;
1474 * Return a DrawTarget for the window which can be composited into.
1476 * Called by BasicCompositor on the compositor thread for OMTC drawing
1477 * before each composition.
1479 virtual mozilla::TemporaryRef<mozilla::gfx::DrawTarget> StartRemoteDrawing() = 0;
1482 * Ensure that what was painted into the DrawTarget returned from
1483 * StartRemoteDrawing reaches the screen.
1485 * Called by BasicCompositor on the compositor thread for OMTC drawing
1486 * after each composition.
1488 virtual void EndRemoteDrawing() = 0;
1491 * Clean up any resources used by Start/EndRemoteDrawing.
1493 * Called by BasicCompositor on the compositor thread for OMTC drawing
1494 * when the compositor is destroyed.
1496 virtual void CleanupRemoteDrawing() = 0;
1499 * Called when Gecko knows which themed widgets exist in this window.
1500 * The passed array contains an entry for every themed widget of the right
1501 * type (currently only NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR and
1502 * NS_THEME_TOOLBAR) within the window, except for themed widgets which are
1503 * transformed or have effects applied to them (e.g. CSS opacity or
1504 * filters).
1505 * This could sometimes be called during display list construction
1506 * outside of painting.
1507 * If called during painting, it will be called before we actually
1508 * paint anything.
1510 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1513 * Informs the widget about the region of the window that is opaque.
1515 * @param aOpaqueRegion the region of the window that is opaque.
1517 virtual void UpdateOpaqueRegion(const nsIntRegion &aOpaqueRegion) {}
1519 /**
1520 * Internal methods
1523 //@{
1524 virtual void AddChild(nsIWidget* aChild) = 0;
1525 virtual void RemoveChild(nsIWidget* aChild) = 0;
1526 virtual void* GetNativeData(uint32_t aDataType) = 0;
1527 virtual void FreeNativeData(void * data, uint32_t aDataType) = 0;//~~~
1529 // GetDeviceContext returns a weak pointer to this widget's device context
1530 virtual nsDeviceContext* GetDeviceContext() = 0;
1532 //@}
1535 * Set the widget's title.
1536 * Must be called after Create.
1538 * @param aTitle string displayed as the title of the widget
1541 NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
1544 * Set the widget's icon.
1545 * Must be called after Create.
1547 * @param anIconSpec string specifying the icon to use; convention is to pass
1548 * a resource: URL from which a platform-dependent resource
1549 * file name will be constructed
1552 NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
1555 * Return this widget's origin in screen coordinates.
1557 * @return screen coordinates stored in the x,y members
1560 virtual nsIntPoint WidgetToScreenOffset() = 0;
1563 * Given the specified client size, return the corresponding window size,
1564 * which includes the area for the borders and titlebar. This method
1565 * should work even when the window is not yet visible.
1567 virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) = 0;
1570 * Dispatches an event to the widget
1573 NS_IMETHOD DispatchEvent(mozilla::WidgetGUIEvent* event,
1574 nsEventStatus & aStatus) = 0;
1577 * Enables the dropping of files to a widget (XXX this is temporary)
1580 NS_IMETHOD EnableDragDrop(bool aEnable) = 0;
1583 * Enables/Disables system mouse capture.
1584 * @param aCapture true enables mouse capture, false disables mouse capture
1587 NS_IMETHOD CaptureMouse(bool aCapture) = 0;
1590 * Classify the window for the window manager. Mostly for X11.
1592 NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0;
1595 * Enables/Disables system capture of any and all events that would cause a
1596 * popup to be rolled up. aListener should be set to a non-null value for
1597 * any popups that are not managed by the popup manager.
1598 * @param aDoCapture true enables capture, false disables capture
1601 NS_IMETHOD CaptureRollupEvents(nsIRollupListener* aListener, bool aDoCapture) = 0;
1604 * Bring this window to the user's attention. This is intended to be a more
1605 * gentle notification than popping the window to the top or putting up an
1606 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
1607 * the Mac. The notification should be suppressed if the window is already
1608 * in the foreground and should be dismissed when the user brings this window
1609 * to the foreground.
1610 * @param aCycleCount Maximum number of times to animate the window per system
1611 * conventions. If set to -1, cycles indefinitely until
1612 * window is brought into the foreground.
1614 NS_IMETHOD GetAttention(int32_t aCycleCount) = 0;
1617 * Ask whether there user input events pending. All input events are
1618 * included, including those not targeted at this nsIwidget instance.
1620 virtual bool HasPendingInputEvent() = 0;
1623 * Set the background color of the window titlebar for this widget. On Mac,
1624 * for example, this will remove the grey gradient and bottom border and
1625 * instead show a single, solid color.
1627 * Ignored on any platform that does not support it. Ignored by widgets that
1628 * do not represent windows.
1630 * @param aColor The color to set the title bar background to. Alpha values
1631 * other than fully transparent (0) are respected if possible
1632 * on the platform. An alpha of 0 will cause the window to
1633 * draw with the default style for the platform.
1635 * @param aActive Whether the color should be applied to active or inactive
1636 * windows.
1638 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, bool aActive) = 0;
1641 * If set to true, the window will draw its contents into the titlebar
1642 * instead of below it.
1644 * Ignored on any platform that does not support it. Ignored by widgets that
1645 * do not represent windows.
1646 * May result in a resize event, so should only be called from places where
1647 * reflow and painting is allowed.
1649 * @param aState Whether drawing into the titlebar should be activated.
1651 virtual void SetDrawsInTitlebar(bool aState) = 0;
1654 * Determine whether the widget shows a resize widget. If it does,
1655 * aResizerRect returns the resizer's rect.
1657 * Returns false on any platform that does not support it.
1659 * @param aResizerRect The resizer's rect in device pixels.
1660 * @return Whether a resize widget is shown.
1662 virtual bool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0;
1665 * Return the popup that was last rolled up, or null if there isn't one.
1667 virtual nsIContent* GetLastRollup() = 0;
1670 * Begin a window resizing drag, based on the event passed in.
1672 NS_IMETHOD BeginResizeDrag(mozilla::WidgetGUIEvent* aEvent,
1673 int32_t aHorizontal,
1674 int32_t aVertical) = 0;
1677 * Begin a window moving drag, based on the event passed in.
1679 NS_IMETHOD BeginMoveDrag(mozilla::WidgetMouseEvent* aEvent) = 0;
1681 enum Modifiers {
1682 CAPS_LOCK = 0x01, // when CapsLock is active
1683 NUM_LOCK = 0x02, // when NumLock is active
1684 SHIFT_L = 0x0100,
1685 SHIFT_R = 0x0200,
1686 CTRL_L = 0x0400,
1687 CTRL_R = 0x0800,
1688 ALT_L = 0x1000, // includes Option
1689 ALT_R = 0x2000,
1690 COMMAND_L = 0x4000,
1691 COMMAND_R = 0x8000,
1692 HELP = 0x10000,
1693 FUNCTION = 0x100000,
1694 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1697 * Utility method intended for testing. Dispatches native key events
1698 * to this widget to simulate the press and release of a key.
1699 * @param aNativeKeyboardLayout a *platform-specific* constant.
1700 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1701 * On Windows, it is converted to a hex string and passed to
1702 * LoadKeyboardLayout, see
1703 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1704 * @param aNativeKeyCode a *platform-specific* keycode.
1705 * On Windows, this is the virtual key code.
1706 * @param aModifiers some combination of the above 'Modifiers' flags;
1707 * not all flags will apply to all platforms. Mac ignores the _R
1708 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1709 * FUNCTION.
1710 * @param aCharacters characters that the OS would decide to generate
1711 * from the event. On Windows, this is the charCode passed by
1712 * WM_CHAR.
1713 * @param aUnmodifiedCharacters characters that the OS would decide
1714 * to generate from the event if modifier keys (other than shift)
1715 * were assumed inactive. Needed on Mac, ignored on Windows.
1716 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1717 * layout is not supported and the event was not fired
1719 virtual nsresult SynthesizeNativeKeyEvent(int32_t aNativeKeyboardLayout,
1720 int32_t aNativeKeyCode,
1721 uint32_t aModifierFlags,
1722 const nsAString& aCharacters,
1723 const nsAString& aUnmodifiedCharacters) = 0;
1726 * Utility method intended for testing. Dispatches native mouse events
1727 * may even move the mouse cursor. On Mac the events are guaranteed to
1728 * be sent to the window containing this widget, but on Windows they'll go
1729 * to whatever's topmost on the screen at that position, so for
1730 * cross-platform testing ensure that your window is at the top of the
1731 * z-order.
1732 * @param aPoint screen location of the mouse, in device
1733 * pixels, with origin at the top left
1734 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
1735 * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
1736 * @param aModifierFlags *platform-specific* modifier flags (ignored
1737 * on Windows)
1739 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
1740 uint32_t aNativeMessage,
1741 uint32_t aModifierFlags) = 0;
1744 * A shortcut to SynthesizeNativeMouseEvent, abstracting away the native message.
1745 * aPoint is location in device pixels to which the mouse pointer moves to.
1747 virtual nsresult SynthesizeNativeMouseMove(nsIntPoint aPoint) = 0;
1750 * Utility method intended for testing. Dispatching native mouse scroll
1751 * events may move the mouse cursor.
1753 * @param aPoint Mouse cursor position in screen coordinates.
1754 * In device pixels, the origin at the top left of
1755 * the primary display.
1756 * @param aNativeMessage Platform native message.
1757 * @param aDeltaX The delta value for X direction. If the native
1758 * message doesn't indicate X direction scrolling,
1759 * this may be ignored.
1760 * @param aDeltaY The delta value for Y direction. If the native
1761 * message doesn't indicate Y direction scrolling,
1762 * this may be ignored.
1763 * @param aDeltaZ The delta value for Z direction. If the native
1764 * message doesn't indicate Z direction scrolling,
1765 * this may be ignored.
1766 * @param aModifierFlags Must be values of Modifiers, or zero.
1767 * @param aAdditionalFlags See nsIDOMWidnowUtils' consts and their
1768 * document.
1770 virtual nsresult SynthesizeNativeMouseScrollEvent(nsIntPoint aPoint,
1771 uint32_t aNativeMessage,
1772 double aDeltaX,
1773 double aDeltaY,
1774 double aDeltaZ,
1775 uint32_t aModifierFlags,
1776 uint32_t aAdditionalFlags) = 0;
1779 * TouchPointerState states for SynthesizeNativeTouchPoint. Match
1780 * touch states in nsIDOMWindowUtils.idl.
1782 enum TouchPointerState {
1783 // The pointer is in a hover state above the digitizer
1784 TOUCH_HOVER = 0x01,
1785 // The pointer is in contact with the digitizer
1786 TOUCH_CONTACT = 0x02,
1787 // The pointer has been removed from the digitizer detection area
1788 TOUCH_REMOVE = 0x04,
1789 // The pointer has been canceled. Will cancel any pending os level
1790 // gestures that would triggered as a result of completion of the
1791 // input sequence. This may not cancel moz platform related events
1792 // that might get tirggered by input already delivered.
1793 TOUCH_CANCEL = 0x08
1797 * Create a new or update an existing touch pointer on the digitizer.
1798 * To trigger os level gestures, individual touch points should
1799 * transition through a complete set of touch states which should be
1800 * sent as individual messages.
1802 * @param aPointerId The touch point id to create or update.
1803 * @param aPointerState one or more of the touch states listed above
1804 * @param aScreenX, aScreenY screen coords of this event
1805 * @param aPressure 0.0 -> 1.0 float val indicating pressure
1806 * @param aOrientation 0 -> 359 degree value indicating the
1807 * orientation of the pointer. Use 90 for normal taps.
1809 virtual nsresult SynthesizeNativeTouchPoint(uint32_t aPointerId,
1810 TouchPointerState aPointerState,
1811 nsIntPoint aPointerScreenPoint,
1812 double aPointerPressure,
1813 uint32_t aPointerOrientation) = 0;
1816 * Cancels all active simulated touch input points and pending long taps.
1817 * Native widgets should track existing points such that they can clear the
1818 * digitizer state when this call is made.
1820 virtual nsresult ClearNativeTouchSequence();
1823 * Helper for simulating a simple tap event with one touch point. When
1824 * aLongTap is true, simulates a native long tap with a duration equal to
1825 * ui.click_hold_context_menus.delay. This pref is compatible with the
1826 * apzc long tap duration. Defaults to 1.5 seconds.
1828 nsresult SynthesizeNativeTouchTap(nsIntPoint aPointerScreenPoint,
1829 bool aLongTap);
1831 private:
1832 class LongTapInfo
1834 public:
1835 LongTapInfo(int32_t aPointerId, nsIntPoint& aPoint,
1836 mozilla::TimeDuration aDuration) :
1837 mPointerId(aPointerId),
1838 mPosition(aPoint),
1839 mDuration(aDuration),
1840 mStamp(mozilla::TimeStamp::Now())
1844 int32_t mPointerId;
1845 nsIntPoint mPosition;
1846 mozilla::TimeDuration mDuration;
1847 mozilla::TimeStamp mStamp;
1850 static void OnLongTapTimerCallback(nsITimer* aTimer, void* aClosure);
1852 nsAutoPtr<LongTapInfo> mLongTapTouchPoint;
1853 nsCOMPtr<nsITimer> mLongTapTimer;
1854 static int32_t sPointerIdCounter;
1856 public:
1858 * Activates a native menu item at the position specified by the index
1859 * string. The index string is a string of positive integers separated
1860 * by the "|" (pipe) character. The last integer in the string represents
1861 * the item index in a submenu located using the integers preceding it.
1863 * Example: 1|0|4
1864 * In this string, the first integer represents the top-level submenu
1865 * in the native menu bar. Since the integer is 1, it is the second submeu
1866 * in the native menu bar. Within that, the first item (index 0) is a
1867 * submenu, and we want to activate the 5th item within that submenu.
1869 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1872 * This is used for native menu system testing.
1874 * Updates a native menu at the position specified by the index string.
1875 * The index string is a string of positive integers separated by the "|"
1876 * (pipe) character.
1878 * Example: 1|0|4
1879 * In this string, the first integer represents the top-level submenu
1880 * in the native menu bar. Since the integer is 1, it is the second submeu
1881 * in the native menu bar. Within that, the first item (index 0) is a
1882 * submenu, and we want to update submenu at index 4 within that submenu.
1884 * If this is called with an empty string it forces a full reload of the
1885 * menu system.
1887 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1890 * Notify IME of the specified notification.
1892 * @return If the notification is mouse button event and it's consumed by
1893 * IME, this returns NS_SUCCESS_EVENT_CONSUMED.
1895 NS_IMETHOD NotifyIME(const IMENotification& aIMENotification) = 0;
1898 * Notifies the input context changes.
1900 NS_IMETHOD_(void) SetInputContext(const InputContext& aContext,
1901 const InputContextAction& aAction) = 0;
1904 * Get current input context.
1906 NS_IMETHOD_(InputContext) GetInputContext() = 0;
1909 * Given a WidgetKeyboardEvent, this method synthesizes a corresponding
1910 * native (OS-level) event for it. This method allows tests to simulate
1911 * keystrokes that trigger native key bindings (which require a native
1912 * event).
1914 NS_IMETHOD AttachNativeKeyEvent(mozilla::WidgetKeyboardEvent& aEvent) = 0;
1917 * Execute native key bindings for aType.
1919 typedef void (*DoCommandCallback)(mozilla::Command, void*);
1920 enum NativeKeyBindingsType
1922 NativeKeyBindingsForSingleLineEditor,
1923 NativeKeyBindingsForMultiLineEditor,
1924 NativeKeyBindingsForRichTextEditor
1926 NS_IMETHOD_(bool) ExecuteNativeKeyBinding(
1927 NativeKeyBindingsType aType,
1928 const mozilla::WidgetKeyboardEvent& aEvent,
1929 DoCommandCallback aCallback,
1930 void* aCallbackData) = 0;
1933 * Set layers acceleration to 'True' or 'False'
1935 NS_IMETHOD SetLayersAcceleration(bool aEnabled) = 0;
1938 * Get toggled key states.
1939 * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or
1940 * NS_VK_SCROLL_LOCK.
1941 * aLEDState is the result for current LED state of the key.
1942 * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
1943 * If the platform doesn't support the LED state (or we cannot get the
1944 * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
1946 NS_IMETHOD GetToggledKeyState(uint32_t aKeyCode, bool* aLEDState) = 0;
1949 * Retrieves preference for IME updates
1951 virtual nsIMEUpdatePreference GetIMEUpdatePreference() = 0;
1954 * Call this method when a dialog is opened which has a default button.
1955 * The button's rectangle should be supplied in aButtonRect.
1957 NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) = 0;
1960 * Compute the overridden system mouse scroll speed on the root content of
1961 * web pages. The widget may set the same value as aOriginalDelta. E.g.,
1962 * when the system scrolling settings were customized, widget can respect
1963 * the will of the user.
1965 * This is called only when the mouse wheel event scrolls the root content
1966 * of the web pages by line. In other words, this isn't called when the
1967 * mouse wheel event is used for zoom, page scroll and other special
1968 * actions. And also this isn't called when the user doesn't use the
1969 * system wheel speed settings.
1971 * @param aOriginalDeltaX The X delta value of the current mouse wheel
1972 * scrolling event.
1973 * @param aOriginalDeltaX The Y delta value of the current mouse wheel
1974 * scrolling event.
1975 * @param aOverriddenDeltaX The overridden mouse scrolling speed along X
1976 * axis. This value may be same as aOriginalDeltaX.
1977 * @param aOverriddenDeltaY The overridden mouse scrolling speed along Y
1978 * axis. This value may be same as aOriginalDeltaY.
1980 NS_IMETHOD OverrideSystemMouseScrollSpeed(double aOriginalDeltaX,
1981 double aOriginalDeltaY,
1982 double& aOverriddenDeltaX,
1983 double& aOverriddenDeltaY) = 0;
1986 * Return true if this process shouldn't use platform widgets, and
1987 * so should use PuppetWidgets instead. If this returns true, the
1988 * result of creating and using a platform widget is undefined,
1989 * and likely to end in crashes or other buggy behavior.
1991 static bool
1992 UsePuppetWidgets()
1994 return XRE_GetProcessType() == GeckoProcessType_Content;
1998 * Allocate and return a "puppet widget" that doesn't directly
1999 * correlate to a platform widget; platform events and data must
2000 * be fed to it. Currently used in content processes. NULL is
2001 * returned if puppet widgets aren't supported in this build
2002 * config, on this platform, or for this process type.
2004 * This function is called "Create" to match CreateInstance().
2005 * The returned widget must still be nsIWidget::Create()d.
2007 static already_AddRefed<nsIWidget>
2008 CreatePuppetWidget(TabChild* aTabChild);
2011 * Reparent this widget's native widget.
2012 * @param aNewParent the native widget of aNewParent is the new native
2013 * parent widget
2015 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0;
2018 * Return the internal format of the default framebuffer for this
2019 * widget.
2021 virtual uint32_t GetGLFrameBufferFormat() { return 0; /*GL_NONE*/ }
2024 * Return true if widget has it's own GL context
2026 virtual bool HasGLContext() { return false; }
2029 * Returns true to indicate that this widget paints an opaque background
2030 * that we want to be visible under the page, so layout should not force
2031 * a default background.
2033 virtual bool WidgetPaintsBackground() { return false; }
2035 virtual bool NeedsPaint() {
2036 if (!IsVisible()) {
2037 return false;
2039 nsIntRect bounds;
2040 nsresult rv = GetBounds(bounds);
2041 NS_ENSURE_SUCCESS(rv, false);
2042 return !bounds.IsEmpty();
2046 * Get the natural bounds of this widget. This method is only
2047 * meaningful for widgets for which Gecko implements screen
2048 * rotation natively. When this is the case, GetBounds() returns
2049 * the widget bounds taking rotation into account, and
2050 * GetNaturalBounds() returns the bounds *not* taking rotation
2051 * into account.
2053 * No code outside of the composition pipeline should know or care
2054 * about this. If you're not an agent of the compositor, you
2055 * probably shouldn't call this method.
2057 virtual nsIntRect GetNaturalBounds() {
2058 nsIntRect bounds;
2059 GetBounds(bounds);
2060 return bounds;
2064 * Set size constraints on the window size such that it is never less than
2065 * the specified minimum size and never larger than the specified maximum
2066 * size. The size constraints are sizes of the outer rectangle including
2067 * the window frame and title bar. Use 0 for an unconstrained minimum size
2068 * and NS_MAXSIZE for an unconstrained maximum size. Note that this method
2069 * does not necessarily change the size of a window to conform to this size,
2070 * thus Resize should be called afterwards.
2072 * @param aConstraints: the size constraints in device pixels
2074 virtual void SetSizeConstraints(const SizeConstraints& aConstraints) = 0;
2077 * Return the size constraints currently observed by the widget.
2079 * @return the constraints in device pixels
2081 virtual const SizeConstraints& GetSizeConstraints() const = 0;
2084 * If this is owned by a TabChild, return that. Otherwise return
2085 * null.
2087 virtual TabChild* GetOwningTabChild() { return nullptr; }
2090 * If this isn't directly compositing to its window surface,
2091 * return the compositor which is doing that on our behalf.
2093 virtual CompositorChild* GetRemoteRenderer()
2094 { return nullptr; }
2097 * If this widget has a more efficient composer available for its
2098 * native framebuffer, return it.
2100 * This can be called from a non-main thread, but that thread must
2101 * hold a strong reference to this.
2103 virtual Composer2D* GetComposer2D()
2104 { return nullptr; }
2107 * Some platforms (only cocoa right now) round widget coordinates to the
2108 * nearest even pixels (see bug 892994), this function allows us to
2109 * determine how widget coordinates will be rounded.
2111 virtual int32_t RoundsWidgetCoordinatesTo() { return 1; }
2113 protected:
2115 * Like GetDefaultScale, but taking into account only the system settings
2116 * and ignoring Gecko preferences.
2118 virtual double GetDefaultScaleInternal() { return 1.0; }
2120 // keep the list of children. We also keep track of our siblings.
2121 // The ownership model is as follows: parent holds a strong ref to
2122 // the first element of the list, and each element holds a strong
2123 // ref to the next element in the list. The prevsibling and
2124 // lastchild pointers are weak, which is fine as long as they are
2125 // maintained properly.
2126 nsCOMPtr<nsIWidget> mFirstChild;
2127 nsIWidget* mLastChild;
2128 nsCOMPtr<nsIWidget> mNextSibling;
2129 nsIWidget* mPrevSibling;
2130 // When Destroy() is called, the sub class should set this true.
2131 bool mOnDestroyCalled;
2132 nsWindowType mWindowType;
2133 int32_t mZIndex;
2136 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
2138 #endif // nsIWidget_h__