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 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 MARGINS_LINE_DRAG: 'marginsLineDrag', | |
|
Evan Stade
2011/10/26 23:16:28
no S
| |
| 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 * Notifies listeners of |customEvents.PRINTER_CAPABILITIES_UPDATED| about the |
| 307 * capabilities of the currently selected printer. It is called from C++ too. | |
| 286 * @param {Object} settingInfo printer setting information. | 308 * @param {Object} settingInfo printer setting information. |
| 287 */ | 309 */ |
| 288 function updateWithPrinterCapabilities(settingInfo) { | 310 function updateWithPrinterCapabilities(settingInfo) { |
| 289 var customEvent = new cr.Event("printerCapabilitiesUpdated"); | 311 var customEvent = new cr.Event(customEvents.PRINTER_CAPABILITIES_UPDATED); |
| 290 customEvent.printerCapabilities = settingInfo; | 312 customEvent.printerCapabilities = settingInfo; |
| 291 document.dispatchEvent(customEvent); | 313 document.dispatchEvent(customEvent); |
| 292 } | 314 } |
| 293 | 315 |
| 294 /** | 316 /** |
| 295 * Turn on the integration of Cloud Print. | 317 * Turn on the integration of Cloud Print. |
| 296 * @param {string} cloudPrintUrl The URL to use for cloud print servers. | 318 * @param {string} cloudPrintUrl The URL to use for cloud print servers. |
| 297 */ | 319 */ |
| 298 function setUseCloudPrint(cloudPrintURL) { | 320 function setUseCloudPrint(cloudPrintURL) { |
| 299 useCloudPrint = true; | 321 useCloudPrint = true; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 481 /** | 503 /** |
| 482 * Loads the selected preview pages. | 504 * Loads the selected preview pages. |
| 483 */ | 505 */ |
| 484 function loadSelectedPages() { | 506 function loadSelectedPages() { |
| 485 pageSettings.updatePageSelection(); | 507 pageSettings.updatePageSelection(); |
| 486 var pageSet = pageSettings.previouslySelectedPages; | 508 var pageSet = pageSettings.previouslySelectedPages; |
| 487 var pageCount = pageSet.length; | 509 var pageCount = pageSet.length; |
| 488 if (pageCount == 0 || currentPreviewUid == '') | 510 if (pageCount == 0 || currentPreviewUid == '') |
| 489 return; | 511 return; |
| 490 | 512 |
| 491 cr.dispatchSimpleEvent(document, 'updateSummary'); | 513 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 492 for (var i = 0; i < pageCount; i++) | 514 for (var i = 0; i < pageCount; i++) |
| 493 onDidPreviewPage(pageSet[i] - 1, currentPreviewUid, lastPreviewRequestID); | 515 onDidPreviewPage(pageSet[i] - 1, currentPreviewUid, lastPreviewRequestID); |
| 494 } | 516 } |
| 495 | 517 |
| 496 /** | 518 /** |
| 497 * Asks the browser to generate a preview PDF based on current print settings. | 519 * Asks the browser to generate a preview PDF based on current print settings. |
| 498 */ | 520 */ |
| 499 function requestPrintPreview() { | 521 function requestPrintPreview() { |
| 500 if (!isTabHidden) | 522 if (!isTabHidden) |
| 501 previewArea.showLoadingAnimation(); | 523 previewArea.showLoadingAnimation(); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 localStrings.getString('invalidPrinterSettings')); | 748 localStrings.getString('invalidPrinterSettings')); |
| 727 } | 749 } |
| 728 | 750 |
| 729 /** | 751 /** |
| 730 * Called when the PDF plugin loads its document. | 752 * Called when the PDF plugin loads its document. |
| 731 */ | 753 */ |
| 732 function onPDFLoad() { | 754 function onPDFLoad() { |
| 733 if (previewModifiable) { | 755 if (previewModifiable) { |
| 734 setPluginPreviewPageCount(); | 756 setPluginPreviewPageCount(); |
| 735 } | 757 } |
| 736 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 758 cr.dispatchSimpleEvent(document, customEvents.PDF_LOADED); |
| 737 isFirstPageLoaded = true; | 759 isFirstPageLoaded = true; |
| 738 checkAndHideOverlayLayerIfValid(); | 760 checkAndHideOverlayLayerIfValid(); |
| 739 sendPrintDocumentRequestIfNeeded(); | 761 sendPrintDocumentRequestIfNeeded(); |
| 740 } | 762 } |
| 741 | 763 |
| 742 function setPluginPreviewPageCount() { | 764 function setPluginPreviewPageCount() { |
| 743 $('pdf-viewer').printPreviewPageCount( | 765 $('pdf-viewer').printPreviewPageCount( |
| 744 pageSettings.previouslySelectedPages.length); | 766 pageSettings.previouslySelectedPages.length); |
| 745 } | 767 } |
| 746 | 768 |
| 747 /** | 769 /** |
| 748 * Update the page count and check the page range. | 770 * Update the page count and check the page range. |
| 749 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). | 771 * Called from PrintPreviewUI::OnDidGetPreviewPageCount(). |
| 750 * @param {number} pageCount The number of pages. | 772 * @param {number} pageCount The number of pages. |
| 751 * @param {boolean} isModifiable Indicates whether the previewed document can be | 773 * @param {boolean} isModifiable Indicates whether the previewed document can be |
| 752 * modified. | 774 * modified. |
| 753 * @param {number} previewResponseId The preview request id that resulted in | 775 * @param {number} previewResponseId The preview request id that resulted in |
| 754 * this response. | 776 * this response. |
| 755 */ | 777 */ |
| 756 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { | 778 function onDidGetPreviewPageCount(pageCount, isModifiable, previewResponseId) { |
| 757 if (!isExpectedPreviewResponse(previewResponseId)) | 779 if (!isExpectedPreviewResponse(previewResponseId)) |
| 758 return; | 780 return; |
| 759 pageSettings.updateState(pageCount); | 781 pageSettings.updateState(pageCount); |
| 760 previewModifiable = isModifiable; | 782 previewModifiable = isModifiable; |
| 761 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 783 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
| 762 return; | 784 return; |
| 763 | 785 |
| 764 cr.dispatchSimpleEvent(document, 'updateSummary'); | 786 cr.dispatchSimpleEvent(document, customEvents.UPDATE_SUMMARY); |
| 765 } | 787 } |
| 766 | 788 |
| 767 /** | 789 /** |
| 768 * @param {printing::PageSizeMargins} pageLayout The default layout of the page | 790 * @param {printing::PageSizeMargins} pageLayout The default layout of the page |
| 769 * in points. | 791 * in points. |
| 770 */ | 792 */ |
| 771 function onDidGetDefaultPageLayout(pageLayout) { | 793 function onDidGetDefaultPageLayout(pageLayout) { |
| 772 marginSettings.currentDefaultPageLayout = new print_preview.PageLayout( | 794 marginSettings.currentDefaultPageLayout = new print_preview.PageLayout( |
| 773 pageLayout.contentWidth, | 795 pageLayout.contentWidth, |
| 774 pageLayout.contentHeight, | 796 pageLayout.contentHeight, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 797 /** | 819 /** |
| 798 * Called when no pipelining previewed pages. | 820 * Called when no pipelining previewed pages. |
| 799 * @param {string} previewUid Preview unique identifier. | 821 * @param {string} previewUid Preview unique identifier. |
| 800 * @param {number} previewResponseId The preview request id that resulted in | 822 * @param {number} previewResponseId The preview request id that resulted in |
| 801 * this response. | 823 * this response. |
| 802 */ | 824 */ |
| 803 function reloadPreviewPages(previewUid, previewResponseId) { | 825 function reloadPreviewPages(previewUid, previewResponseId) { |
| 804 if (!isExpectedPreviewResponse(previewResponseId)) | 826 if (!isExpectedPreviewResponse(previewResponseId)) |
| 805 return; | 827 return; |
| 806 | 828 |
| 807 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 829 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
| 808 checkAndHideOverlayLayerIfValid(); | 830 checkAndHideOverlayLayerIfValid(); |
| 809 var pageSet = pageSettings.previouslySelectedPages; | 831 var pageSet = pageSettings.previouslySelectedPages; |
| 810 for (var i = 0; i < pageSet.length; i++) | 832 for (var i = 0; i < pageSet.length; i++) |
| 811 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); | 833 $('pdf-viewer').loadPreviewPage(getPageSrcURL(previewUid, pageSet[i]-1), i); |
| 812 | 834 |
| 813 hasPendingPreviewRequest = false; | 835 hasPendingPreviewRequest = false; |
| 814 isPrintReadyMetafileReady = true; | 836 isPrintReadyMetafileReady = true; |
| 815 previewArea.pdfLoaded = true; | 837 previewArea.pdfLoaded = true; |
| 816 sendPrintDocumentRequestIfNeeded(); | 838 sendPrintDocumentRequestIfNeeded(); |
| 817 } | 839 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 868 return; | 890 return; |
| 869 isPrintReadyMetafileReady = true; | 891 isPrintReadyMetafileReady = true; |
| 870 | 892 |
| 871 if (!previewModifiable) { | 893 if (!previewModifiable) { |
| 872 // If the preview is not modifiable the plugin has not been created yet. | 894 // If the preview is not modifiable the plugin has not been created yet. |
| 873 currentPreviewUid = previewUid; | 895 currentPreviewUid = previewUid; |
| 874 hasPendingPreviewRequest = false; | 896 hasPendingPreviewRequest = false; |
| 875 createPDFPlugin(PRINT_READY_DATA_INDEX); | 897 createPDFPlugin(PRINT_READY_DATA_INDEX); |
| 876 } | 898 } |
| 877 | 899 |
| 878 cr.dispatchSimpleEvent(document, 'updatePrintButton'); | 900 cr.dispatchSimpleEvent(document, customEvents.UPDATE_PRINT_BUTTON); |
| 879 if (previewModifiable) | 901 if (previewModifiable) |
| 880 sendPrintDocumentRequestIfNeeded(); | 902 sendPrintDocumentRequestIfNeeded(); |
| 881 } | 903 } |
| 882 | 904 |
| 883 /** | 905 /** |
| 884 * Checks to see if the requested print data is available for printing and | 906 * Checks to see if the requested print data is available for printing and |
| 885 * sends a print document request if needed. | 907 * sends a print document request if needed. |
| 886 */ | 908 */ |
| 887 function sendPrintDocumentRequestIfNeeded() { | 909 function sendPrintDocumentRequestIfNeeded() { |
| 888 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) | 910 if (!hasPendingPrintDocumentRequest || !isFirstPageLoaded) |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1069 <include src="copies_settings.js"/> | 1091 <include src="copies_settings.js"/> |
| 1070 <include src="header_footer_settings.js"/> | 1092 <include src="header_footer_settings.js"/> |
| 1071 <include src="layout_settings.js"/> | 1093 <include src="layout_settings.js"/> |
| 1072 <include src="color_settings.js"/> | 1094 <include src="color_settings.js"/> |
| 1073 <include src="margin_settings.js"/> | 1095 <include src="margin_settings.js"/> |
| 1074 <include src="margin_textbox.js"/> | 1096 <include src="margin_textbox.js"/> |
| 1075 <include src="margin_utils.js"/> | 1097 <include src="margin_utils.js"/> |
| 1076 <include src="margins_ui.js"/> | 1098 <include src="margins_ui.js"/> |
| 1077 <include src="margins_ui_pair.js"/> | 1099 <include src="margins_ui_pair.js"/> |
| 1078 <include src="preview_area.js"/> | 1100 <include src="preview_area.js"/> |
| OLD | NEW |