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 Defines a global object. The initialization of this
7 * object happens in init.js.
11 goog
.provide('cvox.ChromeVox');
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
19 '../host/interface/abstract_host.js',
20 ['cvox.AbstractHost'],
24 '../host/interface/tts_interface.js',
25 ['cvox.TtsInterface'],
29 '../host/interface/braille_interface.js',
30 ['cvox.BrailleInterface'],
34 '../host/interface/mathjax_interface.js',
35 ['cvox.MathJaxInterface'],
39 '../chromevox/messages/msgs.js',
44 '../host/interface/abstract_earcons.js',
45 ['cvox.AbstractEarcons'],
49 '../chromevox/common/key_sequence.js',
54 '../chromevox/injected/navigation_manager.js',
55 ['cvox.NavigationManager'],
59 '../chromevox/injected/serializer.js',
65 * Constant for verbosity setting (cvox.ChromeVox.verbosity).
69 cvox
.VERBOSITY_VERBOSE
= 0;
71 * Constant for verbosity setting (cvox.ChromeVox.verbosity).
75 cvox
.VERBOSITY_BRIEF
= 1;
81 cvox
.ChromeVox = function() {};
84 * @type {cvox.AbstractHost}
86 cvox
.ChromeVox
.host
= null;
88 * @type {cvox.TtsInterface}
92 * @type {cvox.BrailleInterface}
94 cvox
.ChromeVox
.braille
;
96 * @type {cvox.MathJaxInterface}
98 cvox
.ChromeVox
.mathJax
;
102 cvox
.ChromeVox
.msgs
= null;
106 cvox
.ChromeVox
.isActive
= true;
110 cvox
.ChromeVox
.version
= null;
112 * @type {cvox.AbstractEarcons}
114 cvox
.ChromeVox
.earcons
= null;
116 * @type {cvox.NavigationManager}
118 cvox
.ChromeVox
.navigationManager
= null;
120 * @type {cvox.Serializer}
122 cvox
.ChromeVox
.serializer
= null;
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.
129 cvox
.ChromeVox
.isStickyPrefOn
= false;
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.
136 cvox
.ChromeVox
.stickyOverride
= null;
140 cvox
.ChromeVox
.keyPrefixOn
= false;
143 * See: cvox.VERBOSITY_VERBOSE and cvox.VERBOSITY_BRIEF
146 cvox
.ChromeVox
.verbosity
= cvox
.VERBOSITY_VERBOSE
;
150 cvox
.ChromeVox
.typingEcho
= 0;
152 * Echoing on key press events.
153 * @type {Object<boolean>}
155 cvox
.ChromeVox
.keyEcho
= {};
157 * @type {Object<{x:number, y:number}>}
159 cvox
.ChromeVox
.position
= {};
163 cvox
.ChromeVox
.isChromeOS
= navigator
.userAgent
.indexOf('CrOS') != -1;
167 cvox
.ChromeVox
.isMac
= navigator
.platform
.indexOf('Mac') != -1;
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';
177 cvox
.ChromeVox
.modKeyStr
= 'Shift+Alt';
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>}
186 cvox
.ChromeVox
.sequenceSwitchKeyCodes
= [];
187 /** @type {Object<boolean>} */
188 cvox
.ChromeVox
.visitedUrls
= {};
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".
198 cvox
.ChromeVox
.markInUserCommand = function() {};
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.
205 cvox
.ChromeVox
.syncToNode = function(
206 targetNode
, speakNode
, opt_queueMode
) {};
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.
214 cvox
.ChromeVox
.speakNode = function(targetNode
, queueMode
, properties
) {};
217 * Provide a way for modules that can't depend on cvox.ChromeVoxUserCommands
218 * to execute commands.
220 * @param {string} commandName The command name as a string.
222 cvox
.ChromeVox
.executeUserCommand = function(commandName
) {};
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.
229 cvox
.ChromeVox
.entireDocumentIsHidden
= false;
232 * Stores state variables in a provided object.
234 * @param {Object} store The object.
236 cvox
.ChromeVox
.storeOn = function(store
) {
237 store
['isStickyPrefOn'] = cvox
.ChromeVox
.isStickyPrefOn
;
238 cvox
.ChromeVox
.navigationManager
.storeOn(store
);
242 * Updates the object with state variables from an earlier storeOn call.
244 * @param {Object} store The object.
246 cvox
.ChromeVox
.readFrom = function(store
) {
247 cvox
.ChromeVox
.isStickyPrefOn
= store
['isStickyPrefOn'];
248 cvox
.ChromeVox
.navigationManager
.readFrom(store
);
252 * Returns whether sticky mode is on, taking both the global sticky mode
253 * pref and the temporary sticky mode override into account.
255 * @return {boolean} Whether sticky mode is on.
257 cvox
.ChromeVox
.isStickyModeOn = function() {
258 if (cvox
.ChromeVox
.stickyOverride
!== null) {
259 return cvox
.ChromeVox
.stickyOverride
;
261 return cvox
.ChromeVox
.isStickyPrefOn
;
266 * Shortcut for document.getElementById.
267 * @param {string} id of the element.
268 * @return {HTMLElement} with the id.
271 return document
.getElementById(id
);
275 * @param {Array} tabs
277 cvox
.ChromeVox
.injectChromeVoxIntoTabs = function(tabs
) {};
280 * Returns whether the document has focus, taking into account whether
281 * it's hidden and also that if an iframe or webview element has focus,
282 * the focus is really inside that frame and not in this document.
283 * @return {boolean} True if the document has focus.
285 cvox
.ChromeVox
.documentHasFocus = function() {
286 if (!document
.hasFocus() || document
.hidden
) {
289 if (document
.activeElement
.tagName
== 'IFRAME' ||
290 document
.activeElement
.tagName
== 'WEBVIEW') {