| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * @interface | 61 * @interface |
| 62 */ | 62 */ |
| 63 WebInspector.ViewportControl.Provider = function() | 63 WebInspector.ViewportControl.Provider = function() |
| 64 { | 64 { |
| 65 } | 65 } |
| 66 | 66 |
| 67 WebInspector.ViewportControl.Provider.prototype = { | 67 WebInspector.ViewportControl.Provider.prototype = { |
| 68 /** | 68 /** |
| 69 * @param {number} index |
| 70 * @return {number} |
| 71 */ |
| 72 fastHeight: function(index) { return 0; }, |
| 73 |
| 74 /** |
| 69 * @return {number} | 75 * @return {number} |
| 70 */ | 76 */ |
| 71 itemCount: function() { return 0; }, | 77 itemCount: function() { return 0; }, |
| 72 | 78 |
| 73 /** | 79 /** |
| 74 * @param {number} index | 80 * @param {number} index |
| 75 * @return {?WebInspector.ViewportElement} | 81 * @return {?WebInspector.ViewportElement} |
| 76 */ | 82 */ |
| 77 itemElement: function(index) { return null; } | 83 itemElement: function(index) { return null; } |
| 78 } | 84 } |
| 79 | 85 |
| 80 /** | 86 /** |
| 81 * @interface | 87 * @interface |
| 82 */ | 88 */ |
| 83 WebInspector.ViewportElement = function() { } | 89 WebInspector.ViewportElement = function() { } |
| 84 WebInspector.ViewportElement.prototype = { | 90 WebInspector.ViewportElement.prototype = { |
| 85 willHide: function() { }, | 91 willHide: function() { }, |
| 86 | 92 |
| 87 wasShown: function() { }, | 93 wasShown: function() { }, |
| 88 | 94 |
| 89 /** | 95 /** |
| 90 * @return {number} | |
| 91 */ | |
| 92 fastHeight: function() { }, | |
| 93 | |
| 94 /** | |
| 95 * @return {!Element} | 96 * @return {!Element} |
| 96 */ | 97 */ |
| 97 element: function() { }, | 98 element: function() { }, |
| 98 } | 99 } |
| 99 | 100 |
| 100 /** | 101 /** |
| 101 * @constructor | 102 * @constructor |
| 102 * @implements {WebInspector.ViewportElement} | 103 * @implements {WebInspector.ViewportElement} |
| 103 * @param {!Element} element | 104 * @param {!Element} element |
| 104 * @param {number} height | |
| 105 */ | 105 */ |
| 106 WebInspector.StaticViewportElement = function(element, height) | 106 WebInspector.StaticViewportElement = function(element) |
| 107 { | 107 { |
| 108 this._element = element; | 108 this._element = element; |
| 109 this._height = height; | |
| 110 } | 109 } |
| 111 | 110 |
| 112 WebInspector.StaticViewportElement.prototype = { | 111 WebInspector.StaticViewportElement.prototype = { |
| 113 willHide: function() { }, | 112 willHide: function() { }, |
| 114 | 113 |
| 115 wasShown: function() { }, | 114 wasShown: function() { }, |
| 116 | 115 |
| 117 /** | 116 /** |
| 118 * @return {number} | |
| 119 */ | |
| 120 fastHeight: function() | |
| 121 { | |
| 122 return this._height; | |
| 123 }, | |
| 124 | |
| 125 /** | |
| 126 * @return {!Element} | 117 * @return {!Element} |
| 127 */ | 118 */ |
| 128 element: function() | 119 element: function() |
| 129 { | 120 { |
| 130 return this._element; | 121 return this._element; |
| 131 }, | 122 }, |
| 132 } | 123 } |
| 133 | 124 |
| 134 WebInspector.ViewportControl.prototype = { | 125 WebInspector.ViewportControl.prototype = { |
| 135 /** | 126 /** |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 }, | 172 }, |
| 182 | 173 |
| 183 _rebuildCumulativeHeightsIfNeeded: function() | 174 _rebuildCumulativeHeightsIfNeeded: function() |
| 184 { | 175 { |
| 185 if (this._cumulativeHeights) | 176 if (this._cumulativeHeights) |
| 186 return; | 177 return; |
| 187 var itemCount = this._provider.itemCount(); | 178 var itemCount = this._provider.itemCount(); |
| 188 if (!itemCount) | 179 if (!itemCount) |
| 189 return; | 180 return; |
| 190 this._cumulativeHeights = new Int32Array(itemCount); | 181 this._cumulativeHeights = new Int32Array(itemCount); |
| 191 this._cumulativeHeights[0] = this._provider.itemElement(0).fastHeight(); | 182 this._cumulativeHeights[0] = this._provider.fastHeight(0); |
| 192 for (var i = 1; i < itemCount; ++i) | 183 for (var i = 1; i < itemCount; ++i) |
| 193 this._cumulativeHeights[i] = this._cumulativeHeights[i - 1] + this._
provider.itemElement(i).fastHeight(); | 184 this._cumulativeHeights[i] = this._cumulativeHeights[i - 1] + this._
provider.fastHeight(i); |
| 194 }, | 185 }, |
| 195 | 186 |
| 196 /** | 187 /** |
| 197 * @param {number} index | 188 * @param {number} index |
| 198 * @return {number} | 189 * @return {number} |
| 199 */ | 190 */ |
| 200 _cachedItemHeight: function(index) | 191 _cachedItemHeight: function(index) |
| 201 { | 192 { |
| 202 return index === 0 ? this._cumulativeHeights[0] : this._cumulativeHeight
s[index] - this._cumulativeHeights[index - 1]; | 193 return index === 0 ? this._cumulativeHeights[0] : this._cumulativeHeight
s[index] - this._cumulativeHeights[index - 1]; |
| 203 }, | 194 }, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 345 |
| 355 var visibleFrom = this.element.scrollTop; | 346 var visibleFrom = this.element.scrollTop; |
| 356 var clientHeight = this.element.clientHeight; | 347 var clientHeight = this.element.clientHeight; |
| 357 var shouldStickToBottom = this._stickToBottom && this.element.isScrolled
ToBottom(); | 348 var shouldStickToBottom = this._stickToBottom && this.element.isScrolled
ToBottom(); |
| 358 | 349 |
| 359 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len
gth) | 350 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len
gth) |
| 360 delete this._cumulativeHeights; | 351 delete this._cumulativeHeights; |
| 361 for (var i = 0; i < this._renderedItems.length; ++i) { | 352 for (var i = 0; i < this._renderedItems.length; ++i) { |
| 362 this._renderedItems[i].willHide(); | 353 this._renderedItems[i].willHide(); |
| 363 // Tolerate 1-pixel error due to double-to-integer rounding errors. | 354 // Tolerate 1-pixel error due to double-to-integer rounding errors. |
| 364 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this.
_firstVisibleIndex + i) - this._renderedItems[i].fastHeight()) > 1) | 355 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this.
_firstVisibleIndex + i) - this._provider.fastHeight(i + this._firstVisibleIndex)
) > 1) |
| 365 delete this._cumulativeHeights; | 356 delete this._cumulativeHeights; |
| 366 } | 357 } |
| 367 this._rebuildCumulativeHeightsIfNeeded(); | 358 this._rebuildCumulativeHeightsIfNeeded(); |
| 368 if (shouldStickToBottom) { | 359 if (shouldStickToBottom) { |
| 369 this._lastVisibleIndex = itemCount - 1; | 360 this._lastVisibleIndex = itemCount - 1; |
| 370 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, this._cumulativeHeights[this._cumulativeHeights.length -
1] - clientHeight), 0); | 361 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, this._cumulativeHeights[this._cumulativeHeights.length -
1] - clientHeight), 0); |
| 371 } else { | 362 } else { |
| 372 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, visibleFrom), 0); | 363 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t
his._cumulativeHeights, visibleFrom), 0); |
| 373 this._lastVisibleIndex = Math.min(Array.prototype.upperBound.call(th
is._cumulativeHeights, visibleFrom + clientHeight), itemCount - 1); | 364 this._lastVisibleIndex = Math.min(Array.prototype.upperBound.call(th
is._cumulativeHeights, visibleFrom + clientHeight), itemCount - 1); |
| 374 } | 365 } |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 | 505 |
| 515 /** | 506 /** |
| 516 * @param {number} index | 507 * @param {number} index |
| 517 */ | 508 */ |
| 518 forceScrollItemToBeLast: function(index) | 509 forceScrollItemToBeLast: function(index) |
| 519 { | 510 { |
| 520 this._rebuildCumulativeHeightsIfNeeded(); | 511 this._rebuildCumulativeHeightsIfNeeded(); |
| 521 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c
lientHeight; | 512 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c
lientHeight; |
| 522 } | 513 } |
| 523 } | 514 } |
| OLD | NEW |