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

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

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

Powered by Google App Engine
This is Rietveld 408576698