Reviewed by justin
authorjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Dec 2005 02:05:12 +0000 (02:05 +0000)
committerjusting <justing@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Dec 2005 02:05:12 +0000 (02:05 +0000)
        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4682>
        -[WebHTMLView firstRectForCharacterRange:] is using _selectedRange instead of the given range if no marked text

        Added layout tests:
        * editing/input/firstrectforcharacterrange-styled
        * editing/input/firstrectforcharacterrange-plain

        * khtml/editing/visible_text.cpp:
        (khtml::TextIterator::rangeFromLocationAndLength):
        Return null if the range isn't found, instead of a startless/endless
        range.  Set the end if the requested location+length is out of bounds.
        * kwq/WebCoreBridge.mm:
        (-[WebCoreBridge convertToDOMRange:]): Handle larged unsigned values
        before calling rangeWithLocationAndLength, which expects signed ints.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@11707 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/khtml/editing/visible_text.cpp
WebCore/kwq/WebCoreBridge.mm

index badac58fc91b12206730fab9ab8eafa5b1d8a2e0..a79e6ba5216fc18bbbc2ae9517022e18fcd18a9b 100644 (file)
@@ -1,3 +1,22 @@
+2005-12-20  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by justin
+        
+        <http://bugzilla.opendarwin.org/show_bug.cgi?id=4682>
+        -[WebHTMLView firstRectForCharacterRange:] is using _selectedRange instead of the given range if no marked text
+
+        Added layout tests:
+        * editing/input/firstrectforcharacterrange-styled
+        * editing/input/firstrectforcharacterrange-plain
+
+        * khtml/editing/visible_text.cpp:
+        (khtml::TextIterator::rangeFromLocationAndLength): 
+        Return null if the range isn't found, instead of a startless/endless 
+        range.  Set the end if the requested location+length is out of bounds.
+        * kwq/WebCoreBridge.mm:
+        (-[WebCoreBridge convertToDOMRange:]): Handle larged unsigned values 
+        before calling rangeWithLocationAndLength, which expects signed ints.
+
 2005-12-20  Adele Peterson  <adele@apple.com>
 
         Reviewed by Darin.
index 531e34f796423ad763a50c79e343c68bc5d619ef..09e43504a2ed4da28f8f894ff86ae5c5c6ac93d4 100644 (file)
@@ -990,11 +990,16 @@ RangeImpl *TextIterator::rangeFromLocationAndLength(DocumentImpl *doc, int range
 
     int docTextPosition = 0;
     int rangeEnd = rangeLocation + rangeLength;
+    bool startRangeFound = false;
+
+    RefPtr<RangeImpl> textRunRange;
 
     for (TextIterator it(rangeOfContents(doc).get()); !it.atEnd(); it.advance()) {
         int len = it.length();
+        textRunRange = it.range();
+
         if (rangeLocation >= docTextPosition && rangeLocation <= docTextPosition + len) {
-            RefPtr<RangeImpl> textRunRange = it.range();
+            startRangeFound = true;
             int exception = 0;
             if (textRunRange->startContainer(exception)->isTextNode()) {
                 int offset = rangeLocation - docTextPosition;
@@ -1007,8 +1012,8 @@ RangeImpl *TextIterator::rangeFromLocationAndLength(DocumentImpl *doc, int range
                 }
             }
         }
+
         if (rangeEnd >= docTextPosition && rangeEnd <= docTextPosition + len) {
-            RefPtr<RangeImpl> textRunRange = it.range();
             int exception = 0;
             if (textRunRange->startContainer(exception)->isTextNode()) {
                 int offset = rangeEnd - docTextPosition;
@@ -1020,13 +1025,24 @@ RangeImpl *TextIterator::rangeFromLocationAndLength(DocumentImpl *doc, int range
                     resultRange->setEnd(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception);
                 }
             }
-            if ( !(rangeLength == 0 && rangeEnd == docTextPosition + len) ) {
+            if (!(rangeLength == 0 && rangeEnd == docTextPosition + len)) {
+                docTextPosition += len;
                 break;
             }
         }
-        docTextPosition += it.length();
+        docTextPosition += len;
     }
-
+    
+    if (!startRangeFound) {
+        delete resultRange;
+        return 0;
+    }
+    
+    if (rangeLength != 0 && rangeEnd > docTextPosition) { // rangeEnd is out of bounds
+        int exception = 0;
+        resultRange->setEnd(textRunRange->endContainer(exception), textRunRange->endOffset(exception), exception);
+    }
+    
     return resultRange;
 }
 
index 27f4f199c1861a7e9df38eaefbe09afc3f711cd4..c0dc90f60c5fe4bebc2aaed6c27214cd8ab8d7e2 100644 (file)
@@ -1679,6 +1679,11 @@ static HTMLFormElementImpl *formElementFromDOMElement(DOMElement *element)
 
 - (RangeImpl *)convertToDOMRange:(NSRange)nsrange
 {
+    if (nsrange.location > INT_MAX)
+        return 0;
+    if (nsrange.length > INT_MAX || nsrange.location + nsrange.length > INT_MAX)
+        nsrange.length = INT_MAX - nsrange.location;
+
     return TextIterator::rangeFromLocationAndLength(_part->xmlDocImpl(), nsrange.location, nsrange.length);
 }