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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 // True when a pending print file request exists. | 47 // True when a pending print file request exists. |
48 var hasPendingPrintDocumentRequest = false; | 48 var hasPendingPrintDocumentRequest = false; |
49 | 49 |
50 // True when the complete metafile for the previewed doc is ready. | 50 // True when the complete metafile for the previewed doc is ready. |
51 var isPrintReadyMetafileReady = false; | 51 var isPrintReadyMetafileReady = false; |
52 | 52 |
53 // True when preview tab is hidden. | 53 // True when preview tab is hidden. |
54 var isTabHidden = false; | 54 var isTabHidden = false; |
55 | 55 |
56 // Object holding the print and cancel buttons. | 56 // @type {print_preview.PrintHeader} Holds the print and cancel buttons. |
57 var printHeader; | 57 var printHeader; |
58 | 58 |
59 // Object holding all the pages related settings. | 59 // @type {print_preview.PageSettings} Holds all the pages related settings. |
60 var pageSettings; | 60 var pageSettings; |
61 | 61 |
62 // Object holding all the copies related settings. | 62 // @type {print_preview.CopiesSettings} Holds all the copies related settings. |
63 var copiesSettings; | 63 var copiesSettings; |
64 | 64 |
65 // Object holding all the layout related settings. | 65 // @type {print_preview.LayoutSettings} Holds all the layout related settings. |
66 var layoutSettings; | 66 var layoutSettings; |
67 | 67 |
68 // Object holding all the margin related settings. | 68 // @type {print_preview.MarginSettings} Holds all the margin related settings. |
69 var marginSettings; | 69 var marginSettings; |
70 | 70 |
71 // Object holding all the header footer related settings. | 71 // @type {print_preview.HeaderFooterSettings} Holds all the header footer |
| 72 // related settings. |
72 var headerFooterSettings; | 73 var headerFooterSettings; |
73 | 74 |
74 // Object holding all the color related settings. | 75 // @type {print_preview.ColorSettings} Holds all the color related settings. |
75 var colorSettings; | 76 var colorSettings; |
76 | 77 |
| 78 // @type {print_preview.PreviewArea} Holds information related to the preview |
| 79 // area (on the right). |
| 80 var previewArea; |
| 81 |
77 // True if the user has click 'Advanced...' in order to open the system print | 82 // True if the user has click 'Advanced...' in order to open the system print |
78 // dialog. | 83 // dialog. |
79 var showingSystemDialog = false; | 84 var showingSystemDialog = false; |
80 | 85 |
81 // The range of options in the printer dropdown controlled by cloud print. | 86 // The range of options in the printer dropdown controlled by cloud print. |
82 var firstCloudPrintOptionPos = 0; | 87 var firstCloudPrintOptionPos = 0; |
83 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; | 88 var lastCloudPrintOptionPos = firstCloudPrintOptionPos; |
84 | 89 |
85 // Store the current previewUid. | 90 // Store the current previewUid. |
86 var currentPreviewUid = ''; | 91 var currentPreviewUid = ''; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 $('mainview').parentElement.removeChild($('dummy-viewer')); | 128 $('mainview').parentElement.removeChild($('dummy-viewer')); |
124 | 129 |
125 $('printer-list').disabled = true; | 130 $('printer-list').disabled = true; |
126 | 131 |
127 pageSettings = print_preview.PageSettings.getInstance(); | 132 pageSettings = print_preview.PageSettings.getInstance(); |
128 copiesSettings = print_preview.CopiesSettings.getInstance(); | 133 copiesSettings = print_preview.CopiesSettings.getInstance(); |
129 layoutSettings = print_preview.LayoutSettings.getInstance(); | 134 layoutSettings = print_preview.LayoutSettings.getInstance(); |
130 marginSettings = print_preview.MarginSettings.getInstance(); | 135 marginSettings = print_preview.MarginSettings.getInstance(); |
131 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); | 136 headerFooterSettings = print_preview.HeaderFooterSettings.getInstance(); |
132 colorSettings = print_preview.ColorSettings.getInstance(); | 137 colorSettings = print_preview.ColorSettings.getInstance(); |
| 138 previewArea = print_preview.PreviewArea.getInstance(); |
133 pageSettings.addEventListeners(); | 139 pageSettings.addEventListeners(); |
134 copiesSettings.addEventListeners(); | 140 copiesSettings.addEventListeners(); |
135 headerFooterSettings.addEventListeners(); | 141 headerFooterSettings.addEventListeners(); |
136 layoutSettings.addEventListeners(); | 142 layoutSettings.addEventListeners(); |
137 marginSettings.addEventListeners(); | 143 marginSettings.addEventListeners(); |
138 colorSettings.addEventListeners(); | 144 colorSettings.addEventListeners(); |
| 145 previewArea.addEventListeners(); |
139 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; | 146 $('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities; |
140 | 147 |
141 showLoadingAnimation(); | 148 showLoadingAnimation(); |
142 chrome.send('getInitiatorTabTitle'); | 149 chrome.send('getInitiatorTabTitle'); |
143 chrome.send('getDefaultPrinter'); | 150 chrome.send('getDefaultPrinter'); |
144 } | 151 } |
145 | 152 |
146 /** | 153 /** |
147 * Disables the input elements in the sidebar. | 154 * Disables the input elements in the sidebar. |
148 */ | 155 */ |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 321 } |
315 | 322 |
316 /** | 323 /** |
317 * Checks whether the specified settings are valid. | 324 * Checks whether the specified settings are valid. |
318 * | 325 * |
319 * @return {boolean} true if settings are valid, false if not. | 326 * @return {boolean} true if settings are valid, false if not. |
320 */ | 327 */ |
321 function areSettingsValid() { | 328 function areSettingsValid() { |
322 var selectedPrinter = getSelectedPrinterName(); | 329 var selectedPrinter = getSelectedPrinterName(); |
323 return pageSettings.isPageSelectionValid() && | 330 return pageSettings.isPageSelectionValid() && |
324 (copiesSettings.isValid() || | 331 marginSettings.areMarginSettingsValid() && |
325 selectedPrinter == PRINT_TO_PDF || | 332 (copiesSettings.isValid() || selectedPrinter == PRINT_TO_PDF || |
326 selectedPrinter == PRINT_WITH_CLOUD_PRINT); | 333 selectedPrinter == PRINT_WITH_CLOUD_PRINT); |
327 } | 334 } |
328 | 335 |
329 /** | 336 /** |
330 * Creates an object based on the values in the printer settings. | 337 * Creates an object based on the values in the printer settings. |
331 * | 338 * |
332 * @return {Object} Object containing print job settings. | 339 * @return {Object} Object containing print job settings. |
333 */ | 340 */ |
334 function getSettings() { | 341 function getSettings() { |
335 var deviceName = getSelectedPrinterName(); | 342 var deviceName = getSelectedPrinterName(); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 loadSelectedPages(); | 504 loadSelectedPages(); |
498 generateDraftData = false; | 505 generateDraftData = false; |
499 } else { | 506 } else { |
500 hasPendingPreviewRequest = true; | 507 hasPendingPreviewRequest = true; |
501 generateDraftData = true; | 508 generateDraftData = true; |
502 pageSettings.updatePageSelection(); | 509 pageSettings.updatePageSelection(); |
503 } | 510 } |
504 | 511 |
505 printSettings.save(); | 512 printSettings.save(); |
506 layoutSettings.updateState(); | 513 layoutSettings.updateState(); |
| 514 previewArea.resetState(); |
507 isPrintReadyMetafileReady = false; | 515 isPrintReadyMetafileReady = false; |
508 isFirstPageLoaded = false; | 516 isFirstPageLoaded = false; |
509 | 517 |
510 var totalPageCount = pageSettings.totalPageCount; | 518 var totalPageCount = pageSettings.totalPageCount; |
511 if (!previewModifiable && totalPageCount > 0) | 519 if (!previewModifiable && totalPageCount > 0) |
512 generateDraftData = false; | 520 generateDraftData = false; |
513 | 521 |
514 var pageCount = totalPageCount != undefined ? totalPageCount : -1; | 522 var pageCount = totalPageCount != undefined ? totalPageCount : -1; |
515 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), | 523 chrome.send('getPreview', [JSON.stringify(getSettingsWithRequestID()), |
516 pageCount, | 524 pageCount, |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
753 displayErrorMessage(localStrings.getString('invalidPrinterSettings')); | 761 displayErrorMessage(localStrings.getString('invalidPrinterSettings')); |
754 } | 762 } |
755 | 763 |
756 /** | 764 /** |
757 * Called when the PDF plugin loads its document. | 765 * Called when the PDF plugin loads its document. |
758 */ | 766 */ |
759 function onPDFLoad() { | 767 function onPDFLoad() { |
760 if (previewModifiable) { | 768 if (previewModifiable) { |
761 setPluginPreviewPageCount(); | 769 setPluginPreviewPageCount(); |
762 } | 770 } |
763 $('pdf-viewer').fitToHeight(); | |
764 cr.dispatchSimpleEvent(document, 'PDFLoaded'); | 771 cr.dispatchSimpleEvent(document, 'PDFLoaded'); |
765 isFirstPageLoaded = true; | 772 isFirstPageLoaded = true; |
766 checkAndHideOverlayLayerIfValid(); | 773 checkAndHideOverlayLayerIfValid(); |
767 sendPrintDocumentRequestIfNeeded(); | 774 sendPrintDocumentRequestIfNeeded(); |
768 } | 775 } |
769 | 776 |
770 function setPluginPreviewPageCount() { | 777 function setPluginPreviewPageCount() { |
771 $('pdf-viewer').printPreviewPageCount( | 778 $('pdf-viewer').printPreviewPageCount( |
772 pageSettings.previouslySelectedPages.length); | 779 pageSettings.previouslySelectedPages.length); |
773 } | 780 } |
(...skipping 11 matching lines...) Expand all Loading... |
785 if (!isExpectedPreviewResponse(previewResponseId)) | 792 if (!isExpectedPreviewResponse(previewResponseId)) |
786 return; | 793 return; |
787 pageSettings.updateState(pageCount); | 794 pageSettings.updateState(pageCount); |
788 previewModifiable = isModifiable; | 795 previewModifiable = isModifiable; |
789 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) | 796 if (!previewModifiable && pageSettings.requestPrintPreviewIfNeeded()) |
790 return; | 797 return; |
791 | 798 |
792 cr.dispatchSimpleEvent(document, 'updateSummary'); | 799 cr.dispatchSimpleEvent(document, 'updateSummary'); |
793 } | 800 } |
794 | 801 |
| 802 /** |
| 803 * @param {printing::PageSizeMargins} pageLayout The default layout of the page |
| 804 * in points. |
| 805 */ |
795 function onDidGetDefaultPageLayout(pageLayout) { | 806 function onDidGetDefaultPageLayout(pageLayout) { |
796 // TODO(aayushkumar): Do something here! | 807 marginSettings.currentDefaultPageLayout = new print_preview.PageLayout( |
| 808 pageLayout.contentWidth, |
| 809 pageLayout.contentHeight, |
| 810 pageLayout.marginLeft, |
| 811 pageLayout.marginTop, |
| 812 pageLayout.marginRight, |
| 813 pageLayout.marginBottom); |
797 } | 814 } |
798 | 815 |
799 /** | 816 /** |
800 * This function sends a request to hide the overlay layer only if there is no | 817 * This function sends a request to hide the overlay layer only if there is no |
801 * pending print document request and we are not waiting for the print ready | 818 * pending print document request and we are not waiting for the print ready |
802 * metafile. | 819 * metafile. |
803 */ | 820 */ |
804 function checkAndHideOverlayLayerIfValid() { | 821 function checkAndHideOverlayLayerIfValid() { |
805 var selectedPrinter = getSelectedPrinterName(); | 822 var selectedPrinter = getSelectedPrinterName(); |
806 var printToDialog = selectedPrinter == PRINT_TO_PDF || | 823 var printToDialog = selectedPrinter == PRINT_TO_PDF || |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 | 979 |
963 pdfViewer = document.createElement('embed'); | 980 pdfViewer = document.createElement('embed'); |
964 pdfViewer.setAttribute('id', 'pdf-viewer'); | 981 pdfViewer.setAttribute('id', 'pdf-viewer'); |
965 pdfViewer.setAttribute('type', | 982 pdfViewer.setAttribute('type', |
966 'application/x-google-chrome-print-preview-pdf'); | 983 'application/x-google-chrome-print-preview-pdf'); |
967 pdfViewer.setAttribute('src', srcURL); | 984 pdfViewer.setAttribute('src', srcURL); |
968 pdfViewer.setAttribute('aria-live', 'polite'); | 985 pdfViewer.setAttribute('aria-live', 'polite'); |
969 pdfViewer.setAttribute('aria-atomic', 'true'); | 986 pdfViewer.setAttribute('aria-atomic', 'true'); |
970 $('mainview').appendChild(pdfViewer); | 987 $('mainview').appendChild(pdfViewer); |
971 pdfViewer.onload('onPDFLoad()'); | 988 pdfViewer.onload('onPDFLoad()'); |
| 989 pdfViewer.onScroll('onPreviewPositionChanged()'); |
| 990 pdfViewer.onPluginSizeChanged('onPreviewPositionChanged()'); |
972 pdfViewer.removePrintButton(); | 991 pdfViewer.removePrintButton(); |
973 pdfViewer.grayscale(true); | 992 pdfViewer.grayscale(true); |
974 } | 993 } |
975 | 994 |
976 /** | 995 /** |
| 996 * Called either when there is a scroll event or when the plugin size changes. |
| 997 */ |
| 998 function onPreviewPositionChanged() { |
| 999 marginSettings.onPreviewPositionChanged(); |
| 1000 } |
| 1001 |
| 1002 /** |
977 * @return {boolean} true if a compatible pdf plugin exists. | 1003 * @return {boolean} true if a compatible pdf plugin exists. |
978 */ | 1004 */ |
979 function checkCompatiblePluginExists() { | 1005 function checkCompatiblePluginExists() { |
980 var dummyPlugin = $('dummy-viewer') | 1006 var dummyPlugin = $('dummy-viewer'); |
981 return !!(dummyPlugin.onload && | 1007 var pluginInterface = [ dummyPlugin.onload, |
982 dummyPlugin.goToPage && | 1008 dummyPlugin.goToPage, |
983 dummyPlugin.removePrintButton && | 1009 dummyPlugin.removePrintButton, |
984 dummyPlugin.loadPreviewPage && | 1010 dummyPlugin.loadPreviewPage, |
985 dummyPlugin.printPreviewPageCount && | 1011 dummyPlugin.printPreviewPageCount, |
986 dummyPlugin.resetPrintPreviewUrl); | 1012 dummyPlugin.resetPrintPreviewUrl, |
| 1013 dummyPlugin.onPluginSizeChanged, |
| 1014 dummyPlugin.onScroll, |
| 1015 dummyPlugin.pageXOffset, |
| 1016 dummyPlugin.pageYOffset, |
| 1017 dummyPlugin.setZoomLevel, |
| 1018 dummyPlugin.setPageXOffset, |
| 1019 dummyPlugin.setPageYOffset, |
| 1020 dummyPlugin.getHorizontalScrollbarThickness, |
| 1021 dummyPlugin.getVerticalScrollbarThickness, |
| 1022 dummyPlugin.getPageLocationNormalized, |
| 1023 dummyPlugin.getHeight, |
| 1024 dummyPlugin.getWidth ]; |
| 1025 |
| 1026 for (var i = 0; i < pluginInterface.length; i++) { |
| 1027 if (!pluginInterface[i]) |
| 1028 return false; |
| 1029 } |
| 1030 return true; |
987 } | 1031 } |
988 | 1032 |
989 /** | 1033 /** |
990 * Sets the default values and sends a request to regenerate preview data. | 1034 * Sets the default values and sends a request to regenerate preview data. |
991 * Resets the margin options only if |resetMargins| is true. | 1035 * Resets the margin options only if |resetMargins| is true. |
992 */ | 1036 */ |
993 function setDefaultValuesAndRegeneratePreview(resetMargins) { | 1037 function setDefaultValuesAndRegeneratePreview(resetMargins) { |
994 if (resetMargins) | 1038 if (resetMargins) |
995 marginSettings.resetMarginsIfNeeded(); | 1039 marginSettings.resetMarginsIfNeeded(); |
996 pageSettings.resetState(); | 1040 pageSettings.resetState(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 <include src="print_preview_animations.js"/> | 1098 <include src="print_preview_animations.js"/> |
1055 <include src="print_preview_cloud.js"/> | 1099 <include src="print_preview_cloud.js"/> |
1056 <include src="print_preview_utils.js"/> | 1100 <include src="print_preview_utils.js"/> |
1057 <include src="print_header.js"/> | 1101 <include src="print_header.js"/> |
1058 <include src="page_settings.js"/> | 1102 <include src="page_settings.js"/> |
1059 <include src="copies_settings.js"/> | 1103 <include src="copies_settings.js"/> |
1060 <include src="header_footer_settings.js"/> | 1104 <include src="header_footer_settings.js"/> |
1061 <include src="layout_settings.js"/> | 1105 <include src="layout_settings.js"/> |
1062 <include src="color_settings.js"/> | 1106 <include src="color_settings.js"/> |
1063 <include src="margin_settings.js"/> | 1107 <include src="margin_settings.js"/> |
| 1108 <include src="margin_textbox.js"/> |
| 1109 <include src="margin_line.js"/> |
| 1110 <include src="margin_utils.js"/> |
| 1111 <include src="margins_ui.js"/> |
| 1112 <include src="preview_area.js"/> |
OLD | NEW |