Chromium Code Reviews| Index: chrome/browser/resources/print_preview/preview_generator.js |
| diff --git a/chrome/browser/resources/print_preview/preview_generator.js b/chrome/browser/resources/print_preview/preview_generator.js |
| index 8313ed736b67de93ec7b07b9178ec17f896dc4f1..80dce339e8e40b22c0e678771944fa75f70b3bba 100644 |
| --- a/chrome/browser/resources/print_preview/preview_generator.js |
| +++ b/chrome/browser/resources/print_preview/preview_generator.js |
| @@ -58,6 +58,15 @@ cr.define('print_preview', function() { |
| this.inFlightRequestId_ = -1; |
| /** |
| + * Whether the current in flight request requires generating draft pages for |
| + * print preview. This is true only for modifiable documents when the print |
| + * settings has changed sufficiently to require re-rendering. |
| + * @type {boolean} |
|
dpapad
2017/04/22 01:32:49
Nit: @private {boolean}
Lei Zhang
2017/04/28 01:38:08
Done.
|
| + * @private |
| + */ |
| + this.generateDraft_ = false; |
| + |
| + /** |
| * Media size to generate preview with. {@code null} indicates default size. |
| * @type {cp.cdd.MediaSizeTicketItem} |
| * @private |
| @@ -173,7 +182,8 @@ cr.define('print_preview', function() { |
| !this.destinationStore_.selectedDestination) { |
| return false; |
| } |
| - if (!this.hasPreviewChanged_()) { |
| + var previewChanged = this.hasPreviewChanged_(); |
| + if (!previewChanged && !this.hasPreviewPageRangeChanged_()) { |
| // Changes to these ticket items might not trigger a new preview, but |
| // they still need to be recorded. |
| this.marginsType_ = this.printTicketStore_.marginsType.getValue(); |
| @@ -195,10 +205,12 @@ cr.define('print_preview', function() { |
| this.selectedDestination_ = this.destinationStore_.selectedDestination; |
| this.inFlightRequestId_++; |
| + this.generateDraft_ = this.documentInfo_.isModifiable && previewChanged; |
| this.nativeLayer_.startGetPreview( |
| this.destinationStore_.selectedDestination, |
| this.printTicketStore_, |
| this.documentInfo_, |
| + this.generateDraft_, |
| this.inFlightRequestId_); |
| return true; |
| }, |
| @@ -273,8 +285,9 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| - * @return {boolean} Whether the print ticket has changed sufficiently to |
| - * determine whether a new preview request should be issued. |
| + * @return {boolean} Whether the print ticket, excluding the page range, has |
| + * changed sufficiently to determine whether a new preview request |
| + * should be issued. |
| * @private |
| */ |
| hasPreviewChanged_: function() { |
| @@ -286,9 +299,6 @@ cr.define('print_preview', function() { |
| !ticketStore.color.isValueEqual(this.colorValue_) || |
| !ticketStore.scaling.isValueEqual(this.scalingValue_) || |
| !ticketStore.fitToPage.isValueEqual(this.isFitToPageEnabled_) || |
| - this.pageRanges_ == null || |
| - !areRangesEqual(ticketStore.pageRange.getPageRanges(), |
| - this.pageRanges_) || |
| (!ticketStore.marginsType.isValueEqual(this.marginsType_) && |
| !ticketStore.marginsType.isValueEqual( |
| print_preview.ticket_items.MarginsType.Value.CUSTOM)) || |
| @@ -305,6 +315,16 @@ cr.define('print_preview', function() { |
| }, |
| /** |
| + * @return {boolean} Whether the page range in the print ticket has changed. |
| + * @private |
| + */ |
| + hasPreviewPageRangeChanged_: function() { |
| + return this.pageRanges_ == null || |
| + !areRangesEqual(this.printTicketStore_.pageRange.getPageRanges(), |
| + this.pageRanges_); |
|
dpapad
2017/04/22 01:32:49
Nit (optional): There used to be a so called "box
Lei Zhang
2017/04/28 01:38:08
Done.
|
| + }, |
| + |
| + /** |
| * Called when the page layout of the document is ready. Always occurs |
| * as a result of a preview request. |
| * @param {Event} event Contains layout info about the document. |
| @@ -387,9 +407,10 @@ cr.define('print_preview', function() { |
| if (this.inFlightRequestId_ != event.previewResponseId) { |
| return; // Ignore old response. |
| } |
| - // Dispatch a PREVIEW_START event since non-modifiable documents don't |
| - // trigger PAGE_READY events. |
| - if (!this.documentInfo_.isModifiable) { |
| + if (!this.generateDraft_) { |
| + // Dispatch a PREVIEW_START event since not generating a draft PDF, |
| + // which includes print preview for non-modifiable documents, does not |
| + // trigger PAGE_READY events. |
| this.dispatchPreviewStartEvent_(event.previewUid, 0); |
| } |
| cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.DOCUMENT_READY); |