com.gargoylesoftware.htmlunit.javascript.host
Class TextRange

java.lang.Object
  extended by net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
      extended by com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
          extended by com.gargoylesoftware.htmlunit.javascript.host.TextRange
All Implemented Interfaces:
Serializable, Cloneable, net.sourceforge.htmlunit.corejs.javascript.ConstProperties, net.sourceforge.htmlunit.corejs.javascript.debug.DebuggableObject, net.sourceforge.htmlunit.corejs.javascript.Scriptable

public class TextRange
extends SimpleScriptable

A JavaScript object for a TextRange (IE only).

Version:
$Revision: 8931 $
Author:
Ahmed Ashour, Marc Guillemot, David Gileadi
See Also:
MSDN documentation (1), MSDN documentation (2), Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface net.sourceforge.htmlunit.corejs.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
TextRange()
          Default constructor used to build the prototype.
TextRange(HTMLElement elt)
          Constructs a text range around the provided element.
TextRange(org.w3c.dom.ranges.Range range)
          Constructs a text range around the provided range.
 
Method Summary
 void collapse(boolean toStart)
          Collapses the range.
protected  int constrainMoveBy(int moveBy, int current, int textLength)
          Constrain the given amount to move the range by to the limits of the given current offset and text length.
 Object duplicate()
          Duplicates this TextRange instance.
 String getBookmark()
          Retrieves a bookmark (opaque string) that can be used with moveToBookmark(java.lang.String) to return to the same range.
 String getHtmlText()
          Retrieves the HTML fragment contained within the range.
 String getText()
          Retrieves the text contained within the range.
 boolean inRange(TextRange other)
          Indicates if a range is contained in current one.
 int moveEnd(String unit, Object count)
          Changes the end position of the range.
 int moveStart(String unit, Object count)
          Changes the start position of the range.
 boolean moveToBookmark(String bookmark)
          Moves to a bookmark.
 void moveToElementText(HTMLElement element)
          Moves the text range so that the start and end positions of the range encompass the text in the specified element.
 Node parentElement()
          Retrieves the parent element for the given text range.
 void select()
          Makes the current range the active selection.
 void setEndPoint(String type, TextRange other)
          Sets the endpoint of the range based on the endpoint of another range..
 void setText(String text)
          Sets the text contained within the range.
 
Methods inherited from class com.gargoylesoftware.htmlunit.javascript.SimpleScriptable
clone, defineFunctionProperties, defineProperty, equivalentValues, get, getBrowserVersion, getClassName, getDefaultValue, getDomNodeOrDie, getDomNodeOrNull, getPrototype, getScriptableFor, getStartingScope, getTransformerScriptableFor, getWindow, getWindow, getWithPreemption, hasInstance, initParentScope, isReadOnlySettable, makeScriptableFor, setCaseSensitive, setDomNode, setDomNode, setHtmlElement, setParentScope
 
Methods inherited from class net.sourceforge.htmlunit.corejs.javascript.ScriptableObject
applyDescriptorToAttributeBitset, associateValue, avoidObjectDetection, buildDataDescriptor, callMethod, callMethod, checkPropertyChange, checkPropertyDefinition, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineOwnProperties, defineOwnProperty, defineOwnProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, ensureScriptable, ensureScriptableObject, get, get, getAllIds, getArrayPrototype, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getOwnPropertyDescriptor, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getSlot, getTopLevelScope, getTopScopeValue, getTypedProperty, getTypedProperty, getTypeOf, has, has, hasProperty, hasProperty, isAccessorDescriptor, isConst, isDataDescriptor, isEmpty, isExtensible, isFalse, isGenericDescriptor, isGetterOrSetter, isSealed, isTrue, preventExtensions, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sameValue, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setPrototype, size
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextRange

public TextRange()
Default constructor used to build the prototype.


TextRange

public TextRange(HTMLElement elt)
Constructs a text range around the provided element.

Parameters:
elt - the element to wrap

TextRange

public TextRange(org.w3c.dom.ranges.Range range)
Constructs a text range around the provided range.

Parameters:
range - the initial range
Method Detail

getText

public String getText()
Retrieves the text contained within the range.

Returns:
the text contained within the range

setText

public void setText(String text)
Sets the text contained within the range.

Parameters:
text - the text contained within the range

getHtmlText

public String getHtmlText()
Retrieves the HTML fragment contained within the range.

Returns:
the HTML fragment contained within the range

duplicate

public Object duplicate()
Duplicates this TextRange instance.

Returns:
a duplicate of this TextRange instance
See Also:
MSDN documentation

parentElement

public Node parentElement()
Retrieves the parent element for the given text range. The parent element is the element that completely encloses the text in the range. If the text range spans text in more than one element, this method returns the smallest element that encloses all the elements. When you insert text into a range that spans multiple elements, the text is placed in the parent element rather than in any of the contained elements.

Returns:
the parent element object if successful, or null otherwise.
See Also:
MSDN doc

collapse

public void collapse(boolean toStart)
Collapses the range.

Parameters:
toStart - indicates if collapse should be done to the start
See Also:
MSDN doc

select

public void select()
Makes the current range the active selection.

See Also:
MSDN doc

moveStart

public int moveStart(String unit,
                     Object count)
Changes the start position of the range.

Parameters:
unit - specifies the units to move
count - the number of units to move
Returns:
the number of units moved

moveEnd

public int moveEnd(String unit,
                   Object count)
Changes the end position of the range.

Parameters:
unit - specifies the units to move
count - the number of units to move
Returns:
the number of units moved

moveToElementText

public void moveToElementText(HTMLElement element)
Moves the text range so that the start and end positions of the range encompass the text in the specified element.

Parameters:
element - the element to move to
See Also:
MSDN Documentation

inRange

public boolean inRange(TextRange other)
Indicates if a range is contained in current one.

Parameters:
other - the other range
Returns:
true if other is contained within current range
See Also:
MSDN doc

setEndPoint

public void setEndPoint(String type,
                        TextRange other)
Sets the endpoint of the range based on the endpoint of another range..

Parameters:
type - end point transfer type. One of "StartToEnd", "StartToStart", "EndToStart" and "EndToEnd"
other - the other range
See Also:
MSDN doc

constrainMoveBy

protected int constrainMoveBy(int moveBy,
                              int current,
                              int textLength)
Constrain the given amount to move the range by to the limits of the given current offset and text length.

Parameters:
moveBy - the amount to move by
current - the current index
textLength - the text length
Returns:
the moveBy amount constrained to the text length

getBookmark

public String getBookmark()
Retrieves a bookmark (opaque string) that can be used with moveToBookmark(java.lang.String) to return to the same range. The current implementation return empty string

Returns:
the bookmark

moveToBookmark

public boolean moveToBookmark(String bookmark)
Moves to a bookmark. The current implementation does nothing

Parameters:
bookmark - the bookmark
Returns:
false


Copyright © 2002–2014 Gargoyle Software Inc.. All rights reserved.