| 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.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * An interface to the native Chromium printing system layer. | 9 * An interface to the native Chromium printing system layer. |
| 10 * @constructor | 10 * @constructor |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 } | 191 } |
| 192 | 192 |
| 193 chrome.send( | 193 chrome.send( |
| 194 'getPreview', | 194 'getPreview', |
| 195 [JSON.stringify(ticket), | 195 [JSON.stringify(ticket), |
| 196 requestId > 0 ? printTicketStore.pageCount : -1, | 196 requestId > 0 ? printTicketStore.pageCount : -1, |
| 197 printTicketStore.isDocumentModifiable]); | 197 printTicketStore.isDocumentModifiable]); |
| 198 }, | 198 }, |
| 199 | 199 |
| 200 /** | 200 /** |
| 201 * Persists the selected destination and print ticket for the next print | |
| 202 * session. | |
| 203 * @param {!print_preview.Destination} destination Destination to save. | |
| 204 * @param {!print_preview.PrintTicketStore} printTicketStore Used for | |
| 205 * generating the serialized print ticket to persist. | |
| 206 */ | |
| 207 startSaveDestinationAndTicket: function(destination, printTicketStore) { | |
| 208 // TODO(rltoscano): Implement a comprehensive serialization process. | |
| 209 var printPreviewSerializedState = { | |
| 210 'version': print_preview.NativeLayer.SERIALIZED_STATE_VERSION_, | |
| 211 'isLocalDestination': | |
| 212 destination.type == print_preview.Destination.Type.LOCAL | |
| 213 }; | |
| 214 chrome.send( | |
| 215 'saveLastPrinter', | |
| 216 [destination.id, JSON.stringify(printPreviewSerializedState)]); | |
| 217 }, | |
| 218 | |
| 219 /** | |
| 220 * Requests that the document be printed. | 201 * Requests that the document be printed. |
| 221 * @param {!print_preview.Destination} destination Destination to print to. | 202 * @param {!print_preview.Destination} destination Destination to print to. |
| 222 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the | 203 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get the |
| 223 * state of the print ticket. | 204 * state of the print ticket. |
| 224 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface | 205 * @param {print_preview.CloudPrintInterface} cloudPrintInterface Interface |
| 225 * to Google Cloud Print. | 206 * to Google Cloud Print. |
| 226 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the | 207 * @param {boolean=} opt_isOpenPdfInPreview Whether to open the PDF in the |
| 227 * system's preview application. | 208 * system's preview application. |
| 228 */ | 209 */ |
| 229 startPrint: function(destination, printTicketStore, cloudPrintInterface, | 210 startPrint: function(destination, printTicketStore, cloudPrintInterface, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 314 |
| 334 /** Navigates the user to the Google Cloud Print management page. */ | 315 /** Navigates the user to the Google Cloud Print management page. */ |
| 335 startManageCloudDestinations: function() { | 316 startManageCloudDestinations: function() { |
| 336 chrome.send('manageCloudPrinters'); | 317 chrome.send('manageCloudPrinters'); |
| 337 }, | 318 }, |
| 338 | 319 |
| 339 /** | 320 /** |
| 340 * @param {!Object} initialSettings Object containing all initial settings. | 321 * @param {!Object} initialSettings Object containing all initial settings. |
| 341 */ | 322 */ |
| 342 onSetInitialSettings_: function(initialSettings) { | 323 onSetInitialSettings_: function(initialSettings) { |
| 343 // TODO(rltoscano): Use initialSettings['cloudPrintData'] to prepopulate | |
| 344 // destination and initial print ticket. | |
| 345 var numberFormatSymbols = | 324 var numberFormatSymbols = |
| 346 print_preview.MeasurementSystem.parseNumberFormat( | 325 print_preview.MeasurementSystem.parseNumberFormat( |
| 347 initialSettings['numberFormat']); | 326 initialSettings['numberFormat']); |
| 348 var unitType = print_preview.MeasurementSystem.UnitType.IMPERIAL; | 327 var unitType = print_preview.MeasurementSystem.UnitType.IMPERIAL; |
| 349 if (initialSettings['measurementSystem'] != null) { | 328 if (initialSettings['measurementSystem'] != null) { |
| 350 unitType = initialSettings['measurementSystem']; | 329 unitType = initialSettings['measurementSystem']; |
| 351 } | 330 } |
| 352 var measurementSystem = new print_preview.MeasurementSystem( | |
| 353 numberFormatSymbols[0], | |
| 354 numberFormatSymbols[1], | |
| 355 unitType); | |
| 356 | |
| 357 var customMargins = null; | |
| 358 if (initialSettings.hasOwnProperty('marginTop') && | |
| 359 initialSettings.hasOwnProperty('marginRight') && | |
| 360 initialSettings.hasOwnProperty('marginBottom') && | |
| 361 initialSettings.hasOwnProperty('marginLeft')) { | |
| 362 customMargins = new print_preview.Margins( | |
| 363 initialSettings['marginTop'] || 0, | |
| 364 initialSettings['marginRight'] || 0, | |
| 365 initialSettings['marginBottom'] || 0, | |
| 366 initialSettings['marginLeft'] || 0); | |
| 367 } | |
| 368 | |
| 369 var marginsType = null; | |
| 370 if (initialSettings.hasOwnProperty('marginsType')) { | |
| 371 marginsType = initialSettings['marginsType']; | |
| 372 } | |
| 373 | |
| 374 // TODO(rltoscano): Replace this loading of serialized state with a | |
| 375 // comprehensive version. | |
| 376 var serializedPrintPreviewState = | |
| 377 JSON.parse(initialSettings['cloudPrintData'] || '{}'); | |
| 378 var isLocalDestination = true; | |
| 379 if (serializedPrintPreviewState && | |
| 380 serializedPrintPreviewState.version == 1) { | |
| 381 isLocalDestination = serializedPrintPreviewState.isLocalDestination; | |
| 382 } | |
| 383 | 331 |
| 384 var nativeInitialSettings = new print_preview.NativeInitialSettings( | 332 var nativeInitialSettings = new print_preview.NativeInitialSettings( |
| 385 initialSettings['printAutomaticallyInKioskMode'] || false, | 333 initialSettings['printAutomaticallyInKioskMode'] || false, |
| 386 numberFormatSymbols[0] || ',', | 334 numberFormatSymbols[0] || ',', |
| 387 numberFormatSymbols[1] || '.', | 335 numberFormatSymbols[1] || '.', |
| 388 unitType, | 336 unitType, |
| 389 initialSettings['previewModifiable'] || false, | 337 initialSettings['previewModifiable'] || false, |
| 390 initialSettings['initiatorTabTitle'] || '', | 338 initialSettings['initiatorTabTitle'] || '', |
| 391 marginsType, | |
| 392 customMargins, | |
| 393 initialSettings['duplex'] || false, | |
| 394 initialSettings['headerFooterEnabled'] || false, | |
| 395 initialSettings['printerName'] || null, | 339 initialSettings['printerName'] || null, |
| 396 isLocalDestination); | 340 initialSettings['appState'] || null); |
| 397 | 341 |
| 398 var initialSettingsSetEvent = new cr.Event( | 342 var initialSettingsSetEvent = new cr.Event( |
| 399 NativeLayer.EventType.INITIAL_SETTINGS_SET); | 343 NativeLayer.EventType.INITIAL_SETTINGS_SET); |
| 400 initialSettingsSetEvent.initialSettings = nativeInitialSettings; | 344 initialSettingsSetEvent.initialSettings = nativeInitialSettings; |
| 401 this.dispatchEvent(initialSettingsSetEvent); | 345 this.dispatchEvent(initialSettingsSetEvent); |
| 402 }, | 346 }, |
| 403 | 347 |
| 404 /** | 348 /** |
| 405 * Turn on the integration of Cloud Print. | 349 * Turn on the integration of Cloud Print. |
| 406 * @param {string} cloudPrintURL The URL to use for cloud print servers. | 350 * @param {string} cloudPrintURL The URL to use for cloud print servers. |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 * Initial settings retrieved from the native layer. | 556 * Initial settings retrieved from the native layer. |
| 613 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be | 557 * @param {boolean} isInKioskAutoPrintMode Whether the print preview should be |
| 614 * in auto-print mode. | 558 * in auto-print mode. |
| 615 * @param {string} thousandsDelimeter Character delimeter of thousands digits. | 559 * @param {string} thousandsDelimeter Character delimeter of thousands digits. |
| 616 * @param {string} decimalDelimeter Character delimeter of the decimal point. | 560 * @param {string} decimalDelimeter Character delimeter of the decimal point. |
| 617 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of | 561 * @param {!print_preview.MeasurementSystem.UnitType} unitType Unit type of |
| 618 * local machine's measurement system. | 562 * local machine's measurement system. |
| 619 * @param {boolean} isDocumentModifiable Whether the document to print is | 563 * @param {boolean} isDocumentModifiable Whether the document to print is |
| 620 * modifiable. | 564 * modifiable. |
| 621 * @param {string} documentTitle Title of the document. | 565 * @param {string} documentTitle Title of the document. |
| 622 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Initial | 566 * @param {?string} systemDefaultDestinationId ID of the system default |
| 623 * margins type. | 567 * destination. |
| 624 * @param {print_preview.Margins} customMargins Initial custom margins. | 568 * @param {?string} serializedAppStateStr Serialized app state. |
| 625 * @param {boolean} isDuplexEnabled Whether duplexing is initially enabled. | |
| 626 * @param {boolean} isHeaderFooterEnabled Whether the header-footer is | |
| 627 * initially enabled. | |
| 628 * @param {?string} initialDestinationId ID of the destination to initially | |
| 629 * select. | |
| 630 * @param {boolean} isLocalDestination Whether the initial destination is | |
| 631 * local. | |
| 632 * @constructor | 569 * @constructor |
| 633 */ | 570 */ |
| 634 function NativeInitialSettings( | 571 function NativeInitialSettings( |
| 635 isInKioskAutoPrintMode, | 572 isInKioskAutoPrintMode, |
| 636 thousandsDelimeter, | 573 thousandsDelimeter, |
| 637 decimalDelimeter, | 574 decimalDelimeter, |
| 638 unitType, | 575 unitType, |
| 639 isDocumentModifiable, | 576 isDocumentModifiable, |
| 640 documentTitle, | 577 documentTitle, |
| 641 marginsType, | 578 systemDefaultDestinationId, |
| 642 customMargins, | 579 serializedAppStateStr) { |
| 643 isDuplexEnabled, | |
| 644 isHeaderFooterEnabled, | |
| 645 initialDestinationId, | |
| 646 isLocalDestination) { | |
| 647 | 580 |
| 648 /** | 581 /** |
| 649 * Whether the print preview should be in auto-print mode. | 582 * Whether the print preview should be in auto-print mode. |
| 650 * @type {boolean} | 583 * @type {boolean} |
| 651 * @private | 584 * @private |
| 652 */ | 585 */ |
| 653 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode; | 586 this.isInKioskAutoPrintMode_ = isInKioskAutoPrintMode; |
| 654 | 587 |
| 655 /** | 588 /** |
| 656 * Character delimeter of thousands digits. | 589 * Character delimeter of thousands digits. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 681 this.isDocumentModifiable_ = isDocumentModifiable; | 614 this.isDocumentModifiable_ = isDocumentModifiable; |
| 682 | 615 |
| 683 /** | 616 /** |
| 684 * Title of the document. | 617 * Title of the document. |
| 685 * @type {string} | 618 * @type {string} |
| 686 * @private | 619 * @private |
| 687 */ | 620 */ |
| 688 this.documentTitle_ = documentTitle; | 621 this.documentTitle_ = documentTitle; |
| 689 | 622 |
| 690 /** | 623 /** |
| 691 * Initial margins type. | 624 * ID of the system default destination. |
| 692 * @type {print_preview.ticket_items.MarginsType.Value} | |
| 693 * @private | |
| 694 */ | |
| 695 this.marginsType_ = marginsType; | |
| 696 | |
| 697 /** | |
| 698 * Initial custom margins. | |
| 699 * @type {print_preview.Margins} | |
| 700 * @private | |
| 701 */ | |
| 702 this.customMargins_ = customMargins; | |
| 703 | |
| 704 /** | |
| 705 * Whether duplexing is initially enabled. | |
| 706 * @type {boolean} | |
| 707 * @private | |
| 708 */ | |
| 709 this.isDuplexEnabled_ = isDuplexEnabled; | |
| 710 | |
| 711 /** | |
| 712 * Whether the header-footer is initially enabled. | |
| 713 * @type {boolean} | |
| 714 * @private | |
| 715 */ | |
| 716 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; | |
| 717 | |
| 718 /** | |
| 719 * ID of the initially selected destination. | |
| 720 * @type {?string} | 625 * @type {?string} |
| 721 * @private | 626 * @private |
| 722 */ | 627 */ |
| 723 this.initialDestinationId_ = initialDestinationId; | 628 this.systemDefaultDestinationId_ = systemDefaultDestinationId; |
| 724 | 629 |
| 725 /** | 630 /** |
| 726 * Whether the initial destination is local. | 631 * Serialized app state. |
| 727 * @type {boolean} | 632 * @type {?string} |
| 728 * @private | 633 * @private |
| 729 */ | 634 */ |
| 730 this.isLocalDestination_ = isLocalDestination; | 635 this.serializedAppStateStr_ = serializedAppStateStr; |
| 731 }; | 636 }; |
| 732 | 637 |
| 733 NativeInitialSettings.prototype = { | 638 NativeInitialSettings.prototype = { |
| 734 /** | 639 /** |
| 735 * @return {boolean} Whether the print preview should be in auto-print mode. | 640 * @return {boolean} Whether the print preview should be in auto-print mode. |
| 736 */ | 641 */ |
| 737 get isInKioskAutoPrintMode() { | 642 get isInKioskAutoPrintMode() { |
| 738 return this.isInKioskAutoPrintMode_; | 643 return this.isInKioskAutoPrintMode_; |
| 739 }, | 644 }, |
| 740 | 645 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 759 /** @return {boolean} Whether the document to print is modifiable. */ | 664 /** @return {boolean} Whether the document to print is modifiable. */ |
| 760 get isDocumentModifiable() { | 665 get isDocumentModifiable() { |
| 761 return this.isDocumentModifiable_; | 666 return this.isDocumentModifiable_; |
| 762 }, | 667 }, |
| 763 | 668 |
| 764 /** @return {string} Document title. */ | 669 /** @return {string} Document title. */ |
| 765 get documentTitle() { | 670 get documentTitle() { |
| 766 return this.documentTitle_; | 671 return this.documentTitle_; |
| 767 }, | 672 }, |
| 768 | 673 |
| 769 /** | 674 /** @return {?string} ID of the system default destination. */ |
| 770 * @return {print_preview.ticket_items.MarginsType.Value} Initial margins | 675 get systemDefaultDestinationId() { |
| 771 * type or {@code null} if not initially set. | 676 return this.systemDefaultDestinationId_; |
| 772 */ | |
| 773 get marginsType() { | |
| 774 return this.marginsType_; | |
| 775 }, | 677 }, |
| 776 | 678 |
| 777 /** @return {print_preview.Margins} Initial custom margins. */ | 679 /** @return {?string} Serialized app state. */ |
| 778 get customMargins() { | 680 get serializedAppStateStr() { |
| 779 return this.customMargins_; | 681 return this.serializedAppStateStr_; |
| 780 }, | |
| 781 | |
| 782 /** @return {boolean} Whether duplexing is initially enabled. */ | |
| 783 get isDuplexEnabled() { | |
| 784 return this.isDuplexEnabled_; | |
| 785 }, | |
| 786 | |
| 787 /** @return {boolean} Whether the header-footer is initially enabled. */ | |
| 788 get isHeaderFooterEnabled() { | |
| 789 return this.isHeaderFooterEnabled_; | |
| 790 }, | |
| 791 | |
| 792 /** @return {?string} ID of the initially selected destination. */ | |
| 793 get initialDestinationId() { | |
| 794 return this.initialDestinationId_; | |
| 795 }, | |
| 796 | |
| 797 /** @return {boolean} Whether the initial destination is local. */ | |
| 798 get isLocalDestination() { | |
| 799 return this.isLocalDestination_; | |
| 800 } | 682 } |
| 801 }; | 683 }; |
| 802 | 684 |
| 803 // Export | 685 // Export |
| 804 return { | 686 return { |
| 805 NativeInitialSettings: NativeInitialSettings, | 687 NativeInitialSettings: NativeInitialSettings, |
| 806 NativeLayer: NativeLayer | 688 NativeLayer: NativeLayer |
| 807 }; | 689 }; |
| 808 }); | 690 }); |
| OLD | NEW |