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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 /** @type {!cvox.Spannable} */ | 49 /** @type {!cvox.Spannable} */ |
50 this.buffer_ = new cvox.Spannable(); | 50 this.buffer_ = new cvox.Spannable(); |
51 /** @type {!cvox.Spannable} */ | 51 /** @type {!cvox.Spannable} */ |
52 this.brailleBuffer_ = new cvox.Spannable(); | 52 this.brailleBuffer_ = new cvox.Spannable(); |
53 /** @type {!Array<Object>} */ | 53 /** @type {!Array<Object>} */ |
54 this.locations_ = []; | 54 this.locations_ = []; |
55 /** @type {function()} */ | 55 /** @type {function()} */ |
56 this.speechStartCallback_; | 56 this.speechStartCallback_; |
57 /** @type {function()} */ | 57 /** @type {function()} */ |
58 this.speechEndCallback_; | 58 this.speechEndCallback_; |
59 /** @type {function()} */ | |
60 this.speechInterruptedCallback_; | |
61 | 59 |
62 /** | 60 /** |
63 * Current global options. | 61 * Current global options. |
64 * @type {{speech: boolean, braille: boolean, location: boolean}} | 62 * @type {{speech: boolean, braille: boolean, location: boolean}} |
65 */ | 63 */ |
66 this.formatOptions_ = {speech: true, braille: false, location: true}; | 64 this.formatOptions_ = {speech: true, braille: false, location: true}; |
67 | 65 |
68 /** | 66 /** |
69 * Speech properties to apply to the entire output. | 67 * Speech properties to apply to the entire output. |
70 * @type {!Object<string, *>} | 68 * @type {!Object<string, *>} |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 /** | 296 /** |
299 * Triggers callback for a speech event. | 297 * Triggers callback for a speech event. |
300 * @param {function()} callback | 298 * @param {function()} callback |
301 */ | 299 */ |
302 onSpeechEnd: function(callback) { | 300 onSpeechEnd: function(callback) { |
303 this.speechEndCallback_ = callback; | 301 this.speechEndCallback_ = callback; |
304 return this; | 302 return this; |
305 }, | 303 }, |
306 | 304 |
307 /** | 305 /** |
308 * Triggers callback for a speech event. | |
309 * @param {function()} callback | |
310 */ | |
311 onSpeechInterrupted: function(callback) { | |
312 this.speechInterruptedCallback_ = callback; | |
313 return this; | |
314 }, | |
315 | |
316 /** | |
317 * Executes all specified output. | 306 * Executes all specified output. |
318 */ | 307 */ |
319 go: function() { | 308 go: function() { |
320 // Speech. | 309 // Speech. |
321 var buff = this.buffer_; | 310 var buff = this.buffer_; |
322 | 311 if (buff.toString()) { |
323 var onEvent = function(evt) { | 312 if (this.speechStartCallback_) |
324 switch (evt.type) { | 313 this.speechProperties_['startCallback'] = this.speechStartCallback_; |
325 case 'start': | 314 if (this.speechEndCallback_) { |
326 this.speechStartCallback_(); | 315 this.speechProperties_['endCallback'] = this.speechEndCallback_; |
327 break; | |
328 case 'end': | |
329 this.speechEndCallback_(); | |
330 break; | |
331 case 'interrupted': | |
332 this.speechInterruptedCallback_ && this.speechInterruptedCallback_(); | |
333 break; | |
334 } | 316 } |
335 }.bind(this); | |
336 | |
337 if (buff.toString()) { | |
338 if (this.speechStartCallback_ || | |
339 this.speechEndCallback_ || | |
340 this.speechInterruptedCallback_) | |
341 this.speechProperties_['onEvent'] = onEvent; | |
342 | 317 |
343 cvox.ChromeVox.tts.speak( | 318 cvox.ChromeVox.tts.speak( |
344 buff.toString(), cvox.QueueMode.FLUSH, this.speechProperties_); | 319 buff.toString(), cvox.QueueMode.FLUSH, this.speechProperties_); |
345 } | 320 } |
346 | 321 |
347 var actions = buff.getSpansInstanceOf(Output.Action); | 322 var actions = buff.getSpansInstanceOf(Output.Action); |
348 if (actions) { | 323 if (actions) { |
349 actions.forEach(function(a) { | 324 actions.forEach(function(a) { |
350 a.run(); | 325 a.run(); |
351 }); | 326 }); |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 669 |
695 /** | 670 /** |
696 * Adds to the given buffer with proper delimiters added. | 671 * Adds to the given buffer with proper delimiters added. |
697 * @param {!cvox.Spannable} spannable | 672 * @param {!cvox.Spannable} spannable |
698 * @param {string|!cvox.Spannable} value | 673 * @param {string|!cvox.Spannable} value |
699 * @param {{ifEmpty: boolean, | 674 * @param {{ifEmpty: boolean, |
700 * annotation: (string|Output.Action|undefined)}=} opt_options | 675 * annotation: (string|Output.Action|undefined)}=} opt_options |
701 */ | 676 */ |
702 addToSpannable_: function(spannable, value, opt_options) { | 677 addToSpannable_: function(spannable, value, opt_options) { |
703 opt_options = opt_options || {ifEmpty: false, annotation: undefined}; | 678 opt_options = opt_options || {ifEmpty: false, annotation: undefined}; |
704 if (value.length == 0 && !opt_options.annotation) | 679 if ((!value || value.length == 0) && !opt_options.annotation) |
705 return; | 680 return; |
706 | 681 |
707 var spannableToAdd = new cvox.Spannable(value, opt_options.annotation); | 682 var spannableToAdd = new cvox.Spannable(value, opt_options.annotation); |
708 if (spannable.getLength() == 0) { | 683 if (spannable.getLength() == 0) { |
709 spannable.append(spannableToAdd); | 684 spannable.append(spannableToAdd); |
710 return; | 685 return; |
711 } | 686 } |
712 | 687 |
713 if (opt_options.ifEmpty && | 688 if (opt_options.ifEmpty && |
714 opt_options.annotation && | 689 opt_options.annotation && |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 731 } |
757 | 732 |
758 if (currentNode != root) | 733 if (currentNode != root) |
759 throw 'Unbalanced parenthesis.'; | 734 throw 'Unbalanced parenthesis.'; |
760 | 735 |
761 return root; | 736 return root; |
762 } | 737 } |
763 }; | 738 }; |
764 | 739 |
765 }); // goog.scope | 740 }); // goog.scope |
OLD | NEW |