Commit 562d9c2a authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Find menu panel node once panel is connected

Currently, Switch Access looks for the menu panel each time it needs it.
Instead, we expect the node to be in the accessibility tree once its
javascript has loaded.

Bug: None
Change-Id: Ic48a3110c1c9ce40ab6581bf78c782b3f2a9d17e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841503Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#703513}
parent a1cc3ed8
......@@ -201,7 +201,7 @@ class MenuManager {
if (!shouldReloadMenu) {
// Wait for the menu to appear in the panel before highlighting the
// first available action.
this.menuPanelNode().addEventListener(
this.menuPanelNode_.addEventListener(
chrome.automation.EventType.CHILDREN_CHANGED,
this.onMenuPanelChildrenChanged_, false /** Don't use capture. */);
}
......@@ -323,7 +323,7 @@ class MenuManager {
// panel, so remove the listener once the callback has been called once.
// This ensures the first action is not continually highlighted as we
// navigate through the menu.
this.menuPanelNode().removeEventListener(
this.menuPanelNode_.removeEventListener(
chrome.automation.EventType.CHILDREN_CHANGED,
this.onMenuPanelChildrenChanged_, false /** Don't use capture. */);
}
......@@ -432,28 +432,23 @@ class MenuManager {
*/
connectMenuPanel(menuPanel) {
this.menuPanel_ = menuPanel;
this.findMenuPanelNode_();
return this;
}
/**
* Get the menu panel node. If it's not defined, search for it.
* @return {!chrome.automation.AutomationNode}
* Searches for the menu panel node.
*/
menuPanelNode() {
if (this.menuPanelNode_) {
return this.menuPanelNode_;
}
findMenuPanelNode_() {
const treeWalker = new AutomationTreeWalker(
this.desktop_, constants.Dir.FORWARD,
SwitchAccessPredicate.switchAccessMenuPanelDiscoveryRestrictions());
const node = treeWalker.next().node;
if (node) {
this.menuPanelNode_ = node;
return this.menuPanelNode_;
if (!node) {
setTimeout(this.findMenuPanelNode_.bind(this), 500);
return;
}
console.log('Unable to find the Switch Access menu panel.');
return this.desktop_;
this.menuPanelNode_ = node;
}
/**
......@@ -467,7 +462,7 @@ class MenuManager {
return this.menuNode_;
}
if (this.menuPanelNode() !== this.desktop_) {
if (this.menuPanelNode_) {
if (this.menuPanelNode_.firstChild) {
this.menuNode_ = this.menuPanelNode_.firstChild;
return this.menuNode_;
......
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