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 }, |
323 | 330 |
324 /** Sets up the page and print preview by getting the printer list. */ | 331 /** Sets up the page and print preview by getting the printer list. */ |
325 initialize: function() { | 332 initialize: function() { |
326 this.decorate($('print-preview')); | 333 this.decorate($('print-preview')); |
327 if (!this.previewArea_.hasCompatiblePlugin) { | 334 if (!this.previewArea_.hasCompatiblePlugin) { |
328 this.setIsEnabled_(false); | 335 this.setIsEnabled_(false); |
329 } | 336 } |
330 this.nativeLayer_.getInitialSettings().then( | 337 this.nativeLayer_.getInitialSettings().then( |
331 this.onInitialSettingsSet_.bind(this)); | 338 this.onInitialSettingsSet_.bind(this)); |
332 print_preview.PrintPreviewFocusManager.getInstance().initialize(); | 339 print_preview.PrintPreviewFocusManager.getInstance().initialize(); |
333 cr.ui.FocusOutlineManager.forDocument(document); | 340 cr.ui.FocusOutlineManager.forDocument(document); |
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.destinationStore_.addWebUIEventListeners(this.listenerTracker); |
336 'privet-printer-added', | |
337 this.destinationStore_.onPrivetPrinterAdded_.bind( | |
338 this.destinationStore_)); | |
339 this.listenerTracker.add( | |
340 'extension-printers-added', | |
341 this.destinationStore_.onExtensionPrintersAdded_.bind( | |
342 this.destinationStore_)); | |
343 this.listenerTracker.add( | 343 this.listenerTracker.add( |
344 'use-cloud-print', this.onCloudPrintEnable_.bind(this)); | 344 'use-cloud-print', this.onCloudPrintEnable_.bind(this)); |
| 345 this.listenerTracker.add( |
| 346 'print-preset-options', |
| 347 this.onPrintPresetOptionsFromDocument_.bind(this)); |
| 348 this.listenerTracker.add( |
| 349 'preview-page-count', this.onPageCountReady_.bind(this)); |
| 350 this.listenerTracker.add( |
| 351 'enable-manipulate-settings-for-test', |
| 352 this.onEnableManipulateSettingsForTest_.bind(this)); |
345 }, | 353 }, |
346 | 354 |
347 /** @override */ | 355 /** @override */ |
348 enterDocument: function() { | 356 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')) { | 357 if ($('system-dialog-link')) { |
365 this.tracker.add( | 358 this.tracker.add( |
366 getRequiredElement('system-dialog-link'), 'click', | 359 getRequiredElement('system-dialog-link'), 'click', |
367 this.openSystemPrintDialog_.bind(this)); | 360 this.openSystemPrintDialog_.bind(this)); |
368 } | 361 } |
369 if ($('open-pdf-in-preview-link')) { | 362 if ($('open-pdf-in-preview-link')) { |
370 this.tracker.add( | 363 this.tracker.add( |
371 getRequiredElement('open-pdf-in-preview-link'), 'click', | 364 getRequiredElement('open-pdf-in-preview-link'), 'click', |
372 this.onOpenPdfInPreviewLinkClick_.bind(this)); | 365 this.onOpenPdfInPreviewLinkClick_.bind(this)); |
373 } | 366 } |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 this.isPreviewGenerationInProgress_ = true; | 810 this.isPreviewGenerationInProgress_ = true; |
818 }, | 811 }, |
819 | 812 |
820 /** | 813 /** |
821 * Called when the preview area's preview generation is complete. | 814 * Called when the preview area's preview generation is complete. |
822 * @private | 815 * @private |
823 */ | 816 */ |
824 onPreviewGenerationDone_: function() { | 817 onPreviewGenerationDone_: function() { |
825 this.isPreviewGenerationInProgress_ = false; | 818 this.isPreviewGenerationInProgress_ = false; |
826 this.printHeader_.isPrintButtonEnabled = true; | 819 this.printHeader_.isPrintButtonEnabled = true; |
827 this.nativeLayer_.previewReadyForTest(); | 820 if (this.isListeningForManipulateSettings_) |
| 821 this.nativeLayer_.previewReadyForTest(); |
828 this.printIfReady_(); | 822 this.printIfReady_(); |
829 }, | 823 }, |
830 | 824 |
831 /** | 825 /** |
832 * Called when the preview area's preview failed to load. | 826 * Called when the preview area's preview failed to load. |
833 * @private | 827 * @private |
834 */ | 828 */ |
835 onPreviewGenerationFail_: function() { | 829 onPreviewGenerationFail_: function() { |
836 this.isPreviewGenerationInProgress_ = false; | 830 this.isPreviewGenerationInProgress_ = false; |
837 this.printHeader_.isPrintButtonEnabled = false; | 831 this.printHeader_.isPrintButtonEnabled = false; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
995 }, | 989 }, |
996 | 990 |
997 /** | 991 /** |
998 * Called when the user wants to sign in to Google Cloud Print. Calls the | 992 * Called when the user wants to sign in to Google Cloud Print. Calls the |
999 * corresponding native layer event. | 993 * corresponding native layer event. |
1000 * @param {boolean} addAccount Whether to open an 'add a new account' or | 994 * @param {boolean} addAccount Whether to open an 'add a new account' or |
1001 * default sign in page. | 995 * default sign in page. |
1002 * @private | 996 * @private |
1003 */ | 997 */ |
1004 onCloudPrintSignInActivated_: function(addAccount) { | 998 onCloudPrintSignInActivated_: function(addAccount) { |
1005 this.nativeLayer_.startCloudPrintSignIn(addAccount); | 999 this.nativeLayer_.signIn(addAccount) |
| 1000 .then(this.destinationStore_.onDestinationsReload.bind( |
| 1001 this.destinationStore_)); |
1006 }, | 1002 }, |
1007 | 1003 |
1008 /** | 1004 /** |
1009 * Updates printing options according to source document presets. | 1005 * Updates printing options according to source document presets. |
1010 * @param {Event} event Contains options from source document. | 1006 * @param {boolean} disableScaling Whether the document disables scaling. |
| 1007 * @param {number} copies The default number of copies from the document. |
| 1008 * @param {number} duplex The default duplex setting from the document. |
1011 * @private | 1009 * @private |
1012 */ | 1010 */ |
1013 onPrintPresetOptionsFromDocument_: function(event) { | 1011 onPrintPresetOptionsFromDocument_: function( |
1014 if (event.optionsFromDocument.disableScaling) | 1012 disableScaling, copies, duplex) { |
| 1013 if (disableScaling) |
1015 this.documentInfo_.updateIsScalingDisabled(true); | 1014 this.documentInfo_.updateIsScalingDisabled(true); |
1016 | 1015 |
1017 if (event.optionsFromDocument.copies > 0 && | 1016 if (copies > 0 && this.printTicketStore_.copies.isCapabilityAvailable()) { |
1018 this.printTicketStore_.copies.isCapabilityAvailable()) { | 1017 this.printTicketStore_.copies.updateValue(copies); |
1019 this.printTicketStore_.copies.updateValue( | |
1020 event.optionsFromDocument.copies); | |
1021 } | 1018 } |
1022 | 1019 |
1023 if (event.optionsFromDocument.duplex >= 0 && | 1020 if (duplex >= 0 & this.printTicketStore_.duplex.isCapabilityAvailable()) { |
1024 this.printTicketStore_.duplex.isCapabilityAvailable()) { | 1021 this.printTicketStore_.duplex.updateValue(duplex); |
1025 this.printTicketStore_.duplex.updateValue( | |
1026 event.optionsFromDocument.duplex); | |
1027 } | 1022 } |
1028 }, | 1023 }, |
1029 | 1024 |
1030 /** | 1025 /** |
1031 * Called when the Page Count Ready message is received to update the fit to | 1026 * Called when the Page Count Ready message is received to update the fit to |
1032 * page scaling value in the scaling settings. | 1027 * page scaling value in the scaling settings. |
1033 * @param {Event} event Event object representing the page count ready | 1028 * @param {number} pageCount The document's page count (unused). |
1034 * message | 1029 * @param {number} previewResponseId The request ID that corresponds to this |
| 1030 * page count (unused). |
| 1031 * @param {number} fitToPageScaling The scaling required to fit the document |
| 1032 * to page. |
1035 * @private | 1033 * @private |
1036 */ | 1034 */ |
1037 onPageCountReady_: function(event) { | 1035 onPageCountReady_: function( |
1038 if (event.fitToPageScaling >= 0) { | 1036 pageCount, previewResponseId, fitToPageScaling) { |
1039 this.scalingSettings_.updateFitToPageScaling(event.fitToPageScaling); | 1037 if (fitToPageScaling >= 0) { |
| 1038 this.scalingSettings_.updateFitToPageScaling(fitToPageScaling); |
1040 } | 1039 } |
1041 }, | 1040 }, |
1042 | 1041 |
1043 /** | 1042 /** |
1044 * Called when printing to a privet or extension printer fails. | 1043 * Called when printing to a privet or extension printer fails. |
1045 * @param {*} httpError The HTTP error code, or -1 or a string describing | 1044 * @param {*} httpError The HTTP error code, or -1 or a string describing |
1046 * the error, if not an HTTP error. | 1045 * the error, if not an HTTP error. |
1047 * @private | 1046 * @private |
1048 */ | 1047 */ |
1049 onPrintFailed_: function(httpError) { | 1048 onPrintFailed_: function(httpError) { |
1050 console.error('Privet printing failed with error code ' + httpError); | 1049 console.error('Privet printing failed with error code ' + httpError); |
1051 this.printHeader_.setErrorMessage( | 1050 this.printHeader_.setErrorMessage( |
1052 loadTimeData.getString('couldNotPrint')); | 1051 loadTimeData.getString('couldNotPrint')); |
1053 }, | 1052 }, |
1054 | 1053 |
1055 /** | 1054 /** |
1056 * Called when the print preview settings need to be changed for testing. | 1055 * Called to start listening for the manipulate-settings-for-test WebUI |
1057 * @param {Event} event Event object that contains the option that is to | 1056 * event so that settings can be modified by this event. |
1058 * be changed and what to set that option. | |
1059 * @private | 1057 * @private |
1060 */ | 1058 */ |
1061 onManipulateSettingsForTest_: function(event) { | 1059 onEnableManipulateSettingsForTest_: function() { |
1062 var settings = | 1060 this.listenerTracker.add( |
1063 /** @type {print_preview.PreviewSettings} */ (event.settings); | 1061 'manipulate-settings-for-test', |
| 1062 this.onManipulateSettingsForTest_.bind(this)); |
| 1063 this.isListeningForManipulateSettings_ = true; |
| 1064 }, |
| 1065 |
| 1066 /** |
| 1067 * Called when the print preview settings need to be changed for testing. |
| 1068 * @param {!print_preview.PreviewSettings} settings Contains print preview |
| 1069 * settings to change and the values to change them to. |
| 1070 * @private |
| 1071 */ |
| 1072 onManipulateSettingsForTest_: function(settings) { |
1064 if ('selectSaveAsPdfDestination' in settings) { | 1073 if ('selectSaveAsPdfDestination' in settings) { |
1065 this.saveAsPdfForTest_(); // No parameters. | 1074 this.saveAsPdfForTest_(); // No parameters. |
1066 } else if ('layoutSettings' in settings) { | 1075 } else if ('layoutSettings' in settings) { |
1067 this.setLayoutSettingsForTest_(settings.layoutSettings.portrait); | 1076 this.setLayoutSettingsForTest_(settings.layoutSettings.portrait); |
1068 } else if ('pageRange' in settings) { | 1077 } else if ('pageRange' in settings) { |
1069 this.setPageRangeForTest_(settings.pageRange); | 1078 this.setPageRangeForTest_(settings.pageRange); |
1070 } else if ('headersAndFooters' in settings) { | 1079 } else if ('headersAndFooters' in settings) { |
1071 this.setHeadersAndFootersForTest_(settings.headersAndFooters); | 1080 this.setHeadersAndFootersForTest_(settings.headersAndFooters); |
1072 } else if ('backgroundColorsAndImages' in settings) { | 1081 } else if ('backgroundColorsAndImages' in settings) { |
1073 this.setBackgroundColorsAndImagesForTest_( | 1082 this.setBackgroundColorsAndImagesForTest_( |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 // <include src="search/destination_search.js"> | 1369 // <include src="search/destination_search.js"> |
1361 // <include src="search/provisional_destination_resolver.js"> | 1370 // <include src="search/provisional_destination_resolver.js"> |
1362 | 1371 |
1363 window.addEventListener('DOMContentLoaded', function() { | 1372 window.addEventListener('DOMContentLoaded', function() { |
1364 var previewWindow = /** @type {{isTest: boolean}} */ (window); | 1373 var previewWindow = /** @type {{isTest: boolean}} */ (window); |
1365 if (!previewWindow.isTest) { | 1374 if (!previewWindow.isTest) { |
1366 var printPreview = new print_preview.PrintPreview(); | 1375 var printPreview = new print_preview.PrintPreview(); |
1367 printPreview.initialize(); | 1376 printPreview.initialize(); |
1368 } | 1377 } |
1369 }); | 1378 }); |
OLD | NEW |