| 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 cr.exportPath('print_preview'); | 5 cr.exportPath('print_preview'); |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * @typedef {{selectSaveAsPdfDestination: boolean, | 8 * @typedef {{selectSaveAsPdfDestination: boolean, |
| 9 * layoutSettings.portrait: boolean, | 9 * layoutSettings.portrait: boolean, |
| 10 * pageRange: string, | 10 * pageRange: string, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 'use strict'; | 81 'use strict'; |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * An interface to the native Chromium printing system layer. | 84 * An interface to the native Chromium printing system layer. |
| 85 * @constructor | 85 * @constructor |
| 86 */ | 86 */ |
| 87 function NativeLayer() { | 87 function NativeLayer() { |
| 88 // Bind global handlers | 88 // Bind global handlers |
| 89 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); | 89 global.setUseCloudPrint = this.onSetUseCloudPrint_.bind(this); |
| 90 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 90 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
| 91 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); | |
| 92 global.invalidPrinterSettings = this.onInvalidPrinterSettings_.bind(this); | |
| 93 global.onDidGetDefaultPageLayout = | 91 global.onDidGetDefaultPageLayout = |
| 94 this.onDidGetDefaultPageLayout_.bind(this); | 92 this.onDidGetDefaultPageLayout_.bind(this); |
| 95 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this); | 93 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this); |
| 96 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 94 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
| 97 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | |
| 98 global.onEnableManipulateSettingsForTest = | 95 global.onEnableManipulateSettingsForTest = |
| 99 this.onEnableManipulateSettingsForTest_.bind(this); | 96 this.onEnableManipulateSettingsForTest_.bind(this); |
| 100 global.printPresetOptionsFromDocument = | 97 global.printPresetOptionsFromDocument = |
| 101 this.onPrintPresetOptionsFromDocument_.bind(this); | 98 this.onPrintPresetOptionsFromDocument_.bind(this); |
| 102 | 99 |
| 103 /** @private {!cr.EventTarget} */ | 100 /** @private {!cr.EventTarget} */ |
| 104 this.eventTarget_ = new cr.EventTarget(); | 101 this.eventTarget_ = new cr.EventTarget(); |
| 105 } | 102 } |
| 106 | 103 |
| 107 /** @private {?print_preview.NativeLayer} */ | 104 /** @private {?print_preview.NativeLayer} */ |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 * - PAGE_LAYOUT_READY | 322 * - PAGE_LAYOUT_READY |
| 326 * - PAGE_PREVIEW_READY | 323 * - PAGE_PREVIEW_READY |
| 327 * - PREVIEW_GENERATION_DONE | 324 * - PREVIEW_GENERATION_DONE |
| 328 * - PREVIEW_GENERATION_FAIL | 325 * - PREVIEW_GENERATION_FAIL |
| 329 * @param {!print_preview.Destination} destination Destination to print to. | 326 * @param {!print_preview.Destination} destination Destination to print to. |
| 330 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 327 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 331 * state of the print ticket. | 328 * state of the print ticket. |
| 332 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 329 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
| 333 * @param {boolean} generateDraft Tell the renderer to re-render. | 330 * @param {boolean} generateDraft Tell the renderer to re-render. |
| 334 * @param {number} requestId ID of the preview request. | 331 * @param {number} requestId ID of the preview request. |
| 332 * @return {!Promise<number>} Promise that resolves with the unique ID of |
| 333 * the preview UI when the preview has been generated. |
| 335 */ | 334 */ |
| 336 startGetPreview: function( | 335 getPreview: function( |
| 337 destination, printTicketStore, documentInfo, generateDraft, requestId) { | 336 destination, printTicketStore, documentInfo, generateDraft, requestId) { |
| 338 assert( | 337 assert( |
| 339 printTicketStore.isTicketValidForPreview(), | 338 printTicketStore.isTicketValidForPreview(), |
| 340 'Trying to generate preview when ticket is not valid'); | 339 'Trying to generate preview when ticket is not valid'); |
| 341 | 340 |
| 342 var ticket = { | 341 var ticket = { |
| 343 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 342 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
| 344 'mediaSize': printTicketStore.mediaSize.getValue(), | 343 'mediaSize': printTicketStore.mediaSize.getValue(), |
| 345 'landscape': printTicketStore.landscape.getValue(), | 344 'landscape': printTicketStore.landscape.getValue(), |
| 346 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 345 'color': this.getNativeColorModel_(destination, printTicketStore.color), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 var orientationEnum = | 388 var orientationEnum = |
| 390 print_preview.ticket_items.CustomMarginsOrientation; | 389 print_preview.ticket_items.CustomMarginsOrientation; |
| 391 ticket['marginsCustom'] = { | 390 ticket['marginsCustom'] = { |
| 392 'marginTop': customMargins.get(orientationEnum.TOP), | 391 'marginTop': customMargins.get(orientationEnum.TOP), |
| 393 'marginRight': customMargins.get(orientationEnum.RIGHT), | 392 'marginRight': customMargins.get(orientationEnum.RIGHT), |
| 394 'marginBottom': customMargins.get(orientationEnum.BOTTOM), | 393 'marginBottom': customMargins.get(orientationEnum.BOTTOM), |
| 395 'marginLeft': customMargins.get(orientationEnum.LEFT) | 394 'marginLeft': customMargins.get(orientationEnum.LEFT) |
| 396 }; | 395 }; |
| 397 } | 396 } |
| 398 | 397 |
| 399 chrome.send('getPreview', [ | 398 return cr.sendWithPromise( |
| 400 JSON.stringify(ticket), requestId > 0 ? documentInfo.pageCount : -1 | 399 'getPreview', JSON.stringify(ticket), |
| 401 ]); | 400 requestId > 0 ? documentInfo.pageCount : -1); |
| 402 }, | 401 }, |
| 403 | 402 |
| 404 /** | 403 /** |
| 405 * Requests that the document be printed. | 404 * Requests that the document be printed. |
| 406 * @param {!print_preview.Destination} destination Destination to print to. | 405 * @param {!print_preview.Destination} destination Destination to print to. |
| 407 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 406 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 408 * state of the print ticket. | 407 * state of the print ticket. |
| 409 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface | 408 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
| 410 * to Google Cloud Print. | 409 * to Google Cloud Print. |
| 411 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 410 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); | 567 this.eventTarget_.dispatchEvent(cloudPrintEnableEvent); |
| 569 }, | 568 }, |
| 570 | 569 |
| 571 /** Reloads the printer list. */ | 570 /** Reloads the printer list. */ |
| 572 onReloadPrintersList_: function() { | 571 onReloadPrintersList_: function() { |
| 573 cr.dispatchSimpleEvent( | 572 cr.dispatchSimpleEvent( |
| 574 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD); | 573 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD); |
| 575 }, | 574 }, |
| 576 | 575 |
| 577 /** | 576 /** |
| 578 * Display an error message when print preview fails. | |
| 579 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). | |
| 580 * @private | |
| 581 */ | |
| 582 onPrintPreviewFailed_: function() { | |
| 583 cr.dispatchSimpleEvent( | |
| 584 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); | |
| 585 }, | |
| 586 | |
| 587 /** | |
| 588 * Display an error message when encountered invalid printer settings. | |
| 589 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). | |
| 590 * @private | |
| 591 */ | |
| 592 onInvalidPrinterSettings_: function() { | |
| 593 cr.dispatchSimpleEvent( | |
| 594 this.eventTarget_, NativeLayer.EventType.SETTINGS_INVALID); | |
| 595 }, | |
| 596 | |
| 597 /** | |
| 598 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, | 577 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, |
| 599 * marginRight: number, marginTop: number, marginBottom: number, | 578 * marginRight: number, marginTop: number, marginBottom: number, |
| 600 * printableAreaX: number, printableAreaY: number, | 579 * printableAreaX: number, printableAreaY: number, |
| 601 * printableAreaWidth: number, printableAreaHeight: number}} | 580 * printableAreaWidth: number, printableAreaHeight: number}} |
| 602 * pageLayout Specifies default page layout details in points. | 581 * pageLayout Specifies default page layout details in points. |
| 603 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed | 582 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed |
| 604 * document has a custom page size style. | 583 * document has a custom page size style. |
| 605 * @private | 584 * @private |
| 606 */ | 585 */ |
| 607 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { | 586 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { | 624 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { |
| 646 var pagePreviewGenEvent = | 625 var pagePreviewGenEvent = |
| 647 new Event(NativeLayer.EventType.PAGE_PREVIEW_READY); | 626 new Event(NativeLayer.EventType.PAGE_PREVIEW_READY); |
| 648 pagePreviewGenEvent.pageIndex = pageNumber; | 627 pagePreviewGenEvent.pageIndex = pageNumber; |
| 649 pagePreviewGenEvent.previewUid = previewUid; | 628 pagePreviewGenEvent.previewUid = previewUid; |
| 650 pagePreviewGenEvent.previewResponseId = previewResponseId; | 629 pagePreviewGenEvent.previewResponseId = previewResponseId; |
| 651 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); | 630 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); |
| 652 }, | 631 }, |
| 653 | 632 |
| 654 /** | 633 /** |
| 655 * Update the print preview when new preview data is available. | |
| 656 * Create the PDF plugin as needed. | |
| 657 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | |
| 658 * @param {number} previewUid Preview unique identifier. | |
| 659 * @param {number} previewResponseId The preview request id that resulted in | |
| 660 * this response. | |
| 661 * @private | |
| 662 */ | |
| 663 onUpdatePrintPreview_: function(previewUid, previewResponseId) { | |
| 664 var previewGenDoneEvent = | |
| 665 new Event(NativeLayer.EventType.PREVIEW_GENERATION_DONE); | |
| 666 previewGenDoneEvent.previewUid = previewUid; | |
| 667 previewGenDoneEvent.previewResponseId = previewResponseId; | |
| 668 this.eventTarget_.dispatchEvent(previewGenDoneEvent); | |
| 669 }, | |
| 670 | |
| 671 /** | |
| 672 * Updates print preset options from source PDF document. | 634 * Updates print preset options from source PDF document. |
| 673 * Called from PrintPreviewUI::OnSetOptionsFromDocument(). | 635 * Called from PrintPreviewUI::OnSetOptionsFromDocument(). |
| 674 * @param {{disableScaling: boolean, copies: number, | 636 * @param {{disableScaling: boolean, copies: number, |
| 675 * duplex: number}} options Specifies | 637 * duplex: number}} options Specifies |
| 676 * printing options according to source document presets. | 638 * printing options according to source document presets. |
| 677 * @private | 639 * @private |
| 678 */ | 640 */ |
| 679 onPrintPresetOptionsFromDocument_: function(options) { | 641 onPrintPresetOptionsFromDocument_: function(options) { |
| 680 var printPresetOptionsEvent = | 642 var printPresetOptionsEvent = |
| 681 new Event(NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 643 new Event(NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 899 return this.serializedDefaultDestinationSelectionRulesStr_; | 861 return this.serializedDefaultDestinationSelectionRulesStr_; |
| 900 } | 862 } |
| 901 }; | 863 }; |
| 902 | 864 |
| 903 // Export | 865 // Export |
| 904 return { | 866 return { |
| 905 NativeInitialSettings: NativeInitialSettings, | 867 NativeInitialSettings: NativeInitialSettings, |
| 906 NativeLayer: NativeLayer | 868 NativeLayer: NativeLayer |
| 907 }; | 869 }; |
| 908 }); | 870 }); |
| OLD | NEW |