OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Provides output services for ChromeVox. | 6 * @fileoverview Provides output services for ChromeVox. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('Output'); | 9 goog.provide('Output'); |
10 goog.provide('Output.EventType'); | 10 goog.provide('Output.EventType'); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 this.speechBuffer_ = []; | 56 this.speechBuffer_ = []; |
57 /** @type {!Array<!Spannable>} */ | 57 /** @type {!Array<!Spannable>} */ |
58 this.brailleBuffer_ = []; | 58 this.brailleBuffer_ = []; |
59 /** @type {!Array<!Object>} */ | 59 /** @type {!Array<!Object>} */ |
60 this.locations_ = []; | 60 this.locations_ = []; |
61 /** @type {function(?)} */ | 61 /** @type {function(?)} */ |
62 this.speechEndCallback_; | 62 this.speechEndCallback_; |
63 | 63 |
64 /** | 64 /** |
65 * Current global options. | 65 * Current global options. |
66 * @type {{speech: boolean, braille: boolean, location: boolean}} | 66 * @type {{speech: boolean, braille: boolean}} |
67 */ | 67 */ |
68 this.formatOptions_ = {speech: true, braille: false, location: true}; | 68 this.formatOptions_ = {speech: true, braille: false}; |
69 | 69 |
70 /** | 70 /** |
71 * Speech properties to apply to the entire output. | 71 * Speech properties to apply to the entire output. |
72 * @type {!Object<*>} | 72 * @type {!Object<*>} |
73 */ | 73 */ |
74 this.speechProperties_ = {}; | 74 this.speechProperties_ = {}; |
75 }; | 75 }; |
76 | 76 |
77 /** | 77 /** |
78 * Delimiter to use between output values. | 78 * Delimiter to use between output values. |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
611 }, | 611 }, |
612 | 612 |
613 /** | 613 /** |
614 * Specify ranges for speech. | 614 * Specify ranges for speech. |
615 * @param {!cursors.Range} range | 615 * @param {!cursors.Range} range |
616 * @param {cursors.Range} prevRange | 616 * @param {cursors.Range} prevRange |
617 * @param {chrome.automation.EventType|Output.EventType} type | 617 * @param {chrome.automation.EventType|Output.EventType} type |
618 * @return {!Output} | 618 * @return {!Output} |
619 */ | 619 */ |
620 withSpeech: function(range, prevRange, type) { | 620 withSpeech: function(range, prevRange, type) { |
621 this.formatOptions_ = {speech: true, braille: false, location: true}; | 621 this.formatOptions_ = {speech: true, braille: false}; |
622 this.render_(range, prevRange, type, this.speechBuffer_); | 622 this.render_(range, prevRange, type, this.speechBuffer_); |
623 return this; | 623 return this; |
624 }, | 624 }, |
625 | 625 |
626 /** | 626 /** |
627 * Specify ranges for braille. | 627 * Specify ranges for braille. |
628 * @param {!cursors.Range} range | 628 * @param {!cursors.Range} range |
629 * @param {cursors.Range} prevRange | 629 * @param {cursors.Range} prevRange |
630 * @param {chrome.automation.EventType|Output.EventType} type | 630 * @param {chrome.automation.EventType|Output.EventType} type |
631 * @return {!Output} | 631 * @return {!Output} |
632 */ | 632 */ |
633 withBraille: function(range, prevRange, type) { | 633 withBraille: function(range, prevRange, type) { |
634 this.formatOptions_ = {speech: false, braille: true, location: false}; | 634 this.formatOptions_ = {speech: false, braille: true}; |
635 this.render_(range, prevRange, type, this.brailleBuffer_); | 635 this.render_(range, prevRange, type, this.brailleBuffer_); |
636 return this; | 636 return this; |
637 }, | 637 }, |
638 | 638 |
639 /** | 639 /** |
| 640 * Specify ranges for location. |
| 641 * @param {!cursors.Range} range |
| 642 * @param {cursors.Range} prevRange |
| 643 * @param {chrome.automation.EventType|Output.EventType} type |
| 644 * @return {!Output} |
| 645 */ |
| 646 withLocation: function(range, prevRange, type) { |
| 647 this.formatOptions_ = {speech: false, braille: false}; |
| 648 this.render_(range, prevRange, type, this.speechBuffer_); |
| 649 return this; |
| 650 }, |
| 651 |
| 652 /** |
640 * Specify the same ranges for speech and braille. | 653 * Specify the same ranges for speech and braille. |
641 * @param {!cursors.Range} range | 654 * @param {!cursors.Range} range |
642 * @param {cursors.Range} prevRange | 655 * @param {cursors.Range} prevRange |
643 * @param {chrome.automation.EventType|Output.EventType} type | 656 * @param {chrome.automation.EventType|Output.EventType} type |
644 * @return {!Output} | 657 * @return {!Output} |
645 */ | 658 */ |
646 withSpeechAndBraille: function(range, prevRange, type) { | 659 withSpeechAndBraille: function(range, prevRange, type) { |
647 this.withSpeech(range, prevRange, type); | 660 this.withSpeech(range, prevRange, type); |
648 this.withBraille(range, prevRange, type); | 661 this.withBraille(range, prevRange, type); |
649 return this; | 662 return this; |
650 }, | 663 }, |
651 | 664 |
652 /** | 665 /** |
653 * Applies the given speech category to the output. | 666 * Applies the given speech category to the output. |
654 * @param {cvox.TtsCategory} category | 667 * @param {cvox.TtsCategory} category |
655 * @return {!Output} | 668 * @return {!Output} |
656 */ | 669 */ |
657 withSpeechCategory: function(category) { | 670 withSpeechCategory: function(category) { |
658 this.speechProperties_['category'] = category; | 671 this.speechProperties_['category'] = category; |
659 return this; | 672 return this; |
660 }, | 673 }, |
661 | 674 |
662 /** | 675 /** |
663 * Apply a format string directly to the output buffer. This lets you | 676 * Apply a format string directly to the output buffer. This lets you |
664 * output a message directly to the buffer using the format syntax. | 677 * output a message directly to the buffer using the format syntax. |
665 * @param {string} formatStr | 678 * @param {string} formatStr |
666 * @return {!Output} | 679 * @return {!Output} |
667 */ | 680 */ |
668 format: function(formatStr) { | 681 format: function(formatStr) { |
669 this.formatOptions_ = {speech: true, braille: false, location: true}; | 682 this.formatOptions_ = {speech: true, braille: false}; |
670 this.format_(null, formatStr, this.speechBuffer_); | 683 this.format_(null, formatStr, this.speechBuffer_); |
671 | 684 |
672 this.formatOptions_ = {speech: false, braille: true, location: false}; | 685 this.formatOptions_ = {speech: false, braille: true}; |
673 this.format_(null, formatStr, this.brailleBuffer_); | 686 this.format_(null, formatStr, this.brailleBuffer_); |
674 | 687 |
675 return this; | 688 return this; |
676 }, | 689 }, |
677 | 690 |
678 /** | 691 /** |
679 * Triggers callback for a speech event. | 692 * Triggers callback for a speech event. |
680 * @param {function()} callback | 693 * @param {function()} callback |
681 */ | 694 */ |
682 onSpeechEnd: function(callback) { | 695 onSpeechEnd: function(callback) { |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1047 range_: function(range, prevRange, type, rangeBuff) { | 1060 range_: function(range, prevRange, type, rangeBuff) { |
1048 if (!prevRange) | 1061 if (!prevRange) |
1049 prevRange = cursors.Range.fromNode(range.start.node.root); | 1062 prevRange = cursors.Range.fromNode(range.start.node.root); |
1050 var cursor = cursors.Cursor.fromNode(range.start.node); | 1063 var cursor = cursors.Cursor.fromNode(range.start.node); |
1051 var prevNode = prevRange.start.node; | 1064 var prevNode = prevRange.start.node; |
1052 | 1065 |
1053 var formatNodeAndAncestors = function(node, prevNode) { | 1066 var formatNodeAndAncestors = function(node, prevNode) { |
1054 var buff = []; | 1067 var buff = []; |
1055 this.ancestry_(node, prevNode, type, buff); | 1068 this.ancestry_(node, prevNode, type, buff); |
1056 this.node_(node, prevNode, type, buff); | 1069 this.node_(node, prevNode, type, buff); |
1057 if (this.formatOptions_.location) | 1070 this.locations_.push(node.location); |
1058 this.locations_.push(node.location); | |
1059 return buff; | 1071 return buff; |
1060 }.bind(this); | 1072 }.bind(this); |
1061 | 1073 |
1062 while (cursor.node != range.end.node) { | 1074 while (cursor.node != range.end.node) { |
1063 var node = cursor.node; | 1075 var node = cursor.node; |
1064 rangeBuff.push.apply(rangeBuff, formatNodeAndAncestors(node, prevNode)); | 1076 rangeBuff.push.apply(rangeBuff, formatNodeAndAncestors(node, prevNode)); |
1065 prevNode = node; | 1077 prevNode = node; |
1066 cursor = cursor.move(cursors.Unit.NODE, | 1078 cursor = cursor.move(cursors.Unit.NODE, |
1067 cursors.Movement.DIRECTIONAL, | 1079 cursors.Movement.DIRECTIONAL, |
1068 Dir.FORWARD); | 1080 Dir.FORWARD); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1176 var prevNode = prevRange.getBound(dir).node; | 1188 var prevNode = prevRange.getBound(dir).node; |
1177 this.ancestry_( | 1189 this.ancestry_( |
1178 range.start.node, prevNode, type, buff, | 1190 range.start.node, prevNode, type, buff, |
1179 {stay: true, name: true, value: true}); | 1191 {stay: true, name: true, value: true}); |
1180 var startIndex = range.start.index; | 1192 var startIndex = range.start.index; |
1181 var endIndex = range.end.index; | 1193 var endIndex = range.end.index; |
1182 if (startIndex === endIndex) | 1194 if (startIndex === endIndex) |
1183 endIndex++; | 1195 endIndex++; |
1184 this.append_( | 1196 this.append_( |
1185 buff, range.start.getText().substring(startIndex, endIndex)); | 1197 buff, range.start.getText().substring(startIndex, endIndex)); |
| 1198 this.locations_.push( |
| 1199 range.start.node.boundsForRange(startIndex, endIndex)); |
1186 }, | 1200 }, |
1187 | 1201 |
1188 /** | 1202 /** |
1189 * Appends output to the |buff|. | 1203 * Appends output to the |buff|. |
1190 * @param {!Array<Spannable>} buff | 1204 * @param {!Array<Spannable>} buff |
1191 * @param {string|!Spannable} value | 1205 * @param {string|!Spannable} value |
1192 * @param {{isUnique: (boolean|undefined), | 1206 * @param {{isUnique: (boolean|undefined), |
1193 * annotation: !Array<*>}=} opt_options | 1207 * annotation: !Array<*>}=} opt_options |
1194 */ | 1208 */ |
1195 append_: function(buff, value, opt_options) { | 1209 append_: function(buff, value, opt_options) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 elem.end); | 1337 elem.end); |
1324 }); | 1338 }); |
1325 spansToRemove.forEach(result.removeSpan.bind(result)); | 1339 spansToRemove.forEach(result.removeSpan.bind(result)); |
1326 separator = Output.SPACE; | 1340 separator = Output.SPACE; |
1327 }); | 1341 }); |
1328 return result; | 1342 return result; |
1329 } | 1343 } |
1330 }; | 1344 }; |
1331 | 1345 |
1332 }); // goog.scope | 1346 }); // goog.scope |
OLD | NEW |