| 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 | 156 |
| 157 pageSettings = print_preview.PageSettings.getInstance(); | 157 pageSettings = print_preview.PageSettings.getInstance(); |
| 158 copiesSettings = print_preview.CopiesSettings.getInstance(); | 158 copiesSettings = print_preview.CopiesSettings.getInstance(); |
| 159 layoutSettings = print_preview.LayoutSettings.getInstance(); | 159 layoutSettings = print_preview.LayoutSettings.getInstance(); |
| 160 marginSettings = print_preview.MarginSettings.getInstance(); | 160 marginSettings = print_preview.MarginSettings.getInstance(); |
| 161 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 161 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
| 162 colorSettings = print_preview.ColorSettings.getInstance(); | 162 colorSettings = print_preview.ColorSettings.getInstance(); |
| 163 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 163 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
| 164 | 164 |
| 165 previewArea.showLoadingAnimation(); | 165 previewArea.showLoadingAnimation(); |
| 166 chrome.send('getInitiatorTabTitle'); | 166 serializeRequests(); |
| 167 chrome.send('getDefaultPrinter'); | 167 chrome.send('getInitialSettings'); |
| 168 chrome.send('getNumberFormatAndMeasurementSystem'); | |
| 169 } | 168 } |
| 170 | 169 |
| 171 /** | 170 /** |
| 171 * Serializes requests |getNumberFormatAndMeasurementSystem|, |
| 172 * |getLastUsedMarginSettings| and |getDefaultPrinter|. It guarantees that |
| 173 * responses to those requests will arrive in the order requested. |
| 174 */ |
| 175 function serializeRequests() { |
| 176 var oldSetInitialSettings = setInitialSettings; |
| 177 setInitialSettings = function setInitialSettings(initiatorTabTitle, |
| 178 numberFormat, measurementSystem, lastUsedMarginType, |
| 179 lastUsedCustomMargins, isModifiable) { |
| 180 oldSetInitialSettings(initiatorTabTitle, numberFormat, measurementSystem, |
| 181 lastUsedMarginType, lastUsedCustomMargins, isModifiable); |
| 182 chrome.send('getDefaultPrinter'); |
| 183 }; |
| 184 } |
| 185 |
| 186 /** |
| 187 * @param {string} initiatorTabTitle The title of the initiator tab. |
| 188 * @param {string} numberFormat Look at |
| 189 * |MarginSettings.setNumberFormatAndMeasurementSystem| for documentation. |
| 190 * @param {numner} measurementSystem Look at |
| 191 * |MarginSettings.setNumberFormatAndMeasurementSystem| for documentation. |
| 192 * @param {number} lastUsedMarginType Look at |
| 193 * |MarginSettings.setLastUsedMargins| for documentation. |
| 194 * @param {object} lastUsedCustomMargins Look at |
| 195 * |MarginSettings.setLastUsedMargins| for documentation. |
| 196 * @param {boolean} isModifiable Indicates whether the previewed document |
| 197 * can be modified. |
| 198 */ |
| 199 function setInitialSettings(initiatorTabTitle, numberFormat, measurementSystem, |
| 200 lastUsedMarginType, lastUsedCustomMargins, |
| 201 isModifiable) { |
| 202 setInitiatorTabTitle(initiatorTabTitle); |
| 203 previewModifiable = isModifiable; |
| 204 if (previewModifiable) { |
| 205 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem( |
| 206 numberFormat, measurementSystem); |
| 207 marginSettings.setLastUsedMargins(lastUsedMarginType, |
| 208 lastUsedCustomMargins); |
| 209 } |
| 210 } |
| 211 |
| 212 /** |
| 172 * Disables the input elements in the sidebar. | 213 * Disables the input elements in the sidebar. |
| 173 */ | 214 */ |
| 174 function disableInputElementsInSidebar() { | 215 function disableInputElementsInSidebar() { |
| 175 var els = $('sidebar').querySelectorAll('input, button, select'); | 216 var els = $('sidebar').querySelectorAll('input, button, select'); |
| 176 for (var i = 0; i < els.length; i++) { | 217 for (var i = 0; i < els.length; i++) { |
| 177 if (els[i] == printHeader.cancelButton) | 218 if (els[i] == printHeader.cancelButton) |
| 178 continue; | 219 continue; |
| 179 els[i].disabled = true; | 220 els[i].disabled = true; |
| 180 } | 221 } |
| 181 } | 222 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 sendPrintDocumentRequest(); | 317 sendPrintDocumentRequest(); |
| 277 } else { | 318 } else { |
| 278 // This message will call back to 'updateWithPrinterCapabilities' | 319 // This message will call back to 'updateWithPrinterCapabilities' |
| 279 // function. | 320 // function. |
| 280 chrome.send('getPrinterCapabilities', [selectedValue]); | 321 chrome.send('getPrinterCapabilities', [selectedValue]); |
| 281 } | 322 } |
| 282 if (!skip_refresh) { | 323 if (!skip_refresh) { |
| 283 lastSelectedPrinterIndex = selectedIndex; | 324 lastSelectedPrinterIndex = selectedIndex; |
| 284 | 325 |
| 285 // Regenerate the preview data based on selected printer settings. | 326 // Regenerate the preview data based on selected printer settings. |
| 286 setDefaultValuesAndRegeneratePreview(true); | 327 setDefaultValuesAndRegeneratePreview(false); |
| 287 } | 328 } |
| 288 } | 329 } |
| 289 | 330 |
| 290 /** | 331 /** |
| 291 * Helper function to do the actual work of updating cloud printer | 332 * Helper function to do the actual work of updating cloud printer |
| 292 * capabilities. | 333 * capabilities. |
| 293 * @param {Object} printer The printer object to set capabilities for. | 334 * @param {Object} printer The printer object to set capabilities for. |
| 294 */ | 335 */ |
| 295 function doUpdateCloudPrinterCapabilities(printer) { | 336 function doUpdateCloudPrinterCapabilities(printer) { |
| 296 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), | 337 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), |
| 297 'setColorAsDefault': cloudprint.colorIsDefault(printer), | 338 'setColorAsDefault': cloudprint.colorIsDefault(printer), |
| 298 'disableCopiesOption': true, | 339 'disableCopiesOption': true, |
| 299 'disableLandscapeOption': true}; | 340 'disableLandscapeOption': true}; |
| 300 updateWithPrinterCapabilities(settings); | 341 updateWithPrinterCapabilities(settings); |
| 301 var printerList = $('printer-list'); | 342 var printerList = $('printer-list'); |
| 302 var selectedIndex = printerList.selectedIndex; | 343 var selectedIndex = printerList.selectedIndex; |
| 303 lastSelectedPrinterIndex = selectedIndex; | 344 lastSelectedPrinterIndex = selectedIndex; |
| 304 | 345 |
| 305 // Regenerate the preview data based on selected printer settings. | 346 // Regenerate the preview data based on selected printer settings. |
| 306 setDefaultValuesAndRegeneratePreview(true); | 347 setDefaultValuesAndRegeneratePreview(false); |
| 307 } | 348 } |
| 308 | 349 |
| 309 /** | 350 /** |
| 310 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the | 351 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the |
| 311 * capabilities of the currently selected printer. It is called from C++ too. | 352 * capabilities of the currently selected printer. It is called from C++ too. |
| 312 * @param {Object} settingInfo printer setting information. | 353 * @param {Object} settingInfo printer setting information. |
| 313 */ | 354 */ |
| 314 function updateWithPrinterCapabilities(settingInfo) { | 355 function updateWithPrinterCapabilities(settingInfo) { |
| 315 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); | 356 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
| 316 customEvent.printerCapabilities = settingInfo; | 357 customEvent.printerCapabilities = settingInfo; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 disableInputElementsInSidebar(); | 611 disableInputElementsInSidebar(); |
| 571 previewArea.showCustomMessage( | 612 previewArea.showCustomMessage( |
| 572 localStrings.getString('printingToPDFInProgress')); | 613 localStrings.getString('printingToPDFInProgress')); |
| 573 } | 614 } |
| 574 | 615 |
| 575 /** | 616 /** |
| 576 * Set the default printer. If there is one, generate a print preview. | 617 * Set the default printer. If there is one, generate a print preview. |
| 577 * @param {string} printer Name of the default printer. Empty if none. | 618 * @param {string} printer Name of the default printer. Empty if none. |
| 578 * @param {string} cloudPrintData Cloud print related data to restore if | 619 * @param {string} cloudPrintData Cloud print related data to restore if |
| 579 * the default printer is a cloud printer. | 620 * the default printer is a cloud printer. |
| 580 * @param {number} lastUsedMarginsType Indicates the last used margins type | |
| 581 * (matches enum MarginType in printing/print_job_constants.h. | |
| 582 */ | 621 */ |
| 583 function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) { | 622 function setDefaultPrinter(printer_name, cloudPrintData) { |
| 584 // Setting the margin selection to the last used one. | |
| 585 marginSettings.setLastUsedMarginsType(lastUsedMarginsType); | |
| 586 // Add a placeholder value so the printer list looks valid. | 623 // Add a placeholder value so the printer list looks valid. |
| 587 addDestinationListOption('', '', true, true, true); | 624 addDestinationListOption('', '', true, true, true); |
| 588 if (printer_name) { | 625 if (printer_name) { |
| 589 defaultOrLastUsedPrinterName = printer_name; | 626 defaultOrLastUsedPrinterName = printer_name; |
| 590 if (cloudPrintData) { | 627 if (cloudPrintData) { |
| 591 cloudprint.setDefaultPrinter(printer_name, | 628 cloudprint.setDefaultPrinter(printer_name, |
| 592 cloudPrintData, | 629 cloudPrintData, |
| 593 addDestinationListOptionAtPosition, | 630 addDestinationListOptionAtPosition, |
| 594 doUpdateCloudPrinterCapabilities); | 631 doUpdateCloudPrinterCapabilities); |
| 595 } else { | 632 } else { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 808 |
| 772 function setPluginPreviewPageCount() { | 809 function setPluginPreviewPageCount() { |
| 773 $('pdf-viewer').printPreviewPageCount( | 810 $('pdf-viewer').printPreviewPageCount( |
| 774 pageSettings.previouslySelectedPages.length); | 811 pageSettings.previouslySelectedPages.length); |
| 775 } | 812 } |
| 776 | 813 |
| 777 /** | 814 /** |
| 778 * Update the page count and check the page range. | 815 * Update the page count and check the page range. |
| 779 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 816 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| 780 * @param {number} pageCount The number of pages. | 817 * @param {number} pageCount The number of pages. |
| 781 * @param {boolean} isModifiable Indicates whether the previewed document can be | |
| 782 * modified. | |
| 783 * @param {number} previewResponseId The preview request id that resulted in | 818 * @param {number} previewResponseId The preview request id that resulted in |
| 784 * this response. | 819 * this response. |
| 785 */ | 820 */ |
| 786 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { | 821 function onDidGetPreviewPageCount(pageCount, previewResponseId) { |
| 787 if (!isExpectedPreviewResponse(previewResponseId)) | 822 if (!isExpectedPreviewResponse(previewResponseId)) |
| 788 return; | 823 return; |
| 789 pageSettings.updateState(pageCount); | 824 pageSettings.updateState(pageCount); |
| 790 previewModifiable = isModifiable; | |
| 791 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 825 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
| 792 return; | 826 return; |
| 793 | 827 |
| 794 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); | 828 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 795 } | 829 } |
| 796 | 830 |
| 797 /** | 831 /** |
| 798 * @param {printing::PageSizeMargins} pageLayout The default layout of the page | 832 * @param {printing::PageSizeMargins} pageLayout The default layout of the page |
| 799 * in points. | 833 * in points. |
| 800 */ | 834 */ |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1050 * Takes a snapshot of the print settings. | 1084 * Takes a snapshot of the print settings. |
| 1051 */ | 1085 */ |
| 1052 PrintSettings.prototype.save = function() { | 1086 PrintSettings.prototype.save = function() { |
| 1053 this.deviceName = getSelectedPrinterName(); | 1087 this.deviceName = getSelectedPrinterName(); |
| 1054 this.isLandscape = layoutSettings.isLandscape(); | 1088 this.isLandscape = layoutSettings.isLandscape(); |
| 1055 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); | 1089 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); |
| 1056 } | 1090 } |
| 1057 | 1091 |
| 1058 /** | 1092 /** |
| 1059 * Updates the title of the print preview tab according to |initiatorTabTitle|. | 1093 * Updates the title of the print preview tab according to |initiatorTabTitle|. |
| 1060 * Called from PrintPreviewUI::OnGetInitiatorTabTitle as a result of sending a | |
| 1061 * 'getInitiatorTabTitle' message. | |
| 1062 * @param {string} initiatorTabTitle The title of the initiator tab. | 1094 * @param {string} initiatorTabTitle The title of the initiator tab. |
| 1063 */ | 1095 */ |
| 1064 function setInitiatorTabTitle(initiatorTabTitle) { | 1096 function setInitiatorTabTitle(initiatorTabTitle) { |
| 1065 if (initiatorTabTitle == '') | 1097 if (initiatorTabTitle == '') |
| 1066 return; | 1098 return; |
| 1067 document.title = localStrings.getStringF( | 1099 document.title = localStrings.getStringF( |
| 1068 'printPreviewTitleFormat', initiatorTabTitle); | 1100 'printPreviewTitleFormat', initiatorTabTitle); |
| 1069 } | 1101 } |
| 1070 | 1102 |
| 1071 /** | 1103 /** |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1099 <include src="copies_settings.js"/> | 1131 <include src="copies_settings.js"/> |
| 1100 <include src="header_footer_settings.js"/> | 1132 <include src="header_footer_settings.js"/> |
| 1101 <include src="layout_settings.js"/> | 1133 <include src="layout_settings.js"/> |
| 1102 <include src="color_settings.js"/> | 1134 <include src="color_settings.js"/> |
| 1103 <include src="margin_settings.js"/> | 1135 <include src="margin_settings.js"/> |
| 1104 <include src="margin_textbox.js"/> | 1136 <include src="margin_textbox.js"/> |
| 1105 <include src="margin_utils.js"/> | 1137 <include src="margin_utils.js"/> |
| 1106 <include src="margins_ui.js"/> | 1138 <include src="margins_ui.js"/> |
| 1107 <include src="margins_ui_pair.js"/> | 1139 <include src="margins_ui_pair.js"/> |
| 1108 <include src="preview_area.js"/> | 1140 <include src="preview_area.js"/> |
| OLD | NEW |