| 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 * Enumeration of IDs shown in the preview area. | 8 * Enumeration of IDs shown in the preview area. |
| 9 * @enum {string} | 9 * @enum {string} |
| 10 * @private | 10 * @private |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 * @private | 164 * @private |
| 165 */ | 165 */ |
| 166 this.overlayEl_ = null; | 166 this.overlayEl_ = null; |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * The "Open system dialog" button. | 169 * The "Open system dialog" button. |
| 170 * @type {HTMLButtonElement} | 170 * @type {HTMLButtonElement} |
| 171 * @private | 171 * @private |
| 172 */ | 172 */ |
| 173 this.openSystemDialogButton_ = null; | 173 this.openSystemDialogButton_ = null; |
| 174 |
| 175 /** |
| 176 * If this is in a browser test (fake plugin). |
| 177 * @private {boolean} |
| 178 */ |
| 179 this.isBrowserTest_ = false; |
| 174 } | 180 } |
| 175 | 181 |
| 176 /** | 182 /** |
| 177 * Event types dispatched by the preview area. | 183 * Event types dispatched by the preview area. |
| 178 * @enum {string} | 184 * @enum {string} |
| 179 */ | 185 */ |
| 180 PreviewArea.EventType = { | 186 PreviewArea.EventType = { |
| 181 // Dispatched when the "Open system dialog" button is clicked. | 187 // Dispatched when the "Open system dialog" button is clicked. |
| 182 OPEN_SYSTEM_DIALOG_CLICK: | 188 OPEN_SYSTEM_DIALOG_CLICK: |
| 183 'print_preview.PreviewArea.OPEN_SYSTEM_DIALOG_CLICK', | 189 'print_preview.PreviewArea.OPEN_SYSTEM_DIALOG_CLICK', |
| 184 | 190 |
| 185 // Dispatched when the document preview is complete. | 191 // Dispatched when the document preview is complete. |
| 186 PREVIEW_GENERATION_DONE: | 192 PREVIEW_GENERATION_DONE: |
| 187 'print_preview.PreviewArea.PREVIEW_GENERATION_DONE', | 193 'print_preview.PreviewArea.PREVIEW_GENERATION_DONE', |
| 188 | 194 |
| 189 // Dispatched when the document preview failed to be generated. | 195 // Dispatched when the document preview failed to be generated. |
| 190 PREVIEW_GENERATION_FAIL: | 196 PREVIEW_GENERATION_FAIL: |
| 191 'print_preview.PreviewArea.PREVIEW_GENERATION_FAIL', | 197 'print_preview.PreviewArea.PREVIEW_GENERATION_FAIL', |
| 192 | 198 |
| 193 // Dispatched when a new document preview is being generated. | 199 // Dispatched when a new document preview is being generated. |
| 194 PREVIEW_GENERATION_IN_PROGRESS: | 200 PREVIEW_GENERATION_IN_PROGRESS: |
| 195 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS' | 201 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS', |
| 202 |
| 203 // Dispatched when invalid printer settings are detected. |
| 204 SETTINGS_INVALID: 'print_preview.PreviewArea.SETTINGS_INVALID' |
| 196 }; | 205 }; |
| 197 | 206 |
| 198 /** | 207 /** |
| 199 * CSS classes used by the preview area. | 208 * CSS classes used by the preview area. |
| 200 * @enum {string} | 209 * @enum {string} |
| 201 * @private | 210 * @private |
| 202 */ | 211 */ |
| 203 PreviewArea.Classes_ = { | 212 PreviewArea.Classes_ = { |
| 204 OUT_OF_PROCESS_COMPATIBILITY_OBJECT: | 213 OUT_OF_PROCESS_COMPATIBILITY_OBJECT: |
| 205 'preview-area-compatibility-object-out-of-process', | 214 'preview-area-compatibility-object-out-of-process', |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 this.tracker.add( | 353 this.tracker.add( |
| 345 this.previewGenerator_, | 354 this.previewGenerator_, |
| 346 print_preview.PreviewGenerator.EventType.PREVIEW_START, | 355 print_preview.PreviewGenerator.EventType.PREVIEW_START, |
| 347 this.onPreviewStart_.bind(this)); | 356 this.onPreviewStart_.bind(this)); |
| 348 this.tracker.add( | 357 this.tracker.add( |
| 349 this.previewGenerator_, | 358 this.previewGenerator_, |
| 350 print_preview.PreviewGenerator.EventType.PAGE_READY, | 359 print_preview.PreviewGenerator.EventType.PAGE_READY, |
| 351 this.onPagePreviewReady_.bind(this)); | 360 this.onPagePreviewReady_.bind(this)); |
| 352 this.tracker.add( | 361 this.tracker.add( |
| 353 this.previewGenerator_, | 362 this.previewGenerator_, |
| 354 print_preview.PreviewGenerator.EventType.FAIL, | |
| 355 this.onPreviewGenerationFail_.bind(this)); | |
| 356 this.tracker.add( | |
| 357 this.previewGenerator_, | |
| 358 print_preview.PreviewGenerator.EventType.DOCUMENT_READY, | 363 print_preview.PreviewGenerator.EventType.DOCUMENT_READY, |
| 359 this.onDocumentReady_.bind(this)); | 364 this.onDocumentReady_.bind(this)); |
| 360 } else { | 365 } else { |
| 361 this.showCustomMessage(loadTimeData.getString('noPlugin')); | 366 this.showCustomMessage(loadTimeData.getString('noPlugin')); |
| 362 } | 367 } |
| 363 }, | 368 }, |
| 364 | 369 |
| 365 /** @override */ | 370 /** @override */ |
| 366 exitDocument: function() { | 371 exitDocument: function() { |
| 367 print_preview.Component.prototype.exitDocument.call(this); | 372 print_preview.Component.prototype.exitDocument.call(this); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 setIsVisible(openSystemDialogThrobber, true); | 521 setIsVisible(openSystemDialogThrobber, true); |
| 517 cr.dispatchSimpleEvent( | 522 cr.dispatchSimpleEvent( |
| 518 this, PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK); | 523 this, PreviewArea.EventType.OPEN_SYSTEM_DIALOG_CLICK); |
| 519 }, | 524 }, |
| 520 | 525 |
| 521 /** | 526 /** |
| 522 * Called when the print ticket changes. Updates the preview. | 527 * Called when the print ticket changes. Updates the preview. |
| 523 * @private | 528 * @private |
| 524 */ | 529 */ |
| 525 onTicketChange_: function() { | 530 onTicketChange_: function() { |
| 526 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { | 531 if (!this.previewGenerator_) |
| 532 return; |
| 533 var previewRequest = this.previewGenerator_.requestPreview(); |
| 534 if (previewRequest.id > -1) { |
| 527 cr.dispatchSimpleEvent( | 535 cr.dispatchSimpleEvent( |
| 528 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); | 536 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); |
| 529 if (this.loadingTimeout_ == null) { | 537 if (this.loadingTimeout_ == null) { |
| 530 this.loadingTimeout_ = setTimeout( | 538 this.loadingTimeout_ = setTimeout( |
| 531 this.showMessage_.bind( | 539 this.showMessage_.bind( |
| 532 this, print_preview.PreviewAreaMessageId_.LOADING), | 540 this, print_preview.PreviewAreaMessageId_.LOADING), |
| 533 PreviewArea.LOADING_TIMEOUT_); | 541 PreviewArea.LOADING_TIMEOUT_); |
| 534 } | 542 } |
| 543 previewRequest.request.then( |
| 544 /** @param {number} previewUid The unique id of the preview. */ |
| 545 function(previewUid) { |
| 546 this.previewGenerator_.onPreviewGenerationDone( |
| 547 previewRequest.id, previewUid); |
| 548 }.bind(this), |
| 549 /** |
| 550 * @param {*} type The type of print preview failure that |
| 551 * occurred. |
| 552 */ |
| 553 function(type) { |
| 554 if (/** @type{string} */ (type) == 'CANCELLED') |
| 555 return; // overriden by a new request, do nothing. |
| 556 else if (/** @type{string} */ (type) == 'SETTINGS_INVALID') { |
| 557 this.cancelTimeout(); |
| 558 this.showCustomMessage( |
| 559 loadTimeData.getString('invalidPrinterSettings')); |
| 560 cr.dispatchSimpleEvent( |
| 561 this, PreviewArea.EventType.SETTINGS_INVALID); |
| 562 } else { |
| 563 this.onPreviewGenerationFail_(); |
| 564 } |
| 565 }.bind(this)); |
| 535 } else { | 566 } else { |
| 536 this.marginControlContainer_.showMarginControlsIfNeeded(); | 567 this.marginControlContainer_.showMarginControlsIfNeeded(); |
| 537 } | 568 } |
| 538 }, | 569 }, |
| 539 | 570 |
| 540 /** | 571 /** |
| 541 * Called when the preview generator begins loading the preview. | 572 * Called when the preview generator begins loading the preview. |
| 542 * @param {Event} event Contains the URL to initialize the plugin to. | 573 * @param {Event} event Contains the URL to initialize the plugin to. |
| 543 * @private | 574 * @private |
| 544 */ | 575 */ |
| (...skipping 22 matching lines...) Expand all Loading... |
| 567 this.plugin_.loadPreviewPage(event.previewUrl, event.previewIndex); | 598 this.plugin_.loadPreviewPage(event.previewUrl, event.previewIndex); |
| 568 }, | 599 }, |
| 569 | 600 |
| 570 /** | 601 /** |
| 571 * Called when the preview generation is complete and the document is ready | 602 * Called when the preview generation is complete and the document is ready |
| 572 * to print. | 603 * to print. |
| 573 * @private | 604 * @private |
| 574 */ | 605 */ |
| 575 onDocumentReady_: function(event) { | 606 onDocumentReady_: function(event) { |
| 576 this.isDocumentReady_ = true; | 607 this.isDocumentReady_ = true; |
| 608 if (this.isBrowserTest_) |
| 609 this.isPluginReloaded_ = true; |
| 577 this.dispatchPreviewGenerationDoneIfReady_(); | 610 this.dispatchPreviewGenerationDoneIfReady_(); |
| 578 }, | 611 }, |
| 579 | 612 |
| 580 /** | 613 /** |
| 581 * Cancels the timeout so that an error message can be shown. | 614 * Cancels the timeout so that an error message can be shown. |
| 582 */ | 615 */ |
| 583 cancelTimeout: function() { | 616 cancelTimeout: function() { |
| 584 if (this.loadingTimeout_) { | 617 if (this.loadingTimeout_) { |
| 585 clearTimeout(this.loadingTimeout_); | 618 clearTimeout(this.loadingTimeout_); |
| 586 this.loadingTimeout_ = null; | 619 this.loadingTimeout_ = null; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 */ | 667 */ |
| 635 onMarginDragChanged_: function(isDragging) { | 668 onMarginDragChanged_: function(isDragging) { |
| 636 if (!this.plugin_) | 669 if (!this.plugin_) |
| 637 return; | 670 return; |
| 638 | 671 |
| 639 // When hovering over the plugin (which may be in a separate iframe) | 672 // When hovering over the plugin (which may be in a separate iframe) |
| 640 // pointer events will be sent to the frame. When dragging the margins, | 673 // pointer events will be sent to the frame. When dragging the margins, |
| 641 // we don't want this to happen as it can cause the margin to stop | 674 // we don't want this to happen as it can cause the margin to stop |
| 642 // being draggable. | 675 // being draggable. |
| 643 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; | 676 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; |
| 677 }, |
| 678 |
| 679 /** @param {boolean} isTest Whether this instance is in a browser test. */ |
| 680 setIsBrowserTest: function(isTest) { |
| 681 this.isBrowserTest_ = isTest; |
| 644 } | 682 } |
| 645 }; | 683 }; |
| 646 | 684 |
| 647 // Export | 685 // Export |
| 648 return {PreviewArea: PreviewArea}; | 686 return {PreviewArea: PreviewArea}; |
| 649 }); | 687 }); |
| OLD | NEW |