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
3 // found in the LICENSE file.
6 * @fileoverview A simple container object for the description of a
7 * navigation from one object to another.
12 goog
.provide('cvox.NavDescription');
14 goog
.require('cvox.AbstractTts');
15 goog
.require('cvox.ChromeVox');
16 goog
.require('cvox.CursorSelection');
17 goog
.require('cvox.QueueMode');
20 * A class representing the description of navigation from one object to
22 * @param {{context: (undefined|string),
24 * userValue: (undefined|string),
25 * annotation: (undefined|string),
26 * earcons: (undefined|Array<number>),
27 * personality: (undefined|Object),
28 * hint: (undefined|string),
29 category: (undefined|string)}} kwargs The arguments for this
31 * context The context, for example descriptions of objects
32 * that were crossed into, like "Toolbar" or "Menu Bar" or "List with
33 * 5 items". This is all spoken with an annotation voice.
34 * text The text of the object itself, including text from
35 * titles, labels, etc.
36 * userValue The text that the user has entered.
37 * annotation The role and state of the object.
38 * earcons A list of the earcon ids to play along
39 * with the spoken description of this object.
40 * personality Optional TTS personality to use for the text.
41 * hint Optional Hint text (.e.g. aria-describedby).
42 * category Optional category (for speech queueing behavior).
45 cvox
.NavDescription = function(kwargs
) {
46 this.context
= kwargs
.context
? kwargs
.context
: '';
47 this.text
= kwargs
.text
? kwargs
.text
: '';
48 this.userValue
= kwargs
.userValue
? kwargs
.userValue
: '';
49 this.annotation
= kwargs
.annotation
? kwargs
.annotation
: '';
50 this.earcons
= kwargs
.earcons
? kwargs
.earcons
: [];
51 this.personality
= kwargs
.personality
;
52 this.hint
= kwargs
.hint
? kwargs
.hint
: '';
53 this.category
= kwargs
.category
? kwargs
.category
: null;
58 * @return {boolean} true if this description is empty.
60 cvox
.NavDescription
.prototype.isEmpty = function() {
61 return (this.context
.length
== 0 &&
62 this.earcons
.length
== 0 &&
63 this.text
.length
== 0 &&
64 this.userValue
.length
== 0 &&
65 this.annotation
.length
== 0);
70 * @return {string} A string representation of this object.
72 cvox
.NavDescription
.prototype.toString = function() {
73 return 'NavDescription(context="' + this.context
+ '" ' +
74 ' text="' + this.text
+ '" ' +
75 ' userValue="' + this.userValue
+ '" ' +
76 ' annotation="' + this.annotation
+
77 (this.category
? '" category="' + this.category
+ '")' : '') +
83 * Modifies the earcon to play along with the spoken description of the object.
84 * @param {number} earconId An earcon id to be pushed on to the list of earcon
85 * ids to play along with the spoken description of this object.
87 cvox
.NavDescription
.prototype.pushEarcon = function(earconId
) {
88 this.earcons
.push(earconId
);
93 * Speak this nav description with the given queue mode.
94 * @param {cvox.QueueMode=} queueMode The queue mode.
95 * @param {function()=} opt_startCallback Function called when this
97 * @param {function()=} opt_endCallback Function called when this ends speaking.
99 cvox
.NavDescription
.prototype.speak = function(
100 queueMode
, opt_startCallback
, opt_endCallback
) {
102 * Return a deep copy of PERSONALITY_ANNOTATION for modifying.
103 * @return {Object} The newly created properties object.
105 function makeAnnotationProps() {
107 var src
= cvox
.AbstractTts
.PERSONALITY_ANNOTATION
;
108 for (var key
in src
) {
109 properties
[key
] = src
[key
];
114 var speakArgs
= new Array();
116 speakArgs
.push([this.context
, queueMode
, makeAnnotationProps()]);
117 queueMode
= cvox
.QueueMode
.QUEUE
;
120 speakArgs
.push([this.text
,
122 this.personality
? this.personality
: {}]);
123 queueMode
= cvox
.QueueMode
.QUEUE
;
125 if (this.userValue
) {
126 speakArgs
.push([this.userValue
, queueMode
, {}]);
129 if (this.annotation
) {
130 speakArgs
.push([this.annotation
, queueMode
, makeAnnotationProps()]);
134 speakArgs
.push([this.hint
, queueMode
, makeAnnotationProps()]);
137 var length
= speakArgs
.length
;
138 for (var i
= 0; i
< length
; i
++) {
139 if (i
== 0 && opt_startCallback
) {
140 speakArgs
[i
][2]['startCallback'] = opt_startCallback
;
142 if (i
== length
- 1 && opt_endCallback
) {
143 speakArgs
[i
][2]['endCallback'] = opt_endCallback
;
146 speakArgs
[i
][2]['category'] = this.category
;
148 cvox
.ChromeVox
.tts
.speak
.apply(cvox
.ChromeVox
.tts
, speakArgs
[i
]);
154 * Compares two NavDescriptions.
155 * @param {cvox.NavDescription} that A NavDescription.
156 * @return {boolean} True if equal.
158 cvox
.NavDescription
.prototype.equals = function(that
) {
159 return this.context
== that
.context
&&
160 this.text
== that
.text
&&
161 this.userValue
== that
.userValue
&&
162 this.annotation
== that
.annotation
;