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 Defines a global object. The initialization of this 7 * object happens in init.js. 8 * 9 */ 10 11 goog.provide('cvox.ChromeVox'); 12 13 // Forward declarations. 14 // TODO (stoarca): Put these in a separate file and pass that 15 // into the build system instead of having it here. This will allow 16 // us to group all of the forward declarations for each file without 17 // having them overwrite the mapping in deps.js 18 goog.addDependency( 19 '../host/interface/abstract_host.js', 20 ['cvox.AbstractHost'], 21 []); 22 23 goog.addDependency( 24 '../host/interface/tts_interface.js', 25 ['cvox.TtsInterface'], 26 []); 27 28 goog.addDependency( 29 '../host/interface/braille_interface.js', 30 ['cvox.BrailleInterface'], 31 []); 32 33 goog.addDependency( 34 '../host/interface/mathjax_interface.js', 35 ['cvox.MathJaxInterface'], 36 []); 37 38 goog.addDependency( 39 '../chromevox/messages/msgs.js', 40 ['cvox.Msgs'], 41 []); 42 43 goog.addDependency( 44 '../host/interface/abstract_earcons.js', 45 ['cvox.AbstractEarcons'], 46 []); 47 48 goog.addDependency( 49 '../chromevox/common/key_sequence.js', 50 ['cvox.KeySequence'], 51 []); 52 53 goog.addDependency( 54 '../chromevox/injected/navigation_manager.js', 55 ['cvox.NavigationManager'], 56 []); 57 58 goog.addDependency( 59 '../chromevox/injected/serializer.js', 60 ['cvox.Serializer'], 61 []); 62 63 // Constants 64 /** 65 * Constant for verbosity setting (cvox.ChromeVox.verbosity). 66 * @const 67 * @type {number} 68 */ 69 cvox.VERBOSITY_VERBOSE = 0; 70 /** 71 * Constant for verbosity setting (cvox.ChromeVox.verbosity). 72 * @const 73 * @type {number} 74 */ 75 cvox.VERBOSITY_BRIEF = 1; 76 77 78 /** 79 * @constructor 80 */ 81 cvox.ChromeVox = function() {}; 82 83 /** 84 * @type {cvox.AbstractHost} 85 */ 86 cvox.ChromeVox.host = null; 87 /** 88 * @type {cvox.TtsInterface} 89 */ 90 cvox.ChromeVox.tts; 91 /** 92 * @type {cvox.BrailleInterface} 93 */ 94 cvox.ChromeVox.braille; 95 /** 96 * @type {cvox.MathJaxInterface} 97 */ 98 cvox.ChromeVox.mathJax; 99 /** 100 * @type {cvox.Msgs} 101 */ 102 cvox.ChromeVox.msgs = null; 103 /** 104 * @type {boolean} 105 */ 106 cvox.ChromeVox.isActive = true; 107 /** 108 * @type {?string} 109 */ 110 cvox.ChromeVox.version = null; 111 /** 112 * @type {cvox.AbstractEarcons} 113 */ 114 cvox.ChromeVox.earcons = null; 115 /** 116 * @type {cvox.NavigationManager} 117 */ 118 cvox.ChromeVox.navigationManager = null; 119 /** 120 * @type {cvox.Serializer} 121 */ 122 cvox.ChromeVox.serializer = null; 123 /** 124 * This indicates whether or not the sticky mode pref is toggled on. 125 * Use cvox.ChromeVox.isStickyModeOn() to test if sticky mode is enabled 126 * either through the pref or due to being temporarily toggled on. 127 * @type {boolean} 128 */ 129 cvox.ChromeVox.isStickyPrefOn = false; 130 /** 131 * If set to true or false, this value overrides cvox.ChromeVox.isStickyPrefOn 132 * temporarily - in order to temporarily enable sticky mode while doing 133 * 'read from here' or to temporarily disable it while using a widget. 134 * @type {?boolean} 135 */ 136 cvox.ChromeVox.stickyOverride = null; 137 /** 138 * @type {boolean} 139 */ 140 cvox.ChromeVox.keyPrefixOn = false; 141 /** 142 * Verbosity setting. 143 * See: cvox.VERBOSITY_VERBOSE and cvox.VERBOSITY_BRIEF 144 * @type {number} 145 */ 146 cvox.ChromeVox.verbosity = cvox.VERBOSITY_VERBOSE; 147 /** 148 * @type {number} 149 */ 150 cvox.ChromeVox.typingEcho = 0; 151 /** 152 * Echoing on key press events. 153 * @type {Object.<string, boolean>} 154 */ 155 cvox.ChromeVox.keyEcho = {}; 156 /** 157 * @type {Object.<string, {x:number, y:number}>} 158 */ 159 cvox.ChromeVox.position = {}; 160 /** 161 * @type {boolean} 162 */ 163 cvox.ChromeVox.isChromeOS = navigator.userAgent.indexOf('CrOS') != -1; 164 /** 165 * @type {boolean} 166 */ 167 cvox.ChromeVox.isMac = navigator.platform.indexOf('Mac') != -1; 168 /** 169 * @type {string} 170 */ 171 cvox.ChromeVox.modKeyStr; 172 if (cvox.ChromeVox.isChromeOS) { 173 cvox.ChromeVox.modKeyStr = 'Shift+Search'; 174 } else if (cvox.ChromeVox.isMac) { 175 cvox.ChromeVox.modKeyStr = 'Ctrl+Cmd'; 176 } else { 177 cvox.ChromeVox.modKeyStr = 'Shift+Alt'; 178 } 179 /** 180 * If any of these keys is pressed with the modifier key, we go in sequence mode 181 * where the subsequent independent key downs (while modifier keys are down) 182 * are a part of the same shortcut. This array is populated in 183 * cvox.ChromeVoxKbHandler.loadKeyToFunctionsTable(). 184 * @type {!Array.<cvox.KeySequence>} 185 */ 186 cvox.ChromeVox.sequenceSwitchKeyCodes = []; 187 /** @type {Object.<string, boolean>} */ 188 cvox.ChromeVox.visitedUrls = {}; 189 /** 190 * This function can be called before doing an operation that may trigger 191 * focus events and other events that would normally be announced. This 192 * tells the event manager that these events should be ignored, they're 193 * a result of another command that's already announced them. This is 194 * a temporary state that's automatically reverted after a few milliseconds, 195 * there's no way to explicitly "un-mark". 196 * @type {Function} 197 */ 198 cvox.ChromeVox.markInUserCommand = function() {}; 199 /** 200 * Synchronizes ChromeVox's internal cursor to the targetNode. 201 * @param {Node} targetNode The node that ChromeVox should be synced to. 202 * @param {boolean=} speakNode If true, speaks out the node. 203 * @param {number=} opt_queueMode The queue mode to use for speaking. 204 */ 205 cvox.ChromeVox.syncToNode = function( 206 targetNode, speakNode, opt_queueMode) {}; 207 208 /** 209 * Speaks the given node. 210 * @param {Node} targetNode The node that ChromeVox should be synced to. 211 * @param {number=} queueMode The queue mode to use for speaking. 212 * @param {Object=} properties Speech properties to use for this utterance. 213 */ 214 cvox.ChromeVox.speakNode = function(targetNode, queueMode, properties) {}; 215 216 /** 217 * Provide a way for modules that can't depend on cvox.ChromeVoxUserCommands 218 * to execute commands. 219 * 220 * @param {string} commandName The command name as a string. 221 */ 222 cvox.ChromeVox.executeUserCommand = function(commandName) {}; 223 224 /** 225 * True if the document body has aria-hidden='true' when we first load. 226 * ChromeVox will disallow any navigation and not eat any keystrokes. 227 * @type {boolean} 228 */ 229 cvox.ChromeVox.entireDocumentIsHidden = false; 230 231 /** 232 * Stores state variables in a provided object. 233 * 234 * @param {Object} store The object. 235 */ 236 cvox.ChromeVox.storeOn = function(store) { 237 store['isStickyPrefOn'] = cvox.ChromeVox.isStickyPrefOn; 238 cvox.ChromeVox.navigationManager.storeOn(store); 239 }; 240 241 /** 242 * Updates the object with state variables from an earlier storeOn call. 243 * 244 * @param {Object} store The object. 245 */ 246 cvox.ChromeVox.readFrom = function(store) { 247 cvox.ChromeVox.isStickyPrefOn = store['isStickyPrefOn']; 248 cvox.ChromeVox.navigationManager.readFrom(store); 249 }; 250 251 /** 252 * Returns whether sticky mode is on, taking both the global sticky mode 253 * pref and the temporary sticky mode override into account. 254 * 255 * @return {boolean} Whether sticky mode is on. 256 */ 257 cvox.ChromeVox.isStickyModeOn = function() { 258 if (cvox.ChromeVox.stickyOverride !== null) { 259 return cvox.ChromeVox.stickyOverride; 260 } else { 261 return cvox.ChromeVox.isStickyPrefOn; 262 } 263 }; 264 265 /** 266 * Shortcut for document.getElementById. 267 * @param {string} id of the element. 268 * @return {HTMLElement} with the id. 269 */ 270 function $(id) { 271 return document.getElementById(id); 272 } 273