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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 // A dictionary of cloud printers that have been added to the printer | 96 // A dictionary of cloud printers that have been added to the printer |
97 // dropdown. | 97 // dropdown. |
98 var addedCloudPrinters = {}; | 98 var addedCloudPrinters = {}; |
99 | 99 |
100 // The maximum number of cloud printers to allow in the dropdown. | 100 // The maximum number of cloud printers to allow in the dropdown. |
101 const maxCloudPrinters = 10; | 101 const maxCloudPrinters = 10; |
102 | 102 |
103 const MIN_REQUEST_ID = 0; | 103 const MIN_REQUEST_ID = 0; |
104 const MAX_REQUEST_ID = 32000; | 104 const MAX_REQUEST_ID = 32000; |
105 | 105 |
106 // Names of all the custom events used. | |
107 var customEvents = { | |
108 // Fired when the mouse moves while a margin line is being dragged. | |
109 DRAG: 'Drag', | |
Evan Stade
2011/10/25 17:16:43
this needs a better name
dpapad
2011/10/25 18:35:32
Done.
| |
110 // Fired when a mousedown event occurs on a margin line. | |
111 MARGINS_LINE_MOUSE_DOWN: 'marginsLineMouseDown', | |
112 // Fired when a new preview might be needed because of margin changes. | |
113 MARGINS_MAY_HAVE_CHANGED: 'marginsMayHaveChanged', | |
114 // Fired when a pdf generation related error occurs. | |
115 PDF_GENERATION_ERROR: 'PDFGenerationError', | |
116 // Fired once the first page of the pdf document is loaded in the plugin. | |
117 PDF_LOADED: 'PDFLoaded', | |
118 // Fired when the selected printer capabilities change. | |
119 PRINTER_CAPABILITIES_UPDATED: 'printerCapabilitiesUpdated', | |
120 // Fired when the print button needs to be updated. | |
121 UPDATE_PRINT_BUTTON: 'updatePrintButton', | |
122 // Fired when the print summary needs to be updated. | |
123 UPDATE_SUMMARY: 'updateSummary', | |
124 } | |
125 | |
106 /** | 126 /** |
107 * Window onload handler, sets up the page and starts print preview by getting | 127 * Window onload handler, sets up the page and starts print preview by getting |
108 * the printer list. | 128 * the printer list. |
109 */ | 129 */ |
110 function onLoad() { | 130 function onLoad() { |
111 cr.enablePlatformSpecificCSSRules(); | 131 cr.enablePlatformSpecificCSSRules(); |
112 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); | 132 initialPreviewRequestID = randomInteger(MIN_REQUEST_ID, MAX_REQUEST_ID); |
113 lastPreviewRequestID = initialPreviewRequestID; | 133 lastPreviewRequestID = initialPreviewRequestID; |
114 | 134 |
115 previewArea = print_preview.PreviewArea.getInstance(); | 135 previewArea = print_preview.PreviewArea.getInstance(); |
116 printHeader = print_preview.PrintHeader.getInstance(); | 136 printHeader = print_preview.PrintHeader.getInstance(); |
117 document.addEventListener('PDFGenerationError', cancelPendingPrintRequest); | 137 document.addEventListener(customEvents.PDF_GENERATION_ERROR, |
138 cancelPendingPrintRequest); | |
118 | 139 |
119 if (!checkCompatiblePluginExists()) { | 140 if (!checkCompatiblePluginExists()) { |
120 disableInputElementsInSidebar(); | 141 disableInputElementsInSidebar(); |
121 previewArea.displayErrorMessageWithButtonAndNotify( | 142 previewArea.displayErrorMessageWithButtonAndNotify( |
122 localStrings.getString('noPlugin'), | 143 localStrings.getString('noPlugin'), |
123 localStrings.getString('launchNativeDialog'), | 144 localStrings.getString('launchNativeDialog'), |
124 launchNativePrintDialog); | 145 launchNativePrintDialog); |
125 $('mainview').parentElement.removeChild($('dummy-viewer')); | 146 $('mainview').parentElement.removeChild($('dummy-viewer')); |
126 return; | 147 return; |
127 } | 148 } |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 updateWithPrinterCapabilities(settings); | 296 updateWithPrinterCapabilities(settings); |
276 var printerList = $('printer-list'); | 297 var printerList = $('printer-list'); |
277 var selectedIndex = printerList.selectedIndex; | 298 var selectedIndex = printerList.selectedIndex; |
278 lastSelectedPrinterIndex = selectedIndex; | 299 lastSelectedPrinterIndex = selectedIndex; |
279 | 300 |
280 // Regenerate the preview data based on selected printer settings. | 301 // Regenerate the preview data based on selected printer settings. |
281 setDefaultValuesAndRegeneratePreview(true); | 302 setDefaultValuesAndRegeneratePreview(true); |
282 } | 303 } |
283 | 304 |
284 /** | 305 /** |
285 * Updates the controls with printer capabilities information. | 306 * Updates the controls with printer capabilities information. |
Evan Stade
2011/10/25 17:16:43
this documentation is out of date
dpapad
2011/10/25 18:35:32
Done.
| |
286 * @param {Object} settingInfo printer setting information. | 307 * @param {Object} settingInfo printer setting information. |
287 */ | 308 */ |
288 function updateWithPrinterCapabilities(settingInfo) { | 309 function updateWithPrinterCapabilities(settingInfo) { |
289 var customEvent = new cr.Event("printerCapabilitiesUpdated"); | 310 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
290 customEvent.printerCapabilities = settingInfo; | 311 customEvent.printerCapabilities = settingInfo; |
291 document.dispatchEvent(customEvent); | 312 document.dispatchEvent(customEvent); |
292 } | 313 } |
293 | 314 |
294 /** | 315 /** |
295 * Turn on the integration of Cloud Print. | 316 * Turn on the integration of Cloud Print. |
296 * @param {string} cloudPrintUrl The URL to use for cloud print servers. | 317 * @param {string} cloudPrintUrl The URL to use for cloud print servers. |
297 */ | 318 */ |
298 function setUseCloudPrint(cloudPrintURL) { | 319 function setUseCloudPrint(cloudPrintURL) { |
299 useCloudPrint = true; | 320 useCloudPrint = true; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 /** | 502 /** |
482 * Loads the selected preview pages. | 503 * Loads the selected preview pages. |
483 */ | 504 */ |
484 function loadSelectedPages() { | 505 function loadSelectedPages() { |
485 pageSettings.updatePageSelection(); | 506 pageSettings.updatePageSelection(); |
486 var pageSet = pageSettings.previouslySelectedPages; | 507 var pageSet = pageSettings.previouslySelectedPages; |
487 var pageCount = pageSet.length; | 508 var pageCount = pageSet.length; |
488 if (pageCount == 0 || currentPreviewUid == '') | 509 if (pageCount == 0 || currentPreviewUid == '') |
489 return; | 510 return; |
490 | 511 |
491 cr.dispatchSimpleEvent(document, 'updateSummary'); | 512 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
492 for (var i = 0; i < pageCount; i++) | 513 for (var i = 0; i < pageCount; i++) |
493 onDidPreviewPage(pageSet[i] - 1, currentPreviewUid, lastPreviewRequestID); | 514 onDidPreviewPage(pageSet[i] - 1, currentPreviewUid, lastPreviewRequestID); |
494 } | 515 } |
495 | 516 |
496 /** | 517 /** |
497 * Asks the browser to generate a preview PDF based on current print settings. | 518 * Asks the browser to generate a preview PDF based on current print settings. |
498 */ | 519 */ |
499 function requestPrintPreview() { | 520 function requestPrintPreview() { |
500 if (!isTabHidden) | 521 if (!isTabHidden) |
501 previewArea.showLoadingAnimation(); | 522 previewArea.showLoadingAnimation(); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 localStrings.getString('invalidPrinterSettings')); | 747 localStrings.getString('invalidPrinterSettings')); |
727 } | 748 } |
728 | 749 |
729 /** | 750 /** |
730 * Called when the PDF plugin loads its document. | 751 * Called when the PDF plugin loads its document. |
731 */ | 752 */ |
732 function onPDFLoad() { | 753 function onPDFLoad() { |
733 if (previewModifiable) { | 754 if (previewModifiable) { |
734 setPluginPreviewPageCount(); | 755 setPluginPreviewPageCount(); |
735 } | 756 } |
736 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 757 cr.dispatchSimpleEvent(document, customEvents.PDF_LOADED); |
737 isFirstPageLoaded = true; | 758 isFirstPageLoaded = true; |
738 checkAndHideOverlayLayerIfValid(); | 759 checkAndHideOverlayLayerIfValid(); |
739 sendPrintDocumentRequestIfNeeded(); | 760 sendPrintDocumentRequestIfNeeded(); |
740 } | 761 } |
741 | 762 |
742 function setPluginPreviewPageCount() { | 763 function setPluginPreviewPageCount() { |
743 $('pdf-viewer').printPreviewPageCount( | 764 $('pdf-viewer').printPreviewPageCount( |
744 pageSettings.previouslySelectedPages.length); | 765 pageSettings.previouslySelectedPages.length); |
745 } | 766 } |
746 | 767 |
747 /** | 768 /** |
748 * Update the page count and check the page range. | 769 * Update the page count and check the page range. |
749 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 770 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
750 * @param {number} pageCount The number of pages. | 771 * @param {number} pageCount The number of pages. |
751 * @param {boolean} isModifiable Indicates whether the previewed document can be | 772 * @param {boolean} isModifiable Indicates whether the previewed document can be |
752 * modified. | 773 * modified. |
753 * @param {number} previewResponseId The preview request id that resulted in | 774 * @param {number} previewResponseId The preview request id that resulted in |
754 * this response. | 775 * this response. |
755 */ | 776 */ |
756 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { | 777 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { |
757 if (!isExpectedPreviewResponse(previewResponseId)) | 778 if (!isExpectedPreviewResponse(previewResponseId)) |
758 return; | 779 return; |
759 pageSettings.updateState(pageCount); | 780 pageSettings.updateState(pageCount); |
760 previewModifiable = isModifiable; | 781 previewModifiable = isModifiable; |
761 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 782 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
762 return; | 783 return; |
763 | 784 |
764 cr.dispatchSimpleEvent(document, 'updateSummary'); | 785 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
765 } | 786 } |
766 | 787 |
767 /** | 788 /** |
768 * @param {printing::PageSizeMargins} pageLayout The default layout of the page | 789 * @param {printing::PageSizeMargins} pageLayout The default layout of the page |
769 * in points. | 790 * in points. |
770 */ | 791 */ |
771 function onDidGetDefaultPageLayout(pageLayout) { | 792 function onDidGetDefaultPageLayout(pageLayout) { |
772 marginSettings.currentDefaultPageLayout = new print_preview.PageLayout( | 793 marginSettings.currentDefaultPageLayout = new print_preview.PageLayout( |
773 pageLayout.contentWidth, | 794 pageLayout.contentWidth, |
774 pageLayout.contentHeight, | 795 pageLayout.contentHeight, |
(...skipping 22 matching lines...) Expand all Loading... | |
797 /** | 818 /** |
798 * Called when no pipelining previewed pages. | 819 * Called when no pipelining previewed pages. |
799 * @param {string} previewUid Preview unique identifier. | 820 * @param {string} previewUid Preview unique identifier. |
800 * @param {number} previewResponseId The preview request id that resulted in | 821 * @param {number} previewResponseId The preview request id that resulted in |
801 * this response. | 822 * this response. |
802 */ | 823 */ |
803 function reloadPreviewPages(previewUid, previewResponseId) { | 824 function reloadPreviewPages(previewUid, previewResponseId) { |
804 if (!isExpectedPreviewResponse(previewResponseId)) | 825 if (!isExpectedPreviewResponse(previewResponseId)) |
805 return; | 826 return; |
806 | 827 |
807 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 828 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
808 checkAndHideOverlayLayerIfValid(); | 829 checkAndHideOverlayLayerIfValid(); |
809 var pageSet = pageSettings.previouslySelectedPages; | 830 var pageSet = pageSettings.previouslySelectedPages; |
810 for (var i = 0; i < pageSet.length; i++) | 831 for (var i = 0; i < pageSet.length; i++) |
811 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); | 832 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); |
812 | 833 |
813 hasPendingPreviewRequest = false; | 834 hasPendingPreviewRequest = false; |
814 isPrintReadyMetafileReady = true; | 835 isPrintReadyMetafileReady = true; |
815 previewArea.pdfLoaded = true; | 836 previewArea.pdfLoaded = true; |
816 sendPrintDocumentRequestIfNeeded(); | 837 sendPrintDocumentRequestIfNeeded(); |
817 } | 838 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
868 return; | 889 return; |
869 isPrintReadyMetafileReady = true; | 890 isPrintReadyMetafileReady = true; |
870 | 891 |
871 if (!previewModifiable) { | 892 if (!previewModifiable) { |
872 // If the preview is not modifiable the plugin has not been created yet. | 893 // If the preview is not modifiable the plugin has not been created yet. |
873 currentPreviewUid = previewUid; | 894 currentPreviewUid = previewUid; |
874 hasPendingPreviewRequest = false; | 895 hasPendingPreviewRequest = false; |
875 createPDFPlugin(PRINT_READY_DATA_INDEX); | 896 createPDFPlugin(PRINT_READY_DATA_INDEX); |
876 } | 897 } |
877 | 898 |
878 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 899 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
879 if (previewModifiable) | 900 if (previewModifiable) |
880 sendPrintDocumentRequestIfNeeded(); | 901 sendPrintDocumentRequestIfNeeded(); |
881 } | 902 } |
882 | 903 |
883 /** | 904 /** |
884 * Checks to see if the requested print data is available for printing and | 905 * Checks to see if the requested print data is available for printing and |
885 * sends a print document request if needed. | 906 * sends a print document request if needed. |
886 */ | 907 */ |
887 function sendPrintDocumentRequestIfNeeded() { | 908 function sendPrintDocumentRequestIfNeeded() { |
888 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) | 909 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1069 <include src="copies_settings.js"/> | 1090 <include src="copies_settings.js"/> |
1070 <include src="header_footer_settings.js"/> | 1091 <include src="header_footer_settings.js"/> |
1071 <include src="layout_settings.js"/> | 1092 <include src="layout_settings.js"/> |
1072 <include src="color_settings.js"/> | 1093 <include src="color_settings.js"/> |
1073 <include src="margin_settings.js"/> | 1094 <include src="margin_settings.js"/> |
1074 <include src="margin_textbox.js"/> | 1095 <include src="margin_textbox.js"/> |
1075 <include src="margin_utils.js"/> | 1096 <include src="margin_utils.js"/> |
1076 <include src="margins_ui.js"/> | 1097 <include src="margins_ui.js"/> |
1077 <include src="margins_ui_pair.js"/> | 1098 <include src="margins_ui_pair.js"/> |
1078 <include src="preview_area.js"/> | 1099 <include src="preview_area.js"/> |
OLD | NEW |