Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/resources/chromeos/chromevox2/cvox2/background/background.js

Issue 337843005: Support basic reading of focus for both desktop and tabs trees. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview The entry point for all ChromeVox2 related code for the 6 * @fileoverview The entry point for all ChromeVox2 related code for the
7 * background page. 7 * background page.
8 */ 8 */
9 9
10 goog.provide('cvox2.Background'); 10 goog.provide('cvox2.Background');
11 goog.provide('cvox2.global'); 11 goog.provide('cvox2.global');
12 12
13 /** Classic Chrome accessibility API. */ 13 /** Classic Chrome accessibility API. */
14 cvox2.global.accessibility = 14 cvox2.global.accessibility =
15 chrome.accessibilityPrivate || chrome.experimental.accessibility; 15 chrome.accessibilityPrivate || chrome.experimental.accessibility;
16 16
17 /** 17 /**
18 * ChromeVox2 background page. 18 * ChromeVox2 background page.
19 */ 19 */
20 cvox2.Background = function() { 20 cvox2.Background = function() {
21 // Only needed with unmerged ChromeVox classic loaded before. 21 // Only needed with unmerged ChromeVox classic loaded before.
22 cvox2.global.accessibility.setAccessibilityEnabled(false); 22 cvox2.global.accessibility.setAccessibilityEnabled(false);
23 chrome.automation.getDesktop(this.onGotDesktop.bind(this)); 23
24 // Register listeners for ...
Peter Lundblad 2014/06/19 20:54:10 How would you feel about breaking the registration
David Tseng 2014/06/19 22:30:38 I think there actually should only be three (deskt
25 // Desktop.
26 chrome.automation.getDesktop(this.onGotTree.bind(this));
27
28 // Tabs.
Peter Lundblad 2014/06/19 20:54:10 nit: indentation.
David Tseng 2014/06/19 22:30:37 Done.
29 chrome.tabs.onUpdated.addListener(this.onTabUpdated.bind(this));
30
31 // Keyboard events (currently Messages from content script).
32 chrome.extension.onConnect.addListener(this.onConnect.bind(this));
24 }; 33 };
25 34
26 cvox2.Background.prototype = { 35 cvox2.Background.prototype = {
27 /** 36 /**
28 * ID of the port used to communicate between content script and background 37 * ID of the port used to communicate between content script and background
29 * page. 38 * page.
30 * @const {string} 39 * @const {string}
31 */ 40 */
32 PORT_ID: 'chromevox2', 41 PORT_ID: 'chromevox2',
33 42
34 /** 43 /**
35 * Waits until a desktop automation tree becomes available. 44 * Handles chrome.extension.onConnect.
36 * Thereafter, registers a simple exploration mode for the desktop tree. 45 * @param {Object} port The port.
37 * @param {AutomationTree} tree The desktop automation tree.
38 */ 46 */
39 onGotDesktop: function(tree) { 47 onConnect: function(port) {
40 if (!tree.root) { 48 if (port.name != this.PORT_ID)
41 window.setTimeout(this.onGotDesktop, 500);
42 return; 49 return;
43 } 50 port.onMessage.addListener(this.onMessage.bind(this));
44 chrome.extension.onConnect.addListener(function(port) { 51 },
45 if (port.name != this.PORT_ID)
46 return;
47 var cur = tree.root;
48 port.onMessage.addListener(function(message) {
49 switch (message.keydown) {
50 case 37:
51 cur = cur.previousSibling() || cur;
52 break;
53 case 38:
54 cur = cur.parent() || cur;
55 break;
56 case 39:
57 cur = cur.nextSibling() || cur;
58 break;
59 case 40:
60 cur = cur.firstChild() || cur;
61 break;
62 }
63 var index = 1;
64 if (cur.parent())
65 index = cur.parent().children().indexOf(cur) + 1;
66 var name = '';
67 if (cur.attributes && cur.attributes['ax_attr_name'])
68 name = cur.attributes['ax_attr_name'];
69 var utterance = index + ' ' + name + cur.role;
70 chrome.tts.speak(String(utterance), {lang: 'en-US'});
71 });
72 }.bind(this));
73 52
53 /**
54 * Dispatches messages to specific handlers.
55 * @param {Object} message The message.
56 */
57 onMessage: function(message) {
58 if (message.keyDown)
59 this.onKeyDown(message);
60 },
61
62 /**
63 * Handles key down messages from the content script.
64 * @param {Object} message The key down message.
65 */
66 onKeyDown: function(message) {
67 // TODO(dtseng): Implement.
68 },
69
70 /**
71 * Handles chrome.tabs.onUpdate.
72 * @param {number} tabId The tab id.
73 * @param {Object} changeInfo Information about the updated tab.
Peter Lundblad 2014/06/19 20:54:10 Is there a better type for this, or should we have
David Tseng 2014/06/19 22:30:37 Check out chrome/common/extensions/api/tabs.json
74 */
75 onTabUpdated: function(tabId, changeInfo) {
76 chrome.automation.getTree(this.onGotTree.bind(this));
77 },
78
79 /**
80 * Handles all setup once a new automation tree appears.
81 * @param {AutomationTree} tree The new automation tree.
82 */
83 onGotTree: function(root) {
74 // Register all automation event listeners. 84 // Register all automation event listeners.
75 tree.root.addEventListener('focus', this.onDesktopEvent.bind(this), true); 85 root.addEventListener(chrome.automation.EventType.focus,
86 this.onAutomationEvent.bind(this),
87 true);
76 }, 88 },
77 89
78 /** 90 /**
79 * A generic handler for all desktop automation events. 91 * A generic handler for all desktop automation events.
80 * @param {AutomationEvent} evt The event. 92 * @param {AutomationEvent} evt The event.
81 */ 93 */
82 onDesktopEvent: function(evt) { 94 onAutomationEvent: function(evt) {
83 var output = evt.target.attributes.name + ' ' + evt.target.role; 95 var output = evt.target.attributes.name + ' ' + evt.target.role;
84 cvox.ChromeVox.tts.speak(output); 96 cvox.ChromeVox.tts.speak(output);
85 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output)); 97 cvox.ChromeVox.braille.write(cvox.NavBraille.fromText(output));
86 } 98 }
87 }; 99 };
88 100
89 /** @type {cvox2.Background} */ 101 /** @type {cvox2.Background} */
90 cvox2.global.backgroundObj = new cvox2.Background(); 102 cvox2.global.backgroundObj = new cvox2.Background();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698