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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Classes related to cursors that point to and select parts of 6 * @fileoverview Classes related to cursors that point to and select parts of
7 * the automation tree. 7 * the automation tree.
8 */ 8 */
9 9
10 goog.provide('cursors.Cursor'); 10 goog.provide('cursors.Cursor');
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 * @param {!AutomationNode} node 90 * @param {!AutomationNode} node
91 * @return {!cursors.Cursor} 91 * @return {!cursors.Cursor}
92 */ 92 */
93 cursors.Cursor.fromNode = function(node) { 93 cursors.Cursor.fromNode = function(node) {
94 return new cursors.Cursor(node, cursors.NODE_INDEX); 94 return new cursors.Cursor(node, cursors.NODE_INDEX);
95 }; 95 };
96 96
97 cursors.Cursor.prototype = { 97 cursors.Cursor.prototype = {
98 /** 98 /**
99 * Returns true if |rhs| is equal to this cursor. 99 * Returns true if |rhs| is equal to this cursor.
100 * Use this for strict equality between cursors.
100 * @param {!cursors.Cursor} rhs 101 * @param {!cursors.Cursor} rhs
101 * @return {boolean} 102 * @return {boolean}
102 */ 103 */
103 equals: function(rhs) { 104 equals: function(rhs) {
104 return this.node === rhs.node && 105 return this.node === rhs.node &&
105 this.index === rhs.index; 106 this.index === rhs.index;
106 }, 107 },
107 108
108 /** 109 /**
110 * Returns true if |rhs| is equal to this cursor.
111 * Use this for loose equality between cursors where specific character-based
112 * indicies do not matter such as when processing node-targeted events.
113 * @param {!cursors.Cursor} rhs
114 * @return {boolean}
115 */
116 contentEquals: function(rhs) {
117 // First, normalize the two nodes so they both point to the first non-text
118 // node.
119 var lNode = this.node;
120 var rNode = rhs.node;
121 while (lNode && (lNode.role == RoleType.inlineTextBox ||
122 lNode.role == RoleType.staticText))
123 lNode = lNode.parent;
124 while (rNode && (rNode.role == RoleType.inlineTextBox ||
125 rNode.role == RoleType.staticText))
126 rNode = rNode.parent;
127
128 // Ignore indicies for now.
129
130 return lNode === rNode && lNode != undefined;
131 },
132
133 /**
109 * Returns the node. If the node is invalid since the last time it 134 * Returns the node. If the node is invalid since the last time it
110 * was accessed, moves the cursor to the nearest valid ancestor first. 135 * was accessed, moves the cursor to the nearest valid ancestor first.
111 * @return {AutomationNode} 136 * @return {AutomationNode}
112 */ 137 */
113 get node() { 138 get node() {
114 for (var i = 0; i < this.ancestry_.length; i++) { 139 for (var i = 0; i < this.ancestry_.length; i++) {
115 var firstValidNode = this.ancestry_[i]; 140 var firstValidNode = this.ancestry_[i];
116 if (firstValidNode != null && firstValidNode.role !== undefined && 141 if (firstValidNode != null && firstValidNode.role !== undefined &&
117 firstValidNode.root !== undefined) { 142 firstValidNode.root !== undefined) {
118 return firstValidNode; 143 return firstValidNode;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 return Dir.FORWARD; 498 return Dir.FORWARD;
474 else if (testDirA == Dir.BACKWARD && testDirB == Dir.FORWARD) 499 else if (testDirA == Dir.BACKWARD && testDirB == Dir.FORWARD)
475 return Dir.BACKWARD; 500 return Dir.BACKWARD;
476 else 501 else
477 return testDirA; 502 return testDirA;
478 }; 503 };
479 504
480 cursors.Range.prototype = { 505 cursors.Range.prototype = {
481 /** 506 /**
482 * Returns true if |rhs| is equal to this range. 507 * Returns true if |rhs| is equal to this range.
508 * Use this for strict equality between ranges.
483 * @param {!cursors.Range} rhs 509 * @param {!cursors.Range} rhs
484 * @return {boolean} 510 * @return {boolean}
485 */ 511 */
486 equals: function(rhs) { 512 equals: function(rhs) {
487 return this.start_.equals(rhs.start) && 513 return this.start_.equals(rhs.start) &&
488 this.end_.equals(rhs.end); 514 this.end_.equals(rhs.end);
489 }, 515 },
490 516
491 /** 517 /**
518 * Returns true if |rhs| is equal to this range.
519 * Use this for loose equality between ranges.
520 * @param {!cursors.Range} rhs
521 * @return {boolean}
522 */
523 contentEquals: function(rhs) {
524 return this.start_.contentEquals(rhs.start) &&
525 this.end_.contentEquals(rhs.end);
526 },
527
528 /**
492 * Gets a cursor bounding this range. 529 * Gets a cursor bounding this range.
493 * @param {Dir} dir Which endpoint cursor to return; Dir.FORWARD for end, 530 * @param {Dir} dir Which endpoint cursor to return; Dir.FORWARD for end,
494 * Dir.BACKWARD for start. 531 * Dir.BACKWARD for start.
495 * @param {boolean=} opt_reverse Specify to have Dir.BACKWARD return end, 532 * @param {boolean=} opt_reverse Specify to have Dir.BACKWARD return end,
496 * Dir.FORWARD return start. 533 * Dir.FORWARD return start.
497 * @return {!cursors.Cursor} 534 * @return {!cursors.Cursor}
498 */ 535 */
499 getBound: function(dir, opt_reverse) { 536 getBound: function(dir, opt_reverse) {
500 if (opt_reverse) 537 if (opt_reverse)
501 return dir == Dir.BACKWARD ? this.end_ : this.start_; 538 return dir == Dir.BACKWARD ? this.end_ : this.start_;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 /** 642 /**
606 * Returns whether this range has valid start and end cursors. 643 * Returns whether this range has valid start and end cursors.
607 * @return {boolean} 644 * @return {boolean}
608 */ 645 */
609 isValid: function() { 646 isValid: function() {
610 return this.start.isValid() && this.end.isValid(); 647 return this.start.isValid() && this.end.isValid();
611 } 648 }
612 }; 649 };
613 650
614 }); // goog.scope 651 }); // goog.scope
OLDNEW
« 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