Mixing content editable and non-editable in direction RTL

Content editable when mixed in direction rtl, it was not moving caret because editing boundary was not calculated correctly. In RTL scenario, nodes need to be calculated from after or before for left and right respectively. Based on the direction of the block calculates appropriate editing boundary.

R=yosin
BUG=409517
TEST=editing/selection/skip-non-editable-rtl.html

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

git-svn-id: svn://svn.chromium.org/blink/trunk@183843 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4d6ef7e2
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
This tests moving the caret in content of mixed editability with direction RTL. The caret should jump to the next editable region that shares a common editable ancestor when it reaches non-editable content.
editable content
non-editable content non-editable content editable content
editable content
Success
Success
Success
Success
<head>
<script>
if (window.testRunner)
testRunner.dumpEditingCallbacks();
</script>
<style>
table, td {
border: 1px solid #aaa;
}
</style>
<script>
function log(str) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(str));
var console = document.getElementById("console");
console.appendChild(li);
}
function assert(bool) {
if (!bool)
log("Failure");
else
log("Success");
}
</script>
</head>
<body contentEditable="true" dir="rtl">
<p>This tests moving the caret in content of mixed editability with direction RTL. The caret should jump to the next editable region that shares a common editable ancestor when it reaches non-editable content.</p>
<div id="e1">editable content</div>
<table cellpadding="5" contentEditable="false">
<tr>
<td>non-editable content</td>
<td>non-editable content</td>
<td id="e2" contentEditable="true">editable content</td>
</table>
<div id="e3">editable content</div>
<ul id="console"></ul>
</body>
<script>
if (window.testRunner)
window.testRunner.dumpAsText();
var s = window.getSelection();
var e1 = document.getElementById("e1");
var e2 = document.getElementById("e2");
var e3 = document.getElementById("e3");
s.collapse(e1.firstChild, e1.firstChild.length);
s.modify("move", "forward", "character");
s.modify("move", "forward", "character");
assert(s.anchorNode == e2.firstChild && s.anchorOffset == 0);
s.modify("move", "backward", "character");
s.modify("move", "backward", "character");
assert(s.anchorNode == e1.firstChild && s.anchorOffset == e1.firstChild.length);
s.collapse(e2.firstChild, e2.firstChild.length);
s.modify("move", "forward", "character");
s.modify("move", "forward", "character");
assert(s.anchorNode == e3.firstChild && s.anchorOffset == 0);
s.modify("move", "backward", "character");
s.modify("move", "backward", "character");
assert(s.anchorNode == e2.firstChild && s.anchorOffset == e2.firstChild.length)
</script>
......@@ -280,8 +280,7 @@ VisiblePosition VisiblePosition::left(bool stayInEditableContent) const
if (!stayInEditableContent)
return left;
// FIXME: This may need to do something different from "before".
return honorEditingBoundaryAtOrBefore(left);
return directionOfEnclosingBlock(left.deepEquivalent()) == LTR ? honorEditingBoundaryAtOrBefore(left) : honorEditingBoundaryAtOrAfter(left);
}
Position VisiblePosition::rightVisuallyDistinctCandidate() const
......@@ -448,8 +447,7 @@ VisiblePosition VisiblePosition::right(bool stayInEditableContent) const
if (!stayInEditableContent)
return right;
// FIXME: This may need to do something different from "after".
return honorEditingBoundaryAtOrAfter(right);
return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditingBoundaryAtOrAfter(right) : honorEditingBoundaryAtOrBefore(right);
}
VisiblePosition VisiblePosition::honorEditingBoundaryAtOrBefore(const VisiblePosition &pos) const
......
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