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

[Switch Access] Add function to print SATree for debugging.

Bug: None
Change-Id: I10a3685214f10695de897510199450d687b1ab8a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1874053
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708803}
parent 54f2f4da
......@@ -73,6 +73,23 @@ class NavigationManager {
this.selectCurrentNode();
}
/**
* Returns the current Switch Access tree, for debugging purposes.
* @param {boolean} wholeTree Whether to print the whole tree, or just the
* current focus.
* @return {!SARootNode}
*/
getTreeForDebugging(wholeTree) {
if (!wholeTree) {
console.log(this.group_.debugString(wholeTree));
return this.group_;
}
const desktopRoot = RootNodeWrapper.buildDesktopTree(this.desktop_);
console.log(desktopRoot.debugString(wholeTree, '', this.node_));
return desktopRoot;
}
/**
* Move to the previous interesting node.
*/
......
......@@ -75,4 +75,9 @@ class BackButtonNode extends SAChildNode {
chrome.accessibilityPrivate.setSwitchAccessMenuState(
false, RectHelper.ZERO_RECT, 0 /* num_actions */);
}
/** @override */
debugString() {
return 'BackButtonNode';
}
}
......@@ -148,6 +148,32 @@ class SAChildNode {
* Called when a node stops being the primary highlighted node.
*/
onUnfocus() {}
/**
* String-ifies the node (for debugging purposes).
* @param {boolean} wholeTree Whether to recursively include descendants.
* @param {string=} prefix
* @param {SAChildNode=} currentNode the currentNode, to highlight.
* @return {string}
*/
debugString(wholeTree, prefix = '', currentNode = null) {
if (this.isGroup_ && wholeTree) {
return this.asRootNode().debugString(
wholeTree, prefix + ' ', currentNode);
}
let str = this.role + ' ';
const autoNode = this.automationNode;
if (autoNode && autoNode.name) str += 'name(' + autoNode.name + ') ';
const loc = this.location;
if (loc) str += 'loc(' + RectHelper.toString(loc) + ') ';
if (this.isGroup_) str += '[isGroup]';
return str;
}
}
/**
......@@ -232,6 +258,31 @@ class SARootNode {
/** Called when a group is exiting. */
onExit() {}
/**
* String-ifies the node (for debugging purposes).
* @param {boolean=} wholeTree Whether to recursively descend the tree
* @param {string=} prefix
* @param {SAChildNode} currentNode the currently focused node, to mark.
* @return {string}
*/
debugString(wholeTree = false, prefix = '', currentNode = null) {
const autoNode = this.automationNode;
let str = 'Root: ';
if (autoNode && autoNode.role) str += autoNode.role + ' ';
if (autoNode && autoNode.name) str += 'name(' + autoNode.name + ') ';
const loc = this.location;
if (loc) str += 'loc(' + RectHelper.toString(loc) + ') ';
for (const child of this.children) {
str += '\n' + prefix + ((child.equals(currentNode)) ? ' * ' : ' - ');
str += child.debugString(wholeTree, prefix, currentNode);
}
return str;
}
/**
* Helper function to connect children.
* @param {!Array<!SAChildNode>} children
......
......@@ -86,6 +86,20 @@ const RectHelper = {
rect1.width === rect2.width && rect1.height === rect2.height;
},
/**
* Returns a string representing the given rectangle.
* @param {chrome.accessibilityPrivate.ScreenRect|undefined} rect
* @return {string}
*/
toString: (rect) => {
let str = '';
if (rect) {
str = rect.left + ',' + rect.top + ' ';
str += rect.width + 'x' + rect.height;
}
return str;
},
/**
* Increases the size of |outer| to entirely enclose |inner|, with |padding|
* buffer on each side.
......
......@@ -291,4 +291,16 @@ class SwitchAccess {
.next()
.node;
}
/**
* Prints out the current Switch Access tree for debugging.
* @param {boolean=} wholeTree whether to print the whole tree, or the current
* focus.
* @return {SARootNode|undefined}
*/
getTreeForDebugging(wholeTree = false) {
if (this.navigationManager_) {
return this.navigationManager_.getTreeForDebugging(wholeTree);
}
}
}
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