Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/resources/print_preview/print_preview.js

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

Powered by Google App Engine
This is Rietveld 408576698