Class SimpleRange

java.lang.Object
org.htmlunit.html.impl.SimpleRange
All Implemented Interfaces:
Serializable

public class SimpleRange extends Object implements Serializable
Simple implementation of an Range.
See Also:
  • Field Details

    • startContainer_

      private DomNode startContainer_
      The start (anchor) container.
    • endContainer_

      private DomNode 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

      public SimpleRange(DomNode node)
      Constructs a range for the specified element.
      Parameters:
      node - the node for the range
    • SimpleRange

      public SimpleRange(DomNode node, int offset)
      Constructs a range for the provided element and start and end offset.
      Parameters:
      node - the node for the range
      offset - the start and end offset
    • SimpleRange

      public SimpleRange(DomNode startNode, int startOffset, DomNode endNode, int endOffset)
      Constructs a range for the provided elements and offsets.
      Parameters:
      startNode - the start node
      startOffset - the start offset
      endNode - the end node
      endOffset - the end offset
  • Method Details

    • cloneContents

      public DomDocumentFragment cloneContents()
      Duplicates the contents of this.
      Returns:
      DocumentFragment that contains content equivalent to this
    • cloneRange

      public SimpleRange 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

      private void deleteContents(DomNode ancestor)
    • extractContents

      public DomDocumentFragment extractContents() throws DOMException
      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

      public boolean isCollapsed() throws DOMException
      Returns:
      true if startContainer equals endContainer and startOffset equals endOffset
      Throws:
      DOMException
    • getCommonAncestorContainer

      public DomNode getCommonAncestorContainer() throws DOMException
      Returns:
      the deepest common ancestor container of this range's two boundary-points.
      Throws:
      DOMException
    • getEndContainer

      public DomNode getEndContainer()
      Returns:
      the Node within which this range ends
    • getEndOffset

      public int getEndOffset()
      Returns:
      offset within the ending node of this
    • getStartContainer

      public DomNode getStartContainer()
      Returns:
      the Node within which this range begins
    • getStartOffset

      public int getStartOffset()
      Returns:
      offset within the starting node of this
    • insertNode

      public void insertNode(DomNode newNode)
      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

      private static void insertNodeOrDocFragment(DomNode parent, DomNode newNode, DomNode refNode)
    • selectNode

      public void selectNode(DomNode node)
      Select a node and its contents.
      Parameters:
      node - The node to select.
    • selectNodeContents

      public void selectNodeContents(DomNode node)
      Select the contents within a node.
      Parameters:
      node - Node to select from
    • setEnd

      public void setEnd(DomNode refNode, int offset)
      Sets the attributes describing the end.
      Parameters:
      refNode - the refNode
      offset - offset
    • setStart

      public void setStart(DomNode refNode, int offset)
      Sets the attributes describing the start.
      Parameters:
      refNode - the refNode
      offset - offset
    • surroundContents

      public 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.
      Parameters:
      newParent - The node to surround the contents with.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isOffsetChars

      private static boolean isOffsetChars(DomNode node)
    • getText

      private static String getText(DomNode node)
    • setText

      private static void setText(DomNode node, String text)
    • deleteBefore

      private static void deleteBefore(DomNode node, int offset)
    • deleteAfter

      private static void deleteAfter(DomNode node, int offset)
    • getMaxOffset

      private static int getMaxOffset(DomNode node)
    • containedNodes

      public List<DomNode> containedNodes()
      Returns:
      a list with all nodes contained in this range