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

Unified Diff: chrome/browser/resources/print_preview/search/destination_search.js

Issue 259873002: Calculate an expected number of visible destinations more accurately to prevent extra (and unnecess… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/print_preview/search/destination_list.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/print_preview/search/destination_search.js
diff --git a/chrome/browser/resources/print_preview/search/destination_search.js b/chrome/browser/resources/print_preview/search/destination_search.js
index 9d25c35c2c2ff2193f8d2b1126d942a9c46a809f..24deb6d34991ab1f98fb404d66bd3ae2d2a5f170 100644
--- a/chrome/browser/resources/print_preview/search/destination_search.js
+++ b/chrome/browser/resources/print_preview/search/destination_search.js
@@ -367,34 +367,57 @@ cr.define('print_preview', function() {
lists.push(this.cloudList_);
}
+ var getListsTotalHeight = function(lists, counts) {
+ return lists.reduce(function(sum, list, index) {
+ return sum + list.getEstimatedHeightInPixels(counts[index]) +
+ DestinationSearch.LIST_BOTTOM_PADDING_;
+ }, 0);
+ };
+ var getCounts = function(lists, count) {
+ return lists.map(function(list) { return count; });
+ };
+
var availableHeight = this.getAvailableListsHeight_();
- this.getChildElement('.lists').style.maxHeight = availableHeight + 'px';
+ var listsEl = this.getChildElement('.lists');
+ listsEl.style.maxHeight = availableHeight + 'px';
var maxListLength = lists.reduce(function(prevCount, list) {
return Math.max(prevCount, list.getDestinationsCount());
}, 0);
for (var i = 1; i <= maxListLength; i++) {
- var listsHeight = lists.reduce(function(sum, list) {
- return sum + list.getEstimatedHeightInPixels(i) +
- DestinationSearch.LIST_BOTTOM_PADDING_;
- }, 0);
- if (listsHeight > availableHeight) {
- i -= 1;
+ if (getListsTotalHeight(lists, getCounts(lists, i)) > availableHeight) {
+ i--;
break;
}
}
+ var counts = getCounts(lists, i);
+ // Fill up the possible n-1 free slots left by the previous loop.
+ if (getListsTotalHeight(lists, counts) < availableHeight) {
+ for (var countIndex = 0; countIndex < counts.length; countIndex++) {
+ counts[countIndex]++;
+ if (getListsTotalHeight(lists, counts) > availableHeight) {
+ counts[countIndex]--;
+ break;
+ }
+ }
+ }
- lists.forEach(function(list) {
- list.updateShortListSize(i);
+ lists.forEach(function(list, index) {
+ list.updateShortListSize(counts[index]);
});
// Set height of the list manually so that search filter doesn't change
// lists height.
- this.getChildElement('.lists').style.height =
- lists.reduce(function(sum, list) {
- return sum + list.getEstimatedHeightInPixels(i) +
- DestinationSearch.LIST_BOTTOM_PADDING_;
- }, 0) + 'px';
+ var listsHeight = getListsTotalHeight(lists, counts) + 'px';
+ if (listsHeight != listsEl.style.height) {
+ // Try to close account select if there's a possibility it's open now.
+ var accountSelectEl = this.getChildElement('.account-select');
+ if (!accountSelectEl.disabled) {
+ accountSelectEl.disabled = true;
+ accountSelectEl.disabled = false;
+ }
+ listsEl.style.height = listsHeight;
+ }
},
/**
« no previous file with comments | « chrome/browser/resources/print_preview/search/destination_list.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698