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 Base class for implementing earcons. | 6 * @fileoverview Base class for implementing earcons. |
7 * | 7 * |
8 * When adding earcons, please add them to getEarconName and getEarconId. | 8 * When adding earcons, please add them to getEarconName and getEarconId. |
9 * | 9 * |
10 */ | 10 */ |
11 | 11 |
12 goog.provide('cvox.AbstractEarcons'); | 12 goog.provide('cvox.AbstractEarcons'); |
| 13 goog.provide('cvox.Earcon'); |
13 | 14 |
14 | 15 |
15 /** | 16 /** |
| 17 * Earcon names. |
| 18 * @enum {string} |
| 19 */ |
| 20 cvox.Earcon = { |
| 21 ALERT_MODAL: 'alert_modal', |
| 22 ALERT_NONMODAL: 'alert_nonmodal', |
| 23 BULLET: 'bullet', |
| 24 BUSY_PROGRESS_LOOP: 'busy_progress_loop', |
| 25 BUTTON: 'button', |
| 26 CHECK_OFF: 'check_off', |
| 27 CHECK_ON: 'check_on', |
| 28 EDITABLE_TEXT: 'editable_text', |
| 29 FONT_CHANGE: 'font_change', |
| 30 INVALID_KEYPRESS: 'invalid_keypress', |
| 31 LINK: 'link', |
| 32 LISTBOX: 'listbox', |
| 33 LIST_ITEM: 'bullet', |
| 34 LONG_DESC: 'long_desc', |
| 35 OBJECT_CLOSE: 'object_close', |
| 36 OBJECT_ENTER: 'object_enter', |
| 37 OBJECT_EXIT: 'object_exit', |
| 38 OBJECT_OPEN: 'object_open', |
| 39 OBJECT_SELECT: 'object_select', |
| 40 PARAGRAPH_BREAK: 'paragraph_break', |
| 41 SECTION: 'section', |
| 42 SELECTION: 'selection', |
| 43 SELECTION_REVERSE: 'selection_reverse', |
| 44 SPECIAL_CONTENT: 'special_content', |
| 45 TASK_SUCCESS: 'task_success', |
| 46 WRAP: 'wrap', |
| 47 WRAP_EDGE: 'wrap_edge', |
| 48 }; |
| 49 |
| 50 |
| 51 /** |
16 * @constructor | 52 * @constructor |
17 */ | 53 */ |
18 cvox.AbstractEarcons = function() { | 54 cvox.AbstractEarcons = function() { |
19 /** | 55 /** |
20 * Public flag set to enable or disable earcons. Callers should prefer | 56 * Public flag set to enable or disable earcons. Callers should prefer |
21 * toggle(); however, this member is public for initialization. | 57 * toggle(); however, this member is public for initialization. |
22 * @type {boolean} | 58 * @type {boolean} |
23 */ | 59 */ |
24 this.enabled = true; | 60 this.enabled = true; |
25 }; | 61 }; |
26 | 62 |
27 | 63 |
28 /** | 64 /** |
29 * Plays the specified earcon sound. | 65 * Plays the specified earcon sound. |
30 * @param {number} earcon An earcon index. | 66 * @param {cvox.Earcon} earcon An earcon identifier. |
31 */ | 67 */ |
32 cvox.AbstractEarcons.prototype.playEarcon = function(earcon) { | 68 cvox.AbstractEarcons.prototype.playEarcon = function(earcon) { |
33 }; | 69 }; |
34 | 70 |
35 | 71 |
36 /** | 72 /** |
37 * Plays the specified earcon sound, given the name of the earcon. | |
38 * @param {string} earconName The name of the earcon. | |
39 */ | |
40 cvox.AbstractEarcons.prototype.playEarconByName = function(earconName) { | |
41 this.playEarcon(this.getEarconId(earconName)); | |
42 }; | |
43 | |
44 | |
45 /** | |
46 * Whether or not earcons are available. | 73 * Whether or not earcons are available. |
47 * @return {boolean} True if earcons are available. | 74 * @return {boolean} True if earcons are available. |
48 */ | 75 */ |
49 cvox.AbstractEarcons.prototype.earconsAvailable = function() { | 76 cvox.AbstractEarcons.prototype.earconsAvailable = function() { |
50 return true; | 77 return true; |
51 }; | 78 }; |
52 | 79 |
53 | 80 |
54 /** | 81 /** |
55 * @param {number} earcon An earcon index. | |
56 * @return {string} The readable earcon name. | |
57 */ | |
58 cvox.AbstractEarcons.prototype.getEarconName = function(earcon) { | |
59 if (!this.earconNames) { | |
60 this.earconNames = new Array(); | |
61 this.earconNames.push('ALERT_MODAL'); | |
62 this.earconNames.push('ALERT_NONMODAL'); | |
63 this.earconNames.push('BULLET'); | |
64 this.earconNames.push('BUSY_PROGRESS_LOOP'); | |
65 this.earconNames.push('BUTTON'); | |
66 this.earconNames.push('CHECK_OFF'); | |
67 this.earconNames.push('CHECK_ON'); | |
68 this.earconNames.push('EDITABLE_TEXT'); | |
69 this.earconNames.push('FONT_CHANGE'); | |
70 this.earconNames.push('INVALID_KEYPRESS'); | |
71 this.earconNames.push('LINK'); | |
72 this.earconNames.push('LISTBOX'); | |
73 this.earconNames.push('LIST_ITEM'); | |
74 this.earconNames.push('LONG_DESC'); | |
75 this.earconNames.push('OBJECT_CLOSE'); | |
76 this.earconNames.push('OBJECT_ENTER'); | |
77 this.earconNames.push('OBJECT_EXIT'); | |
78 this.earconNames.push('OBJECT_OPEN'); | |
79 this.earconNames.push('OBJECT_SELECT'); | |
80 this.earconNames.push('PARAGRAPH_BREAK'); | |
81 this.earconNames.push('SELECTION'); | |
82 this.earconNames.push('SELECTION_REVERSE'); | |
83 this.earconNames.push('SPECIAL_CONTENT'); | |
84 this.earconNames.push('TASK_SUCCESS'); | |
85 this.earconNames.push('WRAP'); | |
86 this.earconNames.push('WRAP_EDGE'); | |
87 } | |
88 return this.earconNames[earcon]; | |
89 }; | |
90 | |
91 | |
92 /** | |
93 * @param {string} earconName An earcon name. | |
94 * @return {number} The earcon ID. | |
95 */ | |
96 cvox.AbstractEarcons.prototype.getEarconId = function(earconName) { | |
97 if (!this.earconNamesToIds) { | |
98 this.earconNamesToIds = new Object(); | |
99 this.earconNamesToIds['ALERT_MODAL'] = | |
100 cvox.AbstractEarcons.ALERT_MODAL; | |
101 this.earconNamesToIds['ALERT_NONMODAL'] = | |
102 cvox.AbstractEarcons.ALERT_NONMODAL; | |
103 this.earconNamesToIds['BULLET'] = cvox.AbstractEarcons.BULLET; | |
104 this.earconNamesToIds['BUSY_PROGRESS_LOOP'] = | |
105 cvox.AbstractEarcons.BUSY_PROGRESS_LOOP; | |
106 this.earconNamesToIds['BUTTON'] = cvox.AbstractEarcons.BUTTON; | |
107 this.earconNamesToIds['CHECK_OFF'] = cvox.AbstractEarcons.CHECK_OFF; | |
108 this.earconNamesToIds['CHECK_ON'] = cvox.AbstractEarcons.CHECK_ON; | |
109 this.earconNamesToIds['EDITABLE_TEXT'] = cvox.AbstractEarcons.EDITABLE_TEXT; | |
110 this.earconNamesToIds['FONT_CHANGE'] = cvox.AbstractEarcons.FONT_CHANGE; | |
111 this.earconNamesToIds['INVALID_KEYPRESS'] = | |
112 cvox.AbstractEarcons.INVALID_KEYPRESS; | |
113 this.earconNamesToIds['LINK'] = cvox.AbstractEarcons.LINK; | |
114 this.earconNamesToIds['LISTBOX'] = cvox.AbstractEarcons.LISTBOX; | |
115 this.earconNamesToIds['LIST_ITEM'] = cvox.AbstractEarcons.LIST_ITEM; | |
116 this.earconNamesToIds['LONG_DESC'] = cvox.AbstractEarcons.LONG_DESC; | |
117 this.earconNamesToIds['OBJECT_CLOSE'] = cvox.AbstractEarcons.OBJECT_CLOSE; | |
118 this.earconNamesToIds['OBJECT_ENTER'] = cvox.AbstractEarcons.OBJECT_ENTER; | |
119 this.earconNamesToIds['OBJECT_EXIT'] = cvox.AbstractEarcons.OBJECT_EXIT; | |
120 this.earconNamesToIds['OBJECT_OPEN'] = cvox.AbstractEarcons.OBJECT_OPEN; | |
121 this.earconNamesToIds['OBJECT_SELECT'] = cvox.AbstractEarcons.OBJECT_SELECT; | |
122 this.earconNamesToIds['PARAGRAPH_BREAK'] = | |
123 cvox.AbstractEarcons.PARAGRAPH_BREAK; | |
124 this.earconNamesToIds['SELECTION'] = cvox.AbstractEarcons.SELECTION; | |
125 this.earconNamesToIds['SELECTION_REVERSE'] = | |
126 cvox.AbstractEarcons.SELECTION_REVERSE; | |
127 this.earconNamesToIds['SPECIAL_CONTENT'] = | |
128 cvox.AbstractEarcons.SPECIAL_CONTENT; | |
129 this.earconNamesToIds['TASK_SUCCESS'] = cvox.AbstractEarcons.TASK_SUCCESS; | |
130 this.earconNamesToIds['WRAP'] = cvox.AbstractEarcons.WRAP; | |
131 this.earconNamesToIds['WRAP_EDGE'] = cvox.AbstractEarcons.WRAP_EDGE; | |
132 } | |
133 return this.earconNamesToIds[earconName]; | |
134 }; | |
135 | |
136 | |
137 /** | |
138 * @param {number} earconId The earcon ID. | |
139 * @return {string} The filename for the earcon. | |
140 */ | |
141 cvox.AbstractEarcons.prototype.getEarconFilename = function(earconId) { | |
142 return cvox.AbstractEarcons.earconMap[earconId]; | |
143 }; | |
144 | |
145 | |
146 /** | |
147 * Toggles earcons on or off. | 82 * Toggles earcons on or off. |
148 * @return {boolean} True if earcons are now enabled; false otherwise. | 83 * @return {boolean} True if earcons are now enabled; false otherwise. |
149 */ | 84 */ |
150 cvox.AbstractEarcons.prototype.toggle = function() { | 85 cvox.AbstractEarcons.prototype.toggle = function() { |
151 this.enabled = !this.enabled; | 86 this.enabled = !this.enabled; |
152 return this.enabled; | 87 return this.enabled; |
153 }; | 88 }; |
154 | |
155 | |
156 /** | |
157 * @type {number} | |
158 */ | |
159 cvox.AbstractEarcons.ALERT_MODAL = 0; | |
160 | |
161 /** | |
162 * @type {number} | |
163 */ | |
164 cvox.AbstractEarcons.ALERT_NONMODAL = 1; | |
165 | |
166 /** | |
167 * @type {number} | |
168 */ | |
169 cvox.AbstractEarcons.BULLET = 2; | |
170 | |
171 /** | |
172 * @type {number} | |
173 */ | |
174 cvox.AbstractEarcons.BUSY_PROGRESS_LOOP = 3; | |
175 | |
176 /** | |
177 * @type {number} | |
178 */ | |
179 cvox.AbstractEarcons.BUTTON = 4; | |
180 | |
181 /** | |
182 * @type {number} | |
183 */ | |
184 cvox.AbstractEarcons.CHECK_OFF = 5; | |
185 | |
186 /** | |
187 * @type {number} | |
188 */ | |
189 cvox.AbstractEarcons.CHECK_ON = 6; | |
190 | |
191 /** | |
192 * @type {number} | |
193 */ | |
194 cvox.AbstractEarcons.EDITABLE_TEXT = 7; | |
195 | |
196 /** | |
197 * @type {number} | |
198 */ | |
199 cvox.AbstractEarcons.FONT_CHANGE = 8; | |
200 | |
201 /** | |
202 * @type {number} | |
203 */ | |
204 cvox.AbstractEarcons.INVALID_KEYPRESS = 9; | |
205 | |
206 /** | |
207 * @type {number} | |
208 */ | |
209 cvox.AbstractEarcons.LINK = 10; | |
210 | |
211 /** | |
212 * @type {number} | |
213 */ | |
214 cvox.AbstractEarcons.LISTBOX = 11; | |
215 | |
216 /** | |
217 * @type {number} | |
218 */ | |
219 cvox.AbstractEarcons.LIST_ITEM = 12; | |
220 | |
221 /** | |
222 * @type {number} | |
223 */ | |
224 cvox.AbstractEarcons.LONG_DESC = 13; | |
225 | |
226 /** | |
227 * @type {number} | |
228 */ | |
229 cvox.AbstractEarcons.OBJECT_CLOSE = 14; | |
230 | |
231 /** | |
232 * @type {number} | |
233 */ | |
234 cvox.AbstractEarcons.OBJECT_ENTER = 15; | |
235 | |
236 /** | |
237 * @type {number} | |
238 */ | |
239 cvox.AbstractEarcons.OBJECT_EXIT = 16; | |
240 | |
241 /** | |
242 * @type {number} | |
243 */ | |
244 cvox.AbstractEarcons.OBJECT_OPEN = 17; | |
245 | |
246 /** | |
247 * @type {number} | |
248 */ | |
249 cvox.AbstractEarcons.OBJECT_SELECT = 18; | |
250 | |
251 /** | |
252 * @type {number} | |
253 */ | |
254 cvox.AbstractEarcons.PARAGRAPH_BREAK = 19; | |
255 | |
256 /** | |
257 * @type {number} | |
258 */ | |
259 cvox.AbstractEarcons.SELECTION = 20; | |
260 | |
261 /** | |
262 * @type {number} | |
263 */ | |
264 cvox.AbstractEarcons.SELECTION_REVERSE = 21; | |
265 | |
266 /** | |
267 * @type {number} | |
268 */ | |
269 cvox.AbstractEarcons.SPECIAL_CONTENT = 22; | |
270 | |
271 /** | |
272 * @type {number} | |
273 */ | |
274 cvox.AbstractEarcons.TASK_SUCCESS = 23; | |
275 | |
276 /** | |
277 * @type {number} | |
278 */ | |
279 cvox.AbstractEarcons.WRAP = 24; | |
280 | |
281 /** | |
282 * @type {number} | |
283 */ | |
284 cvox.AbstractEarcons.WRAP_EDGE = 25; | |
285 | |
286 /** | |
287 * The earcon map. | |
288 * @type {Object} | |
289 */ | |
290 cvox.AbstractEarcons.earconMap = new Object(); | |
291 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.ALERT_NONMODAL] = | |
292 'alert_nonmodal.ogg'; | |
293 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BULLET] = 'bullet.ogg'; | |
294 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BUSY_PROGRESS_LOOP] = | |
295 'busy_progress_loop.ogg'; | |
296 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BUTTON] = 'button.ogg'; | |
297 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.CHECK_OFF] = | |
298 'check_off.ogg'; | |
299 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.CHECK_ON] = 'check_on.ogg'; | |
300 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.EDITABLE_TEXT] = | |
301 'editable_text.ogg'; | |
302 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.FONT_CHANGE] = | |
303 'font_change.ogg'; | |
304 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LINK] = 'link.ogg'; | |
305 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LISTBOX] = 'listbox.ogg'; | |
306 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LIST_ITEM] = 'bullet.ogg'; | |
307 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LONG_DESC] = | |
308 'long_desc.ogg'; | |
309 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_CLOSE] = | |
310 'object_close.ogg'; | |
311 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_ENTER] = | |
312 'object_enter.ogg'; | |
313 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_EXIT] = | |
314 'object_exit.ogg'; | |
315 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_OPEN] = | |
316 'object_open.ogg'; | |
317 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_SELECT] = | |
318 'object_select.ogg'; | |
319 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.PARAGRAPH_BREAK] = | |
320 'paragraph_break.ogg'; | |
321 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SELECTION] = | |
322 'selection.ogg'; | |
323 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SELECTION_REVERSE] = | |
324 'selection_reverse.ogg'; | |
325 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SPECIAL_CONTENT] = | |
326 'special_content.ogg'; | |
327 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.TASK_SUCCESS] = | |
328 'task_success.ogg'; | |
329 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.WRAP] = 'wrap.ogg'; | |
330 cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.WRAP_EDGE] = | |
331 'wrap_edge.ogg'; | |
OLD | NEW |