nddelima 2004/08/04 14:09:06
Modified: java/src/org/apache/xerces/dom RangeImpl.java
Log:
DOM Ranges Fix: The start position of a Range is guaranteed to never be after the
end position. To enforce this restriction, if the start is set to be at a position
after the end, the Range is collapsed to that position. Similarly, if the end is set
to be at a position before the start, the Range is collapsed to that position.
Revision Changes Path
1.31 +44 -28 xml-xerces/java/src/org/apache/xerces/dom/RangeImpl.java
Index: RangeImpl.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/RangeImpl.java,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- RangeImpl.java 4 Aug 2004 20:24:13 -0000 1.30
+++ RangeImpl.java 4 Aug 2004 21:09:05 -0000 1.31
@@ -174,12 +174,15 @@
fStartContainer = refNode;
fStartOffset = offset;
- // If one boundary-point of a Range is set to have a root container other
+ // If one boundary-point of a Range is set to have a root container
+ // other
// than the current one for the Range, the Range should be collapsed to
// the new position.
- if (getCommonAncestorContainer() == null ) {
- collapse(true);
- }
+ // The start position of a Range should never be after the end position.
+ if (getCommonAncestorContainer() == null
+ || (fStartContainer == fEndContainer && fEndOffset < fStartOffset))
{
+ collapse(true);
+ }
}
public void setEnd(Node refNode, int offset)
@@ -206,13 +209,15 @@
fEndContainer = refNode;
fEndOffset = offset;
- // If one boundary-point of a Range is set to have a root container other
+ // If one boundary-point of a Range is set to have a root container
+ // other
// than the current one for the Range, the Range should be collapsed to
// the new position.
- if (getCommonAncestorContainer() == null ) {
- collapse(true);
- }
-
+ // The start position of a Range should never be after the end position.
+ if (getCommonAncestorContainer() == null
+ || (fStartContainer == fEndContainer && fEndOffset < fStartOffset))
{
+ collapse(false);
+ }
}
public void setStartBefore(Node refNode)
@@ -242,12 +247,15 @@
}
fStartOffset = i-1;
- // If one boundary-point of a Range is set to have a root container other
+ // If one boundary-point of a Range is set to have a root container
+ // other
// than the current one for the Range, the Range should be collapsed to
// the new position.
- if (getCommonAncestorContainer() == null ) {
- collapse(true);
- }
+ // The start position of a Range should never be after the end position.
+ if (getCommonAncestorContainer() == null
+ || (fStartContainer == fEndContainer && fEndOffset < fStartOffset))
{
+ collapse(true);
+ }
}
public void setStartAfter(Node refNode)
@@ -276,12 +284,15 @@
}
fStartOffset = i;
- // If one boundary-point of a Range is set to have a root container other
+ // If one boundary-point of a Range is set to have a root container
+ // other
// than the current one for the Range, the Range should be collapsed to
// the new position.
- if (getCommonAncestorContainer() == null ) {
- collapse(true);
- }
+ // The start position of a Range should never be after the end position.
+ if (getCommonAncestorContainer() == null
+ || (fStartContainer == fEndContainer && fEndOffset < fStartOffset))
{
+ collapse(true);
+ }
}
public void setEndBefore(Node refNode)
@@ -310,12 +321,15 @@
}
fEndOffset = i-1;
- // If one boundary-point of a Range is set to have a root container other
+ // If one boundary-point of a Range is set to have a root container
+ // other
// than the current one for the Range, the Range should be collapsed to
// the new position.
- if (getCommonAncestorContainer() == null ) {
- collapse(false);
- }
+ // The start position of a Range should never be after the end position.
+ if (getCommonAncestorContainer() == null
+ || (fStartContainer == fEndContainer && fEndOffset < fStartOffset))
{
+ collapse(false);
+ }
}
public void setEndAfter(Node refNode)
@@ -344,12 +358,15 @@
}
fEndOffset = i;
- // If one boundary-point of a Range is set to have a root container other
- // than the current one for the Range, the Range should be collapsed to
- // the new position.
- if (getCommonAncestorContainer() == null ) {
+ // If one boundary-point of a Range is set to have a root container
+ // other
+ // than the current one for the Range, the Range should be collapsed to
+ // the new position.
+ // The start position of a Range should never be after the end position.
+ if (getCommonAncestorContainer() == null
+ || (fStartContainer == fEndContainer && fEndOffset < fStartOffset))
{
collapse(false);
- }
+ }
}
public void collapse(boolean toStart) {
@@ -712,7 +729,6 @@
Range range = fDocument.createRange();
range.setStart(fStartContainer, fStartOffset);
range.setEnd(fEndContainer, fEndOffset);
- //System.out.println ("Clone Range " + fStartOffset);
return range;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]