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:
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 forSelection
.- See Also:
- MSDN Documentation, Gecko DOM Reference, Serialized Form
-
-
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
-
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.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 Detail
-
TYPE_NONE
private static final java.lang.String TYPE_NONE
- See Also:
- Constant Field Values
-
TYPE_CARET
private static final java.lang.String TYPE_CARET
- See Also:
- Constant Field Values
-
TYPE_RANGE
private static final java.lang.String TYPE_RANGE
- See Also:
- Constant Field Values
-
type_
private java.lang.String type_
-
-
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 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
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 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
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 movedoffset
- 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 benull
)- Returns:
- the scriptable object corresponding to the specified HtmlUnit DOM object, or
null
ifobject
wasnull
-
-