Index: chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js |
diff --git a/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js b/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js |
index 1f3f614f456956e3267a7211d83ff11298e7050f..a3510802e551c0ead6243f8cb070e3a6a41b2f98 100644 |
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js |
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js |
@@ -84,7 +84,7 @@ cursors.Cursor = function(node, index) { |
// The exception is when a user types at the end of a line. In that case, |
// staying on the current node is appropriate. |
- if (node && node.nextOnLine && nextNode) { |
+ if (node && node.nextOnLine && node.nextOnLine.role && nextNode) { |
node = nextNode; |
index = 0; |
} |
@@ -101,9 +101,13 @@ cursors.Cursor = function(node, index) { |
this.index_ = index; |
/** @type {Array<AutomationNode>} @private */ |
this.ancestry_ = []; |
+ /** @type {!Array<number>} @private */ |
+ this.recoveryChildIndex_ = []; |
+ |
var nodeWalker = node; |
while (nodeWalker) { |
this.ancestry_.push(nodeWalker); |
+ this.recoveryChildIndex_.push(nodeWalker.indexInParent); |
dmazzoni
2017/07/06 21:17:06
I like this idea in general but how about a tiny b
David Tseng
2017/07/06 22:15:44
I'm actually something slightly different here tha
|
nodeWalker = nodeWalker.parent; |
if (nodeWalker && nodeWalker.role == RoleType.WINDOW) |
break; |
@@ -189,6 +193,34 @@ cursors.Cursor.prototype = { |
return null; |
}, |
+ /** |
+ * Returns the node. If the node is invalid since the last time it |
+ * was accessed, attempts to recover it based on a child index. |
+ * @return {AutomationNode} |
+ */ |
+ get recoveryNode() { |
+ for (var i = 0; i < this.ancestry_.length; i++) { |
+ var firstValidNode = this.ancestry_[i]; |
+ if (firstValidNode != null && firstValidNode.role !== undefined && |
+ firstValidNode.root != undefined) { |
+ if (i == 0) |
+ return firstValidNode; |
+ |
+ // Otherwise, attempt to recover. |
+ var node = firstValidNode; |
+ for (var j = i - 1; j >= 0; j--) { |
+ var index = this.recoveryChildIndex_[j]; |
+ var children = node.children; |
+ if (!children[index]) |
+ return node; |
+ node = children[index]; |
+ } |
+ return node; |
+ } |
+ } |
+ return null; |
+ }, |
+ |
/** |
* @return {number} |
*/ |