Chromium Code Reviews| 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 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 chrome.send('getInitiatorTabTitle'); |
| 167 chrome.send('getDefaultPrinter'); | 167 serializeRequests(); |
| 168 chrome.send('getNumberFormatAndMeasurementSystem'); | 168 chrome.send('getNumberFormatAndMeasurementSystem'); |
| 169 } | 169 } |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * Serializes requests |getNumberFormatAndMeasurementSystem|, | |
| 173 * |getLastUsedMarginSettings| and |getDefaultPrinter|. It guarantees that | |
| 174 * responses to those requests will arrive in the order requested. | |
| 175 */ | |
| 176 function serializeRequests() { | |
|
kmadhusu
2011/11/03 17:35:38
If the source is pdf, we will not display margin s
vandebo (ex-Chrome)
2011/11/03 18:07:27
serializeRequests is a pretty generic name... May
| |
| 177 var oldSetNumberFormatAndMeasurementSystem = | |
| 178 print_preview.setNumberFormatAndMeasurementSystem; | |
| 179 print_preview.setNumberFormatAndMeasurementSystem = | |
| 180 function(numberFormat, measurementSystem) { | |
| 181 oldSetNumberFormatAndMeasurementSystem(numberFormat, measurementSystem); | |
| 182 chrome.send('getLastUsedMarginSettings'); | |
| 183 }; | |
| 184 var oldSetLastUsedMargins = | |
| 185 print_preview.setLastUsedMargins.bind(marginSettings); | |
| 186 print_preview.setLastUsedMargins = function ( | |
| 187 lastUsedMarginType, lastUsedMargins) { | |
| 188 oldSetLastUsedMargins(lastUsedMarginType, lastUsedMargins); | |
| 189 chrome.send('getDefaultPrinter'); | |
| 190 }; | |
| 191 } | |
| 192 | |
| 193 /** | |
| 172 * Disables the input elements in the sidebar. | 194 * Disables the input elements in the sidebar. |
| 173 */ | 195 */ |
| 174 function disableInputElementsInSidebar() { | 196 function disableInputElementsInSidebar() { |
| 175 var els = $('sidebar').querySelectorAll('input, button, select'); | 197 var els = $('sidebar').querySelectorAll('input, button, select'); |
| 176 for (var i = 0; i < els.length; i++) { | 198 for (var i = 0; i < els.length; i++) { |
| 177 if (els[i] == printHeader.cancelButton) | 199 if (els[i] == printHeader.cancelButton) |
| 178 continue; | 200 continue; |
| 179 els[i].disabled = true; | 201 els[i].disabled = true; |
| 180 } | 202 } |
| 181 } | 203 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 sendPrintDocumentRequest(); | 298 sendPrintDocumentRequest(); |
| 277 } else { | 299 } else { |
| 278 // This message will call back to 'updateWithPrinterCapabilities' | 300 // This message will call back to 'updateWithPrinterCapabilities' |
| 279 // function. | 301 // function. |
| 280 chrome.send('getPrinterCapabilities', [selectedValue]); | 302 chrome.send('getPrinterCapabilities', [selectedValue]); |
| 281 } | 303 } |
| 282 if (!skip_refresh) { | 304 if (!skip_refresh) { |
| 283 lastSelectedPrinterIndex = selectedIndex; | 305 lastSelectedPrinterIndex = selectedIndex; |
| 284 | 306 |
| 285 // Regenerate the preview data based on selected printer settings. | 307 // Regenerate the preview data based on selected printer settings. |
| 286 setDefaultValuesAndRegeneratePreview(true); | 308 setDefaultValuesAndRegeneratePreview(false); |
| 287 } | 309 } |
| 288 } | 310 } |
| 289 | 311 |
| 290 /** | 312 /** |
| 291 * Helper function to do the actual work of updating cloud printer | 313 * Helper function to do the actual work of updating cloud printer |
| 292 * capabilities. | 314 * capabilities. |
| 293 * @param {Object} printer The printer object to set capabilities for. | 315 * @param {Object} printer The printer object to set capabilities for. |
| 294 */ | 316 */ |
| 295 function doUpdateCloudPrinterCapabilities(printer) { | 317 function doUpdateCloudPrinterCapabilities(printer) { |
| 296 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), | 318 var settings = {'disableColorOption': !cloudprint.supportsColor(printer), |
| 297 'setColorAsDefault': cloudprint.colorIsDefault(printer), | 319 'setColorAsDefault': cloudprint.colorIsDefault(printer), |
| 298 'disableCopiesOption': true, | 320 'disableCopiesOption': true, |
| 299 'disableLandscapeOption': true}; | 321 'disableLandscapeOption': true}; |
| 300 updateWithPrinterCapabilities(settings); | 322 updateWithPrinterCapabilities(settings); |
| 301 var printerList = $('printer-list'); | 323 var printerList = $('printer-list'); |
| 302 var selectedIndex = printerList.selectedIndex; | 324 var selectedIndex = printerList.selectedIndex; |
| 303 lastSelectedPrinterIndex = selectedIndex; | 325 lastSelectedPrinterIndex = selectedIndex; |
| 304 | 326 |
| 305 // Regenerate the preview data based on selected printer settings. | 327 // Regenerate the preview data based on selected printer settings. |
| 306 setDefaultValuesAndRegeneratePreview(true); | 328 setDefaultValuesAndRegeneratePreview(false); |
| 307 } | 329 } |
| 308 | 330 |
| 309 /** | 331 /** |
| 310 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the | 332 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the |
| 311 * capabilities of the currently selected printer. It is called from C++ too. | 333 * capabilities of the currently selected printer. It is called from C++ too. |
| 312 * @param {Object} settingInfo printer setting information. | 334 * @param {Object} settingInfo printer setting information. |
| 313 */ | 335 */ |
| 314 function updateWithPrinterCapabilities(settingInfo) { | 336 function updateWithPrinterCapabilities(settingInfo) { |
| 315 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); | 337 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
| 316 customEvent.printerCapabilities = settingInfo; | 338 customEvent.printerCapabilities = settingInfo; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 disableInputElementsInSidebar(); | 592 disableInputElementsInSidebar(); |
| 571 previewArea.showCustomMessage( | 593 previewArea.showCustomMessage( |
| 572 localStrings.getString('printingToPDFInProgress')); | 594 localStrings.getString('printingToPDFInProgress')); |
| 573 } | 595 } |
| 574 | 596 |
| 575 /** | 597 /** |
| 576 * Set the default printer. If there is one, generate a print preview. | 598 * Set the default printer. If there is one, generate a print preview. |
| 577 * @param {string} printer Name of the default printer. Empty if none. | 599 * @param {string} printer Name of the default printer. Empty if none. |
| 578 * @param {string} cloudPrintData Cloud print related data to restore if | 600 * @param {string} cloudPrintData Cloud print related data to restore if |
| 579 * the default printer is a cloud printer. | 601 * 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 */ | 602 */ |
| 583 function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) { | 603 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. | 604 // Add a placeholder value so the printer list looks valid. |
| 587 addDestinationListOption('', '', true, true, true); | 605 addDestinationListOption('', '', true, true, true); |
| 588 if (printer_name) { | 606 if (printer_name) { |
| 589 defaultOrLastUsedPrinterName = printer_name; | 607 defaultOrLastUsedPrinterName = printer_name; |
| 590 if (cloudPrintData) { | 608 if (cloudPrintData) { |
| 591 cloudprint.setDefaultPrinter(printer_name, | 609 cloudprint.setDefaultPrinter(printer_name, |
| 592 cloudPrintData, | 610 cloudPrintData, |
| 593 addDestinationListOptionAtPosition, | 611 addDestinationListOptionAtPosition, |
| 594 doUpdateCloudPrinterCapabilities); | 612 doUpdateCloudPrinterCapabilities); |
| 595 } else { | 613 } else { |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 <include src="copies_settings.js"/> | 1117 <include src="copies_settings.js"/> |
| 1100 <include src="header_footer_settings.js"/> | 1118 <include src="header_footer_settings.js"/> |
| 1101 <include src="layout_settings.js"/> | 1119 <include src="layout_settings.js"/> |
| 1102 <include src="color_settings.js"/> | 1120 <include src="color_settings.js"/> |
| 1103 <include src="margin_settings.js"/> | 1121 <include src="margin_settings.js"/> |
| 1104 <include src="margin_textbox.js"/> | 1122 <include src="margin_textbox.js"/> |
| 1105 <include src="margin_utils.js"/> | 1123 <include src="margin_utils.js"/> |
| 1106 <include src="margins_ui.js"/> | 1124 <include src="margins_ui.js"/> |
| 1107 <include src="margins_ui_pair.js"/> | 1125 <include src="margins_ui_pair.js"/> |
| 1108 <include src="preview_area.js"/> | 1126 <include src="preview_area.js"/> |
| OLD | NEW |