Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox_next/chromevox2/background/background.js |
| diff --git a/chrome/browser/resources/chromeos/chromevox_next/chromevox2/background/background.js b/chrome/browser/resources/chromeos/chromevox_next/chromevox2/background/background.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ec273b03f7d6d361cf9d3d2b8bc4adaad01ba3ce |
| --- /dev/null |
| +++ b/chrome/browser/resources/chromeos/chromevox_next/chromevox2/background/background.js |
| @@ -0,0 +1,68 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview The entry point for all ChromeVox2 related code for the |
|
Peter Lundblad
2014/05/12 18:37:32
Please decide on chromevox_next vs. chromevox2. ;)
David Tseng
2014/05/12 20:33:38
ChromeVox2 it is then.
Note that I didn't change
|
| + * background page. |
| + */ |
| + |
| +/** ChromeVox2 (ChromeVox Next) namespace */ |
| +var cvox2 = function() {}; |
| + |
| +/** Namespace for global objects in the background page. */ |
| +cvox2.global = function() {}; |
| + |
| +/** Classic Chrome accessibility API. */ |
| +cvox2.global.accessibility = |
| + chrome.accessibilityPrivate || chrome.experimental.accessibility; |
| + |
| +/** |
| + * ChromeVox2 background page. |
| + */ |
| +cvox2.Background = function() { |
| + // Only needed with unmerged ChromeVox classic loaded before. |
| + cvox2.global.accessibility.setAccessibilityEnabled(false); |
| + chrome.automation.getDesktop(this.onDesktopAvailable); |
|
dmazzoni
2014/05/12 18:18:12
Do you not need to bind this?
David Tseng
2014/05/12 20:33:38
Not using 'this' within the function, but done any
|
| +}; |
| + |
| +cvox2.Background.prototype = { |
| + onDesktopAvailable: function(tree) { |
|
Peter Lundblad
2014/05/12 18:37:32
jsdoc?
David Tseng
2014/05/12 20:33:38
We need to decide pretty quickly if we want lots o
|
| + if (!tree.root) { |
| + window.setTimeout(this.onDesktopAvailable, 500); |
| + return; |
| + } |
| + chrome.extension.onConnect.addListener(function(port) { |
| + if (port.name != 'chromevox2') |
|
Peter Lundblad
2014/05/12 18:37:32
Make a constant.
David Tseng
2014/05/12 20:33:38
Done.
|
| + return; |
| + var cur = tree.root; |
| + port.onMessage.addListener(function(message) { |
| + switch (message.keydown) { |
| + case 37: |
| + cur = cur.previousSibling() || cur; |
| + break; |
| + case 38: |
| + cur = cur.parent() || cur; |
| + break; |
| + case 39: |
| + cur = cur.nextSibling() || cur; |
| + break; |
| + case 40: |
| + cur = cur.firstChild() || cur; |
| + break; |
| + } |
| + var index = 1; |
| + if (cur.parent()) |
| + index = cur.parent().children().indexOf(cur) + 1; |
| + var name = ''; |
| + if (cur.attributes && cur.attributes['ax_attr_name']) |
| + name = cur.attributes['ax_attr_name']; |
| + var utterance = index + ' ' + name + cur.role; |
| + chrome.tts.speak(String(utterance), {lang: 'en-US'}); |
| + }); |
| + }); |
| + } |
| +}; |
| + |
| +/** @type {cvox2.Background} */ |
| +cvox2.global.backgroundObj = new cvox2.Background(); |