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

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

Issue 7358002: Print Preview: Refactoring layout mode related logic to LayoutSettings class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving function within CopiesSettings 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
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 30 matching lines...) Expand all
41 41
42 // True when preview tab is hidden. 42 // True when preview tab is hidden.
43 var isTabHidden = false; 43 var isTabHidden = false;
44 44
45 // Object holding all the pages related settings. 45 // Object holding all the pages related settings.
46 var pageSettings; 46 var pageSettings;
47 47
48 // Object holding all the copies related settings. 48 // Object holding all the copies related settings.
49 var copiesSettings; 49 var copiesSettings;
50 50
51 // Object holding all the layout related settings.
52 var layoutSettings;
53
51 // True if the user has click 'Advanced...' in order to open the system print 54 // True if the user has click 'Advanced...' in order to open the system print
52 // dialog. 55 // dialog.
53 var showingSystemDialog = false; 56 var showingSystemDialog = false;
54 57
55 // The range of options in the printer dropdown controlled by cloud print. 58 // The range of options in the printer dropdown controlled by cloud print.
56 var firstCloudPrintOptionPos = 0 59 var firstCloudPrintOptionPos = 0
57 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; 60 var lastCloudPrintOptionPos = firstCloudPrintOptionPos;
58 61
59 /** 62 /**
60 * Window onload handler, sets up the page and starts print preview by getting 63 * Window onload handler, sets up the page and starts print preview by getting
(...skipping 15 matching lines...) Expand all
76 79
77 $('print-button').focus(); 80 $('print-button').focus();
78 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); 81 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked);
79 $('mainview').parentElement.removeChild($('dummy-viewer')); 82 $('mainview').parentElement.removeChild($('dummy-viewer'));
80 83
81 $('printer-list').disabled = true; 84 $('printer-list').disabled = true;
82 $('print-button').onclick = printFile; 85 $('print-button').onclick = printFile;
83 86
84 pageSettings = print_preview.PageSettings.getInstance(); 87 pageSettings = print_preview.PageSettings.getInstance();
85 copiesSettings = print_preview.CopiesSettings.getInstance(); 88 copiesSettings = print_preview.CopiesSettings.getInstance();
89 layoutSettings = print_preview.LayoutSettings.getInstance();
86 pageSettings.addEventListeners(); 90 pageSettings.addEventListeners();
87 copiesSettings.addEventListeners(); 91 copiesSettings.addEventListeners();
92 layoutSettings.addEventListeners();
88 93
89 showLoadingAnimation(); 94 showLoadingAnimation();
90 chrome.send('getDefaultPrinter'); 95 chrome.send('getDefaultPrinter');
91 } 96 }
92 97
93 /** 98 /**
94 * Adds event listeners to the settings controls. 99 * Adds event listeners to the settings controls.
95 */ 100 */
96 function addEventListeners() { 101 function addEventListeners() {
97 // Controls that require preview rendering. 102 // Controls that require preview rendering.
98 $('landscape').onclick = onLayoutModeToggle;
99 $('portrait').onclick = onLayoutModeToggle;
100 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; 103 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
101 104
102 // Controls that do not require preview rendering. 105 // Controls that do not require preview rendering.
103 $('color').onclick = function() { setColor(true); }; 106 $('color').onclick = function() { setColor(true); };
104 $('bw').onclick = function() { setColor(false); }; 107 $('bw').onclick = function() { setColor(false); };
105 } 108 }
106 109
107 /** 110 /**
108 * Removes event listeners from the settings controls. 111 * Removes event listeners from the settings controls.
109 */ 112 */
110 function removeEventListeners() { 113 function removeEventListeners() {
111 if (pageSettings) 114 if (pageSettings)
112 clearTimeout(pageSettings.timerId_); 115 clearTimeout(pageSettings.timerId_);
113 116
114 // Controls that require preview rendering 117 // Controls that require preview rendering
115 $('landscape').onclick = null;
116 $('portrait').onclick = null;
117 $('printer-list').onchange = null; 118 $('printer-list').onchange = null;
118 119
119 // Controls that don't require preview rendering. 120 // Controls that don't require preview rendering.
120 $('color').onclick = null; 121 $('color').onclick = null;
121 $('bw').onclick = null; 122 $('bw').onclick = null;
122 } 123 }
123 124
124 /** 125 /**
125 * Disables the input elements in the sidebar. 126 * Disables the input elements in the sidebar.
126 */ 127 */
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 lastSelectedPrinterIndex = selectedIndex; 239 lastSelectedPrinterIndex = selectedIndex;
239 240
240 // Regenerate the preview data based on selected printer settings. 241 // Regenerate the preview data based on selected printer settings.
241 setDefaultValuesAndRegeneratePreview(); 242 setDefaultValuesAndRegeneratePreview();
242 } 243 }
243 244
244 /** 245 /**
245 * Updates the controls with printer capabilities information. 246 * Updates the controls with printer capabilities information.
246 * @param {Object} settingInfo printer setting information. 247 * @param {Object} settingInfo printer setting information.
247 */ 248 */
248 function updateWithPrinterCapabilities(settingInfo) { 249 function updateWithPrinterCapabilities(settingInfo) {
Evan Stade 2011/07/14 18:51:45 could we have a printerCapabilitiesUpdated event s
dpapad 2011/07/14 22:17:45 Done. The remaining statements here will be moved
249 var disableColorOption = settingInfo.disableColorOption; 250 var disableColorOption = settingInfo.disableColorOption;
250 var disableCopiesOption = settingInfo.disableCopiesOption; 251 var disableCopiesOption = settingInfo.disableCopiesOption;
251 var setColorAsDefault = settingInfo.setColorAsDefault; 252 var setColorAsDefault = settingInfo.setColorAsDefault;
252 var disableLandscapeOption = settingInfo.disableLandscapeOption;
253 var setDuplexAsDefault = settingInfo.setDuplexAsDefault; 253 var setDuplexAsDefault = settingInfo.setDuplexAsDefault;
254 var color = $('color'); 254 var color = $('color');
255 var bw = $('bw'); 255 var bw = $('bw');
256 var colorOptions = $('color-options'); 256 var colorOptions = $('color-options');
257 257
258 if (disableCopiesOption) { 258 if (disableCopiesOption) {
259 fadeOutElement($('copies-option')); 259 fadeOutElement($('copies-option'));
260 $('hr-before-copies').classList.remove('invisible'); 260 $('hr-before-copies').classList.remove('invisible');
261 } else { 261 } else {
262 fadeInElement($('copies-option')); 262 fadeInElement($('copies-option'));
263 $('hr-before-copies').classList.add('invisible'); 263 $('hr-before-copies').classList.add('invisible');
264 } 264 }
265 265
266 if (disableLandscapeOption) { 266 layoutSettings.fadeInOut(settingInfo.disableLandscapeOption);
267 fadeOutElement($('landscape-option'));
268 } else {
269 fadeInElement($('landscape-option'));
270 }
271
272 disableColorOption ? fadeOutElement(colorOptions) : 267 disableColorOption ? fadeOutElement(colorOptions) :
273 fadeInElement(colorOptions); 268 fadeInElement(colorOptions);
274 colorOptions.setAttribute('aria-hidden', disableColorOption); 269 colorOptions.setAttribute('aria-hidden', disableColorOption);
275 270
276 if (color.checked != setColorAsDefault) { 271 if (color.checked != setColorAsDefault) {
277 color.checked = setColorAsDefault; 272 color.checked = setColorAsDefault;
278 bw.checked = !setColorAsDefault; 273 bw.checked = !setColorAsDefault;
279 } 274 }
280 copiesSettings.twoSidedCheckbox.checked = setDuplexAsDefault; 275 copiesSettings.twoSidedCheckbox.checked = setDuplexAsDefault;
281 } 276 }
(...skipping 18 matching lines...) Expand all
300 } 295 }
301 296
302 /** 297 /**
303 * Cloud print upload of the PDF file is finished, time to close the dialog. 298 * Cloud print upload of the PDF file is finished, time to close the dialog.
304 */ 299 */
305 function finishedCloudPrinting() { 300 function finishedCloudPrinting() {
306 window.location = cloudprint.getBaseURL(); 301 window.location = cloudprint.getBaseURL();
307 } 302 }
308 303
309 /** 304 /**
310 * Checks whether the preview layout setting is set to 'landscape' or not.
311 *
312 * @return {boolean} true if layout is 'landscape'.
313 */
314 function isLandscape() {
315 return $('landscape').checked;
316 }
317
318 /**
319 * Checks whether the preview color setting is set to 'color' or not. 305 * Checks whether the preview color setting is set to 'color' or not.
320 * 306 *
321 * @return {boolean} true if color is 'color'. 307 * @return {boolean} true if color is 'color'.
322 */ 308 */
323 function isColor() { 309 function isColor() {
324 return $('color').checked; 310 return $('color').checked;
325 } 311 }
326 312
327 /** 313 /**
328 * Checks whether the preview collate setting value is set or not. 314 * Checks whether the preview collate setting value is set or not.
329 * 315 *
330 * @return {boolean} true if collate setting is enabled and checked. 316 * @return {boolean} true if collate setting is enabled and checked.
331 */ 317 */
332 function isCollated() { 318 function isCollated() {
333 return !copiesSettings.collateOption.hidden && $('collate').checked; 319 return !copiesSettings.collateOption.hidden && $('collate').checked;
334 } 320 }
335 321
336 /** 322 /**
337 * Gets the duplex mode for printing.
338 * @return {number} duplex mode.
339 */
340 function getDuplexMode() {
341 // Constants values matches printing::DuplexMode enum.
342 const SIMPLEX = 0;
343 const LONG_EDGE = 1;
344 return !copiesSettings.twoSidedCheckbox.checked ? SIMPLEX : LONG_EDGE;
345 }
346
347 /**
348 * Creates an object based on the values in the printer settings. 323 * Creates an object based on the values in the printer settings.
349 * 324 *
350 * @return {Object} Object containing print job settings. 325 * @return {Object} Object containing print job settings.
351 */ 326 */
352 function getSettings() { 327 function getSettings() {
353 var deviceName = getSelectedPrinterName(); 328 var deviceName = getSelectedPrinterName();
354 var printToPDF = (deviceName == PRINT_TO_PDF); 329 var printToPDF = (deviceName == PRINT_TO_PDF);
355 330
356 var settings = 331 var settings =
357 {'deviceName': deviceName, 332 {'deviceName': deviceName,
358 'pageRange': pageSettings.selectedPageRanges, 333 'pageRange': pageSettings.selectedPageRanges,
359 'printAll': pageSettings.allPagesRadioButton.checked, 334 'printAll': pageSettings.allPagesRadioButton.checked,
360 'duplex': getDuplexMode(), 335 'duplex': copiesSettings.duplexMode,
361 'copies': copiesSettings.numberOfCopies, 336 'copies': copiesSettings.numberOfCopies,
362 'collate': isCollated(), 337 'collate': isCollated(),
363 'landscape': isLandscape(), 338 'landscape': layoutSettings.isLandscape(),
364 'color': isColor(), 339 'color': isColor(),
365 'printToPDF': printToPDF, 340 'printToPDF': printToPDF,
366 'requestID': 0}; 341 'requestID': 0};
367 342
368 var printerList = $('printer-list'); 343 var printerList = $('printer-list');
369 var selectedPrinter = printerList.selectedIndex; 344 var selectedPrinter = printerList.selectedIndex;
370 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { 345 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) {
371 settings['cloudPrintID'] = 346 settings['cloudPrintID'] =
372 printerList.options[selectedPrinter].value; 347 printerList.options[selectedPrinter].value;
373 } 348 }
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 750 }
776 751
777 /** 752 /**
778 * Called when the PDF plugin loads its document. 753 * Called when the PDF plugin loads its document.
779 */ 754 */
780 function onPDFLoad() { 755 function onPDFLoad() {
781 $('pdf-viewer').fitToHeight(); 756 $('pdf-viewer').fitToHeight();
782 setColor($('color').checked); 757 setColor($('color').checked);
783 hideLoadingAnimation(); 758 hideLoadingAnimation();
784 759
785 if (!previewModifiable)
786 fadeOutElement($('landscape-option'));
787 cr.dispatchSimpleEvent(document, 'PDFLoaded'); 760 cr.dispatchSimpleEvent(document, 'PDFLoaded');
788 } 761 }
789 762
790 /** 763 /**
791 * Update the page count and check the page range. 764 * Update the page count and check the page range.
792 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). 765 * Called from PrintPreviewUI::OnDidGetPreviewPageCount().
793 * @param {number} pageCount The number of pages. 766 * @param {number} pageCount The number of pages.
794 */ 767 */
795 function onDidGetPreviewPageCount(pageCount) { 768 function onDidGetPreviewPageCount(pageCount) {
796 pageSettings.updateState(pageCount); 769 pageSettings.updateState(pageCount);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 html = localStrings.getStringF('printPreviewSummaryFormatShort', 942 html = localStrings.getStringF('printPreviewSummaryFormatShort',
970 '<b>' + numOfSheets + '</b>', 943 '<b>' + numOfSheets + '</b>',
971 '<b>' + summaryLabel + '</b>'); 944 '<b>' + summaryLabel + '</b>');
972 945
973 // Removing extra spaces from within the string. 946 // Removing extra spaces from within the string.
974 html = html.replace(/\s{2,}/g, ' '); 947 html = html.replace(/\s{2,}/g, ' ');
975 printSummary.innerHTML = html; 948 printSummary.innerHTML = html;
976 } 949 }
977 950
978 /** 951 /**
979 * When the user switches printing orientation mode the page field selection is
980 * reset to "all pages selected". After the change the number of pages will be
981 * different and currently selected page numbers might no longer be valid.
982 * Even if they are still valid the content of these pages will be different.
983 */
984 function onLayoutModeToggle() {
985 // If the chosen layout is same as before, nothing needs to be done.
986 if (printSettings.isLandscape == isLandscape())
987 return;
988 setDefaultValuesAndRegeneratePreview();
989 }
990
991 /**
992 * Sets the default values and sends a request to regenerate preview data. 952 * Sets the default values and sends a request to regenerate preview data.
993 */ 953 */
994 function setDefaultValuesAndRegeneratePreview() { 954 function setDefaultValuesAndRegeneratePreview() {
995 pageSettings.resetState(); 955 pageSettings.resetState();
996 requestPrintPreview(); 956 requestPrintPreview();
997 } 957 }
998 958
999 /** 959 /**
1000 * Class that represents the state of the print settings. 960 * Class that represents the state of the print settings.
1001 */ 961 */
1002 function PrintSettings() { 962 function PrintSettings() {
1003 this.deviceName = ''; 963 this.deviceName = '';
1004 this.isLandscape = ''; 964 this.isLandscape = '';
1005 } 965 }
1006 966
1007 /** 967 /**
1008 * Takes a snapshot of the print settings. 968 * Takes a snapshot of the print settings.
1009 */ 969 */
1010 PrintSettings.prototype.save = function() { 970 PrintSettings.prototype.save = function() {
1011 this.deviceName = getSelectedPrinterName(); 971 this.deviceName = getSelectedPrinterName();
1012 this.isLandscape = isLandscape(); 972 this.isLandscape = layoutSettings.isLandscape();
1013 } 973 }
1014 974
OLDNEW
« no previous file with comments | « chrome/browser/resources/print_preview/print_preview.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698