nsIDOMWindowUtils

This article is in need of a technical review.

This interface is a DOM utility interface that provides useful DOM methods and attributes.
1.0
28
Introduced
Gecko 1.8
Inherits from: nsISupports Last changed in Gecko 17.0 (Firefox 17.0 / Thunderbird 17.0 / SeaMonkey 2.14)

Implemented by: nsIDOMWindow. To get this interface, use:

var domWindowUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                     .getInterface(Components.interfaces.nsIDOMWindowUtils);

Method overview

void activateNativeMenuItemAt(in AString indexString);
void clearMozAfterPaintEvents();
PRUint32 compareCanvases(in nsIDOMHTMLCanvasElement aCanvas1, in nsIDOMHTMLCanvasElement aCanvas2, out unsigned long aMaxDifference);
double computeAnimationDistance(in nsIDOMElement element, in AString property, in AString value1, in AString value2);
void disableNonTestMouseEvents(in boolean aDisable);
boolean dispatchDOMEventViaPresShell(in nsIDOMNode aTarget, in nsIDOMEvent aEvent, in boolean aTrusted);
nsIDOMElement elementFromPoint(in float aX, in float aY, in boolean aIgnoreRootScrollFrame, in boolean aFlushLayout);
void enterModalState();
nsIDOMElement findElementWithViewId(in nsViewID aId); Mobile Only in Gecko 2.0
void focus(in nsIDOMElement aElement);
void forceUpdateNativeMenuAt(in AString indexString);
void garbageCollect([optional] in nsICycleCollectorListener aListener);
short getCursorType();
AString getDocumentMetadata(in AString aName);
nsIDOMWindow getOuterWindowWithId(in unsigned long long aOuterWindowID);
long getPCCountScriptCount();
AString getPCCountScriptSummary(in long aScript);
AString getPCCountScriptContents(in long aScript);
void getScrollXY(in boolean aFlushLayout, out long aScrollX, out long aScrollY);
AString getVisitedDependentComputedStyle(in nsIDOMElement aElement, in AString aPseudoElement, in AString aPropertyName);
boolean isInModalState();
void leaveModalState();
nsIDOMNodeList nodesFromRect(in float aX, in float aY, in float aTopSize, in float aRightSize, in float aBottomSize, in float aLeftSize, in boolean aIgnoreRootScrollFrame, in boolean aFlushLayout);
void processUpdates();  Obsolete since Gecko 13.0
void purgePCCounts();
unsigned long redraw([optional] in unsigned long aCount);
void RenderDocument(in nsConstRect aRect, in PRUint32 aFlags, in nscolor aBackgroundColor, in gfxContext aThebesContext); Native code only!
void resumeTimeouts();
void sendCompositionEvent(in AString aType);
void sendContentCommandEvent(in AString aType, [optional] in nsITransferable aTransferable);
void getClassName(in object aObj);
boolean sendKeyEvent(in AString aType, in long aKeyCode, in long aCharCode, in long aModifiers, [optional] in boolean aPreventDefault); Obsolete since Gecko 15.0
boolean sendKeyEvent(in AString aType, in long aKeyCode, in long aCharCode, in long aModifiers, [optional] in unsigned long aAdditionalFlags);
void sendMouseEvent(in AString aType, in float aX, in float aY, in long aButton, in long aClickCount, in long aModifiers, [optional] in boolean aIgnoreRootScrollFrame);
void sendMouseEventToWindow(in AString aType, in float aX, in float aY, in long aButton, in long aClickCount, in long aModifiers, [optional] in boolean aIgnoreRootScrollFrame);
void sendMouseScrollEvent(in AString aType, in float aX, in float aY, in long aButton, in long aScrollFlags, in long aDelta, in long aModifiers); Obsolete since Gecko 17.0
void sendWheelEvent(in float aX, in float aY, in double aDeltaX, in double aDeltaY, in double aDeltaZ, in unsigned long aDeltaMode, in long aModifiers, in long aLineOrPageDeltaX, in long aLineOrPageDeltaY, in unsigned long aOptions);
void sendNativeKeyEvent(in long aNativeKeyboardLayout, in long aNativeKeyCode, in long aModifierFlags, in AString aCharacters, in AString aUnmodifiedCharacters);
void sendNativeMouseEvent(in long aScreenX, in long aScreenY, in long aNativeMessage, in long aModifierFlags, in nsIDOMElement aElement);
nsIQueryContentEventResult sendQueryContentEvent(in unsigned long aType, in unsigned long aOffset, in unsigned long aLength, in long aX, in long aY);
boolean sendSelectionSetEvent(in unsigned long aOffset, in unsigned long aLength, in boolean aReverse);
void sendSimpleGestureEvent(in AString aType, in float aX, in float aY, in unsigned long aDirection, in double aDelta, in long aModifiers);
void sendTextEvent(in AString aCompositionString, in long aFirstClauseLength, in unsigned long aFirstClauseAttr, in long aSecondClauseLength, in unsigned long aSecondClauseAttr, in long aThirdClauseLength, in unsigned long aThirdClauseAttr, in long aCaretStart, in long aCaretLength);
boolean sendTouchEvent(in AString aType, [array, size_is(count)] in PRUint32 aIdentifiers, [array, size_is(count)] in PRInt32 aXs, [array, size_is(count)] in PRInt32 aYs, [array, size_is(count)] in PRUint32 aRxs, [array, size_is(count)] in PRUint32 aRys, [array, size_is(count)] in float aRotationAngles, [array, size_is(count)] in float aForces, in PRUint32 count, in long aModifiers, [optional] in boolean aIgnoreRootScrollFrame);
void setCSSViewport(in float aWidthPx, in float aHeightPx);
void setDisplayPort(in float aXPx, in float aYPx, in float aWidthPx, in float aHeightPx);
void setResolution(in float aXResolution, in float aYResolution);
void startPCCountProfiling();
void stopPCCountProfiling();
void suppressEventHandling(in boolean aSuppress);
void suspendTimeouts();
nsIDOMFile wrapDOMFile(nsIFile aFile);

Attributes

Attribute Type Description
currentInnerWindowID unsigned long long

The ID of the window's current inner window. Read only.

Exceptions thrown
NS_ERROR_NOT_AVAILABLE
There is no current inner window
displayDPI float The DPI of the display. Read only.
docCharsetIsForced boolean Whether the charset of the window's current document has been forced by the user. Cannot be accessed from unprivileged context (not content-accessible) Read only.
focusedInputType string The type of the currently-focused HTML <input> element, if one is focused. Mobile Only in Gecko 2.0
imageAnimationMode unsigned short Returns the image animation mode of the window. The attribute's value must be one of the animationMode values from imgIContainer.
IMEIsOpen boolean Returns the IME open state. True if it's open, otherwise false. This attribute only works when IMEStatus is IME_STATUS_ENABLED. Read only.
IMEStatus unsigned long Returns the current IME status. Values correspond to the IME_STATUS_* constants defined below. Read only.
isMozAfterPaintPending boolean Returns true if a MozAfterPaint event has been queued but not yet fired. Read only.
layerManagerType AString What type of layer manager the widget associated with this window is using. "Basic" is unaccelerated; other types are accelerated. Throws an error if there is no widget associated with this window. Read only.
outerWindowID unsigned long long The ID of the window's outer window. Read only.
paintingSuppressed boolean

true if painting is currently suppressed for this window; otherwise false. Read only.

This is used on mobile, for example, to prevent attempts to render content until enough of the page has been loaded to avoid content bouncing around excessively as more content is loaded.

screenPixelsPerCSSPixel float Returns the number of screen pixels per CSS pixel. Read only.

Constants

Constant Value Description
MODIFIER_ALT 0x0001 getModifierState("Alt") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_CONTROL 0x0002 getModifierState("Control") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_SHIFT 0x0004 getModifierState("Shift") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_META 0x0008 getModifierState("Meta") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_ALTGRAPH 0x0010 getModifierState("AltGraph") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_CAPSLOCK 0x0020 getModifierState("CapsLock") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_FN 0x0040 getModifierState("Fn") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_NUMLOCK 0x0080 getModifierState("NumLock") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_SCROLL 0x0100 getModifierState("Scroll") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_SYMBOLLOCK 0x0200 getModifierState("SymbolLock") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
MODIFIER_WIN 0x0400 getModifierState("Win") of the send event will return true if this is specified for aModifiers of send*Event() except sendNative*Event().
KEY_FLAG_PREVENT_DEFAULT 0x0001 getDefaultPrevented() returns true if this is specified to aAdditionalFlags of sendKeyEvent().
KEY_FLAG_LOCATION_STANDARD 0x0010 location attrubute of the sending key event by sendKeyEvent() returns KeyboardEvent.DOM_KEY_LOCATION_STANDARD if this is specified to the aAdditionalFlags.
KEY_FLAG_LOCATION_LEFT 0x0020 location attrubute of the sending key event by sendKeyEvent() returns KeyboardEvent.DOM_KEY_LOCATION_LEFT if this is specified to the aAdditionalFlags.
KEY_FLAG_LOCATION_RIGHT 0x0040 location attrubute of the sending key event by sendKeyEvent() returns KeyboardEvent.DOM_KEY_LOCATION_RIGHT if this is specified to the aAdditionalFlags.
KEY_FLAG_LOCATION_NUMPAD 0x0080 location attrubute of the sending key event by sendKeyEvent() returns KeyboardEvent.DOM_KEY_LOCATION_NUMPAD if this is specified to the aAdditionalFlags.
KEY_FLAG_LOCATION_MOBILE 0x0100 location attrubute of the sending key event by sendKeyEvent() returns KeyboardEvent.DOM_KEY_LOCATION_MOBILE if this is specified to the aAdditionalFlags.
KEY_FLAG_LOCATION_JOYSTICK 0x0200 location attrubute of the sending key event by sendKeyEvent() returns KeyboardEvent.DOM_KEY_LOCATION_JOYSTICK if this is specified to the aAdditionalFlags.
WHEEL_EVENT_CAUSED_BY_PIXEL_ONLEY_DEVICE 0x0001 Used for aOptions of sendWheelEvent(). If this is set, the synthesized wheel event emulates wheel events come from some devices without the line scroll amount by the event. It means that the aLineOrPageDeltaX and aLineOrPageDeltaY don't have proper values.
WHEEL_EVENT_CAUSED_BY_MOMENTUM 0x0002 Used for aOptions of sendWheelEvent(). If this is set, the synthesized wheel event emulates momentum scroll event.
WHEEL_EVENT_CUSTOMIZED_BY_USER_PREFS 0x0004 Used for aOptions of sendWheelEvent(). If this is set, the synthesized wheel event emulates an event whose delta values are computed from user prefs in widget level.
IME_STATUS_DISABLED 0 Users cannot use IME at all. This state is not the same as ime-mode: disabled.
IME_STATUS_ENABLED 1 Users can use all functions of IME. This state is same as ime-mode: normal.
IME_STATUS_PASSWORD 2 Users cannot use most IME functions. On GTK2, users can use "Simple IME" which only supports dead key inputting. This state is the same as ime-mode: password.
IME_STATUS_PLUGIN 3 Plug-in has focus. At this time we should not attempt to set the IME state.
COMPOSITION_ATTR_RAWINPUT 0x02

Synthesize a text event to the window.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

Currently, this method doesn't support 4 or more clauses composition string.
COMPOSITION_ATTR_SELECTEDRAWTEXT 0x03
COMPOSITION_ATTR_CONVERTEDTEXT 0x04
COMPOSITION_ATTR_SELECTEDCONVERTEDTEXT 0x05
QUERY_SELECTED_TEXT 3200 QUERY_SELECTED_TEXT queries the first selection range's information.
QUERY_TEXT_CONTENT 3201 QUERY_TEXT_CONTENT queries the text at the specified range.
QUERY_CARET_RECT 3203 QUERY_CARET_RECT queries the (collapsed) caret rect of the offset. If the actual caret is there at the specified offset, this returns the actual caret rect. Otherwise, this guesses the caret rect from the metrics of the text.
QUERY_TEXT_RECT 3204 QUERY_TEXT_RECT queries the specified text's rect.
QUERY_EDITOR_RECT 3205 QUERY_TEXT_RECT queries the focused editor's rect.
QUERY_CHARACTER_AT_POINT 3208

QUERY_CHARACTER_AT_POINT queries the character information at the specified point. The point is offset in the window.

Note: If there are some panels at the point, this method send the query event to the panel's widget automatically.

Methods

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

activateNativeMenuItemAt()

See nsIWidget.ActivateNativeMenuItemAt().

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void activateNativeMenuItemAt(
  in AString indexString
);
Parameters
indexString
 

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

clearMozAfterPaintEvents()

void clearMozAfterPaintEvents();
Parameters

None.

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

compareCanvases()

Compare the two canvases, returning the number of differing pixels and the maximum difference in a channel. This will throw an error if the dimensions of the two canvases are different.

This method requires UniversalXPConnect privileges.

PRUint32 compareCanvases(
  in nsIDOMHTMLCanvasElement aCanvas1,
  in nsIDOMHTMLCanvasElement aCanvas2,
  out unsigned long aMaxDifference
);
Parameters
aCanvas1
 
aCanvas2
 
aMaxDifference
 
Return value

 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

computeAnimationDistance()

Method for testing nsStyleAnimation::ComputeDistance.

Returns the distance between the two values as reported by nsStyleAnimation::ComputeDistance for the given element and property.

double computeAnimationDistance(
  in nsIDOMElement element,
  in AString property,
  in AString value1,
  in AString value2
);
Parameters
element
 
property
 
value1
 
value2
 
Return value

 

Requires Gecko 1.9.2 (Firefox 3.6 / Thunderbird 3.1 / Fennec 1.0)

disableNonTestMouseEvents()

Disable or enable non synthetic test mouse events on *all* windows.

Cannot be accessed from unprivileged context (not content-accessible). Will throw a DOM security error if called without UniversalXPConnect privileges.

void disableNonTestMouseEvents(
  in boolean aDisable
);
Parameters
aDisable
If true, disable all non synthetic test mouse events on all windows. Otherwise, enable them.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

dispatchDOMEventViaPresShell()

Dispatches aEvent via the nsIPresShell object of the window's document. The event is dispatched to aTarget, which should be an object which implements nsIContent interface (#element, #text, etc).

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

Note: Event handlers won't get aEvent as parameter, but a similar event. Also, aEvent should not be reused.

boolean dispatchDOMEventViaPresShell(
  in nsIDOMNode aTarget,
  in nsIDOMEvent aEvent,
  in boolean aTrusted
);
Parameters
aTarget
 
aEvent
 
aTrusted
 
Return value

boolean to show if the event was successful

 

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

elementFromPoint()

Retrieve the element at point aX, aY in the window's document.

nsIDOMElement elementFromPoint(
  in float aX,
  in float aY,
  in boolean aIgnoreRootScrollFrame,
  in boolean aFlushLayout
);
Parameters
aX
 
aY
 
aIgnoreRootScrollFrame
Whether or not to ignore the root scroll frame when retrieving the element. If false, this method returns null for coordinates outside of the viewport.
aFlushLayout
Flushes layout if true. Otherwise, no flush occurs.
Return value

 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

enterModalState()

Put the window into a state where scripts are frozen and events suppressed, for use when the window has launched a modal prompt.

void enterModalState();
Parameters

None.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

findElementWithViewId()

Mobile Only in Gecko 2.0
Available only in Firefox Mobile as of Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

Given a view ID from the compositor process, return the corresponding DOM element object.

nsIDOMElement findElementWithViewId(
  in nsViewID aId
); 
Parameters
aId
The ID of the view for which to retrieve the corresponding nsIDOMElement object.
Return value

The nsIDOMElement object for the HTML element drawn by the specified view ID.

Note: For scrollable frames containing documents (that is, <frame> and <iframe>), the enclosed document's root element is returned.

Requires Gecko 1.9 (Firefox 3)

focus()

Focus the element aElement. The element should be in the same document that the window is displaying. Pass null to blur the element, if any, that currently has focus, and focus the document.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

Do not use this method. Just use element.focus if available or nsIFocusManager.SetFocus() instead.

void focus(
  in nsIDOMElement aElement
);
Parameters
aElement
The element to focus.

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

forceUpdateNativeMenuAt()

See nsIWidget.ForceUpdateNativeMenuAt().

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void forceUpdateNativeMenuAt(
  in AString indexString
);
Parameters
indexString
 

Requires Gecko 1.9 (Firefox 3)

garbageCollect()

Force a garbage collection followed by a cycle collection.

Will throw a DOM security error if called without UniversalXPConnect privileges in non-debug builds. Available to all callers in debug builds.

void garbageCollect(
  in nsICycleCollectorListener aListener Optional 
);
Parameters
aListener Optional
Listener that receives information about the CC graph (see @mozilla.org/cycle-collector-logger;1 for a logger component)

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

getCursorType()

Get current cursor type from this window.

short getCursorType();
Parameters

None.

Return value

The current value of nsCursor.

getDocumentMetadata()

Function to get metadata associated with the window's current document.

Will throw a DOM security error if called without UniversalXPConnect privileges.

AString getDocumentMetadata(
  in AString aName
);
Parameters
aName
The name of the metadata. This should be all lowercase.
Return value

The value of the metadata, or the empty string if it's not set.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

getOuterWindowWithId()

Returns the nsIDOMWindow matching the specified outer window's ID.

nsIDOMWindow getOuterWindowWithId(
  in unsigned long long aOuterWindowID
);
Parameters
aOuterWindowID
The ID of the outer window for which to return the window.
Return value

An nsIDOMWindow object representing the outer window with the specified ID; if no matching window is found, returns null.


Requires Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)

getPCCountScriptCount()

Returns the number of scripts which profile information was constructed for.  This should be used after a call to stopPCCountProfiling().

long getPCCountScriptCount();
Parameters

None.

Requires Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)

getPCCountScriptSummary()

Returns a summary of the profile information for a script.  This should be used after a call to stopPCCountProfiling().

AString getPCCountScriptSummary(in long aScript);
Parameters
aScript
Index of the profiled script to get the profile summary for.  Should be less than getPCCountScriptCount().
Return value

A JSON string summarizing the information profiled about the script.  This includes counts for how often and in what ways the script executed.  The structure of the JSON is unspecified and may vary between versions of Firefox.

Requires Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)

getPCCountScriptContents()

Returns detailed information about the profile information for a script.  This should be used after a call to stopPCCountProfiling().

AString getPCCountScriptContents(in long script);
Parameters
aScript
Index of the profiled script to get the profile contents for.  Should be less than getPCCountScriptCount().
Return value

A JSON string with all profile information accumulated for the script.  This includes the text of the script and details about its internal representation in SpiderMonkey, and counts for how often and in what ways each operation in the script executed.  The structure of the JSON is unspecified and may vary between versions of Firefox.

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

getScrollXY()

Returns the scroll position of the window's currently loaded document.

void getScrollXY(
  in boolean aFlushLayout,
  out long aScrollX,
  out long aScrollY
);
Parameters
aFlushLayout
Flushes layout if true. Otherwise, no flush occurs.
aScrollX
 
aScrollY
 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

getVisitedDependentComputedStyle()

Perform the equivalent of: window.getComputedStyle(aElement, aPseudoElement). getPropertyValue(aPropertyName) except that, when the link whose presence in history is allowed to influence aElement's style is visited, get the value the property would have if allowed all properties to change as a result of :visited selectors (except for cases where getComputedStyle uses data from the frame).

This is easier to implement than adding our property restrictions to this API, and is sufficient for the present testing requirements (which are essentially testing 'color').

AString getVisitedDependentComputedStyle(
  in nsIDOMElement aElement,
  in AString aPseudoElement,
  in AString aPropertyName
);
Parameters
aElement
 
aPseudoElement
 
aPropertyName
 
Return value

 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

isInModalState()

Is the window is in a modal state? [See enterModalState()]

boolean isInModalState();
Parameters

None.

Return value

 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

leaveModalState()

Resume normal window state, where scripts can run and events are delivered.

void leaveModalState();
Parameters

None.

Requires Gecko 1.9.2.5 (Firefox 3.6.5)

nodesFromRect()

Returns an nsIDOMNodeList containing all nodes that intersect a specified rectangle within the window's document. The rectangle is specified using a central point and a distance to expand in all four cardinal directions. This is used to locate nodes that are within some number of pixels of a point; for example, you can use this to find candidate target nodes when the user taps on a touch screen.

nsIDOMNodeList nodesFromRect(
  in float aX,
  in float aY,
  in float aTopSize,
  in float aRightSize,
  in float aBottomSize,
  in float aLeftSize,
  in boolean aIgnoreRootScrollFrame,
  in boolean aFlushLayout
);
Parameters
aX
The X coordinate of the point at which to begin constructing the rectangle, in CSS pixels.
aY
The Y coordinate of the point at which to begin constructing the rectangle, in CSS pixels.
aTopSize
The number of CSS pixels to expand the rectangle upward from the point (aX, aY).
aRightSize
The number of CSS pixels to expand the rectangle to the right from the point (aX, aY).
aBottomSize
The number of CSS pixels to expand the rectangle downward from the point (aX, aY).
aLeftSize
The number of CSS pixels to expand the rectangle to the left from the point (aX, aY).
aIgnoreRootScrollFrame
Whether or not to ignore the root scroll frame when retrieving the nodes. If this is false, this method will return null for coordinates outside the viewport.
aFlushLayout
If true, layout is flushed before hit testing begins. This ensures that the node list is current. If you don't need an absolutely up to date node list, you can set this to false.
Return value

An nsIDOMNodeList referencing all the nodes that intersect the specified rectangle.

Obsolete since Gecko 13.0 (Firefox 13.0 / Thunderbird 13.0 / SeaMonkey 2.10)

processUpdates()

Force processing of any queued paints.

void processUpdates();
Parameters

None.

Requires Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)

purgePCCounts()

Purge all accumulated profile information for scripts which was generated after a call to stopPCCountProfiling().

void purgePCCounts();
Parameters

None.

Requires Gecko 1.9 (Firefox 3)

redraw()

Force an immediate redraw of this window. The parameter specifies the number of times to redraw, and the return value is the length, in milliseconds, that the redraws took. If aCount is not specified or is 0, it is taken to be 1.

unsigned long redraw(
  in unsigned long aCount Optional 
);
Parameters
aCount Optional
 
Return value

 

Native code only!

RenderDocument

void RenderDocument(
  in nsConstRect aRect,
  in PRUint32 aFlags,
  in nscolor aBackgroundColor,
  in gfxContext aThebesContext
);
Parameters
aRect
 
aFlags
 
aBackgroundColor
 
aThebesContext
 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

resumeTimeouts()

Resumes timeouts on this window and its descendant windows.

void resumeTimeouts();
Parameters

None.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendCompositionEvent()

Synthesize a composition event to the window.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void sendCompositionEvent(
  in AString aType
);
Parameters
aType
The event type: "compositionstart" or "compositionend".

Requires Gecko 1.9.3 (Firefox 4) <- update this template reference to Gecko 2!

getClassName()

Returns the real classname (possibly of the mostly-transparent security wrapper) of aObj.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendContentCommandEvent()

Generate a content command event.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void sendContentCommandEvent(
  in AString aType,
  in nsITransferable aTransferable Optional
);
Parameters
aType
Type of command content event to send. Can be one of "cut", "copy", "paste", "delete", "undo", "redo", or "pasteTransferable".
aTransferable Optional
An instance of nsITransferable when aType is "pasteTransferable"

Requires Gecko 1.9 (Firefox 3)

sendKeyEvent()

Synthesize a key event to the window. The event types supported are: keydown, keyup, keypress.

Key events generally end up being sent to the focused node.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

boolean sendKeyEvent(
  in AString aType,
  in long aKeyCode,
  in long aCharCode,
  in long aModifiers,
  in unsigned long aAdditionalFlags Optional
); 
boolean sendKeyEvent(
  in AString aType,
  in long aKeyCode,
  in long aCharCode,
  in long aModifiers,
  in boolean aPreventDefault Optional 
); Obsolete since Gecko 15.0
Parameters
aType
Event type.
aKeyCode
Key code.
aCharCode
Character code.
aModifiers
Modifiers pressed.
Using constants defined in nsIDOMNSEvent. Obsolete since Gecko 15.0
Using constants defined as MODIFIER_*.
aPreventDefault Optional Obsolete since Gecko 15.0
If true, preventDefault() the event before dispatch.
aAdditionalFlags Optional
0 or KEY_FLAG_PREVENT_DEFAULT and/or one of KEY_FLAG_LOCATION_*.
If KEY_FLAG_PREVENT_DEFAULT is specified, the dispatching key event's default is prevented.
If KEY_FLAG_LOCATION_* isn't set, an appropriate location is automatically computed from aKeyCode. If two or more KEY_FLAG_LOCATION_* is specified, this method will throw an exception.
Return value

false if the event had preventDefault() called on it, true otherwise. In other words, true if and only if the default action was taken.

Requires Gecko 1.9 (Firefox 3)

sendMouseEvent()

Synthesize a mouse event. The event types supported are: mousedown, mouseup, mousemove, mouseover, mouseout, contextmenu.

Events are sent in coordinates offset by aX and aY from the window.

Note: That additional events may be fired as a result of this call. For instance, typically a click event will be fired as a result of a mousedown and mouseup in sequence.

Normally at this level of events, the mouseover and mouseout events are only fired when the window is entered or exited. For inter-element mouseover and mouseout events, a movemove event fired on the new element should be sufficient to generate the correct over and out events as well.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

The event is dispatched via the toplevel window, so it could go to any window under the toplevel window, in some cases it could never reach this window at all.

void sendMouseEvent(
  in AString aType,
  in float aX,
  in float aY,
  in long aButton,
  in long aClickCount,
  in long aModifiers,
  in boolean aIgnoreRootScrollFrame Optional 
);
Parameters
aType
Event type.
aX
X offset in CSS pixels.
aY
Y offset in CSS pixels.
aButton
Button to synthesize.
aClickCount
Number of clicks that have been performed.
aModifiers
Modifiers pressed.
Using constants defined in nsIDOMNSEvent. Obsolete since Gecko 15.0
Using constants defined as MODIFIER_*.
aIgnoreRootScrollFrame Optional
Whether the event should ignore viewport bounds during dispatch.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendMouseEventToWindow()

The same as sendMouseEvent() but ensures that the event is dispatched to this DOM window or one of its children.

void sendMouseEventToWindow(
  in AString aType,
  in float aX,
  in float aY,
  in long aButton,
  in long aClickCount,
  in long aModifiers,
  in boolean aIgnoreRootScrollFrame Optional
);
Parameters
aType
 
aX
 
aY
 
aButton
 
aClickCount
 
aModifiers
Modifiers pressed.
Using constants defined in nsIDOMNSEvent. Obsolete since Gecko 15.0
Using constants defined as MODIFIER_*.
aIgnoreRootScrollFrame Optional
 

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

sendMouseScrollEvent()

Obsolete since Gecko 17.0 (Firefox 17.0 / Thunderbird 17.0 / SeaMonkey 2.14)
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Synthesize a mouse scroll event for a window. The event types supported are: DOMMouseScroll MozMousePixelScroll.

Events are sent in coordinates offset by aX and aY from the window.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void sendMouseScrollEvent(
  in AString aType,
  in float aX,
  in float aY,
  in long aButton,
  in long aScrollFlags,
  in long aDelta,
  in long aModifiers
);
Parameters
aType
Event type.
aX
X offset in CSS pixels.
aY
Y offset in CSS pixels.
aButton
Button to synthesize.
aScrollFlags
Flag bits --- see nsMouseScrollFlags in nsGUIEvent.h.
aDelta
The direction and amount to scroll (in lines or pixels, depending on the event type)
aModifiers
Modifiers pressed.
Using constants defined in nsIDOMNSEvent. Obsolete since Gecko 15.0
Using constants defined as MODIFIER_*.

Requires Gecko 17.0 (Firefox 17.0 / Thunderbird 17.0 / SeaMonkey 2.14)

sendWheelEvent()

Synthesize a wheel event for a window. The event type is always "wheel".

Events are sent in coordinates offset by aX and aY from the window.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void sendWheelEvent(
  in float aX,
  in float aY,
  in double aDeltaX,
  in double aDeltaY,
  in double aDeltaZ,
  in unsigned long aDeltaMode,
  in long aModifiers,
  in long aLineOrPageDeltaX,
  in long aLineOrPageDeltaY,
  in unsigned long aOptions
);
Parameters
aX
X offset in CSS pixels.
aY
Y offset in CSS pixels.
aDeltaX
Delta value around x-axis.
aDeltaY
Delta value around y-axis.
aDeltaZ
Delta value around z-axis.
aDeltaMode
One of delta mode values which are defined by WheelEvent (nsIDOMWheelEvent).
aModifiers
Modifiers pressed. Using constants defined as MODIFIER_*.
aLineOrPageDeltaX
Scroll amount around x-axis by lines (if aDeltaMode is DOM_DELTA_PIXEL or DOM_DELTA_LINE) or pages (if aDeltaMode is DOM_DELTA_PAGE). If this values isn't 0, horizontal DOMMouseScroll event will be dispatched with this value. However, this value may be ignored by nsEventStateManager if some prefs are customized or aOptions value includes some flags.
aLineOrPageDeltaY
Scroll amount around y-axis by lines (if aDeltaMode is DOM_DELTA_PIXEL or DOM_DELTA_LINE) or pages (if aDeltaMode is DOM_DELTA_PAGE). If this values isn't 0, vertical DOMMouseScroll event will be dispatched with this value. However, this value may be ignored by nsEventStateManager if some prefs are customized or aOptions value includes some flags.
aOptions
0 or one or more WHEEL_EVENT_* flags.

Requires Gecko 1.9 (Firefox 3)

sendNativeKeyEvent()

This method lets you create and send keyboard events to a DOM window from a privileged context; for example, this can be used to automate testing. This delivers the key to the currently-focused widget by calling its See nsIWidget.synthesizeNativeKeyEvent() method.

This method throws a DOM security error if called without UniversalXPConnect privileges.

void sendNativeKeyEvent(
  in long aNativeKeyboardLayout,
  in long aNativeKeyCode,
  in long aModifierFlags,
  in AString aCharacters,
  in AString aUnmodifiedCharacters
);
Parameters
aNativeKeyboardLayout
 
aNativeKeyCode
The key code to send.
aModifierFlags
The modifier flags to send.
aCharacters
 
aUnmodifiedCharacters
 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendNativeMouseEvent()

See nsIWidget.SynthesizeNativeMouseEvent().

Will be called on the widget that contains aElement. Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void sendNativeMouseEvent(
  in long aScreenX,
  in long aScreenY,
  in long aNativeMessage,
  in long aModifierFlags,
  in nsIDOMElement aElement
);
Parameters
aScreenX
 
aScreenY
 
aNativeMessage
 
aModifierFlags
 
aElement
 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendQueryContentEvent()

Synthesize a query content event.

nsIQueryContentEventResult sendQueryContentEvent(
  in unsigned long aType,
  in unsigned long aOffset,
  in unsigned long aLength,
  in long aX,
  in long aY
);
Parameters
aType
On of the following const values. And see also each comment for the other parameters and the result.
aOffset
 
aLength
 
aX
 
aY
 
Return value

 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendSelectionSetEvent()

Synthesize a selection set event to the window.

This sets the selection as the specified information.

boolean sendSelectionSetEvent(
  in unsigned long aOffset,
  in unsigned long aLength,
  in boolean aReverse
);
Parameters
aOffset
The caret offset of the selection start.
aLength
The length of the selection. If this is too long, the extra length is ignored.
aReverse
If true, the selection set from |aOffset + aLength| to |aOffset|. Otherwise, set from |aOffset| to |aOffset + aLength|.
Return value

True, if succeeded. Otherwise, false.

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

sendSimpleGestureEvent()

Synthesize a simple gesture event for a window. The event types supported are: MozSwipeGesture, MozMagnifyGestureStart, MozMagnifyGestureUpdate, MozMagnifyGesture, MozRotateGestureStart, MozRotateGestureUpdate, MozRotateGesture, MozPressTapGesture, and MozTapGesture.

Cannot be accessed from unprivileged context (not content-accessible) Will throw a DOM security error if called without UniversalXPConnect privileges.

void sendSimpleGestureEvent(
  in AString aType,
  in float aX,
  in float aY,
  in unsigned long aDirection,
  in double aDelta,
  in long aModifiers
);
Parameters
aType
Event type.
aX
X offset in CSS pixels.
aY
Y offset in CSS pixels.
aDirection
Direction, using constants defined in nsIDOMSimpleGestureEvent.
aDelta
Amount of magnification or rotation for magnify and rotation events.
aModifiers
Modifiers pressed, using constants defined in nsIDOMNSEvent.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

sendTextEvent()

void sendTextEvent(
  in AString aCompositionString,
  in long aFirstClauseLength,
  in unsigned long aFirstClauseAttr,
  in long aSecondClauseLength,
  in unsigned long aSecondClauseAttr,
  in long aThirdClauseLength,
  in unsigned long aThirdClauseAttr,
  in long aCaretStart,
  in long aCaretLength
);
Parameters
aCompositionString
 
aFirstClauseLength
 
aFirstClauseAttr
 
aSecondClauseLength
 
aSecondClauseAttr
 
aThirdClauseLength
 
aThirdClauseAttr
 
aCaretStart
 
aCaretLength
 

Requires Gecko 12.0 (Firefox 12.0 / Thunderbird 12.0 / SeaMonkey 2.9)

sendTouchEvent()

Synthesizes a touch event and sends it to the window. This method supports multiple touches of the same type, but not multiple touches on the screen of different types.

Note: This method cannot be called from unprivileged content; that is, it's not accessible from web content. It will throw a DOM security error if called without UniversalXPConnect privileges.

The event is dispatched via the top-level window, so it could go to any window under that top level. In some cases, it may not even reach the target window, if one of those other windows accepts it.

boolean sendTouchEvent(
  in AString aType,
  [array, size_is(count)] in PRUint32 aIdentifiers,
  [array, size_is(count)] in PRInt32 aXs,
  [array, size_is(count)] in PRInt32 aYs,
  [array, size_is(count)] in PRUint32 aRxs,
  [array, size_is(count)] in PRUint32 aRys,
  [array, size_is(count)] in float aRotationAngles,
  [array, size_is(count)] in float aForces,
  in PRUint32 count,
  in long aModifiers,
  [optional] in boolean aIgnoreRootScrollFrame
);
Parameters
aType
The touch event type to dispatch to the window. This must be one of "touchstart", "touchend", "touchmove", or "touchcancel".
aIdentifiers
An array of the identifiers for each of the touches.
aXs
An array of X offsets in CSS pixels for each touch to be sent to the window.
aYs
An array of Y offsets in CSS pixels for each touch to be sent to the window.
aRxs
An array of touch X radii in CSS pixels for each touch to be sent to the window.
aRys
An array of touch Y radii in CSS pixels for each touch to be sent to the window.
aRotationAngles
An array of angles in degrees for each touch's touch oval.
aForces
An array of forces (from 0 to 1) indicating the amount of pressure applied at each touch point.
count
The number of touches; this is the number of entries in each of the preceding arrays.
aModifiers
Modifiers pressed.
Using constants defined in nsIDOMNSEvent. Obsolete since Gecko 15.0
Using constants defined as MODIFIER_*.
aIgnoreRootScrollFrames
A Boolean value indicating whether or not the event should ignore viewport bounds during dispatch.
Return value

true if the page called Event.preventDefault(), indicating that default processing of the event should not occur.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

setCSSViewport()

Sets the dimensions of the CSS viewport to the specified size in CSS pixels, regardless of the size of the enclosing widget/view. This triggers reflow.

The caller of this method must have UniversalXPConnect privileges.

Note: After calling this method, the window.innerWidth and window.innerHeight properties return the size of the viewport you've specified instead of the size of the browser widget.
void setCSSViewport(
  in float aWidthPx,
  in float aHeightPx
);
Parameters
aWidthPx
The width of the viewport in CSS pixels.
aHeightPx
The height of the viewport in CSS pixels.

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

setDisplayPort()

Set the "displayport" to be <xPx, yPx, widthPx, heightPx> in units of CSS pixels, regardless of the size of the enclosing widget/view. This will *not* trigger reflow.

<x, y> is relative to the top-left of the CSS viewport. This means that the pixels rendered to the displayport take scrolling into account, for example.

The displayport will be used as the window's visible region for the purposes of invalidation and painting. The displayport can approximately be thought of as a "persistent" drawWindow() (albeit with coordinates relative to the CSS viewport): the bounds are remembered by the platform, and layer pixels are retained and updated inside the viewport bounds.

It's legal to set a displayport that extends beyond the CSS viewport in any direction (left/right/top/bottom).

It's also legal to set a displayport that extends beyond the document's bounds. The value of the pixels rendered outside the document bounds is not yet defined.

The caller of this method must have UniversalXPConnect privileges.

void setDisplayPort(
  in float aXPx,
  in float aYPx,
  in float aWidthPx,
  in float aHeightPx
);
Parameters
aXPx
 
aYPx
 
aWidthPx
 
aHeightPx
 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

setResolution()

Get/set the resolution at which rescalable web content is drawn. Currently this is only (some) thebes content.

Setting a new resolution does *not* trigger reflow. This API is entirely separate from textZoom and fullZoom; a resolution scale can be applied together with both textZoom and fullZoom.

The effect of is API for gfx code to allocate more or fewer pixels for rescalable content by a factor of |resolution| in either or both dimensions. setResolution together with setDisplayport() can be used to implement a non-reflowing scale-zoom in concert with another entity that can draw with a scale. For example, to scale a content |window| inside a <browser> by a factor of 2.0.

window.setDisplayport()(x, y, oldW / 2.0, oldH / 2.0); window.setResolution(2.0, 2.0); // elsewhere browser.setViewportScale(2.0, 2.0);

The caller of this method must have UniversalXPConnect privileges.

void setResolution(
  in float aXResolution,
  in float aYResolution
);
Parameters
aXResolution
 
aYResolution
 

Requires Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)

startPCCountProfiling()

Begins detailed profiling of all executed JavaScript code in the browser.  This slows down JavaScript execution, but accumulates information about what code has executed that may be queried after a call to stopPCCountProfiling().

void startPCCountProfiling();
Parameters

None.

Requires Gecko 11.0 (Firefox 11.0 / Thunderbird 11.0 / SeaMonkey 2.8)

stopPCCountProfiling()

Stops profiling of executed JavaScript code.  Profile information about code that has executed since a preceding call to startPCCountProfiling() will be constructed, and will be retained until a call to purgePCCounts().  This profile information may be queried using getPCCountScriptCount(), getPCCountScriptSummary(), and getPCCountScriptContents().

void stopPCCountProfiling();
Parameters

None.

Requires Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

suppressEventHandling()

Suppresses/unsuppresses user initiated event handling in window's document and subdocuments.

void suppressEventHandling(
  in boolean aSuppress
);
Parameters
aSuppress
 

Requires Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1)

suspendTimeouts()

Suspend/resume timeouts on this window and its descendant windows.

void suspendTimeouts();
Parameters

None.

Requires Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

wrapDOMFile()

Wraps the specified nsIDOMFile in a DOM File object.

nsIDOMFile wrapDOMFile(
  nsIFile aFile
);
Parameters
aFile
The nsIFile object to wrap in a DOM File object.
Return value

An nsIDOMFile object, which is a DOM File. You can then use that object with DOM methods that use the File API.

Document Tags and Contributors

Last updated by: Sheppy,