Use correct offset when attribute auto is present

Depending on the inlineBox bidiLevel use the right or left offset.
Do not use bidiLevel of the previous box when attribute is auto.

R=eseidel, leviw
BUG=296847
TEST=TextArea with strong RTL word, when on next line LTR word is
entered, caret position is changed.

Review URL: https://codereview.chromium.org/302433015

git-svn-id: svn://svn.chromium.org/blink/trunk@176151 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent a4986dfd
Test caret position in a textarea with direction auto and having RTL text. When entering a LTR text caret position is changed.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS caretRect[0] is not caretRect1[0]
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../../resources/js-test.js"></script>
<textarea id="textarea" dir="auto" style="font-size: 20px; width: 20ex; border: solid thin black; padding: 10px;">&#x05d0;!</textarea>
<script>
description('Test caret position in a textarea with direction auto and having RTL text. When entering a LTR text caret position is changed.');
var textarea = document.getElementById('textarea');
textarea.focus();
var caretRect = textInputController.firstRectForCharacterRange(0, 0);
window.testRunner.execCommand('MoveToEndOfLine');
document.execCommand('InsertLineBreak');
document.execCommand('InsertText', false, 'hell');
var caretRect1 = textInputController.firstRectForCharacterRange(1, 0);
shouldNotBe('caretRect[0]', 'caretRect1[0]');
</script>
Element direction details are accessible to shadow root
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS getComputedStyle(shadowRoot.getElementById("target2")).direction is "rtl"
PASS getComputedStyle(root).direction is "rtl"
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<div id="target" dir="rtl">
</div>
<script>
description('Element direction details are accessible to shadow root');
var root = document.getElementById('target');
var shadowRoot = root.createShadowRoot();
shadowRoot.innerHTML = "<div id='target2'> hello! </div>"
shouldBeEqualToString('getComputedStyle(shadowRoot.getElementById("target2")).direction', 'rtl');
shouldBeEqualToString('getComputedStyle(root).direction', 'rtl');
</script>
...@@ -228,7 +228,6 @@ Node* Position::computeNodeBeforePosition() const ...@@ -228,7 +228,6 @@ Node* Position::computeNodeBeforePosition() const
{ {
if (!m_anchorNode) if (!m_anchorNode)
return 0; return 0;
switch (anchorType()) { switch (anchorType()) {
case PositionIsBeforeChildren: case PositionIsBeforeChildren:
return 0; return 0;
...@@ -1266,7 +1265,10 @@ void Position::getInlineBoxAndOffset(EAffinity affinity, TextDirection primaryDi ...@@ -1266,7 +1265,10 @@ void Position::getInlineBoxAndOffset(EAffinity affinity, TextDirection primaryDi
break; break;
inlineBox = prevBox; inlineBox = prevBox;
} }
caretOffset = inlineBox->caretLeftmostOffset(); if (m_anchorNode->selfOrAncestorHasDirAutoAttribute())
caretOffset = inlineBox->bidiLevel() < level ? inlineBox->caretLeftmostOffset() : inlineBox->caretRightmostOffset();
else
caretOffset = inlineBox->caretLeftmostOffset();
} else if (nextBox->bidiLevel() > level) { } else if (nextBox->bidiLevel() > level) {
// Left edge of a "tertiary" run. Set to the right edge of that run. // Left edge of a "tertiary" run. Set to the right edge of that run.
while (InlineBox* tertiaryBox = inlineBox->nextLeafChildIgnoringLineBreak()) { while (InlineBox* tertiaryBox = inlineBox->nextLeafChildIgnoringLineBreak()) {
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include "core/dom/ExceptionCode.h" #include "core/dom/ExceptionCode.h"
#include "core/dom/NodeTraversal.h" #include "core/dom/NodeTraversal.h"
#include "core/dom/Text.h" #include "core/dom/Text.h"
#include "core/dom/shadow/ElementShadow.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/markup.h" #include "core/editing/markup.h"
#include "core/events/EventListener.h" #include "core/events/EventListener.h"
#include "core/events/KeyboardEvent.h" #include "core/events/KeyboardEvent.h"
...@@ -634,9 +636,6 @@ static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastN ...@@ -634,9 +636,6 @@ static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastN
Node* node = firstNode->firstChild(); Node* node = firstNode->firstChild();
while (node) { while (node) {
if (node->selfOrAncestorHasDirAutoAttribute() == flag)
return;
if (elementAffectsDirectionality(node)) { if (elementAffectsDirectionality(node)) {
if (node == lastNode) if (node == lastNode)
return; return;
...@@ -750,7 +749,9 @@ void HTMLElement::calculateAndAdjustDirectionality() ...@@ -750,7 +749,9 @@ void HTMLElement::calculateAndAdjustDirectionality()
{ {
Node* strongDirectionalityTextNode; Node* strongDirectionalityTextNode;
TextDirection textDirection = directionality(&strongDirectionalityTextNode); TextDirection textDirection = directionality(&strongDirectionalityTextNode);
setHasDirAutoFlagRecursively(this, true, strongDirectionalityTextNode); setHasDirAutoFlagRecursively(this, hasDirectionAuto(), strongDirectionalityTextNode);
for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot())
setHasDirAutoFlagRecursively(root, hasDirectionAuto());
if (renderer() && renderer()->style() && renderer()->style()->direction() != textDirection) if (renderer() && renderer()->style() && renderer()->style()->direction() != textDirection)
setNeedsStyleRecalc(SubtreeStyleChange); setNeedsStyleRecalc(SubtreeStyleChange);
} }
......
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