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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 MARGINS_MAY_HAVE_CHANGED: 'marginsMayHaveChanged', | 118 MARGINS_MAY_HAVE_CHANGED: 'marginsMayHaveChanged', |
119 // Fired when a pdf generation related error occurs. | 119 // Fired when a pdf generation related error occurs. |
120 PDF_GENERATION_ERROR: 'PDFGenerationError', | 120 PDF_GENERATION_ERROR: 'PDFGenerationError', |
121 // Fired once the first page of the pdf document is loaded in the plugin. | 121 // Fired once the first page of the pdf document is loaded in the plugin. |
122 PDF_LOADED: 'PDFLoaded', | 122 PDF_LOADED: 'PDFLoaded', |
123 // Fired when the selected printer capabilities change. | 123 // Fired when the selected printer capabilities change. |
124 PRINTER_CAPABILITIES_UPDATED: 'printerCapabilitiesUpdated', | 124 PRINTER_CAPABILITIES_UPDATED: 'printerCapabilitiesUpdated', |
125 // Fired when the print button needs to be updated. | 125 // Fired when the print button needs to be updated. |
126 UPDATE_PRINT_BUTTON: 'updatePrintButton', | 126 UPDATE_PRINT_BUTTON: 'updatePrintButton', |
127 // Fired when the print summary needs to be updated. | 127 // Fired when the print summary needs to be updated. |
128 UPDATE_SUMMARY: 'updateSummary', | 128 UPDATE_SUMMARY: 'updateSummary' |
129 } | 129 }; |
130 | 130 |
131 /** | 131 /** |
132 * Window onload handler, sets up the page and starts print preview by getting | 132 * Window onload handler, sets up the page and starts print preview by getting |
133 * the printer list. | 133 * the printer list. |
134 */ | 134 */ |
135 function onLoad() { | 135 function onLoad() { |
136 cr.enablePlatformSpecificCSSRules(); | 136 cr.enablePlatformSpecificCSSRules(); |
137 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); | 137 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); |
138 lastPreviewRequestID = initialPreviewRequestID; | 138 lastPreviewRequestID = initialPreviewRequestID; |
139 | 139 |
(...skipping 28 matching lines...) Expand all Loading... |
168 marginSettings = print_preview.MarginSettings.getInstance(); | 168 marginSettings = print_preview.MarginSettings.getInstance(); |
169 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 169 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
170 colorSettings = print_preview.ColorSettings.getInstance(); | 170 colorSettings = print_preview.ColorSettings.getInstance(); |
171 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 171 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
172 | 172 |
173 previewArea.showLoadingAnimation(); | 173 previewArea.showLoadingAnimation(); |
174 chrome.send('getInitialSettings'); | 174 chrome.send('getInitialSettings'); |
175 } | 175 } |
176 | 176 |
177 /** | 177 /** |
178 * @param {string} initiatorTabTitle The title of the initiator tab. | |
179 * @param {object} initialSettings An object containing all the initial | 178 * @param {object} initialSettings An object containing all the initial |
180 * settings. | 179 * settings. |
181 */ | 180 */ |
182 function setInitialSettings(initialSettings) { | 181 function setInitialSettings(initialSettings) { |
183 setInitiatorTabTitle(initialSettings['initiatorTabTitle']); | 182 setInitiatorTabTitle(initialSettings['initiatorTabTitle']); |
184 previewModifiable = initialSettings['previewModifiable']; | 183 previewModifiable = initialSettings['previewModifiable']; |
185 if (previewModifiable) { | 184 if (previewModifiable) { |
186 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem( | 185 print_preview.MarginSettings.setNumberFormatAndMeasurementSystem( |
187 initialSettings['numberFormat'], | 186 initialSettings['numberFormat'], |
188 initialSettings['measurementSystem']); | 187 initialSettings['measurementSystem']); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 */ | 340 */ |
342 function reloadPrintersList() { | 341 function reloadPrintersList() { |
343 $('printer-list').length = 0; | 342 $('printer-list').length = 0; |
344 firstCloudPrintOptionPos = 0; | 343 firstCloudPrintOptionPos = 0; |
345 lastCloudPrintOptionPos = 0; | 344 lastCloudPrintOptionPos = 0; |
346 chrome.send('getPrinters'); | 345 chrome.send('getPrinters'); |
347 } | 346 } |
348 | 347 |
349 /** | 348 /** |
350 * Turn on the integration of Cloud Print. | 349 * Turn on the integration of Cloud Print. |
351 * @param {string} cloudPrintUrl The URL to use for cloud print servers. | 350 * @param {string} cloudPrintURL The URL to use for cloud print servers. |
352 */ | 351 */ |
353 function setUseCloudPrint(cloudPrintURL) { | 352 function setUseCloudPrint(cloudPrintURL) { |
354 useCloudPrint = true; | 353 useCloudPrint = true; |
355 cloudprint.setBaseURL(cloudPrintURL); | 354 cloudprint.setBaseURL(cloudPrintURL); |
356 } | 355 } |
357 | 356 |
358 /** | 357 /** |
359 * Take the PDF data handed to us and submit it to the cloud, closing the print | 358 * Take the PDF data handed to us and submit it to the cloud, closing the print |
360 * preview tab once the upload is successful. | 359 * preview tab once the upload is successful. |
361 * @param {string} data Data to send as the print job. | 360 * @param {string} data Data to send as the print job. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 function isExpectedPreviewResponse(previewResponseId) { | 468 function isExpectedPreviewResponse(previewResponseId) { |
470 return lastPreviewRequestID == previewResponseId; | 469 return lastPreviewRequestID == previewResponseId; |
471 } | 470 } |
472 | 471 |
473 /** | 472 /** |
474 * Returns the name of the selected printer or the empty string if no | 473 * Returns the name of the selected printer or the empty string if no |
475 * printer is selected. | 474 * printer is selected. |
476 * @return {string} The name of the currently selected printer. | 475 * @return {string} The name of the currently selected printer. |
477 */ | 476 */ |
478 function getSelectedPrinterName() { | 477 function getSelectedPrinterName() { |
479 var printerList = $('printer-list') | 478 var printerList = $('printer-list'); |
480 var selectedPrinter = printerList.selectedIndex; | 479 var selectedPrinter = printerList.selectedIndex; |
481 if (selectedPrinter < 0) | 480 if (selectedPrinter < 0) |
482 return ''; | 481 return ''; |
483 return printerList.options[selectedPrinter].value; | 482 return printerList.options[selectedPrinter].value; |
484 } | 483 } |
485 | 484 |
486 /** | 485 /** |
487 * Asks the browser to print the preview PDF based on current print | 486 * Asks the browser to print the preview PDF based on current print |
488 * settings. If the preview is still loading, printPendingFile() will get | 487 * settings. If the preview is still loading, printPendingFile() will get |
489 * called once the preview loads. | 488 * called once the preview loads. |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 function fileSelectionCompleted() { | 603 function fileSelectionCompleted() { |
605 // If the file selection is completed and the tab is not already closed it | 604 // If the file selection is completed and the tab is not already closed it |
606 // means that a pending print to pdf request exists. | 605 // means that a pending print to pdf request exists. |
607 disableInputElementsInSidebar(); | 606 disableInputElementsInSidebar(); |
608 previewArea.showCustomMessage( | 607 previewArea.showCustomMessage( |
609 localStrings.getString('printingToPDFInProgress')); | 608 localStrings.getString('printingToPDFInProgress')); |
610 } | 609 } |
611 | 610 |
612 /** | 611 /** |
613 * Set the default printer. If there is one, generate a print preview. | 612 * Set the default printer. If there is one, generate a print preview. |
614 * @param {string} printer Name of the default printer. Empty if none. | 613 * @param {string} printerName Name of the default printer. Empty if none. |
615 * @param {string} cloudPrintData Cloud print related data to restore if | 614 * @param {string} cloudPrintData Cloud print related data to restore if |
616 * the default printer is a cloud printer. | 615 * the default printer is a cloud printer. |
617 */ | 616 */ |
618 function setDefaultPrinter(printerName, cloudPrintData) { | 617 function setDefaultPrinter(printerName, cloudPrintData) { |
619 // Add a placeholder value so the printer list looks valid. | 618 // Add a placeholder value so the printer list looks valid. |
620 addDestinationListOption('', '', true, true, true); | 619 addDestinationListOption('', '', true, true, true); |
621 if (printerName) { | 620 if (printerName) { |
622 defaultOrLastUsedPrinterName = printerName; | 621 defaultOrLastUsedPrinterName = printerName; |
623 if (cloudPrintData) { | 622 if (cloudPrintData) { |
624 cloudprint.setDefaultPrinter(printerName, | 623 cloudprint.setDefaultPrinter(printerName, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 option.setAttribute('role', 'separator'); | 707 option.setAttribute('role', 'separator'); |
709 return option; | 708 return option; |
710 } | 709 } |
711 | 710 |
712 /** | 711 /** |
713 * Adds an option to the printer destination list. | 712 * Adds an option to the printer destination list. |
714 * @param {string} optionText specifies the option text content. | 713 * @param {string} optionText specifies the option text content. |
715 * @param {string} optionValue specifies the option value. | 714 * @param {string} optionValue specifies the option value. |
716 * @param {boolean} isDefault is true if the option needs to be selected. | 715 * @param {boolean} isDefault is true if the option needs to be selected. |
717 * @param {boolean} isDisabled is true if the option needs to be disabled. | 716 * @param {boolean} isDisabled is true if the option needs to be disabled. |
| 717 * @param {boolean} isSeparator is true if the option serves just as a |
| 718 * separator. |
718 * @return {Object} The created option. | 719 * @return {Object} The created option. |
719 */ | 720 */ |
720 function addDestinationListOption(optionText, optionValue, isDefault, | 721 function addDestinationListOption(optionText, optionValue, isDefault, |
721 isDisabled, isSeparator) { | 722 isDisabled, isSeparator) { |
722 var option = createDestinationListOption(optionText, | 723 var option = createDestinationListOption(optionText, |
723 optionValue, | 724 optionValue, |
724 isDefault, | 725 isDefault, |
725 isDisabled, | 726 isDisabled, |
726 isSeparator); | 727 isSeparator); |
727 $('printer-list').add(option); | 728 $('printer-list').add(option); |
728 return option; | 729 return option; |
729 } | 730 } |
730 | 731 |
731 /** | 732 /** |
732 * Adds an option to the printer destination list at a specified position. | 733 * Adds an option to the printer destination list at a specified position. |
733 * @param {number} position The index in the printer-list wher the option | 734 * @param {number} position The index in the printer-list wher the option |
734 should be created. | 735 should be created. |
735 * @param {string} optionText specifies the option text content. | 736 * @param {string} optionText specifies the option text content. |
736 * @param {string} optionValue specifies the option value. | 737 * @param {string} optionValue specifies the option value. |
737 * @param {boolean} isDefault is true if the option needs to be selected. | 738 * @param {boolean} isDefault is true if the option needs to be selected. |
738 * @param {boolean} isDisabled is true if the option needs to be disabled. | 739 * @param {boolean} isDisabled is true if the option needs to be disabled. |
| 740 * @param {boolean} isSeparator is true if the option is a visual separator and |
| 741 * needs to be disabled. |
739 * @return {Object} The created option. | 742 * @return {Object} The created option. |
740 */ | 743 */ |
741 function addDestinationListOptionAtPosition(position, | 744 function addDestinationListOptionAtPosition(position, |
742 optionText, | 745 optionText, |
743 optionValue, | 746 optionValue, |
744 isDefault, | 747 isDefault, |
745 isDisabled, | 748 isDisabled, |
746 isSeparator) { | 749 isSeparator) { |
747 var option = createDestinationListOption(optionText, | 750 var option = createDestinationListOption(optionText, |
748 optionValue, | 751 optionValue, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 * @param {number} previewResponseId The preview request id that resulted in | 873 * @param {number} previewResponseId The preview request id that resulted in |
871 * this response. | 874 * this response. |
872 */ | 875 */ |
873 function reloadPreviewPages(previewUid, previewResponseId) { | 876 function reloadPreviewPages(previewUid, previewResponseId) { |
874 if (!isExpectedPreviewResponse(previewResponseId)) | 877 if (!isExpectedPreviewResponse(previewResponseId)) |
875 return; | 878 return; |
876 | 879 |
877 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); | 880 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
878 checkAndHideOverlayLayerIfValid(); | 881 checkAndHideOverlayLayerIfValid(); |
879 var pageSet = pageSettings.previouslySelectedPages; | 882 var pageSet = pageSettings.previouslySelectedPages; |
880 for (var i = 0; i < pageSet.length; i++) | 883 for (var i = 0; i < pageSet.length; i++) { |
881 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); | 884 $('pdf-viewer').loadPreviewPage( |
| 885 getPageSrcURL(previewUid, pageSet[i] - 1), i); |
| 886 } |
882 | 887 |
883 hasPendingPreviewRequest = false; | 888 hasPendingPreviewRequest = false; |
884 isPrintReadyMetafileReady = true; | 889 isPrintReadyMetafileReady = true; |
885 previewArea.pdfLoaded = true; | 890 previewArea.pdfLoaded = true; |
886 sendPrintDocumentRequestIfNeeded(); | 891 sendPrintDocumentRequestIfNeeded(); |
887 } | 892 } |
888 | 893 |
889 /** | 894 /** |
890 * Notification that a print preview page has been rendered. | 895 * Notification that a print preview page has been rendered. |
891 * Check if the settings have changed and request a regeneration if needed. | 896 * Check if the settings have changed and request a regeneration if needed. |
(...skipping 29 matching lines...) Expand all Loading... |
921 hasPendingPreviewRequest = false; | 926 hasPendingPreviewRequest = false; |
922 if (pageIndex != 0) | 927 if (pageIndex != 0) |
923 sendPrintDocumentRequestIfNeeded(); | 928 sendPrintDocumentRequestIfNeeded(); |
924 } | 929 } |
925 } | 930 } |
926 | 931 |
927 /** | 932 /** |
928 * Update the print preview when new preview data is available. | 933 * Update the print preview when new preview data is available. |
929 * Create the PDF plugin as needed. | 934 * Create the PDF plugin as needed. |
930 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 935 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
931 * @param {boolean} modifiable If the preview is modifiable. | |
932 * @param {string} previewUid Preview unique identifier. | 936 * @param {string} previewUid Preview unique identifier. |
933 * @param {number} previewResponseId The preview request id that resulted in | 937 * @param {number} previewResponseId The preview request id that resulted in |
934 * this response. | 938 * this response. |
935 */ | 939 */ |
936 function updatePrintPreview(previewUid, previewResponseId) { | 940 function updatePrintPreview(previewUid, previewResponseId) { |
937 if (!isExpectedPreviewResponse(previewResponseId)) | 941 if (!isExpectedPreviewResponse(previewResponseId)) |
938 return; | 942 return; |
939 isPrintReadyMetafileReady = true; | 943 isPrintReadyMetafileReady = true; |
940 | 944 |
941 if (!previewModifiable) { | 945 if (!previewModifiable) { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 for (var i = 0; i < pluginInterface.length; i++) { | 1066 for (var i = 0; i < pluginInterface.length; i++) { |
1063 if (!pluginInterface[i]) | 1067 if (!pluginInterface[i]) |
1064 return false; | 1068 return false; |
1065 } | 1069 } |
1066 return true; | 1070 return true; |
1067 } | 1071 } |
1068 | 1072 |
1069 /** | 1073 /** |
1070 * Sets the default values and sends a request to regenerate preview data. | 1074 * Sets the default values and sends a request to regenerate preview data. |
1071 * Resets the margin options only if |resetMargins| is true. | 1075 * Resets the margin options only if |resetMargins| is true. |
| 1076 * @param {boolean} resetMargins True if margin settings should be resetted. |
1072 */ | 1077 */ |
1073 function setDefaultValuesAndRegeneratePreview(resetMargins) { | 1078 function setDefaultValuesAndRegeneratePreview(resetMargins) { |
1074 if (resetMargins) | 1079 if (resetMargins) |
1075 marginSettings.resetMarginsIfNeeded(); | 1080 marginSettings.resetMarginsIfNeeded(); |
1076 pageSettings.resetState(); | 1081 pageSettings.resetState(); |
1077 requestPrintPreview(); | 1082 requestPrintPreview(); |
1078 } | 1083 } |
1079 | 1084 |
1080 /** | 1085 /** |
1081 * Class that represents the state of the print settings. | 1086 * Class that represents the state of the print settings. |
1082 */ | 1087 */ |
1083 function PrintSettings() { | 1088 function PrintSettings() { |
1084 this.deviceName = ''; | 1089 this.deviceName = ''; |
1085 this.isLandscape = ''; | 1090 this.isLandscape = ''; |
1086 this.hasHeaderFooter = ''; | 1091 this.hasHeaderFooter = ''; |
1087 } | 1092 } |
1088 | 1093 |
1089 /** | 1094 /** |
1090 * Takes a snapshot of the print settings. | 1095 * Takes a snapshot of the print settings. |
1091 */ | 1096 */ |
1092 PrintSettings.prototype.save = function() { | 1097 PrintSettings.prototype.save = function() { |
1093 this.deviceName = getSelectedPrinterName(); | 1098 this.deviceName = getSelectedPrinterName(); |
1094 this.isLandscape = layoutSettings.isLandscape(); | 1099 this.isLandscape = layoutSettings.isLandscape(); |
1095 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); | 1100 this.hasHeaderFooter = headerFooterSettings.hasHeaderFooter(); |
1096 } | 1101 }; |
1097 | 1102 |
1098 /** | 1103 /** |
1099 * Updates the title of the print preview tab according to |initiatorTabTitle|. | 1104 * Updates the title of the print preview tab according to |initiatorTabTitle|. |
1100 * @param {string} initiatorTabTitle The title of the initiator tab. | 1105 * @param {string} initiatorTabTitle The title of the initiator tab. |
1101 */ | 1106 */ |
1102 function setInitiatorTabTitle(initiatorTabTitle) { | 1107 function setInitiatorTabTitle(initiatorTabTitle) { |
1103 if (initiatorTabTitle == '') | 1108 if (initiatorTabTitle == '') |
1104 return; | 1109 return; |
1105 document.title = localStrings.getStringF( | 1110 document.title = localStrings.getStringF( |
1106 'printPreviewTitleFormat', initiatorTabTitle); | 1111 'printPreviewTitleFormat', initiatorTabTitle); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 <include src="copies_settings.js"/> | 1150 <include src="copies_settings.js"/> |
1146 <include src="header_footer_settings.js"/> | 1151 <include src="header_footer_settings.js"/> |
1147 <include src="layout_settings.js"/> | 1152 <include src="layout_settings.js"/> |
1148 <include src="color_settings.js"/> | 1153 <include src="color_settings.js"/> |
1149 <include src="margin_settings.js"/> | 1154 <include src="margin_settings.js"/> |
1150 <include src="margin_textbox.js"/> | 1155 <include src="margin_textbox.js"/> |
1151 <include src="margin_utils.js"/> | 1156 <include src="margin_utils.js"/> |
1152 <include src="margins_ui.js"/> | 1157 <include src="margins_ui.js"/> |
1153 <include src="margins_ui_pair.js"/> | 1158 <include src="margins_ui_pair.js"/> |
1154 <include src="preview_area.js"/> | 1159 <include src="preview_area.js"/> |
OLD | NEW |