| 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 A collection of JavaScript utilities used to improve selection | 6 * @fileoverview A collection of JavaScript utilities used to improve selection |
| 7 * at different granularities. | 7 * at different granularities. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 | 10 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 var text = range.cloneContents().textContent; | 200 var text = range.cloneContents().textContent; |
| 201 var regExpWhiteSpace = new RegExp(/^\s+$/); | 201 var regExpWhiteSpace = new RegExp(/^\s+$/); |
| 202 return (! ((regExpWhiteSpace.test(text)) || | 202 return (! ((regExpWhiteSpace.test(text)) || |
| 203 (text == ''))); | 203 (text == ''))); |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 /** | 206 /** |
| 207 * Returns absolute top and left positions of an element. | 207 * Returns absolute top and left positions of an element. |
| 208 * | 208 * |
| 209 * @param {!Node} node The element for which to compute the position. | 209 * @param {!Node} node The element for which to compute the position. |
| 210 * @return {Array.<number>} Index 0 is the left; index 1 is the top. | 210 * @return {Array<number>} Index 0 is the left; index 1 is the top. |
| 211 * @private | 211 * @private |
| 212 */ | 212 */ |
| 213 cvox.SelectionUtil.findPos_ = function(node) { | 213 cvox.SelectionUtil.findPos_ = function(node) { |
| 214 var curLeft = 0; | 214 var curLeft = 0; |
| 215 var curTop = 0; | 215 var curTop = 0; |
| 216 if (node.offsetParent) { | 216 if (node.offsetParent) { |
| 217 do { | 217 do { |
| 218 curLeft += node.offsetLeft; | 218 curLeft += node.offsetLeft; |
| 219 curTop += node.offsetTop; | 219 curTop += node.offsetTop; |
| 220 } while (node = node.offsetParent); | 220 } while (node = node.offsetParent); |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 return this.getSelectionText_(); | 581 return this.getSelectionText_(); |
| 582 } | 582 } |
| 583 }; | 583 }; |
| 584 | 584 |
| 585 /** | 585 /** |
| 586 * Returns the selection as text instead of a selection object. Note that this | 586 * Returns the selection as text instead of a selection object. Note that this |
| 587 * function must be used in place of getting text directly from the DOM | 587 * function must be used in place of getting text directly from the DOM |
| 588 * if you want i18n tests to pass. | 588 * if you want i18n tests to pass. |
| 589 * | 589 * |
| 590 * @return {string} The text. | 590 * @return {string} The text. |
| 591 * @private |
| 591 */ | 592 */ |
| 592 cvox.SelectionUtil.getSelectionText_ = function() { | 593 cvox.SelectionUtil.getSelectionText_ = function() { |
| 593 return '' + window.getSelection(); | 594 return '' + window.getSelection(); |
| 594 }; | 595 }; |
| 595 | 596 |
| 596 | 597 |
| 597 /** | 598 /** |
| 598 * Returns a range as text instead of a selection object. Note that this | 599 * Returns a range as text instead of a selection object. Note that this |
| 599 * function must be used in place of getting text directly from the DOM | 600 * function must be used in place of getting text directly from the DOM |
| 600 * if you want i18n tests to pass. | 601 * if you want i18n tests to pass. |
| 601 * | 602 * |
| 602 * @param {Range} range A range. | 603 * @param {Range} range A range. |
| 603 * @return {string} The text. | 604 * @return {string} The text. |
| 604 */ | 605 */ |
| 605 cvox.SelectionUtil.getRangeText = function(range) { | 606 cvox.SelectionUtil.getRangeText = function(range) { |
| 606 if (range) | 607 if (range) |
| 607 return range.cloneContents().textContent.replace(/\s+/g, ' '); | 608 return range.cloneContents().textContent.replace(/\s+/g, ' '); |
| 608 else | 609 else |
| 609 return ''; | 610 return ''; |
| 610 }; | 611 }; |
| OLD | NEW |