<rdar://problem/8891395> -[DOMRange textRects] returns incorrect results for vertical...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 May 2011 22:33:25 +0000 (22:33 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 May 2011 22:33:25 +0000 (22:33 +0000)
https://bugs.webkit.org/show_bug.cgi?id=60067

Reviewed by Darin Adler.

No test because this code path is only used by the Objective-C API, which is not testable from DumpRenderTree.

* rendering/RenderText.cpp:
(WebCore::RenderText::absoluteRectsForRange): Use width/height instead of logicalWidth/logicalHeight here,
and perform the local-to-absolute mapping on the rects rather than their origin, in order to get the right
results for flipped writing modes.

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

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderText.cpp

index 23416e3..d2f24c6 100644 (file)
@@ -1,3 +1,17 @@
+2011-05-03  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Darin Adler.
+
+        <rdar://problem/8891395> -[DOMRange textRects] returns incorrect results for vertical or flipped text
+        https://bugs.webkit.org/show_bug.cgi?id=60067
+
+        No test because this code path is only used by the Objective-C API, which is not testable from DumpRenderTree.
+
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::absoluteRectsForRange): Use width/height instead of logicalWidth/logicalHeight here,
+        and perform the local-to-absolute mapping on the rects rather than their origin, in order to get the right
+        results for flipped writing modes.
+
 2011-05-03  Anton Muhin  <antonm@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index 106526c..7f1be55 100644 (file)
@@ -291,30 +291,33 @@ void RenderText::absoluteRectsForRange(Vector<IntRect>& rects, unsigned start, u
     for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
         // Note: box->end() returns the index of the last character, not the index past it
         if (start <= box->start() && box->end() < end) {
-            IntRect r = IntRect(box->x(), box->y(), box->logicalWidth(), box->logicalHeight());
+            IntRect r = box->calculateBoundaries();
             if (useSelectionHeight) {
                 IntRect selectionRect = box->selectionRect(0, 0, start, end);
-                r.setHeight(selectionRect.height());
-                r.setY(selectionRect.y());
+                if (box->isHorizontal()) {
+                    r.setHeight(selectionRect.height());
+                    r.setY(selectionRect.y());
+                } else {
+                    r.setWidth(selectionRect.width());
+                    r.setX(selectionRect.x());
+                }
             }
-            FloatPoint origin = localToAbsolute(r.location());
-            r.setX(origin.x());
-            r.setY(origin.y());
-            rects.append(r);
+            rects.append(localToAbsoluteQuad(FloatQuad(r)).enclosingBoundingBox());
         } else {
             unsigned realEnd = min(box->end() + 1, end);
             IntRect r = box->selectionRect(0, 0, start, realEnd);
             if (!r.isEmpty()) {
                 if (!useSelectionHeight) {
                     // change the height and y position because selectionRect uses selection-specific values
-                    r.setHeight(box->logicalHeight());
-                    r.setY(box->y());
+                    if (box->isHorizontal()) {
+                        r.setHeight(box->logicalHeight());
+                        r.setY(box->y());
+                    } else {
+                        r.setWidth(box->logicalWidth());
+                        r.setX(box->x());
+                    }
                 }
-                FloatPoint origin = localToAbsolute(r.location());
-                localToAbsolute(origin);
-                r.setX(origin.x());
-                r.setY(origin.y());
-                rects.append(r);
+                rects.append(localToAbsoluteQuad(FloatQuad(r)).enclosingBoundingBox());
             }
         }
     }