| 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 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // Tolerate 1-pixel error due to double-to-integer rounding errors. | 360 // Tolerate 1-pixel error due to double-to-integer rounding errors. |
| 361 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this.
_firstVisibleIndex + i) - this._provider.fastHeight(i + this._firstVisibleIndex)
) > 1) | 361 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this.
_firstVisibleIndex + i) - this._provider.fastHeight(i + this._firstVisibleIndex)
) > 1) |
| 362 delete this._cumulativeHeights; | 362 delete this._cumulativeHeights; |
| 363 } | 363 } |
| 364 this._rebuildCumulativeHeightsIfNeeded(); | 364 this._rebuildCumulativeHeightsIfNeeded(); |
| 365 if (shouldStickToBottom) { | 365 if (shouldStickToBottom) { |
| 366 this._lastVisibleIndex = itemCount - 1; | 366 this._lastVisibleIndex = itemCount - 1; |
| 367 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, this._cumulativeHeights[this._cumulativeHeights.length -
1] - clientHeight), 0); | 367 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, this._cumulativeHeights[this._cumulativeHeights.length -
1] - clientHeight), 0); |
| 368 } else { | 368 } else { |
| 369 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, visibleFrom), 0); | 369 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, visibleFrom), 0); |
| 370 this._lastVisibleIndex = Math.min(Array.prototype.upperBound.call(th
is._cumulativeHeights, visibleFrom + clientHeight), itemCount - 1); | 370 this._lastVisibleIndex = Math.min(Array.prototype.upperBound.call(th
is._cumulativeHeights, visibleFrom + clientHeight - 1), itemCount - 1); |
| 371 } | 371 } |
| 372 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1]
|| 0; | 372 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1]
|| 0; |
| 373 var bottomGapHeight = this._cumulativeHeights[this._cumulativeHeights.le
ngth - 1] - this._cumulativeHeights[this._lastVisibleIndex]; | 373 var bottomGapHeight = this._cumulativeHeights[this._cumulativeHeights.le
ngth - 1] - this._cumulativeHeights[this._lastVisibleIndex]; |
| 374 | 374 |
| 375 this._topGapElement.style.height = topGapHeight + "px"; | 375 this._topGapElement.style.height = topGapHeight + "px"; |
| 376 this._bottomGapElement.style.height = bottomGapHeight + "px"; | 376 this._bottomGapElement.style.height = bottomGapHeight + "px"; |
| 377 this._topGapElement._active = !!topGapHeight; | 377 this._topGapElement._active = !!topGapHeight; |
| 378 this._bottomGapElement._active = !!bottomGapHeight; | 378 this._bottomGapElement._active = !!bottomGapHeight; |
| 379 | 379 |
| 380 this._contentElement.style.setProperty("height", "10000000px"); | 380 this._contentElement.style.setProperty("height", "10000000px"); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 /** | 491 /** |
| 492 * @param {number} index | 492 * @param {number} index |
| 493 * @param {boolean=} makeLast | 493 * @param {boolean=} makeLast |
| 494 */ | 494 */ |
| 495 scrollItemIntoView: function(index, makeLast) | 495 scrollItemIntoView: function(index, makeLast) |
| 496 { | 496 { |
| 497 if (index > this._firstVisibleIndex && index < this._lastVisibleIndex) | 497 if (index > this._firstVisibleIndex && index < this._lastVisibleIndex) |
| 498 return; | 498 return; |
| 499 if (makeLast) | 499 if (makeLast) |
| 500 this.forceScrollItemToBeLast(index); | 500 this.forceScrollItemToBeLast(index); |
| 501 else | 501 else if (index <= this._firstVisibleIndex) |
| 502 this.forceScrollItemToBeFirst(index); | 502 this.forceScrollItemToBeFirst(index); |
| 503 else if (index >= this._lastVisibleIndex) |
| 504 this.forceScrollItemToBeLast(index); |
| 503 }, | 505 }, |
| 504 | 506 |
| 505 /** | 507 /** |
| 506 * @param {number} index | 508 * @param {number} index |
| 507 */ | 509 */ |
| 508 forceScrollItemToBeFirst: function(index) | 510 forceScrollItemToBeFirst: function(index) |
| 509 { | 511 { |
| 510 this._rebuildCumulativeHeightsIfNeeded(); | 512 this._rebuildCumulativeHeightsIfNeeded(); |
| 511 this.element.scrollTop = index > 0 ? this._cumulativeHeights[index - 1]
: 0; | 513 this.element.scrollTop = index > 0 ? this._cumulativeHeights[index - 1]
: 0; |
| 512 }, | 514 }, |
| 513 | 515 |
| 514 /** | 516 /** |
| 515 * @param {number} index | 517 * @param {number} index |
| 516 */ | 518 */ |
| 517 forceScrollItemToBeLast: function(index) | 519 forceScrollItemToBeLast: function(index) |
| 518 { | 520 { |
| 519 this._rebuildCumulativeHeightsIfNeeded(); | 521 this._rebuildCumulativeHeightsIfNeeded(); |
| 520 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c
lientHeight; | 522 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c
lientHeight; |
| 521 } | 523 } |
| 522 } | 524 } |
| OLD | NEW |