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

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: fixed comments Created 6 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
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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 262
263 /** 263 /**
264 * Whether to show system dialog before next printing. 264 * Whether to show system dialog before next printing.
265 * @type {boolean} 265 * @type {boolean}
266 * @private 266 * @private
267 */ 267 */
268 this.showSystemDialogBeforeNextPrint_ = false; 268 this.showSystemDialogBeforeNextPrint_ = false;
269 }; 269 };
270 270
271 /** 271 /**
272 * States of the print preview.
273 * @enum {string}
274 * @private
275 */
276 PrintPreview.UiState_ = {
277 INITIALIZING: 'initializing',
278 READY: 'ready',
279 OPENING_PDF_PREVIEW: 'opening-pdf-preview',
280 OPENING_CLOUD_PRINT_DIALOG: 'opening-cloud-print-dialog',
281 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
282 PRINTING: 'printing',
283 FILE_SELECTION: 'file-selection',
284 CLOSING: 'closing',
285 ERROR: 'error'
286 };
287
288 /**
289 * What can happen when print preview tries to print. 272 * What can happen when print preview tries to print.
290 * @enum {string} 273 * @enum {string}
291 * @private 274 * @private
292 */ 275 */
293 PrintPreview.PrintAttemptResult_ = { 276 PrintPreview.PrintAttemptResult_ = {
294 NOT_READY: 'not-ready', 277 NOT_READY: 'not-ready',
295 PRINTED: 'printed', 278 PRINTED: 'printed',
296 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' 279 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview'
297 }; 280 };
298 281
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 var devicesUrl = 'chrome://devices/register?id=' + e.destination.id; 826 var devicesUrl = 'chrome://devices/register?id=' + e.destination.id;
844 this.nativeLayer_.startForceOpenNewTab(devicesUrl); 827 this.nativeLayer_.startForceOpenNewTab(devicesUrl);
845 this.destinationStore_.waitForRegister(e.destination.id); 828 this.destinationStore_.waitForRegister(e.destination.id);
846 }, 829 },
847 830
848 /** 831 /**
849 * Consume escape key presses and ctrl + shift + p. Delegate everything else 832 * Consume escape key presses and ctrl + shift + p. Delegate everything else
850 * to the preview area. 833 * to the preview area.
851 * @param {KeyboardEvent} e The keyboard event. 834 * @param {KeyboardEvent} e The keyboard event.
852 * @private 835 * @private
836 * @suppress {uselessCode}
837 * Current compiler preprocessor leaves all the code inside all the <if>s,
838 * so the compiler claims that code after first return is unreachable.
853 */ 839 */
854 onKeyDown_: function(e) { 840 onKeyDown_: function(e) {
855 // Escape key closes the dialog. 841 // Escape key closes the dialog.
856 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey && 842 if (e.keyCode == 27 && !e.shiftKey && !e.ctrlKey && !e.altKey &&
857 !e.metaKey) { 843 !e.metaKey) {
858 <if expr="toolkit_views"> 844 <if expr="toolkit_views">
859 // On the toolkit_views environment, ESC key is handled by C++-side 845 // On the toolkit_views environment, ESC key is handled by C++-side
860 // instead of JS-side. 846 // instead of JS-side.
861 return; 847 return;
862 </if> 848 </if>
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 this.destinationSearch_.setIsVisible(true); 909 this.destinationSearch_.setIsVisible(true);
924 }, 910 },
925 911
926 /** 912 /**
927 * Called when the destination settings' change button is activated. 913 * Called when the destination settings' change button is activated.
928 * Displays the destination search component. 914 * Displays the destination search component.
929 * @private 915 * @private
930 */ 916 */
931 onAdvancedOptionsButtonActivated_: function() { 917 onAdvancedOptionsButtonActivated_: function() {
932 this.advancedSettings_.showForDestination( 918 this.advancedSettings_.showForDestination(
933 this.destinationStore_.selectedDestination); 919 assert(this.destinationStore_.selectedDestination));
934 }, 920 },
935 921
936 /** 922 /**
937 * Called when the destination search dispatches manage cloud destinations 923 * Called when the destination search dispatches manage cloud destinations
938 * event. Calls corresponding native layer method. 924 * event. Calls corresponding native layer method.
939 * @private 925 * @private
940 */ 926 */
941 onManageCloudDestinationsActivated_: function() { 927 onManageCloudDestinationsActivated_: function() {
942 this.nativeLayer_.startManageCloudDestinations(); 928 this.nativeLayer_.startManageCloudDestinations();
943 }, 929 },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 localStrings.getString('couldNotPrint')); 970 localStrings.getString('couldNotPrint'));
985 }, 971 },
986 972
987 /** 973 /**
988 * Called when the print preview settings need to be changed for testing. 974 * Called when the print preview settings need to be changed for testing.
989 * @param {Event} event Event object that contains the option that is to 975 * @param {Event} event Event object that contains the option that is to
990 * be changed and what to set that option. 976 * be changed and what to set that option.
991 * @private 977 * @private
992 */ 978 */
993 onManipulateSettingsForTest_: function(event) { 979 onManipulateSettingsForTest_: function(event) {
980 event.settings =
981 /** @type {print_preview.PreviewSettings} */(event.settings);
994 if ('selectSaveAsPdfDestination' in event.settings) { 982 if ('selectSaveAsPdfDestination' in event.settings) {
995 this.saveAsPdfForTest_(); // No parameters. 983 this.saveAsPdfForTest_(); // No parameters.
996 } else if ('layoutSettings' in event.settings) { 984 } else if ('layoutSettings' in event.settings) {
997 this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait); 985 this.setLayoutSettingsForTest_(event.settings.layoutSettings.portrait);
998 } else if ('pageRange' in event.settings) { 986 } else if ('pageRange' in event.settings) {
999 this.setPageRangeForTest_(event.settings.pageRange); 987 this.setPageRangeForTest_(event.settings.pageRange);
1000 } else if ('headersAndFooters' in event.settings) { 988 } else if ('headersAndFooters' in event.settings) {
1001 this.setHeadersAndFootersForTest_(event.settings.headersAndFooters); 989 this.setHeadersAndFootersForTest_(event.settings.headersAndFooters);
1002 } else if ('backgroundColorsAndImages' in event.settings) { 990 } else if ('backgroundColorsAndImages' in event.settings) {
1003 this.setBackgroundColorsAndImagesForTest_( 991 this.setBackgroundColorsAndImagesForTest_(
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 * Returns true if "Print using system dialog" link should be shown for 1111 * Returns true if "Print using system dialog" link should be shown for
1124 * current destination. 1112 * current destination.
1125 * @return {boolean} Returns true if link should be shown. 1113 * @return {boolean} Returns true if link should be shown.
1126 */ 1114 */
1127 shouldShowSystemDialogLink_: function() { 1115 shouldShowSystemDialogLink_: function() {
1128 if (!this.isSystemDialogAvailable_) 1116 if (!this.isSystemDialogAvailable_)
1129 return false; 1117 return false;
1130 if (!cr.isWindows) 1118 if (!cr.isWindows)
1131 return true; 1119 return true;
1132 var selectedDest = this.destinationStore_.selectedDestination; 1120 var selectedDest = this.destinationStore_.selectedDestination;
1133 return selectedDest && 1121 return !!selectedDest &&
1134 selectedDest.origin == print_preview.Destination.Origin.LOCAL && 1122 selectedDest.origin == print_preview.Destination.Origin.LOCAL &&
1135 selectedDest.id != 1123 selectedDest.id !=
1136 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; 1124 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
1137 }, 1125 },
1138 1126
1139 /** 1127 /**
1140 * Called when the open-cloud-print-dialog link is clicked. Opens the Google 1128 * Called when the open-cloud-print-dialog link is clicked. Opens the Google
1141 * Cloud Print web dialog. 1129 * Cloud Print web dialog.
1142 * @private 1130 * @private
1143 */ 1131 */
1144 onCloudPrintDialogLinkClick_: function() { 1132 onCloudPrintDialogLinkClick_: function() {
1145 assert(this.uiState_ == PrintPreview.UiState_.READY, 1133 assert(this.uiState_ == PrintPreview.UiState_.READY,
1146 'Opening Google Cloud Print dialog when not in ready state: ' + 1134 'Opening Google Cloud Print dialog when not in ready state: ' +
1147 this.uiState_); 1135 this.uiState_);
1148 setIsVisible(getRequiredElement('cloud-print-dialog-throbber'), true); 1136 setIsVisible(getRequiredElement('cloud-print-dialog-throbber'), true);
1149 this.setIsEnabled_(false); 1137 this.setIsEnabled_(false);
1150 this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG; 1138 this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG;
1151 this.printIfReady_(); 1139 this.printIfReady_();
1152 }, 1140 },
1153 1141
1154 /** 1142 /**
1155 * Called when a print destination is selected. Shows/hides the "Print with 1143 * Called when a print destination is selected. Shows/hides the "Print with
1156 * Cloud Print" link in the navbar. 1144 * Cloud Print" link in the navbar.
1157 * @private 1145 * @private
1158 */ 1146 */
1159 onDestinationSelect_: function() { 1147 onDestinationSelect_: function() {
1160 var selectedDest = this.destinationStore_.selectedDestination; 1148 var selectedDest = this.destinationStore_.selectedDestination;
1161 setIsVisible( 1149 setIsVisible(
1162 getRequiredElement('cloud-print-dialog-link'), 1150 getRequiredElement('cloud-print-dialog-link'),
1163 selectedDest && !cr.isChromeOS && !selectedDest.isLocal); 1151 !!selectedDest && !cr.isChromeOS && !selectedDest.isLocal);
1164 setIsVisible( 1152 setIsVisible(
1165 getRequiredElement('system-dialog-link'), 1153 getRequiredElement('system-dialog-link'),
1166 this.shouldShowSystemDialogLink_()); 1154 this.shouldShowSystemDialogLink_());
1167 if (selectedDest && this.isInKioskAutoPrintMode_) { 1155 if (selectedDest && this.isInKioskAutoPrintMode_) {
1168 this.onPrintButtonClick_(); 1156 this.onPrintButtonClick_();
1169 } 1157 }
1170 }, 1158 },
1171 1159
1172 /** 1160 /**
1173 * Called when the destination store loads a group of destinations. Shows 1161 * Called when the destination store loads a group of destinations. Shows
1174 * a promo on Chrome OS if the user has no print destinations promoting 1162 * a promo on Chrome OS if the user has no print destinations promoting
1175 * Google Cloud Print. 1163 * Google Cloud Print.
1176 * @private 1164 * @private
1177 */ 1165 */
1178 onDestinationSearchDone_: function() { 1166 onDestinationSearchDone_: function() {
1179 var isPromoVisible = cr.isChromeOS && 1167 var isPromoVisible = cr.isChromeOS &&
1180 this.cloudPrintInterface_ && 1168 this.cloudPrintInterface_ &&
1181 this.userInfo_.activeUser && 1169 this.userInfo_.activeUser &&
1182 !this.appState_.isGcpPromoDismissed && 1170 !this.appState_.isGcpPromoDismissed &&
1183 !this.destinationStore_.isLocalDestinationsSearchInProgress && 1171 !this.destinationStore_.isLocalDestinationSearchInProgress &&
1184 !this.destinationStore_.isCloudDestinationsSearchInProgress && 1172 !this.destinationStore_.isCloudDestinationSearchInProgress &&
1185 this.destinationStore_.hasOnlyDefaultCloudDestinations(); 1173 this.destinationStore_.hasOnlyDefaultCloudDestinations();
1186 setIsVisible(this.getChildElement('#no-destinations-promo'), 1174 setIsVisible(this.getChildElement('#no-destinations-promo'),
1187 isPromoVisible); 1175 isPromoVisible);
1188 if (isPromoVisible) { 1176 if (isPromoVisible) {
1189 new print_preview.GcpPromoMetricsContext().record( 1177 new print_preview.GcpPromoMetricsContext().record(
1190 print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN); 1178 print_preview.Metrics.GcpPromoBucket.PROMO_SHOWN);
1191 } 1179 }
1192 }, 1180 },
1193 1181
1194 /** 1182 /**
(...skipping 22 matching lines...) Expand all
1217 this.close_(); 1205 this.close_();
1218 } 1206 }
1219 }; 1207 };
1220 1208
1221 // Export 1209 // Export
1222 return { 1210 return {
1223 PrintPreview: PrintPreview 1211 PrintPreview: PrintPreview
1224 }; 1212 };
1225 }); 1213 });
1226 1214
1215 /**
1216 * States of the print preview.
1217 * @enum {string}
1218 * @private
1219 */
1220 print_preview.PrintPreview.UiState_ = {
1221 INITIALIZING: 'initializing',
1222 READY: 'ready',
1223 OPENING_PDF_PREVIEW: 'opening-pdf-preview',
1224 OPENING_CLOUD_PRINT_DIALOG: 'opening-cloud-print-dialog',
1225 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog',
1226 PRINTING: 'printing',
1227 FILE_SELECTION: 'file-selection',
1228 CLOSING: 'closing',
1229 ERROR: 'error'
1230 };
1231
1227 // Pull in all other scripts in a single shot. 1232 // Pull in all other scripts in a single shot.
1228 <include src="common/overlay.js"> 1233 <include src="common/overlay.js">
1229 <include src="common/search_box.js"> 1234 <include src="common/search_box.js">
1230 <include src="common/search_bubble.js"> 1235 <include src="common/search_bubble.js">
1231 1236
1232 <include src="data/page_number_set.js"> 1237 <include src="data/page_number_set.js">
1233 <include src="data/destination.js"> 1238 <include src="data/destination.js">
1234 <include src="data/local_parsers.js"> 1239 <include src="data/local_parsers.js">
1235 <include src="data/cloud_parsers.js"> 1240 <include src="data/cloud_parsers.js">
1236 <include src="data/destination_store.js"> 1241 <include src="data/destination_store.js">
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 <include src="search/cloud_destination_list.js"> 1300 <include src="search/cloud_destination_list.js">
1296 <include src="search/recent_destination_list.js"> 1301 <include src="search/recent_destination_list.js">
1297 <include src="search/destination_list_item.js"> 1302 <include src="search/destination_list_item.js">
1298 <include src="search/destination_search.js"> 1303 <include src="search/destination_search.js">
1299 <include src="search/fedex_tos.js"> 1304 <include src="search/fedex_tos.js">
1300 1305
1301 window.addEventListener('DOMContentLoaded', function() { 1306 window.addEventListener('DOMContentLoaded', function() {
1302 printPreview = new print_preview.PrintPreview(); 1307 printPreview = new print_preview.PrintPreview();
1303 printPreview.initialize(); 1308 printPreview.initialize();
1304 }); 1309 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698