| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 break; | 96 break; |
| 97 } | 97 } |
| 98 | 98 |
| 99 range.setStart(startCursor.node, startCursor.index); | 99 range.setStart(startCursor.node, startCursor.index); |
| 100 range.setEnd(endCursor.node, endCursor.index); | 100 range.setEnd(endCursor.node, endCursor.index); |
| 101 rect = range.getBoundingClientRect(); | 101 rect = range.getBoundingClientRect(); |
| 102 if (!rect || rect.width == 0 || rect.height == 0) { | 102 if (!rect || rect.width == 0 || rect.height == 0) { |
| 103 continue; | 103 continue; |
| 104 } | 104 } |
| 105 | 105 |
| 106 if (lastBottom !== null && | 106 if (lastBottom !== null && rect.bottom != lastBottom && textSize > 0 && |
| 107 rect.bottom != lastBottom && | 107 text.substr(-1).match(/\S/) && c.match(/\S/)) { |
| 108 textSize > 0 && | |
| 109 text.substr(-1).match(/\S/) && | |
| 110 c.match(/\S/)) { | |
| 111 text += '\n'; | 108 text += '\n'; |
| 112 textSize++; | 109 textSize++; |
| 113 } | 110 } |
| 114 | 111 |
| 115 if (startCursor.node != endCursor.node && endCursor.index > 0) { | 112 if (startCursor.node != endCursor.node && endCursor.index > 0) { |
| 116 range.setStart(endCursor.node, endCursor.index - 1); | 113 range.setStart(endCursor.node, endCursor.index - 1); |
| 117 rect = range.getBoundingClientRect(); | 114 rect = range.getBoundingClientRect(); |
| 118 if (!rect || rect.width == 0 || rect.height == 0) { | 115 if (!rect || rect.width == 0 || rect.height == 0) { |
| 119 continue; | 116 continue; |
| 120 } | 117 } |
| 121 } | 118 } |
| 122 | 119 |
| 123 if (!setStart && | 120 if (!setStart && selectionStartIndex == -1 && |
| 124 selectionStartIndex == -1 && | |
| 125 endCursor.node == selectionStart.node && | 121 endCursor.node == selectionStart.node && |
| 126 endCursor.index >= selectionStart.index) { | 122 endCursor.index >= selectionStart.index) { |
| 127 if (endCursor.index > selectionStart.index) { | 123 if (endCursor.index > selectionStart.index) { |
| 128 selectionStartIndex = textSize; | 124 selectionStartIndex = textSize; |
| 129 } else { | 125 } else { |
| 130 setStart = true; | 126 setStart = true; |
| 131 } | 127 } |
| 132 } | 128 } |
| 133 if (!setEnd && | 129 if (!setEnd && selectionEndIndex == -1 && |
| 134 selectionEndIndex == -1 && | |
| 135 endCursor.node == selectionEnd.node && | 130 endCursor.node == selectionEnd.node && |
| 136 endCursor.index >= selectionEnd.index) { | 131 endCursor.index >= selectionEnd.index) { |
| 137 if (endCursor.index > selectionEnd.index) { | 132 if (endCursor.index > selectionEnd.index) { |
| 138 selectionEndIndex = textSize; | 133 selectionEndIndex = textSize; |
| 139 } else { | 134 } else { |
| 140 setEnd = true; | 135 setEnd = true; |
| 141 } | 136 } |
| 142 } | 137 } |
| 143 | 138 |
| 144 if (lastBottom === null) { | 139 if (lastBottom === null) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 }; | 221 }; |
| 227 | 222 |
| 228 /** | 223 /** |
| 229 * Get the end character index of a line. | 224 * Get the end character index of a line. |
| 230 * @param {number} index The 0-based line index. | 225 * @param {number} index The 0-based line index. |
| 231 * @return {number} The 0-based index of the end of this line. | 226 * @return {number} The 0-based index of the end of this line. |
| 232 */ | 227 */ |
| 233 cvox.ContentEditableExtractor.prototype.getLineEnd = function(index) { | 228 cvox.ContentEditableExtractor.prototype.getLineEnd = function(index) { |
| 234 return this.lines_[index].endIndex; | 229 return this.lines_[index].endIndex; |
| 235 }; | 230 }; |
| OLD | NEW |