Package org.htmlunit.javascript.host.dom
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
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
FieldsModifier and TypeFieldDescriptionprivate 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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a range to the selection.void
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
empty()
Cancels the current selection, sets the selection type to none.void
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.getDefaultValue
(Class<?> hint) 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.private HtmlUnitScriptable
getScriptableNullSafe
(Object object) Returns the scriptable object corresponding to the specified HtmlUnit DOM object.getType()
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
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.javascript.HtmlUnitScriptable
clone, equivalentValues, get, getBrowserVersion, getClassName, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getWindow, getWindow, getWithPreemption, has, hasInstance, initParentScope, makeScriptableFor, put, setClassName, setDomNode, setDomNode, setParentScope, setupPromise, setupRejectedPromise
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
-
Field Details
-
TYPE_NONE
- See Also:
-
TYPE_CARET
- See Also:
-
TYPE_RANGE
- See Also:
-
type_
-
-
Constructor Details
-
Selection
public Selection()Creates an instance.
-
-
Method Details
-
jsConstructor
public void jsConstructor()JavaScript constructor. -
jsToString
- Returns:
- a string currently being represented by the selection object, i.e. the currently selected text.
-
getDefaultValue
Returns the JavaScript default value of this object. This is the JavaScript equivalent of a toString() in Java.- Specified by:
getDefaultValue
in interfaceorg.htmlunit.corejs.javascript.Scriptable
- Overrides:
getDefaultValue
in classHtmlUnitScriptable
- Parameters:
hint
- a hint as to the format of the default value (ignored in this case)- Returns:
- the default value
-
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
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
Returns the type of selection (IE only).- Returns:
- the type of selection
-
addRange
Adds a range to the selection.- Parameters:
range
- the range to add
-
removeRange
Removes a range from the selection.- Parameters:
range
- the range to remove
-
removeAllRanges
public void removeAllRanges()Removes all ranges from the selection. -
getRangeAt
Returns the range at the specified index.- Parameters:
index
- the index of the range to return- Returns:
- the range at the specified index
-
collapse
Collapses the current selection to a single point. The document is not modified.- Parameters:
parentNode
- the caret location will be within this nodeoffset
- 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
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 movedoffset
- the number of characters from the beginning of parentNode's text the focus will be placed
-
selectAllChildren
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
Returns the current HtmlUnit DOM selection ranges.- Returns:
- the current HtmlUnit DOM selection ranges
-
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
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
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 benull
)- Returns:
- the scriptable object corresponding to the specified HtmlUnit DOM object, or
null
ifobject
wasnull
-