Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1916)

Unified Diff: chrome/browser/resources/chromeos/chromevox/cvox2/background/tree_walker.js

Issue 1948213002: Add a |skipInitialAncestry| option to tree walking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/tree_walker.js
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/tree_walker.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/tree_walker.js
index 18311e4a3a17e5260efeb13095e771d1b5cbaeda..ad7a57c031e27f72d51a47c84f46a80bdc65b957 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/tree_walker.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/tree_walker.js
@@ -32,6 +32,7 @@ AutomationTreeWalkerPhase = {
* @typedef {{leaf: (AutomationPredicate.Unary|undefined),
* root: (AutomationPredicate.Unary|undefined),
* visit: (AutomationPredicate.Unary|undefined),
+ * skipInitialAncestry: (boolean|undefined),
* skipInitialSubtree: (boolean|undefined)}}
*/
var AutomationTreeWalkerRestriction;
@@ -54,6 +55,9 @@ var AutomationTreeWalkerRestriction;
* leaf: this predicate determines if a node should end downward movement in the
* tree.
*
+ * |skipInitialAncestry| skips visiting ancestor nodes of the start node for
+ * multiple invokations of next when moving backward.
+ *
* Finally, a boolean, |skipInitialSubtree|, makes the first invocation of
* |next| skip the initial node's subtree when finding a match. This is useful
* to establish a known initial state when the initial node may not match any of
@@ -87,8 +91,21 @@ AutomationTreeWalker = function(node, dir, opt_restrictions) {
this.backwardAncestor_ = node.parent;
var restrictions = opt_restrictions || {};
- this.visitPred_ =
- restrictions.visit ? restrictions.visit : function() { return true; };
+ this.visitPred_ = function(node) {
+ if (this.skipInitialAncestry_ &&
+ this.phase_ == AutomationTreeWalkerPhase.ANCESTOR)
+ return false;
+
+ if (this.skipInitialSubtree_ &&
+ this.phase != AutomationTreeWalkerPhase.ANCESTOR &&
+ this.phase != AutomationTreeWalkerPhase.OTHER)
+ return false;
+
+ if (restrictions.visit)
+ return restrictions.visit(node);
+
+ return true;
+ };
/** @type {AutomationPredicate.Unary} @private */
this.leafPred_ = restrictions.leaf ? restrictions.leaf :
AutomationTreeWalker.falsePredicate_;
@@ -96,6 +113,8 @@ AutomationTreeWalker = function(node, dir, opt_restrictions) {
this.rootPred_ = restrictions.root ? restrictions.root :
AutomationTreeWalker.falsePredicate_;
/** @const {boolean} @private */
+ this.skipInitialAncestry_ = restrictions.skipInitialAncestry || false;
+ /** @const {boolean} @private */
this.skipInitialSubtree_ = restrictions.skipInitialSubtree || false;
};
@@ -149,6 +168,7 @@ AutomationTreeWalker.prototype = {
if (!this.leafPred_(node) && node.firstChild) {
if (this.phase_ == AutomationTreeWalkerPhase.INITIAL)
this.phase_ = AutomationTreeWalkerPhase.DESCENDANT;
+
if (!this.skipInitialSubtree_ ||
this.phase != AutomationTreeWalkerPhase.DESCENDANT) {
this.node_ = node.firstChild;

Powered by Google App Engine
This is Rietveld 408576698