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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 showLoadingAnimation(); | 94 showLoadingAnimation(); |
95 chrome.send('getDefaultPrinter'); | 95 chrome.send('getDefaultPrinter'); |
96 } | 96 } |
97 | 97 |
98 /** | 98 /** |
99 * Adds event listeners to the settings controls. | 99 * Adds event listeners to the settings controls. |
100 */ | 100 */ |
101 function addEventListeners() { | 101 function addEventListeners() { |
102 // Controls that require preview rendering. | 102 // Controls that require preview rendering. |
103 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 103 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
| 104 $('header-footer').onclick = onHeaderFooterChanged; |
104 | 105 |
105 // Controls that do not require preview rendering. | 106 // Controls that do not require preview rendering. |
106 $('color').onclick = function() { setColor(true); }; | 107 $('color').onclick = function() { setColor(true); }; |
107 $('bw').onclick = function() { setColor(false); }; | 108 $('bw').onclick = function() { setColor(false); }; |
108 } | 109 } |
109 | 110 |
110 /** | 111 /** |
111 * Removes event listeners from the settings controls. | 112 * Removes event listeners from the settings controls. |
112 */ | 113 */ |
113 function removeEventListeners() { | 114 function removeEventListeners() { |
114 if (pageSettings) | 115 if (pageSettings) |
115 clearTimeout(pageSettings.timerId_); | 116 clearTimeout(pageSettings.timerId_); |
116 | 117 |
117 // Controls that require preview rendering | 118 // Controls that require preview rendering |
118 $('printer-list').onchange = null; | 119 $('printer-list').onchange = null; |
| 120 $('header-footer').onclick = null; |
119 | 121 |
120 // Controls that don't require preview rendering. | 122 // Controls that don't require preview rendering. |
121 $('color').onclick = null; | 123 $('color').onclick = null; |
122 $('bw').onclick = null; | 124 $('bw').onclick = null; |
123 } | 125 } |
124 | 126 |
125 /** | 127 /** |
126 * Disables the input elements in the sidebar. | 128 * Disables the input elements in the sidebar. |
127 */ | 129 */ |
128 function disableInputElementsInSidebar() { | 130 function disableInputElementsInSidebar() { |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 /** | 298 /** |
297 * Checks whether the preview color setting is set to 'color' or not. | 299 * Checks whether the preview color setting is set to 'color' or not. |
298 * | 300 * |
299 * @return {boolean} true if color is 'color'. | 301 * @return {boolean} true if color is 'color'. |
300 */ | 302 */ |
301 function isColor() { | 303 function isColor() { |
302 return $('color').checked; | 304 return $('color').checked; |
303 } | 305 } |
304 | 306 |
305 /** | 307 /** |
| 308 * Checks whether the Headers and Footers checkbox is checked or not. |
| 309 * |
| 310 * @return {boolean} true if Headers and Footers are checked. |
| 311 */ |
| 312 function hasHeaderFooter() { |
| 313 return $('header-footer').checked; |
| 314 } |
| 315 |
| 316 /** |
306 * Creates an object based on the values in the printer settings. | 317 * Creates an object based on the values in the printer settings. |
307 * | 318 * |
308 * @return {Object} Object containing print job settings. | 319 * @return {Object} Object containing print job settings. |
309 */ | 320 */ |
310 function getSettings() { | 321 function getSettings() { |
311 var deviceName = getSelectedPrinterName(); | 322 var deviceName = getSelectedPrinterName(); |
312 var printToPDF = (deviceName == PRINT_TO_PDF); | 323 var printToPDF = (deviceName == PRINT_TO_PDF); |
313 | 324 |
314 var settings = | 325 var settings = |
315 {'deviceName': deviceName, | 326 {'deviceName': deviceName, |
316 'pageRange': pageSettings.selectedPageRanges, | 327 'pageRange': pageSettings.selectedPageRanges, |
317 'printAll': pageSettings.allPagesRadioButton.checked, | 328 'printAll': pageSettings.allPagesRadioButton.checked, |
318 'duplex': copiesSettings.duplexMode, | 329 'duplex': copiesSettings.duplexMode, |
319 'copies': copiesSettings.numberOfCopies, | 330 'copies': copiesSettings.numberOfCopies, |
320 'collate': copiesSettings.isCollated(), | 331 'collate': copiesSettings.isCollated(), |
321 'landscape': layoutSettings.isLandscape(), | 332 'landscape': layoutSettings.isLandscape(), |
322 'color': isColor(), | 333 'color': isColor(), |
323 'printToPDF': printToPDF, | 334 'printToPDF': printToPDF, |
| 335 'headerFooter': hasHeaderFooter(), |
324 'requestID': 0}; | 336 'requestID': 0}; |
325 | 337 |
326 var printerList = $('printer-list'); | 338 var printerList = $('printer-list'); |
327 var selectedPrinter = printerList.selectedIndex; | 339 var selectedPrinter = printerList.selectedIndex; |
328 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { | 340 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { |
329 settings['cloudPrintID'] = | 341 settings['cloudPrintID'] = |
330 printerList.options[selectedPrinter].value; | 342 printerList.options[selectedPrinter].value; |
331 } | 343 } |
332 return settings; | 344 return settings; |
333 } | 345 } |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 } | 745 } |
734 | 746 |
735 /** | 747 /** |
736 * Called when the PDF plugin loads its document. | 748 * Called when the PDF plugin loads its document. |
737 */ | 749 */ |
738 function onPDFLoad() { | 750 function onPDFLoad() { |
739 $('pdf-viewer').fitToHeight(); | 751 $('pdf-viewer').fitToHeight(); |
740 setColor($('color').checked); | 752 setColor($('color').checked); |
741 hideLoadingAnimation(); | 753 hideLoadingAnimation(); |
742 | 754 |
| 755 if (!previewModifiable) { |
| 756 fadeOutElement($('options-option')); |
| 757 } |
743 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 758 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
744 } | 759 } |
745 | 760 |
746 /** | 761 /** |
747 * Update the page count and check the page range. | 762 * Update the page count and check the page range. |
748 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 763 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
749 * @param {number} pageCount The number of pages. | 764 * @param {number} pageCount The number of pages. |
750 */ | 765 */ |
751 function onDidGetPreviewPageCount(pageCount) { | 766 function onDidGetPreviewPageCount(pageCount) { |
752 pageSettings.updateState(pageCount); | 767 pageSettings.updateState(pageCount); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 tempPrintSettings.save(); | 821 tempPrintSettings.save(); |
807 | 822 |
808 if (printSettings.deviceName != tempPrintSettings.deviceName) { | 823 if (printSettings.deviceName != tempPrintSettings.deviceName) { |
809 updateControlsWithSelectedPrinterCapabilities(); | 824 updateControlsWithSelectedPrinterCapabilities(); |
810 return true; | 825 return true; |
811 } | 826 } |
812 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { | 827 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { |
813 setDefaultValuesAndRegeneratePreview(); | 828 setDefaultValuesAndRegeneratePreview(); |
814 return true; | 829 return true; |
815 } | 830 } |
| 831 if (printSettings.hasHeaderFooter != tempPrintSettings.hasHeaderFooter) { |
| 832 requestPrintPreview(); |
| 833 return true; |
| 834 } |
816 if (pageSettings.requestPrintPreviewIfNeeded()) | 835 if (pageSettings.requestPrintPreviewIfNeeded()) |
817 return true; | 836 return true; |
818 | 837 |
819 return false; | 838 return false; |
820 } | 839 } |
821 | 840 |
822 /** | 841 /** |
823 * Create the PDF plugin or reload the existing one. | 842 * Create the PDF plugin or reload the existing one. |
824 * @param {string} previewUid Preview unique identifier. | 843 * @param {string} previewUid Preview unique identifier. |
825 */ | 844 */ |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 html = localStrings.getStringF('printPreviewSummaryFormatShort', | 944 html = localStrings.getStringF('printPreviewSummaryFormatShort', |
926 '<b>' + numOfSheets + '</b>', | 945 '<b>' + numOfSheets + '</b>', |
927 '<b>' + summaryLabel + '</b>'); | 946 '<b>' + summaryLabel + '</b>'); |
928 | 947 |
929 // Removing extra spaces from within the string. | 948 // Removing extra spaces from within the string. |
930 html = html.replace(/\s{2,}/g, ' '); | 949 html = html.replace(/\s{2,}/g, ' '); |
931 printSummary.innerHTML = html; | 950 printSummary.innerHTML = html; |
932 } | 951 } |
933 | 952 |
934 /** | 953 /** |
| 954 * When the user selects or de-selects the headers and footers option then we |
| 955 * regenerate the preview pdf. |
| 956 */ |
| 957 function onHeaderFooterChanged() { |
| 958 requestPrintPreview(); |
| 959 } |
| 960 |
| 961 /** |
935 * Sets the default values and sends a request to regenerate preview data. | 962 * Sets the default values and sends a request to regenerate preview data. |
936 */ | 963 */ |
937 function setDefaultValuesAndRegeneratePreview() { | 964 function setDefaultValuesAndRegeneratePreview() { |
938 pageSettings.resetState(); | 965 pageSettings.resetState(); |
939 requestPrintPreview(); | 966 requestPrintPreview(); |
940 } | 967 } |
941 | 968 |
942 /** | 969 /** |
943 * Class that represents the state of the print settings. | 970 * Class that represents the state of the print settings. |
944 */ | 971 */ |
945 function PrintSettings() { | 972 function PrintSettings() { |
946 this.deviceName = ''; | 973 this.deviceName = ''; |
947 this.isLandscape = ''; | 974 this.isLandscape = ''; |
| 975 this.hasHeaderFooter = ''; |
948 } | 976 } |
949 | 977 |
950 /** | 978 /** |
951 * Takes a snapshot of the print settings. | 979 * Takes a snapshot of the print settings. |
952 */ | 980 */ |
953 PrintSettings.prototype.save = function() { | 981 PrintSettings.prototype.save = function() { |
954 this.deviceName = getSelectedPrinterName(); | 982 this.deviceName = getSelectedPrinterName(); |
955 this.isLandscape = layoutSettings.isLandscape(); | 983 this.isLandscape = layoutSettings.isLandscape(); |
| 984 this.hasHeaderFooter = hasHeaderFooter(); |
956 } | 985 } |
957 | 986 |
OLD | NEW |