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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 * @return {?WebInspector.ViewportElement} | 81 * @return {?WebInspector.ViewportElement} |
| 82 */ | 82 */ |
| 83 itemElement: function(index) { return null; } | 83 itemElement: function(index) { return null; } |
| 84 } | 84 } |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * @interface | 87 * @interface |
| 88 */ | 88 */ |
| 89 WebInspector.ViewportElement = function() { } | 89 WebInspector.ViewportElement = function() { } |
| 90 WebInspector.ViewportElement.prototype = { | 90 WebInspector.ViewportElement.prototype = { |
| 91 cacheHeight: function() { }, | |
|
aandrey
2014/06/17 19:21:34
maybe willReLayout()?
one may want to cache someth
| |
| 92 | |
| 91 willHide: function() { }, | 93 willHide: function() { }, |
| 92 | 94 |
| 93 wasShown: function() { }, | 95 wasShown: function() { }, |
| 94 | 96 |
| 95 /** | 97 /** |
| 96 * @return {!Element} | 98 * @return {!Element} |
| 97 */ | 99 */ |
| 98 element: function() { }, | 100 element: function() { }, |
| 99 } | 101 } |
| 100 | 102 |
| 101 /** | 103 /** |
| 102 * @constructor | 104 * @constructor |
| 103 * @implements {WebInspector.ViewportElement} | 105 * @implements {WebInspector.ViewportElement} |
| 104 * @param {!Element} element | 106 * @param {!Element} element |
| 105 */ | 107 */ |
| 106 WebInspector.StaticViewportElement = function(element) | 108 WebInspector.StaticViewportElement = function(element) |
| 107 { | 109 { |
| 108 this._element = element; | 110 this._element = element; |
| 109 } | 111 } |
| 110 | 112 |
| 111 WebInspector.StaticViewportElement.prototype = { | 113 WebInspector.StaticViewportElement.prototype = { |
| 114 cacheHeight: function() { }, | |
| 115 | |
| 112 willHide: function() { }, | 116 willHide: function() { }, |
| 113 | 117 |
| 114 wasShown: function() { }, | 118 wasShown: function() { }, |
| 115 | 119 |
| 116 /** | 120 /** |
| 117 * @return {!Element} | 121 * @return {!Element} |
| 118 */ | 122 */ |
| 119 element: function() | 123 element: function() |
| 120 { | 124 { |
| 121 return this._element; | 125 return this._element; |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 }, | 327 }, |
| 324 | 328 |
| 325 refresh: function() | 329 refresh: function() |
| 326 { | 330 { |
| 327 if (!this.element.clientHeight) | 331 if (!this.element.clientHeight) |
| 328 return; // Do nothing for invisible controls. | 332 return; // Do nothing for invisible controls. |
| 329 | 333 |
| 330 var itemCount = this._provider.itemCount(); | 334 var itemCount = this._provider.itemCount(); |
| 331 if (!itemCount) { | 335 if (!itemCount) { |
| 332 for (var i = 0; i < this._renderedItems.length; ++i) | 336 for (var i = 0; i < this._renderedItems.length; ++i) |
| 337 this._renderedItems[i].cacheHeight(); | |
| 338 for (var i = 0; i < this._renderedItems.length; ++i) | |
| 333 this._renderedItems[i].willHide(); | 339 this._renderedItems[i].willHide(); |
| 334 this._renderedItems = []; | 340 this._renderedItems = []; |
| 335 this._contentElement.removeChildren(); | 341 this._contentElement.removeChildren(); |
| 336 this._topGapElement.style.height = "0px"; | 342 this._topGapElement.style.height = "0px"; |
| 337 this._bottomGapElement.style.height = "0px"; | 343 this._bottomGapElement.style.height = "0px"; |
| 338 this._firstVisibleIndex = -1; | 344 this._firstVisibleIndex = -1; |
| 339 this._lastVisibleIndex = -1; | 345 this._lastVisibleIndex = -1; |
| 340 return; | 346 return; |
| 341 } | 347 } |
| 342 | 348 |
| 343 var selection = window.getSelection(); | 349 var selection = window.getSelection(); |
| 344 var shouldRestoreSelection = this._updateSelectionModel(selection); | 350 var shouldRestoreSelection = this._updateSelectionModel(selection); |
| 345 | 351 |
| 346 var visibleFrom = this.element.scrollTop; | 352 var visibleFrom = this.element.scrollTop; |
| 347 var clientHeight = this.element.clientHeight; | 353 var clientHeight = this.element.clientHeight; |
| 348 var shouldStickToBottom = this._stickToBottom && this.element.isScrolled ToBottom(); | 354 var shouldStickToBottom = this._stickToBottom && this.element.isScrolled ToBottom(); |
| 349 | 355 |
| 350 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len gth) | 356 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len gth) |
| 351 delete this._cumulativeHeights; | 357 delete this._cumulativeHeights; |
| 352 for (var i = 0; i < this._renderedItems.length; ++i) { | 358 for (var i = 0; i < this._renderedItems.length; ++i) { |
| 353 this._renderedItems[i].willHide(); | 359 this._renderedItems[i].cacheHeight(); |
| 354 // Tolerate 1-pixel error due to double-to-integer rounding errors. | 360 // Tolerate 1-pixel error due to double-to-integer rounding errors. |
| 355 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) |
| 356 delete this._cumulativeHeights; | 362 delete this._cumulativeHeights; |
| 357 } | 363 } |
| 358 this._rebuildCumulativeHeightsIfNeeded(); | 364 this._rebuildCumulativeHeightsIfNeeded(); |
| 359 if (shouldStickToBottom) { | 365 if (shouldStickToBottom) { |
| 360 this._lastVisibleIndex = itemCount - 1; | 366 this._lastVisibleIndex = itemCount - 1; |
| 361 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); |
| 362 } else { | 368 } else { |
| 363 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); |
| 364 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), itemCount - 1); |
| 365 } | 371 } |
| 366 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0; | 372 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0; |
| 367 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]; |
| 368 | 374 |
| 369 this._topGapElement.style.height = topGapHeight + "px"; | 375 this._topGapElement.style.height = topGapHeight + "px"; |
| 370 this._bottomGapElement.style.height = bottomGapHeight + "px"; | 376 this._bottomGapElement.style.height = bottomGapHeight + "px"; |
| 371 this._topGapElement._active = !!topGapHeight; | 377 this._topGapElement._active = !!topGapHeight; |
| 372 this._bottomGapElement._active = !!bottomGapHeight; | 378 this._bottomGapElement._active = !!bottomGapHeight; |
| 373 | 379 |
| 374 this._contentElement.style.setProperty("height", "10000000px"); | 380 this._contentElement.style.setProperty("height", "10000000px"); |
| 381 for (var i = 0; i < this._renderedItems.length; ++i) | |
| 382 this._renderedItems[i].willHide(); | |
| 375 this._renderedItems = []; | 383 this._renderedItems = []; |
| 376 this._contentElement.removeChildren(); | 384 this._contentElement.removeChildren(); |
| 377 for (var i = this._firstVisibleIndex; i <= this._lastVisibleIndex; ++i) { | 385 for (var i = this._firstVisibleIndex; i <= this._lastVisibleIndex; ++i) { |
| 378 var viewportElement = this._provider.itemElement(i); | 386 var viewportElement = this._provider.itemElement(i); |
| 379 this._contentElement.appendChild(viewportElement.element()); | 387 this._contentElement.appendChild(viewportElement.element()); |
| 380 this._renderedItems.push(viewportElement); | 388 this._renderedItems.push(viewportElement); |
| 381 viewportElement.wasShown(); | 389 viewportElement.wasShown(); |
| 382 } | 390 } |
| 383 | 391 |
| 384 this._contentElement.style.removeProperty("height"); | 392 this._contentElement.style.removeProperty("height"); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 505 | 513 |
| 506 /** | 514 /** |
| 507 * @param {number} index | 515 * @param {number} index |
| 508 */ | 516 */ |
| 509 forceScrollItemToBeLast: function(index) | 517 forceScrollItemToBeLast: function(index) |
| 510 { | 518 { |
| 511 this._rebuildCumulativeHeightsIfNeeded(); | 519 this._rebuildCumulativeHeightsIfNeeded(); |
| 512 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c lientHeight; | 520 this.element.scrollTop = this._cumulativeHeights[index] - this.element.c lientHeight; |
| 513 } | 521 } |
| 514 } | 522 } |
| OLD | NEW |