Module org.htmlunit

Class Range

java.lang.Object
org.htmlunit.corejs.javascript.SlotMapOwner<org.htmlunit.corejs.javascript.Scriptable>
org.htmlunit.corejs.javascript.ScriptableObject
All Implemented Interfaces:
Serializable, Cloneable, org.htmlunit.corejs.javascript.ConstProperties<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.debug.DebuggableObject, org.htmlunit.corejs.javascript.PropHolder<org.htmlunit.corejs.javascript.Scriptable>, org.htmlunit.corejs.javascript.Scriptable, org.htmlunit.corejs.javascript.SymbolScriptable

public class Range extends AbstractRange
The JavaScript object that represents a Range.
Author:
Marc Guillemot, Ahmed Ashour, Daniel Gredler, James Phillpotts, Ronald Brill
See Also:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    org.htmlunit.corejs.javascript.ScriptableObject.DescriptorInfo, org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator, org.htmlunit.corejs.javascript.ScriptableObject.LambdaGetterFunction, org.htmlunit.corejs.javascript.ScriptableObject.LambdaSetterFunction
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Comparison mode for compareBoundaryPoints.
    static final int
    Comparison mode for compareBoundaryPoints.
    static final int
    Comparison mode for compareBoundaryPoints.
    static final int
    Comparison mode for compareBoundaryPoints.

    Fields inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

    Fields inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    isSealed

    Fields inherited from interface org.htmlunit.corejs.javascript.Scriptable

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance.
    Range(Document document)
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a clone of the range in a document fragment.
    Returns a clone of the range.
    void
    collapse(boolean toStart)
    Collapse a Range onto one of its boundaries.
    int
    compareBoundaryPoints(int how, Range sourceRange)
    Compares the boundary points of two Ranges.
    Parses an HTML snippet.
    void
    Deletes the contents of the range.
    void
    Releases Range from use to improve performance.
    Moves this range's contents from the document tree into a document fragment.
    Returns an object that bounds the contents of the range.
    Retrieves a collection of rectangles that describes the layout of the contents of an object or range within the client.
    Returns the deepest common ancestor container of the Range's two boundary points.
    void
    insertNode(Node newNode)
    Inserts a new node at the beginning of the range.
    void
    JavaScript constructor.
    Returns the text of the Range.
    void
    selectNode(Node refNode)
    Selects a node and its contents.
    void
    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
    Sets the start of the range to be after the node.
    void
    Sets the start of the range to be before the node.
    void
    Surrounds the contents of the range in a new node.

    Methods inherited from class org.htmlunit.corejs.javascript.ScriptableObject

    applyDescriptorToAttributeBitset, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkNotSealed, checkPropertyChangeForSlot, checkPropertyChangeForSlot, checkPropertyDefinition, checkPropertyDefinition, checkSlotRemoval, defineBuiltinProperty, defineBuiltinProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineBuiltInProperty, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, delete, deleteProperty, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, ensureScriptableObjectButNotSymbol, ensureSymbolScriptable, ensureType, get, get, getAllIds, getAncestor, getArrayPrototype, getClassPrototype, getDefaultValue, getExternalArrayData, getExternalArrayLength, getFunctionPrototype, getGeneratorFunctionPrototype, getGetterOrSetter, getGetterOrSetter, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getProperty, getProperty, getPropertyIds, getPrototype, getSuperProperty, getSuperProperty, getSuperProperty, getThis, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, hasProperty, hasProperty, hasProperty, hasProperty, isAccessorDescriptor, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGenericDescriptor, isGetterOrSetter, isGetterOrSetter, isTrue, preventExtensions, put, put, putConst, putConstProperty, putConstProperty, putOwnProperty, putOwnProperty, putOwnProperty, putProperty, putProperty, putProperty, putProperty, putSuperProperty, putSuperProperty, putSuperProperty, querySlot, redefineProperty, redefineProperty, sameValue, sealObject, setCommonDescriptorProperties, setExternalArrayData, setGetterOrSetter, setParentScope, setPrototype, size

    Methods inherited from class org.htmlunit.corejs.javascript.SlotMapOwner

    associateValue, checkNotSealed, copyAssociatedValue, createSlotMap, defineProperty, defineProperty, get, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getAttributes, getIds, has, has, isSealed, readMaps, setAttributes, setAttributes, setAttributes, setAttributes, setAttributes, writeMaps

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.htmlunit.corejs.javascript.Scriptable

    get, getIds, has, has

    Methods inherited from interface org.htmlunit.corejs.javascript.SymbolScriptable

    get, has
  • 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
  • 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
    • 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 int 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 Range 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 DOMRectList 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 DOMRect 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