| 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 // require: cr/ui/print_preview_cloud.js | 5 // require: cr/ui/print_preview_cloud.js |
| 6 | 6 |
| 7 var localStrings = new LocalStrings(); | 7 var localStrings = new LocalStrings(); |
| 8 | 8 |
| 9 // If useCloudPrint is true we attempt to connect to cloud print | 9 // If useCloudPrint is true we attempt to connect to cloud print |
| 10 // and populate the list of printers with cloud print printers. | 10 // and populate the list of printers with cloud print printers. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 showLoadingAnimation(); | 105 showLoadingAnimation(); |
| 106 chrome.send('getDefaultPrinter'); | 106 chrome.send('getDefaultPrinter'); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * Adds event listeners to the settings controls. | 110 * Adds event listeners to the settings controls. |
| 111 */ | 111 */ |
| 112 function addEventListeners() { | 112 function addEventListeners() { |
| 113 // Controls that require preview rendering. | 113 // Controls that require preview rendering. |
| 114 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 114 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
| 115 $('header-footer').onclick = onHeaderFooterChanged; |
| 115 | 116 |
| 116 // Controls that do not require preview rendering. | 117 // Controls that do not require preview rendering. |
| 117 $('color').onclick = function() { setColor(true); }; | 118 $('color').onclick = function() { setColor(true); }; |
| 118 $('bw').onclick = function() { setColor(false); }; | 119 $('bw').onclick = function() { setColor(false); }; |
| 119 } | 120 } |
| 120 | 121 |
| 121 /** | 122 /** |
| 122 * Removes event listeners from the settings controls. | 123 * Removes event listeners from the settings controls. |
| 123 */ | 124 */ |
| 124 function removeEventListeners() { | 125 function removeEventListeners() { |
| 125 if (pageSettings) | 126 if (pageSettings) |
| 126 clearTimeout(pageSettings.timerId_); | 127 clearTimeout(pageSettings.timerId_); |
| 127 | 128 |
| 128 // Controls that require preview rendering | 129 // Controls that require preview rendering |
| 129 $('printer-list').onchange = null; | 130 $('printer-list').onchange = null; |
| 131 $('header-footer').onclick = null; |
| 130 | 132 |
| 131 // Controls that don't require preview rendering. | 133 // Controls that don't require preview rendering. |
| 132 $('color').onclick = null; | 134 $('color').onclick = null; |
| 133 $('bw').onclick = null; | 135 $('bw').onclick = null; |
| 134 } | 136 } |
| 135 | 137 |
| 136 /** | 138 /** |
| 137 * Disables the input elements in the sidebar. | 139 * Disables the input elements in the sidebar. |
| 138 */ | 140 */ |
| 139 function disableInputElementsInSidebar() { | 141 function disableInputElementsInSidebar() { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 * | 316 * |
| 315 * @return {boolean} true if settings are valid, false if not. | 317 * @return {boolean} true if settings are valid, false if not. |
| 316 */ | 318 */ |
| 317 function areSettingsValid() { | 319 function areSettingsValid() { |
| 318 return pageSettings.isPageSelectionValid() && | 320 return pageSettings.isPageSelectionValid() && |
| 319 (copiesSettings.isValid() || | 321 (copiesSettings.isValid() || |
| 320 getSelectedPrinterName() == PRINT_TO_PDF); | 322 getSelectedPrinterName() == PRINT_TO_PDF); |
| 321 } | 323 } |
| 322 | 324 |
| 323 /** | 325 /** |
| 326 * Checks whether the Headers and Footers checkbox is checked or not. |
| 327 * |
| 328 * @return {boolean} true if Headers and Footers are checked. |
| 329 */ |
| 330 function hasHeaderFooter() { |
| 331 return $('header-footer').checked; |
| 332 } |
| 333 |
| 334 /** |
| 324 * Creates an object based on the values in the printer settings. | 335 * Creates an object based on the values in the printer settings. |
| 325 * | 336 * |
| 326 * @return {Object} Object containing print job settings. | 337 * @return {Object} Object containing print job settings. |
| 327 */ | 338 */ |
| 328 function getSettings() { | 339 function getSettings() { |
| 329 var deviceName = getSelectedPrinterName(); | 340 var deviceName = getSelectedPrinterName(); |
| 330 var printToPDF = (deviceName == PRINT_TO_PDF); | 341 var printToPDF = (deviceName == PRINT_TO_PDF); |
| 331 | 342 |
| 332 var settings = | 343 var settings = |
| 333 {'deviceName': deviceName, | 344 {'deviceName': deviceName, |
| 334 'pageRange': pageSettings.selectedPageRanges, | 345 'pageRange': pageSettings.selectedPageRanges, |
| 335 'printAll': pageSettings.allPagesRadioButton.checked, | 346 'printAll': pageSettings.allPagesRadioButton.checked, |
| 336 'duplex': copiesSettings.duplexMode, | 347 'duplex': copiesSettings.duplexMode, |
| 337 'copies': copiesSettings.numberOfCopies, | 348 'copies': copiesSettings.numberOfCopies, |
| 338 'collate': copiesSettings.isCollated(), | 349 'collate': copiesSettings.isCollated(), |
| 339 'landscape': layoutSettings.isLandscape(), | 350 'landscape': layoutSettings.isLandscape(), |
| 340 'color': isColor(), | 351 'color': isColor(), |
| 341 'printToPDF': printToPDF, | 352 'printToPDF': printToPDF, |
| 353 'headerFooter': hasHeaderFooter(), |
| 342 'requestID': 0}; | 354 'requestID': 0}; |
| 343 | 355 |
| 344 var printerList = $('printer-list'); | 356 var printerList = $('printer-list'); |
| 345 var selectedPrinter = printerList.selectedIndex; | 357 var selectedPrinter = printerList.selectedIndex; |
| 346 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { | 358 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { |
| 347 settings['cloudPrintID'] = | 359 settings['cloudPrintID'] = |
| 348 printerList.options[selectedPrinter].value; | 360 printerList.options[selectedPrinter].value; |
| 349 } | 361 } |
| 350 return settings; | 362 return settings; |
| 351 } | 363 } |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 } | 799 } |
| 788 | 800 |
| 789 /** | 801 /** |
| 790 * Called when the PDF plugin loads its document. | 802 * Called when the PDF plugin loads its document. |
| 791 */ | 803 */ |
| 792 function onPDFLoad() { | 804 function onPDFLoad() { |
| 793 $('pdf-viewer').fitToHeight(); | 805 $('pdf-viewer').fitToHeight(); |
| 794 setColor($('color').checked); | 806 setColor($('color').checked); |
| 795 hideLoadingAnimation(); | 807 hideLoadingAnimation(); |
| 796 | 808 |
| 809 if (!previewModifiable) |
| 810 fadeOutElement($('options-option')); |
| 811 |
| 797 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 812 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
| 798 } | 813 } |
| 799 | 814 |
| 800 /** | 815 /** |
| 801 * Update the page count and check the page range. | 816 * Update the page count and check the page range. |
| 802 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 817 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| 803 * @param {number} pageCount The number of pages. | 818 * @param {number} pageCount The number of pages. |
| 804 */ | 819 */ |
| 805 function onDidGetPreviewPageCount(pageCount) { | 820 function onDidGetPreviewPageCount(pageCount) { |
| 806 pageSettings.updateState(pageCount); | 821 pageSettings.updateState(pageCount); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 tempPrintSettings.save(); | 875 tempPrintSettings.save(); |
| 861 | 876 |
| 862 if (printSettings.deviceName != tempPrintSettings.deviceName) { | 877 if (printSettings.deviceName != tempPrintSettings.deviceName) { |
| 863 updateControlsWithSelectedPrinterCapabilities(); | 878 updateControlsWithSelectedPrinterCapabilities(); |
| 864 return true; | 879 return true; |
| 865 } | 880 } |
| 866 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { | 881 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { |
| 867 setDefaultValuesAndRegeneratePreview(); | 882 setDefaultValuesAndRegeneratePreview(); |
| 868 return true; | 883 return true; |
| 869 } | 884 } |
| 885 if (printSettings.hasHeaderFooter != tempPrintSettings.hasHeaderFooter) { |
| 886 requestPrintPreview(); |
| 887 return true; |
| 888 } |
| 870 if (pageSettings.requestPrintPreviewIfNeeded()) | 889 if (pageSettings.requestPrintPreviewIfNeeded()) |
| 871 return true; | 890 return true; |
| 872 | 891 |
| 873 return false; | 892 return false; |
| 874 } | 893 } |
| 875 | 894 |
| 876 /** | 895 /** |
| 877 * Create the PDF plugin or reload the existing one. | 896 * Create the PDF plugin or reload the existing one. |
| 878 * @param {string} previewUid Preview unique identifier. | 897 * @param {string} previewUid Preview unique identifier. |
| 879 */ | 898 */ |
| (...skipping 28 matching lines...) Expand all Loading... |
| 908 function checkCompatiblePluginExists() { | 927 function checkCompatiblePluginExists() { |
| 909 var dummyPlugin = $('dummy-viewer') | 928 var dummyPlugin = $('dummy-viewer') |
| 910 return (dummyPlugin.onload && | 929 return (dummyPlugin.onload && |
| 911 dummyPlugin.goToPage && | 930 dummyPlugin.goToPage && |
| 912 dummyPlugin.removePrintButton); | 931 dummyPlugin.removePrintButton); |
| 913 } | 932 } |
| 914 | 933 |
| 915 window.addEventListener('DOMContentLoaded', onLoad); | 934 window.addEventListener('DOMContentLoaded', onLoad); |
| 916 | 935 |
| 917 /** | 936 /** |
| 937 * When the user selects or de-selects the headers and footers option then a |
| 938 * new preview is requested. |
| 939 */ |
| 940 function onHeaderFooterChanged() { |
| 941 requestPrintPreview(); |
| 942 } |
| 943 |
| 944 /** |
| 918 * Sets the default values and sends a request to regenerate preview data. | 945 * Sets the default values and sends a request to regenerate preview data. |
| 919 */ | 946 */ |
| 920 function setDefaultValuesAndRegeneratePreview() { | 947 function setDefaultValuesAndRegeneratePreview() { |
| 921 pageSettings.resetState(); | 948 pageSettings.resetState(); |
| 922 requestPrintPreview(); | 949 requestPrintPreview(); |
| 923 } | 950 } |
| 924 | 951 |
| 925 /** | 952 /** |
| 926 * Class that represents the state of the print settings. | 953 * Class that represents the state of the print settings. |
| 927 */ | 954 */ |
| 928 function PrintSettings() { | 955 function PrintSettings() { |
| 929 this.deviceName = ''; | 956 this.deviceName = ''; |
| 930 this.isLandscape = ''; | 957 this.isLandscape = ''; |
| 958 this.hasHeaderFooter = ''; |
| 931 } | 959 } |
| 932 | 960 |
| 933 /** | 961 /** |
| 934 * Takes a snapshot of the print settings. | 962 * Takes a snapshot of the print settings. |
| 935 */ | 963 */ |
| 936 PrintSettings.prototype.save = function() { | 964 PrintSettings.prototype.save = function() { |
| 937 this.deviceName = getSelectedPrinterName(); | 965 this.deviceName = getSelectedPrinterName(); |
| 938 this.isLandscape = layoutSettings.isLandscape(); | 966 this.isLandscape = layoutSettings.isLandscape(); |
| 967 this.hasHeaderFooter = hasHeaderFooter(); |
| 939 } | 968 } |
| 940 | 969 |
| OLD | NEW |