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 // <include src="component.js"> | 7 // <include src="component.js"> |
8 // <include src="print_preview_focus_manager.js"> | 8 // <include src="print_preview_focus_manager.js"> |
9 // | 9 // |
10 | 10 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
303 * @private | 303 * @private |
304 */ | 304 */ |
305 this.isPreviewGenerationInProgress_ = true; | 305 this.isPreviewGenerationInProgress_ = true; |
306 | 306 |
307 /** | 307 /** |
308 * Whether to show system dialog before next printing. | 308 * Whether to show system dialog before next printing. |
309 * @type {boolean} | 309 * @type {boolean} |
310 * @private | 310 * @private |
311 */ | 311 */ |
312 this.showSystemDialogBeforeNextPrint_ = false; | 312 this.showSystemDialogBeforeNextPrint_ = false; |
313 | |
314 /** | |
315 * Whether the preview is listening for the manipulate-settings-for-test | |
316 * UI event. | |
317 * @private {boolean} | |
318 */ | |
319 this.isListeningForManipulateSettings_ = false; | |
313 } | 320 } |
314 | 321 |
315 PrintPreview.prototype = { | 322 PrintPreview.prototype = { |
316 __proto__: print_preview.Component.prototype, | 323 __proto__: print_preview.Component.prototype, |
317 /** | 324 /** |
318 * @return {!print_preview.PreviewArea} The preview area. Used for tests. | 325 * @return {!print_preview.PreviewArea} The preview area. Used for tests. |
319 */ | 326 */ |
320 getPreviewArea: function() { | 327 getPreviewArea: function() { |
321 return this.previewArea_; | 328 return this.previewArea_; |
322 }, | 329 }, |
(...skipping 11 matching lines...) Expand all Loading... | |
334 this.listenerTracker.add('print-failed', this.onPrintFailed_.bind(this)); | 341 this.listenerTracker.add('print-failed', this.onPrintFailed_.bind(this)); |
335 this.listenerTracker.add( | 342 this.listenerTracker.add( |
336 'privet-printer-added', | 343 'privet-printer-added', |
337 this.destinationStore_.onPrivetPrinterAdded_.bind( | 344 this.destinationStore_.onPrivetPrinterAdded_.bind( |
338 this.destinationStore_)); | 345 this.destinationStore_)); |
339 this.listenerTracker.add( | 346 this.listenerTracker.add( |
340 'extension-printers-added', | 347 'extension-printers-added', |
341 this.destinationStore_.onExtensionPrintersAdded_.bind( | 348 this.destinationStore_.onExtensionPrintersAdded_.bind( |
342 this.destinationStore_)); | 349 this.destinationStore_)); |
343 this.listenerTracker.add( | 350 this.listenerTracker.add( |
351 'reload-printer-list', | |
352 this.destinationStore_.onDestinationsReload_.bind( | |
dpapad
2017/07/07 17:28:43
Two questions:
1) If onDestinationsReload_ has to
rbpotter
2017/07/07 17:40:13
1) No, compiler did not complain. Will make it pub
dpapad
2017/07/07 18:04:29
Ok, that's odd. I am wondering if this is related
rbpotter
2017/07/07 20:45:10
Done. That does seem a bit cleaner than having to
| |
353 this.destinationStore_)); | |
354 this.listenerTracker.add( | |
344 'use-cloud-print', this.onCloudPrintEnable_.bind(this)); | 355 'use-cloud-print', this.onCloudPrintEnable_.bind(this)); |
356 this.listenerTracker.add( | |
357 'print-preset-options', | |
358 this.onPrintPresetOptionsFromDocument_.bind(this)); | |
359 this.listenerTracker.add( | |
360 'preview-page-count', this.onPageCountReady_.bind(this)); | |
361 this.listenerTracker.add( | |
362 'enable-manipulate-settings-for-test', | |
363 this.onEnableManipulateSettingsForTest_.bind(this)); | |
345 }, | 364 }, |
346 | 365 |
347 /** @override */ | 366 /** @override */ |
348 enterDocument: function() { | 367 enterDocument: function() { |
349 // Native layer events. | |
350 var nativeLayerEventTarget = this.nativeLayer_.getEventTarget(); | |
351 this.tracker.add( | |
352 nativeLayerEventTarget, | |
353 print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS, | |
354 this.onPrintPresetOptionsFromDocument_.bind(this)); | |
355 this.tracker.add( | |
356 nativeLayerEventTarget, | |
357 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, | |
358 this.onPageCountReady_.bind(this)); | |
359 this.tracker.add( | |
360 nativeLayerEventTarget, | |
361 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, | |
362 this.onManipulateSettingsForTest_.bind(this)); | |
363 | |
364 if ($('system-dialog-link')) { | 368 if ($('system-dialog-link')) { |
365 this.tracker.add( | 369 this.tracker.add( |
366 getRequiredElement('system-dialog-link'), 'click', | 370 getRequiredElement('system-dialog-link'), 'click', |
367 this.openSystemPrintDialog_.bind(this)); | 371 this.openSystemPrintDialog_.bind(this)); |
368 } | 372 } |
369 if ($('open-pdf-in-preview-link')) { | 373 if ($('open-pdf-in-preview-link')) { |
370 this.tracker.add( | 374 this.tracker.add( |
371 getRequiredElement('open-pdf-in-preview-link'), 'click', | 375 getRequiredElement('open-pdf-in-preview-link'), 'click', |
372 this.onOpenPdfInPreviewLinkClick_.bind(this)); | 376 this.onOpenPdfInPreviewLinkClick_.bind(this)); |
373 } | 377 } |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 this.isPreviewGenerationInProgress_ = true; | 821 this.isPreviewGenerationInProgress_ = true; |
818 }, | 822 }, |
819 | 823 |
820 /** | 824 /** |
821 * Called when the preview area's preview generation is complete. | 825 * Called when the preview area's preview generation is complete. |
822 * @private | 826 * @private |
823 */ | 827 */ |
824 onPreviewGenerationDone_: function() { | 828 onPreviewGenerationDone_: function() { |
825 this.isPreviewGenerationInProgress_ = false; | 829 this.isPreviewGenerationInProgress_ = false; |
826 this.printHeader_.isPrintButtonEnabled = true; | 830 this.printHeader_.isPrintButtonEnabled = true; |
827 this.nativeLayer_.previewReadyForTest(); | 831 if (this.isListeningForManipulateSettings_) |
832 this.nativeLayer_.previewReadyForTest(); | |
828 this.printIfReady_(); | 833 this.printIfReady_(); |
829 }, | 834 }, |
830 | 835 |
831 /** | 836 /** |
832 * Called when the preview area's preview failed to load. | 837 * Called when the preview area's preview failed to load. |
833 * @private | 838 * @private |
834 */ | 839 */ |
835 onPreviewGenerationFail_: function() { | 840 onPreviewGenerationFail_: function() { |
836 this.isPreviewGenerationInProgress_ = false; | 841 this.isPreviewGenerationInProgress_ = false; |
837 this.printHeader_.isPrintButtonEnabled = false; | 842 this.printHeader_.isPrintButtonEnabled = false; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
995 }, | 1000 }, |
996 | 1001 |
997 /** | 1002 /** |
998 * Called when the user wants to sign in to Google Cloud Print. Calls the | 1003 * Called when the user wants to sign in to Google Cloud Print. Calls the |
999 * corresponding native layer event. | 1004 * corresponding native layer event. |
1000 * @param {boolean} addAccount Whether to open an 'add a new account' or | 1005 * @param {boolean} addAccount Whether to open an 'add a new account' or |
1001 * default sign in page. | 1006 * default sign in page. |
1002 * @private | 1007 * @private |
1003 */ | 1008 */ |
1004 onCloudPrintSignInActivated_: function(addAccount) { | 1009 onCloudPrintSignInActivated_: function(addAccount) { |
1005 this.nativeLayer_.startCloudPrintSignIn(addAccount); | 1010 this.nativeLayer_.signIn(addAccount) |
1011 .then(this.destinationStore_.onDestinationsReload_.bind( | |
1012 this.destinationStore_)); | |
1006 }, | 1013 }, |
1007 | 1014 |
1008 /** | 1015 /** |
1009 * Updates printing options according to source document presets. | 1016 * Updates printing options according to source document presets. |
1010 * @param {Event} event Contains options from source document. | 1017 * @param {boolean} disableScaling Whether the document disables scaling. |
1018 * @param {number} copies The default number of copies from the document. | |
1019 * @param {number} duplex The default duplex setting from the document. | |
1011 * @private | 1020 * @private |
1012 */ | 1021 */ |
1013 onPrintPresetOptionsFromDocument_: function(event) { | 1022 onPrintPresetOptionsFromDocument_: function( |
1014 if (event.optionsFromDocument.disableScaling) | 1023 disableScaling, copies, duplex) { |
1024 if (disableScaling) | |
1015 this.documentInfo_.updateIsScalingDisabled(true); | 1025 this.documentInfo_.updateIsScalingDisabled(true); |
1016 | 1026 |
1017 if (event.optionsFromDocument.copies > 0 && | 1027 if (copies > 0 && this.printTicketStore_.copies.isCapabilityAvailable()) { |
1018 this.printTicketStore_.copies.isCapabilityAvailable()) { | 1028 this.printTicketStore_.copies.updateValue(copies); |
1019 this.printTicketStore_.copies.updateValue( | |
1020 event.optionsFromDocument.copies); | |
1021 } | 1029 } |
1022 | 1030 |
1023 if (event.optionsFromDocument.duplex >= 0 && | 1031 if (duplex >= 0 & this.printTicketStore_.duplex.isCapabilityAvailable()) { |
1024 this.printTicketStore_.duplex.isCapabilityAvailable()) { | 1032 this.printTicketStore_.duplex.updateValue(duplex); |
1025 this.printTicketStore_.duplex.updateValue( | |
1026 event.optionsFromDocument.duplex); | |
1027 } | 1033 } |
1028 }, | 1034 }, |
1029 | 1035 |
1030 /** | 1036 /** |
1031 * Called when the Page Count Ready message is received to update the fit to | 1037 * Called when the Page Count Ready message is received to update the fit to |
1032 * page scaling value in the scaling settings. | 1038 * page scaling value in the scaling settings. |
1033 * @param {Event} event Event object representing the page count ready | 1039 * @param {number} pageCount The document's page count (unused). |
1034 * message | 1040 * @param {number} previewResponseId The request ID that corresponds to this |
1041 * page count (unused). | |
1042 * @param {number} fitToPageScaling The scaling required to fit the document | |
1043 * to page. | |
1035 * @private | 1044 * @private |
1036 */ | 1045 */ |
1037 onPageCountReady_: function(event) { | 1046 onPageCountReady_: function( |
1038 if (event.fitToPageScaling >= 0) { | 1047 pageCount, previewResponseId, fitToPageScaling) { |
1039 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); | 1048 if (fitToPageScaling >= 0) { |
1049 this.scalingSettings_.updateFitToPageScaling(fitToPageScaling); | |
1040 } | 1050 } |
1041 }, | 1051 }, |
1042 | 1052 |
1043 /** | 1053 /** |
1044 * Called when printing to a privet or extension printer fails. | 1054 * Called when printing to a privet or extension printer fails. |
1045 * @param {*} httpError The HTTP error code, or -1 or a string describing | 1055 * @param {*} httpError The HTTP error code, or -1 or a string describing |
1046 * the error, if not an HTTP error. | 1056 * the error, if not an HTTP error. |
1047 * @private | 1057 * @private |
1048 */ | 1058 */ |
1049 onPrintFailed_: function(httpError) { | 1059 onPrintFailed_: function(httpError) { |
1050 console.error('Privet printing failed with error code ' + httpError); | 1060 console.error('Privet printing failed with error code ' + httpError); |
1051 this.printHeader_.setErrorMessage( | 1061 this.printHeader_.setErrorMessage( |
1052 loadTimeData.getString('couldNotPrint')); | 1062 loadTimeData.getString('couldNotPrint')); |
1053 }, | 1063 }, |
1054 | 1064 |
1055 /** | 1065 /** |
1056 * Called when the print preview settings need to be changed for testing. | 1066 * Called to start listening for the manipulate-settings-for-test WebUI |
1057 * @param {Event} event Event object that contains the option that is to | 1067 * event so that settings can be modified by this event. |
1058 * be changed and what to set that option. | |
1059 * @private | 1068 * @private |
1060 */ | 1069 */ |
1061 onManipulateSettingsForTest_: function(event) { | 1070 onEnableManipulateSettingsForTest_: function() { |
1062 var settings = | 1071 this.listenerTracker.add( |
1063 /** @type {print_preview.PreviewSettings} */ (event.settings); | 1072 'manipulate-settings-for-test', |
1073 this.onManipulateSettingsForTest_.bind(this)); | |
1074 this.isListeningForManipulateSettings_ = true; | |
1075 }, | |
1076 | |
1077 /** | |
1078 * Called when the print preview settings need to be changed for testing. | |
1079 * @param {!print_preview.PreviewSettings} settings Contains print preview | |
1080 * settings to change and the values to change them to. | |
1081 * @private | |
1082 */ | |
1083 onManipulateSettingsForTest_: function(settings) { | |
1064 if ('selectSaveAsPdfDestination' in settings) { | 1084 if ('selectSaveAsPdfDestination' in settings) { |
1065 this.saveAsPdfForTest_(); // No parameters. | 1085 this.saveAsPdfForTest_(); // No parameters. |
1066 } else if ('layoutSettings' in settings) { | 1086 } else if ('layoutSettings' in settings) { |
1067 this.setLayoutSettingsForTest_(settings.layoutSettings.portrait); | 1087 this.setLayoutSettingsForTest_(settings.layoutSettings.portrait); |
1068 } else if ('pageRange' in settings) { | 1088 } else if ('pageRange' in settings) { |
1069 this.setPageRangeForTest_(settings.pageRange); | 1089 this.setPageRangeForTest_(settings.pageRange); |
1070 } else if ('headersAndFooters' in settings) { | 1090 } else if ('headersAndFooters' in settings) { |
1071 this.setHeadersAndFootersForTest_(settings.headersAndFooters); | 1091 this.setHeadersAndFootersForTest_(settings.headersAndFooters); |
1072 } else if ('backgroundColorsAndImages' in settings) { | 1092 } else if ('backgroundColorsAndImages' in settings) { |
1073 this.setBackgroundColorsAndImagesForTest_( | 1093 this.setBackgroundColorsAndImagesForTest_( |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1360 // <include src="search/destination_search.js"> | 1380 // <include src="search/destination_search.js"> |
1361 // <include src="search/provisional_destination_resolver.js"> | 1381 // <include src="search/provisional_destination_resolver.js"> |
1362 | 1382 |
1363 window.addEventListener('DOMContentLoaded', function() { | 1383 window.addEventListener('DOMContentLoaded', function() { |
1364 var previewWindow = /** @type {{isTest: boolean}} */ (window); | 1384 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
1365 if (!previewWindow.isTest) { | 1385 if (!previewWindow.isTest) { |
1366 var printPreview = new print_preview.PrintPreview(); | 1386 var printPreview = new print_preview.PrintPreview(); |
1367 printPreview.initialize(); | 1387 printPreview.initialize(); |
1368 } | 1388 } |
1369 }); | 1389 }); |
OLD | NEW |