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 Defines the ContentEditableExtractor class. | 6 * @fileoverview Defines the ContentEditableExtractor class. |
7 */ | 7 */ |
8 | 8 |
9 goog.provide('cvox.ContentEditableExtractor'); | 9 goog.provide('cvox.ContentEditableExtractor'); |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 /** | 33 /** |
34 * The end cursor/selection index. | 34 * The end cursor/selection index. |
35 * @type {number} | 35 * @type {number} |
36 * @private | 36 * @private |
37 */ | 37 */ |
38 this.end_ = 0; | 38 this.end_ = 0; |
39 | 39 |
40 /** | 40 /** |
41 * Map from line index to a data structure containing the start | 41 * Map from line index to a data structure containing the start |
42 * and end index within the line. | 42 * and end index within the line. |
43 * @type {Object.<number, {startIndex: number, endIndex: number}>} | 43 * @type {Object<number, {startIndex: number, endIndex: number}>} |
44 * @private | 44 * @private |
45 */ | 45 */ |
46 this.lines_ = {}; | 46 this.lines_ = {}; |
47 | 47 |
48 /** | 48 /** |
49 * Map from 0-based character index to 0-based line index. | 49 * Map from 0-based character index to 0-based line index. |
50 * @type {Array.<number>} | 50 * @type {Array<number>} |
51 * @private | 51 * @private |
52 */ | 52 */ |
53 this.characterToLineMap_ = []; | 53 this.characterToLineMap_ = []; |
54 }; | 54 }; |
55 | 55 |
56 /** | 56 /** |
57 * Update the metadata. | 57 * Update the metadata. |
58 * @param {Element} element The DOM element that's contentEditable. | 58 * @param {Element} element The DOM element that's contentEditable. |
59 */ | 59 */ |
60 cvox.ContentEditableExtractor.prototype.update = function(element) { | 60 cvox.ContentEditableExtractor.prototype.update = function(element) { |
61 /** | 61 /** |
62 * Map from line index to a data structure containing the start | 62 * Map from line index to a data structure containing the start |
63 * and end index within the line. | 63 * and end index within the line. |
64 * @type {Object.<number, {startIndex: number, endIndex: number}>} | 64 * @type {Object<number, {startIndex: number, endIndex: number}>} |
65 */ | 65 */ |
66 var lines = {0: {startIndex: 0, endIndex: 0}}; | 66 var lines = {0: {startIndex: 0, endIndex: 0}}; |
67 var startCursor = new cvox.Cursor(element, 0, ''); | 67 var startCursor = new cvox.Cursor(element, 0, ''); |
68 var endCursor = startCursor.clone(); | 68 var endCursor = startCursor.clone(); |
69 var range = document.createRange(); | 69 var range = document.createRange(); |
70 var rect; | 70 var rect; |
71 var lineIndex = 0; | 71 var lineIndex = 0; |
72 var lastBottom = null; | 72 var lastBottom = null; |
73 var text = ''; | 73 var text = ''; |
74 var textSize = 0; | 74 var textSize = 0; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 }; | 226 }; |
227 | 227 |
228 /** | 228 /** |
229 * Get the end character index of a line. | 229 * Get the end character index of a line. |
230 * @param {number} index The 0-based line index. | 230 * @param {number} index The 0-based line index. |
231 * @return {number} The 0-based index of the end of this line. | 231 * @return {number} The 0-based index of the end of this line. |
232 */ | 232 */ |
233 cvox.ContentEditableExtractor.prototype.getLineEnd = function(index) { | 233 cvox.ContentEditableExtractor.prototype.getLineEnd = function(index) { |
234 return this.lines_[index].endIndex; | 234 return this.lines_[index].endIndex; |
235 }; | 235 }; |
OLD | NEW |