https://bugs.webkit.org/show_bug.cgi?id=51851
authorjustin.garcia@apple.com <justin.garcia@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jan 2011 02:59:58 +0000 (02:59 +0000)
committerjustin.garcia@apple.com <justin.garcia@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Jan 2011 02:59:58 +0000 (02:59 +0000)
Implement RenderSVGInlineText::localCaretRect()

Reviewed by Dan Bernstein.

WebCore:

* rendering/svg/RenderSVGInlineText.cpp:
(WebCore::RenderSVGInlineText::localCaretRect): Implemented.

LayoutTests:

* svg/text/caret-in-svg-text-expected.txt: Added.
* svg/text/caret-in-svg-text.xhtml: Added.

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

LayoutTests/ChangeLog
LayoutTests/svg/text/caret-in-svg-text-expected.txt [new file with mode: 0644]
LayoutTests/svg/text/caret-in-svg-text.xhtml [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/svg/RenderSVGInlineText.cpp

index 41bb61d..803367f 100644 (file)
@@ -1,3 +1,13 @@
+2011-01-07  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        https://bugs.webkit.org/show_bug.cgi?id=51851
+        Implement RenderSVGInlineText::localCaretRect()
+
+        * svg/text/caret-in-svg-text-expected.txt: Added.
+        * svg/text/caret-in-svg-text.xhtml: Added.
+
 2011-01-06  Ryosuke Niwa  <rniwa@webkit.org>
 
         Reviewed by Adam Barth.
diff --git a/LayoutTests/svg/text/caret-in-svg-text-expected.txt b/LayoutTests/svg/text/caret-in-svg-text-expected.txt
new file mode 100644 (file)
index 0000000..ec7fd3d
--- /dev/null
@@ -0,0 +1,7 @@
+Sheriff Woody
+שדגש
+
+Success
+Success
+Failure. Was: 20,546,0,18, expected: 58,546,0,18
+Failure. Was: 58,546,0,18, expected: 20,546,0,18
diff --git a/LayoutTests/svg/text/caret-in-svg-text.xhtml b/LayoutTests/svg/text/caret-in-svg-text.xhtml
new file mode 100644 (file)
index 0000000..c7b4c4f
--- /dev/null
@@ -0,0 +1,35 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<body style="margin: 0px; ">
+  <div style="width: 400px; height: 100px;">
+    <svg xmlns="http://www.w3.org/2000/svg"> 
+        <text x="20" y="30"><tspan>Sheriff Woody</tspan></text>
+        <text x="20" y="50"><tspan>שדגש</tspan></text>
+    </svg>
+  </div>
+  <div id="log"></div>
+  <script>
+  function log(message) {
+    document.getElementById("log").innerText = document.getElementById("log").innerText + "\n" + message;
+  }
+  function assert(found, expected) {
+      if (found == expected)
+        log("Success");
+      else
+        log("Failure. Was: " + found + ", expected: " + expected);
+  }
+  if (window.layoutTestController) {
+    window.layoutTestController.dumpAsText();
+    // First offset, left edge, LTR text
+    assert(textInputController.firstRectForCharacterRange(0, 0), "20,566,0,18");
+    // Last offset, right edge, RTL text
+    assert(textInputController.firstRectForCharacterRange(13, 0), "114,566,0,18");
+
+    // FIXME: These edges are incorrect (although carets in the middle of RTL runs are correct).
+    // First offset, right edge, RTL text
+    assert(textInputController.firstRectForCharacterRange(14, 0), "58,546,0,18");
+    // Last offset, left edge, RTL text
+    assert(textInputController.firstRectForCharacterRange(18, 0), "20,546,0,18");
+  }
+  </script>
+</body>
+</html>
index 0385faa..2795651 100644 (file)
@@ -1,3 +1,13 @@
+2011-01-07  Justin Garcia  <justin.garcia@apple.com>
+
+        Reviewed by Dan Bernstein.
+
+        https://bugs.webkit.org/show_bug.cgi?id=51851
+        Implement RenderSVGInlineText::localCaretRect()
+
+        * rendering/svg/RenderSVGInlineText.cpp:
+        (WebCore::RenderSVGInlineText::localCaretRect): Implemented.
+
 2011-01-07  Ryosuke Niwa  <rniwa@webkit.org>
 
         Unreviewed; Added the missing null pointer check for r75293.
index 49727ee..b791f3e 100644 (file)
@@ -92,9 +92,25 @@ InlineTextBox* RenderSVGInlineText::createTextBox()
     return box;
 }
 
-IntRect RenderSVGInlineText::localCaretRect(InlineBox*, int, int*)
+IntRect RenderSVGInlineText::localCaretRect(InlineBox* box, int caretOffset, int*)
 {
-    return IntRect();
+    if (!box->isInlineTextBox())
+        return IntRect();
+
+    InlineTextBox* textBox = static_cast<InlineTextBox*>(box);
+    if (static_cast<unsigned>(caretOffset) < textBox->start() || static_cast<unsigned>(caretOffset) > textBox->start() + textBox->len())
+        return IntRect();
+
+    // Use the edge of the selection rect to determine the caret rect.
+    if (static_cast<unsigned>(caretOffset) < textBox->start() + textBox->len()) {
+        IntRect rect = textBox->selectionRect(0, 0, caretOffset, caretOffset + 1);
+        int x = box->isLeftToRightDirection() ? rect.x() : rect.right();
+        return IntRect(x, rect.y(), caretWidth, rect.height());
+    }
+
+    IntRect rect = textBox->selectionRect(0, 0, caretOffset - 1, caretOffset);
+    int x = box->isLeftToRightDirection() ? rect.right() : rect.x();
+    return IntRect(x, rect.y(), caretWidth, rect.height());
 }
 
 IntRect RenderSVGInlineText::linesBoundingBox() const