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

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

Issue 2333533003: Add a |contentEquals| method to cursors and ranges. (Closed)
Patch Set: Add a |contentEquals| method to cursors and ranges. Created 4 years, 3 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
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors_test.extjs » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 974e0a4f0d7313363085ca4bd8f2a114a191d849..074cbdac315723cea6103eacd38debeb5420d18d 100644
--- a/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
+++ b/chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors.js
@@ -97,6 +97,7 @@ cursors.Cursor.fromNode = function(node) {
cursors.Cursor.prototype = {
/**
* Returns true if |rhs| is equal to this cursor.
+ * Use this for strict equality between cursors.
* @param {!cursors.Cursor} rhs
* @return {boolean}
*/
@@ -106,6 +107,30 @@ cursors.Cursor.prototype = {
},
/**
+ * Returns true if |rhs| is equal to this cursor.
+ * Use this for loose equality between cursors where specific character-based
+ * indicies do not matter such as when processing node-targeted events.
+ * @param {!cursors.Cursor} rhs
+ * @return {boolean}
+ */
+ contentEquals: function(rhs) {
+ // First, normalize the two nodes so they both point to the first non-text
+ // node.
+ var lNode = this.node;
+ var rNode = rhs.node;
+ while (lNode && (lNode.role == RoleType.inlineTextBox ||
+ lNode.role == RoleType.staticText))
+ lNode = lNode.parent;
+ while (rNode && (rNode.role == RoleType.inlineTextBox ||
+ rNode.role == RoleType.staticText))
+ rNode = rNode.parent;
+
+ // Ignore indicies for now.
+
+ return lNode === rNode && lNode != undefined;
+ },
+
+ /**
* Returns the node. If the node is invalid since the last time it
* was accessed, moves the cursor to the nearest valid ancestor first.
* @return {AutomationNode}
@@ -480,6 +505,7 @@ cursors.Range.getDirection = function(rangeA, rangeB) {
cursors.Range.prototype = {
/**
* Returns true if |rhs| is equal to this range.
+ * Use this for strict equality between ranges.
* @param {!cursors.Range} rhs
* @return {boolean}
*/
@@ -489,6 +515,17 @@ cursors.Range.prototype = {
},
/**
+ * Returns true if |rhs| is equal to this range.
+ * Use this for loose equality between ranges.
+ * @param {!cursors.Range} rhs
+ * @return {boolean}
+ */
+ contentEquals: function(rhs) {
+ return this.start_.contentEquals(rhs.start) &&
+ this.end_.contentEquals(rhs.end);
+ },
+
+ /**
* Gets a cursor bounding this range.
* @param {Dir} dir Which endpoint cursor to return; Dir.FORWARD for end,
* Dir.BACKWARD for start.
« no previous file with comments | « no previous file | chrome/browser/resources/chromeos/chromevox/cvox2/background/cursors_test.extjs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698