com.gargoylesoftware.htmlunit.javascript.host
Class Range

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.Range
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class Range
extends SimpleScriptable

The JavaScript object that represents a Range.

Version:
$Revision: 8931 $
Author:
Marc Guillemot, Ahmed Ashour, Daniel Gredler, James Phillpotts
See Also:
XULPlanet, DOM-Level-2-Traversal-Range, Serialized Form

Field Summary
static short END_TO_END
          Comparison mode for compareBoundaryPoints.
static short END_TO_START
          Comparison mode for compareBoundaryPoints.
static short START_TO_END
          Comparison mode for compareBoundaryPoints.
static short START_TO_START
          Comparison mode for compareBoundaryPoints.
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
Range()
          Creates a new instance.
Range(HTMLDocument document)
          Creates a new instance.
 
Method Summary
 Object cloneContents()
          Returns a clone of the range in a document fragment.
 Object cloneRange()
          Returns a clone of the range.
 void collapse(boolean toStart)
          Collapse a Range onto one of its boundaries.
 Object compareBoundaryPoints(int how, Range sourceRange)
          Compares the boundary points of two Ranges.
 Object createContextualFragment(String valueAsString)
          Parses an HTML snippet.
 void deleteContents()
          Deletes the contents of the range.
 void detach()
          Releases Range from use to improve performance.
protected  Object equivalentValues(Object value)
          
 Object extractContents()
          Moves this range's contents from the document tree into a document fragment.
 boolean getCollapsed()
          Indicates if the range is collapsed.
 Object getCommonAncestorContainer()
          Returns the deepest common ancestor container of the Range's two boundary points.
 Object getDefaultValue(Class<?> hint)
          Returns the JavaScript default value of this object.
 Object getEndContainer()
          Gets the node within which the Range ends.
 int getEndOffset()
          Gets the offset within the end node of the Range.
 Object getStartContainer()
          Gets the node within which the Range begins.
 int getStartOffset()
          Gets the offset within the starting node of the Range.
 void insertNode(Node newNode)
          Inserts a new node at the beginning of the range.
 void selectNode(Node refNode)
          Selects a node and its contents.
 void selectNodeContents(Node refNode)
          Select the contents within a node.
 void setEnd(Node refNode, int offset)
          Sets the attributes describing the end of a Range.
 void setEndAfter(Node refNode)
          Sets the end of the range to be after the node.
 void setEndBefore(Node refNode)
          Sets the end of the range to be before the node.
 void setStart(Node refNode, int offset)
          Sets the attributes describing the start of a Range.
 void setStartAfter(Node refNode)
          Sets the start of the range to be after the node.
 void setStartBefore(Node refNode)
          Sets the start of the range to be before the node.
 void surroundContents(Node newNode)
          Surrounds the contents of the range in a new node.
 String toString()
          Returns the text of the Range.
 SimpleRange toW3C()
          Returns a W3C Range version of this object.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, get, getBrowserVersion, getClassName, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement, setParentScope
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

START_TO_START

public static final short START_TO_START
Comparison mode for compareBoundaryPoints.

See Also:
Constant Field Values

START_TO_END

public static final short START_TO_END
Comparison mode for compareBoundaryPoints.

See Also:
Constant Field Values

END_TO_END

public static final short END_TO_END
Comparison mode for compareBoundaryPoints.

See Also:
Constant Field Values

END_TO_START

public static final short END_TO_START
Comparison mode for compareBoundaryPoints.

See Also:
Constant Field Values
Constructor Detail

Range

public Range()
Creates a new instance.


Range

public Range(HTMLDocument document)
Creates a new instance.

Parameters:
document - the HTML document creating the range
Method Detail

getDefaultValue

public Object getDefaultValue(Class<?> hint)
Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.

Specified by:
getDefaultValue in interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
Overrides:
getDefaultValue in class SimpleScriptable
Parameters:
hint - a hint as to the format of the default value (ignored in this case)
Returns:
the default value

getStartContainer

public Object getStartContainer()
Gets the node within which the Range begins.

Returns:
undefined if not initialized

getEndContainer

public Object getEndContainer()
Gets the node within which the Range ends.

Returns:
undefined if not initialized

getStartOffset

public int getStartOffset()
Gets the offset within the starting node of the Range.

Returns:
0 if not initialized

getEndOffset

public int getEndOffset()
Gets the offset within the end node of the Range.

Returns:
0 if not initialized

setStart

public void setStart(Node refNode,
                     int offset)
Sets the attributes describing the start of a Range.

Parameters:
refNode - the reference node
offset - the offset value within the node

setStartAfter

public void setStartAfter(Node refNode)
Sets the start of the range to be after the node.

Parameters:
refNode - the reference node

setStartBefore

public void setStartBefore(Node refNode)
Sets the start of the range to be before the node.

Parameters:
refNode - the reference node

getCollapsed

public boolean getCollapsed()
Indicates if the range is collapsed.

Returns:
true if the range is collapsed

setEnd

public void setEnd(Node refNode,
                   int offset)
Sets the attributes describing the end of a Range.

Parameters:
refNode - the reference node
offset - the offset value within the node

setEndAfter

public void setEndAfter(Node refNode)
Sets the end of the range to be after the node.

Parameters:
refNode - the reference node

setEndBefore

public void setEndBefore(Node refNode)
Sets the end of the range to be before the node.

Parameters:
refNode - the reference node

selectNodeContents

public void selectNodeContents(Node refNode)
Select the contents within a node.

Parameters:
refNode - Node to select from

selectNode

public void selectNode(Node refNode)
Selects a node and its contents.

Parameters:
refNode - the node to select

collapse

public void collapse(boolean toStart)
Collapse a Range onto one of its boundaries.

Parameters:
toStart - if true, collapses the Range onto its start; else collapses it onto its end

getCommonAncestorContainer

public Object getCommonAncestorContainer()
Returns the deepest common ancestor container of the Range's two boundary points.

Returns:
the deepest common ancestor container of the Range's two boundary points

createContextualFragment

public Object createContextualFragment(String valueAsString)
Parses an HTML snippet.

Parameters:
valueAsString - text that contains text and tags to be converted to a document fragment
Returns:
a document fragment
See Also:
Mozilla documentation

extractContents

public Object extractContents()
Moves this range's contents from the document tree into a document fragment.

Returns:
the new document fragment containing the range contents

toW3C

public SimpleRange toW3C()
Returns a W3C Range version of this object.

Returns:
a W3C Range version of this object

compareBoundaryPoints

public Object compareBoundaryPoints(int how,
                                    Range sourceRange)
Compares the boundary points of two Ranges.

Parameters:
how - a constant describing the comparison method
sourceRange - the Range to compare boundary points with this range
Returns:
-1, 0, or 1, indicating whether the corresponding boundary-point of range is respectively before, equal to, or after the corresponding boundary-point of sourceRange.

cloneContents

public Object cloneContents()
Returns a clone of the range in a document fragment.

Returns:
a clone

deleteContents

public void deleteContents()
Deletes the contents of the range.


insertNode

public void insertNode(Node newNode)
Inserts a new node at the beginning of the range. If the range begins at an offset, the node is split.

Parameters:
newNode - The node to insert
See Also:
https://developer.mozilla.org/en/DOM/range

surroundContents

public void surroundContents(Node newNode)
Surrounds the contents of the range in a new node.

Parameters:
newNode - The node to surround the range in

cloneRange

public Object cloneRange()
Returns a clone of the range.

Returns:
a clone of the range

detach

public void detach()
Releases Range from use to improve performance.


toString

public String toString()
Returns the text of the Range.

Overrides:
toString in class Object
Returns:
the text

equivalentValues

protected Object equivalentValues(Object value)
Description copied from class: SimpleScriptable

Overrides:
equivalentValues in class SimpleScriptable


Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.