Diff
Modified: trunk/LayoutTests/ChangeLog (214273 => 214274)
--- trunk/LayoutTests/ChangeLog 2017-03-22 20:30:11 UTC (rev 214273)
+++ trunk/LayoutTests/ChangeLog 2017-03-22 20:30:41 UTC (rev 214274)
@@ -1,3 +1,13 @@
+2017-03-22 Nan Wang <[email protected]>
+
+ AX: WebKit is returning the wrong rangeForLine
+ https://bugs.webkit.org/show_bug.cgi?id=169940
+
+ Reviewed by Chris Fleizach.
+
+ * accessibility/mac/range-for-contenteditable-newline-expected.txt:
+ * accessibility/mac/range-for-contenteditable-newline.html:
+
2017-03-22 John Wilander <[email protected]>
Resource Load Statistics: Fix partitioning bug for client-side cookie access
Modified: trunk/LayoutTests/accessibility/mac/range-for-contenteditable-newline-expected.txt (214273 => 214274)
--- trunk/LayoutTests/accessibility/mac/range-for-contenteditable-newline-expected.txt 2017-03-22 20:30:11 UTC (rev 214273)
+++ trunk/LayoutTests/accessibility/mac/range-for-contenteditable-newline-expected.txt 2017-03-22 20:30:41 UTC (rev 214274)
@@ -7,6 +7,13 @@
def
+The quick brown fox
+
+jumped over the lazy dog
+
+Text in a pre element
+is displayed in a fixed-width
+font
This tests that when there are newline characters within text controls, we can get the correct text range from index and length.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
@@ -19,6 +26,14 @@
PASS textareaTextHello is 'hello'
PASS textareaTextWorld is 'world'
PASS textDEF is 'def'
+PASS rangeForLine is '{21, 25}'
+PASS textLine is 'jumped over the lazy dog'
+PASS firstLine is 0
+PASS secondLine is 1
+PASS rangeForLine is '{22, 30}'
+PASS textLine is 'is displayed in a fixed-width\n'
+PASS firstLine is 0
+FAIL secondLine should be 1. Was 2.
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/accessibility/mac/range-for-contenteditable-newline.html (214273 => 214274)
--- trunk/LayoutTests/accessibility/mac/range-for-contenteditable-newline.html 2017-03-22 20:30:11 UTC (rev 214273)
+++ trunk/LayoutTests/accessibility/mac/range-for-contenteditable-newline.html 2017-03-22 20:30:41 UTC (rev 214274)
@@ -12,6 +12,19 @@
</div>
<div id="textcontrol2" contenteditable="true">abc<div><br></div<div><br></div><div><br></div><div>def</div></div>
+<div id="textcontrol3" contenteditable="true">
+<p>The quick brown fox</p>
+<p>jumped over the lazy dog</p>
+</div>
+
+<div id="textcontrol4" contenteditable="true">
+<pre>
+Text in a pre element
+is displayed in a fixed-width
+font
+</pre>
+</div>
+
<div role="group" id="console"></div>
<script>
@@ -43,6 +56,28 @@
var textControl2 = accessibilityController.accessibleElementById("textcontrol2");
var textDEF = textControl2.stringForRange(7, 3);
shouldBe("textDEF", "'def'");
+
+ // Test line ranges in contenteditable
+ var textControl3 = accessibilityController.accessibleElementById("textcontrol3");
+ var rangeForLine = textControl3.rangeForLine(1);
+ shouldBe("rangeForLine", "'{21, 25}'");
+ var textLine = textControl3.stringForRange(21, 25);
+ shouldBe("textLine", "'jumped over the lazy dog'");
+ var firstLine = textControl3.lineForIndex(20);
+ var secondLine = textControl3.lineForIndex(46);
+ shouldBe("firstLine", "0");
+ shouldBe("secondLine", "1");
+
+ // pre tag in contenteditable
+ var textControl4 = accessibilityController.accessibleElementById("textcontrol4");
+ rangeForLine = textControl4.rangeForLine(1);
+ shouldBe("rangeForLine", "'{22, 30}'");
+ textLine = textControl4.stringForRange(22, 30);
+ shouldBe("textLine", "'is displayed in a fixed-width\\n'");
+ firstLine = textControl4.lineForIndex(21);
+ secondLine = textControl4.lineForIndex(52);
+ shouldBe("firstLine", "0");
+ shouldBe("secondLine", "1");
</script>
Modified: trunk/Source/WebCore/ChangeLog (214273 => 214274)
--- trunk/Source/WebCore/ChangeLog 2017-03-22 20:30:11 UTC (rev 214273)
+++ trunk/Source/WebCore/ChangeLog 2017-03-22 20:30:41 UTC (rev 214274)
@@ -1,3 +1,19 @@
+2017-03-22 Nan Wang <[email protected]>
+
+ AX: WebKit is returning the wrong rangeForLine
+ https://bugs.webkit.org/show_bug.cgi?id=169940
+
+ Reviewed by Chris Fleizach.
+
+ The AXRangeForLine is being calculated using VisiblePostition, so
+ when we try to use the index we should validate it using VisiblePosition.
+
+ Changes are covered in the modified test.
+
+ * accessibility/AXObjectCache.cpp:
+ (WebCore::AXObjectCache::traverseToOffsetInRange):
+ (WebCore::AXObjectCache::characterOffsetForIndex):
+
2017-03-22 John Wilander <[email protected]>
Resource Load Statistics: Fix partitioning bug for client-side cookie access
Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (214273 => 214274)
--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp 2017-03-22 20:30:11 UTC (rev 214273)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp 2017-03-22 20:30:41 UTC (rev 214274)
@@ -1621,8 +1621,8 @@
} else if (Element *shadowHost = currentNode->shadowHost()) {
// Since we are entering text controls, we should set the currentNode
// to be the shadow host when there's no content.
- if (nodeIsTextControl(shadowHost)) {
- currentNode = currentNode->shadowHost();
+ if (nodeIsTextControl(shadowHost) && currentNode->isShadowRoot()) {
+ currentNode = shadowHost;
continue;
}
} else if (currentNode != previousNode) {
@@ -2621,11 +2621,28 @@
if (!obj)
return CharacterOffset();
+ VisiblePosition vp = obj->visiblePositionForIndex(index);
+ CharacterOffset validate = characterOffsetFromVisiblePosition(vp);
+ // In text control, VisiblePosition always gives the before position of a
+ // BR node, while CharacterOffset will do the opposite.
+ if (obj->isTextControl() && characterOffsetNodeIsBR(validate))
+ validate.offset = 1;
+
RefPtr<Range> range = obj->elementRange();
CharacterOffset start = startOrEndCharacterOffsetForRange(range, true, true);
CharacterOffset end = startOrEndCharacterOffsetForRange(range, false, true);
CharacterOffset result = start;
for (int i = 0; i < index; i++) {
+ if (result.isEqual(validate)) {
+ // Do not include the new line character, always move the offset to the start of next node.
+ if ((validate.node->isTextNode() || characterOffsetNodeIsBR(validate))) {
+ CharacterOffset next = nextCharacterOffset(validate, false);
+ if (!next.offset && rootAXEditableElement(next.node) == rootAXEditableElement(validate.node))
+ result = next;
+ }
+ break;
+ }
+
result = nextCharacterOffset(result, false);
if (result.isEqual(end))
break;