| 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 |
| 11 cr.exportPath('print_preview'); | 11 cr.exportPath('print_preview'); |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Whether this is a WebUI test. |
| 15 * @type {boolean} |
| 16 */ |
| 17 print_preview.IsWebUITest = false; |
| 18 |
| 19 /** |
| 14 * States of the print preview. | 20 * States of the print preview. |
| 15 * @enum {string} | 21 * @enum {string} |
| 16 * @private | 22 * @private |
| 17 */ | 23 */ |
| 18 print_preview.PrintPreviewUiState_ = { | 24 print_preview.PrintPreviewUiState_ = { |
| 19 INITIALIZING: 'initializing', | 25 INITIALIZING: 'initializing', |
| 20 READY: 'ready', | 26 READY: 'ready', |
| 21 OPENING_PDF_PREVIEW: 'opening-pdf-preview', | 27 OPENING_PDF_PREVIEW: 'opening-pdf-preview', |
| 22 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', | 28 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', |
| 23 PRINTING: 'printing', | 29 PRINTING: 'printing', |
| 24 FILE_SELECTION: 'file-selection', | 30 FILE_SELECTION: 'file-selection', |
| 25 CLOSING: 'closing', | 31 CLOSING: 'closing', |
| 26 ERROR: 'error' | 32 ERROR: 'error' |
| 27 }; | 33 }; |
| 28 | 34 |
| 35 /** |
| 36 * What can happen when print preview tries to print. |
| 37 * @enum {string} |
| 38 * @private |
| 39 */ |
| 40 print_preview.PrintAttemptResult_ = { |
| 41 NOT_READY: 'not-ready', |
| 42 PRINTED: 'printed', |
| 43 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' |
| 44 }; |
| 29 | 45 |
| 30 cr.define('print_preview', function() { | 46 cr.define('print_preview', function() { |
| 31 'use strict'; | 47 'use strict'; |
| 32 | 48 |
| 33 var PrintPreviewUiState_ = print_preview.PrintPreviewUiState_; | 49 var PrintPreviewUiState_ = print_preview.PrintPreviewUiState_; |
| 34 | 50 |
| 35 /** | 51 /** |
| 36 * Container class for Chromium's print preview. | 52 * Container class for Chromium's print preview. |
| 37 * @constructor | 53 * @constructor |
| 38 * @extends {print_preview.Component} | 54 * @extends {print_preview.Component} |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 this.isPreviewGenerationInProgress_ = true; | 321 this.isPreviewGenerationInProgress_ = true; |
| 306 | 322 |
| 307 /** | 323 /** |
| 308 * Whether to show system dialog before next printing. | 324 * Whether to show system dialog before next printing. |
| 309 * @type {boolean} | 325 * @type {boolean} |
| 310 * @private | 326 * @private |
| 311 */ | 327 */ |
| 312 this.showSystemDialogBeforeNextPrint_ = false; | 328 this.showSystemDialogBeforeNextPrint_ = false; |
| 313 } | 329 } |
| 314 | 330 |
| 315 /** | |
| 316 * What can happen when print preview tries to print. | |
| 317 * @enum {string} | |
| 318 * @private | |
| 319 */ | |
| 320 PrintPreview.PrintAttemptResult_ = { | |
| 321 NOT_READY: 'not-ready', | |
| 322 PRINTED: 'printed', | |
| 323 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' | |
| 324 }; | |
| 325 | |
| 326 PrintPreview.prototype = { | 331 PrintPreview.prototype = { |
| 327 __proto__: print_preview.Component.prototype, | 332 __proto__: print_preview.Component.prototype, |
| 328 | 333 |
| 329 /** Sets up the page and print preview by getting the printer list. */ | 334 /** Sets up the page and print preview by getting the printer list. */ |
| 330 initialize: function() { | 335 initialize: function() { |
| 331 this.decorate($('print-preview')); | 336 this.decorate($('print-preview')); |
| 332 if (!this.previewArea_.hasCompatiblePlugin) { | 337 if (!this.previewArea_.hasCompatiblePlugin) { |
| 333 this.setIsEnabled_(false); | 338 this.setIsEnabled_(false); |
| 334 } | 339 } |
| 335 this.nativeLayer_.startGetInitialSettings(); | 340 this.nativeLayer_.startGetInitialSettings(); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 this.uiState_ = PrintPreviewUiState_.OPENING_PDF_PREVIEW; | 547 this.uiState_ = PrintPreviewUiState_.OPENING_PDF_PREVIEW; |
| 543 } else if (this.destinationStore_.selectedDestination.id == | 548 } else if (this.destinationStore_.selectedDestination.id == |
| 544 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 549 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 545 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; | 550 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; |
| 546 } else { | 551 } else { |
| 547 this.uiState_ = PrintPreviewUiState_.PRINTING; | 552 this.uiState_ = PrintPreviewUiState_.PRINTING; |
| 548 } | 553 } |
| 549 this.setIsEnabled_(false); | 554 this.setIsEnabled_(false); |
| 550 this.printHeader_.isCancelButtonEnabled = true; | 555 this.printHeader_.isCancelButtonEnabled = true; |
| 551 var printAttemptResult = this.printIfReady_(); | 556 var printAttemptResult = this.printIfReady_(); |
| 552 if (printAttemptResult == PrintPreview.PrintAttemptResult_.PRINTED || | 557 if (printAttemptResult == print_preview.PrintAttemptResult_.PRINTED || |
| 553 printAttemptResult == | 558 printAttemptResult == |
| 554 PrintPreview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { | 559 print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { |
| 555 if ((this.destinationStore_.selectedDestination.isLocal && | 560 if ((this.destinationStore_.selectedDestination.isLocal && |
| 556 !this.destinationStore_.selectedDestination.isPrivet && | 561 !this.destinationStore_.selectedDestination.isPrivet && |
| 557 !this.destinationStore_.selectedDestination.isExtension && | 562 !this.destinationStore_.selectedDestination.isExtension && |
| 558 this.destinationStore_.selectedDestination.id != | 563 this.destinationStore_.selectedDestination.id != |
| 559 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || | 564 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || |
| 560 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { | 565 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { |
| 561 // Hide the dialog for now. The actual print command will be issued | 566 // Hide the dialog for now. The actual print command will be issued |
| 562 // when the preview generation is done. | 567 // when the preview generation is done. |
| 563 this.nativeLayer_.startHideDialog(); | 568 this.nativeLayer_.startHideDialog(); |
| 564 } | 569 } |
| 565 } | 570 } |
| 566 }, | 571 }, |
| 567 | 572 |
| 568 /** | 573 /** |
| 569 * Attempts to print if needed and if ready. | 574 * Attempts to print if needed and if ready. |
| 570 * @return {PrintPreview.PrintAttemptResult_} Attempt result. | 575 * @return {print_preview.PrintAttemptResult_} Attempt result. |
| 571 * @private | 576 * @private |
| 572 */ | 577 */ |
| 573 printIfReady_: function() { | 578 printIfReady_: function() { |
| 574 var okToPrint = | 579 var okToPrint = |
| 575 (this.uiState_ == PrintPreviewUiState_.PRINTING || | 580 (this.uiState_ == PrintPreviewUiState_.PRINTING || |
| 576 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW || | 581 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW || |
| 577 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION || | 582 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION || |
| 578 this.isInKioskAutoPrintMode_) && | 583 this.isInKioskAutoPrintMode_) && |
| 579 this.destinationStore_.selectedDestination && | 584 this.destinationStore_.selectedDestination && |
| 580 this.destinationStore_.selectedDestination.capabilities; | 585 this.destinationStore_.selectedDestination.capabilities; |
| 581 if (!okToPrint) { | 586 if (!okToPrint) { |
| 582 return PrintPreview.PrintAttemptResult_.NOT_READY; | 587 return print_preview.PrintAttemptResult_.NOT_READY; |
| 583 } | 588 } |
| 584 if (this.isPreviewGenerationInProgress_) { | 589 if (this.isPreviewGenerationInProgress_) { |
| 585 return PrintPreview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW; | 590 return print_preview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW; |
| 586 } | 591 } |
| 587 assert(this.printTicketStore_.isTicketValid(), | 592 assert(this.printTicketStore_.isTicketValid(), |
| 588 'Trying to print with invalid ticket'); | 593 'Trying to print with invalid ticket'); |
| 589 if (getIsVisible(this.moreSettings_.getElement())) { | 594 if (getIsVisible(this.moreSettings_.getElement())) { |
| 590 new print_preview.PrintSettingsUiMetricsContext().record( | 595 new print_preview.PrintSettingsUiMetricsContext().record( |
| 591 this.moreSettings_.isExpanded ? | 596 this.moreSettings_.isExpanded ? |
| 592 print_preview.Metrics.PrintSettingsUiBucket. | 597 print_preview.Metrics.PrintSettingsUiBucket. |
| 593 PRINT_WITH_SETTINGS_EXPANDED : | 598 PRINT_WITH_SETTINGS_EXPANDED : |
| 594 print_preview.Metrics.PrintSettingsUiBucket. | 599 print_preview.Metrics.PrintSettingsUiBucket. |
| 595 PRINT_WITH_SETTINGS_COLLAPSED); | 600 PRINT_WITH_SETTINGS_COLLAPSED); |
| 596 } | 601 } |
| 597 this.nativeLayer_.startPrint( | 602 this.nativeLayer_.startPrint( |
| 598 assert(this.destinationStore_.selectedDestination), | 603 assert(this.destinationStore_.selectedDestination), |
| 599 this.printTicketStore_, | 604 this.printTicketStore_, |
| 600 this.cloudPrintInterface_, | 605 this.cloudPrintInterface_, |
| 601 this.documentInfo_, | 606 this.documentInfo_, |
| 602 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, | 607 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
| 603 this.showSystemDialogBeforeNextPrint_); | 608 this.showSystemDialogBeforeNextPrint_); |
| 604 this.showSystemDialogBeforeNextPrint_ = false; | 609 this.showSystemDialogBeforeNextPrint_ = false; |
| 605 return PrintPreview.PrintAttemptResult_.PRINTED; | 610 return print_preview.PrintAttemptResult_.PRINTED; |
| 606 }, | 611 }, |
| 607 | 612 |
| 608 /** | 613 /** |
| 609 * Closes the print preview. | 614 * Closes the print preview. |
| 610 * @private | 615 * @private |
| 611 */ | 616 */ |
| 612 close_: function() { | 617 close_: function() { |
| 613 this.exitDocument(); | 618 this.exitDocument(); |
| 614 this.uiState_ = PrintPreviewUiState_.CLOSING; | 619 this.uiState_ = PrintPreviewUiState_.CLOSING; |
| 615 this.nativeLayer_.startCloseDialog(); | 620 this.nativeLayer_.startCloseDialog(); |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 // <include src="../pdf/pdf_scripting_api.js"> | 1349 // <include src="../pdf/pdf_scripting_api.js"> |
| 1345 // <include src="previewarea/preview_area.js"> | 1350 // <include src="previewarea/preview_area.js"> |
| 1346 // <include src="preview_generator.js"> | 1351 // <include src="preview_generator.js"> |
| 1347 | 1352 |
| 1348 // <include src="search/destination_list.js"> | 1353 // <include src="search/destination_list.js"> |
| 1349 // <include src="search/cloud_destination_list.js"> | 1354 // <include src="search/cloud_destination_list.js"> |
| 1350 // <include src="search/recent_destination_list.js"> | 1355 // <include src="search/recent_destination_list.js"> |
| 1351 // <include src="search/destination_list_item.js"> | 1356 // <include src="search/destination_list_item.js"> |
| 1352 // <include src="search/destination_search.js"> | 1357 // <include src="search/destination_search.js"> |
| 1353 // <include src="search/provisional_destination_resolver.js"> | 1358 // <include src="search/provisional_destination_resolver.js"> |
| 1354 | |
| 1355 window.addEventListener('DOMContentLoaded', function() { | 1359 window.addEventListener('DOMContentLoaded', function() { |
| 1356 printPreview = new print_preview.PrintPreview(); | 1360 if (!print_preview.IsWebUITest) { |
| 1357 printPreview.initialize(); | 1361 var printPreview = new print_preview.PrintPreview(); |
| 1362 printPreview.initialize(); |
| 1363 } |
| 1358 }); | 1364 }); |
| OLD | NEW |