You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.


TOC PREV NEXT INDEX

Embedding Gecko API


nsISelection


This interface allows for manipulating and querying the current selected range of nodes within the document. It is scriptable.

Methods
getRangeAt

Returns the range at the specified index.

Syntax:

nsIDOMRange nsISelection::getRangeAt(in long index) 

Parameters:

index: The desired index.

Returns:

An nsIDOMRange object.
collapse

Collapses the selection to a single point, at the specified offset in the given DOM node. When the selection is collapsed, and the content is focused and editable, the caret will blink there.

Syntax:

void nsISelection::collapse(in nsIDOMNode parentNode, 
	in long offset) 

Parameters:

parentNode: The given DOM node where the selection will be set
offset: Where in given DOM node to place the selection, i.e., the offset into the given node.

nsresult:

NS_OK if successful.
extend

Extends the selection by moving the focus to the specified node and offset, preserving the anchor postion. The new selection end result will always be from the anchor to the new focus, regardless of direction.

Syntax:

void nsISelection::extend(in nsIDOMNode parentNode, 
	in long offset) 

Parameters:

parentNode: The node to which the selection will be extended.
offset: Where in node to place the offset in the new focused node.

nsresult:

NS_OK if successful.
collapseToStart

Collapses the whole selection to a single point at the start of the current selection (no matter which direction). If content is focused and editable, the caret will blink there.

Syntax:

void nsISelection::collapseToStart() 

Parameters:

None.

nsresult:

NS_OK if successful.
collapseToEnd

Collapses the whole selection to a single point at the end of the current selection (no matter which direction). If content is focused and editable, the caret will blink there.

Syntax:

void nsISelection::collapseToEnd() 

Parameters:

None.

nsresult:

NS_OK if successful.
containsNode

Determines whether or not a selection contains a particular node.

Syntax:

boolean nsISelection::containsNode(in nsIDOMNode node,
	in boolean entirelyContained) 

Parameters:

node: The node being searched for.
entirelyContained: Whether or not the node must be entirely contained in the selection. PR_TRUE indicates it must entirely contained.

Returns:

TRUE if the selection contains the node in the specified manner.
FALSE if it does not.
selectAllChildren

Adds all children of the specified node to the selection.

Syntax:

void nsISelection::selectAllChildren(
	in nsIDOMNode parentNode) 

Parameters:

parentNode: The parent of the children to be added to the selection.

nsresult:

NS_OK if successful.
addRange

Adds a range to the current selection.

Syntax:

void nsISelection::addRange(in nsIDOMRange range) 

Parameters:

range: The range to be added.

nsresult:

NS_OK if successful.
removeRange

Removes a range from the current selection.

Syntax:

void nsISelection::removeRange(in nsIDOMRange range) 

Parameters:

range: The range to be removed.

nsresult:

NS_OK if successful.
removeAllRanges

Removes all ranges from the current selection.

Syntax:

void nsISelection::removeAllRanges() 

Parameters:

None.

nsresult:

NS_OK if successful.
deleteFromDocument

Deletes this selection from the document to which the nodes belong.

Syntax:

void nsISelection::deleteFromDocument() 

Parameters:

None.

nsresult:

NS_OK if successful.
selectionLanguageChange

Modifies the cursor Bidi level after a change in keyboard direction.

Syntax:

void nsISelection::selectionLanguageChange(
	in boolean langRTL) 

Parameters:

langRTL: PR_TRUE if the new language is right-to-left or PR_FALSE if the new language is left-to-right.

nsresult:

NS_OK if successful.
toString

Returns the whole selection into a plain text string.

Syntax:

wstring nsISelection::toString() 

Parameters:

None.

nsresult:

NS_OK if successful
Attributes
readonly attribute nsIDOMNode nsISelection::anchorNode

Gets the node representing one end of the selection.

readonly attribute long nsISelection::anchorOffset

Gets the offset within the (text) node where the selection begins.

readonly attribute nsIDOMNode nsISelection::focusNode

Gets the node with keyboard focus.

readonly attribute long nsISelection::focusOffset

Gets the offset within the (text) node where focus starts.

readonly attribute boolean nsISelection::isCollapsed

Indicates if the selection is collapsed or not.

readonly attribute long nsISelection::rangeCount

Returns the number of ranges in the selection.


Written by:Ellen Evans | Comments, questions, complaints? Bug 143387
TOC PREV NEXT INDEX