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. 4 5/** 6 * @fileoverview Base class for implementing earcons. 7 * 8 * When adding earcons, please add them to getEarconName and getEarconId. 9 * 10 */ 11 12goog.provide('cvox.AbstractEarcons'); 13 14 15/** 16 * @constructor 17 */ 18cvox.AbstractEarcons = function() { 19 /** 20 * Public flag set to enable or disable earcons. Callers should prefer 21 * toggle(); however, this member is public for initialization. 22 * @type {boolean} 23 */ 24 this.enabled = true; 25}; 26 27 28/** 29 * Plays the specified earcon sound. 30 * @param {number} earcon An earcon index. 31 */ 32cvox.AbstractEarcons.prototype.playEarcon = function(earcon) { 33}; 34 35 36/** 37 * Plays the specified earcon sound, given the name of the earcon. 38 * @param {string} earconName The name of the earcon. 39 */ 40cvox.AbstractEarcons.prototype.playEarconByName = function(earconName) { 41 this.playEarcon(this.getEarconId(earconName)); 42}; 43 44 45/** 46 * Whether or not earcons are available. 47 * @return {boolean} True if earcons are available. 48 */ 49cvox.AbstractEarcons.prototype.earconsAvailable = function() { 50 return true; 51}; 52 53 54/** 55 * @param {number} earcon An earcon index. 56 * @return {string} The readable earcon name. 57 */ 58cvox.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('BUSY_WORKING_LOOP'); 66 this.earconNames.push('BUTTON'); 67 this.earconNames.push('CHECK_OFF'); 68 this.earconNames.push('CHECK_ON'); 69 this.earconNames.push('COLLAPSED'); 70 this.earconNames.push('EDITABLE_TEXT'); 71 this.earconNames.push('ELLIPSIS'); 72 this.earconNames.push('EXPANDED'); 73 this.earconNames.push('FONT_CHANGE'); 74 this.earconNames.push('INVALID_KEYPRESS'); 75 this.earconNames.push('LINK'); 76 this.earconNames.push('LISTBOX'); 77 this.earconNames.push('LIST_ITEM'); 78 this.earconNames.push('LONG_DESC'); 79 this.earconNames.push('NEW_MAIL'); 80 this.earconNames.push('OBJECT_CLOSE'); 81 this.earconNames.push('OBJECT_DELETE'); 82 this.earconNames.push('OBJECT_DESELECT'); 83 this.earconNames.push('OBJECT_ENTER'); 84 this.earconNames.push('OBJECT_EXIT'); 85 this.earconNames.push('OBJECT_OPEN'); 86 this.earconNames.push('OBJECT_SELECT'); 87 this.earconNames.push('PARAGRAPH_BREAK'); 88 this.earconNames.push('SEARCH_HIT'); 89 this.earconNames.push('SEARCH_MISS'); 90 this.earconNames.push('SECTION'); 91 this.earconNames.push('SELECTION'); 92 this.earconNames.push('SELECTION_REVERSE'); 93 this.earconNames.push('SPECIAL_CONTENT'); 94 this.earconNames.push('TASK_SUCCESS'); 95 this.earconNames.push('WRAP'); 96 this.earconNames.push('WRAP_EDGE'); 97 } 98 return this.earconNames[earcon]; 99}; 100 101 102/** 103 * @param {string} earconName An earcon name. 104 * @return {number} The earcon ID. 105 */ 106cvox.AbstractEarcons.prototype.getEarconId = function(earconName) { 107 if (!this.earconNamesToIds) { 108 this.earconNamesToIds = new Object(); 109 this.earconNamesToIds['ALERT_MODAL'] = cvox.AbstractEarcons.ALERT_MODAL; 110 this.earconNamesToIds['ALERT_NONMODAL'] = 111 cvox.AbstractEarcons.ALERT_NONMODAL; 112 this.earconNamesToIds['BULLET'] = cvox.AbstractEarcons.BULLET; 113 this.earconNamesToIds['BUSY_PROGRESS_LOOP'] = 114 cvox.AbstractEarcons.BUSY_PROGRESS_LOOP; 115 this.earconNamesToIds['BUSY_WORKING_LOOP'] = 116 cvox.AbstractEarcons.BUSY_WORKING_LOOP; 117 this.earconNamesToIds['BUTTON'] = cvox.AbstractEarcons.BUTTON; 118 this.earconNamesToIds['CHECK_OFF'] = cvox.AbstractEarcons.CHECK_OFF; 119 this.earconNamesToIds['CHECK_ON'] = cvox.AbstractEarcons.CHECK_ON; 120 this.earconNamesToIds['COLLAPSED'] = cvox.AbstractEarcons.COLLAPSED; 121 this.earconNamesToIds['EDITABLE_TEXT'] = cvox.AbstractEarcons.EDITABLE_TEXT; 122 this.earconNamesToIds['ELLIPSIS'] = cvox.AbstractEarcons.ELLIPSIS; 123 this.earconNamesToIds['EXPANDED'] = cvox.AbstractEarcons.EXPANDED; 124 this.earconNamesToIds['FONT_CHANGE'] = cvox.AbstractEarcons.FONT_CHANGE; 125 this.earconNamesToIds['INVALID_KEYPRESS'] = 126 cvox.AbstractEarcons.INVALID_KEYPRESS; 127 this.earconNamesToIds['LINK'] = cvox.AbstractEarcons.LINK; 128 this.earconNamesToIds['LISTBOX'] = cvox.AbstractEarcons.LISTBOX; 129 this.earconNamesToIds['LIST_ITEM'] = cvox.AbstractEarcons.LIST_ITEM; 130 this.earconNamesToIds['LONG_DESC'] = cvox.AbstractEarcons.LONG_DESC; 131 this.earconNamesToIds['NEW_MAIL'] = cvox.AbstractEarcons.NEW_MAIL; 132 this.earconNamesToIds['OBJECT_CLOSE'] = cvox.AbstractEarcons.OBJECT_CLOSE; 133 this.earconNamesToIds['OBJECT_DELETE'] = cvox.AbstractEarcons.OBJECT_DELETE; 134 this.earconNamesToIds['OBJECT_DESELECT'] = 135 cvox.AbstractEarcons.OBJECT_DESELECT; 136 this.earconNamesToIds['OBJECT_ENTER'] = cvox.AbstractEarcons.OBJECT_ENTER; 137 this.earconNamesToIds['OBJECT_EXIT'] = cvox.AbstractEarcons.OBJECT_EXIT; 138 this.earconNamesToIds['OBJECT_OPEN'] = cvox.AbstractEarcons.OBJECT_OPEN; 139 this.earconNamesToIds['OBJECT_SELECT'] = cvox.AbstractEarcons.OBJECT_SELECT; 140 this.earconNamesToIds['PARAGRAPH_BREAK'] = 141 cvox.AbstractEarcons.PARAGRAPH_BREAK; 142 this.earconNamesToIds['SEARCH_HIT'] = cvox.AbstractEarcons.SEARCH_HIT; 143 this.earconNamesToIds['SEARCH_MISS'] = cvox.AbstractEarcons.SEARCH_MISS; 144 this.earconNamesToIds['SECTION'] = cvox.AbstractEarcons.SECTION; 145 this.earconNamesToIds['SELECTION'] = cvox.AbstractEarcons.SELECTION; 146 this.earconNamesToIds['SELECTION_REVERSE'] = 147 cvox.AbstractEarcons.SELECTION_REVERSE; 148 this.earconNamesToIds['SPECIAL_CONTENT'] = 149 cvox.AbstractEarcons.SPECIAL_CONTENT; 150 this.earconNamesToIds['TASK_SUCCESS'] = cvox.AbstractEarcons.TASK_SUCCESS; 151 this.earconNamesToIds['WRAP'] = cvox.AbstractEarcons.WRAP; 152 this.earconNamesToIds['WRAP_EDGE'] = cvox.AbstractEarcons.WRAP_EDGE; 153 } 154 return this.earconNamesToIds[earconName]; 155}; 156 157 158/** 159 * @param {number} earconId The earcon ID. 160 * @return {string} The filename for the earcon. 161 */ 162cvox.AbstractEarcons.prototype.getEarconFilename = function(earconId) { 163 return cvox.AbstractEarcons.earconMap[earconId]; 164}; 165 166 167/** 168 * Toggles earcons on or off. 169 * @return {boolean} True if earcons are now enabled; false otherwise. 170 */ 171cvox.AbstractEarcons.prototype.toggle = function() { 172 this.enabled = !this.enabled; 173 return this.enabled; 174}; 175 176 177/** 178 * @type {number} 179 */ 180cvox.AbstractEarcons.ALERT_MODAL = 0; 181 182/** 183 * @type {number} 184 */ 185cvox.AbstractEarcons.ALERT_NONMODAL = 1; 186 187/** 188 * @type {number} 189 */ 190cvox.AbstractEarcons.BULLET = 2; 191 192/** 193 * @type {number} 194 */ 195cvox.AbstractEarcons.BUSY_PROGRESS_LOOP = 3; 196 197/** 198 * @type {number} 199 */ 200cvox.AbstractEarcons.BUSY_WORKING_LOOP = 4; 201 202/** 203 * @type {number} 204 */ 205cvox.AbstractEarcons.BUTTON = 5; 206 207/** 208 * @type {number} 209 */ 210cvox.AbstractEarcons.CHECK_OFF = 6; 211 212/** 213 * @type {number} 214 */ 215cvox.AbstractEarcons.CHECK_ON = 7; 216 217/** 218 * @type {number} 219 */ 220cvox.AbstractEarcons.COLLAPSED = 8; 221 222/** 223 * @type {number} 224 */ 225cvox.AbstractEarcons.EDITABLE_TEXT = 9; 226 227/** 228 * @type {number} 229 */ 230cvox.AbstractEarcons.ELLIPSIS = 10; 231 232/** 233 * @type {number} 234 */ 235cvox.AbstractEarcons.EXPANDED = 11; 236 237/** 238 * @type {number} 239 */ 240cvox.AbstractEarcons.FONT_CHANGE = 12; 241 242/** 243 * @type {number} 244 */ 245cvox.AbstractEarcons.INVALID_KEYPRESS = 13; 246 247/** 248 * @type {number} 249 */ 250cvox.AbstractEarcons.LINK = 14; 251 252/** 253 * @type {number} 254 */ 255cvox.AbstractEarcons.LISTBOX = 15; 256 257/** 258 * @type {number} 259 */ 260cvox.AbstractEarcons.LIST_ITEM = 16; 261 262/** 263 * @type {number} 264 */ 265cvox.AbstractEarcons.LONG_DESC = 17; 266 267/** 268 * @type {number} 269 */ 270cvox.AbstractEarcons.NEW_MAIL = 18; 271 272/** 273 * @type {number} 274 */ 275cvox.AbstractEarcons.OBJECT_CLOSE = 19; 276 277/** 278 * @type {number} 279 */ 280cvox.AbstractEarcons.OBJECT_DELETE = 20; 281 282/** 283 * @type {number} 284 */ 285cvox.AbstractEarcons.OBJECT_DESELECT = 21; 286 287/** 288 * @type {number} 289 */ 290cvox.AbstractEarcons.OBJECT_ENTER = 22; 291 292/** 293 * @type {number} 294 */ 295cvox.AbstractEarcons.OBJECT_EXIT = 23; 296 297/** 298 * @type {number} 299 */ 300cvox.AbstractEarcons.OBJECT_OPEN = 24; 301 302/** 303 * @type {number} 304 */ 305cvox.AbstractEarcons.OBJECT_SELECT = 25; 306 307/** 308 * @type {number} 309 */ 310cvox.AbstractEarcons.PARAGRAPH_BREAK = 26; 311 312/** 313 * @type {number} 314 */ 315cvox.AbstractEarcons.SEARCH_HIT = 27; 316 317/** 318 * @type {number} 319 */ 320cvox.AbstractEarcons.SEARCH_MISS = 28; 321 322/** 323 * @type {number} 324 */ 325cvox.AbstractEarcons.SECTION = 29; 326 327/** 328 * @type {number} 329 */ 330cvox.AbstractEarcons.SELECTION = 30; 331 332/** 333 * @type {number} 334 */ 335cvox.AbstractEarcons.SELECTION_REVERSE = 31; 336 337/** 338 * @type {number} 339 */ 340cvox.AbstractEarcons.SPECIAL_CONTENT = 32; 341 342/** 343 * @type {number} 344 */ 345cvox.AbstractEarcons.TASK_SUCCESS = 33; 346 347/** 348 * @type {number} 349 */ 350cvox.AbstractEarcons.WRAP = 34; 351 352/** 353 * @type {number} 354 */ 355cvox.AbstractEarcons.WRAP_EDGE = 35; 356 357/** 358 * The earcon map. 359 * @type {Object} 360 */ 361cvox.AbstractEarcons.earconMap = new Object(); 362cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.ALERT_MODAL] = 363 'alert_modal.ogg'; 364cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.ALERT_NONMODAL] = 365 'alert_nonmodal.ogg'; 366cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BULLET] = 'bullet.ogg'; 367cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BUSY_PROGRESS_LOOP] = 368 'busy_progress_loop.ogg'; 369cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BUSY_WORKING_LOOP] = 370 'busy_working_loop.ogg'; 371cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.BUTTON] = 'button.ogg'; 372cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.CHECK_OFF] = 373 'check_off.ogg'; 374cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.CHECK_ON] = 'check_on.ogg'; 375cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.COLLAPSED] = 376 'collapsed.ogg'; 377cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.EDITABLE_TEXT] = 378 'editable_text.ogg'; 379cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.ELLIPSIS] = 'ellipsis.ogg'; 380cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.EXPANDED] = 'expanded.ogg'; 381cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.FONT_CHANGE] = 382 'font_change.ogg'; 383cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.INVALID_KEYPRESS] = 384 'invalid_keypress.ogg'; 385cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LINK] = 'link.ogg'; 386cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LISTBOX] = 'listbox.ogg'; 387cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LIST_ITEM] = 'bullet.ogg'; 388cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.LONG_DESC] = 389 'long_desc.ogg'; 390cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.NEW_MAIL] = 'new_mail.ogg'; 391cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_CLOSE] = 392 'object_close.ogg'; 393cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_DELETE] = 394 'object_delete.ogg'; 395cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_DESELECT] = 396 'object_deselect.ogg'; 397cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_ENTER] = 398 'object_enter.ogg'; 399cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_EXIT] = 400 'object_exit.ogg'; 401cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_OPEN] = 402 'object_open.ogg'; 403cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.OBJECT_SELECT] = 404 'object_select.ogg'; 405cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.PARAGRAPH_BREAK] = 406 'paragraph_break.ogg'; 407cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SEARCH_HIT] = 408 'search_hit.ogg'; 409cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SEARCH_MISS] = 410 'search_miss.ogg'; 411cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SECTION] = 'section.ogg'; 412cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SELECTION] = 413 'selection.ogg'; 414cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SELECTION_REVERSE] = 415 'selection_reverse.ogg'; 416cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.SPECIAL_CONTENT] = 417 'special_content.ogg'; 418cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.TASK_SUCCESS] = 419 'task_success.ogg'; 420cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.WRAP] = 'wrap.ogg'; 421cvox.AbstractEarcons.earconMap[cvox.AbstractEarcons.WRAP_EDGE] = 422 'wrap_edge.ogg'; 423