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 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.onGotDesktop.bind(this)); |
| 27 }; |
| 28 |
| 29 cvox2.Background.prototype = { |
| 30 /** |
| 31 * ID of the port used to communicate between content script and background |
| 32 * page. |
| 33 * @const {string} |
| 34 */ |
| 35 PORT_ID: 'chromevox2', |
| 36 |
| 37 /** |
| 38 * Waits until a desktop automation tree becomes available. |
| 39 * Thereafter, registers a simple exploration mode for the desktop tree. |
| 40 * @param {AutomationTree} tree The desktop automation tree. |
| 41 */ |
| 42 onGotDesktop: function(tree) { |
| 43 if (!tree.root) { |
| 44 window.setTimeout(this.onGotDesktop, 500); |
| 45 return; |
| 46 } |
| 47 chrome.extension.onConnect.addListener(function(port) { |
| 48 if (port.name != this.PORT_ID) |
| 49 return; |
| 50 var cur = tree.root; |
| 51 port.onMessage.addListener(function(message) { |
| 52 switch (message.keydown) { |
| 53 case 37: |
| 54 cur = cur.previousSibling() || cur; |
| 55 break; |
| 56 case 38: |
| 57 cur = cur.parent() || cur; |
| 58 break; |
| 59 case 39: |
| 60 cur = cur.nextSibling() || cur; |
| 61 break; |
| 62 case 40: |
| 63 cur = cur.firstChild() || cur; |
| 64 break; |
| 65 } |
| 66 var index = 1; |
| 67 if (cur.parent()) |
| 68 index = cur.parent().children().indexOf(cur) + 1; |
| 69 var name = ''; |
| 70 if (cur.attributes && cur.attributes['ax_attr_name']) |
| 71 name = cur.attributes['ax_attr_name']; |
| 72 var utterance = index + ' ' + name + cur.role; |
| 73 chrome.tts.speak(String(utterance), {lang: 'en-US'}); |
| 74 }); |
| 75 }.bind(this)); |
| 76 |
| 77 // Register all automation event listeners. |
| 78 tree.root.addEventListener('focus', this.onDesktopEvent.bind(this), true); |
| 79 }, |
| 80 |
| 81 /** |
| 82 * A generic handler for all desktop automation events. |
| 83 * @param {AutomationEvent} evt The event. |
| 84 */ |
| 85 onDesktopEvent: function(evt) { |
| 86 var output = evt.target.attributes.name + ' ' + evt.target.role; |
| 87 cvox.ChromeVox.tts.speak(output); |
| 88 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); |
| 89 } |
| 90 }; |
| 91 |
| 92 /** @type {cvox2.Background} */ |
| 93 cvox2.global.backgroundObj = new cvox2.Background(); |
OLD | NEW |