Class Selection

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.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:
    MSDN Documentation, Gecko DOM Reference, Serialized Form
    • 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 java.lang.String type_  
      private static java.lang.String TYPE_CARET  
      private static java.lang.String TYPE_NONE  
      private static java.lang.String TYPE_RANGE  
      • 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
      Selection()
      Creates an instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      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 collapseToEnd()
      Moves the anchor of the selection to the same point as the focus.
      void collapseToStart()
      Moves the focus of the selection to the same point at the anchor.
      void empty()
      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.
      Node getAnchorNode()
      Returns the node in which the selection begins.
      int getAnchorOffset()
      Returns the number of characters that the selection's anchor is offset within the anchor node.
      java.lang.Object getDefaultValue​(java.lang.Class<?> hint)
      Returns the JavaScript default value of this object.
      private SimpleRange getFirstRange()
      Returns the first selection range in the current document, by document position.
      Node getFocusNode()
      Returns the node in which the selection ends.
      int getFocusOffset()
      Returns the number of characters that the selection's focus is offset within the focus node.
      private SimpleRange getLastRange()
      Returns the last selection range in the current document, by document position.
      Range getRangeAt​(int index)
      Returns the range at the specified index.
      int getRangeCount()
      Returns the number of ranges in the selection.
      private java.util.List<SimpleRange> getRanges()
      Returns the current HtmlUnit DOM selection ranges.
      private HtmlUnitScriptable getScriptableNullSafe​(java.lang.Object object)
      Returns the scriptable object corresponding to the specified HtmlUnit DOM object.
      java.lang.String getType()
      Returns the type of selection (IE only).
      boolean isIsCollapsed()
      Returns a boolean indicating whether the selection's start and end points are at the same position.
      void jsConstructor()
      JavaScript constructor.
      java.lang.String jsToString()  
      void removeAllRanges()
      Removes all ranges from the selection.
      void removeRange​(Range range)
      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
    • Constructor Detail

      • Selection

        public Selection()
        Creates an instance.
    • Method Detail

      • jsConstructor

        public void jsConstructor()
        JavaScript constructor.
      • jsToString

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

        public java.lang.Object getDefaultValue​(java.lang.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 java.lang.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 java.util.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​(java.lang.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