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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 | 64 |
| 65 // Object holding all the margin related settings. | 65 // Object holding all the margin related settings. |
| 66 var marginSettings; | 66 var marginSettings; |
| 67 | 67 |
| 68 // Object holding all the header footer related settings. | 68 // Object holding all the header footer related settings. |
| 69 var headerFooterSettings; | 69 var headerFooterSettings; |
| 70 | 70 |
| 71 // Object holding all the color related settings. | 71 // Object holding all the color related settings. |
| 72 var colorSettings; | 72 var colorSettings; |
| 73 | 73 |
| 74 var previewArea; | |
|
Evan Stade
2011/10/05 03:05:23
docs
dpapad
2011/10/05 16:39:49
Done. Also updated the doc of the remaining object
| |
| 75 | |
| 74 // True if the user has click 'Advanced...' in order to open the system print | 76 // True if the user has click 'Advanced...' in order to open the system print |
| 75 // dialog. | 77 // dialog. |
| 76 var showingSystemDialog = false; | 78 var showingSystemDialog = false; |
| 77 | 79 |
| 78 // The range of options in the printer dropdown controlled by cloud print. | 80 // The range of options in the printer dropdown controlled by cloud print. |
| 79 var firstCloudPrintOptionPos = 0; | 81 var firstCloudPrintOptionPos = 0; |
| 80 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; | 82 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; |
| 81 | 83 |
| 82 // Store the current previewUid. | 84 // Store the current previewUid. |
| 83 var currentPreviewUid = ''; | 85 var currentPreviewUid = ''; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 | 120 |
| 119 $('printer-list').disabled = true; | 121 $('printer-list').disabled = true; |
| 120 | 122 |
| 121 printHeader = print_preview.PrintHeader.getInstance(); | 123 printHeader = print_preview.PrintHeader.getInstance(); |
| 122 pageSettings = print_preview.PageSettings.getInstance(); | 124 pageSettings = print_preview.PageSettings.getInstance(); |
| 123 copiesSettings = print_preview.CopiesSettings.getInstance(); | 125 copiesSettings = print_preview.CopiesSettings.getInstance(); |
| 124 layoutSettings = print_preview.LayoutSettings.getInstance(); | 126 layoutSettings = print_preview.LayoutSettings.getInstance(); |
| 125 marginSettings = print_preview.MarginSettings.getInstance(); | 127 marginSettings = print_preview.MarginSettings.getInstance(); |
| 126 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 128 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
| 127 colorSettings = print_preview.ColorSettings.getInstance(); | 129 colorSettings = print_preview.ColorSettings.getInstance(); |
| 130 previewArea = print_preview.PreviewArea.getInstance(); | |
| 128 printHeader.addEventListeners(); | 131 printHeader.addEventListeners(); |
| 129 pageSettings.addEventListeners(); | 132 pageSettings.addEventListeners(); |
| 130 copiesSettings.addEventListeners(); | 133 copiesSettings.addEventListeners(); |
| 131 headerFooterSettings.addEventListeners(); | 134 headerFooterSettings.addEventListeners(); |
| 132 layoutSettings.addEventListeners(); | 135 layoutSettings.addEventListeners(); |
| 133 marginSettings.addEventListeners(); | 136 marginSettings.addEventListeners(); |
| 134 colorSettings.addEventListeners(); | 137 colorSettings.addEventListeners(); |
| 138 previewArea.addEventListeners(); | |
| 135 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 139 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
| 136 | 140 |
| 137 showLoadingAnimation(); | 141 showLoadingAnimation(); |
| 138 chrome.send('getInitiatorTabTitle'); | 142 chrome.send('getInitiatorTabTitle'); |
| 139 chrome.send('getDefaultPrinter'); | 143 chrome.send('getDefaultPrinter'); |
| 140 } | 144 } |
| 141 | 145 |
| 142 /** | 146 /** |
| 143 * Disables the input elements in the sidebar. | 147 * Disables the input elements in the sidebar. |
| 144 */ | 148 */ |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 305 window.location = cloudprint.getBaseURL(); | 309 window.location = cloudprint.getBaseURL(); |
| 306 } | 310 } |
| 307 | 311 |
| 308 /** | 312 /** |
| 309 * Checks whether the specified settings are valid. | 313 * Checks whether the specified settings are valid. |
| 310 * | 314 * |
| 311 * @return {boolean} true if settings are valid, false if not. | 315 * @return {boolean} true if settings are valid, false if not. |
| 312 */ | 316 */ |
| 313 function areSettingsValid() { | 317 function areSettingsValid() { |
| 314 var selectedPrinter = getSelectedPrinterName(); | 318 var selectedPrinter = getSelectedPrinterName(); |
| 315 return pageSettings.isPageSelectionValid() && | 319 return pageSettings.isPageSelectionValid() |
| 316 (copiesSettings.isValid() || | 320 && marginSettings.areMarginSettingsValid() && |
|
Evan Stade
2011/10/05 03:05:23
operator on end of line
dpapad
2011/10/05 16:39:49
Done.
| |
| 317 selectedPrinter == PRINT_TO_PDF || | 321 (copiesSettings.isValid() || selectedPrinter == PRINT_TO_PDF || |
| 318 selectedPrinter == PRINT_WITH_CLOUD_PRINT); | 322 selectedPrinter == PRINT_WITH_CLOUD_PRINT); |
| 319 } | 323 } |
| 320 | 324 |
| 321 /** | 325 /** |
| 322 * Creates an object based on the values in the printer settings. | 326 * Creates an object based on the values in the printer settings. |
| 323 * | 327 * |
| 324 * @return {Object} Object containing print job settings. | 328 * @return {Object} Object containing print job settings. |
| 325 */ | 329 */ |
| 326 function getSettings() { | 330 function getSettings() { |
| 327 var deviceName = getSelectedPrinterName(); | 331 var deviceName = getSelectedPrinterName(); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 loadSelectedPages(); | 493 loadSelectedPages(); |
| 490 generateDraftData = false; | 494 generateDraftData = false; |
| 491 } else { | 495 } else { |
| 492 hasPendingPreviewRequest = true; | 496 hasPendingPreviewRequest = true; |
| 493 generateDraftData = true; | 497 generateDraftData = true; |
| 494 pageSettings.updatePageSelection(); | 498 pageSettings.updatePageSelection(); |
| 495 } | 499 } |
| 496 | 500 |
| 497 printSettings.save(); | 501 printSettings.save(); |
| 498 layoutSettings.updateState(); | 502 layoutSettings.updateState(); |
| 503 previewArea.resetState(); | |
| 499 isPrintReadyMetafileReady = false; | 504 isPrintReadyMetafileReady = false; |
| 500 isFirstPageLoaded = false; | 505 isFirstPageLoaded = false; |
| 501 | 506 |
| 502 var totalPageCount = pageSettings.totalPageCount; | 507 var totalPageCount = pageSettings.totalPageCount; |
| 503 if (!previewModifiable && totalPageCount > 0) | 508 if (!previewModifiable && totalPageCount > 0) |
| 504 generateDraftData = false; | 509 generateDraftData = false; |
| 505 | 510 |
| 506 var pageCount = totalPageCount != undefined ? totalPageCount : -1; | 511 var pageCount = totalPageCount != undefined ? totalPageCount : -1; |
| 507 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), | 512 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), |
| 508 pageCount, | 513 pageCount, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 var option = createDestinationListOption(optionText, | 671 var option = createDestinationListOption(optionText, |
| 667 optionValue, | 672 optionValue, |
| 668 isDefault, | 673 isDefault, |
| 669 isDisabled, | 674 isDisabled, |
| 670 isSeparator); | 675 isSeparator); |
| 671 var printerList = $('printer-list'); | 676 var printerList = $('printer-list'); |
| 672 var before = printerList[position]; | 677 var before = printerList[position]; |
| 673 printerList.add(option, before); | 678 printerList.add(option, before); |
| 674 return option; | 679 return option; |
| 675 } | 680 } |
| 681 | |
| 676 /** | 682 /** |
| 677 * Sets the color mode for the PDF plugin. | 683 * Sets the color mode for the PDF plugin. |
| 678 * Called from PrintPreviewHandler::ProcessColorSetting(). | 684 * Called from PrintPreviewHandler::ProcessColorSetting(). |
| 679 * @param {boolean} color is true if the PDF plugin should display in color. | 685 * @param {boolean} color is true if the PDF plugin should display in color. |
| 680 */ | 686 */ |
| 681 function setColor(color) { | 687 function setColor(color) { |
| 682 var pdfViewer = $('pdf-viewer'); | 688 var pdfViewer = $('pdf-viewer'); |
| 683 if (!pdfViewer) { | 689 if (!pdfViewer) { |
| 684 return; | 690 return; |
| 685 } | 691 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 747 displayErrorMessage(localStrings.getString('invalidPrinterSettings')); | 753 displayErrorMessage(localStrings.getString('invalidPrinterSettings')); |
| 748 } | 754 } |
| 749 | 755 |
| 750 /** | 756 /** |
| 751 * Called when the PDF plugin loads its document. | 757 * Called when the PDF plugin loads its document. |
| 752 */ | 758 */ |
| 753 function onPDFLoad() { | 759 function onPDFLoad() { |
| 754 if (previewModifiable) { | 760 if (previewModifiable) { |
| 755 setPluginPreviewPageCount(); | 761 setPluginPreviewPageCount(); |
| 756 } | 762 } |
| 757 $('pdf-viewer').fitToHeight(); | |
| 758 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 763 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
| 759 isFirstPageLoaded = true; | 764 isFirstPageLoaded = true; |
| 760 checkAndHideOverlayLayerIfValid(); | 765 checkAndHideOverlayLayerIfValid(); |
| 761 sendPrintDocumentRequestIfNeeded(); | 766 sendPrintDocumentRequestIfNeeded(); |
| 762 } | 767 } |
| 763 | 768 |
| 764 function setPluginPreviewPageCount() { | 769 function setPluginPreviewPageCount() { |
| 765 $('pdf-viewer').printPreviewPageCount( | 770 $('pdf-viewer').printPreviewPageCount( |
| 766 pageSettings.previouslySelectedPages.length); | 771 pageSettings.previouslySelectedPages.length); |
| 767 } | 772 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 779 if (!isExpectedPreviewResponse(previewResponseId)) | 784 if (!isExpectedPreviewResponse(previewResponseId)) |
| 780 return; | 785 return; |
| 781 pageSettings.updateState(pageCount); | 786 pageSettings.updateState(pageCount); |
| 782 previewModifiable = isModifiable; | 787 previewModifiable = isModifiable; |
| 783 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 788 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
| 784 return; | 789 return; |
| 785 | 790 |
| 786 cr.dispatchSimpleEvent(document, 'updateSummary'); | 791 cr.dispatchSimpleEvent(document, 'updateSummary'); |
| 787 } | 792 } |
| 788 | 793 |
| 794 /** | |
| 795 * @param {printing::PageSizeMargins} pageLayout The default layout of the page | |
| 796 * in points. | |
| 797 */ | |
| 789 function onDidGetDefaultPageLayout(pageLayout) { | 798 function onDidGetDefaultPageLayout(pageLayout) { |
| 790 // TODO(aayushkumar): Do something here! | 799 marginSettings.currentDefaultPageLayout = new print_preview.PageLayout( |
| 800 pageLayout.contentWidth, | |
| 801 pageLayout.contentHeight, | |
| 802 pageLayout.marginLeft, | |
| 803 pageLayout.marginTop, | |
| 804 pageLayout.marginRight, | |
| 805 pageLayout.marginBottom); | |
| 791 } | 806 } |
| 792 | 807 |
| 793 /** | 808 /** |
| 794 * This function sends a request to hide the overlay layer only if there is no | 809 * This function sends a request to hide the overlay layer only if there is no |
| 795 * pending print document request and we are not waiting for the print ready | 810 * pending print document request and we are not waiting for the print ready |
| 796 * metafile. | 811 * metafile. |
| 797 */ | 812 */ |
| 798 function checkAndHideOverlayLayerIfValid() { | 813 function checkAndHideOverlayLayerIfValid() { |
| 799 var selectedPrinter = getSelectedPrinterName(); | 814 var selectedPrinter = getSelectedPrinterName(); |
| 800 var printToDialog = selectedPrinter == PRINT_TO_PDF || | 815 var printToDialog = selectedPrinter == PRINT_TO_PDF || |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 956 | 971 |
| 957 pdfViewer = document.createElement('embed'); | 972 pdfViewer = document.createElement('embed'); |
| 958 pdfViewer.setAttribute('id', 'pdf-viewer'); | 973 pdfViewer.setAttribute('id', 'pdf-viewer'); |
| 959 pdfViewer.setAttribute('type', | 974 pdfViewer.setAttribute('type', |
| 960 'application/x-google-chrome-print-preview-pdf'); | 975 'application/x-google-chrome-print-preview-pdf'); |
| 961 pdfViewer.setAttribute('src', srcURL); | 976 pdfViewer.setAttribute('src', srcURL); |
| 962 pdfViewer.setAttribute('aria-live', 'polite'); | 977 pdfViewer.setAttribute('aria-live', 'polite'); |
| 963 pdfViewer.setAttribute('aria-atomic', 'true'); | 978 pdfViewer.setAttribute('aria-atomic', 'true'); |
| 964 $('mainview').appendChild(pdfViewer); | 979 $('mainview').appendChild(pdfViewer); |
| 965 pdfViewer.onload('onPDFLoad()'); | 980 pdfViewer.onload('onPDFLoad()'); |
| 981 pdfViewer.onScroll('onPreviewPositionChanged()'); | |
| 982 pdfViewer.onPluginSizeChanged('onPreviewPositionChanged()'); | |
| 966 pdfViewer.removePrintButton(); | 983 pdfViewer.removePrintButton(); |
| 967 pdfViewer.grayscale(true); | 984 pdfViewer.grayscale(true); |
| 968 } | 985 } |
| 969 | 986 |
| 970 /** | 987 /** |
| 988 * Called either when there is a scroll event or when the plugin size changes. | |
| 989 */ | |
| 990 function onPreviewPositionChanged() { | |
| 991 marginSettings.onPreviewPositionChanged(); | |
| 992 } | |
| 993 | |
| 994 /** | |
| 971 * @return {boolean} true if a compatible pdf plugin exists. | 995 * @return {boolean} true if a compatible pdf plugin exists. |
| 972 */ | 996 */ |
| 973 function checkCompatiblePluginExists() { | 997 function checkCompatiblePluginExists() { |
| 974 var dummyPlugin = $('dummy-viewer') | 998 var dummyPlugin = $('dummy-viewer'); |
| 975 return !!(dummyPlugin.onload && | 999 var pluginInterface = [ dummyPlugin.onload, |
| 976 dummyPlugin.goToPage && | 1000 dummyPlugin.goToPage, |
| 977 dummyPlugin.removePrintButton && | 1001 dummyPlugin.removePrintButton, |
| 978 dummyPlugin.loadPreviewPage && | 1002 dummyPlugin.loadPreviewPage, |
| 979 dummyPlugin.printPreviewPageCount && | 1003 dummyPlugin.printPreviewPageCount, |
| 980 dummyPlugin.resetPrintPreviewUrl); | 1004 dummyPlugin.resetPrintPreviewUrl, |
| 1005 dummyPlugin.onPluginSizeChanged, | |
| 1006 dummyPlugin.onScroll, | |
| 1007 dummyPlugin.pageXOffset, | |
| 1008 dummyPlugin.pageYOffset, | |
| 1009 dummyPlugin.setZoomLevel, | |
| 1010 dummyPlugin.setPageXOffset, | |
| 1011 dummyPlugin.setPageYOffset, | |
| 1012 dummyPlugin.getHorizontalScrollbarThickness, | |
| 1013 dummyPlugin.getVerticalScrollbarThickness, | |
| 1014 dummyPlugin.getPageLocationNormalized, | |
| 1015 dummyPlugin.getHeight, | |
| 1016 dummyPlugin.getWidth ]; | |
| 1017 | |
| 1018 for (var i = 0; i < pluginInterface.length; i++) { | |
| 1019 if (!pluginInterface[i]) | |
| 1020 return false; | |
| 1021 } | |
| 1022 return true; | |
| 981 } | 1023 } |
| 982 | 1024 |
| 983 window.addEventListener('DOMContentLoaded', onLoad); | 1025 window.addEventListener('DOMContentLoaded', onLoad); |
| 984 | 1026 |
| 985 /** | 1027 /** |
| 986 * Sets the default values and sends a request to regenerate preview data. | 1028 * Sets the default values and sends a request to regenerate preview data. |
| 987 * Resets the margin options only if |resetMargins| is true. | 1029 * Resets the margin options only if |resetMargins| is true. |
| 988 */ | 1030 */ |
| 989 function setDefaultValuesAndRegeneratePreview(resetMargins) { | 1031 function setDefaultValuesAndRegeneratePreview(resetMargins) { |
| 990 if (resetMargins) | 1032 if (resetMargins) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 <include src="print_preview_animations.js"/> | 1070 <include src="print_preview_animations.js"/> |
| 1029 <include src="print_preview_cloud.js"/> | 1071 <include src="print_preview_cloud.js"/> |
| 1030 <include src="print_preview_utils.js"/> | 1072 <include src="print_preview_utils.js"/> |
| 1031 <include src="print_header.js"/> | 1073 <include src="print_header.js"/> |
| 1032 <include src="page_settings.js"/> | 1074 <include src="page_settings.js"/> |
| 1033 <include src="copies_settings.js"/> | 1075 <include src="copies_settings.js"/> |
| 1034 <include src="header_footer_settings.js"/> | 1076 <include src="header_footer_settings.js"/> |
| 1035 <include src="layout_settings.js"/> | 1077 <include src="layout_settings.js"/> |
| 1036 <include src="color_settings.js"/> | 1078 <include src="color_settings.js"/> |
| 1037 <include src="margin_settings.js"/> | 1079 <include src="margin_settings.js"/> |
| 1080 <include src="margin_textbox.js"/> | |
| 1081 <include src="margin_line.js"/> | |
| 1082 <include src="margin_utils.js"/> | |
| 1083 <include src="margins_ui.js"/> | |
| 1084 <include src="preview_area.js"/> | |
| OLD | NEW |