| OLD | NEW |
| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 return new cursors.Cursor(node, cursors.NODE_INDEX); | 82 return new cursors.Cursor(node, cursors.NODE_INDEX); |
| 83 }; | 83 }; |
| 84 | 84 |
| 85 cursors.Cursor.prototype = { | 85 cursors.Cursor.prototype = { |
| 86 /** | 86 /** |
| 87 * Returns true if |rhs| is equal to this cursor. | 87 * Returns true if |rhs| is equal to this cursor. |
| 88 * @param {!cursors.Cursor} rhs | 88 * @param {!cursors.Cursor} rhs |
| 89 * @return {boolean} | 89 * @return {boolean} |
| 90 */ | 90 */ |
| 91 equals: function(rhs) { | 91 equals: function(rhs) { |
| 92 return this.node_ === rhs.getNode() && | 92 return this.node_ === rhs.node && |
| 93 this.index_ === rhs.getIndex(); | 93 this.index_ === rhs.getIndex(); |
| 94 }, | 94 }, |
| 95 | 95 |
| 96 /** | 96 /** |
| 97 * @return {!AutomationNode} | 97 * @return {!AutomationNode} |
| 98 */ | 98 */ |
| 99 getNode: function() { | 99 get node() { |
| 100 return this.node_; | 100 return this.node_; |
| 101 }, | 101 }, |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * @return {number} | 104 * @return {number} |
| 105 */ | 105 */ |
| 106 getIndex: function() { | 106 getIndex: function() { |
| 107 return this.index_; | 107 return this.index_; |
| 108 }, | 108 }, |
| 109 | 109 |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 * relates them. | 277 * relates them. |
| 278 * @param {!cursors.Range} rangeA | 278 * @param {!cursors.Range} rangeA |
| 279 * @param {!cursors.Range} rangeB | 279 * @param {!cursors.Range} rangeB |
| 280 * @return {Dir} | 280 * @return {Dir} |
| 281 */ | 281 */ |
| 282 cursors.Range.getDirection = function(rangeA, rangeB) { | 282 cursors.Range.getDirection = function(rangeA, rangeB) { |
| 283 if (!rangeA || !rangeB) | 283 if (!rangeA || !rangeB) |
| 284 return Dir.FORWARD; | 284 return Dir.FORWARD; |
| 285 | 285 |
| 286 // They are the same range. | 286 // They are the same range. |
| 287 if (rangeA.getStart().getNode() === rangeB.getStart().getNode() && | 287 if (rangeA.start.node === rangeB.start.node && |
| 288 rangeB.getEnd().getNode() === rangeA.getEnd().getNode()) | 288 rangeB.end.node === rangeA.end.node) |
| 289 return Dir.FORWARD; | 289 return Dir.FORWARD; |
| 290 | 290 |
| 291 var testDirA = | 291 var testDirA = |
| 292 AutomationUtil.getDirection( | 292 AutomationUtil.getDirection( |
| 293 rangeA.getStart().getNode(), rangeB.getEnd().getNode()); | 293 rangeA.start.node, rangeB.end.node); |
| 294 var testDirB = | 294 var testDirB = |
| 295 AutomationUtil.getDirection( | 295 AutomationUtil.getDirection( |
| 296 rangeB.getStart().getNode(), rangeA.getEnd().getNode()); | 296 rangeB.start.node, rangeA.end.node); |
| 297 | 297 |
| 298 // The two ranges are either partly overlapping or non overlapping. | 298 // The two ranges are either partly overlapping or non overlapping. |
| 299 if (testDirA == Dir.FORWARD && testDirB == Dir.BACKWARD) | 299 if (testDirA == Dir.FORWARD && testDirB == Dir.BACKWARD) |
| 300 return Dir.FORWARD; | 300 return Dir.FORWARD; |
| 301 else if (testDirA == Dir.BACKWARD && testDirB == Dir.FORWARD) | 301 else if (testDirA == Dir.BACKWARD && testDirB == Dir.FORWARD) |
| 302 return Dir.BACKWARD; | 302 return Dir.BACKWARD; |
| 303 else | 303 else |
| 304 return testDirA; | 304 return testDirA; |
| 305 }; | 305 }; |
| 306 | 306 |
| 307 cursors.Range.prototype = { | 307 cursors.Range.prototype = { |
| 308 /** | 308 /** |
| 309 * Returns true if |rhs| is equal to this range. | 309 * Returns true if |rhs| is equal to this range. |
| 310 * @param {!cursors.Range} rhs | 310 * @param {!cursors.Range} rhs |
| 311 * @return {boolean} | 311 * @return {boolean} |
| 312 */ | 312 */ |
| 313 equals: function(rhs) { | 313 equals: function(rhs) { |
| 314 return this.start_.equals(rhs.getStart()) && | 314 return this.start_.equals(rhs.start) && |
| 315 this.end_.equals(rhs.getEnd()); | 315 this.end_.equals(rhs.end); |
| 316 }, | 316 }, |
| 317 | 317 |
| 318 /** | 318 /** |
| 319 * Gets a cursor bounding this range. | 319 * Gets a cursor bounding this range. |
| 320 * @param {Dir} dir Which endpoint cursor to return; Dir.FORWARD for end, | 320 * @param {Dir} dir Which endpoint cursor to return; Dir.FORWARD for end, |
| 321 * Dir.BACKWARD for start. | 321 * Dir.BACKWARD for start. |
| 322 * @param {boolean=} opt_reverse Specify to have Dir.BACKWARD return end, | 322 * @param {boolean=} opt_reverse Specify to have Dir.BACKWARD return end, |
| 323 * Dir.FORWARD return start. | 323 * Dir.FORWARD return start. |
| 324 * @return {!cursors.Cursor} | 324 * @return {!cursors.Cursor} |
| 325 */ | 325 */ |
| 326 getBound: function(dir, opt_reverse) { | 326 getBound: function(dir, opt_reverse) { |
| 327 if (opt_reverse) | 327 if (opt_reverse) |
| 328 return dir == Dir.BACKWARD ? this.end_ : this.start_; | 328 return dir == Dir.BACKWARD ? this.end_ : this.start_; |
| 329 return dir == Dir.FORWARD ? this.end_ : this.start_; | 329 return dir == Dir.FORWARD ? this.end_ : this.start_; |
| 330 }, | 330 }, |
| 331 | 331 |
| 332 /** | 332 /** |
| 333 * @return {!cursors.Cursor} | 333 * @return {!cursors.Cursor} |
| 334 */ | 334 */ |
| 335 getStart: function() { | 335 get start() { |
| 336 return this.start_; | 336 return this.start_; |
| 337 }, | 337 }, |
| 338 | 338 |
| 339 /** | 339 /** |
| 340 * @return {!cursors.Cursor} | 340 * @return {!cursors.Cursor} |
| 341 */ | 341 */ |
| 342 getEnd: function() { | 342 get end() { |
| 343 return this.end_; | 343 return this.end_; |
| 344 }, | 344 }, |
| 345 | 345 |
| 346 /** | 346 /** |
| 347 * Returns true if this range covers less than a node. | 347 * Returns true if this range covers less than a node. |
| 348 * @return {boolean} | 348 * @return {boolean} |
| 349 */ | 349 */ |
| 350 isSubNode: function() { | 350 isSubNode: function() { |
| 351 return this.getStart().getNode() === this.getEnd().getNode() && | 351 return this.start.node === this.end.node && |
| 352 this.getStart().getIndex() > -1 && | 352 this.start.getIndex() > -1 && |
| 353 this.getEnd().getIndex() > -1; | 353 this.end.getIndex() > -1; |
| 354 }, | 354 }, |
| 355 | 355 |
| 356 /** | 356 /** |
| 357 * Makes a Range which has been moved from this range by the given unit and | 357 * Makes a Range which has been moved from this range by the given unit and |
| 358 * direction. | 358 * direction. |
| 359 * @param {Unit} unit | 359 * @param {Unit} unit |
| 360 * @param {Dir} dir | 360 * @param {Dir} dir |
| 361 * @return {cursors.Range} | 361 * @return {cursors.Range} |
| 362 */ | 362 */ |
| 363 move: function(unit, dir) { | 363 move: function(unit, dir) { |
| 364 var newStart = this.start_; | 364 var newStart = this.start_; |
| 365 var newEnd = newStart; | 365 var newEnd = newStart; |
| 366 switch (unit) { | 366 switch (unit) { |
| 367 case Unit.CHARACTER: | 367 case Unit.CHARACTER: |
| 368 newStart = newStart.move(unit, Movement.BOUND, dir); | 368 newStart = newStart.move(unit, Movement.BOUND, dir); |
| 369 newEnd = newStart.move(unit, Movement.BOUND, Dir.FORWARD); | 369 newEnd = newStart.move(unit, Movement.BOUND, Dir.FORWARD); |
| 370 // Character crossed a node; collapses to the end of the node. | 370 // Character crossed a node; collapses to the end of the node. |
| 371 if (newStart.getNode() !== newEnd.getNode()) | 371 if (newStart.node !== newEnd.node) |
| 372 newEnd = newStart; | 372 newEnd = newStart; |
| 373 break; | 373 break; |
| 374 case Unit.WORD: | 374 case Unit.WORD: |
| 375 case Unit.LINE: | 375 case Unit.LINE: |
| 376 newStart = newStart.move(unit, Movement.DIRECTIONAL, dir); | 376 newStart = newStart.move(unit, Movement.DIRECTIONAL, dir); |
| 377 newStart = newStart.move(unit, Movement.BOUND, Dir.BACKWARD); | 377 newStart = newStart.move(unit, Movement.BOUND, Dir.BACKWARD); |
| 378 newEnd = newStart.move(unit, Movement.BOUND, Dir.FORWARD); | 378 newEnd = newStart.move(unit, Movement.BOUND, Dir.FORWARD); |
| 379 break; | 379 break; |
| 380 case Unit.NODE: | 380 case Unit.NODE: |
| 381 newStart = newStart.move(unit, Movement.DIRECTIONAL, dir); | 381 newStart = newStart.move(unit, Movement.DIRECTIONAL, dir); |
| 382 newEnd = newStart; | 382 newEnd = newStart; |
| 383 break; | 383 break; |
| 384 } | 384 } |
| 385 return new cursors.Range(newStart, newEnd); | 385 return new cursors.Range(newStart, newEnd); |
| 386 } | 386 } |
| 387 }; | 387 }; |
| 388 | 388 |
| 389 }); // goog.scope | 389 }); // goog.scope |
| OLD | NEW |