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

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

Issue 7348010: Added Header and Footer support using Skia (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Rebased and moved PrintHeaderAndFooter to private member function. Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 showLoadingAnimation(); 109 showLoadingAnimation();
110 chrome.send('getDefaultPrinter'); 110 chrome.send('getDefaultPrinter');
111 } 111 }
112 112
113 /** 113 /**
114 * Adds event listeners to the settings controls. 114 * Adds event listeners to the settings controls.
115 */ 115 */
116 function addEventListeners() { 116 function addEventListeners() {
117 // Controls that require preview rendering. 117 // Controls that require preview rendering.
118 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 118 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
119 $('header-footer').onclick = onHeaderFooterChanged;
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 133
132 /** 134 /**
133 * Disables the input elements in the sidebar. 135 * Disables the input elements in the sidebar.
134 */ 136 */
135 function disableInputElementsInSidebar() { 137 function disableInputElementsInSidebar() {
136 var els = $('sidebar').querySelectorAll('input, button, select'); 138 var els = $('sidebar').querySelectorAll('input, button, select');
137 for (var i = 0; i < els.length; i++) 139 for (var i = 0; i < els.length; i++)
138 els[i].disabled = true; 140 els[i].disabled = true;
139 } 141 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 * 288 *
287 * @return {boolean} true if settings are valid, false if not. 289 * @return {boolean} true if settings are valid, false if not.
288 */ 290 */
289 function areSettingsValid() { 291 function areSettingsValid() {
290 return pageSettings.isPageSelectionValid() && 292 return pageSettings.isPageSelectionValid() &&
291 (copiesSettings.isValid() || 293 (copiesSettings.isValid() ||
292 getSelectedPrinterName() == PRINT_TO_PDF); 294 getSelectedPrinterName() == PRINT_TO_PDF);
293 } 295 }
294 296
295 /** 297 /**
298 * Checks whether the Headers and Footers checkbox is checked or not.
299 *
300 * @return {boolean} true if Headers and Footers are checked.
301 */
302 function hasHeaderFooter() {
303 return $('header-footer').checked;
304 }
305
306 /**
296 * Creates an object based on the values in the printer settings. 307 * Creates an object based on the values in the printer settings.
297 * 308 *
298 * @return {Object} Object containing print job settings. 309 * @return {Object} Object containing print job settings.
299 */ 310 */
300 function getSettings() { 311 function getSettings() {
301 var deviceName = getSelectedPrinterName(); 312 var deviceName = getSelectedPrinterName();
302 var printToPDF = (deviceName == PRINT_TO_PDF); 313 var printToPDF = (deviceName == PRINT_TO_PDF);
303 314
304 var settings = 315 var settings =
305 {'deviceName': deviceName, 316 {'deviceName': deviceName,
306 'pageRange': pageSettings.selectedPageRanges, 317 'pageRange': pageSettings.selectedPageRanges,
307 'printAll': pageSettings.allPagesRadioButton.checked, 318 'printAll': pageSettings.allPagesRadioButton.checked,
308 'duplex': copiesSettings.duplexMode, 319 'duplex': copiesSettings.duplexMode,
309 'copies': copiesSettings.numberOfCopies, 320 'copies': copiesSettings.numberOfCopies,
310 'collate': copiesSettings.isCollated(), 321 'collate': copiesSettings.isCollated(),
311 'landscape': layoutSettings.isLandscape(), 322 'landscape': layoutSettings.isLandscape(),
312 'color': colorSettings.isColor(), 323 'color': colorSettings.isColor(),
313 'printToPDF': printToPDF, 324 'printToPDF': printToPDF,
325 'headerFooter': hasHeaderFooter(),
314 'requestID': 0}; 326 'requestID': 0};
315 327
316 var printerList = $('printer-list'); 328 var printerList = $('printer-list');
317 var selectedPrinter = printerList.selectedIndex; 329 var selectedPrinter = printerList.selectedIndex;
318 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { 330 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) {
319 settings['cloudPrintID'] = 331 settings['cloudPrintID'] =
320 printerList.options[selectedPrinter].value; 332 printerList.options[selectedPrinter].value;
321 } 333 }
322 return settings; 334 return settings;
323 } 335 }
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 782
771 /** 783 /**
772 * Called when the PDF plugin loads its document. 784 * Called when the PDF plugin loads its document.
773 */ 785 */
774 function onPDFLoad() { 786 function onPDFLoad() {
775 if (previewModifiable) { 787 if (previewModifiable) {
776 setPluginPreviewPageCount(); 788 setPluginPreviewPageCount();
777 cr.dispatchSimpleEvent(document, 'updateSummary'); 789 cr.dispatchSimpleEvent(document, 'updateSummary');
778 } 790 }
779 $('pdf-viewer').fitToHeight(); 791 $('pdf-viewer').fitToHeight();
792 if (!previewModifiable)
793 fadeOutElement($('options-option'));
kmadhusu 2011/07/28 20:31:20 Can you add line #793 in the else block of line #7
Aayush Kumar 2011/07/29 00:21:46 Done.
780 cr.dispatchSimpleEvent(document, 'PDFLoaded'); 794 cr.dispatchSimpleEvent(document, 'PDFLoaded');
781 hideLoadingAnimation(); 795 hideLoadingAnimation();
782 } 796 }
783 797
784 function setPluginPreviewPageCount() { 798 function setPluginPreviewPageCount() {
785 $('pdf-viewer').printPreviewPageCount( 799 $('pdf-viewer').printPreviewPageCount(
786 pageSettings.previouslySelectedPages.length); 800 pageSettings.previouslySelectedPages.length);
787 } 801 }
788 802
789 /** 803 /**
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 tempPrintSettings.save(); 898 tempPrintSettings.save();
885 899
886 if (printSettings.deviceName != tempPrintSettings.deviceName) { 900 if (printSettings.deviceName != tempPrintSettings.deviceName) {
887 updateControlsWithSelectedPrinterCapabilities(); 901 updateControlsWithSelectedPrinterCapabilities();
888 return true; 902 return true;
889 } 903 }
890 if (printSettings.isLandscape != tempPrintSettings.isLandscape) { 904 if (printSettings.isLandscape != tempPrintSettings.isLandscape) {
891 setDefaultValuesAndRegeneratePreview(); 905 setDefaultValuesAndRegeneratePreview();
892 return true; 906 return true;
893 } 907 }
908 if (printSettings.hasHeaderFooter != tempPrintSettings.hasHeaderFooter) {
909 requestPrintPreview();
910 return true;
911 }
894 if (pageSettings.requestPrintPreviewIfNeeded()) 912 if (pageSettings.requestPrintPreviewIfNeeded())
895 return true; 913 return true;
896 914
897 return false; 915 return false;
898 } 916 }
899 917
900 /** 918 /**
901 * Create the PDF plugin or reload the existing one. 919 * Create the PDF plugin or reload the existing one.
902 * @param {string} previewUid Preview unique identifier. 920 * @param {string} previewUid Preview unique identifier.
903 */ 921 */
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 return !!(dummyPlugin.onload && 954 return !!(dummyPlugin.onload &&
937 dummyPlugin.goToPage && 955 dummyPlugin.goToPage &&
938 dummyPlugin.removePrintButton && 956 dummyPlugin.removePrintButton &&
939 dummyPlugin.loadPreviewPage && 957 dummyPlugin.loadPreviewPage &&
940 dummyPlugin.printPreviewPageCount); 958 dummyPlugin.printPreviewPageCount);
941 } 959 }
942 960
943 window.addEventListener('DOMContentLoaded', onLoad); 961 window.addEventListener('DOMContentLoaded', onLoad);
944 962
945 /** 963 /**
964 * When the user selects or de-selects the headers and footers option then a
965 * new preview is requested.
966 */
967 function onHeaderFooterChanged() {
968 requestPrintPreview();
969 }
970
971 /**
946 * Sets the default values and sends a request to regenerate preview data. 972 * Sets the default values and sends a request to regenerate preview data.
947 */ 973 */
948 function setDefaultValuesAndRegeneratePreview() { 974 function setDefaultValuesAndRegeneratePreview() {
949 pageSettings.resetState(); 975 pageSettings.resetState();
950 requestPrintPreview(); 976 requestPrintPreview();
951 } 977 }
952 978
953 /** 979 /**
954 * Class that represents the state of the print settings. 980 * Class that represents the state of the print settings.
955 */ 981 */
956 function PrintSettings() { 982 function PrintSettings() {
957 this.deviceName = ''; 983 this.deviceName = '';
958 this.isLandscape = ''; 984 this.isLandscape = '';
985 this.hasHeaderFooter = '';
959 } 986 }
960 987
961 /** 988 /**
962 * Takes a snapshot of the print settings. 989 * Takes a snapshot of the print settings.
963 */ 990 */
964 PrintSettings.prototype.save = function() { 991 PrintSettings.prototype.save = function() {
965 this.deviceName = getSelectedPrinterName(); 992 this.deviceName = getSelectedPrinterName();
966 this.isLandscape = layoutSettings.isLandscape(); 993 this.isLandscape = layoutSettings.isLandscape();
994 this.hasHeaderFooter = hasHeaderFooter();
967 } 995 }
968 996
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698