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 {
*/
static enterKeyboard() {
const navigator = NavigationManager.instance;
const keyboard = KeyboardRootNode.buildTree();
navigator.node_.automationNode.focus();
const keyboard = KeyboardRootNode.buildTree();
navigator.jumpTo_(keyboard);
}
......
......@@ -134,18 +134,18 @@ class KeyboardRootNode extends RootNodeWrapper {
KeyboardRootNode.loadKeyboard_();
AutoScanManager.setInKeyboard(true);
if (!KeyboardRootNode.keyboardObject_) {
const keyboardObject = KeyboardRootNode.getKeyboardObject();
if (!keyboardObject) {
throw SwitchAccess.error(
SAConstants.ErrorType.MISSING_KEYBOARD,
'Could not find keyboard in the automation tree',
true /* shouldRecover */);
}
const keyboard =
new AutomationTreeWalker(
KeyboardRootNode.keyboardObject_, constants.Dir.FORWARD, {
visit: (node) => SwitchAccessPredicate.isGroup(node, null),
root: (node) => node === KeyboardRootNode.keyboardObject_
})
new AutomationTreeWalker(keyboardObject, constants.Dir.FORWARD, {
visit: (node) => SwitchAccessPredicate.isGroup(node, null),
root: (node) => node === keyboardObject
})
.next()
.node;
......@@ -158,10 +158,18 @@ class KeyboardRootNode extends RootNodeWrapper {
* Start listening for keyboard open/closed.
*/
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_ =
SwitchAccessPredicate.isVisible(KeyboardRootNode.keyboardObject_);
SwitchAccessPredicate.isVisible(keyboardObject);
KeyboardRootNode.keyboardObject_.addEventListener(
keyboardObject.addEventListener(
chrome.automation.EventType.ARIA_ATTRIBUTE_CHANGED,
KeyboardRootNode.checkVisibilityChanged_, false /* capture */);
}
......@@ -174,7 +182,7 @@ class KeyboardRootNode extends RootNodeWrapper {
*/
static checkVisibilityChanged_(event) {
const currentlyVisible =
SwitchAccessPredicate.isVisible(KeyboardRootNode.keyboardObject_);
SwitchAccessPredicate.isVisible(KeyboardRootNode.getKeyboardObject());
if (currentlyVisible === KeyboardRootNode.isVisible_) {
return;
}
......@@ -199,7 +207,7 @@ class KeyboardRootNode extends RootNodeWrapper {
* @return {AutomationNode}
* @private
*/
static get keyboardObject_() {
static getKeyboardObject() {
if (!this.object_ || !this.object_.role) {
this.object_ = NavigationManager.desktopNode.find(
{role: chrome.automation.RoleType.KEYBOARD});
......
......@@ -18,10 +18,8 @@ class SwitchAccess {
NavigationManager.initialize(desktop);
Commands.initialize();
SwitchAccessPreferences.initialize();
// This can throw an error, so it is done last.
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