| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 cr.define('print_preview', function() { | 80 cr.define('print_preview', function() { |
| 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.reloadPrintersList = this.onReloadPrintersList_.bind(this); | 89 global.reloadPrintersList = this.onReloadPrintersList_.bind(this); |
| 90 global.printPreviewFailed = this.onPrintPreviewFailed_.bind(this); | |
| 91 global.invalidPrinterSettings = this.onInvalidPrinterSettings_.bind(this); | |
| 92 global.onDidGetDefaultPageLayout = | 90 global.onDidGetDefaultPageLayout = |
| 93 this.onDidGetDefaultPageLayout_.bind(this); | 91 this.onDidGetDefaultPageLayout_.bind(this); |
| 94 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this); | 92 global.onDidGetPreviewPageCount = this.onDidGetPreviewPageCount_.bind(this); |
| 95 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); | 93 global.onDidPreviewPage = this.onDidPreviewPage_.bind(this); |
| 96 global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this); | |
| 97 global.onEnableManipulateSettingsForTest = | 94 global.onEnableManipulateSettingsForTest = |
| 98 this.onEnableManipulateSettingsForTest_.bind(this); | 95 this.onEnableManipulateSettingsForTest_.bind(this); |
| 99 global.printPresetOptionsFromDocument = | 96 global.printPresetOptionsFromDocument = |
| 100 this.onPrintPresetOptionsFromDocument_.bind(this); | 97 this.onPrintPresetOptionsFromDocument_.bind(this); |
| 101 | 98 |
| 102 /** @private {!cr.EventTarget} */ | 99 /** @private {!cr.EventTarget} */ |
| 103 this.eventTarget_ = new cr.EventTarget(); | 100 this.eventTarget_ = new cr.EventTarget(); |
| 104 } | 101 } |
| 105 | 102 |
| 106 /** @private {?print_preview.NativeLayer} */ | 103 /** @private {?print_preview.NativeLayer} */ |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 * - PAGE_LAYOUT_READY | 320 * - PAGE_LAYOUT_READY |
| 324 * - PAGE_PREVIEW_READY | 321 * - PAGE_PREVIEW_READY |
| 325 * - PREVIEW_GENERATION_DONE | 322 * - PREVIEW_GENERATION_DONE |
| 326 * - PREVIEW_GENERATION_FAIL | 323 * - PREVIEW_GENERATION_FAIL |
| 327 * @param {!print_preview.Destination} destination Destination to print to. | 324 * @param {!print_preview.Destination} destination Destination to print to. |
| 328 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 325 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 329 * state of the print ticket. | 326 * state of the print ticket. |
| 330 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 327 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
| 331 * @param {boolean} generateDraft Tell the renderer to re-render. | 328 * @param {boolean} generateDraft Tell the renderer to re-render. |
| 332 * @param {number} requestId ID of the preview request. | 329 * @param {number} requestId ID of the preview request. |
| 330 * @return {!Promise<number>} Promise that resolves with the unique ID of |
| 331 * the preview UI when the preview has been generated. |
| 333 */ | 332 */ |
| 334 startGetPreview: function( | 333 getPreview: function( |
| 335 destination, printTicketStore, documentInfo, generateDraft, requestId) { | 334 destination, printTicketStore, documentInfo, generateDraft, requestId) { |
| 336 assert( | 335 assert( |
| 337 printTicketStore.isTicketValidForPreview(), | 336 printTicketStore.isTicketValidForPreview(), |
| 338 'Trying to generate preview when ticket is not valid'); | 337 'Trying to generate preview when ticket is not valid'); |
| 339 | 338 |
| 340 var ticket = { | 339 var ticket = { |
| 341 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), | 340 'pageRange': printTicketStore.pageRange.getDocumentPageRanges(), |
| 342 'mediaSize': printTicketStore.mediaSize.getValue(), | 341 'mediaSize': printTicketStore.mediaSize.getValue(), |
| 343 'landscape': printTicketStore.landscape.getValue(), | 342 'landscape': printTicketStore.landscape.getValue(), |
| 344 'color': this.getNativeColorModel_(destination, printTicketStore.color), | 343 'color': this.getNativeColorModel_(destination, printTicketStore.color), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 var orientationEnum = | 386 var orientationEnum = |
| 388 print_preview.ticket_items.CustomMarginsOrientation; | 387 print_preview.ticket_items.CustomMarginsOrientation; |
| 389 ticket['marginsCustom'] = { | 388 ticket['marginsCustom'] = { |
| 390 'marginTop': customMargins.get(orientationEnum.TOP), | 389 'marginTop': customMargins.get(orientationEnum.TOP), |
| 391 'marginRight': customMargins.get(orientationEnum.RIGHT), | 390 'marginRight': customMargins.get(orientationEnum.RIGHT), |
| 392 'marginBottom': customMargins.get(orientationEnum.BOTTOM), | 391 'marginBottom': customMargins.get(orientationEnum.BOTTOM), |
| 393 'marginLeft': customMargins.get(orientationEnum.LEFT) | 392 'marginLeft': customMargins.get(orientationEnum.LEFT) |
| 394 }; | 393 }; |
| 395 } | 394 } |
| 396 | 395 |
| 397 chrome.send('getPreview', [ | 396 return cr.sendWithPromise( |
| 398 JSON.stringify(ticket), requestId > 0 ? documentInfo.pageCount : -1 | 397 'getPreview', JSON.stringify(ticket), |
| 399 ]); | 398 requestId > 0 ? documentInfo.pageCount : -1); |
| 400 }, | 399 }, |
| 401 | 400 |
| 402 /** | 401 /** |
| 403 * Requests that the document be printed. | 402 * Requests that the document be printed. |
| 404 * @param {!print_preview.Destination} destination Destination to print to. | 403 * @param {!print_preview.Destination} destination Destination to print to. |
| 405 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 404 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 406 * state of the print ticket. | 405 * state of the print ticket. |
| 407 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface | 406 * @param {cloudprint.CloudPrintInterface} cloudPrintInterface Interface |
| 408 * to Google Cloud Print. | 407 * to Google Cloud Print. |
| 409 * @param {!print_preview.DocumentInfo} documentInfo Document data model. | 408 * @param {!print_preview.DocumentInfo} documentInfo Document data model. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 chrome.send('forceOpenNewTab', [url]); | 551 chrome.send('forceOpenNewTab', [url]); |
| 553 }, | 552 }, |
| 554 | 553 |
| 555 /** Reloads the printer list. */ | 554 /** Reloads the printer list. */ |
| 556 onReloadPrintersList_: function() { | 555 onReloadPrintersList_: function() { |
| 557 cr.dispatchSimpleEvent( | 556 cr.dispatchSimpleEvent( |
| 558 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD); | 557 this.eventTarget_, NativeLayer.EventType.DESTINATIONS_RELOAD); |
| 559 }, | 558 }, |
| 560 | 559 |
| 561 /** | 560 /** |
| 562 * Display an error message when print preview fails. | |
| 563 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). | |
| 564 * @private | |
| 565 */ | |
| 566 onPrintPreviewFailed_: function() { | |
| 567 cr.dispatchSimpleEvent( | |
| 568 this.eventTarget_, NativeLayer.EventType.PREVIEW_GENERATION_FAIL); | |
| 569 }, | |
| 570 | |
| 571 /** | |
| 572 * Display an error message when encountered invalid printer settings. | |
| 573 * Called from PrintPreviewMessageHandler::OnInvalidPrinterSettings(). | |
| 574 * @private | |
| 575 */ | |
| 576 onInvalidPrinterSettings_: function() { | |
| 577 cr.dispatchSimpleEvent( | |
| 578 this.eventTarget_, NativeLayer.EventType.SETTINGS_INVALID); | |
| 579 }, | |
| 580 | |
| 581 /** | |
| 582 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, | 561 * @param {{contentWidth: number, contentHeight: number, marginLeft: number, |
| 583 * marginRight: number, marginTop: number, marginBottom: number, | 562 * marginRight: number, marginTop: number, marginBottom: number, |
| 584 * printableAreaX: number, printableAreaY: number, | 563 * printableAreaX: number, printableAreaY: number, |
| 585 * printableAreaWidth: number, printableAreaHeight: number}} | 564 * printableAreaWidth: number, printableAreaHeight: number}} |
| 586 * pageLayout Specifies default page layout details in points. | 565 * pageLayout Specifies default page layout details in points. |
| 587 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed | 566 * @param {boolean} hasCustomPageSizeStyle Indicates whether the previewed |
| 588 * document has a custom page size style. | 567 * document has a custom page size style. |
| 589 * @private | 568 * @private |
| 590 */ | 569 */ |
| 591 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { | 570 onDidGetDefaultPageLayout_: function(pageLayout, hasCustomPageSizeStyle) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { | 608 onDidPreviewPage_: function(pageNumber, previewUid, previewResponseId) { |
| 630 var pagePreviewGenEvent = | 609 var pagePreviewGenEvent = |
| 631 new Event(NativeLayer.EventType.PAGE_PREVIEW_READY); | 610 new Event(NativeLayer.EventType.PAGE_PREVIEW_READY); |
| 632 pagePreviewGenEvent.pageIndex = pageNumber; | 611 pagePreviewGenEvent.pageIndex = pageNumber; |
| 633 pagePreviewGenEvent.previewUid = previewUid; | 612 pagePreviewGenEvent.previewUid = previewUid; |
| 634 pagePreviewGenEvent.previewResponseId = previewResponseId; | 613 pagePreviewGenEvent.previewResponseId = previewResponseId; |
| 635 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); | 614 this.eventTarget_.dispatchEvent(pagePreviewGenEvent); |
| 636 }, | 615 }, |
| 637 | 616 |
| 638 /** | 617 /** |
| 639 * Update the print preview when new preview data is available. | |
| 640 * Create the PDF plugin as needed. | |
| 641 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | |
| 642 * @param {number} previewUid Preview unique identifier. | |
| 643 * @param {number} previewResponseId The preview request id that resulted in | |
| 644 * this response. | |
| 645 * @private | |
| 646 */ | |
| 647 onUpdatePrintPreview_: function(previewUid, previewResponseId) { | |
| 648 var previewGenDoneEvent = | |
| 649 new Event(NativeLayer.EventType.PREVIEW_GENERATION_DONE); | |
| 650 previewGenDoneEvent.previewUid = previewUid; | |
| 651 previewGenDoneEvent.previewResponseId = previewResponseId; | |
| 652 this.eventTarget_.dispatchEvent(previewGenDoneEvent); | |
| 653 }, | |
| 654 | |
| 655 /** | |
| 656 * Updates print preset options from source PDF document. | 618 * Updates print preset options from source PDF document. |
| 657 * Called from PrintPreviewUI::OnSetOptionsFromDocument(). | 619 * Called from PrintPreviewUI::OnSetOptionsFromDocument(). |
| 658 * @param {{disableScaling: boolean, copies: number, | 620 * @param {{disableScaling: boolean, copies: number, |
| 659 * duplex: number}} options Specifies | 621 * duplex: number}} options Specifies |
| 660 * printing options according to source document presets. | 622 * printing options according to source document presets. |
| 661 * @private | 623 * @private |
| 662 */ | 624 */ |
| 663 onPrintPresetOptionsFromDocument_: function(options) { | 625 onPrintPresetOptionsFromDocument_: function(options) { |
| 664 var printPresetOptionsEvent = | 626 var printPresetOptionsEvent = |
| 665 new Event(NativeLayer.EventType.PRINT_PRESET_OPTIONS); | 627 new Event(NativeLayer.EventType.PRINT_PRESET_OPTIONS); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 883 return this.serializedDefaultDestinationSelectionRulesStr_; | 845 return this.serializedDefaultDestinationSelectionRulesStr_; |
| 884 } | 846 } |
| 885 }; | 847 }; |
| 886 | 848 |
| 887 // Export | 849 // Export |
| 888 return { | 850 return { |
| 889 NativeInitialSettings: NativeInitialSettings, | 851 NativeInitialSettings: NativeInitialSettings, |
| 890 NativeLayer: NativeLayer | 852 NativeLayer: NativeLayer |
| 891 }; | 853 }; |
| 892 }); | 854 }); |
| OLD | NEW |