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 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 // True when preview tab is hidden. | 39 // True when preview tab is hidden. |
40 var isTabHidden = false; | 40 var isTabHidden = false; |
41 | 41 |
42 // Object holding all the pages related settings. | 42 // Object holding all the pages related settings. |
43 var pageSettings; | 43 var pageSettings; |
44 | 44 |
45 // Object holding all the copies related settings. | 45 // Object holding all the copies related settings. |
46 var copiesSettings; | 46 var copiesSettings; |
47 | 47 |
48 // Object holding all the layout related settings. | |
49 var layoutSettings; | |
50 | |
48 // True if the user has click 'Advanced...' in order to open the system print | 51 // True if the user has click 'Advanced...' in order to open the system print |
49 // dialog. | 52 // dialog. |
50 var showingSystemDialog = false; | 53 var showingSystemDialog = false; |
51 | 54 |
52 // The range of options in the printer dropdown controlled by cloud print. | 55 // The range of options in the printer dropdown controlled by cloud print. |
53 var firstCloudPrintOptionPos = 0 | 56 var firstCloudPrintOptionPos = 0 |
54 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; | 57 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; |
55 | 58 |
56 /** | 59 /** |
57 * Window onload handler, sets up the page and starts print preview by getting | 60 * Window onload handler, sets up the page and starts print preview by getting |
(...skipping 15 matching lines...) Expand all Loading... | |
73 | 76 |
74 $('print-button').focus(); | 77 $('print-button').focus(); |
75 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); | 78 $('system-dialog-link').addEventListener('click', onSystemDialogLinkClicked); |
76 $('mainview').parentElement.removeChild($('dummy-viewer')); | 79 $('mainview').parentElement.removeChild($('dummy-viewer')); |
77 | 80 |
78 $('printer-list').disabled = true; | 81 $('printer-list').disabled = true; |
79 $('print-button').onclick = printFile; | 82 $('print-button').onclick = printFile; |
80 | 83 |
81 pageSettings = print_preview.PageSettings.getInstance(); | 84 pageSettings = print_preview.PageSettings.getInstance(); |
82 copiesSettings = print_preview.CopiesSettings.getInstance(); | 85 copiesSettings = print_preview.CopiesSettings.getInstance(); |
86 layoutSettings = print_preview.LayoutSettings.getInstance(); | |
83 pageSettings.addEventListeners(); | 87 pageSettings.addEventListeners(); |
84 copiesSettings.addEventListeners(); | 88 copiesSettings.addEventListeners(); |
89 layoutSettings.addEventListeners(); | |
85 | 90 |
86 showLoadingAnimation(); | 91 showLoadingAnimation(); |
87 chrome.send('getDefaultPrinter'); | 92 chrome.send('getDefaultPrinter'); |
88 } | 93 } |
89 | 94 |
90 /** | 95 /** |
91 * Adds event listeners to the settings controls. | 96 * Adds event listeners to the settings controls. |
92 */ | 97 */ |
93 function addEventListeners() { | 98 function addEventListeners() { |
94 // Controls that require preview rendering. | 99 // Controls that require preview rendering. |
95 $('landscape').onclick = onLayoutModeToggle; | |
96 $('portrait').onclick = onLayoutModeToggle; | |
97 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 100 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
98 | 101 |
99 // Controls that do not require preview rendering. | 102 // Controls that do not require preview rendering. |
100 $('color').onclick = function() { setColor(true); }; | 103 $('color').onclick = function() { setColor(true); }; |
101 $('bw').onclick = function() { setColor(false); }; | 104 $('bw').onclick = function() { setColor(false); }; |
102 } | 105 } |
103 | 106 |
104 /** | 107 /** |
105 * Removes event listeners from the settings controls. | 108 * Removes event listeners from the settings controls. |
106 */ | 109 */ |
107 function removeEventListeners() { | 110 function removeEventListeners() { |
108 clearTimeout(pageSettings.timerId_); | 111 clearTimeout(pageSettings.timerId_); |
109 | 112 |
110 // Controls that require preview rendering | 113 // Controls that require preview rendering |
111 $('landscape').onclick = null; | |
112 $('portrait').onclick = null; | |
113 $('printer-list').onchange = null; | 114 $('printer-list').onchange = null; |
114 | 115 |
115 // Controls that don't require preview rendering. | 116 // Controls that don't require preview rendering. |
116 $('color').onclick = null; | 117 $('color').onclick = null; |
117 $('bw').onclick = null; | 118 $('bw').onclick = null; |
118 } | 119 } |
119 | 120 |
120 /** | 121 /** |
121 * Disables the input elements in the sidebar. | 122 * Disables the input elements in the sidebar. |
122 */ | 123 */ |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 } | 239 } |
239 | 240 |
240 /** | 241 /** |
241 * Updates the controls with printer capabilities information. | 242 * Updates the controls with printer capabilities information. |
242 * @param {Object} settingInfo printer setting information. | 243 * @param {Object} settingInfo printer setting information. |
243 */ | 244 */ |
244 function updateWithPrinterCapabilities(settingInfo) { | 245 function updateWithPrinterCapabilities(settingInfo) { |
245 var disableColorOption = settingInfo.disableColorOption; | 246 var disableColorOption = settingInfo.disableColorOption; |
246 var disableCopiesOption = settingInfo.disableCopiesOption; | 247 var disableCopiesOption = settingInfo.disableCopiesOption; |
247 var setColorAsDefault = settingInfo.setColorAsDefault; | 248 var setColorAsDefault = settingInfo.setColorAsDefault; |
248 var disableLandscapeOption = settingInfo.disableLandscapeOption; | 249 var disableLayoutOption = settingInfo.disableLandscapeOption; |
Evan Stade
2011/07/13 23:42:40
I don't see much point in stashing this into a loc
dpapad
2011/07/14 00:45:15
Done.
| |
249 var setDuplexAsDefault = settingInfo.setDuplexAsDefault; | 250 var setDuplexAsDefault = settingInfo.setDuplexAsDefault; |
250 var color = $('color'); | 251 var color = $('color'); |
251 var bw = $('bw'); | 252 var bw = $('bw'); |
252 var colorOptions = $('color-options'); | 253 var colorOptions = $('color-options'); |
253 | 254 |
254 if (disableCopiesOption) { | 255 if (disableCopiesOption) { |
255 fadeOutElement($('copies-option')); | 256 fadeOutElement($('copies-option')); |
256 $('hr-before-copies').classList.remove('invisible'); | 257 $('hr-before-copies').classList.remove('invisible'); |
257 } else { | 258 } else { |
258 fadeInElement($('copies-option')); | 259 fadeInElement($('copies-option')); |
259 $('hr-before-copies').classList.add('invisible'); | 260 $('hr-before-copies').classList.add('invisible'); |
260 } | 261 } |
261 | 262 |
262 if (disableLandscapeOption) { | 263 disableLayoutOption ? fadeOutElement(layoutSettings.layoutOption) : |
Evan Stade
2011/07/13 23:42:40
layoutSettings.enableLayoutOption(!disableLayoutOp
dpapad
2011/07/14 00:45:15
Done.
| |
263 fadeOutElement($('landscape-option')); | 264 fadeInElement(layoutSettings.layoutOption); |
264 } else { | |
265 fadeInElement($('landscape-option')); | |
266 } | |
267 | 265 |
268 disableColorOption ? fadeOutElement(colorOptions) : | 266 disableColorOption ? fadeOutElement(colorOptions) : |
269 fadeInElement(colorOptions); | 267 fadeInElement(colorOptions); |
270 colorOptions.setAttribute('aria-hidden', disableColorOption); | 268 colorOptions.setAttribute('aria-hidden', disableColorOption); |
271 | 269 |
272 if (color.checked != setColorAsDefault) { | 270 if (color.checked != setColorAsDefault) { |
273 color.checked = setColorAsDefault; | 271 color.checked = setColorAsDefault; |
274 bw.checked = !setColorAsDefault; | 272 bw.checked = !setColorAsDefault; |
275 } | 273 } |
276 copiesSettings.twoSidedCheckbox.checked = setDuplexAsDefault; | 274 copiesSettings.twoSidedCheckbox.checked = setDuplexAsDefault; |
(...skipping 19 matching lines...) Expand all Loading... | |
296 } | 294 } |
297 | 295 |
298 /** | 296 /** |
299 * Cloud print upload of the PDF file is finished, time to close the dialog. | 297 * Cloud print upload of the PDF file is finished, time to close the dialog. |
300 */ | 298 */ |
301 function finishedCloudPrinting() { | 299 function finishedCloudPrinting() { |
302 window.location = cloudprint.getBaseURL(); | 300 window.location = cloudprint.getBaseURL(); |
303 } | 301 } |
304 | 302 |
305 /** | 303 /** |
306 * Checks whether the preview layout setting is set to 'landscape' or not. | |
307 * | |
308 * @return {boolean} true if layout is 'landscape'. | |
309 */ | |
310 function isLandscape() { | |
311 return $('landscape').checked; | |
312 } | |
313 | |
314 /** | |
315 * Checks whether the preview color setting is set to 'color' or not. | 304 * Checks whether the preview color setting is set to 'color' or not. |
316 * | 305 * |
317 * @return {boolean} true if color is 'color'. | 306 * @return {boolean} true if color is 'color'. |
318 */ | 307 */ |
319 function isColor() { | 308 function isColor() { |
320 return $('color').checked; | 309 return $('color').checked; |
321 } | 310 } |
322 | 311 |
323 /** | 312 /** |
324 * Checks whether the preview collate setting value is set or not. | 313 * Checks whether the preview collate setting value is set or not. |
(...skipping 23 matching lines...) Expand all Loading... | |
348 function getSettingsJSON() { | 337 function getSettingsJSON() { |
349 var deviceName = getSelectedPrinterName(); | 338 var deviceName = getSelectedPrinterName(); |
350 var printToPDF = (deviceName == PRINT_TO_PDF); | 339 var printToPDF = (deviceName == PRINT_TO_PDF); |
351 | 340 |
352 var settings = {'deviceName': deviceName, | 341 var settings = {'deviceName': deviceName, |
353 'pageRange': pageSettings.selectedPageRanges, | 342 'pageRange': pageSettings.selectedPageRanges, |
354 'printAll': pageSettings.allPagesRadioButton.checked, | 343 'printAll': pageSettings.allPagesRadioButton.checked, |
355 'duplex': getDuplexMode(), | 344 'duplex': getDuplexMode(), |
356 'copies': copiesSettings.numberOfCopies, | 345 'copies': copiesSettings.numberOfCopies, |
357 'collate': isCollated(), | 346 'collate': isCollated(), |
358 'landscape': isLandscape(), | 347 'landscape': layoutSettings.isLandscape(), |
359 'color': isColor(), | 348 'color': isColor(), |
360 'printToPDF': printToPDF}; | 349 'printToPDF': printToPDF}; |
361 var printerList = $('printer-list'); | 350 var printerList = $('printer-list'); |
362 var selectedPrinter = printerList.selectedIndex; | 351 var selectedPrinter = printerList.selectedIndex; |
363 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { | 352 if (cloudprint.isCloudPrint(printerList.options[selectedPrinter])) { |
364 settings['cloudPrintID'] = | 353 settings['cloudPrintID'] = |
365 printerList.options[selectedPrinter].value; | 354 printerList.options[selectedPrinter].value; |
366 } | 355 } |
367 | 356 |
368 return JSON.stringify(settings); | 357 return JSON.stringify(settings); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 | 750 |
762 /** | 751 /** |
763 * Called when the PDF plugin loads its document. | 752 * Called when the PDF plugin loads its document. |
764 */ | 753 */ |
765 function onPDFLoad() { | 754 function onPDFLoad() { |
766 $('pdf-viewer').fitToHeight(); | 755 $('pdf-viewer').fitToHeight(); |
767 setColor($('color').checked); | 756 setColor($('color').checked); |
768 hideLoadingAnimation(); | 757 hideLoadingAnimation(); |
769 | 758 |
770 if (!previewModifiable) | 759 if (!previewModifiable) |
771 fadeOutElement($('landscape-option')); | 760 fadeOutElement(layoutSettings.layoutOption); |
Evan Stade
2011/07/13 23:42:40
attach PDFLoaded handler in layoutSettings to do t
dpapad
2011/07/14 00:45:15
Done.
| |
772 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 761 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
773 } | 762 } |
774 | 763 |
775 /** | 764 /** |
776 * Update the page count and check the page range. | 765 * Update the page count and check the page range. |
777 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 766 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
778 * @param {number} pageCount The number of pages. | 767 * @param {number} pageCount The number of pages. |
779 */ | 768 */ |
780 function onDidGetPreviewPageCount(pageCount) { | 769 function onDidGetPreviewPageCount(pageCount) { |
781 pageSettings.updateState(pageCount); | 770 pageSettings.updateState(pageCount); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 html = localStrings.getStringF('printPreviewSummaryFormatShort', | 936 html = localStrings.getStringF('printPreviewSummaryFormatShort', |
948 '<b>' + numOfSheets + '</b>', | 937 '<b>' + numOfSheets + '</b>', |
949 '<b>' + summaryLabel + '</b>'); | 938 '<b>' + summaryLabel + '</b>'); |
950 | 939 |
951 // Removing extra spaces from within the string. | 940 // Removing extra spaces from within the string. |
952 html = html.replace(/\s{2,}/g, ' '); | 941 html = html.replace(/\s{2,}/g, ' '); |
953 printSummary.innerHTML = html; | 942 printSummary.innerHTML = html; |
954 } | 943 } |
955 | 944 |
956 /** | 945 /** |
957 * When the user switches printing orientation mode the page field selection is | |
958 * reset to "all pages selected". After the change the number of pages will be | |
959 * different and currently selected page numbers might no longer be valid. | |
960 * Even if they are still valid the content of these pages will be different. | |
961 */ | |
962 function onLayoutModeToggle() { | |
963 // If the chosen layout is same as before, nothing needs to be done. | |
964 if (printSettings.isLandscape == isLandscape()) | |
965 return; | |
966 setDefaultValuesAndRegeneratePreview(); | |
967 } | |
968 | |
969 /** | |
970 * Sets the default values and sends a request to regenerate preview data. | 946 * Sets the default values and sends a request to regenerate preview data. |
971 */ | 947 */ |
972 function setDefaultValuesAndRegeneratePreview() { | 948 function setDefaultValuesAndRegeneratePreview() { |
973 pageSettings.resetState(); | 949 pageSettings.resetState(); |
974 requestPrintPreview(); | 950 requestPrintPreview(); |
975 } | 951 } |
976 | 952 |
977 /** | 953 /** |
978 * Class that represents the state of the print settings. | 954 * Class that represents the state of the print settings. |
979 */ | 955 */ |
980 function PrintSettings() { | 956 function PrintSettings() { |
981 this.deviceName = ''; | 957 this.deviceName = ''; |
982 this.isLandscape = ''; | 958 this.isLandscape = ''; |
983 } | 959 } |
984 | 960 |
985 /** | 961 /** |
986 * Takes a snapshot of the print settings. | 962 * Takes a snapshot of the print settings. |
987 */ | 963 */ |
988 PrintSettings.prototype.save = function() { | 964 PrintSettings.prototype.save = function() { |
989 this.deviceName = getSelectedPrinterName(); | 965 this.deviceName = getSelectedPrinterName(); |
990 this.isLandscape = isLandscape(); | 966 this.isLandscape = layoutSettings.isLandscape(); |
991 } | 967 } |
992 | 968 |
OLD | NEW |