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

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

Issue 588713002: Compile print_preview, part 3: reduce down to 185 errors (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@I_print_preview_2
Patch Set: Created 6 years, 3 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
OLDNEW
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 <include src="print_preview_focus_manager.js"/> 10 <include src="print_preview_focus_manager.js"/>
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 /** 256 /**
257 * Whether to show system dialog before next printing. 257 * Whether to show system dialog before next printing.
258 * @type {boolean} 258 * @type {boolean}
259 * @private 259 * @private
260 */ 260 */
261 this.showSystemDialogBeforeNextPrint_ = false; 261 this.showSystemDialogBeforeNextPrint_ = false;
262 }; 262 };
263 263
264 /** 264 /**
265 * States of the print preview.
266 * @enum {string}
267 * @private
268 */
269 PrintPreview.UiState_ = {
270 INITIALIZING: 'initializing',
271 READY: 'ready',
272 OPENING_PDF_PREVIEW: 'opening-pdf-preview',
273 OPENING_CLOUD_PRINT_DIALOG: 'opening-cloud-print-dialog',
274 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
275 PRINTING: 'printing',
276 FILE_SELECTION: 'file-selection',
277 CLOSING: 'closing',
278 ERROR: 'error'
279 };
280
281 /**
282 * What can happen when print preview tries to print. 265 * What can happen when print preview tries to print.
283 * @enum {string} 266 * @enum {string}
284 * @private 267 * @private
285 */ 268 */
286 PrintPreview.PrintAttemptResult_ = { 269 PrintPreview.PrintAttemptResult_ = {
287 NOT_READY: 'not-ready', 270 NOT_READY: 'not-ready',
288 PRINTED: 'printed', 271 PRINTED: 'printed',
289 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' 272 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview'
290 }; 273 };
291 274
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 var devicesUrl = 'chrome://devices/register?id=' + e.destination.id; 817 var devicesUrl = 'chrome://devices/register?id=' + e.destination.id;
835 this.nativeLayer_.startForceOpenNewTab(devicesUrl); 818 this.nativeLayer_.startForceOpenNewTab(devicesUrl);
836 this.destinationStore_.waitForRegister(e.destination.id); 819 this.destinationStore_.waitForRegister(e.destination.id);
837 }, 820 },
838 821
839 /** 822 /**
840 * Consume escape key presses and ctrl + shift + p. Delegate everything else 823 * Consume escape key presses and ctrl + shift + p. Delegate everything else
841 * to the preview area. 824 * to the preview area.
842 * @param {KeyboardEvent} e The keyboard event. 825 * @param {KeyboardEvent} e The keyboard event.
843 * @private 826 * @private
827 * @suppress {uselessCode}
828 * Current compiler preprocessor leaves all the code inside all the <if>s,
829 * so the compiler claims that code after first return is unreachable.
844 */ 830 */
845 onKeyDown_: function(e) { 831 onKeyDown_: function(e) {
846 // Escape key closes the dialog. 832 // Escape key closes the dialog.
847 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && 833 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey &&
848 !e.metaKey) { 834 !e.metaKey) {
849 <if expr="toolkit_views"> 835 <if expr="toolkit_views">
850 // On the toolkit_views environment, ESC key is handled by C++-side 836 // On the toolkit_views environment, ESC key is handled by C++-side
851 // instead of JS-side. 837 // instead of JS-side.
852 return; 838 return;
853 </if> 839 </if>
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 this.destinationStore_.startLoadPrivetDestinations(); 903 this.destinationStore_.startLoadPrivetDestinations();
918 }, 904 },
919 905
920 /** 906 /**
921 * Called when the destination settings' change button is activated. 907 * Called when the destination settings' change button is activated.
922 * Displays the destination search component. 908 * Displays the destination search component.
923 * @private 909 * @private
924 */ 910 */
925 onAdvancedOptionsButtonActivated_: function() { 911 onAdvancedOptionsButtonActivated_: function() {
926 this.advancedSettings_.showForDestination( 912 this.advancedSettings_.showForDestination(
927 this.destinationStore_.selectedDestination); 913 assert(this.destinationStore_.selectedDestination));
928 }, 914 },
929 915
930 /** 916 /**
931 * Called when the destination search dispatches manage cloud destinations 917 * Called when the destination search dispatches manage cloud destinations
932 * event. Calls corresponding native layer method. 918 * event. Calls corresponding native layer method.
933 * @private 919 * @private
934 */ 920 */
935 onManageCloudDestinationsActivated_: function() { 921 onManageCloudDestinationsActivated_: function() {
936 this.nativeLayer_.startManageCloudDestinations(); 922 this.nativeLayer_.startManageCloudDestinations();
937 }, 923 },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 localStrings.getString('couldNotPrint')); 964 localStrings.getString('couldNotPrint'));
979 }, 965 },
980 966
981 /** 967 /**
982 * Called when the print preview settings need to be changed for testing. 968 * Called when the print preview settings need to be changed for testing.
983 * @param {Event} event Event object that contains the option that is to 969 * @param {Event} event Event object that contains the option that is to
984 * be changed and what to set that option. 970 * be changed and what to set that option.
985 * @private 971 * @private
986 */ 972 */
987 onManipulateSettingsForTest_: function(event) { 973 onManipulateSettingsForTest_: function(event) {
974 event.settings =
975 /** @type {print_preview.PreviewSettings} */(event.settings);
988 if ('selectSaveAsPdfDestination' in event.settings) { 976 if ('selectSaveAsPdfDestination' in event.settings) {
989 this.saveAsPdfForTest_(); // No parameters. 977 this.saveAsPdfForTest_(); // No parameters.
990 } else if ('layoutSettings' in event.settings) { 978 } else if ('layoutSettings' in event.settings) {
991 this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait); 979 this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait);
992 } else if ('pageRange' in event.settings) { 980 } else if ('pageRange' in event.settings) {
993 this.setPageRangeForTest_(event.settings.pageRange); 981 this.setPageRangeForTest_(event.settings.pageRange);
994 } else if ('headersAndFooters' in event.settings) { 982 } else if ('headersAndFooters' in event.settings) {
995 this.setHeadersAndFootersForTest_(event.settings.headersAndFooters); 983 this.setHeadersAndFootersForTest_(event.settings.headersAndFooters);
996 } else if ('backgroundColorsAndImages' in event.settings) { 984 } else if ('backgroundColorsAndImages' in event.settings) {
997 this.setBackgroundColorsAndImagesForTest_( 985 this.setBackgroundColorsAndImagesForTest_(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 * Returns true if "Print using system dialog" link should be shown for 1105 * Returns true if "Print using system dialog" link should be shown for
1118 * current destination. 1106 * current destination.
1119 * @return {boolean} Returns true if link should be shown. 1107 * @return {boolean} Returns true if link should be shown.
1120 */ 1108 */
1121 shouldShowSystemDialogLink_: function() { 1109 shouldShowSystemDialogLink_: function() {
1122 if (!this.isSystemDialogAvailable_) 1110 if (!this.isSystemDialogAvailable_)
1123 return false; 1111 return false;
1124 if (!cr.isWindows) 1112 if (!cr.isWindows)
1125 return true; 1113 return true;
1126 var selectedDest = this.destinationStore_.selectedDestination; 1114 var selectedDest = this.destinationStore_.selectedDestination;
1127 return selectedDest && 1115 return !!selectedDest &&
1128 selectedDest.origin == print_preview.Destination.Origin.LOCAL && 1116 selectedDest.origin == print_preview.Destination.Origin.LOCAL &&
1129 selectedDest.id != 1117 selectedDest.id !=
1130 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; 1118 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
1131 }, 1119 },
1132 1120
1133 /** 1121 /**
1134 * Called when the open-cloud-print-dialog link is clicked. Opens the Google 1122 * Called when the open-cloud-print-dialog link is clicked. Opens the Google
1135 * Cloud Print web dialog. 1123 * Cloud Print web dialog.
1136 * @private 1124 * @private
1137 */ 1125 */
1138 onCloudPrintDialogLinkClick_: function() { 1126 onCloudPrintDialogLinkClick_: function() {
1139 assert(this.uiState_ == PrintPreview.UiState_.READY, 1127 assert(this.uiState_ == PrintPreview.UiState_.READY,
1140 'Opening Google Cloud Print dialog when not in ready state: ' + 1128 'Opening Google Cloud Print dialog when not in ready state: ' +
1141 this.uiState_); 1129 this.uiState_);
1142 setIsVisible(getRequiredElement('cloud-print-dialog-throbber'), true); 1130 setIsVisible(getRequiredElement('cloud-print-dialog-throbber'), true);
1143 this.setIsEnabled_(false); 1131 this.setIsEnabled_(false);
1144 this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG; 1132 this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG;
1145 this.printIfReady_(); 1133 this.printIfReady_();
1146 }, 1134 },
1147 1135
1148 /** 1136 /**
1149 * Called when a print destination is selected. Shows/hides the "Print with 1137 * Called when a print destination is selected. Shows/hides the "Print with
1150 * Cloud Print" link in the navbar. 1138 * Cloud Print" link in the navbar.
1151 * @private 1139 * @private
1152 */ 1140 */
1153 onDestinationSelect_: function() { 1141 onDestinationSelect_: function() {
1154 var selectedDest = this.destinationStore_.selectedDestination; 1142 var selectedDest = this.destinationStore_.selectedDestination;
1155 setIsVisible( 1143 setIsVisible(
1156 getRequiredElement('cloud-print-dialog-link'), 1144 getRequiredElement('cloud-print-dialog-link'),
1157 selectedDest && !cr.isChromeOS && !selectedDest.isLocal); 1145 !!selectedDest && !cr.isChromeOS && !selectedDest.isLocal);
1158 setIsVisible( 1146 setIsVisible(
1159 getRequiredElement('system-dialog-link'), 1147 getRequiredElement('system-dialog-link'),
1160 this.shouldShowSystemDialogLink_()); 1148 this.shouldShowSystemDialogLink_());
1161 if (selectedDest && this.isInKioskAutoPrintMode_) { 1149 if (selectedDest && this.isInKioskAutoPrintMode_) {
1162 this.onPrintButtonClick_(); 1150 this.onPrintButtonClick_();
1163 } 1151 }
1164 }, 1152 },
1165 1153
1166 /** 1154 /**
1167 * Called when the destination store loads a group of destinations. Shows 1155 * Called when the destination store loads a group of destinations. Shows
1168 * a promo on Chrome OS if the user has no print destinations promoting 1156 * a promo on Chrome OS if the user has no print destinations promoting
1169 * Google Cloud Print. 1157 * Google Cloud Print.
1170 * @private 1158 * @private
1171 */ 1159 */
1172 onDestinationSearchDone_: function() { 1160 onDestinationSearchDone_: function() {
1173 var isPromoVisible = cr.isChromeOS && 1161 var isPromoVisible = cr.isChromeOS &&
1174 this.cloudPrintInterface_ && 1162 this.cloudPrintInterface_ &&
1175 this.userInfo_.activeUser && 1163 this.userInfo_.activeUser &&
1176 !this.appState_.isGcpPromoDismissed && 1164 !this.appState_.isGcpPromoDismissed &&
Aleksey Shlyapnikov 2014/09/22 22:00:40 It should be: !this.destinationStore_.isLocalD
Vitaly Pavlenko 2014/09/22 22:33:11 Done.
1177 !this.destinationStore_.isLocalDestinationsSearchInProgress &&
1178 !this.destinationStore_.isCloudDestinationsSearchInProgress &&
1179 this.destinationStore_.hasOnlyDefaultCloudDestinations(); 1165 this.destinationStore_.hasOnlyDefaultCloudDestinations();
1180 setIsVisible(this.getChildElement('#no-destinations-promo'), 1166 setIsVisible(this.getChildElement('#no-destinations-promo'),
1181 isPromoVisible); 1167 isPromoVisible);
1182 if (isPromoVisible) { 1168 if (isPromoVisible) {
1183 new print_preview.GcpPromoMetricsContext().record( 1169 new print_preview.GcpPromoMetricsContext().record(
1184 print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN); 1170 print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN);
1185 } 1171 }
1186 }, 1172 },
1187 1173
1188 /** 1174 /**
(...skipping 22 matching lines...) Expand all
1211 this.close_(); 1197 this.close_();
1212 } 1198 }
1213 }; 1199 };
1214 1200
1215 // Export 1201 // Export
1216 return { 1202 return {
1217 PrintPreview: PrintPreview 1203 PrintPreview: PrintPreview
1218 }; 1204 };
1219 }); 1205 });
1220 1206
1207 /**
1208 * States of the print preview.
1209 * @enum {string}
1210 * @private
1211 */
1212 print_preview.PrintPreview.UiState_ = {
1213 INITIALIZING: 'initializing',
1214 READY: 'ready',
1215 OPENING_PDF_PREVIEW: 'opening-pdf-preview',
1216 OPENING_CLOUD_PRINT_DIALOG: 'opening-cloud-print-dialog',
1217 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
1218 PRINTING: 'printing',
1219 FILE_SELECTION: 'file-selection',
1220 CLOSING: 'closing',
1221 ERROR: 'error'
1222 };
1223
1221 // Pull in all other scripts in a single shot. 1224 // Pull in all other scripts in a single shot.
1222 <include src="common/overlay.js"/> 1225 <include src="common/overlay.js"/>
1223 <include src="common/search_box.js"/> 1226 <include src="common/search_box.js"/>
1224 <include src="common/search_bubble.js"/> 1227 <include src="common/search_bubble.js"/>
1225 1228
1226 <include src="data/page_number_set.js"/> 1229 <include src="data/page_number_set.js"/>
1227 <include src="data/destination.js"/> 1230 <include src="data/destination.js"/>
1228 <include src="data/local_parsers.js"/> 1231 <include src="data/local_parsers.js"/>
1229 <include src="data/cloud_parsers.js"/> 1232 <include src="data/cloud_parsers.js"/>
1230 <include src="data/destination_store.js"/> 1233 <include src="data/destination_store.js"/>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 <include src="search/cloud_destination_list.js"/> 1290 <include src="search/cloud_destination_list.js"/>
1288 <include src="search/recent_destination_list.js"/> 1291 <include src="search/recent_destination_list.js"/>
1289 <include src="search/destination_list_item.js"/> 1292 <include src="search/destination_list_item.js"/>
1290 <include src="search/destination_search.js"/> 1293 <include src="search/destination_search.js"/>
1291 <include src="search/fedex_tos.js"/> 1294 <include src="search/fedex_tos.js"/>
1292 1295
1293 window.addEventListener('DOMContentLoaded', function() { 1296 window.addEventListener('DOMContentLoaded', function() {
1294 printPreview = new print_preview.PrintPreview(); 1297 printPreview = new print_preview.PrintPreview();
1295 printPreview.initialize(); 1298 printPreview.initialize();
1296 }); 1299 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698