| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * Component used for searching for a print destination. | 9 * Component used for searching for a print destination. |
| 10 * This is a modal dialog that allows the user to search and select a | 10 * This is a modal dialog that allows the user to search and select a |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 if (!this.getIsVisible()) { | 360 if (!this.getIsVisible()) { |
| 361 return; | 361 return; |
| 362 } | 362 } |
| 363 | 363 |
| 364 var hasCloudList = getIsVisible(this.getChildElement('.cloud-list')); | 364 var hasCloudList = getIsVisible(this.getChildElement('.cloud-list')); |
| 365 var lists = [this.recentList_, this.localList_]; | 365 var lists = [this.recentList_, this.localList_]; |
| 366 if (hasCloudList) { | 366 if (hasCloudList) { |
| 367 lists.push(this.cloudList_); | 367 lists.push(this.cloudList_); |
| 368 } | 368 } |
| 369 | 369 |
| 370 var getListsTotalHeight = function(lists, counts) { |
| 371 return lists.reduce(function(sum, list, index) { |
| 372 return sum + list.getEstimatedHeightInPixels(counts[index]) + |
| 373 DestinationSearch.LIST_BOTTOM_PADDING_; |
| 374 }, 0); |
| 375 }; |
| 376 var getCounts = function(lists, count) { |
| 377 return lists.map(function(list) { return count; }); |
| 378 }; |
| 379 |
| 370 var availableHeight = this.getAvailableListsHeight_(); | 380 var availableHeight = this.getAvailableListsHeight_(); |
| 371 this.getChildElement('.lists').style.maxHeight = availableHeight + 'px'; | 381 var listsEl = this.getChildElement('.lists'); |
| 382 listsEl.style.maxHeight = availableHeight + 'px'; |
| 372 | 383 |
| 373 var maxListLength = lists.reduce(function(prevCount, list) { | 384 var maxListLength = lists.reduce(function(prevCount, list) { |
| 374 return Math.max(prevCount, list.getDestinationsCount()); | 385 return Math.max(prevCount, list.getDestinationsCount()); |
| 375 }, 0); | 386 }, 0); |
| 376 for (var i = 1; i <= maxListLength; i++) { | 387 for (var i = 1; i <= maxListLength; i++) { |
| 377 var listsHeight = lists.reduce(function(sum, list) { | 388 if (getListsTotalHeight(lists, getCounts(lists, i)) > availableHeight) { |
| 378 return sum + list.getEstimatedHeightInPixels(i) + | 389 i--; |
| 379 DestinationSearch.LIST_BOTTOM_PADDING_; | |
| 380 }, 0); | |
| 381 if (listsHeight > availableHeight) { | |
| 382 i -= 1; | |
| 383 break; | 390 break; |
| 384 } | 391 } |
| 385 } | 392 } |
| 393 var counts = getCounts(lists, i); |
| 394 // Fill up the possible n-1 free slots left by the previous loop. |
| 395 if (getListsTotalHeight(lists, counts) < availableHeight) { |
| 396 for (var countIndex = 0; countIndex < counts.length; countIndex++) { |
| 397 counts[countIndex]++; |
| 398 if (getListsTotalHeight(lists, counts) > availableHeight) { |
| 399 counts[countIndex]--; |
| 400 break; |
| 401 } |
| 402 } |
| 403 } |
| 386 | 404 |
| 387 lists.forEach(function(list) { | 405 lists.forEach(function(list, index) { |
| 388 list.updateShortListSize(i); | 406 list.updateShortListSize(counts[index]); |
| 389 }); | 407 }); |
| 390 | 408 |
| 391 // Set height of the list manually so that search filter doesn't change | 409 // Set height of the list manually so that search filter doesn't change |
| 392 // lists height. | 410 // lists height. |
| 393 this.getChildElement('.lists').style.height = | 411 var listsHeight = getListsTotalHeight(lists, counts) + 'px'; |
| 394 lists.reduce(function(sum, list) { | 412 if (listsHeight != listsEl.style.height) { |
| 395 return sum + list.getEstimatedHeightInPixels(i) + | 413 // Try to close account select if there's a possibility it's open now. |
| 396 DestinationSearch.LIST_BOTTOM_PADDING_; | 414 var accountSelectEl = this.getChildElement('.account-select'); |
| 397 }, 0) + 'px'; | 415 if (!accountSelectEl.disabled) { |
| 416 accountSelectEl.disabled = true; |
| 417 accountSelectEl.disabled = false; |
| 418 } |
| 419 listsEl.style.height = listsHeight; |
| 420 } |
| 398 }, | 421 }, |
| 399 | 422 |
| 400 /** | 423 /** |
| 401 * Updates whether the throbbers for the various destination lists should be | 424 * Updates whether the throbbers for the various destination lists should be |
| 402 * shown or hidden. | 425 * shown or hidden. |
| 403 * @private | 426 * @private |
| 404 */ | 427 */ |
| 405 updateThrobbers_: function() { | 428 updateThrobbers_: function() { |
| 406 this.localList_.setIsThrobberVisible( | 429 this.localList_.setIsThrobberVisible( |
| 407 this.destinationStore_.isLocalDestinationSearchInProgress); | 430 this.destinationStore_.isLocalDestinationSearchInProgress); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 onWindowResize_: function() { | 630 onWindowResize_: function() { |
| 608 this.reflowLists_(); | 631 this.reflowLists_(); |
| 609 } | 632 } |
| 610 }; | 633 }; |
| 611 | 634 |
| 612 // Export | 635 // Export |
| 613 return { | 636 return { |
| 614 DestinationSearch: DestinationSearch | 637 DestinationSearch: DestinationSearch |
| 615 }; | 638 }; |
| 616 }); | 639 }); |
| OLD | NEW |