Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODO(rltoscano): Move data/* into print_preview.data namespace | 5 // TODO(rltoscano): Move data/* into print_preview.data namespace |
| 6 | 6 |
| 7 var localStrings = new LocalStrings(templateData); | 7 var localStrings = new LocalStrings(templateData); |
| 8 | 8 |
| 9 <include src="component.js"/> | 9 <include src="component.js"/> |
| 10 | 10 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 print_preview.NativeLayer.EventType.SETTINGS_INVALID, | 278 print_preview.NativeLayer.EventType.SETTINGS_INVALID, |
| 279 this.onSettingsInvalid_.bind(this)); | 279 this.onSettingsInvalid_.bind(this)); |
| 280 this.tracker.add( | 280 this.tracker.add( |
| 281 this.nativeLayer_, | 281 this.nativeLayer_, |
| 282 print_preview.NativeLayer.EventType.DISABLE_SCALING, | 282 print_preview.NativeLayer.EventType.DISABLE_SCALING, |
| 283 this.onDisableScaling_.bind(this)); | 283 this.onDisableScaling_.bind(this)); |
| 284 this.tracker.add( | 284 this.tracker.add( |
| 285 this.nativeLayer_, | 285 this.nativeLayer_, |
| 286 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, | 286 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, |
| 287 this.onPrivetPrintFailed_.bind(this)); | 287 this.onPrivetPrintFailed_.bind(this)); |
| 288 | 288 this.tracker.add( |
| 289 this.nativeLayer_, | |
| 290 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, | |
| 291 this.onManipulateSettingsForTest_.bind(this)); | |
| 289 | 292 |
| 290 this.tracker.add( | 293 this.tracker.add( |
| 291 $('system-dialog-link'), | 294 $('system-dialog-link'), |
| 292 'click', | 295 'click', |
| 293 this.openSystemPrintDialog_.bind(this)); | 296 this.openSystemPrintDialog_.bind(this)); |
| 294 this.tracker.add( | 297 this.tracker.add( |
| 295 $('cloud-print-dialog-link'), | 298 $('cloud-print-dialog-link'), |
| 296 'click', | 299 'click', |
| 297 this.onCloudPrintDialogLinkClick_.bind(this)); | 300 this.onCloudPrintDialogLinkClick_.bind(this)); |
| 298 this.tracker.add( | 301 this.tracker.add( |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 684 this.isPreviewGenerationInProgress_ = true; | 687 this.isPreviewGenerationInProgress_ = true; |
| 685 }, | 688 }, |
| 686 | 689 |
| 687 /** | 690 /** |
| 688 * Called when the preview area's preview generation is complete. | 691 * Called when the preview area's preview generation is complete. |
| 689 * @private | 692 * @private |
| 690 */ | 693 */ |
| 691 onPreviewGenerationDone_: function() { | 694 onPreviewGenerationDone_: function() { |
| 692 this.isPreviewGenerationInProgress_ = false; | 695 this.isPreviewGenerationInProgress_ = false; |
| 693 this.printHeader_.isPrintButtonEnabled = true; | 696 this.printHeader_.isPrintButtonEnabled = true; |
| 697 this.nativeLayer_.previewReadyForTest(); | |
| 694 this.printIfReady_(); | 698 this.printIfReady_(); |
| 695 }, | 699 }, |
| 696 | 700 |
| 697 /** | 701 /** |
| 698 * Called when the preview area's preview failed to load. | 702 * Called when the preview area's preview failed to load. |
| 699 * @private | 703 * @private |
| 700 */ | 704 */ |
| 701 onPreviewGenerationFail_: function() { | 705 onPreviewGenerationFail_: function() { |
| 702 this.isPreviewGenerationInProgress_ = false; | 706 this.isPreviewGenerationInProgress_ = false; |
| 703 this.printHeader_.isPrintButtonEnabled = false; | 707 this.printHeader_.isPrintButtonEnabled = false; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 * @private | 887 * @private |
| 884 */ | 888 */ |
| 885 onPrivetPrintFailed_: function(event) { | 889 onPrivetPrintFailed_: function(event) { |
| 886 console.error('Privet printing failed with error code ' + | 890 console.error('Privet printing failed with error code ' + |
| 887 event.httpError); | 891 event.httpError); |
| 888 this.printHeader_.setErrorMessage( | 892 this.printHeader_.setErrorMessage( |
| 889 localStrings.getString('couldNotPrint')); | 893 localStrings.getString('couldNotPrint')); |
| 890 }, | 894 }, |
| 891 | 895 |
| 892 /** | 896 /** |
| 897 * Called when the print preview settings need to be changed for testing. | |
| 898 * @param {Event} event Event object that contains the option that is to | |
| 899 * be changed and what to set that option. | |
| 900 * @private | |
| 901 */ | |
| 902 onManipulateSettingsForTest_: function(event) { | |
| 903 if ('selectSaveAsPdfDestination' in event.settings) { | |
| 904 this.saveAsPdfForTest_(); // No parameters | |
| 905 } else if ('layoutSettings' in event.settings) { | |
| 906 this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait); | |
| 907 } else if ('pageRange' in event.settings) { | |
| 908 this.setPageRangeForTest_(event.settings.pageRange); | |
| 909 } else if ('headersAndFooters' in event.settings) { | |
| 910 this.setHeadersAndFootersForTest_(event.settings.headersAndFooters); | |
| 911 } else if ('backgroundColorsAndImages' in event.settings) { | |
| 912 this.setBackgroundColorsAndImagesForTest_( | |
| 913 event.settings.backgroundColorsAndImages); | |
| 914 } else if ('margins' in event.settings) { | |
| 915 this.setMarginsForTest_(event.settings.margins); | |
| 916 } | |
| 917 }, | |
| 918 | |
| 919 /** | |
| 920 * Called by onManipulateSettingsForTest_(). Sets the print destination | |
| 921 * as a pdf. | |
| 922 * @private | |
| 923 */ | |
| 924 saveAsPdfForTest_: function() { | |
| 925 if (print_preview.Destination.GooglePromotedId.SAVE_AS_PDF == | |
|
Aleksey Shlyapnikov
2014/07/09 01:45:07
Check that this.destinationStore_.selectedDestinat
| |
| 926 this.destinationStore_.selectedDestination.id) { | |
|
Aleksey Shlyapnikov
2014/07/09 01:45:07
2 less spaces indent.
| |
| 927 this.nativeLayer_.previewReadyForTest(); | |
| 928 return; | |
| 929 } | |
| 930 | |
| 931 var destinations = this.destinationStore_.destinations(); | |
| 932 var pdfDestination = null; | |
| 933 for (var i = 0; i < destinations.length; i++) { | |
| 934 if (destinations[i].id == | |
| 935 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | |
| 936 pdfDestination = destinations[i]; | |
| 937 break; | |
| 938 } | |
| 939 } | |
| 940 | |
| 941 if (pdfDestination) | |
| 942 this.destinationStore_.selectDestination(pdfDestination); | |
| 943 else | |
| 944 this.nativeLayer_.previewFailedForTest(); | |
| 945 }, | |
| 946 | |
| 947 /** | |
| 948 * Called by onManipulateSettingsForTest_(). Sets the layout settings to | |
| 949 * either portrait or landscape. | |
| 950 * @param {boolean} portrait Whether to use portrait page layout; | |
| 951 * if false: landscape. | |
| 952 * @private | |
| 953 */ | |
| 954 setLayoutSettingsForTest_: function(portrait) { | |
| 955 var element = document.querySelector(portrait ? | |
| 956 '.layout-settings-portrait-radio' : | |
| 957 '.layout-settings-landscape-radio'); | |
| 958 if (element.checked) | |
| 959 this.nativeLayer_.previewReadyForTest(); | |
| 960 else | |
| 961 element.click(); | |
| 962 }, | |
| 963 | |
| 964 /** | |
| 965 * Called by onManipulateSettingsForTest_(). Sets the page range for | |
| 966 * for the print preview settings. | |
| 967 * @param {string} pageRange Sets the page range to the desired value(s). | |
| 968 * Ex: "1-5,9" means pages 1 through 5 and page 9 will be printed. | |
| 969 * @private | |
| 970 */ | |
| 971 setPageRangeForTest_: function(pageRange) { | |
| 972 var textbox = document.querySelector('.page-settings-custom-input'); | |
| 973 if (textbox.value == pageRange) { | |
| 974 this.nativeLayer_.previewReadyForTest(); | |
| 975 } else { | |
| 976 textbox.value = pageRange; | |
| 977 document.querySelector('.page-settings-custom-radio').click(); | |
| 978 } | |
| 979 }, | |
| 980 | |
| 981 /** | |
| 982 * Called by onManipulateSettings_(). Checks or unchecks the headers and | |
| 983 * footers option on print preview. | |
| 984 * @param {boolean} headersAndFooters Whether the "Headers and Footers" | |
| 985 * checkbox should be checked. | |
| 986 * @private | |
| 987 */ | |
| 988 setHeadersAndFootersForTest_: function(headersAndFooters) { | |
| 989 var checkbox = document.querySelector('.header-footer-checkbox'); | |
| 990 if (headersAndFooters == checkbox.checked) | |
| 991 this.nativeLayer_.previewReadyForTest(); | |
| 992 else | |
| 993 checkbox.click(); | |
| 994 }, | |
| 995 | |
| 996 /** | |
| 997 * Called by onManipulateSettings_(). Checks or unchecks the background | |
| 998 * colors and images option on print preview. | |
| 999 * @param {boolean} backgroundColorsAndImages If true, the checkbox should | |
| 1000 * be checked. Otherwise it should be unchecked. | |
| 1001 * @private | |
| 1002 */ | |
| 1003 setBackgroundColorsAndImagesForTest_: function(backgroundColorsAndImages) { | |
| 1004 var checkbox = document.querySelector('.css-background-checkbox'); | |
| 1005 if (backgroundColorsAndImages == checkbox.checked) | |
| 1006 this.nativeLayer_.previewReadyForTest(); | |
| 1007 else | |
| 1008 checkbox.click(); | |
| 1009 }, | |
| 1010 | |
| 1011 /** | |
| 1012 * Called by onManipulateSettings_(). Sets the margin settings | |
| 1013 * that are desired. Custom margin settings aren't currently supported. | |
| 1014 * @param {number} margins The desired margins combobox index. Must be | |
| 1015 * a valid index or else the test fails. | |
| 1016 * @private | |
| 1017 */ | |
| 1018 setMarginsForTest_: function(margins) { | |
| 1019 var combobox = document.querySelector('.margin-settings-select'); | |
| 1020 if (margins == combobox.selectedIndex) { | |
| 1021 this.nativeLayer_.previewReadyForTest(); | |
| 1022 } else if (margins >= 0 && margins < combobox.length) { | |
| 1023 combobox.selectedIndex = margins; | |
| 1024 this.marginSettings_.onSelectChange_(); | |
| 1025 } else { | |
| 1026 this.nativeLayer_.previewFailedForTest(); | |
| 1027 } | |
| 1028 }, | |
| 1029 | |
| 1030 /** | |
| 893 * Called when the open-cloud-print-dialog link is clicked. Opens the Google | 1031 * Called when the open-cloud-print-dialog link is clicked. Opens the Google |
| 894 * Cloud Print web dialog. | 1032 * Cloud Print web dialog. |
| 895 * @private | 1033 * @private |
| 896 */ | 1034 */ |
| 897 onCloudPrintDialogLinkClick_: function() { | 1035 onCloudPrintDialogLinkClick_: function() { |
| 898 assert(this.uiState_ == PrintPreview.UiState_.READY, | 1036 assert(this.uiState_ == PrintPreview.UiState_.READY, |
| 899 'Opening Google Cloud Print dialog when not in ready state: ' + | 1037 'Opening Google Cloud Print dialog when not in ready state: ' + |
| 900 this.uiState_); | 1038 this.uiState_); |
| 901 setIsVisible($('cloud-print-dialog-throbber'), true); | 1039 setIsVisible($('cloud-print-dialog-throbber'), true); |
| 902 this.setIsEnabled_(false); | 1040 this.setIsEnabled_(false); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1034 <include src="search/recent_destination_list.js"/> | 1172 <include src="search/recent_destination_list.js"/> |
| 1035 <include src="search/destination_list_item.js"/> | 1173 <include src="search/destination_list_item.js"/> |
| 1036 <include src="search/destination_search.js"/> | 1174 <include src="search/destination_search.js"/> |
| 1037 <include src="search/search_box.js"/> | 1175 <include src="search/search_box.js"/> |
| 1038 <include src="search/fedex_tos.js"/> | 1176 <include src="search/fedex_tos.js"/> |
| 1039 | 1177 |
| 1040 window.addEventListener('DOMContentLoaded', function() { | 1178 window.addEventListener('DOMContentLoaded', function() { |
| 1041 printPreview = new print_preview.PrintPreview(); | 1179 printPreview = new print_preview.PrintPreview(); |
| 1042 printPreview.initialize(); | 1180 printPreview.initialize(); |
| 1043 }); | 1181 }); |
| OLD | NEW |