Chromium Code Reviews| 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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 373 | 373 |
| 374 selection.setBaseAndExtent(anchorElement, anchorOffset, headElement, hea dOffset); | 374 selection.setBaseAndExtent(anchorElement, anchorOffset, headElement, hea dOffset); |
| 375 }, | 375 }, |
| 376 | 376 |
| 377 refresh: function() | 377 refresh: function() |
| 378 { | 378 { |
| 379 this._innerRefresh(false); | 379 this._innerRefresh(false); |
| 380 }, | 380 }, |
| 381 | 381 |
| 382 /** | 382 /** |
| 383 * @param {boolean} isUserGesture | 383 * @param {boolean} isScroll |
| 384 */ | 384 */ |
| 385 _innerRefresh: function(isUserGesture) | 385 _innerRefresh: function(isScroll) |
|
lushnikov
2016/07/19 02:26:19
we can now remove this argument altogether
luoe
2016/07/19 17:52:33
Done.
| |
| 386 { | 386 { |
| 387 if (!this._visibleHeight()) | 387 if (!this._visibleHeight()) |
| 388 return; // Do nothing for invisible controls. | 388 return; // Do nothing for invisible controls. |
| 389 | 389 |
| 390 if (!this._itemCount) { | 390 if (!this._itemCount) { |
| 391 for (var i = 0; i < this._renderedItems.length; ++i) | 391 for (var i = 0; i < this._renderedItems.length; ++i) |
| 392 this._renderedItems[i].willHide(); | 392 this._renderedItems[i].willHide(); |
| 393 this._renderedItems = []; | 393 this._renderedItems = []; |
| 394 this._contentElement.removeChildren(); | 394 this._contentElement.removeChildren(); |
| 395 this._topGapElement.style.height = "0px"; | 395 this._topGapElement.style.height = "0px"; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 409 | 409 |
| 410 for (var i = 0; i < this._renderedItems.length; ++i) { | 410 for (var i = 0; i < this._renderedItems.length; ++i) { |
| 411 // Tolerate 1-pixel error due to double-to-integer rounding errors. | 411 // Tolerate 1-pixel error due to double-to-integer rounding errors. |
| 412 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this. _firstVisibleIndex + i) - this._renderedItems[i].element().offsetHeight) > 1) | 412 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this. _firstVisibleIndex + i) - this._renderedItems[i].element().offsetHeight) > 1) |
| 413 delete this._cumulativeHeights; | 413 delete this._cumulativeHeights; |
| 414 } | 414 } |
| 415 this._rebuildCumulativeHeightsIfNeeded(); | 415 this._rebuildCumulativeHeightsIfNeeded(); |
| 416 var oldFirstVisibleIndex = this._firstVisibleIndex; | 416 var oldFirstVisibleIndex = this._firstVisibleIndex; |
| 417 var oldLastVisibleIndex = this._lastVisibleIndex; | 417 var oldLastVisibleIndex = this._lastVisibleIndex; |
| 418 | 418 |
| 419 var shouldStickToBottom = !isUserGesture && this._stickToBottom && this. _scrolledToBottom; | 419 var shouldStickToBottom = this._stickToBottom && this._scrolledToBottom; |
| 420 | 420 |
| 421 if (shouldStickToBottom) { | 421 if (shouldStickToBottom) { |
| 422 this._lastVisibleIndex = this._itemCount - 1; | 422 this._lastVisibleIndex = this._itemCount - 1; |
| 423 this._firstVisibleIndex = Math.max(this._itemCount - Math.ceil(visib leHeight / this._provider.minimumRowHeight()), 0); | 423 this._firstVisibleIndex = Math.max(this._itemCount - Math.ceil(visib leHeight / this._provider.minimumRowHeight()), 0); |
| 424 } else { | 424 } else { |
| 425 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t his._cumulativeHeights, visibleFrom + 1), 0); | 425 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t his._cumulativeHeights, visibleFrom + 1), 0); |
| 426 // Proactively render more rows in case some of them will be collaps ed without triggering refresh. @see crbug.com/390169 | 426 // Proactively render more rows in case some of them will be collaps ed without triggering refresh. @see crbug.com/390169 |
| 427 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible Height / this._provider.minimumRowHeight()) - 1; | 427 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible Height / this._provider.minimumRowHeight()) - 1; |
| 428 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, this._item Count - 1); | 428 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, this._item Count - 1); |
| 429 } | 429 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 561 while ((node = node.traverseNextTextNode()) && node !== container) | 561 while ((node = node.traverseNextTextNode()) && node !== container) |
| 562 chars += node.textContent.length; | 562 chars += node.textContent.length; |
| 563 return chars + offset; | 563 return chars + offset; |
| 564 }, | 564 }, |
| 565 | 565 |
| 566 /** | 566 /** |
| 567 * @param {!Event} event | 567 * @param {!Event} event |
| 568 */ | 568 */ |
| 569 _onScroll: function(event) | 569 _onScroll: function(event) |
| 570 { | 570 { |
| 571 this._innerRefresh(event.isTrusted); | 571 this._innerRefresh(true); |
| 572 }, | 572 }, |
| 573 | 573 |
| 574 /** | 574 /** |
| 575 * @return {number} | 575 * @return {number} |
| 576 */ | 576 */ |
| 577 firstVisibleIndex: function() | 577 firstVisibleIndex: function() |
| 578 { | 578 { |
| 579 return this._firstVisibleIndex; | 579 return this._firstVisibleIndex; |
| 580 }, | 580 }, |
| 581 | 581 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 | 637 |
| 638 /** | 638 /** |
| 639 * @return {number} | 639 * @return {number} |
| 640 */ | 640 */ |
| 641 _visibleHeight: function() | 641 _visibleHeight: function() |
| 642 { | 642 { |
| 643 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll. | 643 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll. |
| 644 return this.element.offsetHeight; | 644 return this.element.offsetHeight; |
| 645 } | 645 } |
| 646 } | 646 } |
| OLD | NEW |