Commit e7bee7ef authored by yi.4.shen@nokia.com's avatar yi.4.shen@nokia.com
Browse files

Caret is not rendered properly inside an input element with text-indent

https://bugs.webkit.org/show_bug.cgi?id=82688

Reviewed by Ryosuke Niwa.

For an empty input element, there is no RenderText. Instead, RenderBlock::localCaretRect provides
the caret position for rendering the caret in the empty input element. To get correct caret rect,
textIndentOffset() should be used to adjust the caret's position.

Source/WebCore:

Test: editing/style/text-indent.html

* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::localCaretRect):

LayoutTests:

* editing/style/text-indent-expected.txt: Added.
* editing/style/text-indent.html: Added.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@114461 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c5768351
2012-04-17 Yi Shen <yi.4.shen@nokia.com>
Caret is not rendered properly inside an input element with text-indent
https://bugs.webkit.org/show_bug.cgi?id=82688
Reviewed by Ryosuke Niwa.
For an empty input element, there is no RenderText. Instead, RenderBlock::localCaretRect provides
the caret position for rendering the caret in the empty input element. To get correct caret rect,
textIndentOffset() should be used to adjust the caret's position.
* editing/style/text-indent-expected.txt: Added.
* editing/style/text-indent.html: Added.
2012-04-17 Vincent Scheib <scheib@chromium.org>
 
[Chromium] Mark test failing IMAGE: svg/transforms/transform-origin-css-property.xhtml
Success. The caret's x positions of empty&nonempty input field were the same.
Success. The caret's x positions of empty&nonempty input field were the same.
Success. The caret's x positions of empty&nonempty input field were the same.
Success. The caret's x positions of empty&nonempty input field were the same.
Success. The caret's x positions of empty&nonempty input field were the same.
Success. The caret's x positions of empty&nonempty input field were the same.
Success. The caret's x positions was set to desired position when the text-align is center.
Success. The caret's x positions was set to desired position when the text-align is center.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
<script>
function testTextIndent(testContent, characterIndex)
{
document.body.innerHTML = testContent;
var editor = document.getElementById('textIndentTest');
editor.focus();
var caretRect = textInputController.firstRectForCharacterRange(0, 0);
var caretXPosition_withoutTextRender = caretRect[0];
editor.setSelectionRange(0, 0);
document.execCommand('InsertText', false, 'a');
caretRect = textInputController.firstRectForCharacterRange(characterIndex, 0);
var caretXPosition_withTextRender = caretRect[0];
if (caretXPosition_withoutTextRender == caretXPosition_withTextRender)
return "Success. The caret's x positions of empty&nonempty input field were the same.\n";
else
return "Failure. The caret's x position of empty input field was " + caretXPosition_withoutTextRender + ", should have been " + caretXPosition_withTextRender + ".\n";
}
function testTextIndentWhenTextAlignsToCenter(textIndent)
{
document.body.innerHTML = "<input id='textIndentTest' type='text' style='text-align:center;'>";
var editor = document.getElementById('textIndentTest');
editor.focus();
var caretRect = textInputController.firstRectForCharacterRange(0, 0);
var caretXPosition_withoutTextIndent = caretRect[0];
editor.blur();
editor.style.textIndent = textIndent + "px";
editor.focus();
caretRect = textInputController.firstRectForCharacterRange(0, 0);
var caretXPosition_withTextIndent = caretRect[0];
var desiredCaretXPosition = caretXPosition_withoutTextIndent + textIndent / 2;
if (desiredCaretXPosition == caretXPosition_withTextIndent)
return "Success. The caret's x positions was set to desired position when the text-align is center.\n";
else
return "Failure. The caret's x position of input field was " + caretXPosition_withTextIndent + ", should have been " + desiredCaretXPosition + ".\n";
}
if (window.layoutTestController)
window.layoutTestController.dumpAsText();
var output = "";
output += testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;'></input>", 0);
output += testTextIndent("<input id='textIndentTest' type='text' style='text-indent:-30px;'>", 0);
output += testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;text-align:left'>", 0);
output += testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;text-align:right'>", 1);
output += testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;direction:rtl;'>", 0);
output += testTextIndent("<input id='textIndentTest' type='text' style='text-indent:30px;direction:rtl;text-align:right;'>", 0);
output += testTextIndentWhenTextAlignsToCenter(30);
output += testTextIndentWhenTextAlignsToCenter(-30);
document.body.innerText = output;
</script>
</html>
\ No newline at end of file
2012-04-17 Yi Shen <yi.4.shen@nokia.com>
Caret is not rendered properly inside an input element with text-indent
https://bugs.webkit.org/show_bug.cgi?id=82688
Reviewed by Ryosuke Niwa.
For an empty input element, there is no RenderText. Instead, RenderBlock::localCaretRect provides
the caret position for rendering the caret in the empty input element. To get correct caret rect,
textIndentOffset() should be used to adjust the caret's position.
Test: editing/style/text-indent.html
* rendering/RenderBlock.cpp:
(WebCore::RenderBlock::localCaretRect):
2012-04-17 Filip Pizlo <fpizlo@apple.com>
 
It should be possible to create an inheritorID for the global this object without crashing
......@@ -6482,14 +6482,23 @@ LayoutRect RenderBlock::localCaretRect(InlineBox* inlineBox, int caretOffset, La
switch (alignment) {
case alignLeft:
if (currentStyle->isLeftToRightDirection())
x += textIndentOffset();
break;
case alignCenter:
x = (x + w - (borderRight() + paddingRight())) / 2;
if (currentStyle->isLeftToRightDirection())
x += textIndentOffset() / 2;
else
x -= textIndentOffset() / 2;
break;
case alignRight:
x = w - (borderRight() + paddingRight()) - caretWidth;
if (!currentStyle->isLeftToRightDirection())
x -= textIndentOffset();
break;
}
x = min(x, w - borderRight() - paddingRight() - caretWidth);
if (extraWidthToEndOfLine) {
if (isRenderBlock()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment