| 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 // |
| 10 |
| 11 cr.exportPath('print_preview'); |
| 12 |
| 13 /** |
| 14 * States of the print preview. |
| 15 * @enum {string} |
| 16 * @private |
| 17 */ |
| 18 print_preview.PrintPreviewUiState_ = { |
| 19 INITIALIZING: 'initializing', |
| 20 READY: 'ready', |
| 21 OPENING_PDF_PREVIEW: 'opening-pdf-preview', |
| 22 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', |
| 23 PRINTING: 'printing', |
| 24 FILE_SELECTION: 'file-selection', |
| 25 CLOSING: 'closing', |
| 26 ERROR: 'error' |
| 27 }; |
| 28 |
| 9 | 29 |
| 10 cr.define('print_preview', function() { | 30 cr.define('print_preview', function() { |
| 11 'use strict'; | 31 'use strict'; |
| 12 | 32 |
| 33 var PrintPreviewUiState_ = print_preview.PrintPreviewUiState_; |
| 34 |
| 13 /** | 35 /** |
| 14 * Container class for Chromium's print preview. | 36 * Container class for Chromium's print preview. |
| 15 * @constructor | 37 * @constructor |
| 16 * @extends {print_preview.Component} | 38 * @extends {print_preview.Component} |
| 17 */ | 39 */ |
| 18 function PrintPreview() { | 40 function PrintPreview() { |
| 19 print_preview.Component.call(this); | 41 print_preview.Component.call(this); |
| 20 | 42 |
| 21 /** | 43 /** |
| 22 * Used to communicate with Chromium's print system. | 44 * Used to communicate with Chromium's print system. |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 /** | 285 /** |
| 264 * Whether Print with System Dialog link should be hidden. Overrides the | 286 * Whether Print with System Dialog link should be hidden. Overrides the |
| 265 * default rules for System dialog link visibility. | 287 * default rules for System dialog link visibility. |
| 266 * @type {boolean} | 288 * @type {boolean} |
| 267 * @private | 289 * @private |
| 268 */ | 290 */ |
| 269 this.hideSystemDialogLink_ = true; | 291 this.hideSystemDialogLink_ = true; |
| 270 | 292 |
| 271 /** | 293 /** |
| 272 * State of the print preview UI. | 294 * State of the print preview UI. |
| 273 * @type {print_preview.PrintPreview.UiState_} | 295 * @type {print_preview.PrintPreviewUiState_} |
| 274 * @private | 296 * @private |
| 275 */ | 297 */ |
| 276 this.uiState_ = PrintPreview.UiState_.INITIALIZING; | 298 this.uiState_ = PrintPreviewUiState_.INITIALIZING; |
| 277 | 299 |
| 278 /** | 300 /** |
| 279 * Whether document preview generation is in progress. | 301 * Whether document preview generation is in progress. |
| 280 * @type {boolean} | 302 * @type {boolean} |
| 281 * @private | 303 * @private |
| 282 */ | 304 */ |
| 283 this.isPreviewGenerationInProgress_ = true; | 305 this.isPreviewGenerationInProgress_ = true; |
| 284 | 306 |
| 285 /** | 307 /** |
| 286 * Whether to show system dialog before next printing. | 308 * Whether to show system dialog before next printing. |
| 287 * @type {boolean} | 309 * @type {boolean} |
| 288 * @private | 310 * @private |
| 289 */ | 311 */ |
| 290 this.showSystemDialogBeforeNextPrint_ = false; | 312 this.showSystemDialogBeforeNextPrint_ = false; |
| 291 }; | 313 } |
| 292 | |
| 293 /** | |
| 294 * States of the print preview. | |
| 295 * @enum {string} | |
| 296 * @private | |
| 297 */ | |
| 298 PrintPreview.UiState_ = { | |
| 299 INITIALIZING: 'initializing', | |
| 300 READY: 'ready', | |
| 301 OPENING_PDF_PREVIEW: 'opening-pdf-preview', | |
| 302 OPENING_NATIVE_PRINT_DIALOG: 'opening-native-print-dialog', | |
| 303 PRINTING: 'printing', | |
| 304 FILE_SELECTION: 'file-selection', | |
| 305 CLOSING: 'closing', | |
| 306 ERROR: 'error' | |
| 307 }; | |
| 308 | 314 |
| 309 /** | 315 /** |
| 310 * What can happen when print preview tries to print. | 316 * What can happen when print preview tries to print. |
| 311 * @enum {string} | 317 * @enum {string} |
| 312 * @private | 318 * @private |
| 313 */ | 319 */ |
| 314 PrintPreview.PrintAttemptResult_ = { | 320 PrintPreview.PrintAttemptResult_ = { |
| 315 NOT_READY: 'not-ready', | 321 NOT_READY: 'not-ready', |
| 316 PRINTED: 'printed', | 322 PRINTED: 'printed', |
| 317 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' | 323 READY_WAITING_FOR_PREVIEW: 'ready-waiting-for-preview' |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 this.nativeLayer_, | 376 this.nativeLayer_, |
| 371 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, | 377 print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED, |
| 372 this.onPrivetPrintFailed_.bind(this)); | 378 this.onPrivetPrintFailed_.bind(this)); |
| 373 this.tracker.add( | 379 this.tracker.add( |
| 374 this.nativeLayer_, | 380 this.nativeLayer_, |
| 375 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, | 381 print_preview.NativeLayer.EventType.MANIPULATE_SETTINGS_FOR_TEST, |
| 376 this.onManipulateSettingsForTest_.bind(this)); | 382 this.onManipulateSettingsForTest_.bind(this)); |
| 377 | 383 |
| 378 if ($('system-dialog-link')) { | 384 if ($('system-dialog-link')) { |
| 379 this.tracker.add( | 385 this.tracker.add( |
| 380 $('system-dialog-link'), | 386 getRequiredElement('system-dialog-link'), |
| 381 'click', | 387 'click', |
| 382 this.openSystemPrintDialog_.bind(this)); | 388 this.openSystemPrintDialog_.bind(this)); |
| 383 } | 389 } |
| 384 if ($('open-pdf-in-preview-link')) { | 390 if ($('open-pdf-in-preview-link')) { |
| 385 this.tracker.add( | 391 this.tracker.add( |
| 386 $('open-pdf-in-preview-link'), | 392 getRequiredElement('open-pdf-in-preview-link'), |
| 387 'click', | 393 'click', |
| 388 this.onOpenPdfInPreviewLinkClick_.bind(this)); | 394 this.onOpenPdfInPreviewLinkClick_.bind(this)); |
| 389 } | 395 } |
| 390 | 396 |
| 391 this.tracker.add( | 397 this.tracker.add( |
| 392 this.previewArea_, | 398 this.previewArea_, |
| 393 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, | 399 print_preview.PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS, |
| 394 this.onPreviewGenerationInProgress_.bind(this)); | 400 this.onPreviewGenerationInProgress_.bind(this)); |
| 395 this.tracker.add( | 401 this.tracker.add( |
| 396 this.previewArea_, | 402 this.previewArea_, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 this.otherOptionsSettings_.isEnabled = isEnabled; | 528 this.otherOptionsSettings_.isEnabled = isEnabled; |
| 523 this.advancedOptionsSettings_.isEnabled = isEnabled; | 529 this.advancedOptionsSettings_.isEnabled = isEnabled; |
| 524 }, | 530 }, |
| 525 | 531 |
| 526 /** | 532 /** |
| 527 * Prints the document or launches a pdf preview on the local system. | 533 * Prints the document or launches a pdf preview on the local system. |
| 528 * @param {boolean} isPdfPreview Whether to launch the pdf preview. | 534 * @param {boolean} isPdfPreview Whether to launch the pdf preview. |
| 529 * @private | 535 * @private |
| 530 */ | 536 */ |
| 531 printDocumentOrOpenPdfPreview_: function(isPdfPreview) { | 537 printDocumentOrOpenPdfPreview_: function(isPdfPreview) { |
| 532 assert(this.uiState_ == PrintPreview.UiState_.READY, | 538 assert(this.uiState_ == PrintPreviewUiState_.READY, |
| 533 'Print document request received when not in ready state: ' + | 539 'Print document request received when not in ready state: ' + |
| 534 this.uiState_); | 540 this.uiState_); |
| 535 if (isPdfPreview) { | 541 if (isPdfPreview) { |
| 536 this.uiState_ = PrintPreview.UiState_.OPENING_PDF_PREVIEW; | 542 this.uiState_ = PrintPreviewUiState_.OPENING_PDF_PREVIEW; |
| 537 } else if (this.destinationStore_.selectedDestination.id == | 543 } else if (this.destinationStore_.selectedDestination.id == |
| 538 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { | 544 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) { |
| 539 this.uiState_ = PrintPreview.UiState_.FILE_SELECTION; | 545 this.uiState_ = PrintPreviewUiState_.FILE_SELECTION; |
| 540 } else { | 546 } else { |
| 541 this.uiState_ = PrintPreview.UiState_.PRINTING; | 547 this.uiState_ = PrintPreviewUiState_.PRINTING; |
| 542 } | 548 } |
| 543 this.setIsEnabled_(false); | 549 this.setIsEnabled_(false); |
| 544 this.printHeader_.isCancelButtonEnabled = true; | 550 this.printHeader_.isCancelButtonEnabled = true; |
| 545 var printAttemptResult = this.printIfReady_(); | 551 var printAttemptResult = this.printIfReady_(); |
| 546 if (printAttemptResult == PrintPreview.PrintAttemptResult_.PRINTED || | 552 if (printAttemptResult == PrintPreview.PrintAttemptResult_.PRINTED || |
| 547 printAttemptResult == | 553 printAttemptResult == |
| 548 PrintPreview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { | 554 PrintPreview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW) { |
| 549 if ((this.destinationStore_.selectedDestination.isLocal && | 555 if ((this.destinationStore_.selectedDestination.isLocal && |
| 550 !this.destinationStore_.selectedDestination.isPrivet && | 556 !this.destinationStore_.selectedDestination.isPrivet && |
| 551 !this.destinationStore_.selectedDestination.isExtension && | 557 !this.destinationStore_.selectedDestination.isExtension && |
| 552 this.destinationStore_.selectedDestination.id != | 558 this.destinationStore_.selectedDestination.id != |
| 553 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || | 559 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF) || |
| 554 this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW) { | 560 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW) { |
| 555 // Hide the dialog for now. The actual print command will be issued | 561 // Hide the dialog for now. The actual print command will be issued |
| 556 // when the preview generation is done. | 562 // when the preview generation is done. |
| 557 this.nativeLayer_.startHideDialog(); | 563 this.nativeLayer_.startHideDialog(); |
| 558 } | 564 } |
| 559 } | 565 } |
| 560 }, | 566 }, |
| 561 | 567 |
| 562 /** | 568 /** |
| 563 * Attempts to print if needed and if ready. | 569 * Attempts to print if needed and if ready. |
| 564 * @return {PrintPreview.PrintAttemptResult_} Attempt result. | 570 * @return {PrintPreview.PrintAttemptResult_} Attempt result. |
| 565 * @private | 571 * @private |
| 566 */ | 572 */ |
| 567 printIfReady_: function() { | 573 printIfReady_: function() { |
| 568 var okToPrint = | 574 var okToPrint = |
| 569 (this.uiState_ == PrintPreview.UiState_.PRINTING || | 575 (this.uiState_ == PrintPreviewUiState_.PRINTING || |
| 570 this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW || | 576 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW || |
| 571 this.uiState_ == PrintPreview.UiState_.FILE_SELECTION || | 577 this.uiState_ == PrintPreviewUiState_.FILE_SELECTION || |
| 572 this.isInKioskAutoPrintMode_) && | 578 this.isInKioskAutoPrintMode_) && |
| 573 this.destinationStore_.selectedDestination && | 579 this.destinationStore_.selectedDestination && |
| 574 this.destinationStore_.selectedDestination.capabilities; | 580 this.destinationStore_.selectedDestination.capabilities; |
| 575 if (!okToPrint) { | 581 if (!okToPrint) { |
| 576 return PrintPreview.PrintAttemptResult_.NOT_READY; | 582 return PrintPreview.PrintAttemptResult_.NOT_READY; |
| 577 } | 583 } |
| 578 if (this.isPreviewGenerationInProgress_) { | 584 if (this.isPreviewGenerationInProgress_) { |
| 579 return PrintPreview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW; | 585 return PrintPreview.PrintAttemptResult_.READY_WAITING_FOR_PREVIEW; |
| 580 } | 586 } |
| 581 assert(this.printTicketStore_.isTicketValid(), | 587 assert(this.printTicketStore_.isTicketValid(), |
| 582 'Trying to print with invalid ticket'); | 588 'Trying to print with invalid ticket'); |
| 583 if (getIsVisible(this.moreSettings_.getElement())) { | 589 if (getIsVisible(this.moreSettings_.getElement())) { |
| 584 new print_preview.PrintSettingsUiMetricsContext().record( | 590 new print_preview.PrintSettingsUiMetricsContext().record( |
| 585 this.moreSettings_.isExpanded ? | 591 this.moreSettings_.isExpanded ? |
| 586 print_preview.Metrics.PrintSettingsUiBucket. | 592 print_preview.Metrics.PrintSettingsUiBucket. |
| 587 PRINT_WITH_SETTINGS_EXPANDED : | 593 PRINT_WITH_SETTINGS_EXPANDED : |
| 588 print_preview.Metrics.PrintSettingsUiBucket. | 594 print_preview.Metrics.PrintSettingsUiBucket. |
| 589 PRINT_WITH_SETTINGS_COLLAPSED); | 595 PRINT_WITH_SETTINGS_COLLAPSED); |
| 590 } | 596 } |
| 591 this.nativeLayer_.startPrint( | 597 this.nativeLayer_.startPrint( |
| 592 this.destinationStore_.selectedDestination, | 598 assert(this.destinationStore_.selectedDestination), |
| 593 this.printTicketStore_, | 599 this.printTicketStore_, |
| 594 this.cloudPrintInterface_, | 600 this.cloudPrintInterface_, |
| 595 this.documentInfo_, | 601 this.documentInfo_, |
| 596 this.uiState_ == PrintPreview.UiState_.OPENING_PDF_PREVIEW, | 602 this.uiState_ == PrintPreviewUiState_.OPENING_PDF_PREVIEW, |
| 597 this.showSystemDialogBeforeNextPrint_); | 603 this.showSystemDialogBeforeNextPrint_); |
| 598 this.showSystemDialogBeforeNextPrint_ = false; | 604 this.showSystemDialogBeforeNextPrint_ = false; |
| 599 return PrintPreview.PrintAttemptResult_.PRINTED; | 605 return PrintPreview.PrintAttemptResult_.PRINTED; |
| 600 }, | 606 }, |
| 601 | 607 |
| 602 /** | 608 /** |
| 603 * Closes the print preview. | 609 * Closes the print preview. |
| 604 * @private | 610 * @private |
| 605 */ | 611 */ |
| 606 close_: function() { | 612 close_: function() { |
| 607 this.exitDocument(); | 613 this.exitDocument(); |
| 608 this.uiState_ = PrintPreview.UiState_.CLOSING; | 614 this.uiState_ = PrintPreviewUiState_.CLOSING; |
| 609 this.nativeLayer_.startCloseDialog(); | 615 this.nativeLayer_.startCloseDialog(); |
| 610 }, | 616 }, |
| 611 | 617 |
| 612 /** | 618 /** |
| 613 * Opens the native system print dialog after disabling all controls. | 619 * Opens the native system print dialog after disabling all controls. |
| 614 * @private | 620 * @private |
| 615 */ | 621 */ |
| 616 openSystemPrintDialog_: function() { | 622 openSystemPrintDialog_: function() { |
| 617 if (!this.shouldShowSystemDialogLink_()) | 623 if (!this.shouldShowSystemDialogLink_()) |
| 618 return; | 624 return; |
| 619 if ($('system-dialog-link').classList.contains('disabled')) | 625 if ($('system-dialog-link').classList.contains('disabled')) |
| 620 return; | 626 return; |
| 621 if (cr.isWindows) { | 627 if (cr.isWindows) { |
| 622 this.showSystemDialogBeforeNextPrint_ = true; | 628 this.showSystemDialogBeforeNextPrint_ = true; |
| 623 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); | 629 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); |
| 624 return; | 630 return; |
| 625 } | 631 } |
| 626 setIsVisible(getRequiredElement('system-dialog-throbber'), true); | 632 setIsVisible(getRequiredElement('system-dialog-throbber'), true); |
| 627 this.setIsEnabled_(false); | 633 this.setIsEnabled_(false); |
| 628 this.uiState_ = PrintPreview.UiState_.OPENING_NATIVE_PRINT_DIALOG; | 634 this.uiState_ = PrintPreviewUiState_.OPENING_NATIVE_PRINT_DIALOG; |
| 629 this.nativeLayer_.startShowSystemDialog(); | 635 this.nativeLayer_.startShowSystemDialog(); |
| 630 }, | 636 }, |
| 631 | 637 |
| 632 /** | 638 /** |
| 633 * Called when the native layer has initial settings to set. Sets the | 639 * Called when the native layer has initial settings to set. Sets the |
| 634 * initial settings of the print preview and begins fetching print | 640 * initial settings of the print preview and begins fetching print |
| 635 * destinations. | 641 * destinations. |
| 636 * @param {Event} event Contains the initial print preview settings | 642 * @param {Event} event Contains the initial print preview settings |
| 637 * persisted through the session. | 643 * persisted through the session. |
| 638 * @private | 644 * @private |
| 639 */ | 645 */ |
| 640 onInitialSettingsSet_: function(event) { | 646 onInitialSettingsSet_: function(event) { |
| 641 assert(this.uiState_ == PrintPreview.UiState_.INITIALIZING, | 647 assert(this.uiState_ == PrintPreviewUiState_.INITIALIZING, |
| 642 'Updating initial settings when not in initializing state: ' + | 648 'Updating initial settings when not in initializing state: ' + |
| 643 this.uiState_); | 649 this.uiState_); |
| 644 this.uiState_ = PrintPreview.UiState_.READY; | 650 this.uiState_ = PrintPreviewUiState_.READY; |
| 645 | 651 |
| 646 var settings = event.initialSettings; | 652 var settings = event.initialSettings; |
| 647 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; | 653 this.isInKioskAutoPrintMode_ = settings.isInKioskAutoPrintMode; |
| 648 this.isInAppKioskMode_ = settings.isInAppKioskMode; | 654 this.isInAppKioskMode_ = settings.isInAppKioskMode; |
| 649 | 655 |
| 650 // The following components must be initialized in this order. | 656 // The following components must be initialized in this order. |
| 651 this.appState_.init(settings.serializedAppStateStr); | 657 this.appState_.init(settings.serializedAppStateStr); |
| 652 this.documentInfo_.init( | 658 this.documentInfo_.init( |
| 653 settings.isDocumentModifiable, | 659 settings.isDocumentModifiable, |
| 654 settings.documentTitle, | 660 settings.documentTitle, |
| 655 settings.documentHasSelection); | 661 settings.documentHasSelection); |
| 656 this.printTicketStore_.init( | 662 this.printTicketStore_.init( |
| 657 settings.thousandsDelimeter, | 663 settings.thousandsDelimeter, |
| 658 settings.decimalDelimeter, | 664 settings.decimalDelimeter, |
| 659 settings.unitType, | 665 settings.unitType, |
| 660 settings.selectionOnly); | 666 settings.selectionOnly); |
| 661 this.destinationStore_.init( | 667 this.destinationStore_.init( |
| 662 settings.isInAppKioskMode, | 668 settings.isInAppKioskMode, |
| 663 settings.systemDefaultDestinationId, | 669 settings.systemDefaultDestinationId, |
| 664 settings.serializedDefaultDestinationSelectionRulesStr); | 670 settings.serializedDefaultDestinationSelectionRulesStr); |
| 665 this.appState_.setInitialized(); | 671 this.appState_.setInitialized(); |
| 666 | 672 |
| 667 $('document-title').innerText = settings.documentTitle; | 673 $('document-title').innerText = settings.documentTitle; |
| 668 this.hideSystemDialogLink_ = settings.isInAppKioskMode; | 674 this.hideSystemDialogLink_ = settings.isInAppKioskMode; |
| 669 if ($('system-dialog-link')) { | 675 if ($('system-dialog-link')) { |
| 670 setIsVisible($('system-dialog-link'), | 676 setIsVisible(getRequiredElement('system-dialog-link'), |
| 671 this.shouldShowSystemDialogLink_()); | 677 this.shouldShowSystemDialogLink_()); |
| 672 } | 678 } |
| 673 }, | 679 }, |
| 674 | 680 |
| 675 /** | 681 /** |
| 676 * Calls when the native layer enables Google Cloud Print integration. | 682 * Calls when the native layer enables Google Cloud Print integration. |
| 677 * Fetches the user's cloud printers. | 683 * Fetches the user's cloud printers. |
| 678 * @param {Event} event Contains the base URL of the Google Cloud Print | 684 * @param {Event} event Contains the base URL of the Google Cloud Print |
| 679 * service. | 685 * service. |
| 680 * @private | 686 * @private |
| 681 */ | 687 */ |
| 682 onCloudPrintEnable_: function(event) { | 688 onCloudPrintEnable_: function(event) { |
| 683 this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface( | 689 this.cloudPrintInterface_ = new cloudprint.CloudPrintInterface( |
| 684 event.baseCloudPrintUrl, | 690 event.baseCloudPrintUrl, |
| 685 this.nativeLayer_, | 691 this.nativeLayer_, |
| 686 this.userInfo_, | 692 this.userInfo_, |
| 687 event.appKioskMode); | 693 event.appKioskMode); |
| 688 this.tracker.add( | 694 this.tracker.add( |
| 689 this.cloudPrintInterface_, | 695 this.cloudPrintInterface_, |
| 690 cloudprint.CloudPrintInterface.EventType.SUBMIT_DONE, | 696 cloudprint.CloudPrintInterfaceEventType.SUBMIT_DONE, |
| 691 this.onCloudPrintSubmitDone_.bind(this)); | 697 this.onCloudPrintSubmitDone_.bind(this)); |
| 692 this.tracker.add( | 698 this.tracker.add( |
| 693 this.cloudPrintInterface_, | 699 this.cloudPrintInterface_, |
| 694 cloudprint.CloudPrintInterface.EventType.SEARCH_FAILED, | 700 cloudprint.CloudPrintInterfaceEventType.SEARCH_FAILED, |
| 695 this.onCloudPrintError_.bind(this)); | 701 this.onCloudPrintError_.bind(this)); |
| 696 this.tracker.add( | 702 this.tracker.add( |
| 697 this.cloudPrintInterface_, | 703 this.cloudPrintInterface_, |
| 698 cloudprint.CloudPrintInterface.EventType.SUBMIT_FAILED, | 704 cloudprint.CloudPrintInterfaceEventType.SUBMIT_FAILED, |
| 699 this.onCloudPrintError_.bind(this)); | 705 this.onCloudPrintError_.bind(this)); |
| 700 this.tracker.add( | 706 this.tracker.add( |
| 701 this.cloudPrintInterface_, | 707 this.cloudPrintInterface_, |
| 702 cloudprint.CloudPrintInterface.EventType.PRINTER_FAILED, | 708 cloudprint.CloudPrintInterfaceEventType.PRINTER_FAILED, |
| 703 this.onCloudPrintError_.bind(this)); | 709 this.onCloudPrintError_.bind(this)); |
| 704 | 710 |
| 705 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); | 711 this.destinationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
| 706 this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); | 712 this.invitationStore_.setCloudPrintInterface(this.cloudPrintInterface_); |
| 707 if (this.destinationSearch_.getIsVisible()) { | 713 if (this.destinationSearch_.getIsVisible()) { |
| 708 this.destinationStore_.startLoadCloudDestinations(); | 714 this.destinationStore_.startLoadCloudDestinations(); |
| 709 this.invitationStore_.startLoadingInvitations(); | 715 this.invitationStore_.startLoadingInvitations(); |
| 710 } | 716 } |
| 711 }, | 717 }, |
| 712 | 718 |
| 713 /** | 719 /** |
| 714 * Called from the native layer when ready to print to Google Cloud Print. | 720 * Called from the native layer when ready to print to Google Cloud Print. |
| 715 * @param {Event} event Contains the body to send in the HTTP request. | 721 * @param {Event} event Contains the body to send in the HTTP request. |
| 716 * @private | 722 * @private |
| 717 */ | 723 */ |
| 718 onPrintToCloud_: function(event) { | 724 onPrintToCloud_: function(event) { |
| 719 assert(this.uiState_ == PrintPreview.UiState_.PRINTING, | 725 assert(this.uiState_ == PrintPreviewUiState_.PRINTING, |
| 720 'Document ready to be sent to the cloud when not in printing ' + | 726 'Document ready to be sent to the cloud when not in printing ' + |
| 721 'state: ' + this.uiState_); | 727 'state: ' + this.uiState_); |
| 722 assert(this.cloudPrintInterface_ != null, | 728 assert(this.cloudPrintInterface_ != null, |
| 723 'Google Cloud Print is not enabled'); | 729 'Google Cloud Print is not enabled'); |
| 730 assert(this.destinationStore_.selectedDestination != null); |
| 724 this.cloudPrintInterface_.submit( | 731 this.cloudPrintInterface_.submit( |
| 725 this.destinationStore_.selectedDestination, | 732 this.destinationStore_.selectedDestination, |
| 726 this.printTicketStore_, | 733 this.printTicketStore_, |
| 727 this.documentInfo_, | 734 this.documentInfo_, |
| 728 event.data); | 735 event.data); |
| 729 }, | 736 }, |
| 730 | 737 |
| 731 /** | 738 /** |
| 732 * Called from the native layer when the user cancels the save-to-pdf file | 739 * Called from the native layer when the user cancels the save-to-pdf file |
| 733 * selection dialog. | 740 * selection dialog. |
| 734 * @private | 741 * @private |
| 735 */ | 742 */ |
| 736 onFileSelectionCancel_: function() { | 743 onFileSelectionCancel_: function() { |
| 737 assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, | 744 assert(this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
| 738 'File selection cancelled when not in file-selection state: ' + | 745 'File selection cancelled when not in file-selection state: ' + |
| 739 this.uiState_); | 746 this.uiState_); |
| 740 this.setIsEnabled_(true); | 747 this.setIsEnabled_(true); |
| 741 this.uiState_ = PrintPreview.UiState_.READY; | 748 this.uiState_ = PrintPreviewUiState_.READY; |
| 742 }, | 749 }, |
| 743 | 750 |
| 744 /** | 751 /** |
| 745 * Called from the native layer when save-to-pdf file selection is complete. | 752 * Called from the native layer when save-to-pdf file selection is complete. |
| 746 * @private | 753 * @private |
| 747 */ | 754 */ |
| 748 onFileSelectionComplete_: function() { | 755 onFileSelectionComplete_: function() { |
| 749 assert(this.uiState_ == PrintPreview.UiState_.FILE_SELECTION, | 756 assert(this.uiState_ == PrintPreviewUiState_.FILE_SELECTION, |
| 750 'File selection completed when not in file-selection state: ' + | 757 'File selection completed when not in file-selection state: ' + |
| 751 this.uiState_); | 758 this.uiState_); |
| 752 this.previewArea_.showCustomMessage( | 759 this.previewArea_.showCustomMessage( |
| 753 loadTimeData.getString('printingToPDFInProgress')); | 760 loadTimeData.getString('printingToPDFInProgress')); |
| 754 this.uiState_ = PrintPreview.UiState_.PRINTING; | 761 this.uiState_ = PrintPreviewUiState_.PRINTING; |
| 755 }, | 762 }, |
| 756 | 763 |
| 757 /** | 764 /** |
| 758 * Called after successfully submitting a job to Google Cloud Print. | 765 * Called after successfully submitting a job to Google Cloud Print. |
| 759 * @param {!Event} event Contains the ID of the submitted print job. | 766 * @param {!Event} event Contains the ID of the submitted print job. |
| 760 * @private | 767 * @private |
| 761 */ | 768 */ |
| 762 onCloudPrintSubmitDone_: function(event) { | 769 onCloudPrintSubmitDone_: function(event) { |
| 763 assert(this.uiState_ == PrintPreview.UiState_.PRINTING, | 770 assert(this.uiState_ == PrintPreviewUiState_.PRINTING, |
| 764 'Submited job to Google Cloud Print but not in printing state ' + | 771 'Submited job to Google Cloud Print but not in printing state ' + |
| 765 this.uiState_); | 772 this.uiState_); |
| 766 this.close_(); | 773 this.close_(); |
| 767 }, | 774 }, |
| 768 | 775 |
| 769 /** | 776 /** |
| 770 * Called when there was an error communicating with Google Cloud print. | 777 * Called when there was an error communicating with Google Cloud print. |
| 771 * Displays an error message in the print header. | 778 * Displays an error message in the print header. |
| 772 * @param {!Event} event Contains the error message. | 779 * @param {!Event} event Contains the error message. |
| 773 * @private | 780 * @private |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 this.printIfReady_(); | 817 this.printIfReady_(); |
| 811 }, | 818 }, |
| 812 | 819 |
| 813 /** | 820 /** |
| 814 * Called when the preview area's preview failed to load. | 821 * Called when the preview area's preview failed to load. |
| 815 * @private | 822 * @private |
| 816 */ | 823 */ |
| 817 onPreviewGenerationFail_: function() { | 824 onPreviewGenerationFail_: function() { |
| 818 this.isPreviewGenerationInProgress_ = false; | 825 this.isPreviewGenerationInProgress_ = false; |
| 819 this.printHeader_.isPrintButtonEnabled = false; | 826 this.printHeader_.isPrintButtonEnabled = false; |
| 820 if (this.uiState_ == PrintPreview.UiState_.PRINTING) | 827 if (this.uiState_ == PrintPreviewUiState_.PRINTING) |
| 821 this.nativeLayer_.startCancelPendingPrint(); | 828 this.nativeLayer_.startCancelPendingPrint(); |
| 822 }, | 829 }, |
| 823 | 830 |
| 824 /** | 831 /** |
| 825 * Called when the 'Open pdf in preview' link is clicked. Launches the pdf | 832 * Called when the 'Open pdf in preview' link is clicked. Launches the pdf |
| 826 * preview app. | 833 * preview app. |
| 827 * @private | 834 * @private |
| 828 */ | 835 */ |
| 829 onOpenPdfInPreviewLinkClick_: function() { | 836 onOpenPdfInPreviewLinkClick_: function() { |
| 830 if ($('open-pdf-in-preview-link').classList.contains('disabled')) | 837 if ($('open-pdf-in-preview-link').classList.contains('disabled')) |
| 831 return; | 838 return; |
| 832 assert(this.uiState_ == PrintPreview.UiState_.READY, | 839 assert(this.uiState_ == PrintPreviewUiState_.READY, |
| 833 'Trying to open pdf in preview when not in ready state: ' + | 840 'Trying to open pdf in preview when not in ready state: ' + |
| 834 this.uiState_); | 841 this.uiState_); |
| 835 setIsVisible(getRequiredElement('open-preview-app-throbber'), true); | 842 setIsVisible(getRequiredElement('open-preview-app-throbber'), true); |
| 836 this.previewArea_.showCustomMessage( | 843 this.previewArea_.showCustomMessage( |
| 837 loadTimeData.getString('openingPDFInPreview')); | 844 loadTimeData.getString('openingPDFInPreview')); |
| 838 this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/); | 845 this.printDocumentOrOpenPdfPreview_(true /*isPdfPreview*/); |
| 839 }, | 846 }, |
| 840 | 847 |
| 841 /** | 848 /** |
| 842 * Called when the print header's print button is clicked. Prints the | 849 * Called when the print header's print button is clicked. Prints the |
| 843 * document. | 850 * document. |
| 844 * @private | 851 * @private |
| 845 */ | 852 */ |
| 846 onPrintButtonClick_: function() { | 853 onPrintButtonClick_: function() { |
| 847 assert(this.uiState_ == PrintPreview.UiState_.READY, | 854 assert(this.uiState_ == PrintPreviewUiState_.READY, |
| 848 'Trying to print when not in ready state: ' + this.uiState_); | 855 'Trying to print when not in ready state: ' + this.uiState_); |
| 849 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); | 856 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); |
| 850 }, | 857 }, |
| 851 | 858 |
| 852 /** | 859 /** |
| 853 * Called when the print header's cancel button is clicked. Closes the | 860 * Called when the print header's cancel button is clicked. Closes the |
| 854 * print dialog. | 861 * print dialog. |
| 855 * @private | 862 * @private |
| 856 */ | 863 */ |
| 857 onCancelButtonClick_: function() { | 864 onCancelButtonClick_: function() { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 e.preventDefault(); | 911 e.preventDefault(); |
| 905 return; | 912 return; |
| 906 } | 913 } |
| 907 } | 914 } |
| 908 | 915 |
| 909 if (e.keyCode == 13 /*enter*/ && | 916 if (e.keyCode == 13 /*enter*/ && |
| 910 !document.querySelector('.overlay:not([hidden])') && | 917 !document.querySelector('.overlay:not([hidden])') && |
| 911 this.destinationStore_.selectedDestination && | 918 this.destinationStore_.selectedDestination && |
| 912 this.printTicketStore_.isTicketValid() && | 919 this.printTicketStore_.isTicketValid() && |
| 913 this.printHeader_.isPrintButtonEnabled) { | 920 this.printHeader_.isPrintButtonEnabled) { |
| 914 assert(this.uiState_ == PrintPreview.UiState_.READY, | 921 assert(this.uiState_ == PrintPreviewUiState_.READY, |
| 915 'Trying to print when not in ready state: ' + this.uiState_); | 922 'Trying to print when not in ready state: ' + this.uiState_); |
| 916 var activeElementTag = document.activeElement.tagName.toUpperCase(); | 923 var activeElementTag = document.activeElement.tagName.toUpperCase(); |
| 917 if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT' && | 924 if (activeElementTag != 'BUTTON' && activeElementTag != 'SELECT' && |
| 918 activeElementTag != 'A') { | 925 activeElementTag != 'A') { |
| 919 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); | 926 this.printDocumentOrOpenPdfPreview_(false /*isPdfPreview*/); |
| 920 e.preventDefault(); | 927 e.preventDefault(); |
| 921 } | 928 } |
| 922 return; | 929 return; |
| 923 } | 930 } |
| 924 | 931 |
| 925 // Pass certain directional keyboard events to the PDF viewer. | 932 // Pass certain directional keyboard events to the PDF viewer. |
| 926 this.previewArea_.handleDirectionalKeyEvent(e); | 933 this.previewArea_.handleDirectionalKeyEvent(e); |
| 927 }, | 934 }, |
| 928 | 935 |
| 929 /** | 936 /** |
| 930 * Called when native layer receives invalid settings for a print request. | 937 * Called when native layer receives invalid settings for a print request. |
| 931 * @private | 938 * @private |
| 932 */ | 939 */ |
| 933 onSettingsInvalid_: function() { | 940 onSettingsInvalid_: function() { |
| 934 this.uiState_ = PrintPreview.UiState_.ERROR; | 941 this.uiState_ = PrintPreviewUiState_.ERROR; |
| 935 this.isPreviewGenerationInProgress_ = false; | 942 this.isPreviewGenerationInProgress_ = false; |
| 936 this.printHeader_.isPrintButtonEnabled = false; | 943 this.printHeader_.isPrintButtonEnabled = false; |
| 937 this.previewArea_.cancelTimeout(); | 944 this.previewArea_.cancelTimeout(); |
| 938 this.previewArea_.showCustomMessage( | 945 this.previewArea_.showCustomMessage( |
| 939 loadTimeData.getString('invalidPrinterSettings')); | 946 loadTimeData.getString('invalidPrinterSettings')); |
| 940 }, | 947 }, |
| 941 | 948 |
| 942 /** | 949 /** |
| 943 * Called when the destination settings' change button is activated. | 950 * Called when the destination settings' change button is activated. |
| 944 * Displays the destination search component. | 951 * Displays the destination search component. |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; | 1196 print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; |
| 1190 }, | 1197 }, |
| 1191 | 1198 |
| 1192 /** | 1199 /** |
| 1193 * Called when a print destination is selected. Shows/hides the "Print with | 1200 * Called when a print destination is selected. Shows/hides the "Print with |
| 1194 * Cloud Print" link in the navbar. | 1201 * Cloud Print" link in the navbar. |
| 1195 * @private | 1202 * @private |
| 1196 */ | 1203 */ |
| 1197 onDestinationSelect_: function() { | 1204 onDestinationSelect_: function() { |
| 1198 if ($('system-dialog-link')) { | 1205 if ($('system-dialog-link')) { |
| 1199 setIsVisible($('system-dialog-link'), | 1206 setIsVisible(getRequiredElement('system-dialog-link'), |
| 1200 this.shouldShowSystemDialogLink_()); | 1207 this.shouldShowSystemDialogLink_()); |
| 1201 } | 1208 } |
| 1202 // Reset if we had a bad settings fetch since the user selected a new | 1209 // Reset if we had a bad settings fetch since the user selected a new |
| 1203 // printer. | 1210 // printer. |
| 1204 if (this.uiState_ == PrintPreview.UiState_.ERROR) | 1211 if (this.uiState_ == PrintPreviewUiState_.ERROR) |
| 1205 this.uiState_ = PrintPreview.UiState_.READY; | 1212 this.uiState_ = PrintPreviewUiState_.READY; |
| 1206 if (this.destinationStore_.selectedDestination && | 1213 if (this.destinationStore_.selectedDestination && |
| 1207 this.isInKioskAutoPrintMode_) { | 1214 this.isInKioskAutoPrintMode_) { |
| 1208 this.onPrintButtonClick_(); | 1215 this.onPrintButtonClick_(); |
| 1209 } | 1216 } |
| 1210 }, | 1217 }, |
| 1211 | 1218 |
| 1212 /** | 1219 /** |
| 1213 * Called when the destination store loads a group of destinations. Shows | 1220 * Called when the destination store loads a group of destinations. Shows |
| 1214 * a promo on Chrome OS if the user has no print destinations promoting | 1221 * a promo on Chrome OS if the user has no print destinations promoting |
| 1215 * Google Cloud Print. | 1222 * Google Cloud Print. |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1342 // <include src="search/cloud_destination_list.js"> | 1349 // <include src="search/cloud_destination_list.js"> |
| 1343 // <include src="search/recent_destination_list.js"> | 1350 // <include src="search/recent_destination_list.js"> |
| 1344 // <include src="search/destination_list_item.js"> | 1351 // <include src="search/destination_list_item.js"> |
| 1345 // <include src="search/destination_search.js"> | 1352 // <include src="search/destination_search.js"> |
| 1346 // <include src="search/provisional_destination_resolver.js"> | 1353 // <include src="search/provisional_destination_resolver.js"> |
| 1347 | 1354 |
| 1348 window.addEventListener('DOMContentLoaded', function() { | 1355 window.addEventListener('DOMContentLoaded', function() { |
| 1349 printPreview = new print_preview.PrintPreview(); | 1356 printPreview = new print_preview.PrintPreview(); |
| 1350 printPreview.initialize(); | 1357 printPreview.initialize(); |
| 1351 }); | 1358 }); |
| OLD | NEW |