| 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 EditableTextAreaShadow class. | 6 * @fileoverview Defines the EditableTextAreaShadow class. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 goog.provide('cvox.EditableTextAreaShadow'); | 9 goog.provide('cvox.EditableTextAreaShadow'); |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Creates a shadow element for an editable text area used to compute line | 12 * Creates a shadow element for an editable text area used to compute line |
| 13 * numbers. | 13 * numbers. |
| 14 * @constructor | 14 * @constructor |
| 15 */ | 15 */ |
| 16 cvox.EditableTextAreaShadow = function() { | 16 cvox.EditableTextAreaShadow = function() { |
| 17 /** | 17 /** |
| 18 * @type {Element} | 18 * @type {Element} |
| 19 * @private | 19 * @private |
| 20 */ | 20 */ |
| 21 this.shadowElement_ = document.createElement('div'); | 21 this.shadowElement_ = document.createElement('div'); |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Map from line index to a data structure containing the start | 24 * Map from line index to a data structure containing the start |
| 25 * and end index within the line. | 25 * and end index within the line. |
| 26 * @type {Object.<number, {startIndex: number, endIndex: number}>} | 26 * @type {Object<number, {startIndex: number, endIndex: number}>} |
| 27 * @private | 27 * @private |
| 28 */ | 28 */ |
| 29 this.lines_ = {}; | 29 this.lines_ = {}; |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * Map from 0-based character index to 0-based line index. | 32 * Map from 0-based character index to 0-based line index. |
| 33 * @type {Array.<number>} | 33 * @type {Array<number>} |
| 34 * @private | 34 * @private |
| 35 */ | 35 */ |
| 36 this.characterToLineMap_ = []; | 36 this.characterToLineMap_ = []; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 /** | 39 /** |
| 40 * Update the shadow element. | 40 * Update the shadow element. |
| 41 * @param {Element} element The textarea element. | 41 * @param {Element} element The textarea element. |
| 42 */ | 42 */ |
| 43 cvox.EditableTextAreaShadow.prototype.update = function(element) { | 43 cvox.EditableTextAreaShadow.prototype.update = function(element) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 * none of the characters are newlines and they're all at the same | 65 * none of the characters are newlines and they're all at the same |
| 66 * vertical position, we don't have to examine each one. If not, | 66 * vertical position, we don't have to examine each one. If not, |
| 67 * fall back to moving by one character at a time. | 67 * fall back to moving by one character at a time. |
| 68 * @const | 68 * @const |
| 69 */ | 69 */ |
| 70 var SKIP = 8; | 70 var SKIP = 8; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Map from line index to a data structure containing the start | 73 * Map from line index to a data structure containing the start |
| 74 * and end index within the line. | 74 * and end index within the line. |
| 75 * @type {Object.<number, {startIndex: number, endIndex: number}>} | 75 * @type {Object<number, {startIndex: number, endIndex: number}>} |
| 76 */ | 76 */ |
| 77 var lines = {0: {startIndex: 0, endIndex: 0}}; | 77 var lines = {0: {startIndex: 0, endIndex: 0}}; |
| 78 | 78 |
| 79 var range = document.createRange(); | 79 var range = document.createRange(); |
| 80 var offset = 0; | 80 var offset = 0; |
| 81 var lastGoodOffset = 0; | 81 var lastGoodOffset = 0; |
| 82 var lineIndex = 0; | 82 var lineIndex = 0; |
| 83 var lastBottom = null; | 83 var lastBottom = null; |
| 84 var nearNewline = false; | 84 var nearNewline = false; |
| 85 var rect; | 85 var rect; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 }; | 181 }; |
| 182 | 182 |
| 183 /** | 183 /** |
| 184 * Get the end character index of a line. | 184 * Get the end character index of a line. |
| 185 * @param {number} index The 0-based line index. | 185 * @param {number} index The 0-based line index. |
| 186 * @return {number} The 0-based index of the end of this line. | 186 * @return {number} The 0-based index of the end of this line. |
| 187 */ | 187 */ |
| 188 cvox.EditableTextAreaShadow.prototype.getLineEnd = function(index) { | 188 cvox.EditableTextAreaShadow.prototype.getLineEnd = function(index) { |
| 189 return this.lines_[index].endIndex; | 189 return this.lines_[index].endIndex; |
| 190 }; | 190 }; |
| OLD | NEW |