WebCore/ChangeLog

 12010-04-15 Xiaomei Ji <xji@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Fix issue "caret does not paint after type in characters in right
 6 aligned div or after delete all characters in RTL div or
 7 0px right padding RTL textarea"
 8 https://bugs.webkit.org/show_bug.cgi?id=25319
 9
 10 Test: editing/inserting/caret-position.html
 11
 12 * rendering/RenderText.cpp:
 13 (WebCore::RenderText::localCaretRect):
 14
1152010-04-15 Jian Li <jianli@chromium.org>
216
317 Reviewed by Dmitry Titov.
57696

WebCore/rendering/RenderText.cpp

@@IntRect RenderText::localCaretRect(Inlin
443443 *extraWidthToEndOfLine = (box->root()->width() + rootLeft) - (left + 1);
444444
445445 RenderBlock* cb = containingBlock();
 446 RenderStyle* cbStyle = cb->style();
 447 int leftEdge;
 448 int rightEdge;
446449 if (style()->autoWrap()) {
447  int availableWidth = cb->lineWidth(top, false);
448  if (box->direction() == LTR)
449  left = min(left, rootLeft + availableWidth - caretWidthRightOfOffset);
450  else
451  left = max(left, cb->x());
 450 leftEdge = cb->x();
 451 rightEdge = cb->x() + cb->width();
452452 } else {
453  // If there is no wrapping, the caret can leave its containing block, but not its root line box.
454  if (cb->style()->direction() == LTR) {
455  int rightEdge = max(cb->width(), rootRight);
456  left = min(left, rightEdge - caretWidthRightOfOffset);
457  left = max(left, rootLeft);
458  } else {
459  int leftEdge = min(cb->x(), rootLeft);
460  left = max(left, leftEdge);
461  left = min(left, rootRight - caretWidth);
462  }
 453 leftEdge = min(cb->x(), rootLeft);
 454 rightEdge = max(cb->x() + cb->width(), rootRight);
 455 }
 456 if (cbStyle->direction() == RTL || cbStyle->textAlign() == RIGHT || cbStyle->textAlign() == WEBKIT_RIGHT) {
 457 left = max(left, leftEdge);
 458 left = min(left, rootRight - caretWidth);
 459 } else {
 460 left = min(left, rightEdge - caretWidthRightOfOffset);
 461 left = max(left, rootLeft);
463462 }
464463
465464 return IntRect(left, top, caretWidth, height);
57655

LayoutTests/ChangeLog

 12010-04-15 Xiaomei Ji <xji@chromium.org>
 2
 3 Reviewed by NOBODY (OOPS!).
 4
 5 Fix issue "caret does not paint after type in characters in right
 6 aligned div or after delete all characters in RTL div or
 7 0px right padding RTL textarea"
 8 https://bugs.webkit.org/show_bug.cgi?id=25319
 9
 10 * editing/inserting/caret-position-expected.txt: Added.
 11 * editing/inserting/caret-position.html: Added.
 12 * platform/mac/editing/input/caret-primary-bidi-expected.txt:
 13
1142010-04-15 Albert J. Wong <ajwong@chromium.org>
215
316 Not reviewed. Sheriffing.
57696

LayoutTests/editing/inserting/caret-position-expected.txt

 1
 2Right aligned div.
 3x
 4
 5RTL div.
 6a
 7
 80px right padding RTL textarea.
 9
 10LTR div and textarea.
 11a
 12
 13
 14NO WRAPPING
 15No wrapping right aligned div.
 16
 17No wrapping RTL div.
 18a
 19
 20No wrapping 0px right padding RTL textarea.
 21
 22No wrapping LTR div and textarea.
 23a
 24
 25
 26
0

LayoutTests/editing/inserting/caret-position.html

 1<html>
 2<head>
 3<script src=../editing.js language="JavaScript" type="text/JavaScript" ></script>
 4<script>
 5
 6function log(str) {
 7 var li = document.createElement("li");
 8 li.appendChild(document.createTextNode(str));
 9 var console = document.getElementById("console");
 10 console.appendChild(li);
 11}
 12
 13function assertEqual(test_name, actual, expected)
 14{
 15 if (actual != expected) {
 16 log("==================================");
 17 log("FAILED: " + test_name);
 18 log("actual: " + actual);
 19 log("expected: " + expected);
 20 }
 21}
 22function testCaretPosition(elementId, caretPosition)
 23{
 24 e = document.getElementById(elementId, caretPosition);
 25 e.focus();
 26 if (window.textInputController) {
 27 var caretRect = textInputController.firstRectForCharacterRange(0, 0);
 28 assertEqual(elementId, caretRect[0], caretPosition);
 29 }
 30}
 31
 32function runTest()
 33{
 34 if (window.layoutTestController)
 35 layoutTestController.dumpAsText();
 36 var e = document.getElementById("right-align-div");
 37 e.focus();
 38 selectAllCommand();
 39 typeCharacterCommand();
 40 if (window.textInputController) {
 41 var caretRect = textInputController.firstRectForCharacterRange(1, 0);
 42 assertEqual("right-align-div", caretRect[0], 208);
 43 }
 44
 45 testCaretPosition("rtl-div", 208);
 46 testCaretPosition("0-right-padding-rtl-textarea", 206);
 47 testCaretPosition("ltr-div", 9);
 48 testCaretPosition("ltr-textarea", 10);
 49 testCaretPosition("no-wrapping-right-align-div", 208);
 50 testCaretPosition("no-wrapping-rtl-div", 208);
 51 testCaretPosition("no-wrapping-0-right-padding-rtl-textarea", 206);
 52 testCaretPosition("no-wrapping-ltr-div", 9);
 53 testCaretPosition("no-wrapping-ltr-textarea", 10);
 54}
 55
 56</script>
 57</head>
 58<body>
 59<br>
 60Right aligned div.
 61<br>
 62<div CONTENTEDITABLE id="right-align-div" style="text-align: right; width:200px; border: solid thin;"></div>
 63<br>
 64RTL div.
 65<br>
 66<div CONTENTEDITABLE id="rtl-div" style="direction: rtl; width:200px; border: solid thin; ">a</div>
 67<br>
 680px right padding RTL textarea.
 69<br>
 70<textarea id="0-right-padding-rtl-textarea" style="direction:rtl; padding: 1px 0px 1px 1px; width:200px">a</textarea>
 71<br>
 72LTR div and textarea.
 73<br>
 74<div CONTENTEDITABLE id="ltr-div" style="width:200px; border: solid thin; ">a</div>
 75<br>
 76<textarea id="ltr-textarea" style="padding: 1px 0px 1px 1px; width:200px">a</textarea>
 77<br>
 78NO WRAPPING
 79<br>
 80No wrapping right aligned div.
 81<br>
 82<div CONTENTEDITABLE id="no-wrapping-right-align-div" style="white-space:nowrap; text-align: right; width:200px; border: solid thin;"></div>
 83<br>
 84No wrapping RTL div.
 85<br>
 86<div CONTENTEDITABLE id="no-wrapping-rtl-div" style="white-space:nowrap; direction: rtl; width:200px; border: solid thin; ">a</div>
 87<br>
 88No wrapping 0px right padding RTL textarea.
 89<br>
 90<textarea id="no-wrapping-0-right-padding-rtl-textarea" style="white-space:nowrap; direction:rtl; padding: 1px 0px 1px 1px; width:200px">a</textarea>
 91<br>
 92No wrapping LTR div and textarea.
 93<br>
 94<div CONTENTEDITABLE id="no-wrapping-ltr-div" style="white-space:nowrap; width:200px; border: solid thin; ">a</div>
 95<br>
 96<textarea id="no-wrapping-ltr-textarea" style="white-space:nowrap; padding: 1px 0px 1px 1px; width:200px">a</textarea>
 97<br>
 98<ul id="console"></ul>
 99</body>
 100<script> runTest(); </script>
 101</html>
0

LayoutTests/platform/mac/editing/input/caret-primary-bidi-expected.txt

414140: 114,478,0,28
424241: 97,478,0,28
434342: 126,478,0,28
44 43: 792,450,0,28
 4443: 791,450,0,28
454544: 764,450,0,28
464645: 779,450,0,28
474746: 751,450,0,28

575756: 605,450,0,28
585857: 618,450,0,28
595958: 590,450,0,28
60 59: 792,422,0,28
 6059: 791,422,0,28
616160: 777,422,0,28
626261: 763,422,0,28
636362: 752,422,0,28

676766: 694,422,0,28
686867: 677,422,0,28
696968: 669,422,0,28
70 69: 792,394,0,28
 7069: 791,394,0,28
717170: 777,394,0,28
727271: 763,394,0,28
737372: 752,394,0,28
747473: 660,394,0,28
757574: 643,394,0,28
767675: 635,394,0,28
77 76: 792,364,0,28
 7776: 791,364,0,28
787877: 764,364,0,28
797978: 779,364,0,28
808079: 751,364,0,28
57655