org.xwiki.gwt.dom.client.internal
Class DefaultRange

java.lang.Object
  extended by org.xwiki.gwt.dom.client.internal.DefaultRange
All Implemented Interfaces:
Range
Direct Known Subclasses:
DefaultNativeRangeWrapper

public class DefaultRange
extends Object
implements Range

This is a cross-browser implementation of the W3C Range specification.

Acknowledgment to Mozilla Foundation for making nsRange.cpp public.

See Also:
"http://hg.mozilla.org/mozilla-central/file/b945b4f67e7e/content/base/src/nsRange.cpp"

Constructor Summary
DefaultRange()
           
 
Method Summary
 DocumentFragment cloneContents()
          Duplicates the contents of this range.
 Range cloneRange()
          Produces a new Range whose boundary-points are equal to the boundary-points of this range.
 void collapse(boolean toStart)
          Collapse this range onto one of its boundary-points.
 short compareBoundaryPoints(RangeCompare how, Range sourceRange)
          Compare the boundary-points of two Ranges in a document.
 void deleteContents()
          Removes the contents of this range from the containing document or document fragment without returning a reference to the removed content.
 void detach()
          Called to indicate that this range is no longer in use and that the implementation may relinquish any resources associated with this range.
 DocumentFragment extractContents()
          Moves the contents of this range from the containing document or document fragment to a new DocumentFragment.
 com.google.gwt.dom.client.Node getCommonAncestorContainer()
           
 com.google.gwt.dom.client.Node getEndContainer()
           
 int getEndOffset()
           
 com.google.gwt.dom.client.Node getStartContainer()
           
 int getStartOffset()
           
 void insertNode(com.google.gwt.dom.client.Node newNode)
          Inserts a node into the Document or DocumentFragment at the start of the Range.
 boolean isCollapsed()
           
 void selectNode(com.google.gwt.dom.client.Node refNode)
          Select a node and its contents.
 void selectNodeContents(com.google.gwt.dom.client.Node refNode)
          Select the contents within a node.
 void setEnd(com.google.gwt.dom.client.Node refNode, int offset)
          Sets the attributes describing the end of this range.
 void setEndAfter(com.google.gwt.dom.client.Node refNode)
          Sets the end of this Range to be after the given node.
 void setEndBefore(com.google.gwt.dom.client.Node refNode)
          Sets the end position to be before the given node.
 void setStart(com.google.gwt.dom.client.Node refNode, int offset)
          Sets the attributes describing the start of this range.
 void setStartAfter(com.google.gwt.dom.client.Node refNode)
          Sets the start position to be after the given node.
 void setStartBefore(com.google.gwt.dom.client.Node refNode)
          Sets the start position to be before the given node.
 void surroundContents(com.google.gwt.dom.client.Node newParent)
          Re-parents the contents of this range to the given node and inserts the node at the position of the start of this range.
 String toHTML()
           
 String toString()
          Returns the contents of this range as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultRange

public DefaultRange()
Method Detail

cloneContents

public DocumentFragment cloneContents()
Description copied from interface: Range
Duplicates the contents of this range.

Specified by:
cloneContents in interface Range
Returns:
a DocumentFragment that contains content equivalent to this range

cloneRange

public Range cloneRange()
Description copied from interface: Range
Produces a new Range whose boundary-points are equal to the boundary-points of this range.

Specified by:
cloneRange in interface Range
Returns:
the duplicated range

collapse

public void collapse(boolean toStart)
Description copied from interface: Range
Collapse this range onto one of its boundary-points.

Specified by:
collapse in interface Range
Parameters:
toStart - if true, collapses this range onto its start; if false, collapses it onto its end.

compareBoundaryPoints

public short compareBoundaryPoints(RangeCompare how,
                                   Range sourceRange)
Description copied from interface: Range
Compare the boundary-points of two Ranges in a document.

Specified by:
compareBoundaryPoints in interface Range
Parameters:
how - the type of comparison
sourceRange - the range to compared to
Returns:
-1, 0 or 1 depending on whether the corresponding boundary-point of this range is respectively before, equal to, or after the corresponding boundary-point of sourceRange

deleteContents

public void deleteContents()
Description copied from interface: Range
Removes the contents of this range from the containing document or document fragment without returning a reference to the removed content.

Specified by:
deleteContents in interface Range

detach

public void detach()
Description copied from interface: Range
Called to indicate that this range is no longer in use and that the implementation may relinquish any resources associated with this range.

Specified by:
detach in interface Range

extractContents

public DocumentFragment extractContents()
Description copied from interface: Range
Moves the contents of this range from the containing document or document fragment to a new DocumentFragment.

Specified by:
extractContents in interface Range
Returns:
a DocumentFragment containing the extracted contents

getCommonAncestorContainer

public com.google.gwt.dom.client.Node getCommonAncestorContainer()
Specified by:
getCommonAncestorContainer in interface Range
Returns:
the deepest common ancestor container of this range's two boundary-points

getEndContainer

public com.google.gwt.dom.client.Node getEndContainer()
Specified by:
getEndContainer in interface Range
Returns:
the node within which this range ends

getEndOffset

public int getEndOffset()
Specified by:
getEndOffset in interface Range
Returns:
the offset within the ending node of this range

getStartContainer

public com.google.gwt.dom.client.Node getStartContainer()
Specified by:
getStartContainer in interface Range
Returns:
the node within which this range begins

getStartOffset

public int getStartOffset()
Specified by:
getStartOffset in interface Range
Returns:
the offset within the starting node of this range

insertNode

public void insertNode(com.google.gwt.dom.client.Node newNode)
Description copied from interface: Range
Inserts a node into the Document or DocumentFragment at the start of the Range. If the container is a Text node, this will be split at the start of the Range (as if the Text node's splitText method was performed at the insertion point) and the insertion will occur between the two resulting Text nodes. Adjacent Text nodes will not be automatically merged. If the node to be inserted is a DocumentFragment node, the children will be inserted rather than the DocumentFragment node itself.

Specified by:
insertNode in interface Range
Parameters:
newNode - the node to insert at the start of this range.

isCollapsed

public boolean isCollapsed()
Specified by:
isCollapsed in interface Range
Returns:
true if this range is collapsed

selectNode

public void selectNode(com.google.gwt.dom.client.Node refNode)
Description copied from interface: Range
Select a node and its contents.

Specified by:
selectNode in interface Range
Parameters:
refNode - the node to select

selectNodeContents

public void selectNodeContents(com.google.gwt.dom.client.Node refNode)
Description copied from interface: Range
Select the contents within a node.

Specified by:
selectNodeContents in interface Range
Parameters:
refNode - the node to select from

setEnd

public void setEnd(com.google.gwt.dom.client.Node refNode,
                   int offset)
Description copied from interface: Range
Sets the attributes describing the end of this range.

Specified by:
setEnd in interface Range
Parameters:
refNode - the #endContainer value. This parameter must be different from null.
offset - the #endOffset value

setEndAfter

public void setEndAfter(com.google.gwt.dom.client.Node refNode)
Description copied from interface: Range
Sets the end of this Range to be after the given node.

Specified by:
setEndAfter in interface Range
Parameters:
refNode - the reference node, after which this range will end

setEndBefore

public void setEndBefore(com.google.gwt.dom.client.Node refNode)
Description copied from interface: Range
Sets the end position to be before the given node.

Specified by:
setEndBefore in interface Range
Parameters:
refNode - the reference node, before which this range will end

setStart

public void setStart(com.google.gwt.dom.client.Node refNode,
                     int offset)
Description copied from interface: Range
Sets the attributes describing the start of this range.

Specified by:
setStart in interface Range
Parameters:
refNode - the #startContainer value. This parameter must be different from null.
offset - the #startOffset value

setStartAfter

public void setStartAfter(com.google.gwt.dom.client.Node refNode)
Description copied from interface: Range
Sets the start position to be after the given node.

Specified by:
setStartAfter in interface Range
Parameters:
refNode - the reference node, after which this range will start

setStartBefore

public void setStartBefore(com.google.gwt.dom.client.Node refNode)
Description copied from interface: Range
Sets the start position to be before the given node.

Specified by:
setStartBefore in interface Range
Parameters:
refNode - the reference node, before which this range will start

surroundContents

public void surroundContents(com.google.gwt.dom.client.Node newParent)
Description copied from interface: Range
Re-parents the contents of this range to the given node and inserts the node at the position of the start of this range.

Specified by:
surroundContents in interface Range
Parameters:
newParent - the node to surround the contents with

toHTML

public String toHTML()
Specified by:
toHTML in interface Range
Returns:
the HTML contents of this range

toString

public String toString()
Description copied from interface: Range
Returns the contents of this range as a string. This string contains only the data characters, not any mark-up.

Specified by:
toString in interface Range
Overrides:
toString in class Object
Returns:
the contents of this range