| Index: chrome/browser/resources/chromeos/switch_access/switch_access.js
|
| diff --git a/chrome/browser/resources/chromeos/switch_access/switch_access.js b/chrome/browser/resources/chromeos/switch_access/switch_access.js
|
| index 6333888bc62a6722cc3b744a8d85a0bcdb9e2783..fe66d77bbcd877e8d3fc45cd34528ce50e00c632 100644
|
| --- a/chrome/browser/resources/chromeos/switch_access/switch_access.js
|
| +++ b/chrome/browser/resources/chromeos/switch_access/switch_access.js
|
| @@ -5,29 +5,37 @@
|
| let AutomationNode = chrome.automation.AutomationNode;
|
|
|
| let debuggingEnabled = true;
|
| +
|
| /**
|
| * @constructor
|
| */
|
| let SwitchAccess = function() {
|
| console.log('Switch access is enabled');
|
|
|
| - // Currently selected node.
|
| - /** @private {AutomationNode} */
|
| + /**
|
| + * User preferences.
|
| + */
|
| + this.switchAccessPrefs = new SwitchAccessPrefs();
|
| +
|
| + /**
|
| + * Currently selected node.
|
| + *
|
| + * @private {AutomationNode}
|
| + */
|
| this.node_ = null;
|
|
|
| - // Root node (i.e., the desktop).
|
| - /** @private {AutomationNode} */
|
| + /**
|
| + * Root node (i.e., the desktop).
|
| + *
|
| + * @private {AutomationNode}
|
| + */
|
| this.root_ = null;
|
|
|
| - // List of nodes to push to / pop from in case this.node_ is lost.
|
| - /** @private {!Array<!AutomationNode>} */
|
| - this.ancestorList_ = [];
|
| -
|
| chrome.automation.getDesktop(function(desktop) {
|
| this.node_ = desktop;
|
| this.root_ = desktop;
|
| console.log('AutomationNode for desktop is loaded');
|
| - this.printDetails_();
|
| + this.printNode_(this.node_);
|
|
|
| document.addEventListener('keyup', function(event) {
|
| switch (event.key) {
|
| @@ -43,6 +51,9 @@ let SwitchAccess = function() {
|
| console.log('3 = do default on element');
|
| this.doDefault_();
|
| break;
|
| + case '4':
|
| + this.showOptionsPage_();
|
| + break;
|
| }
|
| if (debuggingEnabled) {
|
| switch (event.key) {
|
| @@ -68,6 +79,8 @@ let SwitchAccess = function() {
|
| chrome.accessibilityPrivate.setFocusRing([this.node_.location]);
|
| }.bind(this));
|
| }.bind(this));
|
| +
|
| + document.addEventListener('prefsUpdate', this.handlePrefsUpdate_);
|
| };
|
|
|
| SwitchAccess.prototype = {
|
| @@ -227,6 +240,83 @@ SwitchAccess.prototype = {
|
| return node.state && node.state.focusable;
|
| },
|
|
|
| +
|
| + /**
|
| + * Perform the default action on the currently selected node.
|
| + *
|
| + * @private
|
| + */
|
| + doDefault_: function() {
|
| + let state = this.node_.state;
|
| + if (state && state.focusable)
|
| + console.log('Node was focusable, doing default on it')
|
| + else if (state)
|
| + console.log('Node was not focusable, but still doing default');
|
| + else
|
| + console.log('Node has no state, still doing default');
|
| + console.log('\n');
|
| + this.node_.doDefault();
|
| + },
|
| +
|
| + /**
|
| + * Open the options page in a new tab.
|
| + *
|
| + * @private
|
| + */
|
| + showOptionsPage_: function() {
|
| + let optionsPage = {url: 'options.html'};
|
| + chrome.tabs.create(optionsPage);
|
| + },
|
| +
|
| + /**
|
| + * Handle a change in user preferences.
|
| + *
|
| + * @param {!Event} event
|
| + * @private
|
| + */
|
| + handlePrefsUpdate_: function(event) {
|
| + let updatedPrefs = event.detail;
|
| + for (let key of Object.keys(updatedPrefs)) {
|
| + switch (key) {
|
| + case 'enableAutoScan':
|
| + console.log('Auto-scan enabled set to: ' + updatedPrefs[key]);
|
| + break;
|
| + case 'autoScanTime':
|
| + console.log(
|
| + 'Auto-scan time set to: ' + updatedPrefs[key] + " seconds");
|
| + break;
|
| + }
|
| + }
|
| + },
|
| +
|
| + // TODO(elichtenberg): Move print functions to a custom logger class. Only
|
| + // log when debuggingEnabled is true.
|
| + /**
|
| + * Print out details about a node.
|
| + *
|
| + * @param {AutomationNode} node
|
| + * @private
|
| + */
|
| + printNode_: function(node) {
|
| + if (node) {
|
| + console.log('Name = ' + node.name);
|
| + console.log('Role = ' + node.role);
|
| + if (!node.parent)
|
| + console.log('At index ' + node.indexInParent + ', has no parent');
|
| + else {
|
| + let numSiblings = node.parent.children.length;
|
| + console.log(
|
| + 'At index ' + node.indexInParent + ', there are '
|
| + + numSiblings + ' siblings');
|
| + }
|
| + console.log('Has ' + node.children.length + ' children');
|
| + } else {
|
| + console.log('Node is null');
|
| + }
|
| + console.log(node);
|
| + console.log('\n');
|
| + },
|
| +
|
| /**
|
| * Move to the previous sibling of this.node_ if it has one.
|
| *
|
| @@ -236,7 +326,7 @@ SwitchAccess.prototype = {
|
| let previous = this.node_.previousSibling;
|
| if (previous) {
|
| this.node_ = previous;
|
| - this.printDetails_();
|
| + this.printNode_(this.node_);
|
| } else {
|
| console.log('Node is first of siblings');
|
| console.log('\n');
|
| @@ -252,7 +342,7 @@ SwitchAccess.prototype = {
|
| let next = this.node_.nextSibling;
|
| if (next) {
|
| this.node_ = next;
|
| - this.printDetails_();
|
| + this.printNode_(this.node_);
|
| } else {
|
| console.log('Node is last of siblings');
|
| console.log('\n');
|
| @@ -267,9 +357,8 @@ SwitchAccess.prototype = {
|
| debugMoveToFirstChild_: function() {
|
| let child = this.node_.firstChild;
|
| if (child) {
|
| - this.ancestorList_.push(this.node_);
|
| this.node_ = child;
|
| - this.printDetails_();
|
| + this.printNode_(this.node_);
|
| } else {
|
| console.log('Node has no children');
|
| console.log('\n');
|
| @@ -277,85 +366,19 @@ SwitchAccess.prototype = {
|
| },
|
|
|
| /**
|
| - * Move to the parent of this.node_ if it has one. If it does not have a
|
| - * parent but it is not the top level root node, then this.node_ lost track of
|
| - * its neighbors, and we move to an ancestor node.
|
| + * Move to the parent of this.node_ if it has one.
|
| *
|
| * @private
|
| */
|
| debugMoveToParent_: function() {
|
| let parent = this.node_.parent;
|
| if (parent) {
|
| - this.ancestorList_.pop();
|
| this.node_ = parent;
|
| - this.printDetails_();
|
| - } else if (this.ancestorList_.length === 0) {
|
| + this.printNode_(this.node_);
|
| + } else {
|
| console.log('Node has no parent');
|
| console.log('\n');
|
| - } else {
|
| - console.log(
|
| - 'Node could not find its parent, so moved to recent ancestor');
|
| - let ancestor = this.ancestorList_.pop();
|
| - this.node_ = ancestor;
|
| - this.printDetails_();
|
| }
|
| - },
|
| -
|
| - /**
|
| - * Perform the default action on the currently selected node.
|
| - *
|
| - * @private
|
| - */
|
| - doDefault_: function() {
|
| - let state = this.node_.state;
|
| - if (state && state.focusable)
|
| - console.log('Node was focusable, doing default on it')
|
| - else if (state)
|
| - console.log('Node was not focusable, but still doing default');
|
| - else
|
| - console.log('Node has no state, still doing default');
|
| - console.log('\n');
|
| - this.node_.doDefault();
|
| - },
|
| -
|
| - // TODO(elichtenberg): Move print functions to a custom logger class. Only
|
| - // log when debuggingEnabled is true.
|
| - /**
|
| - * Print out details about the currently selected node and the list of
|
| - * ancestors.
|
| - *
|
| - * @private
|
| - */
|
| - printDetails_: function() {
|
| - this.printNode_(this.node_);
|
| - console.log(this.ancestorList_);
|
| - console.log('\n');
|
| - },
|
| -
|
| - /**
|
| - * Print out details about a node.
|
| - *
|
| - * @param {AutomationNode} node
|
| - * @private
|
| - */
|
| - printNode_: function(node) {
|
| - if (node) {
|
| - console.log('Name = ' + node.name);
|
| - console.log('Role = ' + node.role);
|
| - if (!node.parent)
|
| - console.log('At index ' + node.indexInParent + ', has no parent');
|
| - else {
|
| - let numSiblings = node.parent.children.length;
|
| - console.log(
|
| - 'At index ' + node.indexInParent + ', there are '
|
| - + numSiblings + ' siblings');
|
| - }
|
| - console.log('Has ' + node.children.length + ' children');
|
| - } else {
|
| - console.log('Node is null');
|
| - }
|
| - console.log(node);
|
| - console.log('\n');
|
| }
|
| };
|
|
|
|
|