CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / widget / public / nsIWidget.h
blob96b50780bd2fa10739087bab595741f90c182881
1 /* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsIWidget_h__
39 #define nsIWidget_h__
41 #include "nsISupports.h"
42 #include "nsColor.h"
43 #include "nsCoord.h"
44 #include "nsRect.h"
45 #include "nsPoint.h"
46 #include "nsRegion.h"
47 #include "nsStringGlue.h"
49 #include "prthread.h"
50 #include "nsEvent.h"
51 #include "nsCOMPtr.h"
52 #include "nsITheme.h"
53 #include "nsNativeWidget.h"
54 #include "nsWidgetInitData.h"
55 #include "nsTArray.h"
56 #include "nsXULAppAPI.h"
58 // forward declarations
59 class nsIAppShell;
60 class nsIToolkit;
61 class nsIFontMetrics;
62 class nsIRenderingContext;
63 class nsIDeviceContext;
64 struct nsFont;
65 class nsIRollupListener;
66 class nsIMenuRollup;
67 class nsGUIEvent;
68 class imgIContainer;
69 class gfxASurface;
70 class nsIContent;
71 class ViewWrapper;
73 namespace mozilla {
74 namespace layers {
75 class LayerManager;
77 #ifdef MOZ_IPC
78 namespace dom {
79 class PBrowserChild;
81 #endif
84 /**
85 * Callback function that processes events.
87 * The argument is actually a subtype (subclass) of nsEvent which carries
88 * platform specific information about the event. Platform specific code
89 * knows how to deal with it.
91 * The return value determines whether or not the default action should take
92 * place.
94 typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
96 /**
97 * Flags for the getNativeData function.
98 * See getNativeData()
100 #define NS_NATIVE_WINDOW 0
101 #define NS_NATIVE_GRAPHIC 1
102 #define NS_NATIVE_TMP_WINDOW 2
103 #define NS_NATIVE_WIDGET 3
104 #define NS_NATIVE_DISPLAY 4
105 #define NS_NATIVE_REGION 5
106 #define NS_NATIVE_OFFSETX 6
107 #define NS_NATIVE_OFFSETY 7
108 #define NS_NATIVE_PLUGIN_PORT 8
109 #define NS_NATIVE_SCREEN 9
110 #define NS_NATIVE_SHELLWIDGET 10 // Get the shell GtkWidget
111 #ifdef XP_MACOSX
112 #define NS_NATIVE_PLUGIN_PORT_QD 100
113 #define NS_NATIVE_PLUGIN_PORT_CG 101
114 #endif
115 #ifdef XP_WIN
116 #define NS_NATIVE_TSF_THREAD_MGR 100
117 #define NS_NATIVE_TSF_CATEGORY_MGR 101
118 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
119 #endif
121 // cc443f0b-af39-415d-9c4b-7e06eaa8b13b
122 #define NS_IWIDGET_IID \
123 { 0xcc443f0b, 0xaf39, 0x415d, \
124 { 0x9c, 0x4b, 0x7e, 0x06, 0xea, 0xa8, 0xb1, 0x3b } }
126 // {8FC2D005-5359-4dbf-ACB1-701992FB4617}
127 #define NS_IWIDGET_MOZILLA_2_0_BRANCH_IID \
128 { 0x8fc2d005, 0x5359, 0x4dbf, \
129 { 0xac, 0xb1, 0x70, 0x19, 0x92, 0xfb, 0x46, 0x17 } }
132 * Window shadow styles
133 * Also used for the -moz-window-shadow CSS property
136 #define NS_STYLE_WINDOW_SHADOW_NONE 0
137 #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
138 #define NS_STYLE_WINDOW_SHADOW_MENU 2
139 #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3
140 #define NS_STYLE_WINDOW_SHADOW_SHEET 4
143 * nsIWidget::OnIMEFocusChange should be called during blur,
144 * but other OnIME*Change methods should not be called
146 #define NS_SUCCESS_IME_NO_UPDATES \
147 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_WIDGET, 1)
150 * Cursor types.
153 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
154 eCursor_standard,
155 ///(system is busy, usually rendered as a hourglass or watch)
156 eCursor_wait,
157 ///(Selecting something, usually rendered as an IBeam)
158 eCursor_select,
159 ///(can hyper-link, usually rendered as a human hand)
160 eCursor_hyperlink,
161 ///(north/south/west/east edge sizing)
162 eCursor_n_resize,
163 eCursor_s_resize,
164 eCursor_w_resize,
165 eCursor_e_resize,
166 ///(corner sizing)
167 eCursor_nw_resize,
168 eCursor_se_resize,
169 eCursor_ne_resize,
170 eCursor_sw_resize,
171 eCursor_crosshair,
172 eCursor_move,
173 eCursor_help,
174 eCursor_copy, // CSS3
175 eCursor_alias,
176 eCursor_context_menu,
177 eCursor_cell,
178 eCursor_grab,
179 eCursor_grabbing,
180 eCursor_spinning,
181 eCursor_zoom_in,
182 eCursor_zoom_out,
183 eCursor_not_allowed,
184 eCursor_col_resize,
185 eCursor_row_resize,
186 eCursor_no_drop,
187 eCursor_vertical_text,
188 eCursor_all_scroll,
189 eCursor_nesw_resize,
190 eCursor_nwse_resize,
191 eCursor_ns_resize,
192 eCursor_ew_resize,
193 eCursor_none,
194 // This one better be the last one in this list.
195 eCursorCount
198 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
199 eZPlacementBottom = 0, // bottom of the window stack
200 eZPlacementBelow, // just below another widget
201 eZPlacementTop // top of the window stack
206 * Preference for receiving IME updates
208 * If mWantUpdates is true, PuppetWidget will forward
209 * nsIWidget::OnIMETextChange and nsIWidget::OnIMESelectionChange to the chrome
210 * process. This incurs overhead from observers and IPDL. If the IME
211 * implementation on a particular platform doesn't care about OnIMETextChange
212 * and OnIMESelectionChange from content processes, they should set
213 * mWantUpdates to false to avoid these overheads.
215 * If mWantHints is true, PuppetWidget will forward the content of text fields
216 * to the chrome process to be cached. This way we return the cached content
217 * during query events. (see comments in bug 583976). This only makes sense
218 * for IME implementations that do use query events, otherwise there's a
219 * significant overhead. Platforms that don't use query events should set
220 * mWantHints to false.
222 struct nsIMEUpdatePreference {
224 nsIMEUpdatePreference()
225 : mWantUpdates(PR_FALSE), mWantHints(PR_FALSE)
228 nsIMEUpdatePreference(PRBool aWantUpdates, PRBool aWantHints)
229 : mWantUpdates(aWantUpdates), mWantHints(aWantHints)
232 PRPackedBool mWantUpdates;
233 PRPackedBool mWantHints;
238 * Contains IMEStatus plus information about the current
239 * input context that the IME can use as hints if desired.
241 struct IMEContext {
242 PRUint32 mStatus;
244 /* The type of the input if the input is a html input field */
245 nsString mHTMLInputType;
247 /* A hint for the action that is performed when the input is submitted */
248 nsString mActionHint;
253 * The base class for all the widgets. It provides the interface for
254 * all basic and necessary functionality.
256 class nsIWidget : public nsISupports {
257 #ifdef MOZ_IPC
258 protected:
259 typedef mozilla::dom::PBrowserChild PBrowserChild;
260 #endif
262 public:
263 typedef mozilla::layers::LayerManager LayerManager;
265 // Used in UpdateThemeGeometries.
266 struct ThemeGeometry {
267 // The -moz-appearance value for the themed widget
268 PRUint8 mWidgetType;
269 // The device-pixel rect within the window for the themed widget
270 nsIntRect mRect;
272 ThemeGeometry(PRUint8 aWidgetType, const nsIntRect& aRect)
273 : mWidgetType(aWidgetType)
274 , mRect(aRect)
278 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
280 nsIWidget()
281 : mLastChild(nsnull)
282 , mPrevSibling(nsnull)
287 * Create and initialize a widget.
289 * All the arguments can be NULL in which case a top level window
290 * with size 0 is created. The event callback function has to be
291 * provided only if the caller wants to deal with the events this
292 * widget receives. The event callback is basically a preprocess
293 * hook called synchronously. The return value determines whether
294 * the event goes to the default window procedure or it is hidden
295 * to the os. The assumption is that if the event handler returns
296 * false the widget does not see the event. The widget should not
297 * automatically clear the window to the background color. The
298 * calling code must handle paint messages and clear the background
299 * itself.
301 * In practice at least one of aParent and aNativeParent will be null. If
302 * both are null the widget isn't parented (e.g. context menus or
303 * independent top level windows).
305 * @param aParent parent nsIWidget
306 * @param aNativeParent native parent widget
307 * @param aRect the widget dimension
308 * @param aHandleEventFunction the event handler callback function
309 * @param aContext
310 * @param aAppShell the parent application shell. If nsnull,
311 * the parent window's application shell will be used.
312 * @param aToolkit
313 * @param aInitData data that is used for widget initialization
316 NS_IMETHOD Create(nsIWidget *aParent,
317 nsNativeWidget aNativeParent,
318 const nsIntRect &aRect,
319 EVENT_CALLBACK aHandleEventFunction,
320 nsIDeviceContext *aContext,
321 nsIAppShell *aAppShell = nsnull,
322 nsIToolkit *aToolkit = nsnull,
323 nsWidgetInitData *aInitData = nsnull) = 0;
326 * Allocate, initialize, and return a widget that is a child of
327 * |this|. The returned widget (if nonnull) has gone through the
328 * equivalent of CreateInstance(widgetCID) + Create(...).
330 * |CreateChild()| lets widget backends decide whether to parent
331 * the new child widget to this, nonnatively parent it, or both.
332 * This interface exists to support the PuppetWidget backend,
333 * which is entirely non-native. All other params are the same as
334 * for |Create()|.
336 * |aForceUseIWidgetParent| forces |CreateChild()| to only use the
337 * |nsIWidget*| this, not its native widget (if it exists), when
338 * calling |Create()|. This is a timid hack around poorly
339 * understood code, and shouldn't be used in new code.
341 virtual already_AddRefed<nsIWidget>
342 CreateChild(const nsIntRect &aRect,
343 EVENT_CALLBACK aHandleEventFunction,
344 nsIDeviceContext *aContext,
345 nsIAppShell *aAppShell = nsnull,
346 nsIToolkit *aToolkit = nsnull,
347 nsWidgetInitData *aInitData = nsnull,
348 PRBool aForceUseIWidgetParent = PR_FALSE) = 0;
351 * Attach to a top level widget.
353 * In cases where a top level chrome widget is being used as a content
354 * container, attach a secondary event callback and update the device
355 * context. The primary event callback will continue to be called, so the
356 * owning base window will continue to function.
358 * aViewEventFunction Event callback that will receive mirrored
359 * events.
360 * aContext The new device context for the view
362 NS_IMETHOD AttachViewToTopLevel(EVENT_CALLBACK aViewEventFunction,
363 nsIDeviceContext *aContext) = 0;
366 * Accessor functions to get and set secondary client data. Used by
367 * nsIView in connection with AttachViewToTopLevel above.
369 NS_IMETHOD SetAttachedViewPtr(ViewWrapper* aViewWrapper) = 0;
370 virtual ViewWrapper* GetAttachedViewPtr() = 0;
373 * Accessor functions to get and set the client data associated with the
374 * widget.
376 //@{
377 NS_IMETHOD GetClientData(void*& aClientData) = 0;
378 NS_IMETHOD SetClientData(void* aClientData) = 0;
379 //@}
382 * Close and destroy the internal native window.
383 * This method does not delete the widget.
386 NS_IMETHOD Destroy(void) = 0;
390 * Reparent a widget
392 * Change the widgets parent
394 * @param aNewParent new parent
396 NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
398 NS_IMETHOD RegisterTouchWindow() = 0;
399 NS_IMETHOD UnregisterTouchWindow() = 0;
402 * Return the parent Widget of this Widget or nsnull if this is a
403 * top level window
405 * @return the parent widget or nsnull if it does not have a parent
408 virtual nsIWidget* GetParent(void) = 0;
411 * Return the top level Widget of this Widget
413 * @return the top level widget
415 virtual nsIWidget* GetTopLevelWidget() = 0;
418 * Return the top (non-sheet) parent of this Widget if it's a sheet,
419 * or nsnull if this isn't a sheet (or some other error occurred).
420 * Sheets are only supported on some platforms (currently only OS X).
422 * @return the top (non-sheet) parent widget or nsnull
425 virtual nsIWidget* GetSheetWindowParent(void) = 0;
428 * Return the physical DPI of the screen containing the window ...
429 * the number of device pixels per inch.
431 virtual float GetDPI() = 0;
434 * Return the default scale factor for the window. This is the
435 * default number of device pixels per CSS pixel to use. This should
436 * depend on OS/platform settings such as the Mac's "UI scale factor"
437 * or Windows' "font DPI".
439 virtual double GetDefaultScale() = 0;
442 * Return the first child of this widget. Will return null if
443 * there are no children.
445 nsIWidget* GetFirstChild() const {
446 return mFirstChild;
450 * Return the last child of this widget. Will return null if
451 * there are no children.
453 nsIWidget* GetLastChild() const {
454 return mLastChild;
458 * Return the next sibling of this widget
460 nsIWidget* GetNextSibling() const {
461 return mNextSibling;
465 * Set the next sibling of this widget
467 void SetNextSibling(nsIWidget* aSibling) {
468 mNextSibling = aSibling;
472 * Return the previous sibling of this widget
474 nsIWidget* GetPrevSibling() const {
475 return mPrevSibling;
479 * Set the previous sibling of this widget
481 void SetPrevSibling(nsIWidget* aSibling) {
482 mPrevSibling = aSibling;
486 * Show or hide this widget
488 * @param aState PR_TRUE to show the Widget, PR_FALSE to hide it
491 NS_IMETHOD Show(PRBool aState) = 0;
494 * Make the window modal
497 NS_IMETHOD SetModal(PRBool aModal) = 0;
500 * Returns whether the window is visible
503 NS_IMETHOD IsVisible(PRBool & aState) = 0;
506 * Perform platform-dependent sanity check on a potential window position.
507 * This is guaranteed to work only for top-level windows.
509 * @param aAllowSlop: if true, allow the window to slop offscreen;
510 * the window should be partially visible. if false,
511 * force the entire window onscreen (or at least
512 * the upper-left corner, if it's too large).
513 * @param aX in: an x position expressed in screen coordinates.
514 * out: the x position constrained to fit on the screen(s).
515 * @param aY in: an y position expressed in screen coordinates.
516 * out: the y position constrained to fit on the screen(s).
517 * @return vapid success indication. but see also the parameters.
520 NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
521 PRInt32 *aX,
522 PRInt32 *aY) = 0;
525 * Move this widget.
527 * Coordinates refer to the top-left of the widget. For toplevel windows
528 * with decorations, this is the top-left of the titlebar and frame .
530 * @param aX the new x position expressed in the parent's coordinate system
531 * @param aY the new y position expressed in the parent's coordinate system
534 NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0;
537 * Resize this widget.
539 * @param aWidth the new width expressed in the parent's coordinate system
540 * @param aHeight the new height expressed in the parent's coordinate system
541 * @param aRepaint whether the widget should be repainted
544 NS_IMETHOD Resize(PRInt32 aWidth,
545 PRInt32 aHeight,
546 PRBool aRepaint) = 0;
549 * Move or resize this widget.
551 * @param aX the new x position expressed in the parent's coordinate system
552 * @param aY the new y position expressed in the parent's coordinate system
553 * @param aWidth the new width expressed in the parent's coordinate system
554 * @param aHeight the new height expressed in the parent's coordinate system
555 * @param aRepaint whether the widget should be repainted if the size changes
558 NS_IMETHOD Resize(PRInt32 aX,
559 PRInt32 aY,
560 PRInt32 aWidth,
561 PRInt32 aHeight,
562 PRBool aRepaint) = 0;
565 * Resize and reposition the inner client area of the widget.
567 * @param aX the new x offset expressed in the parent's coordinate system
568 * @param aY the new y offset expressed in the parent's coordinate system
569 * @param aWidth the new width of the client area.
570 * @param aHeight the new height of the client area.
571 * @param aRepaint whether the widget should be repainted
574 NS_IMETHOD ResizeClient(PRInt32 aX,
575 PRInt32 aY,
576 PRInt32 aWidth,
577 PRInt32 aHeight,
578 PRBool aRepaint) = 0;
581 * Sets the widget's z-index.
583 NS_IMETHOD SetZIndex(PRInt32 aZIndex) = 0;
586 * Gets the widget's z-index.
588 NS_IMETHOD GetZIndex(PRInt32* aZIndex) = 0;
591 * Position this widget just behind the given widget. (Used to
592 * control z-order for top-level widgets. Get/SetZIndex by contrast
593 * control z-order for child widgets of other widgets.)
594 * @param aPlacement top, bottom, or below a widget
595 * (if top or bottom, param aWidget is ignored)
596 * @param aWidget widget to place this widget behind
597 * (only if aPlacement is eZPlacementBelow).
598 * null is equivalent to aPlacement of eZPlacementTop
599 * @param aActivate true to activate the widget after placing it
601 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
602 nsIWidget *aWidget, PRBool aActivate) = 0;
605 * Minimize, maximize or normalize the window size.
606 * Takes a value from nsSizeMode (see nsGUIEvent.h)
608 NS_IMETHOD SetSizeMode(PRInt32 aMode) = 0;
611 * Return size mode (minimized, maximized, normalized).
612 * Returns a value from nsSizeMode (see nsGUIEvent.h)
614 NS_IMETHOD GetSizeMode(PRInt32* aMode) = 0;
617 * Enable or disable this Widget
619 * @param aState PR_TRUE to enable the Widget, PR_FALSE to disable it.
622 NS_IMETHOD Enable(PRBool aState) = 0;
625 * Ask whether the widget is enabled
626 * @param aState returns PR_TRUE if the widget is enabled
628 NS_IMETHOD IsEnabled(PRBool *aState) = 0;
631 * Request activation of this window or give focus to this widget.
633 * @param aRaise If PR_TRUE, this function requests activation of this
634 * widget's toplevel window.
635 * If PR_FALSE, the appropriate toplevel window (which in
636 * the case of popups may not be this widget's toplevel
637 * window) is already active, and this function indicates
638 * that keyboard events should be reported through the
639 * aHandleEventFunction provided to this->Create().
641 NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE) = 0;
644 * Get this widget's outside dimensions relative to its parent widget
646 * @param aRect On return it holds the x, y, width and height of
647 * this widget.
649 NS_IMETHOD GetBounds(nsIntRect &aRect) = 0;
652 * Get this widget's outside dimensions in global coordinates. This
653 * includes any title bar on the window.
655 * @param aRect On return it holds the x, y, width and height of
656 * this widget.
658 NS_IMETHOD GetScreenBounds(nsIntRect &aRect) = 0;
661 * Get this widget's client area dimensions, if the window has a 3D
662 * border appearance this returns the area inside the border. Origin
663 * is always zero.
665 * @param aRect On return it holds the x. y, width and height of
666 * the client area of this widget.
668 NS_IMETHOD GetClientBounds(nsIntRect &aRect) = 0;
671 * Get the non-client area dimensions of the window.
674 NS_IMETHOD GetNonClientMargins(nsIntMargin &margins) = 0;
677 * Sets the non-client area dimensions of the window. Pass -1 to restore
678 * the system default frame size for that border. Pass zero to remove
679 * a border, or pass a specific value adjust a border. Units are in
680 * pixels. (DPI dependent)
682 * Platform notes:
683 * Windows: shrinking top non-client height will remove application
684 * icon and window title text. Glass desktops will refuse to set
685 * dimensions between zero and size < system default.
688 NS_IMETHOD SetNonClientMargins(nsIntMargin &margins) = 0;
691 * Get the client offset from the window origin.
693 * @return the x and y of the offset.
696 virtual nsIntPoint GetClientOffset() = 0;
699 * Get the foreground color for this widget
701 * @return this widget's foreground color
704 virtual nscolor GetForegroundColor(void) = 0;
707 * Set the foreground color for this widget
709 * @param aColor the new foreground color
713 NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
716 * Get the background color for this widget
718 * @return this widget's background color
722 virtual nscolor GetBackgroundColor(void) = 0;
725 * Set the background color for this widget
727 * @param aColor the new background color
731 NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
734 * Get the cursor for this widget.
736 * @return this widget's cursor.
739 virtual nsCursor GetCursor(void) = 0;
742 * Set the cursor for this widget
744 * @param aCursor the new cursor for this widget
747 NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
750 * Sets an image as the cursor for this widget.
752 * @param aCursor the cursor to set
753 * @param aX the X coordinate of the hotspot (from left).
754 * @param aY the Y coordinate of the hotspot (from top).
755 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
756 * supported
758 NS_IMETHOD SetCursor(imgIContainer* aCursor,
759 PRUint32 aHotspotX, PRUint32 aHotspotY) = 0;
761 /**
762 * Get the window type of this widget
764 * @param aWindowType the window type of the widget
766 NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
769 * Set the transparency mode of the top-level window containing this widget.
770 * So, e.g., if you call this on the widget for an IFRAME, the top level
771 * browser window containing the IFRAME actually gets set. Be careful.
773 * This can fail if the platform doesn't support
774 * transparency/glass. By default widgets are not
775 * transparent. This will also fail if the toplevel window is not
776 * a Mozilla window, e.g., if the widget is in an embedded
777 * context.
779 * After transparency/glass has been enabled, the initial alpha channel
780 * value for all pixels is 1, i.e., opaque.
781 * If the window is resized then the alpha channel values for
782 * all pixels are reset to 1.
783 * Pixel RGB color values are already premultiplied with alpha channel values.
785 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
788 * Get the transparency mode of the top-level window that contains this
789 * widget.
791 virtual nsTransparencyMode GetTransparencyMode() = 0;
794 * depreciated, see 2.0 interface.
796 virtual void UpdatePossiblyTransparentRegion(const nsIntRegion &aDirtyRegion,
797 const nsIntRegion &aPossiblyTransparentRegion) {};
800 * This represents a command to set the bounds and clip region of
801 * a child widget.
803 struct Configuration {
804 nsIWidget* mChild;
805 nsIntRect mBounds;
806 nsTArray<nsIntRect> mClipRegion;
810 * Sets the clip region of each mChild (which must actually be a child
811 * of this widget) to the union of the pixel rects given in
812 * mClipRegion, all relative to the top-left of the child
813 * widget. Clip regions are not implemented on all platforms and only
814 * need to actually work for children that are plugins.
816 * Also sets the bounds of each child to mBounds.
818 * This will invalidate areas of the children that have changed, but
819 * does not need to invalidate any part of this widget.
821 * Children should be moved in the order given; the array is
822 * sorted so to minimize unnecessary invalidation if children are
823 * moved in that order.
825 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
828 * Appends to aRects the rectangles constituting this widget's clip
829 * region. If this widget is not clipped, appends a single rectangle
830 * (0, 0, bounds.width, bounds.height).
832 virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects) = 0;
835 * Set the shadow style of the window.
837 * Ignored on child widgets and on non-Mac platforms.
839 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle) = 0;
842 * On Mac OS X, this method shows or hides the pill button in the titlebar
843 * that's used to collapse the toolbar.
845 * Ignored on child widgets and on non-Mac platforms.
847 virtual void SetShowsToolbarButton(PRBool aShow) = 0;
849 /**
850 * Hide window chrome (borders, buttons) for this widget.
853 NS_IMETHOD HideWindowChrome(PRBool aShouldHide) = 0;
856 * Put the toplevel window into or out of fullscreen mode.
859 NS_IMETHOD MakeFullScreen(PRBool aFullScreen) = 0;
862 * Invalidate a specified rect for a widget and repaints it.
864 * @param aIsSynchronouse PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
865 * @see #Update()
868 NS_IMETHOD Invalidate(const nsIntRect & aRect, PRBool aIsSynchronous) = 0;
871 * Force a synchronous repaint of the window if there are dirty rects.
873 * @see Invalidate()
876 NS_IMETHOD Update() = 0;
879 * Return the widget's toolkit
881 * An AddRef has NOT been done for the caller.
883 * @return the toolkit this widget was created in. See nsToolkit.
886 virtual nsIToolkit* GetToolkit() = 0;
889 * Return the widget's LayerManager. The layer tree for that
890 * LayerManager is what gets rendered to the widget.
892 * @param aAllowRetaining an outparam that states whether the returned
893 * layer manager should be used for retained layers
895 virtual LayerManager* GetLayerManager(bool* aAllowRetaining = nsnull) = 0;
897 /**
898 * Internal methods
901 //@{
902 virtual void AddChild(nsIWidget* aChild) = 0;
903 virtual void RemoveChild(nsIWidget* aChild) = 0;
904 virtual void* GetNativeData(PRUint32 aDataType) = 0;
905 virtual void FreeNativeData(void * data, PRUint32 aDataType) = 0;//~~~
907 // GetDeviceContext returns a weak pointer to this widget's device context
908 virtual nsIDeviceContext* GetDeviceContext() = 0;
910 //@}
913 * Set the widget's title.
914 * Must be called after Create.
916 * @param aTitle string displayed as the title of the widget
919 NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
922 * Set the widget's icon.
923 * Must be called after Create.
925 * @param anIconSpec string specifying the icon to use; convention is to pass
926 * a resource: URL from which a platform-dependent resource
927 * file name will be constructed
930 NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
933 * Return this widget's origin in screen coordinates.
935 * @return screen coordinates stored in the x,y members
938 virtual nsIntPoint WidgetToScreenOffset() = 0;
941 * Given the specified client size, return the corresponding window size,
942 * which includes the area for the borders and titlebar. This method
943 * should work even when the window is not yet visible.
945 virtual nsIntSize ClientToWindowSize(const nsIntSize& aClientSize) = 0;
948 * Dispatches an event to the widget
951 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
954 * Enables the dropping of files to a widget (XXX this is temporary)
957 NS_IMETHOD EnableDragDrop(PRBool aEnable) = 0;
960 * Enables/Disables system mouse capture.
961 * @param aCapture PR_TRUE enables mouse capture, PR_FALSE disables mouse capture
964 NS_IMETHOD CaptureMouse(PRBool aCapture) = 0;
967 * Classify the window for the window manager. Mostly for X11.
969 NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0;
972 * Enables/Disables system capture of any and all events that would cause a
973 * dropdown to be rolled up, This method ignores the aConsumeRollupEvent
974 * parameter when aDoCapture is FALSE
975 * @param aDoCapture PR_TRUE enables capture, PR_FALSE disables capture
976 * @param aConsumeRollupEvent PR_TRUE consumes the rollup event, PR_FALSE dispatches rollup event
979 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, nsIMenuRollup * aMenuRollup,
980 PRBool aDoCapture, PRBool aConsumeRollupEvent) = 0;
983 * Bring this window to the user's attention. This is intended to be a more
984 * gentle notification than popping the window to the top or putting up an
985 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
986 * the Mac. The notification should be suppressed if the window is already
987 * in the foreground and should be dismissed when the user brings this window
988 * to the foreground.
989 * @param aCycleCount Maximum number of times to animate the window per system
990 * conventions. If set to -1, cycles indefinitely until
991 * window is brought into the foreground.
993 NS_IMETHOD GetAttention(PRInt32 aCycleCount) = 0;
996 * Ask whether there user input events pending. All input events are
997 * included, including those not targeted at this nsIwidget instance.
999 virtual PRBool HasPendingInputEvent() = 0;
1002 * Called when when we need to begin secure keyboard input, such as when a password field
1003 * gets focus.
1005 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
1006 * for one widget at a time.
1008 NS_IMETHOD BeginSecureKeyboardInput() = 0;
1011 * Called when when we need to end secure keyboard input, such as when a password field
1012 * loses focus.
1014 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
1015 * for one widget at a time.
1017 NS_IMETHOD EndSecureKeyboardInput() = 0;
1020 * Set the background color of the window titlebar for this widget. On Mac,
1021 * for example, this will remove the grey gradient and bottom border and
1022 * instead show a single, solid color.
1024 * Ignored on any platform that does not support it. Ignored by widgets that
1025 * do not represent windows.
1027 * @param aColor The color to set the title bar background to. Alpha values
1028 * other than fully transparent (0) are respected if possible
1029 * on the platform. An alpha of 0 will cause the window to
1030 * draw with the default style for the platform.
1032 * @param aActive Whether the color should be applied to active or inactive
1033 * windows.
1035 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive) = 0;
1038 * If set to true, the window will draw its contents into the titlebar
1039 * instead of below it.
1041 * Ignored on any platform that does not support it. Ignored by widgets that
1042 * do not represent windows.
1043 * May result in a resize event, so should only be called from places where
1044 * reflow and painting is allowed.
1046 * @param aState Whether drawing into the titlebar should be activated.
1048 virtual void SetDrawsInTitlebar(PRBool aState) = 0;
1051 * Determine whether the widget shows a resize widget. If it does,
1052 * aResizerRect returns the resizer's rect.
1054 * Returns false on any platform that does not support it.
1056 * @param aResizerRect The resizer's rect in device pixels.
1057 * @return Whether a resize widget is shown.
1059 virtual PRBool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0;
1062 * Get the Thebes surface associated with this widget.
1064 virtual gfxASurface *GetThebesSurface() = 0;
1067 * Return the popup that was last rolled up, or null if there isn't one.
1069 virtual nsIContent* GetLastRollup() = 0;
1072 * Begin a window resizing drag, based on the event passed in.
1074 NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical) = 0;
1077 * Begin a window moving drag, based on the event passed in.
1079 NS_IMETHOD BeginMoveDrag(nsMouseEvent* aEvent) = 0;
1081 enum Modifiers {
1082 CAPS_LOCK = 0x01, // when CapsLock is active
1083 NUM_LOCK = 0x02, // when NumLock is active
1084 SHIFT_L = 0x0100,
1085 SHIFT_R = 0x0200,
1086 CTRL_L = 0x0400,
1087 CTRL_R = 0x0800,
1088 ALT_L = 0x1000, // includes Option
1089 ALT_R = 0x2000,
1090 COMMAND_L = 0x4000,
1091 COMMAND_R = 0x8000,
1092 HELP = 0x10000,
1093 FUNCTION = 0x100000,
1094 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
1097 * Utility method intended for testing. Dispatches native key events
1098 * to this widget to simulate the press and release of a key.
1099 * @param aNativeKeyboardLayout a *platform-specific* constant.
1100 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
1101 * On Windows, it is converted to a hex string and passed to
1102 * LoadKeyboardLayout, see
1103 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
1104 * @param aNativeKeyCode a *platform-specific* keycode.
1105 * On Windows, this is the virtual key code.
1106 * @param aModifiers some combination of the above 'Modifiers' flags;
1107 * not all flags will apply to all platforms. Mac ignores the _R
1108 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
1109 * FUNCTION.
1110 * @param aCharacters characters that the OS would decide to generate
1111 * from the event. On Windows, this is the charCode passed by
1112 * WM_CHAR.
1113 * @param aUnmodifiedCharacters characters that the OS would decide
1114 * to generate from the event if modifier keys (other than shift)
1115 * were assumed inactive. Needed on Mac, ignored on Windows.
1116 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
1117 * layout is not supported and the event was not fired
1119 virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
1120 PRInt32 aNativeKeyCode,
1121 PRUint32 aModifierFlags,
1122 const nsAString& aCharacters,
1123 const nsAString& aUnmodifiedCharacters) = 0;
1126 * Utility method intended for testing. Dispatches native mouse events
1127 * may even move the mouse cursor. On Mac the events are guaranteed to
1128 * be sent to the window containing this widget, but on Windows they'll go
1129 * to whatever's topmost on the screen at that position, so for
1130 * cross-platform testing ensure that your window is at the top of the
1131 * z-order.
1132 * @param aPoint screen location of the mouse, in device
1133 * pixels, with origin at the top left
1134 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
1135 * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
1136 * @param aModifierFlags *platform-specific* modifier flags (ignored
1137 * on Windows)
1139 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
1140 PRUint32 aNativeMessage,
1141 PRUint32 aModifierFlags) = 0;
1144 * Activates a native menu item at the position specified by the index
1145 * string. The index string is a string of positive integers separated
1146 * by the "|" (pipe) character. The last integer in the string represents
1147 * the item index in a submenu located using the integers preceding it.
1149 * Example: 1|0|4
1150 * In this string, the first integer represents the top-level submenu
1151 * in the native menu bar. Since the integer is 1, it is the second submeu
1152 * in the native menu bar. Within that, the first item (index 0) is a
1153 * submenu, and we want to activate the 5th item within that submenu.
1155 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
1158 * This is used for native menu system testing.
1160 * Updates a native menu at the position specified by the index string.
1161 * The index string is a string of positive integers separated by the "|"
1162 * (pipe) character.
1164 * Example: 1|0|4
1165 * In this string, the first integer represents the top-level submenu
1166 * in the native menu bar. Since the integer is 1, it is the second submeu
1167 * in the native menu bar. Within that, the first item (index 0) is a
1168 * submenu, and we want to update submenu at index 4 within that submenu.
1170 * If this is called with an empty string it forces a full reload of the
1171 * menu system.
1173 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
1176 * Force Input Method Editor to commit the uncommitted input
1178 NS_IMETHOD ResetInputState()=0;
1181 * Following methods relates to IME 'Opened'/'Closed' state.
1182 * 'Opened' means the user can input any character. I.e., users can input Japanese
1183 * and other characters. The user can change the state to 'Closed'.
1184 * 'Closed' means the user can input ASCII characters only. This is the same as a
1185 * non-IME environment. The user can change the state to 'Opened'.
1186 * For more information is here.
1187 * http://bugzilla.mozilla.org/show_bug.cgi?id=16940#c48
1191 * Set the state to 'Opened' or 'Closed'.
1192 * If aState is TRUE, IME open state is set to 'Opened'.
1193 * If aState is FALSE, set to 'Closed'.
1195 NS_IMETHOD SetIMEOpenState(PRBool aState) = 0;
1198 * Get IME is 'Opened' or 'Closed'.
1199 * If IME is 'Opened', aState is set PR_TRUE.
1200 * If IME is 'Closed', aState is set PR_FALSE.
1202 NS_IMETHOD GetIMEOpenState(PRBool* aState) = 0;
1205 * IME enabled states, the aState value of SetIMEEnabled/GetIMEEnabled
1206 * should be one value of following values.
1208 * WARNING: If you change these values, you also need to edit:
1209 * nsIDOMWindowUtils.idl
1210 * nsDOMWindowUtils::SetIMEEnabled
1211 * nsContentUtils::GetWidgetStatusFromIMEStatus
1213 enum IMEStatus {
1215 * 'Disabled' means the user cannot use IME. So, the open state should be
1216 * 'closed' during 'disabled'.
1218 IME_STATUS_DISABLED = 0,
1220 * 'Enabled' means the user can use IME.
1222 IME_STATUS_ENABLED = 1,
1224 * 'Password' state is a special case for the password editors.
1225 * E.g., on mac, the password editors should disable the non-Roman
1226 * keyboard layouts at getting focus. Thus, the password editor may have
1227 * special rules on some platforms.
1229 IME_STATUS_PASSWORD = 2,
1231 * This state is used when a plugin is focused.
1232 * When a plug-in is focused content, we should send native events
1233 * directly. Because we don't process some native events, but they may
1234 * be needed by the plug-in.
1236 IME_STATUS_PLUGIN = 3
1240 * Set the state to 'Enabled' or 'Disabled' or 'Password'.
1242 NS_IMETHOD SetIMEEnabled(PRUint32 aState) = 0;
1245 * Get IME is 'Enabled' or 'Disabled' or 'Password'.
1247 NS_IMETHOD GetIMEEnabled(PRUint32* aState) = 0;
1250 * Destruct and don't commit the IME composition string.
1252 NS_IMETHOD CancelIMEComposition() = 0;
1255 * Set accelerated rendering to 'True' or 'False'
1257 NS_IMETHOD SetAcceleratedRendering(PRBool aEnabled) = 0;
1260 * Get toggled key states.
1261 * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or
1262 * NS_VK_SCROLL_LOCK.
1263 * aLEDState is the result for current LED state of the key.
1264 * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
1265 * If the platform doesn't support the LED state (or we cannot get the
1266 * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
1268 NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) = 0;
1271 * An editable node (i.e. input/textarea/design mode document)
1272 * is receiving or giving up focus
1273 * aFocus is true if node is receiving focus
1274 * aFocus is false if node is giving up focus (blur)
1276 * If this returns NS_ERROR_*, OnIMETextChange and OnIMESelectionChange
1277 * and OnIMEFocusChange(PR_FALSE) will be never called.
1279 * If this returns NS_SUCCESS_IME_NO_UPDATES, OnIMEFocusChange(PR_FALSE)
1280 * will be called but OnIMETextChange and OnIMESelectionChange will NOT.
1282 NS_IMETHOD OnIMEFocusChange(PRBool aFocus) = 0;
1285 * Text content of the focused node has changed
1286 * aStart is the starting offset of the change
1287 * aOldEnd is the ending offset of the change
1288 * aNewEnd is the caret offset after the change
1290 NS_IMETHOD OnIMETextChange(PRUint32 aStart,
1291 PRUint32 aOldEnd,
1292 PRUint32 aNewEnd) = 0;
1295 * Selection has changed in the focused node
1297 NS_IMETHOD OnIMESelectionChange(void) = 0;
1300 * Retrieves preference for IME updates
1302 virtual nsIMEUpdatePreference GetIMEUpdatePreference() = 0;
1305 * Call this method when a dialog is opened which has a default button.
1306 * The button's rectangle should be supplied in aButtonRect.
1308 NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) = 0;
1311 * Compute the overridden system mouse scroll speed on the root content of
1312 * web pages. The widget may set the same value as aOriginalDelta. E.g.,
1313 * when the system scrolling settings were customized, widget can respect
1314 * the will of the user.
1316 * This is called only when the mouse wheel event scrolls the root content
1317 * of the web pages by line. In other words, this isn't called when the
1318 * mouse wheel event is used for zoom, page scroll and other special
1319 * actions. And also this isn't called when the user doesn't use the
1320 * system wheel speed settings.
1322 * @param aOriginalDelta The delta value of the current mouse wheel
1323 * scrolling event.
1324 * @param aIsHorizontal If TRUE, the scrolling direction is horizontal.
1325 * Otherwise, it's vertical.
1326 * @param aOverriddenDelta The overridden mouse scrolling speed. This value
1327 * may be same as aOriginalDelta.
1329 NS_IMETHOD OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta,
1330 PRBool aIsHorizontal,
1331 PRInt32 &aOverriddenDelta) = 0;
1334 * Return true if this process shouldn't use platform widgets, and
1335 * so should use PuppetWidgets instead. If this returns true, the
1336 * result of creating and using a platform widget is undefined,
1337 * and likely to end in crashes or other buggy behavior.
1339 static bool
1340 UsePuppetWidgets()
1342 #ifdef MOZ_IPC
1343 return XRE_GetProcessType() == GeckoProcessType_Content;
1344 #else
1345 return PR_FALSE;
1346 #endif
1349 #ifdef MOZ_IPC
1351 * Allocate and return a "puppet widget" that doesn't directly
1352 * correlate to a platform widget; platform events and data must
1353 * be fed to it. Currently used in content processes. NULL is
1354 * returned if puppet widgets aren't supported in this build
1355 * config, on this platform, or for this process type.
1357 * This function is called "Create" to match CreateInstance().
1358 * The returned widget must still be nsIWidget::Create()d.
1360 static already_AddRefed<nsIWidget>
1361 CreatePuppetWidget(PBrowserChild *aTabChild);
1362 #endif
1365 * Reparent this widget's native widget.
1366 * @param aNewParent the native widget of aNewParent is the new native
1367 * parent widget
1369 NS_IMETHOD ReparentNativeWidget(nsIWidget* aNewParent) = 0;
1370 protected:
1372 // keep the list of children. We also keep track of our siblings.
1373 // The ownership model is as follows: parent holds a strong ref to
1374 // the first element of the list, and each element holds a strong
1375 // ref to the next element in the list. The prevsibling and
1376 // lastchild pointers are weak, which is fine as long as they are
1377 // maintained properly.
1378 nsCOMPtr<nsIWidget> mFirstChild;
1379 nsIWidget* mLastChild;
1380 nsCOMPtr<nsIWidget> mNextSibling;
1381 nsIWidget* mPrevSibling;
1384 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
1386 class nsIWidget_MOZILLA_2_0_BRANCH : public nsIWidget {
1387 public:
1388 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_MOZILLA_2_0_BRANCH_IID)
1390 typedef mozilla::layers::LayerManager LayerManager;
1393 * Notifies the IME if the input context changes.
1395 * aContext cannot be null.
1396 * Set mStatus to 'Enabled' or 'Disabled' or 'Password'.
1398 NS_IMETHOD SetInputMode(const IMEContext& aContext) = 0;
1401 * Get IME is 'Enabled' or 'Disabled' or 'Password' and other input context
1403 NS_IMETHOD GetInputMode(IMEContext& aContext) = 0;
1405 enum LayerManagerPersistence
1407 LAYER_MANAGER_CURRENT = 0,
1408 LAYER_MANAGER_PERSISTENT
1411 virtual LayerManager *GetLayerManager(LayerManagerPersistence aPersistence = LAYER_MANAGER_CURRENT,
1412 bool* aAllowRetaining = nsnull) = 0;
1414 // Hide build warnings about nsIWidget::GetLayerManager being hidden by
1415 // our GetLayerManager method above.
1416 using nsIWidget::GetLayerManager;
1419 * Called after the LayerManager draws the layer tree
1421 * @param aManager The drawing LayerManager.
1422 * @param aRect Current widget rect that is being drawn.
1424 virtual void DrawOver(LayerManager* aManager, nsIntRect aRect) = 0;
1427 * Called when Gecko knows which themed widgets exist in this window.
1428 * The passed array contains an entry for every themed widget of the right
1429 * type (currently only NS_THEME_MOZ_MAC_UNIFIED_TOOLBAR and
1430 * NS_THEME_TOOLBAR) within the window, except for themed widgets which are
1431 * transformed or have effects applied to them (e.g. CSS opacity or
1432 * filters).
1433 * This could sometimes be called during display list construction
1434 * outside of painting.
1435 * If called during painting, it will be called before we actually
1436 * paint anything.
1438 virtual void UpdateThemeGeometries(const nsTArray<ThemeGeometry>& aThemeGeometries) = 0;
1441 * Informs the widget about the region of the window that is partially
1442 * transparent. Widgets should assume that the initial transparent
1443 * region is empty.
1445 * @param aTransparentRegion the region of the window that is partially
1446 * transparent.
1448 virtual void UpdateTransparentRegion(const nsIntRegion &aTransparentRegion) {};
1451 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget_MOZILLA_2_0_BRANCH, NS_IWIDGET_MOZILLA_2_0_BRANCH_IID)
1453 #endif // nsIWidget_h__