Commit 08d26fc1 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Wait to set listener on keyboard

Previously, Switch Access would try to set a listener on the keyboard
node, regardless of whether the node was found in the tree.

This change checks if the keyboard is found, and if not sets a callback
for when the node is found.

It also re-orders the calls in enterKeyboard() to reduce the times when
focus is drawn back to the text field after it has shifted to the
keyboard.

AX-Relnotes: n/a.
Bug: None.
Change-Id: I79663f1bc3297ce8e468e38f0364bd7e3a90f01a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302748
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790071}
parent 6e0304e5
...@@ -49,8 +49,8 @@ class NavigationManager { ...@@ -49,8 +49,8 @@ class NavigationManager {
*/ */
static enterKeyboard() { static enterKeyboard() {
const navigator = NavigationManager.instance; const navigator = NavigationManager.instance;
const keyboard = KeyboardRootNode.buildTree();
navigator.node_.automationNode.focus(); navigator.node_.automationNode.focus();
const keyboard = KeyboardRootNode.buildTree();
navigator.jumpTo_(keyboard); navigator.jumpTo_(keyboard);
} }
......
...@@ -134,18 +134,18 @@ class KeyboardRootNode extends RootNodeWrapper { ...@@ -134,18 +134,18 @@ class KeyboardRootNode extends RootNodeWrapper {
KeyboardRootNode.loadKeyboard_(); KeyboardRootNode.loadKeyboard_();
AutoScanManager.setInKeyboard(true); AutoScanManager.setInKeyboard(true);
if (!KeyboardRootNode.keyboardObject_) { const keyboardObject = KeyboardRootNode.getKeyboardObject();
if (!keyboardObject) {
throw SwitchAccess.error( throw SwitchAccess.error(
SAConstants.ErrorType.MISSING_KEYBOARD, SAConstants.ErrorType.MISSING_KEYBOARD,
'Could not find keyboard in the automation tree', 'Could not find keyboard in the automation tree',
true /* shouldRecover */); true /* shouldRecover */);
} }
const keyboard = const keyboard =
new AutomationTreeWalker( new AutomationTreeWalker(keyboardObject, constants.Dir.FORWARD, {
KeyboardRootNode.keyboardObject_, constants.Dir.FORWARD, { visit: (node) => SwitchAccessPredicate.isGroup(node, null),
visit: (node) => SwitchAccessPredicate.isGroup(node, null), root: (node) => node === keyboardObject
root: (node) => node === KeyboardRootNode.keyboardObject_ })
})
.next() .next()
.node; .node;
...@@ -158,10 +158,18 @@ class KeyboardRootNode extends RootNodeWrapper { ...@@ -158,10 +158,18 @@ class KeyboardRootNode extends RootNodeWrapper {
* Start listening for keyboard open/closed. * Start listening for keyboard open/closed.
*/ */
static startWatchingVisibility() { static startWatchingVisibility() {
const keyboardObject = KeyboardRootNode.getKeyboardObject();
if (!keyboardObject) {
const isKeyboard = (n) => n.role === chrome.automation.RoleType.KEYBOARD;
SwitchAccess.findNodeMatchingPredicate(
isKeyboard, KeyboardRootNode.startWatchingVisibility);
return;
}
KeyboardRootNode.isVisible_ = KeyboardRootNode.isVisible_ =
SwitchAccessPredicate.isVisible(KeyboardRootNode.keyboardObject_); SwitchAccessPredicate.isVisible(keyboardObject);
KeyboardRootNode.keyboardObject_.addEventListener( keyboardObject.addEventListener(
chrome.automation.EventType.ARIA_ATTRIBUTE_CHANGED, chrome.automation.EventType.ARIA_ATTRIBUTE_CHANGED,
KeyboardRootNode.checkVisibilityChanged_, false /* capture */); KeyboardRootNode.checkVisibilityChanged_, false /* capture */);
} }
...@@ -174,7 +182,7 @@ class KeyboardRootNode extends RootNodeWrapper { ...@@ -174,7 +182,7 @@ class KeyboardRootNode extends RootNodeWrapper {
*/ */
static checkVisibilityChanged_(event) { static checkVisibilityChanged_(event) {
const currentlyVisible = const currentlyVisible =
SwitchAccessPredicate.isVisible(KeyboardRootNode.keyboardObject_); SwitchAccessPredicate.isVisible(KeyboardRootNode.getKeyboardObject());
if (currentlyVisible === KeyboardRootNode.isVisible_) { if (currentlyVisible === KeyboardRootNode.isVisible_) {
return; return;
} }
...@@ -199,7 +207,7 @@ class KeyboardRootNode extends RootNodeWrapper { ...@@ -199,7 +207,7 @@ class KeyboardRootNode extends RootNodeWrapper {
* @return {AutomationNode} * @return {AutomationNode}
* @private * @private
*/ */
static get keyboardObject_() { static getKeyboardObject() {
if (!this.object_ || !this.object_.role) { if (!this.object_ || !this.object_.role) {
this.object_ = NavigationManager.desktopNode.find( this.object_ = NavigationManager.desktopNode.find(
{role: chrome.automation.RoleType.KEYBOARD}); {role: chrome.automation.RoleType.KEYBOARD});
......
...@@ -18,10 +18,8 @@ class SwitchAccess { ...@@ -18,10 +18,8 @@ class SwitchAccess {
NavigationManager.initialize(desktop); NavigationManager.initialize(desktop);
Commands.initialize(); Commands.initialize();
SwitchAccessPreferences.initialize();
// This can throw an error, so it is done last.
KeyboardRootNode.startWatchingVisibility(); KeyboardRootNode.startWatchingVisibility();
SwitchAccessPreferences.initialize();
}); });
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment