Package org.htmlunit.javascript.host.dom
Class Range
- java.lang.Object
-
- org.htmlunit.corejs.javascript.ScriptableObject
-
- org.htmlunit.javascript.HtmlUnitScriptable
-
- org.htmlunit.javascript.host.dom.AbstractRange
-
- org.htmlunit.javascript.host.dom.Range
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,org.htmlunit.corejs.javascript.ConstProperties,org.htmlunit.corejs.javascript.debug.DebuggableObject,org.htmlunit.corejs.javascript.Scriptable,org.htmlunit.corejs.javascript.SymbolScriptable
public class Range extends AbstractRange
The JavaScript object that represents a Range.- See Also:
- XULPlanet, DOM-Level-2-Traversal-Range, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static intEND_TO_ENDComparison mode for compareBoundaryPoints.static intEND_TO_STARTComparison mode for compareBoundaryPoints.static intSTART_TO_ENDComparison mode for compareBoundaryPoints.static intSTART_TO_STARTComparison mode for compareBoundaryPoints.
-
Constructor Summary
Constructors Constructor Description Range()Creates an instance.Range(SimpleRange simpleRange)Range(Document document)Creates a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HtmlUnitScriptablecloneContents()Returns a clone of the range in a document fragment.java.lang.ObjectcloneRange()Returns a clone of the range.voidcollapse(boolean toStart)Collapse a Range onto one of its boundaries.java.lang.ObjectcompareBoundaryPoints(int how, Range sourceRange)Compares the boundary points of two Ranges.HtmlUnitScriptablecreateContextualFragment(java.lang.String valueAsString)Parses an HTML snippet.voiddeleteContents()Deletes the contents of the range.voiddetach()Releases Range from use to improve performance.HtmlUnitScriptableextractContents()Moves this range's contents from the document tree into a document fragment.ClientRectgetBoundingClientRect()Returns an object that bounds the contents of the range.ClientRectListgetClientRects()Retrieves a collection of rectangles that describes the layout of the contents of an object or range within the client.java.lang.ObjectgetCommonAncestorContainer()Returns the deepest common ancestor container of the Range's two boundary points.private static intgetPositionInContainer(Node refNode)voidinsertNode(Node newNode)Inserts a new node at the beginning of the range.voidjsConstructor()JavaScript constructor.java.lang.StringjsToString()Returns the text of the Range.voidselectNode(Node refNode)Selects a node and its contents.voidselectNodeContents(Node refNode)Select the contents within a node.voidsetEnd(Node refNode, int offset)Sets the attributes describing the end of a Range.voidsetEndAfter(Node refNode)Sets the end of the range to be after the node.voidsetEndBefore(Node refNode)Sets the end of the range to be before the node.voidsetStart(Node refNode, int offset)Sets the attributes describing the start of a Range.voidsetStartAfter(Node refNode)Sets the start of the range to be after the node.voidsetStartBefore(Node refNode)Sets the start of the range to be before the node.voidsurroundContents(Node newNode)Surrounds the contents of the range in a new node.-
Methods inherited from class org.htmlunit.javascript.host.dom.AbstractRange
equivalentValues, getDefaultValue, getEndContainer, getEndOffset, getSimpleRange, getStartContainer, getStartOffset, internGetEndContainer, internGetEndOffset, internGetStartContainer, internGetStartOffset, internSetEndContainer, internSetEndOffset, internSetStartContainer, internSetStartOffset, isCollapsed
-
Methods inherited from class org.htmlunit.javascript.HtmlUnitScriptable
clone, get, getBrowserVersion, getClassName, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
-
Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureSymbolScriptable, get, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, putProperty, querySlot, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setPrototype, size
-
-
-
-
Field Detail
-
START_TO_START
public static final int START_TO_START
Comparison mode for compareBoundaryPoints.- See Also:
- Constant Field Values
-
START_TO_END
public static final int START_TO_END
Comparison mode for compareBoundaryPoints.- See Also:
- Constant Field Values
-
END_TO_END
public static final int END_TO_END
Comparison mode for compareBoundaryPoints.- See Also:
- Constant Field Values
-
END_TO_START
public static final int END_TO_START
Comparison mode for compareBoundaryPoints.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Range
public Range()
Creates an instance.
-
Range
public Range(Document document)
Creates a new instance.- Parameters:
document- the HTML document creating the range
-
Range
Range(SimpleRange simpleRange)
-
-
Method Detail
-
jsConstructor
public void jsConstructor()
JavaScript constructor.- Overrides:
jsConstructorin classAbstractRange
-
setStart
public void setStart(Node refNode, int offset)
Sets the attributes describing the start of a Range.- Parameters:
refNode- the reference nodeoffset- 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
-
getPositionInContainer
private static int getPositionInContainer(Node refNode)
-
setEnd
public void setEnd(Node refNode, int offset)
Sets the attributes describing the end of a Range.- Parameters:
refNode- the reference nodeoffset- 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- iftrue, collapses the Range onto its start; else collapses it onto its end
-
getCommonAncestorContainer
public java.lang.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 HtmlUnitScriptable createContextualFragment(java.lang.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 HtmlUnitScriptable extractContents()
Moves this range's contents from the document tree into a document fragment.- Returns:
- the new document fragment containing the range contents
-
compareBoundaryPoints
public java.lang.Object compareBoundaryPoints(int how, Range sourceRange)Compares the boundary points of two Ranges.- Parameters:
how- a constant describing the comparison methodsourceRange- 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 HtmlUnitScriptable 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 java.lang.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.
-
jsToString
public java.lang.String jsToString()
Returns the text of the Range.- Returns:
- the text
-
getClientRects
public ClientRectList getClientRects()
Retrieves a collection of rectangles that describes the layout of the contents of an object or range within the client. Each rectangle describes a single line.- Returns:
- a collection of rectangles that describes the layout of the contents
-
getBoundingClientRect
public ClientRect getBoundingClientRect()
Returns an object that bounds the contents of the range. this a rectangle enclosing the union of the bounding rectangles for all the elements in the range.- Returns:
- an object the bounds the contents of the range
-
-