Package org.htmlunit.html.impl
Class SimpleRange
java.lang.Object
org.htmlunit.html.impl.SimpleRange
- All Implemented Interfaces:
Serializable
Simple implementation of an Range.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate DomNode
The end (focus) container.private int
The end (focus) offset; units are chars if the end container is a text node or an input element, DOM nodes otherwise.private DomNode
The start (anchor) container.private int
The start (anchor) offset; units are chars if the start container is a text node or an input element, DOM nodes otherwise. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a range without any content.SimpleRange
(DomNode node) Constructs a range for the specified element.SimpleRange
(DomNode node, int offset) Constructs a range for the provided element and start and end offset.SimpleRange
(DomNode startNode, int startOffset, DomNode endNode, int endOffset) Constructs a range for the provided elements and offsets. -
Method Summary
Modifier and TypeMethodDescriptionDuplicates the contents of this.Produces a new SimpleRange whose boundary-points are equal to the boundary-points of this.void
collapse
(boolean toStart) Collapse this range onto one of its boundary-points.private static void
deleteAfter
(DomNode node, int offset) private static void
deleteBefore
(DomNode node, int offset) void
Removes the contents of this range from the containing document or document fragment without returning a reference to the removed content.private void
deleteContents
(DomNode ancestor) boolean
Moves the contents of a Range from the containing document or document fragment to a new DocumentFragment.int
private static int
getMaxOffset
(DomNode node) int
private static String
int
hashCode()
void
insertNode
(DomNode newNode) Inserts a node into the Document or DocumentFragment at the start of the Range.private static void
insertNodeOrDocFragment
(DomNode parent, DomNode newNode, DomNode refNode) boolean
private static boolean
isOffsetChars
(DomNode node) void
selectNode
(DomNode node) Select a node and its contents.void
selectNodeContents
(DomNode node) Select the contents within a node.void
Sets the attributes describing the end.void
Sets the attributes describing the start.private static void
void
surroundContents
(DomNode newParent) Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.toString()
-
Field Details
-
startContainer_
The start (anchor) container. -
endContainer_
The end (focus) container. -
startOffset_
private int startOffset_The start (anchor) offset; units are chars if the start container is a text node or an input element, DOM nodes otherwise. -
endOffset_
private int endOffset_The end (focus) offset; units are chars if the end container is a text node or an input element, DOM nodes otherwise.
-
-
Constructor Details
-
SimpleRange
public SimpleRange()Constructs a range without any content. -
SimpleRange
Constructs a range for the specified element.- Parameters:
node
- the node for the range
-
SimpleRange
Constructs a range for the provided element and start and end offset.- Parameters:
node
- the node for the rangeoffset
- the start and end offset
-
SimpleRange
Constructs a range for the provided elements and offsets.- Parameters:
startNode
- the start nodestartOffset
- the start offsetendNode
- the end nodeendOffset
- the end offset
-
-
Method Details
-
cloneContents
Duplicates the contents of this.- Returns:
- DocumentFragment that contains content equivalent to this
-
cloneRange
Produces a new SimpleRange whose boundary-points are equal to the boundary-points of this.- Returns:
- duplicated simple
-
collapse
public void collapse(boolean toStart) Collapse this range onto one of its boundary-points.- Parameters:
toStart
- if true, collapses the Range onto its start; else collapses it onto its end.
-
deleteContents
public void deleteContents()Removes the contents of this range from the containing document or document fragment without returning a reference to the removed content. -
deleteContents
-
extractContents
Moves the contents of a Range from the containing document or document fragment to a new DocumentFragment.- Returns:
- DocumentFragment containing the extracted contents
- Throws:
DOMException
-
isCollapsed
- Returns:
- true if startContainer equals endContainer and startOffset equals endOffset
- Throws:
DOMException
-
getCommonAncestorContainer
- Returns:
- the deepest common ancestor container of this range's two boundary-points.
- Throws:
DOMException
-
getEndContainer
- Returns:
- the Node within which this range ends
-
getEndOffset
public int getEndOffset()- Returns:
- offset within the ending node of this
-
getStartContainer
- Returns:
- the Node within which this range begins
-
getStartOffset
public int getStartOffset()- Returns:
- offset within the starting node of this
-
insertNode
Inserts a node into the Document or DocumentFragment at the start of the Range. If the container is a Text node, this will be split at the start of the Range (as if the Text node's splitText method was performed at the insertion point) and the insertion will occur between the two resulting Text nodes. Adjacent Text nodes will not be automatically merged. If the node to be inserted is a DocumentFragment node, the children will be inserted rather than the DocumentFragment node itself.- Parameters:
newNode
- The node to insert at the start of the Range
-
insertNodeOrDocFragment
-
selectNode
Select a node and its contents.- Parameters:
node
- The node to select.
-
selectNodeContents
Select the contents within a node.- Parameters:
node
- Node to select from
-
setEnd
Sets the attributes describing the end.- Parameters:
refNode
- the refNodeoffset
- offset
-
setStart
Sets the attributes describing the start.- Parameters:
refNode
- the refNodeoffset
- offset
-
surroundContents
Reparents the contents of the Range to the given node and inserts the node at the position of the start of the Range.- Parameters:
newParent
- The node to surround the contents with.
-
equals
-
hashCode
public int hashCode() -
toString
-
isOffsetChars
-
getText
-
setText
-
deleteBefore
-
deleteAfter
-
getMaxOffset
-
containedNodes
- Returns:
- a list with all nodes contained in this range
-