Commit 8dc65084 authored by Zach Helfinstein's avatar Zach Helfinstein Committed by Commit Bot

Fix Switch Access method youngestDescendant

This fixes an issue with navigation where an invisible object was
highlighted when navigating backwards.

Bug: 864820
Change-Id: Id4e8971122f8335d1754ed197cf8a46fbbe1b79b
Reviewed-on: https://chromium-review.googlesource.com/c/1281324Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Zach Helfinstein <zhelfins@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601351}
parent 236a97bf
...@@ -406,12 +406,37 @@ class AutomationManager { ...@@ -406,12 +406,37 @@ class AutomationManager {
* @private * @private
*/ */
youngestDescendant_(node) { youngestDescendant_(node) {
let leaf = SwitchAccessPredicate.leaf(this.scope_); const leaf = SwitchAccessPredicate.leaf(this.scope_);
const visit = SwitchAccessPredicate.visit(this.scope_);
while (node.lastChild && !leaf(node)) const result = this.youngestDescendantHelper_(node, leaf, visit);
node = node.lastChild; if (!result)
return this.scope_;
return result;
}
/**
* @param {!chrome.automation.AutomationNode} node
* @param {function(!chrome.automation.AutomationNode): boolean} leaf
* @param {function(!chrome.automation.AutomationNode): boolean} visit
* @return {chrome.automation.AutomationNode}
* @private
*/
youngestDescendantHelper_(node, leaf, visit) {
if (!node)
return null;
if (leaf(node))
return visit(node) ? node : null;
const reverseChildren = node.children.reverse();
for (const child of reverseChildren) {
const youngest = this.youngestDescendantHelper_(child, leaf, visit);
if (youngest)
return youngest;
}
return node; return visit(node) ? node : null;
} }
// ----------------------Debugging Methods------------------------ // ----------------------Debugging Methods------------------------
......
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