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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 pageSettings = print_preview.PageSettings.getInstance(); | 158 pageSettings = print_preview.PageSettings.getInstance(); |
159 copiesSettings = print_preview.CopiesSettings.getInstance(); | 159 copiesSettings = print_preview.CopiesSettings.getInstance(); |
160 layoutSettings = print_preview.LayoutSettings.getInstance(); | 160 layoutSettings = print_preview.LayoutSettings.getInstance(); |
161 marginSettings = print_preview.MarginSettings.getInstance(); | 161 marginSettings = print_preview.MarginSettings.getInstance(); |
162 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 162 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
163 colorSettings = print_preview.ColorSettings.getInstance(); | 163 colorSettings = print_preview.ColorSettings.getInstance(); |
164 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 164 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
165 | 165 |
166 previewArea.showLoadingAnimation(); | 166 previewArea.showLoadingAnimation(); |
167 chrome.send('getInitiatorTabTitle'); | 167 chrome.send('getInitialSettings'); |
168 chrome.send('getDefaultPrinter'); | |
169 chrome.send('getNumberFormatAndMeasurementSystem'); | |
170 } | 168 } |
171 | 169 |
172 /** | 170 /** |
| 171 * @param {string} initiatorTabTitle The title of the initiator tab. |
| 172 * @param {object} initialSettings An object containing all the initial |
| 173 * settings. |
| 174 */ |
| 175 function setInitialSettings(initialSettings) { |
| 176 setInitiatorTabTitle(initialSettings['initiatorTabTitle']); |
| 177 previewModifiable = initialSettings['previewModifiable']; |
| 178 if (previewModifiable) { |
| 179 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem( |
| 180 initialSettings['numberFormat'], |
| 181 initialSettings['measurementSystem']); |
| 182 marginSettings.setLastUsedMargins(initialSettings); |
| 183 } |
| 184 setDefaultPrinter(initialSettings['printerName'], |
| 185 initialSettings['cloudPrintData']); |
| 186 } |
| 187 |
| 188 /** |
173 * Disables the input elements in the sidebar. | 189 * Disables the input elements in the sidebar. |
174 */ | 190 */ |
175 function disableInputElementsInSidebar() { | 191 function disableInputElementsInSidebar() { |
176 var els = $('navbar-container').querySelectorAll('input, button, select'); | 192 var els = $('navbar-container').querySelectorAll('input, button, select'); |
177 for (var i = 0; i < els.length; i++) { | 193 for (var i = 0; i < els.length; i++) { |
178 if (els[i] == printHeader.cancelButton) | 194 if (els[i] == printHeader.cancelButton) |
179 continue; | 195 continue; |
180 els[i].disabled = true; | 196 els[i].disabled = true; |
181 } | 197 } |
182 } | 198 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 sendPrintDocumentRequest(); | 293 sendPrintDocumentRequest(); |
278 } else { | 294 } else { |
279 // This message will call back to 'updateWithPrinterCapabilities' | 295 // This message will call back to 'updateWithPrinterCapabilities' |
280 // function. | 296 // function. |
281 chrome.send('getPrinterCapabilities', [selectedValue]); | 297 chrome.send('getPrinterCapabilities', [selectedValue]); |
282 } | 298 } |
283 if (!skip_refresh) { | 299 if (!skip_refresh) { |
284 lastSelectedPrinterIndex = selectedIndex; | 300 lastSelectedPrinterIndex = selectedIndex; |
285 | 301 |
286 // Regenerate the preview data based on selected printer settings. | 302 // Regenerate the preview data based on selected printer settings. |
287 setDefaultValuesAndRegeneratePreview(true); | 303 // Do not reset the margins if no preview request has been made. |
| 304 var resetMargins = lastPreviewRequestID != initialPreviewRequestID; |
| 305 setDefaultValuesAndRegeneratePreview(resetMargins); |
288 } | 306 } |
289 } | 307 } |
290 | 308 |
291 /** | 309 /** |
292 * Helper function to do the actual work of updating cloud printer | 310 * Helper function to do the actual work of updating cloud printer |
293 * capabilities. | 311 * capabilities. |
294 * @param {Object} printer The printer object to set capabilities for. | 312 * @param {Object} printer The printer object to set capabilities for. |
295 */ | 313 */ |
296 function doUpdateCloudPrinterCapabilities(printer) { | 314 function doUpdateCloudPrinterCapabilities(printer) { |
297 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), | 315 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), |
298 'setColorAsDefault': cloudprint.colorIsDefault(printer), | 316 'setColorAsDefault': cloudprint.colorIsDefault(printer), |
299 'disableCopiesOption': true, | 317 'disableCopiesOption': true, |
300 'disableLandscapeOption': true}; | 318 'disableLandscapeOption': true}; |
301 updateWithPrinterCapabilities(settings); | 319 updateWithPrinterCapabilities(settings); |
302 var printerList = $('printer-list'); | 320 var printerList = $('printer-list'); |
303 var selectedIndex = printerList.selectedIndex; | 321 var selectedIndex = printerList.selectedIndex; |
304 lastSelectedPrinterIndex = selectedIndex; | 322 lastSelectedPrinterIndex = selectedIndex; |
305 | 323 |
306 // Regenerate the preview data based on selected printer settings. | 324 // Regenerate the preview data based on selected printer settings. |
307 setDefaultValuesAndRegeneratePreview(true); | 325 // Do not reset the margins if no preview request has been made. |
| 326 var resetMargins = lastPreviewRequestID != initialPreviewRequestID; |
| 327 setDefaultValuesAndRegeneratePreview(resetMargins); |
308 } | 328 } |
309 | 329 |
310 /** | 330 /** |
311 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the | 331 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the |
312 * capabilities of the currently selected printer. It is called from C++ too. | 332 * capabilities of the currently selected printer. It is called from C++ too. |
313 * @param {Object} settingInfo printer setting information. | 333 * @param {Object} settingInfo printer setting information. |
314 */ | 334 */ |
315 function updateWithPrinterCapabilities(settingInfo) { | 335 function updateWithPrinterCapabilities(settingInfo) { |
316 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); | 336 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
317 customEvent.printerCapabilities = settingInfo; | 337 customEvent.printerCapabilities = settingInfo; |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 disableInputElementsInSidebar(); | 591 disableInputElementsInSidebar(); |
572 previewArea.showCustomMessage( | 592 previewArea.showCustomMessage( |
573 localStrings.getString('printingToPDFInProgress')); | 593 localStrings.getString('printingToPDFInProgress')); |
574 } | 594 } |
575 | 595 |
576 /** | 596 /** |
577 * Set the default printer. If there is one, generate a print preview. | 597 * Set the default printer. If there is one, generate a print preview. |
578 * @param {string} printer Name of the default printer. Empty if none. | 598 * @param {string} printer Name of the default printer. Empty if none. |
579 * @param {string} cloudPrintData Cloud print related data to restore if | 599 * @param {string} cloudPrintData Cloud print related data to restore if |
580 * the default printer is a cloud printer. | 600 * the default printer is a cloud printer. |
581 * @param {number} lastUsedMarginsType Indicates the last used margins type | |
582 * (matches enum MarginType in printing/print_job_constants.h. | |
583 */ | 601 */ |
584 function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) { | 602 function setDefaultPrinter(printerName, cloudPrintData) { |
585 // Setting the margin selection to the last used one. | |
586 marginSettings.setLastUsedMarginsType(lastUsedMarginsType); | |
587 // Add a placeholder value so the printer list looks valid. | 603 // Add a placeholder value so the printer list looks valid. |
588 addDestinationListOption('', '', true, true, true); | 604 addDestinationListOption('', '', true, true, true); |
589 if (printer_name) { | 605 if (printerName) { |
590 defaultOrLastUsedPrinterName = printer_name; | 606 defaultOrLastUsedPrinterName = printerName; |
591 if (cloudPrintData) { | 607 if (cloudPrintData) { |
592 cloudprint.setDefaultPrinter(printer_name, | 608 cloudprint.setDefaultPrinter(printerName, |
593 cloudPrintData, | 609 cloudPrintData, |
594 addDestinationListOptionAtPosition, | 610 addDestinationListOptionAtPosition, |
595 doUpdateCloudPrinterCapabilities); | 611 doUpdateCloudPrinterCapabilities); |
596 } else { | 612 } else { |
597 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 613 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
598 updateControlsWithSelectedPrinterCapabilities(); | 614 updateControlsWithSelectedPrinterCapabilities(); |
599 } | 615 } |
600 } | 616 } |
601 chrome.send('getPrinters'); | 617 chrome.send('getPrinters'); |
602 } | 618 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 788 |
773 function setPluginPreviewPageCount() { | 789 function setPluginPreviewPageCount() { |
774 $('pdf-viewer').printPreviewPageCount( | 790 $('pdf-viewer').printPreviewPageCount( |
775 pageSettings.previouslySelectedPages.length); | 791 pageSettings.previouslySelectedPages.length); |
776 } | 792 } |
777 | 793 |
778 /** | 794 /** |
779 * Update the page count and check the page range. | 795 * Update the page count and check the page range. |
780 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 796 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
781 * @param {number} pageCount The number of pages. | 797 * @param {number} pageCount The number of pages. |
782 * @param {boolean} isModifiable Indicates whether the previewed document can be | |
783 * modified. | |
784 * @param {number} previewResponseId The preview request id that resulted in | 798 * @param {number} previewResponseId The preview request id that resulted in |
785 * this response. | 799 * this response. |
786 */ | 800 */ |
787 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { | 801 function onDidGetPreviewPageCount(pageCount, previewResponseId) { |
788 if (!isExpectedPreviewResponse(previewResponseId)) | 802 if (!isExpectedPreviewResponse(previewResponseId)) |
789 return; | 803 return; |
790 pageSettings.updateState(pageCount); | 804 pageSettings.updateState(pageCount); |
791 previewModifiable = isModifiable; | |
792 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 805 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
793 return; | 806 return; |
794 | 807 |
795 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); | 808 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
796 } | 809 } |
797 | 810 |
798 /** | 811 /** |
799 * @param {printing::PageSizeMargins} pageLayout The default layout of the page | 812 * @param {printing::PageSizeMargins} pageLayout The default layout of the page |
800 * in points. | 813 * in points. |
801 */ | 814 */ |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 * Takes a snapshot of the print settings. | 1064 * Takes a snapshot of the print settings. |
1052 */ | 1065 */ |
1053 PrintSettings.prototype.save = function() { | 1066 PrintSettings.prototype.save = function() { |
1054 this.deviceName = getSelectedPrinterName(); | 1067 this.deviceName = getSelectedPrinterName(); |
1055 this.isLandscape = layoutSettings.isLandscape(); | 1068 this.isLandscape = layoutSettings.isLandscape(); |
1056 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); | 1069 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); |
1057 } | 1070 } |
1058 | 1071 |
1059 /** | 1072 /** |
1060 * Updates the title of the print preview tab according to |initiatorTabTitle|. | 1073 * Updates the title of the print preview tab according to |initiatorTabTitle|. |
1061 * Called from PrintPreviewUI::OnGetInitiatorTabTitle as a result of sending a | |
1062 * 'getInitiatorTabTitle' message. | |
1063 * @param {string} initiatorTabTitle The title of the initiator tab. | 1074 * @param {string} initiatorTabTitle The title of the initiator tab. |
1064 */ | 1075 */ |
1065 function setInitiatorTabTitle(initiatorTabTitle) { | 1076 function setInitiatorTabTitle(initiatorTabTitle) { |
1066 if (initiatorTabTitle == '') | 1077 if (initiatorTabTitle == '') |
1067 return; | 1078 return; |
1068 document.title = localStrings.getStringF( | 1079 document.title = localStrings.getStringF( |
1069 'printPreviewTitleFormat', initiatorTabTitle); | 1080 'printPreviewTitleFormat', initiatorTabTitle); |
1070 } | 1081 } |
1071 | 1082 |
1072 /** | 1083 /** |
(...skipping 27 matching lines...) Expand all Loading... |
1100 <include src="copies_settings.js"/> | 1111 <include src="copies_settings.js"/> |
1101 <include src="header_footer_settings.js"/> | 1112 <include src="header_footer_settings.js"/> |
1102 <include src="layout_settings.js"/> | 1113 <include src="layout_settings.js"/> |
1103 <include src="color_settings.js"/> | 1114 <include src="color_settings.js"/> |
1104 <include src="margin_settings.js"/> | 1115 <include src="margin_settings.js"/> |
1105 <include src="margin_textbox.js"/> | 1116 <include src="margin_textbox.js"/> |
1106 <include src="margin_utils.js"/> | 1117 <include src="margin_utils.js"/> |
1107 <include src="margins_ui.js"/> | 1118 <include src="margins_ui.js"/> |
1108 <include src="margins_ui_pair.js"/> | 1119 <include src="margins_ui_pair.js"/> |
1109 <include src="preview_area.js"/> | 1120 <include src="preview_area.js"/> |
OLD | NEW |