Class Selection

java.lang.Object
org.htmlunit.corejs.javascript.ScriptableObject
org.htmlunit.javascript.HtmlUnitScriptable
org.htmlunit.javascript.host.dom.Selection
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 Selection extends HtmlUnitScriptable
A JavaScript object for Selection.
See Also:
  • Nested Class Summary

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

    org.htmlunit.corejs.javascript.ScriptableObject.KeyComparator
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
     
    private static final String
     
    private static final String
     
    private static final String
     

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

    CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST

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

    NOT_FOUND
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addRange(Range range)
    Adds a range to the selection.
    void
    collapse(Node parentNode, int offset)
    Collapses the current selection to a single point.
    void
    Moves the anchor of the selection to the same point as the focus.
    void
    Moves the focus of the selection to the same point at the anchor.
    void
    Cancels the current selection, sets the selection type to none.
    void
    extend(Node parentNode, int offset)
    Moves the focus of the selection to a specified point.
    Returns the node in which the selection begins.
    int
    Returns the number of characters that the selection's anchor is offset within the anchor node.
    Returns the JavaScript default value of this object.
    private SimpleRange
    Returns the first selection range in the current document, by document position.
    Returns the node in which the selection ends.
    int
    Returns the number of characters that the selection's focus is offset within the focus node.
    private SimpleRange
    Returns the last selection range in the current document, by document position.
    getRangeAt(int index)
    Returns the range at the specified index.
    int
    Returns the number of ranges in the selection.
    private List<SimpleRange>
    Returns the current HtmlUnit DOM selection ranges.
    Returns the scriptable object corresponding to the specified HtmlUnit DOM object.
    Returns the type of selection (IE only).
    boolean
    Returns a boolean indicating whether the selection's start and end points are at the same position.
    void
    JavaScript constructor.
     
    void
    Removes all ranges from the selection.
    void
    Removes a range from the selection.
    void
    selectAllChildren(Node parentNode)
    Adds all the children of the specified node to the selection.

    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

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • Selection

      public Selection()
      Creates an instance.
  • Method Details

    • jsConstructor

      public void jsConstructor()
      JavaScript constructor.
    • jsToString

      public String jsToString()
      Returns:
      a string currently being represented by the selection object, i.e. the currently selected text.
    • getDefaultValue

      public Object getDefaultValue(Class<?> hint)
      Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.
      Specified by:
      getDefaultValue in interface org.htmlunit.corejs.javascript.Scriptable
      Overrides:
      getDefaultValue in class HtmlUnitScriptable
      Parameters:
      hint - a hint as to the format of the default value (ignored in this case)
      Returns:
      the default value
    • getAnchorNode

      public Node getAnchorNode()
      Returns the node in which the selection begins.
      Returns:
      the node in which the selection begins
    • getAnchorOffset

      public int getAnchorOffset()
      Returns the number of characters that the selection's anchor is offset within the anchor node.
      Returns:
      the number of characters that the selection's anchor is offset within the anchor node
    • getFocusNode

      public Node getFocusNode()
      Returns the node in which the selection ends.
      Returns:
      the node in which the selection ends
    • getFocusOffset

      public int getFocusOffset()
      Returns the number of characters that the selection's focus is offset within the focus node.
      Returns:
      the number of characters that the selection's focus is offset within the focus node
    • isIsCollapsed

      public boolean isIsCollapsed()
      Returns a boolean indicating whether the selection's start and end points are at the same position.
      Returns:
      a boolean indicating whether the selection's start and end points are at the same position
    • getRangeCount

      public int getRangeCount()
      Returns the number of ranges in the selection.
      Returns:
      the number of ranges in the selection
    • getType

      public String getType()
      Returns the type of selection (IE only).
      Returns:
      the type of selection
    • addRange

      public void addRange(Range range)
      Adds a range to the selection.
      Parameters:
      range - the range to add
    • removeRange

      public void removeRange(Range range)
      Removes a range from the selection.
      Parameters:
      range - the range to remove
    • removeAllRanges

      public void removeAllRanges()
      Removes all ranges from the selection.
    • getRangeAt

      public Range getRangeAt(int index)
      Returns the range at the specified index.
      Parameters:
      index - the index of the range to return
      Returns:
      the range at the specified index
    • collapse

      public void collapse(Node parentNode, int offset)
      Collapses the current selection to a single point. The document is not modified.
      Parameters:
      parentNode - the caret location will be within this node
      offset - the caret will be placed this number of characters from the beginning of the parentNode's text
    • collapseToEnd

      public void collapseToEnd()
      Moves the anchor of the selection to the same point as the focus. The focus does not move.
    • collapseToStart

      public void collapseToStart()
      Moves the focus of the selection to the same point at the anchor. The anchor does not move.
    • empty

      public void empty()
      Cancels the current selection, sets the selection type to none.
    • extend

      public void extend(Node parentNode, int offset)
      Moves the focus of the selection to a specified point. The anchor of the selection does not move.
      Parameters:
      parentNode - the node within which the focus will be moved
      offset - the number of characters from the beginning of parentNode's text the focus will be placed
    • selectAllChildren

      public void selectAllChildren(Node parentNode)
      Adds all the children of the specified node to the selection. The previous selection is lost.
      Parameters:
      parentNode - all children of parentNode will be selected; parentNode itself is not part of the selection
    • getRanges

      private List<SimpleRange> getRanges()
      Returns the current HtmlUnit DOM selection ranges.
      Returns:
      the current HtmlUnit DOM selection ranges
    • getFirstRange

      private SimpleRange getFirstRange()
      Returns the first selection range in the current document, by document position.
      Returns:
      the first selection range in the current document, by document position
    • getLastRange

      private SimpleRange getLastRange()
      Returns the last selection range in the current document, by document position.
      Returns:
      the last selection range in the current document, by document position
    • getScriptableNullSafe

      private HtmlUnitScriptable getScriptableNullSafe(Object object)
      Returns the scriptable object corresponding to the specified HtmlUnit DOM object.
      Parameters:
      object - the HtmlUnit DOM object whose scriptable object is to be returned (may be null)
      Returns:
      the scriptable object corresponding to the specified HtmlUnit DOM object, or null if object was null