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
3 // found in the LICENSE file.
6 * @fileoverview Simple class to represent a cursor location in the document.
9 goog.provide('cvox.Cursor');
12 * A class to represent a cursor location in the document,
13 * like the start position or end position of a selection range.
15 * Later this may be extended to support "virtual text" for an object,
16 * like the ALT text for an image.
18 * Note: we cache the text of a particular node at the time we
19 * traverse into it. Later we should add support for dynamically
21 * NOTE: Undefined behavior if node is null
22 * @param {Node} node The DOM node.
23 * @param {number} index The index of the character within the node.
24 * @param {string} text The cached text contents of the node.
27 cvox.Cursor = function(node, index, text) {
34 * @return {!cvox.Cursor} A new cursor pointing to the same location.
36 cvox.Cursor.prototype.clone = function() {
37 return new cvox.Cursor(this.node, this.index, this.text);
41 * Modify this cursor to point to the location that another cursor points to.
42 * @param {!cvox.Cursor} otherCursor The cursor to copy from.
44 cvox.Cursor.prototype.copyFrom = function(otherCursor) {
45 this.node = otherCursor.node;
46 this.index = otherCursor.index;
47 this.text = otherCursor.text;
52 * @param {!cvox.Cursor} rhs The cursor to compare against.
53 * @return {boolean} True if equal.
55 cvox.Cursor.prototype.equals = function(rhs) {
56 return this.node == rhs.node &&
57 this.index == rhs.index &&
58 this.text == rhs.text;