Commit fc4fa957 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Refactor isGroup function to allow for changing values

In preparation for future changes, change the behavior of how Switch
Access checks if a child node is a group from initializing a field on
construction to implementing an abstract function.

Bug: None
Change-Id: I9a0657c19fcd7b3428ddfecb108d52a9cd0b2250
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1907192Reviewed-by: default avatarAran Gilman <gilmanmh@google.com>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#713989}
parent ee70c140
...@@ -10,7 +10,7 @@ class BackButtonNode extends SAChildNode { ...@@ -10,7 +10,7 @@ class BackButtonNode extends SAChildNode {
* @param {!SARootNode} group * @param {!SARootNode} group
*/ */
constructor(group) { constructor(group) {
super(false /* isGroup */); super();
/** /**
* The group that the back button is shown for. * The group that the back button is shown for.
* @private {!SARootNode} * @private {!SARootNode}
...@@ -65,6 +65,11 @@ class BackButtonNode extends SAChildNode { ...@@ -65,6 +65,11 @@ class BackButtonNode extends SAChildNode {
return this.node_ === node; return this.node_ === node;
} }
/** @override */
isGroup() {
return false;
}
/** @override */ /** @override */
asRootNode() { asRootNode() {
return null; return null;
......
...@@ -15,7 +15,7 @@ class GroupNode extends SAChildNode { ...@@ -15,7 +15,7 @@ class GroupNode extends SAChildNode {
* @private * @private
*/ */
constructor(children) { constructor(children) {
super(true /* isGroup */); super();
/** @type {!Array<!SAChildNode>} */ /** @type {!Array<!SAChildNode>} */
this.children_ = children; this.children_ = children;
...@@ -70,6 +70,11 @@ class GroupNode extends SAChildNode { ...@@ -70,6 +70,11 @@ class GroupNode extends SAChildNode {
return false; return false;
} }
/** @override */
isGroup() {
return true;
}
/** @override */ /** @override */
asRootNode() { asRootNode() {
const root = new SARootNode(); const root = new SARootNode();
......
...@@ -14,9 +14,12 @@ class NodeWrapper extends SAChildNode { ...@@ -14,9 +14,12 @@ class NodeWrapper extends SAChildNode {
* @param {?SARootNode} parent * @param {?SARootNode} parent
*/ */
constructor(baseNode, parent) { constructor(baseNode, parent) {
super(SwitchAccessPredicate.isGroup(baseNode, parent)); super();
/** @private {!AutomationNode} */ /** @private {!AutomationNode} */
this.baseNode_ = baseNode; this.baseNode_ = baseNode;
/** @private {boolean} */
this.isGroup_ = SwitchAccessPredicate.isGroup(this.baseNode_, parent);
} }
/** @override */ /** @override */
...@@ -138,6 +141,11 @@ class NodeWrapper extends SAChildNode { ...@@ -138,6 +141,11 @@ class NodeWrapper extends SAChildNode {
return this.baseNode_ === node; return this.baseNode_ === node;
} }
/** @override */
isGroup() {
return this.isGroup_;
}
/** @override */ /** @override */
asRootNode() { asRootNode() {
if (!this.isGroup()) { if (!this.isGroup()) {
......
...@@ -13,12 +13,7 @@ ...@@ -13,12 +13,7 @@
* @abstract * @abstract
*/ */
class SAChildNode { class SAChildNode {
/** constructor() {
* @param {boolean} isGroup
*/
constructor(isGroup) {
this.isGroup_ = isGroup;
/** @private {?SAChildNode} */ /** @private {?SAChildNode} */
this.previous_ = null; this.previous_ = null;
...@@ -71,10 +66,9 @@ class SAChildNode { ...@@ -71,10 +66,9 @@ class SAChildNode {
/** /**
* Returns whether this node should be displayed as a group. * Returns whether this node should be displayed as a group.
* @return {boolean} * @return {boolean}
* @abstract
*/ */
isGroup() { isGroup() {}
return this.isGroup_;
}
/** /**
* Returns a list of all the actions available for this node. * Returns a list of all the actions available for this node.
...@@ -159,7 +153,7 @@ class SAChildNode { ...@@ -159,7 +153,7 @@ class SAChildNode {
* @return {string} * @return {string}
*/ */
debugString(wholeTree, prefix = '', currentNode = null) { debugString(wholeTree, prefix = '', currentNode = null) {
if (this.isGroup_ && wholeTree) { if (this.isGroup() && wholeTree) {
return this.asRootNode().debugString( return this.asRootNode().debugString(
wholeTree, prefix + ' ', currentNode); wholeTree, prefix + ' ', currentNode);
} }
...@@ -176,7 +170,7 @@ class SAChildNode { ...@@ -176,7 +170,7 @@ class SAChildNode {
str += 'loc(' + RectHelper.toString(loc) + ') '; str += 'loc(' + RectHelper.toString(loc) + ') ';
} }
if (this.isGroup_) { if (this.isGroup()) {
str += '[isGroup]'; str += '[isGroup]';
} }
......
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