Class Range

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
All Implemented Interfaces:
Serializable, 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:
  • Field Details

    • START_TO_START

      public static final int START_TO_START
      Comparison mode for compareBoundaryPoints.
      See Also:
    • START_TO_END

      public static final int START_TO_END
      Comparison mode for compareBoundaryPoints.
      See Also:
    • END_TO_END

      public static final int END_TO_END
      Comparison mode for compareBoundaryPoints.
      See Also:
    • END_TO_START

      public static final int END_TO_START
      Comparison mode for compareBoundaryPoints.
      See Also:
  • Constructor Details

    • 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 Details

    • jsConstructor

      public void jsConstructor()
      JavaScript constructor.
      Overrides:
      jsConstructor in class AbstractRange
    • 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
    • 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 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 HtmlUnitScriptable 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:
    • 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 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 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:
    • 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.
    • jsToString

      public 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