| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 * be passed as a COUNT named parameter to MessageFormat. | 51 * be passed as a COUNT named parameter to MessageFormat. |
| 52 * TODO(plundblad): Make subsequent arguments normal placeholder arguments | 52 * TODO(plundblad): Make subsequent arguments normal placeholder arguments |
| 53 * when needed. | 53 * when needed. |
| 54 * = suffix: used to specify substitution only if not previously appended. | 54 * = suffix: used to specify substitution only if not previously appended. |
| 55 * For example, $name= would insert the name attribute only if no name | 55 * For example, $name= would insert the name attribute only if no name |
| 56 * attribute had been inserted previously. | 56 * attribute had been inserted previously. |
| 57 * @constructor | 57 * @constructor |
| 58 */ | 58 */ |
| 59 Output = function() { | 59 Output = function() { |
| 60 // TODO(dtseng): Include braille specific rules. | 60 // TODO(dtseng): Include braille specific rules. |
| 61 /** @type {!Array<!Spannable>} */ | 61 /** @type {!Array<!Spannable>} @private */ |
| 62 this.speechBuffer_ = []; | 62 this.speechBuffer_ = []; |
| 63 /** @type {!Array<!Spannable>} */ | 63 /** @type {!Array<!Spannable>} @private */ |
| 64 this.brailleBuffer_ = []; | 64 this.brailleBuffer_ = []; |
| 65 /** @type {!Array<!Object>} */ | 65 /** @type {!Array<!Object>} @private */ |
| 66 this.locations_ = []; | 66 this.locations_ = []; |
| 67 /** @type {function(?)} */ | 67 /** @type {function(?)} @private */ |
| 68 this.speechEndCallback_; | 68 this.speechEndCallback_; |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Current global options. | 71 * Current global options. |
| 72 * @type {{speech: boolean, braille: boolean, auralStyle: boolean}} | 72 * @type {{speech: boolean, braille: boolean, auralStyle: boolean}} |
| 73 * @private | 73 * @private |
| 74 */ | 74 */ |
| 75 this.formatOptions_ = {speech: true, braille: false, auralStyle: false}; | 75 this.formatOptions_ = {speech: true, braille: false, auralStyle: false}; |
| 76 | 76 |
| 77 /** | 77 /** |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 | 681 |
| 682 /** | 682 /** |
| 683 * Possible events handled by ChromeVox internally. | 683 * Possible events handled by ChromeVox internally. |
| 684 * @enum {string} | 684 * @enum {string} |
| 685 */ | 685 */ |
| 686 Output.EventType = { | 686 Output.EventType = { |
| 687 NAVIGATE: 'navigate' | 687 NAVIGATE: 'navigate' |
| 688 }; | 688 }; |
| 689 | 689 |
| 690 /** | 690 /** |
| 691 * If true, the next speech utterance will flush instead of the normal | 691 * If set, the next speech utterance will use this value instead of the normal |
| 692 * queueing mode. | 692 * queueing mode. |
| 693 * @type {boolean} | 693 * @type {cvox.QueueMode|undefined} |
| 694 * @private | 694 * @private |
| 695 */ | 695 */ |
| 696 Output.flushNextSpeechUtterance_ = false; | 696 Output.forceModeForNextSpeechUtterance_; |
| 697 | 697 |
| 698 /** | 698 /** |
| 699 * Calling this will make the next speech utterance flush even if it would | 699 * Calling this will make the next speech utterance use |mode| even if it would |
| 700 * normally queue or do a category flush. | 700 * normally queue or do a category flush. This differs from the |withQueueMode| |
| 701 * instance method as it can apply to future output. |
| 702 * @param {cvox.QueueMode} mode |
| 701 */ | 703 */ |
| 702 Output.flushNextSpeechUtterance = function() { | 704 Output.forceModeForNextSpeechUtterance = function(mode) { |
| 703 Output.flushNextSpeechUtterance_ = true; | 705 Output.forceModeForNextSpeechUtterance_ = mode; |
| 704 }; | 706 }; |
| 705 | 707 |
| 706 Output.prototype = { | 708 Output.prototype = { |
| 707 /** | 709 /** |
| 708 * Gets the spoken output with separator '|'. | 710 * Gets the spoken output with separator '|'. |
| 709 * @return {!Spannable} | 711 * @return {!Spannable} |
| 710 */ | 712 */ |
| 711 get speechOutputForTest() { | 713 get speechOutputForTest() { |
| 712 return this.speechBuffer_.reduce(function(prev, cur) { | 714 return this.speechBuffer_.reduce(function(prev, cur) { |
| 713 if (prev === null) | 715 if (prev === null) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 | 902 |
| 901 this.formatOptions_ = {speech: false, braille: true, auralStyle: false}; | 903 this.formatOptions_ = {speech: false, braille: true, auralStyle: false}; |
| 902 this.format_(node, formatStr, this.brailleBuffer_); | 904 this.format_(node, formatStr, this.brailleBuffer_); |
| 903 | 905 |
| 904 return this; | 906 return this; |
| 905 }, | 907 }, |
| 906 | 908 |
| 907 /** | 909 /** |
| 908 * Triggers callback for a speech event. | 910 * Triggers callback for a speech event. |
| 909 * @param {function()} callback | 911 * @param {function()} callback |
| 912 * @return {Output} |
| 910 */ | 913 */ |
| 911 onSpeechEnd: function(callback) { | 914 onSpeechEnd: function(callback) { |
| 912 this.speechEndCallback_ = function(opt_cleanupOnly) { | 915 this.speechEndCallback_ = function(opt_cleanupOnly) { |
| 913 if (!opt_cleanupOnly) | 916 if (!opt_cleanupOnly) |
| 914 callback(); | 917 callback(); |
| 915 }.bind(this); | 918 }.bind(this); |
| 916 return this; | 919 return this; |
| 917 }, | 920 }, |
| 918 | 921 |
| 919 /** | 922 /** |
| 920 * Executes all specified output. | 923 * Executes all specified output. |
| 921 */ | 924 */ |
| 922 go: function() { | 925 go: function() { |
| 923 // Speech. | 926 // Speech. |
| 924 var queueMode = this.queueMode_; | 927 var queueMode = this.queueMode_; |
| 925 this.speechBuffer_.forEach(function(buff, i, a) { | 928 this.speechBuffer_.forEach(function(buff, i, a) { |
| 926 if (Output.flushNextSpeechUtterance_ && buff.length > 0) { | 929 if (Output.forceModeForNextSpeechUtterance_ !== undefined && |
| 927 queueMode = cvox.QueueMode.FLUSH; | 930 buff.length > 0) { |
| 928 Output.flushNextSpeechUtterance_ = false; | 931 queueMode = Output.forceModeForNextSpeechUtterance_; |
| 932 Output.forceModeForNextSpeechUtterance_ = undefined; |
| 929 } | 933 } |
| 930 | 934 |
| 931 var speechProps = {}; | 935 var speechProps = {}; |
| 932 (function() { | 936 (function() { |
| 933 var scopedBuff = buff; | 937 var scopedBuff = buff; |
| 934 speechProps = | 938 speechProps = |
| 935 scopedBuff.getSpanInstanceOf(Output.SpeechProperties) || {}; | 939 scopedBuff.getSpanInstanceOf(Output.SpeechProperties) || {}; |
| 936 speechProps.category = this.speechCategory_; | 940 speechProps.category = this.speechCategory_; |
| 937 | 941 |
| 938 speechProps['startCallback'] = function() { | 942 speechProps['startCallback'] = function() { |
| (...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1702 break; | 1706 break; |
| 1703 } | 1707 } |
| 1704 earconFinder = earconFinder.parent; | 1708 earconFinder = earconFinder.parent; |
| 1705 } | 1709 } |
| 1706 } | 1710 } |
| 1707 return null; | 1711 return null; |
| 1708 } | 1712 } |
| 1709 }; | 1713 }; |
| 1710 | 1714 |
| 1711 }); // goog.scope | 1715 }); // goog.scope |
| OLD | NEW |