OLD | NEW |
(Empty) | |
| 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 The entry point for all ChromeVox2 related code for the |
| 7 * background page. |
| 8 */ |
| 9 |
| 10 /** ChromeVox2 (ChromeVox Next) namespace */ |
| 11 var cvox2 = function() {}; |
| 12 |
| 13 /** Namespace for global objects in the background page. */ |
| 14 cvox2.global = function() {}; |
| 15 |
| 16 /** Classic Chrome accessibility API. */ |
| 17 cvox2.global.accessibility = |
| 18 chrome.accessibilityPrivate || chrome.experimental.accessibility; |
| 19 |
| 20 /** |
| 21 * ChromeVox2 background page. |
| 22 */ |
| 23 cvox2.Background = function() { |
| 24 // Only needed with unmerged ChromeVox classic loaded before. |
| 25 cvox2.global.accessibility.setAccessibilityEnabled(false); |
| 26 chrome.automation.getDesktop(this.onDesktopAvailable); |
| 27 }; |
| 28 |
| 29 cvox2.Background.prototype = { |
| 30 onDesktopAvailable: function(tree) { |
| 31 if (!tree.root) { |
| 32 window.setTimeout(this.onDesktopAvailable, 500); |
| 33 return; |
| 34 } |
| 35 chrome.extension.onConnect.addListener(function(port) { |
| 36 var cur = tree.root; |
| 37 port.onMessage.addListener(function(message) { |
| 38 switch (message.keydown) { |
| 39 case 37: |
| 40 cur = cur.previousSibling() || cur; |
| 41 break; |
| 42 case 38: |
| 43 cur = cur.parent() || cur; |
| 44 break; |
| 45 case 39: |
| 46 cur = cur.nextSibling() || cur; |
| 47 break; |
| 48 case 40: |
| 49 cur = cur.firstChild() || cur; |
| 50 break; |
| 51 } |
| 52 var index = 1; |
| 53 if (cur.parent()) |
| 54 index = cur.parent().children().indexOf(cur) + 1; |
| 55 var name = ''; |
| 56 if (cur.attributes && cur.attributes['ax_attr_name']) |
| 57 name = cur.attributes['ax_attr_name']; |
| 58 var utterance = index + ' ' + name + cur.role; |
| 59 chrome.tts.speak(String(utterance), {lang: 'en-US'}); |
| 60 }); |
| 61 }); |
| 62 } |
| 63 }; |
| 64 |
| 65 /** @type {cvox2.Background} */ |
| 66 cvox2.global.backgroundObj = new cvox2.Background(); |
OLD | NEW |