org.xwiki.gwt.dom.client.internal.ie
Class IESelection

java.lang.Object
  extended by org.xwiki.gwt.dom.client.internal.AbstractSelection
      extended by org.xwiki.gwt.dom.client.internal.ie.IESelection
All Implemented Interfaces:
Selection

public class IESelection
extends AbstractSelection

The implementation of Mozilla's selection specification using Internet Explorer's selection API.

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

Nested Class Summary
protected static class IESelection.RangeBoundary
          Specifies where a range starts or ends inside the DOM tree.
 
Constructor Summary
IESelection(NativeSelection nativeSelection)
          Creates a new instance that wraps the given native selection object.
 
Method Summary
 void addRange(Range range)
          Adds a range to this selection.
protected  void addTextRange(Range range)
          Creates a text selection from the given range.
protected  Element createBoundaryMarker()
           
protected  IESelection.RangeBoundary getBoundary(TextRange textRange, boolean start)
          Computes the start or end container of a text range.
protected  int getFirstLineHeight(TextRange textRange)
           
protected  int getLeft(Element element)
          NOTE: For a strong element that starts in the middle of a line and spans multiple lines this method returns the distance in pixels from its first character (provided it starts with text) to the left boundary of the parent window.
protected  NativeSelection getNativeSelection()
           
protected  int getOffset(TextRange left, TextRange right, boolean rightBoundary)
          Computes the number of characters between the start of the left range to the specified boundary of the right range.
 Range getRangeAt(int index)
          
 int getRangeCount()
          
protected  int getTop(Element element)
           
protected  void moveTextRangeBeforeElement(TextRange textRange, Element element)
          Moves the given text range before the specified element.
 void removeAllRanges()
          Removes all ranges from the current selection.
 void removeRange(Range range)
          Removes the given range from the selection.
 
Methods inherited from class org.xwiki.gwt.dom.client.internal.AbstractSelection
collapse, collapseToEnd, collapseToStart, containsNode, deleteFromDocument, extend, getAnchorNode, getAnchorOffset, getFocusNode, getFocusOffset, isCollapsed, selectAllChildren, selectionLanguageChange, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IESelection

public IESelection(NativeSelection nativeSelection)
Creates a new instance that wraps the given native selection object. This object will be used to implement Mozilla's selection specification.

Parameters:
nativeSelection - the underlying native selection object to be used
Method Detail

getNativeSelection

protected NativeSelection getNativeSelection()
Returns:
nativeSelection

addRange

public void addRange(Range range)
Adds a range to this selection.

Parameters:
range - the range to be added
See Also:
Selection.addRange(Range)

addTextRange

protected void addTextRange(Range range)
Creates a text selection from the given range.

Parameters:
range - the range to be added to the selection

createBoundaryMarker

protected Element createBoundaryMarker()
Returns:
an element that can be used a range boundary marker for this selection

getRangeAt

public Range getRangeAt(int index)

Parameters:
index - the index of the range to retrieve. Usually the selection contains just one range.
Returns:
the range at the specified index
See Also:
Selection.getRangeAt(int)

getRangeCount

public int getRangeCount()

Returns:
the number of ranges in the selection
See Also:
Selection.getRangeCount()

removeAllRanges

public void removeAllRanges()
Removes all ranges from the current selection.

See Also:
Selection.removeAllRanges()

removeRange

public void removeRange(Range range)
Removes the given range from the selection.

Parameters:
range - the range to be removed from the selection.
See Also:
Selection.removeRange(Range)

getBoundary

protected IESelection.RangeBoundary getBoundary(TextRange textRange,
                                                boolean start)
Computes the start or end container of a text range.

Parameters:
textRange - the text range for which to compute the boundary container
start - specifies which boundary container to compute
Returns:
the container of the range's start , if start is true, or the container of the range's end, otherwise

moveTextRangeBeforeElement

protected void moveTextRangeBeforeElement(TextRange textRange,
                                          Element element)
Moves the given text range before the specified element.

Parameters:
textRange - the text range to be moved
element - the element before which the text range is moved

getLeft

protected int getLeft(Element element)
NOTE: For a strong element that starts in the middle of a line and spans multiple lines this method returns the distance in pixels from its first character (provided it starts with text) to the left boundary of the parent window. This is important since the bounding rectangle of the strong element can have the width of the parent window so the distance from the left side of this bounding rectangle to the left boundary of the parent window could be 0.

Parameters:
element - a DOM element
Returns:
the distance, in pixels, from the given element's start point to the left boundary of the parent window

getTop

protected int getTop(Element element)
Parameters:
element - a DOM element
Returns:
the distance, in pixels, from the given element's start point to the top boundary of the parent window

getFirstLineHeight

protected int getFirstLineHeight(TextRange textRange)
Parameters:
textRange - a text range
Returns:
the height, in pixels, of the first line selected by the given text range

getOffset

protected int getOffset(TextRange left,
                        TextRange right,
                        boolean rightBoundary)
Computes the number of characters between the start of the left range to the specified boundary of the right range. The given ranges need to overlap and the start of the left range has to be before or equal to the specified boundary of the right range.

Parameters:
left - the left text range
right - the rich text range
rightBoundary - specifies which boundary of the right text range to consider. Use true for start boundary and false for end boundary.
Returns:
the offset of the right range from the start of the left range


Copyright © 2004-2009 XWiki. All Rights Reserved.