| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 286 } |
| 287 this._selectionIsBackward = isBackward; | 287 this._selectionIsBackward = isBackward; |
| 288 return true; | 288 return true; |
| 289 }, | 289 }, |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * @param {?Selection} selection | 292 * @param {?Selection} selection |
| 293 */ | 293 */ |
| 294 _restoreSelection: function(selection) | 294 _restoreSelection: function(selection) |
| 295 { | 295 { |
| 296 var anchorElement; | 296 var anchorElement = null; |
| 297 var anchorOffset; | 297 var anchorOffset; |
| 298 if (this._firstVisibleIndex <= this._anchorSelection.item && this._ancho
rSelection.item <= this._lastVisibleIndex) { | 298 if (this._firstVisibleIndex <= this._anchorSelection.item && this._ancho
rSelection.item <= this._lastVisibleIndex) { |
| 299 anchorElement = this._anchorSelection.node; | 299 anchorElement = this._anchorSelection.node; |
| 300 anchorOffset = this._anchorSelection.offset; | 300 anchorOffset = this._anchorSelection.offset; |
| 301 } else { | 301 } else { |
| 302 if (this._anchorSelection.item < this._firstVisibleIndex) | 302 if (this._anchorSelection.item < this._firstVisibleIndex) |
| 303 anchorElement = this._topGapElement; | 303 anchorElement = this._topGapElement; |
| 304 else if (this._anchorSelection.item > this._lastVisibleIndex) | 304 else if (this._anchorSelection.item > this._lastVisibleIndex) |
| 305 anchorElement = this._bottomGapElement; | 305 anchorElement = this._bottomGapElement; |
| 306 anchorOffset = this._selectionIsBackward ? 1 : 0; | 306 anchorOffset = this._selectionIsBackward ? 1 : 0; |
| 307 } | 307 } |
| 308 | 308 |
| 309 var headElement; | 309 var headElement = null; |
| 310 var headOffset; | 310 var headOffset; |
| 311 if (this._firstVisibleIndex <= this._headSelection.item && this._headSel
ection.item <= this._lastVisibleIndex) { | 311 if (this._firstVisibleIndex <= this._headSelection.item && this._headSel
ection.item <= this._lastVisibleIndex) { |
| 312 headElement = this._headSelection.node; | 312 headElement = this._headSelection.node; |
| 313 headOffset = this._headSelection.offset; | 313 headOffset = this._headSelection.offset; |
| 314 } else { | 314 } else { |
| 315 if (this._headSelection.item < this._firstVisibleIndex) | 315 if (this._headSelection.item < this._firstVisibleIndex) |
| 316 headElement = this._topGapElement; | 316 headElement = this._topGapElement; |
| 317 else if (this._headSelection.item > this._lastVisibleIndex) | 317 else if (this._headSelection.item > this._lastVisibleIndex) |
| 318 headElement = this._bottomGapElement; | 318 headElement = this._bottomGapElement; |
| 319 headOffset = this._selectionIsBackward ? 0 : 1; | 319 headOffset = this._selectionIsBackward ? 0 : 1; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 * @param {!Node} container | 432 * @param {!Node} container |
| 433 * @param {number} offset | 433 * @param {number} offset |
| 434 * @return {number} | 434 * @return {number} |
| 435 */ | 435 */ |
| 436 _textOffsetInNode: function(itemElement, container, offset) | 436 _textOffsetInNode: function(itemElement, container, offset) |
| 437 { | 437 { |
| 438 if (!offset) | 438 if (!offset) |
| 439 return 0; | 439 return 0; |
| 440 var chars = 0; | 440 var chars = 0; |
| 441 var node = itemElement; | 441 var node = itemElement; |
| 442 while ((node = node.traverseNextTextNode(true)) && node !== container) | 442 while ((node = node.traverseNextTextNode()) && node !== container) |
| 443 chars += node.textContent.length; | 443 chars += node.textContent.length; |
| 444 return chars + offset; | 444 return chars + offset; |
| 445 }, | 445 }, |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * @param {?Event} event | 448 * @param {?Event} event |
| 449 */ | 449 */ |
| 450 _onScroll: function(event) | 450 _onScroll: function(event) |
| 451 { | 451 { |
| 452 this.refresh(); | 452 this.refresh(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 505 |
| 506 /** | 506 /** |
| 507 * @param {number} index | 507 * @param {number} index |
| 508 */ | 508 */ |
| 509 forceScrollItemToBeLast: function(index) | 509 forceScrollItemToBeLast: function(index) |
| 510 { | 510 { |
| 511 this._rebuildCumulativeHeightsIfNeeded(); | 511 this._rebuildCumulativeHeightsIfNeeded(); |
| 512 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c
lientHeight; | 512 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c
lientHeight; |
| 513 } | 513 } |
| 514 } | 514 } |
| OLD | NEW |