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

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

Issue 480303002: Use document from preview for System Dialog printing on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tue 08/19/2014 11:17:57.84 Created 6 years, 4 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) 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 * @private 219 * @private
220 */ 220 */
221 this.uiState_ = PrintPreview.UiState_.INITIALIZING; 221 this.uiState_ = PrintPreview.UiState_.INITIALIZING;
222 222
223 /** 223 /**
224 * Whether document preview generation is in progress. 224 * Whether document preview generation is in progress.
225 * @type {boolean} 225 * @type {boolean}
226 * @private 226 * @private
227 */ 227 */
228 this.isPreviewGenerationInProgress_ = true; 228 this.isPreviewGenerationInProgress_ = true;
229
230 /**
231 * Whether to show system dialog before next printing.
232 * @type {boolean}
233 * @private
234 */
235 this.showSystemDialog_ = false;
229 }; 236 };
230 237
231 /** 238 /**
232 * States of the print preview. 239 * States of the print preview.
233 * @enum {string} 240 * @enum {string}
234 * @private 241 * @private
235 */ 242 */
236 PrintPreview.UiState_ = { 243 PrintPreview.UiState_ = {
237 INITIALIZING: 'initializing', 244 INITIALIZING: 'initializing',
238 READY: 'ready', 245 READY: 'ready',
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 'Trying to print with invalid ticket'); 520 'Trying to print with invalid ticket');
514 if (this.uiState_ == PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG) { 521 if (this.uiState_ == PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG) {
515 this.nativeLayer_.startShowCloudPrintDialog( 522 this.nativeLayer_.startShowCloudPrintDialog(
516 this.printTicketStore_.pageRange.getPageNumberSet().size); 523 this.printTicketStore_.pageRange.getPageNumberSet().size);
517 } else { 524 } else {
518 this.nativeLayer_.startPrint( 525 this.nativeLayer_.startPrint(
519 this.destinationStore_.selectedDestination, 526 this.destinationStore_.selectedDestination,
520 this.printTicketStore_, 527 this.printTicketStore_,
521 this.cloudPrintInterface_, 528 this.cloudPrintInterface_,
522 this.documentInfo_, 529 this.documentInfo_,
523 this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW); 530 this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW,
531 this.showSystemDialog_);
524 } 532 }
525 return PrintPreview.PrintAttemptResult_.PRINTED; 533 return PrintPreview.PrintAttemptResult_.PRINTED;
526 }, 534 },
527 535
528 /** 536 /**
529 * Closes the print preview. 537 * Closes the print preview.
530 * @private 538 * @private
531 */ 539 */
532 close_: function() { 540 close_: function() {
533 this.exitDocument(); 541 this.exitDocument();
534 this.uiState_ = PrintPreview.UiState_.CLOSING; 542 this.uiState_ = PrintPreview.UiState_.CLOSING;
535 this.nativeLayer_.startCloseDialog(); 543 this.nativeLayer_.startCloseDialog();
536 }, 544 },
537 545
538 /** 546 /**
539 * Opens the native system print dialog after disabling all controls. 547 * Opens the native system print dialog after disabling all controls.
540 * @private 548 * @private
541 */ 549 */
542 openSystemPrintDialog_: function() { 550 openSystemPrintDialog_: function() {
551 if (!this.shouldShowSystemDialogLink_())
552 return;
543 setIsVisible($('system-dialog-throbber'), true); 553 setIsVisible($('system-dialog-throbber'), true);
544 this.setIsEnabled_(false); 554 this.setIsEnabled_(false);
545 this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG; 555 this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG;
546 this.nativeLayer_.startShowSystemDialog(); 556 this.nativeLayer_.startShowSystemDialog();
547 }, 557 },
548 558
549 /** 559 /**
550 * Called when the native layer has initial settings to set. Sets the 560 * Called when the native layer has initial settings to set. Sets the
551 * initial settings of the print preview and begins fetching print 561 * initial settings of the print preview and begins fetching print
552 * destinations. 562 * destinations.
(...skipping 21 matching lines...) Expand all
574 settings.documentHasSelection); 584 settings.documentHasSelection);
575 this.printTicketStore_.init( 585 this.printTicketStore_.init(
576 settings.thousandsDelimeter, 586 settings.thousandsDelimeter,
577 settings.decimalDelimeter, 587 settings.decimalDelimeter,
578 settings.unitType, 588 settings.unitType,
579 settings.selectionOnly); 589 settings.selectionOnly);
580 this.destinationStore_.init(settings.isInAppKioskMode); 590 this.destinationStore_.init(settings.isInAppKioskMode);
581 this.appState_.setInitialized(); 591 this.appState_.setInitialized();
582 592
583 $('document-title').innerText = settings.documentTitle; 593 $('document-title').innerText = settings.documentTitle;
584 setIsVisible($('system-dialog-link'), 594 if (settings.hidePrintWithSystemDialogLink || settings.isInAppKioskMode)
585 !settings.hidePrintWithSystemDialogLink && 595 this.shouldShowSystemDialogLink_ = function() { return false; };
Noam Samuel 2014/08/20 00:04:17 This seems like it could become fairly unreadable
Vitaly Buka (NO REVIEWS) 2014/08/20 02:42:55 Done.
586 !settings.isInAppKioskMode); 596 setIsVisible($('system-dialog-link'), this.shouldShowSystemDialogLink_());
587 }, 597 },
588 598
589 /** 599 /**
590 * Calls when the native layer enables Google Cloud Print integration. 600 * Calls when the native layer enables Google Cloud Print integration.
591 * Fetches the user's cloud printers. 601 * Fetches the user's cloud printers.
592 * @param {Event} event Contains the base URL of the Google Cloud Print 602 * @param {Event} event Contains the base URL of the Google Cloud Print
593 * service. 603 * service.
594 * @private 604 * @private
595 */ 605 */
596 onCloudPrintEnable_: function(event) { 606 onCloudPrintEnable_: function(event) {
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 this.nativeLayer_.previewReadyForTest(); 1066 this.nativeLayer_.previewReadyForTest();
1057 } else if (margins >= 0 && margins < combobox.length) { 1067 } else if (margins >= 0 && margins < combobox.length) {
1058 combobox.selectedIndex = margins; 1068 combobox.selectedIndex = margins;
1059 this.marginSettings_.onSelectChange_(); 1069 this.marginSettings_.onSelectChange_();
1060 } else { 1070 } else {
1061 this.nativeLayer_.previewFailedForTest(); 1071 this.nativeLayer_.previewFailedForTest();
1062 } 1072 }
1063 }, 1073 },
1064 1074
1065 /** 1075 /**
1076 * Returns true if "Print using system dialog" link should be shown for
1077 * current destination.
1078 * @return {boolean} Returns true if link should be shown.
1079 */
1080 shouldShowSystemDialogLink_: function() {
1081 if (!cr.isWindows)
1082 return true;
1083 var selectedDest = this.destinationStore_.selectedDestination;
1084 return selectedDest &&
1085 selectedDest.origin == print_preview.Destination.Origin.LOCAL &&
1086 selectedDest.id !=
1087 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
1088 },
1089
1090 /**
1066 * Called when the open-cloud-print-dialog link is clicked. Opens the Google 1091 * Called when the open-cloud-print-dialog link is clicked. Opens the Google
1067 * Cloud Print web dialog. 1092 * Cloud Print web dialog.
1068 * @private 1093 * @private
1069 */ 1094 */
1070 onCloudPrintDialogLinkClick_: function() { 1095 onCloudPrintDialogLinkClick_: function() {
1071 assert(this.uiState_ == PrintPreview.UiState_.READY, 1096 assert(this.uiState_ == PrintPreview.UiState_.READY,
1072 'Opening Google Cloud Print dialog when not in ready state: ' + 1097 'Opening Google Cloud Print dialog when not in ready state: ' +
1073 this.uiState_); 1098 this.uiState_);
1074 setIsVisible($('cloud-print-dialog-throbber'), true); 1099 setIsVisible($('cloud-print-dialog-throbber'), true);
1075 this.setIsEnabled_(false); 1100 this.setIsEnabled_(false);
1076 this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG; 1101 this.uiState_ = PrintPreview.UiState_.OPENING_CLOUD_PRINT_DIALOG;
1077 this.printIfReady_(); 1102 this.printIfReady_();
1078 }, 1103 },
1079 1104
1080 /** 1105 /**
1081 * Called when a print destination is selected. Shows/hides the "Print with 1106 * Called when a print destination is selected. Shows/hides the "Print with
1082 * Cloud Print" link in the navbar. 1107 * Cloud Print" link in the navbar.
1083 * @private 1108 * @private
1084 */ 1109 */
1085 onDestinationSelect_: function() { 1110 onDestinationSelect_: function() {
1086 var selectedDest = this.destinationStore_.selectedDestination; 1111 var selectedDest = this.destinationStore_.selectedDestination;
1087 setIsVisible( 1112 setIsVisible(
1088 $('cloud-print-dialog-link'), 1113 $('cloud-print-dialog-link'),
1089 selectedDest && !cr.isChromeOS && !selectedDest.isLocal); 1114 selectedDest && !cr.isChromeOS && !selectedDest.isLocal);
1115 setIsVisible(
1116 $('system-dialog-link'),
1117 this.shouldShowSystemDialogLink_());
1090 if (selectedDest && this.isInKioskAutoPrintMode_) { 1118 if (selectedDest && this.isInKioskAutoPrintMode_) {
1091 this.onPrintButtonClick_(); 1119 this.onPrintButtonClick_();
1092 } 1120 }
1093 }, 1121 },
1094 1122
1095 /** 1123 /**
1096 * Called when the destination store loads a group of destinations. Shows 1124 * Called when the destination store loads a group of destinations. Shows
1097 * a promo on Chrome OS if the user has no print destinations promoting 1125 * a promo on Chrome OS if the user has no print destinations promoting
1098 * Google Cloud Print. 1126 * Google Cloud Print.
1099 * @private 1127 * @private
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1212 <include src="search/cloud_destination_list.js"/> 1240 <include src="search/cloud_destination_list.js"/>
1213 <include src="search/recent_destination_list.js"/> 1241 <include src="search/recent_destination_list.js"/>
1214 <include src="search/destination_list_item.js"/> 1242 <include src="search/destination_list_item.js"/>
1215 <include src="search/destination_search.js"/> 1243 <include src="search/destination_search.js"/>
1216 <include src="search/fedex_tos.js"/> 1244 <include src="search/fedex_tos.js"/>
1217 1245
1218 window.addEventListener('DOMContentLoaded', function() { 1246 window.addEventListener('DOMContentLoaded', function() {
1219 printPreview = new print_preview.PrintPreview(); 1247 printPreview = new print_preview.PrintPreview();
1220 printPreview.initialize(); 1248 printPreview.initialize();
1221 }); 1249 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698