Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/output.js

Issue 1458723002: Finish implementing ChromeVox Next active indicator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@load_key_map
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 var output = new cvox.NavBraille({ 747 var output = new cvox.NavBraille({
735 text: buff, 748 text: buff,
736 startIndex: startIndex, 749 startIndex: startIndex,
737 endIndex: endIndex 750 endIndex: endIndex
738 }); 751 });
739 752
740 cvox.ChromeVox.braille.write(output); 753 cvox.ChromeVox.braille.write(output);
741 } 754 }
742 755
743 // Display. 756 // Display.
744 chrome.accessibilityPrivate.setFocusRing(this.locations_); 757 if (chrome.accessibilityPrivate)
Peter Lundblad 2015/11/20 11:15:03 This guard wouldn't be enoguh on Linux, where the
dmazzoni 2015/11/20 23:35:14 Agreed, testing for isChromeOS makes more sense. D
758 chrome.accessibilityPrivate.setFocusRing(this.locations_);
745 }, 759 },
746 760
747 /** 761 /**
748 * Renders the given range using optional context previous range and event 762 * Renders the given range using optional context previous range and event
749 * type. 763 * type.
750 * @param {!cursors.Range} range 764 * @param {!cursors.Range} range
751 * @param {cursors.Range} prevRange 765 * @param {cursors.Range} prevRange
752 * @param {chrome.automation.EventType|string} type 766 * @param {chrome.automation.EventType|string} type
753 * @param {!Array<Spannable>} buff Buffer to receive rendered output. 767 * @param {!Array<Spannable>} buff Buffer to receive rendered output.
754 * @private 768 * @private
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 range_: function(range, prevRange, type, rangeBuff) { 1060 range_: function(range, prevRange, type, rangeBuff) {
1047 if (!prevRange) 1061 if (!prevRange)
1048 prevRange = cursors.Range.fromNode(range.start.node.root); 1062 prevRange = cursors.Range.fromNode(range.start.node.root);
1049 var cursor = cursors.Cursor.fromNode(range.start.node); 1063 var cursor = cursors.Cursor.fromNode(range.start.node);
1050 var prevNode = prevRange.start.node; 1064 var prevNode = prevRange.start.node;
1051 1065
1052 var formatNodeAndAncestors = function(node, prevNode) { 1066 var formatNodeAndAncestors = function(node, prevNode) {
1053 var buff = []; 1067 var buff = [];
1054 this.ancestry_(node, prevNode, type, buff); 1068 this.ancestry_(node, prevNode, type, buff);
1055 this.node_(node, prevNode, type, buff); 1069 this.node_(node, prevNode, type, buff);
1056 if (this.formatOptions_.location) 1070 this.locations_.push(node.location);
1057 this.locations_.push(node.location);
1058 return buff; 1071 return buff;
1059 }.bind(this); 1072 }.bind(this);
1060 1073
1061 while (cursor.node != range.end.node) { 1074 while (cursor.node != range.end.node) {
1062 var node = cursor.node; 1075 var node = cursor.node;
1063 rangeBuff.push.apply(rangeBuff, formatNodeAndAncestors(node, prevNode)); 1076 rangeBuff.push.apply(rangeBuff, formatNodeAndAncestors(node, prevNode));
1064 prevNode = node; 1077 prevNode = node;
1065 cursor = cursor.move(cursors.Unit.NODE, 1078 cursor = cursor.move(cursors.Unit.NODE,
1066 cursors.Movement.DIRECTIONAL, 1079 cursors.Movement.DIRECTIONAL,
1067 Dir.FORWARD); 1080 Dir.FORWARD);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 var prevNode = prevRange.getBound(dir).node; 1188 var prevNode = prevRange.getBound(dir).node;
1176 this.ancestry_( 1189 this.ancestry_(
1177 range.start.node, prevNode, type, buff, 1190 range.start.node, prevNode, type, buff,
1178 {stay: true, name: true, value: true}); 1191 {stay: true, name: true, value: true});
1179 var startIndex = range.start.index; 1192 var startIndex = range.start.index;
1180 var endIndex = range.end.index; 1193 var endIndex = range.end.index;
1181 if (startIndex === endIndex) 1194 if (startIndex === endIndex)
1182 endIndex++; 1195 endIndex++;
1183 this.append_( 1196 this.append_(
1184 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));
Peter Lundblad 2015/11/20 11:15:03 Cool, it is nice to not have to use document selec
dmazzoni 2015/11/20 23:35:14 Acknowledged.
1185 }, 1200 },
1186 1201
1187 /** 1202 /**
1188 * Appends output to the |buff|. 1203 * Appends output to the |buff|.
1189 * @param {!Array<Spannable>} buff 1204 * @param {!Array<Spannable>} buff
1190 * @param {string|!Spannable} value 1205 * @param {string|!Spannable} value
1191 * @param {{isUnique: (boolean|undefined), 1206 * @param {{isUnique: (boolean|undefined),
1192 * annotation: !Array<*>}=} opt_options 1207 * annotation: !Array<*>}=} opt_options
1193 */ 1208 */
1194 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
1322 elem.end); 1337 elem.end);
1323 }); 1338 });
1324 spansToRemove.forEach(result.removeSpan.bind(result)); 1339 spansToRemove.forEach(result.removeSpan.bind(result));
1325 separator = Output.SPACE; 1340 separator = Output.SPACE;
1326 }); 1341 });
1327 return result; 1342 return result;
1328 } 1343 }
1329 }; 1344 };
1330 1345
1331 }); // goog.scope 1346 }); // goog.scope
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698