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 00:19:49
let's just remove this argument altogether
| |
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 | |
425 if (isScroll) | |
426 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.ca ll(this._cumulativeHeights, visibleFrom + 1), 0); | |
lushnikov
2016/07/19 00:19:49
let's kill this - viewport control should work fin
| |
424 } else { | 427 } else { |
425 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t his._cumulativeHeights, visibleFrom + 1), 0); | 428 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 | 429 // 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; | 430 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible Height / this._provider.minimumRowHeight()) - 1; |
428 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, this._item Count - 1); | 431 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, this._item Count - 1); |
429 } | 432 } |
430 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0; | 433 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0; |
431 var bottomGapHeight = this._cumulativeHeights[this._cumulativeHeights.le ngth - 1] - this._cumulativeHeights[this._lastVisibleIndex]; | 434 var bottomGapHeight = this._cumulativeHeights[this._cumulativeHeights.le ngth - 1] - this._cumulativeHeights[this._lastVisibleIndex]; |
432 | 435 |
433 /** | 436 /** |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
561 while ((node = node.traverseNextTextNode()) && node !== container) | 564 while ((node = node.traverseNextTextNode()) && node !== container) |
562 chars += node.textContent.length; | 565 chars += node.textContent.length; |
563 return chars + offset; | 566 return chars + offset; |
564 }, | 567 }, |
565 | 568 |
566 /** | 569 /** |
567 * @param {!Event} event | 570 * @param {!Event} event |
568 */ | 571 */ |
569 _onScroll: function(event) | 572 _onScroll: function(event) |
570 { | 573 { |
571 this._innerRefresh(event.isTrusted); | 574 this._innerRefresh(true); |
572 }, | 575 }, |
573 | 576 |
574 /** | 577 /** |
575 * @return {number} | 578 * @return {number} |
576 */ | 579 */ |
577 firstVisibleIndex: function() | 580 firstVisibleIndex: function() |
578 { | 581 { |
579 return this._firstVisibleIndex; | 582 return this._firstVisibleIndex; |
580 }, | 583 }, |
581 | 584 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
637 | 640 |
638 /** | 641 /** |
639 * @return {number} | 642 * @return {number} |
640 */ | 643 */ |
641 _visibleHeight: function() | 644 _visibleHeight: function() |
642 { | 645 { |
643 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll. | 646 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll. |
644 return this.element.offsetHeight; | 647 return this.element.offsetHeight; |
645 } | 648 } |
646 } | 649 } |
OLD | NEW |