Chromium Code Reviews| Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/desktop_automation_handler.js |
| diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/desktop_automation_handler.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/desktop_automation_handler.js |
| index 266ff6a7ac2cef43a289e809b7e473e6043757d2..9ace2ea6c2507bd7913340686bb6de53841ebe4c 100644 |
| --- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/desktop_automation_handler.js |
| +++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/desktop_automation_handler.js |
| @@ -8,6 +8,7 @@ |
| goog.provide('DesktopAutomationHandler'); |
| +goog.require('AutomationObjectInstaller'); |
| goog.require('BaseAutomationHandler'); |
| goog.require('ChromeVoxState'); |
| goog.require('editing.TextEditHandler'); |
| @@ -16,6 +17,7 @@ goog.scope(function() { |
| var AutomationEvent = chrome.automation.AutomationEvent; |
| var AutomationNode = chrome.automation.AutomationNode; |
| var Dir = constants.Dir; |
| +var EventType = chrome.automation.EventType; |
| var RoleType = chrome.automation.RoleType; |
| /** |
| @@ -39,21 +41,39 @@ DesktopAutomationHandler = function(node) { |
| */ |
| this.lastValueChanged_ = new Date(0); |
| + var e = EventType; |
| + this.addListener_(e.activedescendantchanged, this.onActiveDescendantChanged); |
| + this.addListener_(e.alert, this.onAlert); |
| + this.addListener_(e.ariaAttributeChanged, this.onEventIfInRange); |
| + this.addListener_(e.checkedStateChanged, this.onEventIfInRange); |
| + this.addListener_(e.focus, this.onFocus); |
| + this.addListener_(e.hover, this.onEventWithFlushedOutput); |
| + this.addListener_(e.loadComplete, this.onLoadComplete); |
| + this.addListener_(e.menuEnd, this.onMenuEnd); |
| + this.addListener_(e.menuListItemSelected, this.onEventDefault); |
| + this.addListener_(e.menuStart, this.onMenuStart); |
| + this.addListener_(e.scrollPositionChanged, this.onScrollPositionChanged); |
| + this.addListener_(e.selection, this.onEventWithFlushedOutput); |
| + this.addListener_(e.textChanged, this.onTextChanged); |
| + this.addListener_(e.textSelectionChanged, this.onTextSelectionChanged); |
| + this.addListener_(e.valueChanged, this.onValueChanged); |
| + |
| // The focused state gets set on the containing webView node. |
| var webView = node.find({role: RoleType.webView, state: {focused: true}}); |
| if (webView) { |
| var root = webView.find({role: RoleType.rootWebArea}); |
| if (root) { |
| this.onLoadComplete( |
| - {target: root, |
| - type: chrome.automation.EventType.loadComplete}); |
| + new chrome.automation.AutomationEvent(EventType.loadComplete, root)); |
|
dmazzoni
2016/05/02 22:15:48
Is there a possible race condition if the chrome.a
David Tseng
2016/05/03 20:18:27
Went with a callback as suggested below.
|
| } |
| } |
| chrome.automation.getFocus((function(focus) { |
| if (focus) |
| - this.onFocus({target: focus, type: 'focus'}); |
| + this.onFocus(new chrome.automation.AutomationEvent(EventType.focus, focus)); |
|
dmazzoni
2016/05/02 22:15:48
nit: indentation
David Tseng
2016/05/03 20:18:27
Done.
|
| }).bind(this)); |
| + |
| + AutomationObjectInstaller.init(node); |
|
dmazzoni
2016/05/02 22:15:48
Perhaps this init should just take a callback argu
David Tseng
2016/05/03 20:18:27
Done.
|
| }; |
| /** |
| @@ -118,8 +138,38 @@ DesktopAutomationHandler.prototype = { |
| }, |
| /** |
| + * @param {!AutomationEvent} evt |
| + */ |
| + onEventIfInRange: function(evt) { |
| + // TODO(dtseng): Consider the end of the current range as well. |
| + if (AutomationUtil.isDescendantOf( |
| + global.backgroundObj.currentRange.start.node, evt.target) || |
| + evt.target.state.focused) |
| + this.onEventDefault(evt); |
| + }, |
| + |
| + /** |
| + * @param {!AutomationEvent} evt |
| + */ |
| + onEventWithFlushedOutput: function(evt) { |
| + Output.flushNextSpeechUtterance(); |
| + this.onEventDefault(evt); |
| + }, |
| + |
| + /** |
| * Makes an announcement without changing focus. |
| - * @param {Object} evt |
| + * @param {!AutomationEvent} evt |
| + */ |
| + onActiveDescendantChanged: function(evt) { |
| + if (!evt.target.activeDescendant) |
| + return; |
| + this.onEventDefault(new chrome.automation.AutomationEvent( |
| + EventType.focus, evt.target.activeDescendant)); |
| + }, |
| + |
| + /** |
| + * Makes an announcement without changing focus. |
| + * @param {!AutomationEvent} evt |
| */ |
| onAlert: function(evt) { |
| var node = evt.target; |
| @@ -139,7 +189,7 @@ DesktopAutomationHandler.prototype = { |
| /** |
| * Provides all feedback once a focus event fires. |
| - * @param {Object} evt |
| + * @param {!AutomationEvent} evt |
| */ |
| onFocus: function(evt) { |
| // Invalidate any previous editable text handler state. |
| @@ -160,13 +210,12 @@ DesktopAutomationHandler.prototype = { |
| Output.flushNextSpeechUtterance(); |
| this.onEventDefault( |
| - /** @type {!AutomationEvent} */ |
| - ({target: node, type: chrome.automation.EventType.focus})); |
| + new chrome.automation.AutomationEvent(EventType.focus, node)); |
| }, |
| /** |
| * Provides all feedback once a load complete event fires. |
| - * @param {Object} evt |
| + * @param {!AutomationEvent} evt |
| */ |
| onLoadComplete: function(evt) { |
| ChromeVoxState.instance.refreshMode(evt.target.docUrl); |
| @@ -193,13 +242,20 @@ DesktopAutomationHandler.prototype = { |
| }).bind(this)); |
| }, |
| - /** @override */ |
| + |
| + /** |
| + * Provides all feedback once a text changed event fires. |
| + * @param {!AutomationEvent} evt |
| + */ |
| onTextChanged: function(evt) { |
| if (evt.target.state.editable) |
| this.onEditableChanged_(evt); |
| }, |
| - /** @override */ |
| + /** |
| + * Provides all feedback once a text selection changed event fires. |
| + * @param {!AutomationEvent} evt |
| + */ |
| onTextSelectionChanged: function(evt) { |
| if (evt.target.state.editable) |
| this.onEditableChanged_(evt); |
| @@ -266,7 +322,7 @@ DesktopAutomationHandler.prototype = { |
| /** |
| * Handle updating the active indicator when the document scrolls. |
| - * @override |
| + * @param {!AutomationEvent} evt |
| */ |
| onScrollPositionChanged: function(evt) { |
| if (ChromeVoxState.instance.mode === ChromeVoxMode.CLASSIC) |
| @@ -277,13 +333,19 @@ DesktopAutomationHandler.prototype = { |
| new Output().withLocation(currentRange, null, evt.type).go(); |
| }, |
| - /** @override */ |
| + /** |
| + * Provides all feedback once a menu start event fires. |
| + * @param {!AutomationEvent} evt |
| + */ |
| onMenuStart: function(evt) { |
| global.backgroundObj.startExcursion(); |
| this.onEventDefault(evt); |
| }, |
| - /** @override */ |
| + /** |
| + * Provides all feedback once a menu end event fires. |
| + * @param {!AutomationEvent} evt |
| + */ |
| onMenuEnd: function(evt) { |
| this.onEventDefault(evt); |
| global.backgroundObj.endExcursion(); |