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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 this.element.addEventListener("scroll", this._onScroll.bind(this), false); | 48 this.element.addEventListener("scroll", this._onScroll.bind(this), false); |
49 this.element.addEventListener("copy", this._onCopy.bind(this), false); | 49 this.element.addEventListener("copy", this._onCopy.bind(this), false); |
50 this.element.addEventListener("dragstart", this._onDragStart.bind(this), fal
se); | 50 this.element.addEventListener("dragstart", this._onDragStart.bind(this), fal
se); |
51 | 51 |
52 this._firstVisibleIndex = 0; | 52 this._firstVisibleIndex = 0; |
53 this._lastVisibleIndex = -1; | 53 this._lastVisibleIndex = -1; |
54 this._renderedItems = []; | 54 this._renderedItems = []; |
55 this._anchorSelection = null; | 55 this._anchorSelection = null; |
56 this._headSelection = null; | 56 this._headSelection = null; |
57 this._stickToBottom = false; | 57 this._stickToBottom = false; |
| 58 this._scrolledToBottom = true; |
58 } | 59 } |
59 | 60 |
60 /** | 61 /** |
61 * @interface | 62 * @interface |
62 */ | 63 */ |
63 WebInspector.ViewportControl.Provider = function() | 64 WebInspector.ViewportControl.Provider = function() |
64 { | 65 { |
65 } | 66 } |
66 | 67 |
67 WebInspector.ViewportControl.Provider.prototype = { | 68 WebInspector.ViewportControl.Provider.prototype = { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 * @return {!Element} | 127 * @return {!Element} |
127 */ | 128 */ |
128 element: function() | 129 element: function() |
129 { | 130 { |
130 return this._element; | 131 return this._element; |
131 }, | 132 }, |
132 } | 133 } |
133 | 134 |
134 WebInspector.ViewportControl.prototype = { | 135 WebInspector.ViewportControl.prototype = { |
135 /** | 136 /** |
| 137 * @return {boolean} |
| 138 */ |
| 139 scrolledToBottom: function() |
| 140 { |
| 141 return this._scrolledToBottom; |
| 142 }, |
| 143 |
| 144 /** |
136 * @param {boolean} value | 145 * @param {boolean} value |
137 */ | 146 */ |
138 setStickToBottom: function(value) | 147 setStickToBottom: function(value) |
139 { | 148 { |
140 this._stickToBottom = value; | 149 this._stickToBottom = value; |
141 }, | 150 }, |
142 | 151 |
143 /** | 152 /** |
144 * @param {!Event} event | 153 * @param {!Event} event |
145 */ | 154 */ |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 this._firstVisibleIndex = -1; | 375 this._firstVisibleIndex = -1; |
367 this._lastVisibleIndex = -1; | 376 this._lastVisibleIndex = -1; |
368 return; | 377 return; |
369 } | 378 } |
370 | 379 |
371 var selection = window.getSelection(); | 380 var selection = window.getSelection(); |
372 var shouldRestoreSelection = this._updateSelectionModel(selection); | 381 var shouldRestoreSelection = this._updateSelectionModel(selection); |
373 | 382 |
374 var visibleFrom = this.element.scrollTop; | 383 var visibleFrom = this.element.scrollTop; |
375 var visibleHeight = this._visibleHeight(); | 384 var visibleHeight = this._visibleHeight(); |
376 var shouldStickToBottom = this._stickToBottom && this.element.isScrolled
ToBottom(); | 385 this._scrolledToBottom = this.element.isScrolledToBottom(); |
377 var isInvalidating = !this._cumulativeHeights; | 386 var isInvalidating = !this._cumulativeHeights; |
378 | 387 |
379 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len
gth) | 388 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len
gth) |
380 delete this._cumulativeHeights; | 389 delete this._cumulativeHeights; |
381 for (var i = 0; i < this._renderedItems.length; ++i) { | 390 for (var i = 0; i < this._renderedItems.length; ++i) { |
382 this._renderedItems[i].cacheFastHeight(); | 391 this._renderedItems[i].cacheFastHeight(); |
383 // Tolerate 1-pixel error due to double-to-integer rounding errors. | 392 // Tolerate 1-pixel error due to double-to-integer rounding errors. |
384 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this.
_firstVisibleIndex + i) - this._provider.fastHeight(i + this._firstVisibleIndex)
) > 1) | 393 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this.
_firstVisibleIndex + i) - this._provider.fastHeight(i + this._firstVisibleIndex)
) > 1) |
385 delete this._cumulativeHeights; | 394 delete this._cumulativeHeights; |
386 } | 395 } |
387 this._rebuildCumulativeHeightsIfNeeded(); | 396 this._rebuildCumulativeHeightsIfNeeded(); |
388 var oldFirstVisibleIndex = this._firstVisibleIndex; | 397 var oldFirstVisibleIndex = this._firstVisibleIndex; |
389 var oldLastVisibleIndex = this._lastVisibleIndex; | 398 var oldLastVisibleIndex = this._lastVisibleIndex; |
| 399 |
| 400 var shouldStickToBottom = this._stickToBottom && this._scrolledToBottom; |
390 if (shouldStickToBottom) { | 401 if (shouldStickToBottom) { |
391 this._lastVisibleIndex = itemCount - 1; | 402 this._lastVisibleIndex = itemCount - 1; |
392 this._firstVisibleIndex = Math.max(itemCount - Math.ceil(visibleHeig
ht / this._provider.minimumRowHeight()), 0); | 403 this._firstVisibleIndex = Math.max(itemCount - Math.ceil(visibleHeig
ht / this._provider.minimumRowHeight()), 0); |
393 } else { | 404 } else { |
394 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, visibleFrom + 1), 0); | 405 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, visibleFrom + 1), 0); |
395 // Proactively render more rows in case some of them will be collaps
ed without triggering refresh. @see crbug.com/390169 | 406 // Proactively render more rows in case some of them will be collaps
ed without triggering refresh. @see crbug.com/390169 |
396 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible
Height / this._provider.minimumRowHeight()) - 1; | 407 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible
Height / this._provider.minimumRowHeight()) - 1; |
397 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, itemCount
- 1); | 408 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, itemCount
- 1); |
398 } | 409 } |
399 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1]
|| 0; | 410 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1]
|| 0; |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 601 |
591 /** | 602 /** |
592 * @return {number} | 603 * @return {number} |
593 */ | 604 */ |
594 _visibleHeight: function() | 605 _visibleHeight: function() |
595 { | 606 { |
596 // Use offsetHeight instead of clientHeight to avoid being affected by h
orizontal scroll. | 607 // Use offsetHeight instead of clientHeight to avoid being affected by h
orizontal scroll. |
597 return this.element.offsetHeight; | 608 return this.element.offsetHeight; |
598 } | 609 } |
599 } | 610 } |
OLD | NEW |