Commit 1185dbb2 authored by dtseng's avatar dtseng Committed by Commit bot

Support output of heading levels.

- adds rules for headings, both entering and speaking.
- adds a '+' delimiter which allows for subsittutions inside of message tokens.

TEST=OutputE2ETest.*

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

Cr-Commit-Position: refs/heads/master@{#325566}
parent 44bc8c87
...@@ -169,8 +169,8 @@ Output.RULES = { ...@@ -169,8 +169,8 @@ Output.RULES = {
enter: '$name $role' enter: '$name $role'
}, },
heading: { heading: {
enter: '@aria_role_heading', enter: '@tag_h+$hierarchicalLevel',
speak: '@aria_role_heading $name=' speak: '@tag_h+$hierarchicalLevel $name='
}, },
inlineTextBox: { inlineTextBox: {
speak: '$value=' speak: '$value='
...@@ -623,6 +623,14 @@ Output.prototype = { ...@@ -623,6 +623,14 @@ Output.prototype = {
} }
} }
} else if (prefix == '@') { } else if (prefix == '@') {
// Tokens can have substitutions.
var pieces = token.split('+');
token = pieces.reduce(function(prev, cur) {
var lookup = cur;
if (cur[0] == '$')
lookup = node.attributes[cur.slice(1)];
return prev + lookup;
}.bind(this), '');
var msgId = token; var msgId = token;
var msgArgs = []; var msgArgs = [];
var curMsg = tree.firstChild; var curMsg = tree.firstChild;
......
...@@ -83,3 +83,57 @@ TEST_F('OutputE2ETest', 'InLineTextBoxValueGetsIgnored', function() { ...@@ -83,3 +83,57 @@ TEST_F('OutputE2ETest', 'InLineTextBoxValueGetsIgnored', function() {
]}, o.toSpannable()); ]}, o.toSpannable());
}); });
}); });
TEST_F('OutputE2ETest', 'Headings', function() {
this.runWithLoadedTree(
'<h1>a</h1><h2>b</h2><h3>c</h3><h4>d</h4><h5>e</h5><h6>f</h6>',
function(root) {
var el = root.firstChild;
var range = cursors.Range.fromNode(el);
var o = new Output().withSpeechAndBraille(range, null, 'navigate');
assertEqualsJSON({string_: 'Heading 1a', 'spans_': [
// Attributes.
{value: 'name', start: 9, end: 10}
]}, o.toSpannable());
el = el.nextSibling;
range = cursors.Range.fromNode(el);
o = new Output().withSpeechAndBraille(range, null, 'navigate');
assertEqualsJSON({string_: 'Heading 2b', 'spans_': [
// Attributes.
{value: 'name', start: 9, end: 10}
]}, o.toSpannable());
el = el.nextSibling;
range = cursors.Range.fromNode(el);
o = new Output().withSpeechAndBraille(range, null, 'navigate');
assertEqualsJSON({string_: 'Heading 3c', 'spans_': [
// Attributes.
{value: 'name', start: 9, end: 10}
]}, o.toSpannable());
el = el.nextSibling;
range = cursors.Range.fromNode(el);
o = new Output().withSpeechAndBraille(range, null, 'navigate');
assertEqualsJSON({string_: 'Heading 4d', 'spans_': [
// Attributes.
{value: 'name', start: 9, end: 10}
]}, o.toSpannable());
el = el.nextSibling;
range = cursors.Range.fromNode(el);
o = new Output().withSpeechAndBraille(range, null, 'navigate');
assertEqualsJSON({string_: 'Heading 5e', 'spans_': [
// Attributes.
{value: 'name', start: 9, end: 10}
]}, o.toSpannable());
el = el.nextSibling;
range = cursors.Range.fromNode(el);
o = new Output().withSpeechAndBraille(range, null, 'navigate');
assertEqualsJSON({string_: 'Heading 6f', 'spans_': [
// Attributes.
{value: 'name', start: 9, end: 10}
]}, o.toSpannable());
});
});
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