2010-04-23 Xiaomei Ji <xji@chromium.org>
authorxji@chromium.org <xji@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Apr 2010 22:07:46 +0000 (22:07 +0000)
committerxji@chromium.org <xji@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 23 Apr 2010 22:07:46 +0000 (22:07 +0000)
        Reviewed by Dan Bernstein and Darin Adler

        Fix issue "caret does not paint after type in characters in right
        aligned div or after delete all characters in RTL div or
        0px right padding RTL textarea"
        https://bugs.webkit.org/show_bug.cgi?id=25319

        Test: editing/inserting/caret-position.html

        * rendering/RenderText.cpp:
        (WebCore::RenderText::localCaretRect):
2010-04-23  Xiaomei Ji  <xji@chromium.org>

        Reviewed by Dan Bernstein and Darin Adler

        Fix issue "caret does not paint after type in characters in right
        aligned div or after delete all characters in RTL div or
        0px right padding RTL textarea"
        https://bugs.webkit.org/show_bug.cgi?id=25319

        * editing/inserting/caret-position-expected.txt: Added.
        * editing/inserting/caret-position.html: Added.
        * platform/mac/editing/input/caret-primary-bidi-expected.txt:

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

LayoutTests/ChangeLog
LayoutTests/editing/inserting/caret-position-expected.txt [new file with mode: 0644]
LayoutTests/editing/inserting/caret-position.html [new file with mode: 0644]
LayoutTests/platform/mac/editing/input/caret-primary-bidi-expected.txt
WebCore/ChangeLog
WebCore/rendering/RenderText.cpp

index eb4e79e..312c5cc 100644 (file)
@@ -1,3 +1,16 @@
+2010-04-23  Xiaomei Ji  <xji@chromium.org>
+
+        Reviewed by Dan Bernstein and Darin Adler
+
+        Fix issue "caret does not paint after type in characters in right
+        aligned div or after delete all characters in RTL div or 
+        0px right padding RTL textarea"
+        https://bugs.webkit.org/show_bug.cgi?id=25319
+
+        * editing/inserting/caret-position-expected.txt: Added.
+        * editing/inserting/caret-position.html: Added.
+        * platform/mac/editing/input/caret-primary-bidi-expected.txt:
+
 2010-04-23  MORITA Hajime  <morrita@google.com>
 
         Reviewed by Nikolas Zimmermann.
diff --git a/LayoutTests/editing/inserting/caret-position-expected.txt b/LayoutTests/editing/inserting/caret-position-expected.txt
new file mode 100644 (file)
index 0000000..ccf64e2
--- /dev/null
@@ -0,0 +1,26 @@
+
+Right aligned div. 
+x
+
+RTL div. 
+a
+
+0px right padding RTL textarea. 
+LTR div and textarea. 
+a
+
+NO WRAPPING 
+No wrapping right aligned div. 
+
+No wrapping RTL div. 
+a
+
+No wrapping 0px right padding RTL textarea. 
+No wrapping LTR div and textarea. 
+a
+
+
diff --git a/LayoutTests/editing/inserting/caret-position.html b/LayoutTests/editing/inserting/caret-position.html
new file mode 100644 (file)
index 0000000..e7e6070
--- /dev/null
@@ -0,0 +1,101 @@
+<html>
+<head>
+<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
+<script>
+
+function log(str) {
+    var li = document.createElement("li");
+    li.appendChild(document.createTextNode(str));
+    var console = document.getElementById("console");
+    console.appendChild(li);
+}
+
+function assertEqual(test_name, actual, expected)
+{
+    if (actual != expected) {
+        log("==================================");
+        log("FAILED: " + test_name);
+        log("actual: " + actual);
+        log("expected: " + expected);
+    }
+}
+function testCaretPosition(elementId, caretPosition)
+{
+    e = document.getElementById(elementId, caretPosition);
+    e.focus();
+    if (window.textInputController) {
+        var caretRect = textInputController.firstRectForCharacterRange(0, 0);
+        assertEqual(elementId, caretRect[0], caretPosition);
+    }  
+}
+
+function runTest()
+{
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    var e = document.getElementById("right-align-div");
+    e.focus();
+    selectAllCommand();
+    typeCharacterCommand();
+    if (window.textInputController) {
+        var caretRect = textInputController.firstRectForCharacterRange(1, 0);
+        assertEqual("right-align-div", caretRect[0], 208);
+    }
+
+    testCaretPosition("rtl-div", 208);
+    testCaretPosition("0-right-padding-rtl-textarea", 206);
+    testCaretPosition("ltr-div", 9);
+    testCaretPosition("ltr-textarea", 10);
+    testCaretPosition("no-wrapping-right-align-div", 208);
+    testCaretPosition("no-wrapping-rtl-div", 208);
+    testCaretPosition("no-wrapping-0-right-padding-rtl-textarea", 206);
+    testCaretPosition("no-wrapping-ltr-div", 9);
+    testCaretPosition("no-wrapping-ltr-textarea", 10);
+}
+
+</script>
+</head>
+<body>
+<br>
+Right aligned div.
+<br>
+<div CONTENTEDITABLE id="right-align-div" style="text-align: right; width:200px; border: solid thin;"></div> 
+<br>
+RTL div.
+<br>
+<div CONTENTEDITABLE id="rtl-div" style="direction: rtl; width:200px; border: solid thin; ">a</div> 
+<br>
+0px right padding RTL textarea.
+<br>
+<textarea id="0-right-padding-rtl-textarea" style="direction:rtl; padding: 1px 0px 1px 1px; width:200px">a</textarea>
+<br>
+LTR div and textarea.
+<br>
+<div CONTENTEDITABLE id="ltr-div" style="width:200px; border: solid thin; ">a</div> 
+<br>
+<textarea id="ltr-textarea" style="padding: 1px 0px 1px 1px; width:200px">a</textarea>
+<br>
+NO WRAPPING
+<br>
+No wrapping right aligned div.
+<br>
+<div CONTENTEDITABLE id="no-wrapping-right-align-div" style="white-space:nowrap; text-align: right; width:200px; border: solid thin;"></div> 
+<br>
+No wrapping RTL div.
+<br>
+<div CONTENTEDITABLE id="no-wrapping-rtl-div" style="white-space:nowrap; direction: rtl; width:200px; border: solid thin; ">a</div> 
+<br>
+No wrapping 0px right padding RTL textarea.
+<br>
+<textarea id="no-wrapping-0-right-padding-rtl-textarea" style="white-space:nowrap; direction:rtl; padding: 1px 0px 1px 1px; width:200px">a</textarea>
+<br>
+No wrapping LTR div and textarea.
+<br>
+<div CONTENTEDITABLE id="no-wrapping-ltr-div" style="white-space:nowrap; width:200px; border: solid thin; ">a</div> 
+<br>
+<textarea id="no-wrapping-ltr-textarea" style="white-space:nowrap; padding: 1px 0px 1px 1px; width:200px">a</textarea>
+<br>
+<ul id="console"></ul>
+</body>
+<script> runTest(); </script>
+</html>
index c3a9eb0..25646db 100644 (file)
@@ -41,7 +41,7 @@
 40: 114,478,0,28
 41: 97,478,0,28
 42: 126,478,0,28
-43: 792,450,0,28
+43: 791,450,0,28
 44: 764,450,0,28
 45: 779,450,0,28
 46: 751,450,0,28
@@ -57,7 +57,7 @@
 56: 605,450,0,28
 57: 618,450,0,28
 58: 590,450,0,28
-59: 792,422,0,28
+59: 791,422,0,28
 60: 777,422,0,28
 61: 763,422,0,28
 62: 752,422,0,28
 66: 694,422,0,28
 67: 677,422,0,28
 68: 669,422,0,28
-69: 792,394,0,28
+69: 791,394,0,28
 70: 777,394,0,28
 71: 763,394,0,28
 72: 752,394,0,28
 73: 660,394,0,28
 74: 643,394,0,28
 75: 635,394,0,28
-76: 792,364,0,28
+76: 791,364,0,28
 77: 764,364,0,28
 78: 779,364,0,28
 79: 751,364,0,28
index 398a99f..dc7179e 100644 (file)
@@ -1,3 +1,17 @@
+2010-04-23  Xiaomei Ji  <xji@chromium.org>
+
+        Reviewed by Dan Bernstein and Darin Adler
+
+        Fix issue "caret does not paint after type in characters in right
+        aligned div or after delete all characters in RTL div or 
+        0px right padding RTL textarea"
+        https://bugs.webkit.org/show_bug.cgi?id=25319
+
+        Test: editing/inserting/caret-position.html
+
+        * rendering/RenderText.cpp:
+        (WebCore::RenderText::localCaretRect):
+
 2010-04-23  No'am Rosenthal  <noam.rosenthal@nokia.com>
 
         Reviewed by Kenneth Rohde Christiansen.
index 90ad6d8..bede6a6 100644 (file)
@@ -455,23 +455,40 @@ IntRect RenderText::localCaretRect(InlineBox* inlineBox, int caretOffset, int* e
         *extraWidthToEndOfLine = (box->root()->width() + rootLeft) - (left + 1);
 
     RenderBlock* cb = containingBlock();
+    RenderStyle* cbStyle = cb->style();
+    int leftEdge;
+    int rightEdge;
     if (style()->autoWrap()) {
-        int availableWidth = cb->lineWidth(top, false);
-        if (box->direction() == LTR)
-            left = min(left, rootLeft + availableWidth - caretWidthRightOfOffset);
-        else
-            left = max(left, cb->x());
+        leftEdge = cb->x();
+        rightEdge = cb->frameRect().right();
     } else {
-        // If there is no wrapping, the caret can leave its containing block, but not its root line box.
-        if (cb->style()->direction() == LTR) {
-            int rightEdge = max(cb->width(), rootRight);
-            left = min(left, rightEdge - caretWidthRightOfOffset);
-            left = max(left, rootLeft);
-        } else {
-            int leftEdge = min(cb->x(), rootLeft);
-            left = max(left, leftEdge);
-            left = min(left, rootRight - caretWidth);
-        }
+        leftEdge = min(cb->x(), rootLeft);
+        rightEdge = max(cb->frameRect().right(), rootRight);
+    }
+
+    bool rightAligned = false;
+    switch (cbStyle->textAlign()) {
+    case TAAUTO:
+    case JUSTIFY:
+        rightAligned = cbStyle->direction() == RTL;
+        break;
+    case RIGHT:
+    case WEBKIT_RIGHT:
+        rightAligned = true;
+        break;
+    case LEFT:
+    case WEBKIT_LEFT:
+    case CENTER:
+    case WEBKIT_CENTER:
+        break;
+    }
+
+    if (rightAligned) {
+        left = max(left, leftEdge);
+        left = min(left, rootRight - caretWidth);
+    } else {
+        left = min(left, rightEdge - caretWidthRightOfOffset);
+        left = max(left, rootLeft);
     }
 
     return IntRect(left, top, caretWidth, height);