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 var localStrings = new LocalStrings(templateData); | |
8 | |
9 <include src="component.js"> | 7 <include src="component.js"> |
10 <include src="print_preview_focus_manager.js"> | 8 <include src="print_preview_focus_manager.js"> |
11 | 9 |
12 cr.define('print_preview', function() { | 10 cr.define('print_preview', function() { |
13 'use strict'; | 11 'use strict'; |
14 | 12 |
15 /** | 13 /** |
16 * Container class for Chromium's print preview. | 14 * Container class for Chromium's print preview. |
17 * @constructor | 15 * @constructor |
18 * @extends {print_preview.Component} | 16 * @extends {print_preview.Component} |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 PRINTED: 'printed', | 293 PRINTED: 'printed', |
296 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' | 294 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' |
297 }; | 295 }; |
298 | 296 |
299 PrintPreview.prototype = { | 297 PrintPreview.prototype = { |
300 __proto__: print_preview.Component.prototype, | 298 __proto__: print_preview.Component.prototype, |
301 | 299 |
302 /** Sets up the page and print preview by getting the printer list. */ | 300 /** Sets up the page and print preview by getting the printer list. */ |
303 initialize: function() { | 301 initialize: function() { |
304 this.decorate($('print-preview')); | 302 this.decorate($('print-preview')); |
305 i18nTemplate.process(document, templateData); | |
306 if (!this.previewArea_.hasCompatiblePlugin) { | 303 if (!this.previewArea_.hasCompatiblePlugin) { |
307 this.setIsEnabled_(false); | 304 this.setIsEnabled_(false); |
308 } | 305 } |
309 this.nativeLayer_.startGetInitialSettings(); | 306 this.nativeLayer_.startGetInitialSettings(); |
310 print_preview.PrintPreviewFocusManager.getInstance().initialize(); | 307 print_preview.PrintPreviewFocusManager.getInstance().initialize(); |
311 cr.ui.FocusOutlineManager.forDocument(document); | 308 cr.ui.FocusOutlineManager.forDocument(document); |
312 }, | 309 }, |
313 | 310 |
314 /** @override */ | 311 /** @override */ |
315 enterDocument: function() { | 312 enterDocument: function() { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 this.onManipulateSettingsForTest_.bind(this)); | 349 this.onManipulateSettingsForTest_.bind(this)); |
353 | 350 |
354 this.tracker.add( | 351 this.tracker.add( |
355 $('system-dialog-link'), | 352 $('system-dialog-link'), |
356 'click', | 353 'click', |
357 this.openSystemPrintDialog_.bind(this)); | 354 this.openSystemPrintDialog_.bind(this)); |
358 this.tracker.add( | 355 this.tracker.add( |
359 $('cloud-print-dialog-link'), | 356 $('cloud-print-dialog-link'), |
360 'click', | 357 'click', |
361 this.onCloudPrintDialogLinkClick_.bind(this)); | 358 this.onCloudPrintDialogLinkClick_.bind(this)); |
362 this.tracker.add( | 359 if ($('open-pdf-in-preview-link')) { |
363 $('open-pdf-in-preview-link'), | 360 this.tracker.add( |
364 'click', | 361 $('open-pdf-in-preview-link'), |
365 this.onOpenPdfInPreviewLinkClick_.bind(this)); | 362 'click', |
| 363 this.onOpenPdfInPreviewLinkClick_.bind(this)); |
| 364 } |
366 | 365 |
367 this.tracker.add( | 366 this.tracker.add( |
368 this.previewArea_, | 367 this.previewArea_, |
369 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, | 368 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, |
370 this.onPreviewGenerationInProgress_.bind(this)); | 369 this.onPreviewGenerationInProgress_.bind(this)); |
371 this.tracker.add( | 370 this.tracker.add( |
372 this.previewArea_, | 371 this.previewArea_, |
373 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE, | 372 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_DONE, |
374 this.onPreviewGenerationDone_.bind(this)); | 373 this.onPreviewGenerationDone_.bind(this)); |
375 this.tracker.add( | 374 this.tracker.add( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 this.copiesSettings_.decorate($('copies-settings')); | 461 this.copiesSettings_.decorate($('copies-settings')); |
463 this.mediaSizeSettings_.decorate($('media-size-settings')); | 462 this.mediaSizeSettings_.decorate($('media-size-settings')); |
464 this.layoutSettings_.decorate($('layout-settings')); | 463 this.layoutSettings_.decorate($('layout-settings')); |
465 this.colorSettings_.decorate($('color-settings')); | 464 this.colorSettings_.decorate($('color-settings')); |
466 this.marginSettings_.decorate($('margin-settings')); | 465 this.marginSettings_.decorate($('margin-settings')); |
467 this.otherOptionsSettings_.decorate($('other-options-settings')); | 466 this.otherOptionsSettings_.decorate($('other-options-settings')); |
468 this.advancedOptionsSettings_.decorate($('advanced-options-settings')); | 467 this.advancedOptionsSettings_.decorate($('advanced-options-settings')); |
469 this.advancedSettings_.decorate($('advanced-settings')); | 468 this.advancedSettings_.decorate($('advanced-settings')); |
470 this.moreSettings_.decorate($('more-settings')); | 469 this.moreSettings_.decorate($('more-settings')); |
471 this.previewArea_.decorate($('preview-area')); | 470 this.previewArea_.decorate($('preview-area')); |
472 | |
473 setIsVisible($('open-pdf-in-preview-link'), cr.isMac); | |
474 }, | 471 }, |
475 | 472 |
476 /** | 473 /** |
477 * Sets whether the controls in the print preview are enabled. | 474 * Sets whether the controls in the print preview are enabled. |
478 * @param {boolean} isEnabled Whether the controls in the print preview are | 475 * @param {boolean} isEnabled Whether the controls in the print preview are |
479 * enabled. | 476 * enabled. |
480 * @private | 477 * @private |
481 */ | 478 */ |
482 setIsEnabled_: function(isEnabled) { | 479 setIsEnabled_: function(isEnabled) { |
483 $('system-dialog-link').disabled = !isEnabled; | 480 $('system-dialog-link').disabled = !isEnabled; |
484 $('cloud-print-dialog-link').disabled = !isEnabled; | 481 $('cloud-print-dialog-link').disabled = !isEnabled; |
485 $('open-pdf-in-preview-link').disabled = !isEnabled; | 482 if ($('open-pdf-in-preview-link')) { |
| 483 $('open-pdf-in-preview-link').disabled = !isEnabled; |
| 484 } |
486 this.printHeader_.isEnabled = isEnabled; | 485 this.printHeader_.isEnabled = isEnabled; |
487 this.destinationSettings_.isEnabled = isEnabled; | 486 this.destinationSettings_.isEnabled = isEnabled; |
488 this.pageSettings_.isEnabled = isEnabled; | 487 this.pageSettings_.isEnabled = isEnabled; |
489 this.copiesSettings_.isEnabled = isEnabled; | 488 this.copiesSettings_.isEnabled = isEnabled; |
490 this.mediaSizeSettings_.isEnabled = isEnabled; | 489 this.mediaSizeSettings_.isEnabled = isEnabled; |
491 this.layoutSettings_.isEnabled = isEnabled; | 490 this.layoutSettings_.isEnabled = isEnabled; |
492 this.colorSettings_.isEnabled = isEnabled; | 491 this.colorSettings_.isEnabled = isEnabled; |
493 this.marginSettings_.isEnabled = isEnabled; | 492 this.marginSettings_.isEnabled = isEnabled; |
494 this.otherOptionsSettings_.isEnabled = isEnabled; | 493 this.otherOptionsSettings_.isEnabled = isEnabled; |
495 this.advancedOptionsSettings_.isEnabled = isEnabled; | 494 this.advancedOptionsSettings_.isEnabled = isEnabled; |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 711 |
713 /** | 712 /** |
714 * Called from the native layer when save-to-pdf file selection is complete. | 713 * Called from the native layer when save-to-pdf file selection is complete. |
715 * @private | 714 * @private |
716 */ | 715 */ |
717 onFileSelectionComplete_: function() { | 716 onFileSelectionComplete_: function() { |
718 assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, | 717 assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, |
719 'File selection completed when not in file-selection state: ' + | 718 'File selection completed when not in file-selection state: ' + |
720 this.uiState_); | 719 this.uiState_); |
721 this.previewArea_.showCustomMessage( | 720 this.previewArea_.showCustomMessage( |
722 localStrings.getString('printingToPDFInProgress')); | 721 loadTimeData.getString('printingToPDFInProgress')); |
723 this.uiState_ = PrintPreview.UiState_.PRINTING; | 722 this.uiState_ = PrintPreview.UiState_.PRINTING; |
724 }, | 723 }, |
725 | 724 |
726 /** | 725 /** |
727 * Called after successfully submitting a job to Google Cloud Print. | 726 * Called after successfully submitting a job to Google Cloud Print. |
728 * @param {!Event} event Contains the ID of the submitted print job. | 727 * @param {!Event} event Contains the ID of the submitted print job. |
729 * @private | 728 * @private |
730 */ | 729 */ |
731 onCloudPrintSubmitDone_: function(event) { | 730 onCloudPrintSubmitDone_: function(event) { |
732 assert(this.uiState_ == PrintPreview.UiState_.PRINTING, | 731 assert(this.uiState_ == PrintPreview.UiState_.PRINTING, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 * Called when the 'Open pdf in preview' link is clicked. Launches the pdf | 802 * Called when the 'Open pdf in preview' link is clicked. Launches the pdf |
804 * preview app. | 803 * preview app. |
805 * @private | 804 * @private |
806 */ | 805 */ |
807 onOpenPdfInPreviewLinkClick_: function() { | 806 onOpenPdfInPreviewLinkClick_: function() { |
808 assert(this.uiState_ == PrintPreview.UiState_.READY, | 807 assert(this.uiState_ == PrintPreview.UiState_.READY, |
809 'Trying to open pdf in preview when not in ready state: ' + | 808 'Trying to open pdf in preview when not in ready state: ' + |
810 this.uiState_); | 809 this.uiState_); |
811 setIsVisible($('open-preview-app-throbber'), true); | 810 setIsVisible($('open-preview-app-throbber'), true); |
812 this.previewArea_.showCustomMessage( | 811 this.previewArea_.showCustomMessage( |
813 localStrings.getString('openingPDFInPreview')); | 812 loadTimeData.getString('openingPDFInPreview')); |
814 this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/); | 813 this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/); |
815 }, | 814 }, |
816 | 815 |
817 /** | 816 /** |
818 * Called when the print header's print button is clicked. Prints the | 817 * Called when the print header's print button is clicked. Prints the |
819 * document. | 818 * document. |
820 * @private | 819 * @private |
821 */ | 820 */ |
822 onPrintButtonClick_: function() { | 821 onPrintButtonClick_: function() { |
823 assert(this.uiState_ == PrintPreview.UiState_.READY, | 822 assert(this.uiState_ == PrintPreview.UiState_.READY, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 }, | 902 }, |
904 | 903 |
905 /** | 904 /** |
906 * Called when native layer receives invalid settings for a print request. | 905 * Called when native layer receives invalid settings for a print request. |
907 * @private | 906 * @private |
908 */ | 907 */ |
909 onSettingsInvalid_: function() { | 908 onSettingsInvalid_: function() { |
910 this.uiState_ = PrintPreview.UiState_.ERROR; | 909 this.uiState_ = PrintPreview.UiState_.ERROR; |
911 console.error('Invalid settings error reported from native layer'); | 910 console.error('Invalid settings error reported from native layer'); |
912 this.previewArea_.showCustomMessage( | 911 this.previewArea_.showCustomMessage( |
913 localStrings.getString('invalidPrinterSettings')); | 912 loadTimeData.getString('invalidPrinterSettings')); |
914 }, | 913 }, |
915 | 914 |
916 /** | 915 /** |
917 * Called when the destination settings' change button is activated. | 916 * Called when the destination settings' change button is activated. |
918 * Displays the destination search component. | 917 * Displays the destination search component. |
919 * @private | 918 * @private |
920 */ | 919 */ |
921 onDestinationChangeButtonActivate_: function() { | 920 onDestinationChangeButtonActivate_: function() { |
922 this.destinationSearch_.setIsVisible(true); | 921 this.destinationSearch_.setIsVisible(true); |
923 }, | 922 }, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 | 972 |
974 /** | 973 /** |
975 * Called when privet printing fails. | 974 * Called when privet printing fails. |
976 * @param {Event} event Event object representing the failure. | 975 * @param {Event} event Event object representing the failure. |
977 * @private | 976 * @private |
978 */ | 977 */ |
979 onPrivetPrintFailed_: function(event) { | 978 onPrivetPrintFailed_: function(event) { |
980 console.error('Privet printing failed with error code ' + | 979 console.error('Privet printing failed with error code ' + |
981 event.httpError); | 980 event.httpError); |
982 this.printHeader_.setErrorMessage( | 981 this.printHeader_.setErrorMessage( |
983 localStrings.getString('couldNotPrint')); | 982 loadTimeData.getString('couldNotPrint')); |
984 }, | 983 }, |
985 | 984 |
986 /** | 985 /** |
987 * Called when the print preview settings need to be changed for testing. | 986 * Called when the print preview settings need to be changed for testing. |
988 * @param {Event} event Event object that contains the option that is to | 987 * @param {Event} event Event object that contains the option that is to |
989 * be changed and what to set that option. | 988 * be changed and what to set that option. |
990 * @private | 989 * @private |
991 */ | 990 */ |
992 onManipulateSettingsForTest_: function(event) { | 991 onManipulateSettingsForTest_: function(event) { |
993 if ('selectSaveAsPdfDestination' in event.settings) { | 992 if ('selectSaveAsPdfDestination' in event.settings) { |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1294 <include src="search/cloud_destination_list.js"> | 1293 <include src="search/cloud_destination_list.js"> |
1295 <include src="search/recent_destination_list.js"> | 1294 <include src="search/recent_destination_list.js"> |
1296 <include src="search/destination_list_item.js"> | 1295 <include src="search/destination_list_item.js"> |
1297 <include src="search/destination_search.js"> | 1296 <include src="search/destination_search.js"> |
1298 <include src="search/fedex_tos.js"> | 1297 <include src="search/fedex_tos.js"> |
1299 | 1298 |
1300 window.addEventListener('DOMContentLoaded', function() { | 1299 window.addEventListener('DOMContentLoaded', function() { |
1301 printPreview = new print_preview.PrintPreview(); | 1300 printPreview = new print_preview.PrintPreview(); |
1302 printPreview.initialize(); | 1301 printPreview.initialize(); |
1303 }); | 1302 }); |
OLD | NEW |