Fix orange in wake of patch for bug 542002.
[mozilla-central.git] / widget / public / nsIWidget.h
blobab43ab197929f5546968c8bda0660b88e67ec4e5
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"
47 #include "prthread.h"
48 #include "nsEvent.h"
49 #include "nsCOMPtr.h"
50 #include "nsITheme.h"
51 #include "nsNativeWidget.h"
52 #include "nsWidgetInitData.h"
53 #include "nsTArray.h"
55 // forward declarations
56 class nsIAppShell;
57 class nsIToolkit;
58 class nsIFontMetrics;
59 class nsIRenderingContext;
60 class nsIDeviceContext;
61 struct nsFont;
62 class nsIRollupListener;
63 class nsIMenuRollup;
64 class nsGUIEvent;
65 class imgIContainer;
66 class gfxASurface;
67 class nsIContent;
69 /**
70 * Callback function that processes events.
72 * The argument is actually a subtype (subclass) of nsEvent which carries
73 * platform specific information about the event. Platform specific code
74 * knows how to deal with it.
76 * The return value determines whether or not the default action should take
77 * place.
79 typedef nsEventStatus (* EVENT_CALLBACK)(nsGUIEvent *event);
81 /**
82 * Flags for the getNativeData function.
83 * See getNativeData()
85 #define NS_NATIVE_WINDOW 0
86 #define NS_NATIVE_GRAPHIC 1
87 #define NS_NATIVE_WIDGET 3
88 #define NS_NATIVE_DISPLAY 4
89 #define NS_NATIVE_REGION 5
90 #define NS_NATIVE_OFFSETX 6
91 #define NS_NATIVE_OFFSETY 7
92 #define NS_NATIVE_PLUGIN_PORT 8
93 #define NS_NATIVE_SCREEN 9
94 #define NS_NATIVE_SHELLWIDGET 10 // Get the shell GtkWidget
95 #ifdef XP_MACOSX
96 #define NS_NATIVE_PLUGIN_PORT_QD 100
97 #define NS_NATIVE_PLUGIN_PORT_CG 101
98 #endif
99 #ifdef XP_WIN
100 #define NS_NATIVE_TSF_THREAD_MGR 100
101 #define NS_NATIVE_TSF_CATEGORY_MGR 101
102 #define NS_NATIVE_TSF_DISPLAY_ATTR_MGR 102
103 #endif
105 #define NS_IWIDGET_IID \
106 { 0x6bdb96ba, 0x1727, 0x40ae, \
107 { 0x85, 0x55, 0x9c, 0x53, 0x4b, 0x95, 0x23, 0x98 } }
110 * Window shadow styles
111 * Also used for the -moz-window-shadow CSS property
114 #define NS_STYLE_WINDOW_SHADOW_NONE 0
115 #define NS_STYLE_WINDOW_SHADOW_DEFAULT 1
116 #define NS_STYLE_WINDOW_SHADOW_MENU 2
117 #define NS_STYLE_WINDOW_SHADOW_TOOLTIP 3
118 #define NS_STYLE_WINDOW_SHADOW_SHEET 4
121 * Cursor types.
124 enum nsCursor { ///(normal cursor, usually rendered as an arrow)
125 eCursor_standard,
126 ///(system is busy, usually rendered as a hourglass or watch)
127 eCursor_wait,
128 ///(Selecting something, usually rendered as an IBeam)
129 eCursor_select,
130 ///(can hyper-link, usually rendered as a human hand)
131 eCursor_hyperlink,
132 ///(north/south/west/east edge sizing)
133 eCursor_n_resize,
134 eCursor_s_resize,
135 eCursor_w_resize,
136 eCursor_e_resize,
137 ///(corner sizing)
138 eCursor_nw_resize,
139 eCursor_se_resize,
140 eCursor_ne_resize,
141 eCursor_sw_resize,
142 eCursor_crosshair,
143 eCursor_move,
144 eCursor_help,
145 eCursor_copy, // CSS3
146 eCursor_alias,
147 eCursor_context_menu,
148 eCursor_cell,
149 eCursor_grab,
150 eCursor_grabbing,
151 eCursor_spinning,
152 eCursor_zoom_in,
153 eCursor_zoom_out,
154 eCursor_not_allowed,
155 eCursor_col_resize,
156 eCursor_row_resize,
157 eCursor_no_drop,
158 eCursor_vertical_text,
159 eCursor_all_scroll,
160 eCursor_nesw_resize,
161 eCursor_nwse_resize,
162 eCursor_ns_resize,
163 eCursor_ew_resize,
164 eCursor_none,
165 // This one better be the last one in this list.
166 eCursorCount
169 enum nsTopLevelWidgetZPlacement { // for PlaceBehind()
170 eZPlacementBottom = 0, // bottom of the window stack
171 eZPlacementBelow, // just below another widget
172 eZPlacementTop // top of the window stack
177 * The base class for all the widgets. It provides the interface for
178 * all basic and necessary functionality.
180 class nsIWidget : public nsISupports {
182 public:
184 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IWIDGET_IID)
186 nsIWidget()
187 : mLastChild(nsnull)
188 , mPrevSibling(nsnull)
193 * Create and initialize a widget.
195 * All the arguments can be NULL in which case a top level window
196 * with size 0 is created. The event callback function has to be
197 * provided only if the caller wants to deal with the events this
198 * widget receives. The event callback is basically a preprocess
199 * hook called synchronously. The return value determines whether
200 * the event goes to the default window procedure or it is hidden
201 * to the os. The assumption is that if the event handler returns
202 * false the widget does not see the event. The widget should not
203 * automatically clear the window to the background color. The
204 * calling code must handle paint messages and clear the background
205 * itself.
207 * In practice at least one of aParent and aNativeParent will be null. If
208 * both are null the widget isn't parented (e.g. context menus or
209 * independent top level windows).
211 * @param aParent parent nsIWidget
212 * @param aNativeParent native parent widget
213 * @param aRect the widget dimension
214 * @param aHandleEventFunction the event handler callback function
215 * @param aContext
216 * @param aAppShell the parent application shell. If nsnull,
217 * the parent window's application shell will be used.
218 * @param aToolkit
219 * @param aInitData data that is used for widget initialization
222 NS_IMETHOD Create(nsIWidget *aParent,
223 nsNativeWidget aNativeParent,
224 const nsIntRect &aRect,
225 EVENT_CALLBACK aHandleEventFunction,
226 nsIDeviceContext *aContext,
227 nsIAppShell *aAppShell = nsnull,
228 nsIToolkit *aToolkit = nsnull,
229 nsWidgetInitData *aInitData = nsnull) = 0;
232 * Accessor functions to get and set the client data associated with the
233 * widget.
235 //@{
236 NS_IMETHOD GetClientData(void*& aClientData) = 0;
237 NS_IMETHOD SetClientData(void* aClientData) = 0;
238 //@}
241 * Close and destroy the internal native window.
242 * This method does not delete the widget.
245 NS_IMETHOD Destroy(void) = 0;
249 * Reparent a widget
251 * Change the widgets parent
253 * @param aNewParent new parent
255 NS_IMETHOD SetParent(nsIWidget* aNewParent) = 0;
259 * Return the parent Widget of this Widget or nsnull if this is a
260 * top level window
262 * @return the parent widget or nsnull if it does not have a parent
265 virtual nsIWidget* GetParent(void) = 0;
268 * Return the top level Widget of this Widget
270 * @return the top level widget
272 virtual nsIWidget* GetTopLevelWidget() = 0;
275 * Return the top (non-sheet) parent of this Widget if it's a sheet,
276 * or nsnull if this isn't a sheet (or some other error occurred).
277 * Sheets are only supported on some platforms (currently only OS X).
279 * @return the top (non-sheet) parent widget or nsnull
282 virtual nsIWidget* GetSheetWindowParent(void) = 0;
285 * Return the first child of this widget. Will return null if
286 * there are no children.
288 nsIWidget* GetFirstChild() const {
289 return mFirstChild;
293 * Return the last child of this widget. Will return null if
294 * there are no children.
296 nsIWidget* GetLastChild() const {
297 return mLastChild;
301 * Return the next sibling of this widget
303 nsIWidget* GetNextSibling() const {
304 return mNextSibling;
308 * Set the next sibling of this widget
310 void SetNextSibling(nsIWidget* aSibling) {
311 mNextSibling = aSibling;
315 * Return the previous sibling of this widget
317 nsIWidget* GetPrevSibling() const {
318 return mPrevSibling;
322 * Set the previous sibling of this widget
324 void SetPrevSibling(nsIWidget* aSibling) {
325 mPrevSibling = aSibling;
329 * Show or hide this widget
331 * @param aState PR_TRUE to show the Widget, PR_FALSE to hide it
334 NS_IMETHOD Show(PRBool aState) = 0;
337 * Make the window modal
340 NS_IMETHOD SetModal(PRBool aModal) = 0;
343 * Returns whether the window is visible
346 NS_IMETHOD IsVisible(PRBool & aState) = 0;
349 * Perform platform-dependent sanity check on a potential window position.
350 * This is guaranteed to work only for top-level windows.
352 * @param aAllowSlop: if true, allow the window to slop offscreen;
353 * the window should be partially visible. if false,
354 * force the entire window onscreen (or at least
355 * the upper-left corner, if it's too large).
356 * @param aX in: an x position expressed in screen coordinates.
357 * out: the x position constrained to fit on the screen(s).
358 * @param aY in: an y position expressed in screen coordinates.
359 * out: the y position constrained to fit on the screen(s).
360 * @return vapid success indication. but see also the parameters.
363 NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
364 PRInt32 *aX,
365 PRInt32 *aY) = 0;
368 * Move this widget.
370 * @param aX the new x position expressed in the parent's coordinate system
371 * @param aY the new y position expressed in the parent's coordinate system
374 NS_IMETHOD Move(PRInt32 aX, PRInt32 aY) = 0;
377 * Resize this widget.
379 * @param aWidth the new width expressed in the parent's coordinate system
380 * @param aHeight the new height expressed in the parent's coordinate system
381 * @param aRepaint whether the widget should be repainted
384 NS_IMETHOD Resize(PRInt32 aWidth,
385 PRInt32 aHeight,
386 PRBool aRepaint) = 0;
389 * Move or resize this widget.
391 * @param aX the new x position expressed in the parent's coordinate system
392 * @param aY the new y position expressed in the parent's coordinate system
393 * @param aWidth the new width expressed in the parent's coordinate system
394 * @param aHeight the new height expressed in the parent's coordinate system
395 * @param aRepaint whether the widget should be repainted if the size changes
398 NS_IMETHOD Resize(PRInt32 aX,
399 PRInt32 aY,
400 PRInt32 aWidth,
401 PRInt32 aHeight,
402 PRBool aRepaint) = 0;
405 * Sets the widget's z-index.
407 NS_IMETHOD SetZIndex(PRInt32 aZIndex) = 0;
410 * Gets the widget's z-index.
412 NS_IMETHOD GetZIndex(PRInt32* aZIndex) = 0;
415 * Position this widget just behind the given widget. (Used to
416 * control z-order for top-level widgets. Get/SetZIndex by contrast
417 * control z-order for child widgets of other widgets.)
418 * @param aPlacement top, bottom, or below a widget
419 * (if top or bottom, param aWidget is ignored)
420 * @param aWidget widget to place this widget behind
421 * (only if aPlacement is eZPlacementBelow).
422 * null is equivalent to aPlacement of eZPlacementTop
423 * @param aActivate true to activate the widget after placing it
425 NS_IMETHOD PlaceBehind(nsTopLevelWidgetZPlacement aPlacement,
426 nsIWidget *aWidget, PRBool aActivate) = 0;
429 * Minimize, maximize or normalize the window size.
430 * Takes a value from nsSizeMode (see nsGUIEvent.h)
432 NS_IMETHOD SetSizeMode(PRInt32 aMode) = 0;
435 * Return size mode (minimized, maximized, normalized).
436 * Returns a value from nsSizeMode (see nsGUIEvent.h)
438 NS_IMETHOD GetSizeMode(PRInt32* aMode) = 0;
441 * Enable or disable this Widget
443 * @param aState PR_TRUE to enable the Widget, PR_FALSE to disable it.
446 NS_IMETHOD Enable(PRBool aState) = 0;
449 * Ask whether the widget is enabled
450 * @param aState returns PR_TRUE if the widget is enabled
452 NS_IMETHOD IsEnabled(PRBool *aState) = 0;
455 * Give focus to this widget.
457 NS_IMETHOD SetFocus(PRBool aRaise = PR_FALSE) = 0;
460 * Get this widget's outside dimensions relative to its parent widget
462 * @param aRect on return it holds the x, y, width and height of this widget
465 NS_IMETHOD GetBounds(nsIntRect &aRect) = 0;
469 * Get this widget's outside dimensions in global coordinates. (One might think this
470 * could be accomplished by stringing together other methods in this interface, but
471 * then one would bloody one's nose on different coordinate system handling by different
472 * platforms.) This includes any title bar on the window.
475 * @param aRect on return it holds the x, y, width and height of this widget
478 NS_IMETHOD GetScreenBounds(nsIntRect &aRect) = 0;
482 * Get this widget's client area dimensions, if the window has a 3D border appearance
483 * this returns the area inside the border, The x and y are always zero
485 * @param aRect on return it holds the x. y, width and height of the client area of this widget
488 NS_IMETHOD GetClientBounds(nsIntRect &aRect) = 0;
491 * Get the foreground color for this widget
493 * @return this widget's foreground color
496 virtual nscolor GetForegroundColor(void) = 0;
499 * Set the foreground color for this widget
501 * @param aColor the new foreground color
505 NS_IMETHOD SetForegroundColor(const nscolor &aColor) = 0;
508 * Get the background color for this widget
510 * @return this widget's background color
514 virtual nscolor GetBackgroundColor(void) = 0;
517 * Set the background color for this widget
519 * @param aColor the new background color
523 NS_IMETHOD SetBackgroundColor(const nscolor &aColor) = 0;
526 * Get the cursor for this widget.
528 * @return this widget's cursor.
531 virtual nsCursor GetCursor(void) = 0;
534 * Set the cursor for this widget
536 * @param aCursor the new cursor for this widget
539 NS_IMETHOD SetCursor(nsCursor aCursor) = 0;
542 * Sets an image as the cursor for this widget.
544 * @param aCursor the cursor to set
545 * @param aX the X coordinate of the hotspot (from left).
546 * @param aY the Y coordinate of the hotspot (from top).
547 * @retval NS_ERROR_NOT_IMPLEMENTED if setting images as cursors is not
548 * supported
550 NS_IMETHOD SetCursor(imgIContainer* aCursor,
551 PRUint32 aHotspotX, PRUint32 aHotspotY) = 0;
553 /**
554 * Get the window type of this widget
556 * @param aWindowType the window type of the widget
558 NS_IMETHOD GetWindowType(nsWindowType& aWindowType) = 0;
561 * Set the transparency mode of the top-level window containing this widget.
562 * So, e.g., if you call this on the widget for an IFRAME, the top level
563 * browser window containing the IFRAME actually gets set. Be careful.
565 * This can fail if the platform doesn't support
566 * transparency/glass. By default widgets are not
567 * transparent. This will also fail if the toplevel window is not
568 * a Mozilla window, e.g., if the widget is in an embedded
569 * context.
571 * After transparency/glass has been enabled, the initial alpha channel
572 * value for all pixels is 1, i.e., opaque.
573 * If the window is resized then the alpha channel values for
574 * all pixels are reset to 1.
575 * Pixel RGB color values are already premultiplied with alpha channel values.
577 virtual void SetTransparencyMode(nsTransparencyMode aMode) = 0;
580 * Get the transparency mode of the top-level window that contains this
581 * widget.
583 virtual nsTransparencyMode GetTransparencyMode() = 0;
586 * This represents a command to set the bounds and clip region of
587 * a child widget.
589 struct Configuration {
590 nsIWidget* mChild;
591 nsIntRect mBounds;
592 nsTArray<nsIntRect> mClipRegion;
596 * Sets the clip region of each mChild (which must actually be a child
597 * of this widget) to the union of the pixel rects given in
598 * mClipRegion, all relative to the top-left of the child
599 * widget. Clip regions are not implemented on all platforms and only
600 * need to actually work for children that are plugins.
602 * Also sets the bounds of each child to mBounds.
604 * This will invalidate areas of the children that have changed, but
605 * does not need to invalidate any part of this widget.
607 virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
610 * Appends to aRects the rectangles constituting this widget's clip
611 * region. If this widget is not clipped, appends a single rectangle
612 * (0, 0, bounds.width, bounds.height).
614 virtual void GetWindowClipRegion(nsTArray<nsIntRect>* aRects) = 0;
617 * Set the shadow style of the window.
619 * Ignored on child widgets and on non-Mac platforms.
621 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle) = 0;
624 * On Mac OS X, this method shows or hides the pill button in the titlebar
625 * that's used to collapse the toolbar.
627 * Ignored on child widgets and on non-Mac platforms.
629 virtual void SetShowsToolbarButton(PRBool aShow) = 0;
631 /**
632 * Hide window chrome (borders, buttons) for this widget.
635 NS_IMETHOD HideWindowChrome(PRBool aShouldHide) = 0;
638 * Put the toplevel window into or out of fullscreen mode.
641 NS_IMETHOD MakeFullScreen(PRBool aFullScreen) = 0;
644 * Invalidate a specified rect for a widget and repaints it.
646 * @param aIsSynchronouse PR_TRUE then repaint synchronously. If PR_FALSE repaint later.
647 * @see #Update()
650 NS_IMETHOD Invalidate(const nsIntRect & aRect, PRBool aIsSynchronous) = 0;
653 * Force a synchronous repaint of the window if there are dirty rects.
655 * @see Invalidate()
658 NS_IMETHOD Update() = 0;
661 * Return the widget's toolkit
663 * An AddRef has NOT been done for the caller.
665 * @return the toolkit this widget was created in. See nsToolkit.
668 virtual nsIToolkit* GetToolkit() = 0;
671 * Scroll a set of rectangles in this widget and (as simultaneously as
672 * possible) modify the specified child widgets.
674 * This will invalidate areas of the children that have changed, unless
675 * they have just moved by the scroll amount, but does not need to
676 * invalidate any part of this widget, except where the scroll
677 * operation fails to blit because part of the window is unavailable
678 * (e.g. partially offscreen).
680 * The caller guarantees that the rectangles in aDestRects are
681 * non-intersecting.
683 * @param aDelta amount to scroll (device pixels)
684 * @param aDestRects rectangles to copy into
685 * (device pixels relative to this widget)
686 * @param aReconfigureChildren commands to set the bounds and clip
687 * region of a subset of the children of this widget; these should
688 * be performed simultaneously with the scrolling, as far as possible,
689 * to avoid visual artifacts.
691 virtual void Scroll(const nsIntPoint& aDelta,
692 const nsTArray<nsIntRect>& aDestRects,
693 const nsTArray<Configuration>& aReconfigureChildren) = 0;
695 /**
696 * Internal methods
699 //@{
700 virtual void AddChild(nsIWidget* aChild) = 0;
701 virtual void RemoveChild(nsIWidget* aChild) = 0;
702 virtual void* GetNativeData(PRUint32 aDataType) = 0;
703 virtual void FreeNativeData(void * data, PRUint32 aDataType) = 0;//~~~
704 virtual nsIRenderingContext* GetRenderingContext() = 0;
706 // GetDeviceContext returns a weak pointer to this widget's device context
707 virtual nsIDeviceContext* GetDeviceContext() = 0;
709 //@}
712 * Set the widget's title.
713 * Must be called after Create.
715 * @param aTitle string displayed as the title of the widget
718 NS_IMETHOD SetTitle(const nsAString& aTitle) = 0;
721 * Set the widget's icon.
722 * Must be called after Create.
724 * @param anIconSpec string specifying the icon to use; convention is to pass
725 * a resource: URL from which a platform-dependent resource
726 * file name will be constructed
729 NS_IMETHOD SetIcon(const nsAString& anIconSpec) = 0;
732 * Return this widget's origin in screen coordinates.
734 * @return screen coordinates stored in the x,y members
737 virtual nsIntPoint WidgetToScreenOffset() = 0;
740 * Dispatches an event to the widget
743 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) = 0;
746 * Enables the dropping of files to a widget (XXX this is temporary)
749 NS_IMETHOD EnableDragDrop(PRBool aEnable) = 0;
752 * Enables/Disables system mouse capture.
753 * @param aCapture PR_TRUE enables mouse capture, PR_FALSE disables mouse capture
756 NS_IMETHOD CaptureMouse(PRBool aCapture) = 0;
759 * Classify the window for the window manager. Mostly for X11.
761 NS_IMETHOD SetWindowClass(const nsAString& xulWinType) = 0;
764 * Enables/Disables system capture of any and all events that would cause a
765 * dropdown to be rolled up, This method ignores the aConsumeRollupEvent
766 * parameter when aDoCapture is FALSE
767 * @param aDoCapture PR_TRUE enables capture, PR_FALSE disables capture
768 * @param aConsumeRollupEvent PR_TRUE consumes the rollup event, PR_FALSE dispatches rollup event
771 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, nsIMenuRollup * aMenuRollup,
772 PRBool aDoCapture, PRBool aConsumeRollupEvent) = 0;
775 * Bring this window to the user's attention. This is intended to be a more
776 * gentle notification than popping the window to the top or putting up an
777 * alert. See, for example, Win32 FlashWindow or the NotificationManager on
778 * the Mac. The notification should be suppressed if the window is already
779 * in the foreground and should be dismissed when the user brings this window
780 * to the foreground.
781 * @param aCycleCount Maximum number of times to animate the window per system
782 * conventions. If set to -1, cycles indefinitely until
783 * window is brought into the foreground.
785 NS_IMETHOD GetAttention(PRInt32 aCycleCount) = 0;
788 * Ask whether there user input events pending. All input events are
789 * included, including those not targeted at this nsIwidget instance.
791 virtual PRBool HasPendingInputEvent() = 0;
794 * Called when when we need to begin secure keyboard input, such as when a password field
795 * gets focus.
797 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
798 * for one widget at a time.
800 NS_IMETHOD BeginSecureKeyboardInput() = 0;
803 * Called when when we need to end secure keyboard input, such as when a password field
804 * loses focus.
806 * NOTE: Calls to this method may not be nested and you can only enable secure keyboard input
807 * for one widget at a time.
809 NS_IMETHOD EndSecureKeyboardInput() = 0;
812 * Set the background color of the window titlebar for this widget. On Mac,
813 * for example, this will remove the grey gradient and bottom border and
814 * instead show a single, solid color.
816 * Ignored on any platform that does not support it. Ignored by widgets that
817 * do not represent windows.
819 * @param aColor The color to set the title bar background to. Alpha values
820 * other than fully transparent (0) are respected if possible
821 * on the platform. An alpha of 0 will cause the window to
822 * draw with the default style for the platform.
824 * @param aActive Whether the color should be applied to active or inactive
825 * windows.
827 NS_IMETHOD SetWindowTitlebarColor(nscolor aColor, PRBool aActive) = 0;
830 * If set to true, the window will draw its contents into the titlebar
831 * instead of below it.
833 * Ignored on any platform that does not support it. Ignored by widgets that
834 * do not represent windows.
835 * May result in a resize event, so should only be called from places where
836 * reflow and painting is allowed.
838 * @param aState Whether drawing into the titlebar should be activated.
840 virtual void SetDrawsInTitlebar(PRBool aState) = 0;
843 * Determine whether the widget shows a resize widget. If it does,
844 * aResizerRect returns the resizer's rect.
846 * Returns false on any platform that does not support it.
848 * @param aResizerRect The resizer's rect in device pixels.
849 * @return Whether a resize widget is shown.
851 virtual PRBool ShowsResizeIndicator(nsIntRect* aResizerRect) = 0;
854 * Get the Thebes surface associated with this widget.
856 virtual gfxASurface *GetThebesSurface() = 0;
859 * Return the popup that was last rolled up, or null if there isn't one.
861 virtual nsIContent* GetLastRollup() = 0;
864 * Begin a window resizing drag, based on the event passed in.
866 NS_IMETHOD BeginResizeDrag(nsGUIEvent* aEvent, PRInt32 aHorizontal, PRInt32 aVertical) = 0;
868 enum Modifiers {
869 CAPS_LOCK = 0x01, // when CapsLock is active
870 NUM_LOCK = 0x02, // when NumLock is active
871 SHIFT_L = 0x0100,
872 SHIFT_R = 0x0200,
873 CTRL_L = 0x0400,
874 CTRL_R = 0x0800,
875 ALT_L = 0x1000, // includes Option
876 ALT_R = 0x2000,
877 COMMAND_L = 0x4000,
878 COMMAND_R = 0x8000,
879 HELP = 0x10000,
880 FUNCTION = 0x100000,
881 NUMERIC_KEY_PAD = 0x01000000 // when the key is coming from the keypad
884 * Utility method intended for testing. Dispatches native key events
885 * to this widget to simulate the press and release of a key.
886 * @param aNativeKeyboardLayout a *platform-specific* constant.
887 * On Mac, this is the resource ID for a 'uchr' or 'kchr' resource.
888 * On Windows, it is converted to a hex string and passed to
889 * LoadKeyboardLayout, see
890 * http://msdn.microsoft.com/en-us/library/ms646305(VS.85).aspx
891 * @param aNativeKeyCode a *platform-specific* keycode.
892 * On Windows, this is the virtual key code.
893 * @param aModifiers some combination of the above 'Modifiers' flags;
894 * not all flags will apply to all platforms. Mac ignores the _R
895 * modifiers. Windows ignores COMMAND, NUMERIC_KEY_PAD, HELP and
896 * FUNCTION.
897 * @param aCharacters characters that the OS would decide to generate
898 * from the event. On Windows, this is the charCode passed by
899 * WM_CHAR.
900 * @param aUnmodifiedCharacters characters that the OS would decide
901 * to generate from the event if modifier keys (other than shift)
902 * were assumed inactive. Needed on Mac, ignored on Windows.
903 * @return NS_ERROR_NOT_AVAILABLE to indicate that the keyboard
904 * layout is not supported and the event was not fired
906 virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
907 PRInt32 aNativeKeyCode,
908 PRUint32 aModifierFlags,
909 const nsAString& aCharacters,
910 const nsAString& aUnmodifiedCharacters) = 0;
913 * Utility method intended for testing. Dispatches native mouse events
914 * may even move the mouse cursor. On Mac the events are guaranteed to
915 * be sent to the window containing this widget, but on Windows they'll go
916 * to whatever's topmost on the screen at that position, so for
917 * cross-platform testing ensure that your window is at the top of the
918 * z-order.
919 * @param aPoint screen location of the mouse, in device
920 * pixels, with origin at the top left
921 * @param aNativeMessage *platform-specific* event type (e.g. on Mac,
922 * NSMouseMoved; on Windows, MOUSEEVENTF_MOVE, MOUSEEVENTF_LEFTDOWN etc)
923 * @param aModifierFlags *platform-specific* modifier flags (ignored
924 * on Windows)
926 virtual nsresult SynthesizeNativeMouseEvent(nsIntPoint aPoint,
927 PRUint32 aNativeMessage,
928 PRUint32 aModifierFlags) = 0;
931 * Activates a native menu item at the position specified by the index
932 * string. The index string is a string of positive integers separated
933 * by the "|" (pipe) character. The last integer in the string represents
934 * the item index in a submenu located using the integers preceeding it.
936 * Example: 1|0|4
937 * In this string, the first integer represents the top-level submenu
938 * in the native menu bar. Since the integer is 1, it is the second submeu
939 * in the native menu bar. Within that, the first item (index 0) is a
940 * submenu, and we want to activate the 5th item within that submenu.
942 virtual nsresult ActivateNativeMenuItemAt(const nsAString& indexString) = 0;
945 * This is used for native menu system testing.
947 * Updates a native menu at the position specified by the index string.
948 * The index string is a string of positive integers separated by the "|"
949 * (pipe) character.
951 * Example: 1|0|4
952 * In this string, the first integer represents the top-level submenu
953 * in the native menu bar. Since the integer is 1, it is the second submeu
954 * in the native menu bar. Within that, the first item (index 0) is a
955 * submenu, and we want to update submenu at index 4 within that submenu.
957 * If this is called with an empty string it forces a full reload of the
958 * menu system.
960 virtual nsresult ForceUpdateNativeMenuAt(const nsAString& indexString) = 0;
963 * Force Input Method Editor to commit the uncommitted input
965 NS_IMETHOD ResetInputState()=0;
968 * Following methods relates to IME 'Opened'/'Closed' state.
969 * 'Opened' means the user can input any character. I.e., users can input Japanese
970 * and other characters. The user can change the state to 'Closed'.
971 * 'Closed' means the user can input ASCII characters only. This is the same as a
972 * non-IME environment. The user can change the state to 'Opened'.
973 * For more information is here.
974 * http://bugzilla.mozilla.org/show_bug.cgi?id=16940#c48
978 * Set the state to 'Opened' or 'Closed'.
979 * If aState is TRUE, IME open state is set to 'Opened'.
980 * If aState is FALSE, set to 'Closed'.
982 NS_IMETHOD SetIMEOpenState(PRBool aState) = 0;
985 * Get IME is 'Opened' or 'Closed'.
986 * If IME is 'Opened', aState is set PR_TRUE.
987 * If IME is 'Closed', aState is set PR_FALSE.
989 NS_IMETHOD GetIMEOpenState(PRBool* aState) = 0;
992 * IME enabled states, the aState value of SetIMEEnabled/GetIMEEnabled
993 * should be one value of following values.
995 * WARNING: If you change these values, you also need to edit:
996 * nsIDOMWindowUtils.idl
997 * nsDOMWindowUtils::SetIMEEnabled
998 * nsContentUtils::GetWidgetStatusFromIMEStatus
1000 enum IMEStatus {
1002 * 'Disabled' means the user cannot use IME. So, the open state should be
1003 * 'closed' during 'disabled'.
1005 IME_STATUS_DISABLED = 0,
1007 * 'Enabled' means the user can use IME.
1009 IME_STATUS_ENABLED = 1,
1011 * 'Password' state is a special case for the password editors.
1012 * E.g., on mac, the password editors should disable the non-Roman
1013 * keyboard layouts at getting focus. Thus, the password editor may have
1014 * special rules on some platforms.
1016 IME_STATUS_PASSWORD = 2,
1018 * This state is used when a plugin is focused.
1019 * When a plug-in is focused content, we should send native events
1020 * directly. Because we don't process some native events, but they may
1021 * be needed by the plug-in.
1023 IME_STATUS_PLUGIN = 3
1027 * Set the state to 'Enabled' or 'Disabled' or 'Password'.
1029 NS_IMETHOD SetIMEEnabled(PRUint32 aState) = 0;
1032 * Get IME is 'Enabled' or 'Disabled' or 'Password'.
1034 NS_IMETHOD GetIMEEnabled(PRUint32* aState) = 0;
1037 * Destruct and don't commit the IME composition string.
1039 NS_IMETHOD CancelIMEComposition() = 0;
1042 * Get toggled key states.
1043 * aKeyCode should be NS_VK_CAPS_LOCK or NS_VK_NUM_LOCK or
1044 * NS_VK_SCROLL_LOCK.
1045 * aLEDState is the result for current LED state of the key.
1046 * If the LED is 'ON', it returns TRUE, otherwise, FALSE.
1047 * If the platform doesn't support the LED state (or we cannot get the
1048 * state), this method returns NS_ERROR_NOT_IMPLEMENTED.
1050 NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode, PRBool* aLEDState) = 0;
1053 * An editable node (i.e. input/textarea/design mode document)
1054 * is receiving or giving up focus
1055 * aFocus is true if node is receiving focus
1056 * aFocus is false if node is giving up focus (blur)
1058 * If this returns NS_ERROR_*, OnIMETextChange and OnIMESelectionChange
1059 * and OnIMEFocusChange(PR_FALSE) will be never called.
1061 NS_IMETHOD OnIMEFocusChange(PRBool aFocus) = 0;
1064 * Text content of the focused node has changed
1065 * aStart is the starting offset of the change
1066 * aOldEnd is the ending offset of the change
1067 * aNewEnd is the caret offset after the change
1069 NS_IMETHOD OnIMETextChange(PRUint32 aStart,
1070 PRUint32 aOldEnd,
1071 PRUint32 aNewEnd) = 0;
1074 * Selection has changed in the focused node
1076 NS_IMETHOD OnIMESelectionChange(void) = 0;
1079 * Call this method when a dialog is opened which has a default button.
1080 * The button's rectangle should be supplied in aButtonRect.
1082 NS_IMETHOD OnDefaultButtonLoaded(const nsIntRect &aButtonRect) = 0;
1085 * Compute the overridden system mouse scroll speed on the root content of
1086 * web pages. The widget may set the same value as aOriginalDelta. E.g.,
1087 * when the system scrolling settings were customized, widget can respect
1088 * the will of the user.
1090 * This is called only when the mouse wheel event scrolls the root content
1091 * of the web pages by line. In other words, this isn't called when the
1092 * mouse wheel event is used for zoom, page scroll and other special
1093 * actions. And also this isn't called when the user doesn't use the
1094 * system wheel speed settings.
1096 * @param aOriginalDelta The delta value of the current mouse wheel
1097 * scrolling event.
1098 * @param aIsHorizontal If TRUE, the scrolling direction is horizontal.
1099 * Otherwise, it's vertical.
1100 * @param aOverriddenDelta The overridden mouse scrolling speed. This value
1101 * may be same as aOriginalDelta.
1103 NS_IMETHOD OverrideSystemMouseScrollSpeed(PRInt32 aOriginalDelta,
1104 PRBool aIsHorizontal,
1105 PRInt32 &aOverriddenDelta) = 0;
1107 protected:
1108 // keep the list of children. We also keep track of our siblings.
1109 // The ownership model is as follows: parent holds a strong ref to
1110 // the first element of the list, and each element holds a strong
1111 // ref to the next element in the list. The prevsibling and
1112 // lastchild pointers are weak, which is fine as long as they are
1113 // maintained properly.
1114 nsCOMPtr<nsIWidget> mFirstChild;
1115 nsIWidget* mLastChild;
1116 nsCOMPtr<nsIWidget> mNextSibling;
1117 nsIWidget* mPrevSibling;
1120 NS_DEFINE_STATIC_IID_ACCESSOR(nsIWidget, NS_IWIDGET_IID)
1122 #endif // nsIWidget_h__