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 | 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 console.log(initialSettings); | |
|
kmadhusu
2011/11/10 18:39:56
nit: remove console.log
dpapad
2011/11/10 20:04:01
Done.
| |
| 177 setInitiatorTabTitle(initialSettings['initiatorTabTitle']); | |
| 178 previewModifiable = initialSettings['previewModifiable']; | |
| 179 if (previewModifiable) { | |
| 180 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem( | |
| 181 initialSettings['numberFormat'], | |
| 182 initialSettings['measurementSystem']); | |
| 183 marginSettings.setLastUsedMargins(initialSettings); | |
| 184 } | |
| 185 setDefaultPrinter(initialSettings['printerName'], | |
| 186 initialSettings['cloudPrintData']); | |
| 187 } | |
| 188 | |
| 189 /** | |
| 173 * Disables the input elements in the sidebar. | 190 * Disables the input elements in the sidebar. |
| 174 */ | 191 */ |
| 175 function disableInputElementsInSidebar() { | 192 function disableInputElementsInSidebar() { |
| 176 var els = $('navbar-container').querySelectorAll('input, button, select'); | 193 var els = $('navbar-container').querySelectorAll('input, button, select'); |
| 177 for (var i = 0; i < els.length; i++) { | 194 for (var i = 0; i < els.length; i++) { |
| 178 if (els[i] == printHeader.cancelButton) | 195 if (els[i] == printHeader.cancelButton) |
| 179 continue; | 196 continue; |
| 180 els[i].disabled = true; | 197 els[i].disabled = true; |
| 181 } | 198 } |
| 182 } | 199 } |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 571 disableInputElementsInSidebar(); | 588 disableInputElementsInSidebar(); |
| 572 previewArea.showCustomMessage( | 589 previewArea.showCustomMessage( |
| 573 localStrings.getString('printingToPDFInProgress')); | 590 localStrings.getString('printingToPDFInProgress')); |
| 574 } | 591 } |
| 575 | 592 |
| 576 /** | 593 /** |
| 577 * Set the default printer. If there is one, generate a print preview. | 594 * Set the default printer. If there is one, generate a print preview. |
| 578 * @param {string} printer Name of the default printer. Empty if none. | 595 * @param {string} printer Name of the default printer. Empty if none. |
| 579 * @param {string} cloudPrintData Cloud print related data to restore if | 596 * @param {string} cloudPrintData Cloud print related data to restore if |
| 580 * the default printer is a cloud printer. | 597 * 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 */ | 598 */ |
| 584 function setDefaultPrinter(printer_name, cloudPrintData, lastUsedMarginsType) { | 599 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. | 600 // Add a placeholder value so the printer list looks valid. |
| 588 addDestinationListOption('', '', true, true, true); | 601 addDestinationListOption('', '', true, true, true); |
| 589 if (printer_name) { | 602 if (printerName) { |
| 590 defaultOrLastUsedPrinterName = printer_name; | 603 defaultOrLastUsedPrinterName = printerName; |
| 591 if (cloudPrintData) { | 604 if (cloudPrintData) { |
| 592 cloudprint.setDefaultPrinter(printer_name, | 605 cloudprint.setDefaultPrinter(printerName, |
| 593 cloudPrintData, | 606 cloudPrintData, |
| 594 addDestinationListOptionAtPosition, | 607 addDestinationListOptionAtPosition, |
| 595 doUpdateCloudPrinterCapabilities); | 608 doUpdateCloudPrinterCapabilities); |
| 596 } else { | 609 } else { |
| 597 $('printer-list')[0].value = defaultOrLastUsedPrinterName; | 610 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
| 598 updateControlsWithSelectedPrinterCapabilities(); | 611 updateControlsWithSelectedPrinterCapabilities(); |
| 599 } | 612 } |
| 600 } | 613 } |
| 601 chrome.send('getPrinters'); | 614 chrome.send('getPrinters'); |
| 602 } | 615 } |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 | 785 |
| 773 function setPluginPreviewPageCount() { | 786 function setPluginPreviewPageCount() { |
| 774 $('pdf-viewer').printPreviewPageCount( | 787 $('pdf-viewer').printPreviewPageCount( |
| 775 pageSettings.previouslySelectedPages.length); | 788 pageSettings.previouslySelectedPages.length); |
| 776 } | 789 } |
| 777 | 790 |
| 778 /** | 791 /** |
| 779 * Update the page count and check the page range. | 792 * Update the page count and check the page range. |
| 780 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 793 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| 781 * @param {number} pageCount The number of pages. | 794 * @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 | 795 * @param {number} previewResponseId The preview request id that resulted in |
| 785 * this response. | 796 * this response. |
| 786 */ | 797 */ |
| 787 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { | 798 function onDidGetPreviewPageCount(pageCount, previewResponseId) { |
| 788 if (!isExpectedPreviewResponse(previewResponseId)) | 799 if (!isExpectedPreviewResponse(previewResponseId)) |
| 789 return; | 800 return; |
| 790 pageSettings.updateState(pageCount); | 801 pageSettings.updateState(pageCount); |
| 791 previewModifiable = isModifiable; | |
| 792 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 802 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
| 793 return; | 803 return; |
| 794 | 804 |
| 795 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); | 805 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 796 } | 806 } |
| 797 | 807 |
| 798 /** | 808 /** |
| 799 * @param {printing::PageSizeMargins} pageLayout The default layout of the page | 809 * @param {printing::PageSizeMargins} pageLayout The default layout of the page |
| 800 * in points. | 810 * in points. |
| 801 */ | 811 */ |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 * Takes a snapshot of the print settings. | 1061 * Takes a snapshot of the print settings. |
| 1052 */ | 1062 */ |
| 1053 PrintSettings.prototype.save = function() { | 1063 PrintSettings.prototype.save = function() { |
| 1054 this.deviceName = getSelectedPrinterName(); | 1064 this.deviceName = getSelectedPrinterName(); |
| 1055 this.isLandscape = layoutSettings.isLandscape(); | 1065 this.isLandscape = layoutSettings.isLandscape(); |
| 1056 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); | 1066 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); |
| 1057 } | 1067 } |
| 1058 | 1068 |
| 1059 /** | 1069 /** |
| 1060 * Updates the title of the print preview tab according to |initiatorTabTitle|. | 1070 * 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. | 1071 * @param {string} initiatorTabTitle The title of the initiator tab. |
| 1064 */ | 1072 */ |
| 1065 function setInitiatorTabTitle(initiatorTabTitle) { | 1073 function setInitiatorTabTitle(initiatorTabTitle) { |
| 1066 if (initiatorTabTitle == '') | 1074 if (initiatorTabTitle == '') |
| 1067 return; | 1075 return; |
| 1068 document.title = localStrings.getStringF( | 1076 document.title = localStrings.getStringF( |
| 1069 'printPreviewTitleFormat', initiatorTabTitle); | 1077 'printPreviewTitleFormat', initiatorTabTitle); |
| 1070 } | 1078 } |
| 1071 | 1079 |
| 1072 /** | 1080 /** |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1100 <include src="copies_settings.js"/> | 1108 <include src="copies_settings.js"/> |
| 1101 <include src="header_footer_settings.js"/> | 1109 <include src="header_footer_settings.js"/> |
| 1102 <include src="layout_settings.js"/> | 1110 <include src="layout_settings.js"/> |
| 1103 <include src="color_settings.js"/> | 1111 <include src="color_settings.js"/> |
| 1104 <include src="margin_settings.js"/> | 1112 <include src="margin_settings.js"/> |
| 1105 <include src="margin_textbox.js"/> | 1113 <include src="margin_textbox.js"/> |
| 1106 <include src="margin_utils.js"/> | 1114 <include src="margin_utils.js"/> |
| 1107 <include src="margins_ui.js"/> | 1115 <include src="margins_ui.js"/> |
| 1108 <include src="margins_ui_pair.js"/> | 1116 <include src="margins_ui_pair.js"/> |
| 1109 <include src="preview_area.js"/> | 1117 <include src="preview_area.js"/> |
| OLD | NEW |