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

java.lang.Object
  extended by org.xwiki.gwt.dom.client.internal.AbstractSelection
All Implemented Interfaces:
Selection
Direct Known Subclasses:
DefaultSelection, IESelection

public abstract class AbstractSelection
extends java.lang.Object
implements Selection

Abstract Selection implementation.

NOTE: In the current implementation we often make the assumption that the selection contains at most one range. All the other ranges, if they exist, are sometimes ignored. Additionally, but somehow as a consequence, we consider the anchor node as being the start container of the first range and the focus node as the end container of the first range. This has to do with the fact that not all the browsers distinguish the direction in which the user makes the selection (from left to right or the opposite).

Version:
$Id: AbstractSelection.java 20039 2009-05-16 12:04:30Z sdumitriu $

Constructor Summary
AbstractSelection()
           
 
Method Summary
 void collapse(com.google.gwt.dom.client.Node parentNode, int offset)
          Collapses the selection to a single point, at the specified offset in the given DOM node.
 void collapseToEnd()
          Collapses the whole selection to a single point at the end of the current selection (irrespective of direction).
 void collapseToStart()
          Collapses the whole selection to a single point at the start of the current selection (irrespective of direction).
 boolean containsNode(com.google.gwt.dom.client.Node node, boolean partlyContained)
          Indicates whether the given node is part of the selection.
 void deleteFromDocument()
          Deletes this selection from document the nodes belong to.
 void extend(com.google.gwt.dom.client.Node parentNode, int offset)
          Extends the selection by moving the selection end to the specified node and offset, preserving the selection begin position.
 com.google.gwt.dom.client.Node getAnchorNode()
          
 int getAnchorOffset()
          
 com.google.gwt.dom.client.Node getFocusNode()
          
 int getFocusOffset()
          
 boolean isCollapsed()
          
 void selectAllChildren(com.google.gwt.dom.client.Node parentNode)
          Adds all children of the specified node to the selection.
 void selectionLanguageChange(boolean langRTL)
          Modifies the cursor Bidi level after a change in keyboard direction.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.xwiki.gwt.dom.client.Selection
addRange, getRangeAt, getRangeCount, removeAllRanges, removeRange
 

Constructor Detail

AbstractSelection

public AbstractSelection()
Method Detail

collapse

public void collapse(com.google.gwt.dom.client.Node parentNode,
                     int offset)
Collapses the selection to a single point, at the specified offset in the given DOM node. When the selection is collapsed, and the content is focused and editable, the caret will blink there.

Specified by:
collapse in interface Selection
Parameters:
parentNode - the DOM node where the selection will be set
offset - specifies where to place the selection in the given node
See Also:
Selection.collapse(Node, int)

collapseToEnd

public void collapseToEnd()
Collapses the whole selection to a single point at the end of the current selection (irrespective of direction). If content is focused and editable, the caret will blink there.

Specified by:
collapseToEnd in interface Selection
See Also:
Selection.collapseToEnd()

collapseToStart

public void collapseToStart()
Collapses the whole selection to a single point at the start of the current selection (irrespective of direction). If content is focused and editable, the caret will blink there.

Specified by:
collapseToStart in interface Selection
See Also:
Selection.collapseToStart()

containsNode

public boolean containsNode(com.google.gwt.dom.client.Node node,
                            boolean partlyContained)
Indicates whether the given node is part of the selection.

Specified by:
containsNode in interface Selection
Parameters:
node - the DOM node to be tested
partlyContained - if false, the entire subtree rooted in the given node is tested
Returns:
true when the entire node is part of the selection
See Also:
Selection.containsNode(Node, boolean)

deleteFromDocument

public void deleteFromDocument()
Deletes this selection from document the nodes belong to.

Specified by:
deleteFromDocument in interface Selection
See Also:
Selection.deleteFromDocument()

extend

public void extend(com.google.gwt.dom.client.Node parentNode,
                   int offset)
Extends the selection by moving the selection end to the specified node and offset, preserving the selection begin position. The new selection end result will always be from the anchorNode to the new focusNode, regardless of direction.

Specified by:
extend in interface Selection
Parameters:
parentNode - the node where the selection will be extended to
offset - specifies where to end the selection in the given node
See Also:
Selection.extend(Node, int)

getAnchorNode

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

Specified by:
getAnchorNode in interface Selection
Returns:
the node in which the selection begins
See Also:
Selection.getAnchorNode()

getAnchorOffset

public int getAnchorOffset()

Specified by:
getAnchorOffset in interface Selection
Returns:
the offset within the Selection.getAnchorNode() where the selection begins
See Also:
Selection.getAnchorOffset()

getFocusNode

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

Specified by:
getFocusNode in interface Selection
Returns:
the node in which the selection ends
See Also:
Selection.getFocusNode()

getFocusOffset

public int getFocusOffset()

Specified by:
getFocusOffset in interface Selection
Returns:
the offset within the Selection.getFocusNode() where the selection ends.
See Also:
Selection.getFocusOffset()

isCollapsed

public boolean isCollapsed()

Specified by:
isCollapsed in interface Selection
Returns:
true if the selection is collapsed
See Also:
Selection.isCollapsed()

selectAllChildren

public void selectAllChildren(com.google.gwt.dom.client.Node parentNode)
Adds all children of the specified node to the selection. Previous selection is lost.

Specified by:
selectAllChildren in interface Selection
Parameters:
parentNode - the parent of the children to be added to the selection
See Also:
Selection.selectAllChildren(Node)

selectionLanguageChange

public void selectionLanguageChange(boolean langRTL)
Modifies the cursor Bidi level after a change in keyboard direction.

Specified by:
selectionLanguageChange in interface Selection
Parameters:
langRTL - is true if the new language is right-to-left or false if the new language is left-to-right
See Also:
Selection.selectionLanguageChange(boolean)

toString

public java.lang.String toString()

Specified by:
toString in interface Selection
Overrides:
toString in class java.lang.Object
Returns:
the currently selected text
See Also:
Selection.toString()


Copyright © 2004-2009 XWiki. All Rights Reserved.