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

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: Added Headers and Footers support - New Snapshot Uploaded Created 9 years, 5 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 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; 9 var totalPageCount;
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // Controls that require preview rendering. 114 // Controls that require preview rendering.
115 $('all-pages').onclick = onPageSelectionMayHaveChanged; 115 $('all-pages').onclick = onPageSelectionMayHaveChanged;
116 $('print-pages').onclick = handleIndividualPagesCheckbox; 116 $('print-pages').onclick = handleIndividualPagesCheckbox;
117 var individualPages = $('individual-pages'); 117 var individualPages = $('individual-pages');
118 individualPages.onblur = onIndividualPagesBlur; 118 individualPages.onblur = onIndividualPagesBlur;
119 individualPages.onfocus = onIndividualPagesFocus; 119 individualPages.onfocus = onIndividualPagesFocus;
120 individualPages.oninput = onIndividualPagesInput; 120 individualPages.oninput = onIndividualPagesInput;
121 $('landscape').onclick = onLayoutModeToggle; 121 $('landscape').onclick = onLayoutModeToggle;
122 $('portrait').onclick = onLayoutModeToggle; 122 $('portrait').onclick = onLayoutModeToggle;
123 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 123 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
124 $('header-footer').onclick = onHeaderFooterChanged;
124 125
125 // Controls that do not require preview rendering. 126 // Controls that do not require preview rendering.
126 $('color').onclick = function() { setColor(true); }; 127 $('color').onclick = function() { setColor(true); };
127 $('bw').onclick = function() { setColor(false); }; 128 $('bw').onclick = function() { setColor(false); };
128 } 129 }
129 130
130 /** 131 /**
131 * Handles the blur event for the |individual-pages| element. Un-checks the 132 * Handles the blur event for the |individual-pages| element. Un-checks the
132 * associated radio control if the input field is empty. 133 * associated radio control if the input field is empty.
133 */ 134 */
(...skipping 29 matching lines...) Expand all
163 * Removes event listeners from the settings controls. 164 * Removes event listeners from the settings controls.
164 */ 165 */
165 function removeEventListeners() { 166 function removeEventListeners() {
166 clearTimeout(timerId); 167 clearTimeout(timerId);
167 setDefaultHandlersForPagesAndCopiesControls(); 168 setDefaultHandlersForPagesAndCopiesControls();
168 169
169 // Controls that require preview rendering 170 // Controls that require preview rendering
170 $('landscape').onclick = null; 171 $('landscape').onclick = null;
171 $('portrait').onclick = null; 172 $('portrait').onclick = null;
172 $('printer-list').onchange = null; 173 $('printer-list').onchange = null;
174 $('header-footer').onclick = null;
173 175
174 // Controls that don't require preview rendering. 176 // Controls that don't require preview rendering.
175 $('color').onclick = null; 177 $('color').onclick = null;
176 $('bw').onclick = null; 178 $('bw').onclick = null;
177 } 179 }
178 180
179 /** 181 /**
180 * Disables the input elements in the sidebar. 182 * Disables the input elements in the sidebar.
181 */ 183 */
182 function disableInputElementsInSidebar() { 184 function disableInputElementsInSidebar() {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 * @return {number} duplex mode. 325 * @return {number} duplex mode.
324 */ 326 */
325 function getDuplexMode() { 327 function getDuplexMode() {
326 // Constants values matches printing::DuplexMode enum. 328 // Constants values matches printing::DuplexMode enum.
327 const SIMPLEX = 0; 329 const SIMPLEX = 0;
328 const LONG_EDGE = 1; 330 const LONG_EDGE = 1;
329 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE; 331 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE;
330 } 332 }
331 333
332 /** 334 /**
335 * Checks whether the Headers and Footers checkbox is checked or not.
336 *
337 * @return {boolean} true if Headers and Footers are checked.
338 */
339 function isHeaderFooter() {
Lei Zhang 2011/07/12 22:04:50 how about hasHeadersFooters() ?
Aayush Kumar 2011/07/13 21:52:16 Done.
340 return $('header-footer').checked;
341 }
342
343 /**
333 * Creates a JSON string based on the values in the printer settings. 344 * Creates a JSON string based on the values in the printer settings.
334 * 345 *
335 * @return {string} JSON string with print job settings. 346 * @return {string} JSON string with print job settings.
336 */ 347 */
337 function getSettingsJSON() { 348 function getSettingsJSON() {
338 var printAll = $('all-pages').checked; 349 var printAll = $('all-pages').checked;
339 var deviceName = getSelectedPrinterName(); 350 var deviceName = getSelectedPrinterName();
340 var printToPDF = (deviceName == PRINT_TO_PDF); 351 var printToPDF = (deviceName == PRINT_TO_PDF);
341 352
342 return JSON.stringify( 353 return JSON.stringify(
343 {'deviceName': deviceName, 354 {'deviceName': deviceName,
344 'pageRange': pageSetToPageRanges(getSelectedPagesSet()), 355 'pageRange': pageSetToPageRanges(getSelectedPagesSet()),
345 'printAll': printAll, 356 'printAll': printAll,
346 'duplex': getDuplexMode(), 357 'duplex': getDuplexMode(),
347 'copies': copiesSettings.numberOfCopies, 358 'copies': copiesSettings.numberOfCopies,
348 'collate': isCollated(), 359 'collate': isCollated(),
349 'landscape': isLandscape(), 360 'landscape': isLandscape(),
350 'color': isColor(), 361 'color': isColor(),
351 'printToPDF': printToPDF}); 362 'printToPDF': printToPDF,
363 'headerFooter': isHeaderFooter()});
352 } 364 }
353 365
354 /** 366 /**
355 * Returns the name of the selected printer or the empty string if no 367 * Returns the name of the selected printer or the empty string if no
356 * printer is selected. 368 * printer is selected.
357 */ 369 */
358 function getSelectedPrinterName() { 370 function getSelectedPrinterName() {
359 var printerList = $('printer-list') 371 var printerList = $('printer-list')
360 var selectedPrinter = printerList.selectedIndex; 372 var selectedPrinter = printerList.selectedIndex;
361 if (selectedPrinter < 0) 373 if (selectedPrinter < 0)
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) { 680 } else if (printSettings.isLandscape != tempPrintSettings.isLandscape) {
669 setDefaultValuesAndRegeneratePreview(); 681 setDefaultValuesAndRegeneratePreview();
670 return true; 682 return true;
671 } else if (isSelectedPagesValid()) { 683 } else if (isSelectedPagesValid()) {
672 var currentlySelectedPages = getSelectedPagesSet(); 684 var currentlySelectedPages = getSelectedPagesSet();
673 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) { 685 if (!areArraysEqual(previouslySelectedPages, currentlySelectedPages)) {
674 previouslySelectedPages = currentlySelectedPages; 686 previouslySelectedPages = currentlySelectedPages;
675 requestPrintPreview(); 687 requestPrintPreview();
676 return true; 688 return true;
677 } 689 }
690 } else if (printSettings.isHeaderFooter != tempPrintSettings.isHeaderFooter) {
691 requestPrintPreview();
692 return true;
678 } 693 }
679 694
680 if (!isSelectedPagesValid()) 695 if (!isSelectedPagesValid())
681 pageRangesFieldChanged(); 696 pageRangesFieldChanged();
682 return false; 697 return false;
683 } 698 }
684 699
685 /** 700 /**
686 * Create the PDF plugin or reload the existing one. 701 * Create the PDF plugin or reload the existing one.
687 * @param {string} previewUid Preview unique identifier. 702 * @param {string} previewUid Preview unique identifier.
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 function onLayoutModeToggle() { 865 function onLayoutModeToggle() {
851 // If the chosen layout is same as before, nothing needs to be done. 866 // If the chosen layout is same as before, nothing needs to be done.
852 if (printSettings.isLandscape == isLandscape()) 867 if (printSettings.isLandscape == isLandscape())
853 return; 868 return;
854 869
855 $('individual-pages').classList.remove('invalid'); 870 $('individual-pages').classList.remove('invalid');
856 setDefaultValuesAndRegeneratePreview(); 871 setDefaultValuesAndRegeneratePreview();
857 } 872 }
858 873
859 /** 874 /**
875 * When the user selects or de-selects the Headers and footers option then we
876 * regenerate the preview pdf.
877 */
878 function onHeaderFooterChanged() {
879 requestPrintPreview();
880 }
881
882 /**
860 * Sets the default values and sends a request to regenerate preview data. 883 * Sets the default values and sends a request to regenerate preview data.
861 */ 884 */
862 function setDefaultValuesAndRegeneratePreview() { 885 function setDefaultValuesAndRegeneratePreview() {
863 fadeOutElement($('individual-pages-hint')); 886 fadeOutElement($('individual-pages-hint'));
864 totalPageCount = undefined; 887 totalPageCount = undefined;
865 previouslySelectedPages.length = 0; 888 previouslySelectedPages.length = 0;
866 requestPrintPreview(); 889 requestPrintPreview();
867 } 890 }
868 891
869 /** 892 /**
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 previouslySelectedPages = currentlySelectedPages; 959 previouslySelectedPages = currentlySelectedPages;
937 requestPrintPreview(); 960 requestPrintPreview();
938 } 961 }
939 962
940 /** 963 /**
941 * Class that represents the state of the print settings. 964 * Class that represents the state of the print settings.
942 */ 965 */
943 function PrintSettings() { 966 function PrintSettings() {
944 this.deviceName = ''; 967 this.deviceName = '';
945 this.isLandscape = ''; 968 this.isLandscape = '';
969 this.isHeaderFooter = '';
946 } 970 }
947 971
948 /** 972 /**
949 * Takes a snapshot of the print settings. 973 * Takes a snapshot of the print settings.
950 */ 974 */
951 PrintSettings.prototype.save = function() { 975 PrintSettings.prototype.save = function() {
952 this.deviceName = getSelectedPrinterName(); 976 this.deviceName = getSelectedPrinterName();
953 this.isLandscape = isLandscape(); 977 this.isLandscape = isLandscape();
978 this.isHeaderFooter = isHeaderFooter();
954 } 979 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698