| Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
|
| diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
|
| index c33060899fe391dfc8a3de1b3118514e1d1a699b..7659707e0e8df9f73408e8af4ae124b754fe9506 100644
|
| --- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
|
| +++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/background.js
|
| @@ -16,7 +16,6 @@ goog.require('Output');
|
| goog.require('Output.EventType');
|
| goog.require('cursors.Cursor');
|
| goog.require('cvox.ChromeVoxEditableTextBase');
|
| -goog.require('cvox.TabsApiHandler');
|
|
|
| goog.scope(function() {
|
| var AutomationNode = chrome.automation.AutomationNode;
|
| @@ -37,14 +36,6 @@ Background = function() {
|
| this.whitelist_ = ['chromevox_next_test'];
|
|
|
| /**
|
| - * @type {cvox.TabsApiHandler}
|
| - * @private
|
| - */
|
| - this.tabsHandler_ = new cvox.TabsApiHandler(cvox.ChromeVox.tts,
|
| - cvox.ChromeVox.braille,
|
| - cvox.ChromeVox.earcons);
|
| -
|
| - /**
|
| * @type {cursors.Range}
|
| * @private
|
| */
|
| @@ -82,43 +73,29 @@ Background = function() {
|
|
|
| // Register listeners for ...
|
| // Desktop.
|
| - chrome.automation.getDesktop(this.onGotTree);
|
| -
|
| - // Tabs.
|
| - chrome.tabs.onUpdated.addListener(this.onTabUpdated);
|
| + chrome.automation.getDesktop(this.onGotDesktop);
|
| };
|
|
|
| Background.prototype = {
|
| /**
|
| - * Handles chrome.tabs.onUpdated.
|
| - * @param {number} tabId
|
| - * @param {Object} changeInfo
|
| - */
|
| - onTabUpdated: function(tabId, changeInfo) {
|
| - if (changeInfo.status != 'complete')
|
| - return;
|
| - chrome.tabs.get(tabId, function(tab) {
|
| - if (!tab.url)
|
| - return;
|
| -
|
| - var next = this.isWhitelisted_(tab.url);
|
| -
|
| - this.toggleChromeVoxVersion({next: next, classic: !next});
|
| - }.bind(this));
|
| - },
|
| -
|
| - /**
|
| * Handles all setup once a new automation tree appears.
|
| - * @param {chrome.automation.AutomationNode} root
|
| + * @param {chrome.automation.AutomationNode} desktop
|
| */
|
| - onGotTree: function(root) {
|
| + onGotDesktop: function(desktop) {
|
| // Register all automation event listeners.
|
| for (var eventType in this.listeners_)
|
| - root.addEventListener(eventType, this.listeners_[eventType], true);
|
| -
|
| - if (root.attributes.docLoaded) {
|
| - this.onLoadComplete(
|
| - {target: root, type: chrome.automation.EventType.loadComplete});
|
| + desktop.addEventListener(eventType, this.listeners_[eventType], true);
|
| +
|
| + // The focused state gets set on the containing webView node.
|
| + var webView = desktop.find({role: chrome.automation.RoleType.webView,
|
| + state: {focused: true}});
|
| + if (webView) {
|
| + var root = webView.find({role: chrome.automation.RoleType.rootWebArea});
|
| + if (root) {
|
| + this.onLoadComplete(
|
| + {target: root,
|
| + type: chrome.automation.EventType.loadComplete});
|
| + }
|
| }
|
| },
|
|
|
| @@ -270,14 +247,28 @@ Background.prototype = {
|
| * @param {Object} evt
|
| */
|
| onLoadComplete: function(evt) {
|
| + var next = this.isWhitelisted_(evt.target.attributes.url);
|
| + this.toggleChromeVoxVersion({next: next, classic: !next});
|
| // Don't process nodes inside of web content if ChromeVox Next is inactive.
|
| if (evt.target.root.role != chrome.automation.RoleType.desktop &&
|
| !this.active_)
|
| return;
|
|
|
| - var node = AutomationUtil.findNodePost(evt.target,
|
| + if (this.currentRange_)
|
| + return;
|
| +
|
| + var root = evt.target;
|
| + var webView = root;
|
| + while (webView && webView.role != chrome.automation.RoleType.webView)
|
| + webView = webView.parent;
|
| +
|
| + if (!webView || !webView.state.focused)
|
| + return;
|
| +
|
| + var node = AutomationUtil.findNodePost(root,
|
| Dir.FORWARD,
|
| AutomationPredicate.leaf);
|
| +
|
| if (node)
|
| this.currentRange_ = cursors.Range.fromNode(node);
|
|
|
| @@ -362,21 +353,11 @@ Background.prototype = {
|
|
|
| if (opt_options.next) {
|
| if (!chrome.commands.onCommand.hasListener(this.onGotCommand))
|
| - chrome.commands.onCommand.addListener(this.onGotCommand);
|
| -
|
| - if (!this.active_)
|
| - chrome.automation.getTree(this.onGotTree);
|
| - this.active_ = true;
|
| + chrome.commands.onCommand.addListener(this.onGotCommand);
|
| + this.active_ = true;
|
| } else {
|
| if (chrome.commands.onCommand.hasListener(this.onGotCommand))
|
| chrome.commands.onCommand.removeListener(this.onGotCommand);
|
| -
|
| - if (this.active_) {
|
| - for (var eventType in this.listeners_) {
|
| - this.currentRange_.getStart().getNode().root.removeEventListener(
|
| - eventType, this.listeners_[eventType], true);
|
| - }
|
| - }
|
| this.active_ = false;
|
| }
|
|
|
|
|