Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/ViewportControl.js

Issue 1688053004: DevTools: [Console] fix viewport stick-to-bottom behavior (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/console/console-viewport-stick-to-bottom-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 371 }
372 372
373 selection.setBaseAndExtent(anchorElement, anchorOffset, headElement, hea dOffset); 373 selection.setBaseAndExtent(anchorElement, anchorOffset, headElement, hea dOffset);
374 }, 374 },
375 375
376 refresh: function() 376 refresh: function()
377 { 377 {
378 if (!this._visibleHeight()) 378 if (!this._visibleHeight())
379 return; // Do nothing for invisible controls. 379 return; // Do nothing for invisible controls.
380 380
381 var itemCount = this._provider.itemCount(); 381 if (!this._provider.itemCount()) {
382 if (!itemCount) {
383 for (var i = 0; i < this._renderedItems.length; ++i) 382 for (var i = 0; i < this._renderedItems.length; ++i)
384 this._renderedItems[i].willHide(); 383 this._renderedItems[i].willHide();
385 this._renderedItems = []; 384 this._renderedItems = [];
386 this._contentElement.removeChildren(); 385 this._contentElement.removeChildren();
387 this._topGapElement.style.height = "0px"; 386 this._topGapElement.style.height = "0px";
388 this._bottomGapElement.style.height = "0px"; 387 this._bottomGapElement.style.height = "0px";
389 this._firstVisibleIndex = -1; 388 this._firstVisibleIndex = -1;
390 this._lastVisibleIndex = -1; 389 this._lastVisibleIndex = -1;
391 return; 390 return;
392 } 391 }
393 392
394 var selection = this.element.getComponentSelection(); 393 var selection = this.element.getComponentSelection();
395 var shouldRestoreSelection = this._updateSelectionModel(selection); 394 var shouldRestoreSelection = this._updateSelectionModel(selection);
396 395
397 var visibleFrom = this.element.scrollTop; 396 var visibleFrom = this.element.scrollTop;
398 var visibleHeight = this._visibleHeight(); 397 var visibleHeight = this._visibleHeight();
399 this._scrolledToBottom = this.element.isScrolledToBottom(); 398 this._scrolledToBottom = this.element.isScrolledToBottom();
400 var isInvalidating = !this._cumulativeHeights; 399 var isInvalidating = !this._cumulativeHeights;
401 400
402 if (this._cumulativeHeights && itemCount !== this._cumulativeHeights.len gth)
403 delete this._cumulativeHeights;
404 for (var i = 0; i < this._renderedItems.length; ++i) { 401 for (var i = 0; i < this._renderedItems.length; ++i) {
405 // Tolerate 1-pixel error due to double-to-integer rounding errors. 402 // Tolerate 1-pixel error due to double-to-integer rounding errors.
406 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this. _firstVisibleIndex + i) - this._renderedItems[i].element().offsetHeight) > 1) 403 if (this._cumulativeHeights && Math.abs(this._cachedItemHeight(this. _firstVisibleIndex + i) - this._renderedItems[i].element().offsetHeight) > 1)
407 delete this._cumulativeHeights; 404 delete this._cumulativeHeights;
408 } 405 }
409 this._rebuildCumulativeHeightsIfNeeded(); 406 this._rebuildCumulativeHeightsIfNeeded();
407 var itemCount = this._cumulativeHeights.length;
410 var oldFirstVisibleIndex = this._firstVisibleIndex; 408 var oldFirstVisibleIndex = this._firstVisibleIndex;
411 var oldLastVisibleIndex = this._lastVisibleIndex; 409 var oldLastVisibleIndex = this._lastVisibleIndex;
412 410
413 var shouldStickToBottom = this._stickToBottom && this._scrolledToBottom; 411 var shouldStickToBottom = isInvalidating && this._stickToBottom && this. _scrolledToBottom;
412
414 if (shouldStickToBottom) { 413 if (shouldStickToBottom) {
415 this._lastVisibleIndex = itemCount - 1; 414 this._lastVisibleIndex = itemCount - 1;
416 this._firstVisibleIndex = Math.max(itemCount - Math.ceil(visibleHeig ht / this._provider.minimumRowHeight()), 0); 415 this._firstVisibleIndex = Math.max(itemCount - Math.ceil(visibleHeig ht / this._provider.minimumRowHeight()), 0);
417 } else { 416 } else {
418 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t his._cumulativeHeights, visibleFrom + 1), 0); 417 this._firstVisibleIndex = Math.max(Array.prototype.lowerBound.call(t his._cumulativeHeights, visibleFrom + 1), 0);
419 // Proactively render more rows in case some of them will be collaps ed without triggering refresh. @see crbug.com/390169 418 // Proactively render more rows in case some of them will be collaps ed without triggering refresh. @see crbug.com/390169
420 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible Height / this._provider.minimumRowHeight()) - 1; 419 this._lastVisibleIndex = this._firstVisibleIndex + Math.ceil(visible Height / this._provider.minimumRowHeight()) - 1;
421 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, itemCount - 1); 420 this._lastVisibleIndex = Math.min(this._lastVisibleIndex, itemCount - 1);
422 } 421 }
423 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0; 422 var topGapHeight = this._cumulativeHeights[this._firstVisibleIndex - 1] || 0;
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 629
631 /** 630 /**
632 * @return {number} 631 * @return {number}
633 */ 632 */
634 _visibleHeight: function() 633 _visibleHeight: function()
635 { 634 {
636 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll. 635 // Use offsetHeight instead of clientHeight to avoid being affected by h orizontal scroll.
637 return this.element.offsetHeight; 636 return this.element.offsetHeight;
638 } 637 }
639 } 638 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/console/console-viewport-stick-to-bottom-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698