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