| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 var localStrings = new LocalStrings(); | 5 var localStrings = new LocalStrings(); |
| 6 | 6 |
| 7 // The total page count of the previewed document regardless of which pages the | 7 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 8 // user has selected. |
| 9 var totalPageCount = -1; | 9 var totalPageCount = -1; |
| 10 | 10 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 */ | 150 */ |
| 151 function updateControlsWithSelectedPrinterCapabilities() { | 151 function updateControlsWithSelectedPrinterCapabilities() { |
| 152 var printerList = $('printer-list'); | 152 var printerList = $('printer-list'); |
| 153 var selectedIndex = printerList.selectedIndex; | 153 var selectedIndex = printerList.selectedIndex; |
| 154 if (selectedIndex < 0) | 154 if (selectedIndex < 0) |
| 155 return; | 155 return; |
| 156 | 156 |
| 157 var selectedValue = printerList.options[selectedIndex].value; | 157 var selectedValue = printerList.options[selectedIndex].value; |
| 158 if (selectedValue == PRINT_TO_PDF) { | 158 if (selectedValue == PRINT_TO_PDF) { |
| 159 updateWithPrinterCapabilities({'disableColorOption': true, | 159 updateWithPrinterCapabilities({'disableColorOption': true, |
| 160 'setColorAsDefault': true}); | 160 'setColorAsDefault': true, |
| 161 'disableCopiesOption': true}); |
| 161 } else if (selectedValue == MANAGE_PRINTERS) { | 162 } else if (selectedValue == MANAGE_PRINTERS) { |
| 162 printerList.selectedIndex = lastSelectedPrinterIndex; | 163 printerList.selectedIndex = lastSelectedPrinterIndex; |
| 163 chrome.send('managePrinters'); | 164 chrome.send('managePrinters'); |
| 164 return; | 165 return; |
| 165 } else { | 166 } else { |
| 166 // This message will call back to 'updateWithPrinterCapabilities' | 167 // This message will call back to 'updateWithPrinterCapabilities' |
| 167 // function. | 168 // function. |
| 168 chrome.send('getPrinterCapabilities', [selectedValue]); | 169 chrome.send('getPrinterCapabilities', [selectedValue]); |
| 169 } | 170 } |
| 170 | 171 |
| 171 lastSelectedPrinterIndex = selectedIndex; | 172 lastSelectedPrinterIndex = selectedIndex; |
| 172 | 173 |
| 173 // Regenerate the preview data based on selected printer settings. | 174 // Regenerate the preview data based on selected printer settings. |
| 174 setDefaultValuesAndRegeneratePreview(); | 175 setDefaultValuesAndRegeneratePreview(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 /** | 178 /** |
| 178 * Updates the controls with printer capabilities information. | 179 * Updates the controls with printer capabilities information. |
| 179 * @param {Object} settingInfo printer setting information. | 180 * @param {Object} settingInfo printer setting information. |
| 180 */ | 181 */ |
| 181 function updateWithPrinterCapabilities(settingInfo) { | 182 function updateWithPrinterCapabilities(settingInfo) { |
| 182 var disableColorOption = settingInfo.disableColorOption; | 183 var disableColorOption = settingInfo.disableColorOption; |
| 184 var disableCopiesOption = settingInfo.disableCopiesOption; |
| 183 var setColorAsDefault = settingInfo.setColorAsDefault; | 185 var setColorAsDefault = settingInfo.setColorAsDefault; |
| 184 var colorOption = $('color'); | 186 var colorOption = $('color'); |
| 185 var bwOption = $('bw'); | 187 var bwOption = $('bw'); |
| 186 | 188 |
| 187 if (disableColorOption) | 189 if (disableCopiesOption) { |
| 188 $('color-options').classList.add("hidden"); | 190 fadeOutElement($('copies-option')); |
| 189 else | 191 $('hr-before-copies').classList.remove('invisible'); |
| 190 $('color-options').classList.remove("hidden"); | 192 } else { |
| 193 fadeInElement($('copies-option')); |
| 194 $('hr-before-copies').classList.add('invisible'); |
| 195 } |
| 196 |
| 197 disableColorOption ? fadeOutElement($('color-options')) : |
| 198 fadeInElement($('color-options')); |
| 191 | 199 |
| 192 if (colorOption.checked != setColorAsDefault) { | 200 if (colorOption.checked != setColorAsDefault) { |
| 193 colorOption.checked = setColorAsDefault; | 201 colorOption.checked = setColorAsDefault; |
| 194 bwOption.checked = !setColorAsDefault; | 202 bwOption.checked = !setColorAsDefault; |
| 195 setColor(colorOption.checked); | 203 setColor(colorOption.checked); |
| 196 } | 204 } |
| 197 } | 205 } |
| 198 | 206 |
| 199 /** | 207 /** |
| 200 * Disables or enables all controls in the options pane except for the cancel | 208 * Disables or enables all controls in the options pane except for the cancel |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 * Called when the PDF plugin loads its document. | 456 * Called when the PDF plugin loads its document. |
| 449 */ | 457 */ |
| 450 function onPDFLoad() { | 458 function onPDFLoad() { |
| 451 if (isLandscape()) | 459 if (isLandscape()) |
| 452 $('pdf-viewer').fitToWidth(); | 460 $('pdf-viewer').fitToWidth(); |
| 453 else | 461 else |
| 454 $('pdf-viewer').fitToHeight(); | 462 $('pdf-viewer').fitToHeight(); |
| 455 | 463 |
| 456 $('dancing-dots').classList.add('invisible'); | 464 $('dancing-dots').classList.add('invisible'); |
| 457 | 465 |
| 458 if (!previewModifiable) { | 466 if (!previewModifiable) |
| 459 $('landscape').disabled = true; | 467 fadeOutElement($('landscape-option')); |
| 460 $('portrait').disabled = true; | |
| 461 } | |
| 462 | 468 |
| 463 updateCopiesButtonsState(); | 469 updateCopiesButtonsState(); |
| 464 } | 470 } |
| 465 | 471 |
| 466 /** | 472 /** |
| 467 * Update the print preview when new preview data is available. | 473 * Update the print preview when new preview data is available. |
| 468 * Create the PDF plugin as needed. | 474 * Create the PDF plugin as needed. |
| 469 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 475 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
| 470 * @param {number} pageCount The expected total pages count. | 476 * @param {number} pageCount The expected total pages count. |
| 471 * @param {string} jobTitle The print job title. | 477 * @param {string} jobTitle The print job title. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 */ | 563 */ |
| 558 function checkCompatiblePluginExists() { | 564 function checkCompatiblePluginExists() { |
| 559 var dummyPlugin = $('dummy-viewer') | 565 var dummyPlugin = $('dummy-viewer') |
| 560 return !!dummyPlugin.onload; | 566 return !!dummyPlugin.onload; |
| 561 } | 567 } |
| 562 | 568 |
| 563 /** | 569 /** |
| 564 * Updates the state of print button depending on the user selection. | 570 * Updates the state of print button depending on the user selection. |
| 565 * The button is enabled only when the following conditions are true. | 571 * The button is enabled only when the following conditions are true. |
| 566 * 1) The selected page ranges are valid. | 572 * 1) The selected page ranges are valid. |
| 567 * 2) The number of copies is valid. | 573 * 2) The number of copies is valid (if applicable). |
| 568 */ | 574 */ |
| 569 function updatePrintButtonState() { | 575 function updatePrintButtonState() { |
| 570 $('print-button').disabled = (!isNumberOfCopiesValid() || | 576 if (getSelectedPrinterName() == PRINT_TO_PDF) { |
| 571 getSelectedPagesValidityLevel() != 1); | 577 $('print-button').disabled = (getSelectedPagesValidityLevel() != 1); |
| 578 } else { |
| 579 $('print-button').disabled = (!isNumberOfCopiesValid() || |
| 580 getSelectedPagesValidityLevel() != 1); |
| 581 } |
| 572 } | 582 } |
| 573 | 583 |
| 574 window.addEventListener('DOMContentLoaded', onLoad); | 584 window.addEventListener('DOMContentLoaded', onLoad); |
| 575 | 585 |
| 576 /** | 586 /** |
| 577 * Listener function that executes whenever a change occurs in the 'copies' | 587 * Listener function that executes whenever a change occurs in the 'copies' |
| 578 * field. | 588 * field. |
| 579 */ | 589 */ |
| 580 function copiesFieldChanged() { | 590 function copiesFieldChanged() { |
| 581 updateCopiesButtonsState(); | 591 updateCopiesButtonsState(); |
| 582 $('collate-option').hidden = getCopies() <= 1; | 592 $('collate-option').hidden = getCopies() <= 1; |
| 583 } | 593 } |
| 584 | 594 |
| 585 /** | 595 /** |
| 586 * Executes whenever a blur event occurs on the 'individual-pages' | 596 * Executes whenever a blur event occurs on the 'individual-pages' |
| 587 * field or when the timer expires. It takes care of | 597 * field or when the timer expires. It takes care of |
| 588 * 1) showing/hiding warnings/suggestions | 598 * 1) showing/hiding warnings/suggestions |
| 589 * 2) updating print button/summary | 599 * 2) updating print button/summary |
| 590 */ | 600 */ |
| 591 function pageRangesFieldChanged() { | 601 function pageRangesFieldChanged() { |
| 592 var currentlySelectedPages = getSelectedPagesSet(); | 602 var currentlySelectedPages = getSelectedPagesSet(); |
| 593 var individualPagesField = $('individual-pages'); | 603 var individualPagesField = $('individual-pages'); |
| 594 var individualPagesHint = $('individual-pages-hint'); | 604 var individualPagesHint = $('individual-pages-hint'); |
| 595 var validityLevel = getSelectedPagesValidityLevel(); | 605 var validityLevel = getSelectedPagesValidityLevel(); |
| 596 | 606 |
| 597 if (validityLevel == 1) { | 607 if (validityLevel == 1) { |
| 598 individualPagesField.classList.remove('invalid'); | 608 individualPagesField.classList.remove('invalid'); |
| 599 hideInvalidHint(individualPagesHint); | 609 fadeOutElement(individualPagesHint); |
| 600 } else { | 610 } else { |
| 601 individualPagesField.classList.add('invalid'); | 611 individualPagesField.classList.add('invalid'); |
| 602 individualPagesHint.classList.remove('suggestion'); | 612 individualPagesHint.classList.remove('suggestion'); |
| 603 individualPagesHint.innerHTML = | 613 individualPagesHint.innerHTML = |
| 604 localStrings.getStringF('pageRangeInstruction', | 614 localStrings.getStringF('pageRangeInstruction', |
| 605 localStrings.getString( | 615 localStrings.getString( |
| 606 'examplePageRangeText')); | 616 'examplePageRangeText')); |
| 607 showInvalidHint(individualPagesHint); | 617 fadeInElement(individualPagesHint); |
| 608 } | 618 } |
| 609 | 619 |
| 610 resetPageRangeFieldTimer(); | 620 resetPageRangeFieldTimer(); |
| 611 updatePrintButtonState(); | 621 updatePrintButtonState(); |
| 612 updatePrintSummary(); | 622 updatePrintSummary(); |
| 613 } | 623 } |
| 614 | 624 |
| 615 /** | 625 /** |
| 616 * Updates the state of the increment/decrement buttons based on the current | 626 * Updates the state of the increment/decrement buttons based on the current |
| 617 * 'copies' value. | 627 * 'copies' value. |
| 618 */ | 628 */ |
| 619 function updateCopiesButtonsState() { | 629 function updateCopiesButtonsState() { |
| 620 var copiesField = $('copies'); | 630 var copiesField = $('copies'); |
| 621 if (!isNumberOfCopiesValid()) { | 631 if (!isNumberOfCopiesValid()) { |
| 622 copiesField.classList.add('invalid'); | 632 copiesField.classList.add('invalid'); |
| 623 $('increment').disabled = false; | 633 $('increment').disabled = false; |
| 624 $('decrement').disabled = false; | 634 $('decrement').disabled = false; |
| 625 showInvalidHint($('copies-hint')); | 635 fadeInElement($('copies-hint')); |
| 626 } | 636 } |
| 627 else { | 637 else { |
| 628 copiesField.classList.remove('invalid'); | 638 copiesField.classList.remove('invalid'); |
| 629 $('increment').disabled = (getCopies() == copiesField.max) ? true : false; | 639 $('increment').disabled = (getCopies() == copiesField.max) ? true : false; |
| 630 $('decrement').disabled = (getCopies() == copiesField.min) ? true : false; | 640 $('decrement').disabled = (getCopies() == copiesField.min) ? true : false; |
| 631 hideInvalidHint($('copies-hint')); | 641 fadeOutElement($('copies-hint')); |
| 632 } | 642 } |
| 633 } | 643 } |
| 634 | 644 |
| 635 /** | 645 /** |
| 636 * Updates the print summary based on the currently selected user options. | 646 * Updates the print summary based on the currently selected user options. |
| 637 * | 647 * |
| 638 */ | 648 */ |
| 639 function updatePrintSummary() { | 649 function updatePrintSummary() { |
| 640 var copies = getCopies(); | 650 var printToPDF = getSelectedPrinterName() == PRINT_TO_PDF; |
| 651 var copies = printToPDF ? 1 : getCopies(); |
| 641 var printSummary = $('print-summary'); | 652 var printSummary = $('print-summary'); |
| 642 | 653 |
| 643 if (!isNumberOfCopiesValid()) { | 654 if (!printToPDF && !isNumberOfCopiesValid()) { |
| 644 printSummary.innerHTML = localStrings.getString('invalidNumberOfCopies'); | 655 printSummary.innerHTML = localStrings.getString('invalidNumberOfCopies'); |
| 645 return; | 656 return; |
| 646 } | 657 } |
| 647 | 658 |
| 648 if (getSelectedPagesValidityLevel() != 1) { | 659 if (getSelectedPagesValidityLevel() != 1) { |
| 649 printSummary.innerHTML = ''; | 660 printSummary.innerHTML = ''; |
| 650 return; | 661 return; |
| 651 } | 662 } |
| 652 | 663 |
| 653 var pageList = getSelectedPagesSet(); | 664 var pageList = getSelectedPagesSet(); |
| 654 var numOfSheets = pageList.length; | 665 var numOfSheets = pageList.length; |
| 655 var sheetsLabel = localStrings.getString('printPreviewSheetsLabelSingular'); | 666 var sheetsLabel = localStrings.getString('printPreviewSheetsLabelSingular'); |
| 656 var numOfPagesText = ''; | 667 var numOfPagesText = ''; |
| 657 var pagesLabel = ''; | 668 var pagesLabel = ''; |
| 658 | 669 |
| 659 if (isTwoSided()) | 670 if (!printToPDF && isTwoSided()) |
| 660 numOfSheets = Math.ceil(numOfSheets / 2); | 671 numOfSheets = Math.ceil(numOfSheets / 2); |
| 661 numOfSheets *= copies; | 672 numOfSheets *= copies; |
| 662 | 673 |
| 663 if (numOfSheets > 1) | 674 if (numOfSheets > 1) |
| 664 sheetsLabel = localStrings.getString('printPreviewSheetsLabelPlural'); | 675 sheetsLabel = localStrings.getString('printPreviewSheetsLabelPlural'); |
| 665 | 676 |
| 666 var html = ''; | 677 var html = ''; |
| 667 if (pageList.length * copies != numOfSheets) { | 678 if (pageList.length * copies != numOfSheets) { |
| 668 numOfPagesText = pageList.length * copies; | 679 numOfPagesText = pageList.length * copies; |
| 669 pagesLabel = localStrings.getString('printPreviewPageLabelPlural'); | 680 pagesLabel = localStrings.getString('printPreviewPageLabelPlural'); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 return; | 719 return; |
| 709 | 720 |
| 710 $('individual-pages').classList.remove('invalid'); | 721 $('individual-pages').classList.remove('invalid'); |
| 711 setDefaultValuesAndRegeneratePreview(); | 722 setDefaultValuesAndRegeneratePreview(); |
| 712 } | 723 } |
| 713 | 724 |
| 714 /** | 725 /** |
| 715 * Sets the default values and sends a request to regenerate preview data. | 726 * Sets the default values and sends a request to regenerate preview data. |
| 716 */ | 727 */ |
| 717 function setDefaultValuesAndRegeneratePreview() { | 728 function setDefaultValuesAndRegeneratePreview() { |
| 718 hideInvalidHint($('individual-pages-hint')); | 729 fadeOutElement($('individual-pages-hint')); |
| 719 totalPageCount = -1; | 730 totalPageCount = -1; |
| 720 previouslySelectedPages.length = 0; | 731 previouslySelectedPages.length = 0; |
| 721 requestPrintPreview(); | 732 requestPrintPreview(); |
| 722 } | 733 } |
| 723 | 734 |
| 724 /** | 735 /** |
| 725 * Returns a list of all pages in the specified ranges. The pages are listed in | 736 * Returns a list of all pages in the specified ranges. The pages are listed in |
| 726 * the order they appear in the 'individual-pages' textbox and duplicates are | 737 * the order they appear in the 'individual-pages' textbox and duplicates are |
| 727 * not eliminated. If the page ranges can't be parsed an empty list is | 738 * not eliminated. If the page ranges can't be parsed an empty list is |
| 728 * returned. | 739 * returned. |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 this.isLandscape = ''; | 950 this.isLandscape = ''; |
| 940 } | 951 } |
| 941 | 952 |
| 942 /** | 953 /** |
| 943 * Takes a snapshot of the print settings. | 954 * Takes a snapshot of the print settings. |
| 944 */ | 955 */ |
| 945 PrintSettings.prototype.save = function() { | 956 PrintSettings.prototype.save = function() { |
| 946 this.deviceName = getSelectedPrinterName(); | 957 this.deviceName = getSelectedPrinterName(); |
| 947 this.isLandscape = isLandscape(); | 958 this.isLandscape = isLandscape(); |
| 948 } | 959 } |
| OLD | NEW |