| 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 * Interface to the Chromium print preview generator. | 9 * Interface to the Chromium print preview generator. |
| 10 * @param {!print_preview.DestinationStore} destinationStore Used to get the | 10 * @param {!print_preview.DestinationStore} destinationStore Used to get the |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 this.isColorEnabled_ = false; | 70 this.isColorEnabled_ = false; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * Whether the document should be fitted to the page. | 73 * Whether the document should be fitted to the page. |
| 74 * @type {boolean} | 74 * @type {boolean} |
| 75 * @private | 75 * @private |
| 76 */ | 76 */ |
| 77 this.isFitToPageEnabled_ = false; | 77 this.isFitToPageEnabled_ = false; |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * Page number set used to generate the last preview. | 80 * Page ranges setting used used to generate the last preview. |
| 81 * @type {print_preview.PageNumberSet} | 81 * @type {!Array.<object.<{from: number, to: number}>>} |
| 82 * @private | 82 * @private |
| 83 */ | 83 */ |
| 84 this.pageNumberSet_ = null; | 84 this.pageRanges_ = null; |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Margins type used to generate the last preview. | 87 * Margins type used to generate the last preview. |
| 88 * @type {!print_preview.ticket_items.MarginsType.Value} | 88 * @type {!print_preview.ticket_items.MarginsType.Value} |
| 89 * @private | 89 * @private |
| 90 */ | 90 */ |
| 91 this.marginsType_ = print_preview.ticket_items.MarginsType.Value.DEFAULT; | 91 this.marginsType_ = print_preview.ticket_items.MarginsType.Value.DEFAULT; |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Whether the document should have element CSS backgrounds printed. | 94 * Whether the document should have element CSS backgrounds printed. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Changes to these ticket items might not trigger a new preview, but | 151 // Changes to these ticket items might not trigger a new preview, but |
| 152 // they still need to be recorded. | 152 // they still need to be recorded. |
| 153 this.marginsType_ = this.printTicketStore_.getMarginsType(); | 153 this.marginsType_ = this.printTicketStore_.getMarginsType(); |
| 154 return false; | 154 return false; |
| 155 } | 155 } |
| 156 this.isLandscapeEnabled_ = this.printTicketStore_.isLandscapeEnabled(); | 156 this.isLandscapeEnabled_ = this.printTicketStore_.isLandscapeEnabled(); |
| 157 this.isHeaderFooterEnabled_ = | 157 this.isHeaderFooterEnabled_ = |
| 158 this.printTicketStore_.isHeaderFooterEnabled(); | 158 this.printTicketStore_.isHeaderFooterEnabled(); |
| 159 this.isColorEnabled_ = this.printTicketStore_.isColorEnabled(); | 159 this.isColorEnabled_ = this.printTicketStore_.isColorEnabled(); |
| 160 this.isFitToPageEnabled_ = this.printTicketStore_.isFitToPageEnabled(); | 160 this.isFitToPageEnabled_ = this.printTicketStore_.isFitToPageEnabled(); |
| 161 this.pageNumberSet_ = this.printTicketStore_.getPageNumberSet(); | 161 this.pageRanges_ = this.printTicketStore_.getPageRanges(); |
| 162 this.marginsType_ = this.printTicketStore_.getMarginsType(); | 162 this.marginsType_ = this.printTicketStore_.getMarginsType(); |
| 163 this.isCssBackgroundEnabled_ = | 163 this.isCssBackgroundEnabled_ = |
| 164 this.printTicketStore_.isCssBackgroundEnabled(); | 164 this.printTicketStore_.isCssBackgroundEnabled(); |
| 165 this.isSelectionOnlyEnabled_ = | 165 this.isSelectionOnlyEnabled_ = |
| 166 this.printTicketStore_.isSelectionOnlyEnabled(); | 166 this.printTicketStore_.isSelectionOnlyEnabled(); |
| 167 this.selectedDestination_ = this.destinationStore_.selectedDestination; | 167 this.selectedDestination_ = this.destinationStore_.selectedDestination; |
| 168 | 168 |
| 169 this.inFlightRequestId_++; | 169 this.inFlightRequestId_++; |
| 170 this.nativeLayer_.startGetPreview( | 170 this.nativeLayer_.startGetPreview( |
| 171 this.destinationStore_.selectedDestination, | 171 this.destinationStore_.selectedDestination, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 * determine whether a new preview request should be issued. | 252 * determine whether a new preview request should be issued. |
| 253 * @private | 253 * @private |
| 254 */ | 254 */ |
| 255 hasPreviewChanged_: function() { | 255 hasPreviewChanged_: function() { |
| 256 var ticketStore = this.printTicketStore_; | 256 var ticketStore = this.printTicketStore_; |
| 257 return this.inFlightRequestId_ == -1 || | 257 return this.inFlightRequestId_ == -1 || |
| 258 ticketStore.isLandscapeEnabled() != this.isLandscapeEnabled_ || | 258 ticketStore.isLandscapeEnabled() != this.isLandscapeEnabled_ || |
| 259 ticketStore.isHeaderFooterEnabled() != this.isHeaderFooterEnabled_ || | 259 ticketStore.isHeaderFooterEnabled() != this.isHeaderFooterEnabled_ || |
| 260 ticketStore.isColorEnabled() != this.isColorEnabled_ || | 260 ticketStore.isColorEnabled() != this.isColorEnabled_ || |
| 261 ticketStore.isFitToPageEnabled() != this.isFitToPageEnabled_ || | 261 ticketStore.isFitToPageEnabled() != this.isFitToPageEnabled_ || |
| 262 !ticketStore.getPageNumberSet().equals(this.pageNumberSet_) || | 262 this.pageRanges_ == null || |
| 263 !areRangesEqual(ticketStore.getPageRanges(), this.pageRanges_) || |
| 263 (ticketStore.getMarginsType() != this.marginsType_ && | 264 (ticketStore.getMarginsType() != this.marginsType_ && |
| 264 ticketStore.getMarginsType() != | 265 ticketStore.getMarginsType() != |
| 265 print_preview.ticket_items.MarginsType.Value.CUSTOM) || | 266 print_preview.ticket_items.MarginsType.Value.CUSTOM) || |
| 266 (ticketStore.getMarginsType() == | 267 (ticketStore.getMarginsType() == |
| 267 print_preview.ticket_items.MarginsType.Value.CUSTOM && | 268 print_preview.ticket_items.MarginsType.Value.CUSTOM && |
| 268 !ticketStore.getCustomMargins().equals( | 269 !ticketStore.getCustomMargins().equals( |
| 269 ticketStore.getDocumentMargins())) || | 270 ticketStore.getDocumentMargins())) || |
| 270 (ticketStore.isCssBackgroundEnabled() != | 271 (ticketStore.isCssBackgroundEnabled() != |
| 271 this.isCssBackgroundEnabled_) || | 272 this.isCssBackgroundEnabled_) || |
| 272 (ticketStore.isSelectionOnlyEnabled() != | 273 (ticketStore.isSelectionOnlyEnabled() != |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 * Called when the document page count is received from the native layer. | 317 * Called when the document page count is received from the native layer. |
| 317 * Always occurs as a result of a preview request. | 318 * Always occurs as a result of a preview request. |
| 318 * @param {cr.Event} event Contains the document's page count. | 319 * @param {cr.Event} event Contains the document's page count. |
| 319 * @private | 320 * @private |
| 320 */ | 321 */ |
| 321 onPageCountReady_: function(event) { | 322 onPageCountReady_: function(event) { |
| 322 if (this.inFlightRequestId_ != event.previewResponseId) { | 323 if (this.inFlightRequestId_ != event.previewResponseId) { |
| 323 return; // Ignore old response. | 324 return; // Ignore old response. |
| 324 } | 325 } |
| 325 this.printTicketStore_.updatePageCount(event.pageCount); | 326 this.printTicketStore_.updatePageCount(event.pageCount); |
| 326 this.pageNumberSet_ = this.printTicketStore_.getPageNumberSet(); | 327 this.pageRanges_ = this.printTicketStore_.getPageRanges(); |
| 327 }, | 328 }, |
| 328 | 329 |
| 329 /** | 330 /** |
| 330 * Called when the print preview should be reloaded. | 331 * Called when the print preview should be reloaded. |
| 331 * @param {cr.Event} event Contains the preview UID and request ID. | 332 * @param {cr.Event} event Contains the preview UID and request ID. |
| 332 * @private | 333 * @private |
| 333 */ | 334 */ |
| 334 onPreviewReload_: function(event) { | 335 onPreviewReload_: function(event) { |
| 335 if (this.inFlightRequestId_ != event.previewResponseId) { | 336 if (this.inFlightRequestId_ != event.previewResponseId) { |
| 336 return; // Ignore old response. | 337 return; // Ignore old response. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 // current one. | 395 // current one. |
| 395 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); | 396 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); |
| 396 } | 397 } |
| 397 }; | 398 }; |
| 398 | 399 |
| 399 // Export | 400 // Export |
| 400 return { | 401 return { |
| 401 PreviewGenerator: PreviewGenerator | 402 PreviewGenerator: PreviewGenerator |
| 402 }; | 403 }; |
| 403 }); | 404 }); |
| OLD | NEW |