Commit 9ede3249 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Respond to childrenChanged events

This CL updates Switch Access nodes to respond to childrenChanged events
to update the cached tree structure, as needed.

Bug: 1023035
Change-Id: Id24d489424caabbfc04f4a3e4f3d16eca05c8069
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2003397Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#733736}
parent 908830f5
...@@ -261,10 +261,9 @@ class NavigationManager { ...@@ -261,10 +261,9 @@ class NavigationManager {
* @private * @private
*/ */
onTreeChange_(treeChange) { onTreeChange_(treeChange) {
if (treeChange.type === chrome.automation.TreeChangeType.TEXT_CHANGED) { if (treeChange.type === chrome.automation.TreeChangeType.NODE_REMOVED) {
return; this.moveToValidNode();
} }
this.moveToValidNode();
} }
// ------------------------------------------------------- // -------------------------------------------------------
......
...@@ -211,6 +211,9 @@ class RootNodeWrapper extends SARootNode { ...@@ -211,6 +211,9 @@ class RootNodeWrapper extends SARootNode {
/** @private {!AutomationNode} */ /** @private {!AutomationNode} */
this.baseNode_ = baseNode; this.baseNode_ = baseNode;
/** @private {function(chrome.automation.AutomationEvent)} */
this.childrenChangedHandler_ = this.refresh_.bind(this);
/** @private {function(chrome.automation.AutomationEvent)} */ /** @private {function(chrome.automation.AutomationEvent)} */
this.locationChangedHandler_ = SwitchAccess.refreshFocusRings; this.locationChangedHandler_ = SwitchAccess.refreshFocusRings;
} }
...@@ -259,6 +262,9 @@ class RootNodeWrapper extends SARootNode { ...@@ -259,6 +262,9 @@ class RootNodeWrapper extends SARootNode {
/** @override */ /** @override */
onFocus() { onFocus() {
super.onFocus(); super.onFocus();
this.baseNode_.addEventListener(
chrome.automation.EventType.CHILDREN_CHANGED,
this.childrenChangedHandler_, false /* is_capture */);
this.baseNode_.addEventListener( this.baseNode_.addEventListener(
chrome.automation.EventType.LOCATION_CHANGED, chrome.automation.EventType.LOCATION_CHANGED,
this.locationChangedHandler_, false /* is_capture */); this.locationChangedHandler_, false /* is_capture */);
...@@ -267,11 +273,52 @@ class RootNodeWrapper extends SARootNode { ...@@ -267,11 +273,52 @@ class RootNodeWrapper extends SARootNode {
/** @override */ /** @override */
onUnfocus() { onUnfocus() {
super.onUnfocus(); super.onUnfocus();
this.baseNode_.removeEventListener(
chrome.automation.EventType.CHILDREN_CHANGED,
this.childrenChangedHandler_, false /* is_capture */);
this.baseNode_.removeEventListener( this.baseNode_.removeEventListener(
chrome.automation.EventType.LOCATION_CHANGED, chrome.automation.EventType.LOCATION_CHANGED,
this.locationChangedHandler_, false /* is_capture */); this.locationChangedHandler_, false /* is_capture */);
} }
// ================= Private methods =================
/**
* Refreshes the children of this root node.
* @private
*/
refresh_() {
// Find the currently focused child.
let focusedChild = null;
for (const child of this.children) {
if (child.isFocused()) {
focusedChild = child;
break;
}
}
// Update this RootNodeWrapper's children.
const childConstructor = (node) => new NodeWrapper(node, this);
try {
RootNodeWrapper.findAndSetChildren(this, childConstructor);
} catch (e) {
SwitchAccess.moveToValidNode();
return;
}
// Set the new instance of that child to be the focused node.
for (const child of this.children) {
if (child.isEquivalentTo(focusedChild)) {
SwitchAccess.forceFocusedNode(child);
return;
}
}
// If the previously focused node no longer exists, focus the first node in
// the group.
SwitchAccess.forceFocusedNode(this.children[0]);
}
// ================= Static methods ================= // ================= Static 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