Commit 74450318 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Stop on headings with only text children

Bug: 814978
Test: manually with STR from the bug.

Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I4d054c5bf1becb44d8592d58ff2a77c3141254f5
Reviewed-on: https://chromium-review.googlesource.com/945414
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541134}
parent f97d1b9f
...@@ -237,6 +237,24 @@ AutomationPredicate.object = function(node) { ...@@ -237,6 +237,24 @@ AutomationPredicate.object = function(node) {
AutomationPredicate.formField(node))) AutomationPredicate.formField(node)))
return true; return true;
// Containers who have name from contents should be treated like objects if
// the contents is all static text and not large.
if (node.name && node.nameFrom == 'contents') {
var onlyStaticText = true;
var textLength = 0;
for (var i = 0, child; child = node.children[i]; i++) {
if (child.role != Role.STATIC_TEXT) {
onlyStaticText = false;
break;
}
textLength += child.name ? child.name.length + textLength : textLength;
}
if (onlyStaticText && textLength > 0 &&
textLength < constants.OBJECT_MAX_CHARCOUNT)
return true;
}
// Otherwise, leaf or static text nodes that don't contain only whitespace // Otherwise, leaf or static text nodes that don't contain only whitespace
// should be visited with the exception of non-text only nodes. This covers // should be visited with the exception of non-text only nodes. This covers
// cases where an author might make a link with a name of ' '. // cases where an author might make a link with a name of ' '.
......
...@@ -174,6 +174,8 @@ TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() { ...@@ -174,6 +174,8 @@ TEST_F('BackgroundTest', 'ForwardBackwardNavigation', function() {
mockFeedback.call(doCmd('previousObject')) mockFeedback.call(doCmd('previousObject'))
.expectSpeech('foxtraut', 'Heading 2') .expectSpeech('foxtraut', 'Heading 2')
.expectBraille('foxtraut h2'); .expectBraille('foxtraut h2');
mockFeedback.call(doCmd('nextLine'))
.expectSpeech('foxtraut');
mockFeedback.call(doCmd('nextLine')) mockFeedback.call(doCmd('nextLine'))
.expectSpeech('end', 'of test') .expectSpeech('end', 'of test')
.expectBraille('endof test'); .expectBraille('endof test');
......
...@@ -1083,12 +1083,19 @@ Output.prototype = { ...@@ -1083,12 +1083,19 @@ Output.prototype = {
options.annotation.push('name'); options.annotation.push('name');
this.append_(buff, node.name || '', options); this.append_(buff, node.name || '', options);
} else if (token == 'nameOrDescendants') { } else if (token == 'nameOrDescendants') {
// This token is similar to nameOrTextContent except it gathers rich
// output for descendants. It also lets name from contents override
// the descendants text if |node| has only static text children.
options.annotation.push(token); options.annotation.push(token);
if (node.name && if (node.name &&
node.nameFrom != chrome.automation.NameFromType.CONTENTS) (node.nameFrom != 'contents' ||
node.children.every(function(child) {
return child.role == RoleType.STATIC_TEXT;
}))) {
this.append_(buff, node.name || '', options); this.append_(buff, node.name || '', options);
else } else {
this.format_(node, '$descendants', buff); this.format_(node, '$descendants', buff);
}
} else if (token == 'description') { } else if (token == 'description') {
if (node.name == node.description || node.value == node.description) if (node.name == node.description || node.value == node.description)
return; return;
...@@ -1280,7 +1287,7 @@ Output.prototype = { ...@@ -1280,7 +1287,7 @@ Output.prototype = {
} }
} }
} else if (token == 'nameOrTextContent') { } else if (token == 'nameOrTextContent') {
if (node.name) { if (node.name && node.nameFrom != 'contents') {
this.format_(node, '$name', buff); this.format_(node, '$name', buff);
return; return;
} }
......
...@@ -190,12 +190,11 @@ TEST_F('OutputE2ETest', 'Headings', function() { ...@@ -190,12 +190,11 @@ TEST_F('OutputE2ETest', 'Headings', function() {
var letter = String.fromCharCode('a'.charCodeAt(0) + i -1); var letter = String.fromCharCode('a'.charCodeAt(0) + i -1);
assertEqualsJSON({string_: letter + '|Heading ' + i, 'spans_': [ assertEqualsJSON({string_: letter + '|Heading ' + i, 'spans_': [
// Attributes. // Attributes.
{value: 'name', start: 0, end: 1} {value: 'nameOrDescendants', start: 0, end: 1}
]}, o.speechOutputForTest); ]}, o.speechOutputForTest);
checkBrailleOutput( checkBrailleOutput(
letter + ' h' + i, letter + ' h' + i,
[ [
{value: new Output.NodeSpan(el.firstChild), start: 0, end: 1},
{value: new Output.NodeSpan(el), start: 0, end: 4} {value: new Output.NodeSpan(el), start: 0, end: 4}
], ],
o); o);
...@@ -624,7 +623,7 @@ TEST_F('OutputE2ETest', 'AuralStyledHeadings', function() { ...@@ -624,7 +623,7 @@ TEST_F('OutputE2ETest', 'AuralStyledHeadings', function() {
{value: {'relativePitch': toFixed(-0.1 * i)}, start: 0, end: 0}, {value: {'relativePitch': toFixed(-0.1 * i)}, start: 0, end: 0},
// Attributes. // Attributes.
{value: 'name', start: 0, end: 1}, {value: 'nameOrDescendants', start: 0, end: 1},
{value: {'relativePitch': -0.2}, start: 2, end: 2} {value: {'relativePitch': -0.2}, start: 2, end: 2}
]}, o.speechOutputForTest); ]}, o.speechOutputForTest);
......
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