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 java.lang.Object
implements Range

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

Acknowledgment to Mozilla Foundation for making nsRange.cpp public.

Version:
$Id: DefaultRange.java 20039 2009-05-16 12:04:30Z sdumitriu $
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.
 java.lang.String toHTML()
          
 java.lang.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()
Duplicates the contents of this range.

Specified by:
cloneContents in interface Range
Returns:
a DocumentFragment that contains content equivalent to this range
See Also:
Range.cloneContents()

cloneRange

public Range cloneRange()
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
See Also:
Range.cloneRange()

collapse

public void collapse(boolean toStart)
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.
See Also:
Range.collapse(boolean)

compareBoundaryPoints

public short compareBoundaryPoints(RangeCompare how,
                                   Range sourceRange)
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
See Also:
Range.compareBoundaryPoints(RangeCompare, Range)

deleteContents

public void deleteContents()
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
See Also:
Range.deleteContents()

detach

public 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.

Specified by:
detach in interface Range
See Also:
Range.detach()

extractContents

public DocumentFragment extractContents()
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
See Also:
Range.extractContents(), deleteContents()

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
See Also:
Range.getCommonAncestorContainer()

getEndContainer

public com.google.gwt.dom.client.Node getEndContainer()

Specified by:
getEndContainer in interface Range
Returns:
the node within which this range ends
See Also:
Range.getEndContainer()

getEndOffset

public int getEndOffset()

Specified by:
getEndOffset in interface Range
Returns:
the offset within the ending node of this range
See Also:
Range.getEndOffset()

getStartContainer

public com.google.gwt.dom.client.Node getStartContainer()

Specified by:
getStartContainer in interface Range
Returns:
the node within which this range begins
See Also:
Range.getStartContainer()

getStartOffset

public int getStartOffset()

Specified by:
getStartOffset in interface Range
Returns:
the offset within the starting node of this range
See Also:
Range.getStartOffset()

insertNode

public void insertNode(com.google.gwt.dom.client.Node newNode)
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.
See Also:
Range.insertNode(Node)

isCollapsed

public boolean isCollapsed()

Specified by:
isCollapsed in interface Range
Returns:
true if this range is collapsed
See Also:
Range.isCollapsed()

selectNode

public void selectNode(com.google.gwt.dom.client.Node refNode)
Select a node and its contents.

Specified by:
selectNode in interface Range
Parameters:
refNode - the node to select
See Also:
Range.selectNode(Node)

selectNodeContents

public void selectNodeContents(com.google.gwt.dom.client.Node refNode)
Select the contents within a node.

Specified by:
selectNodeContents in interface Range
Parameters:
refNode - the node to select from
See Also:
Range.selectNodeContents(Node)

setEnd

public void setEnd(com.google.gwt.dom.client.Node refNode,
                   int offset)
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
See Also:
Range.setEnd(Node, int)

setEndAfter

public void setEndAfter(com.google.gwt.dom.client.Node refNode)
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
See Also:
Range.setEndAfter(Node)

setEndBefore

public void setEndBefore(com.google.gwt.dom.client.Node refNode)
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
See Also:
Range.setEndBefore(Node)

setStart

public void setStart(com.google.gwt.dom.client.Node refNode,
                     int offset)
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
See Also:
Range.setStart(Node, int)

setStartAfter

public void setStartAfter(com.google.gwt.dom.client.Node refNode)
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
See Also:
Range.setStartAfter(Node)

setStartBefore

public void setStartBefore(com.google.gwt.dom.client.Node refNode)
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
See Also:
Range.setStartBefore(Node)

surroundContents

public 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.

Specified by:
surroundContents in interface Range
Parameters:
newParent - the node to surround the contents with
See Also:
Range.surroundContents(Node)

toHTML

public java.lang.String toHTML()

Specified by:
toHTML in interface Range
Returns:
the HTML contents of this range
See Also:
Range.toHTML()

toString

public java.lang.String toString()
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 java.lang.Object
Returns:
the contents of this range
See Also:
Range.toString()


Copyright © 2004-2009 XWiki. All Rights Reserved.