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 {print_preview.ticket_items.PageRange} |
82 * @private | 82 * @private |
83 */ | 83 */ |
84 this.pageNumberSet_ = null; | 84 this.pageRange_ = 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.pageRange_ = this.printTicketStore_.getPageRange().clone(); |
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 !ticketStore.getPageRange().equals(this.pageRange_) || |
263 (ticketStore.getMarginsType() != this.marginsType_ && | 263 (ticketStore.getMarginsType() != this.marginsType_ && |
264 ticketStore.getMarginsType() != | 264 ticketStore.getMarginsType() != |
265 print_preview.ticket_items.MarginsType.Value.CUSTOM) || | 265 print_preview.ticket_items.MarginsType.Value.CUSTOM) || |
266 (ticketStore.getMarginsType() == | 266 (ticketStore.getMarginsType() == |
267 print_preview.ticket_items.MarginsType.Value.CUSTOM && | 267 print_preview.ticket_items.MarginsType.Value.CUSTOM && |
268 !ticketStore.getCustomMargins().equals( | 268 !ticketStore.getCustomMargins().equals( |
269 ticketStore.getDocumentMargins())) || | 269 ticketStore.getDocumentMargins())) || |
270 (ticketStore.isCssBackgroundEnabled() != | 270 (ticketStore.isCssBackgroundEnabled() != |
271 this.isCssBackgroundEnabled_) || | 271 this.isCssBackgroundEnabled_) || |
272 (ticketStore.isSelectionOnlyEnabled() != | 272 (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. | 316 * Called when the document page count is received from the native layer. |
317 * Always occurs as a result of a preview request. | 317 * Always occurs as a result of a preview request. |
318 * @param {cr.Event} event Contains the document's page count. | 318 * @param {cr.Event} event Contains the document's page count. |
319 * @private | 319 * @private |
320 */ | 320 */ |
321 onPageCountReady_: function(event) { | 321 onPageCountReady_: function(event) { |
322 if (this.inFlightRequestId_ != event.previewResponseId) { | 322 if (this.inFlightRequestId_ != event.previewResponseId) { |
323 return; // Ignore old response. | 323 return; // Ignore old response. |
324 } | 324 } |
325 this.printTicketStore_.updatePageCount(event.pageCount); | 325 this.printTicketStore_.updatePageCount(event.pageCount); |
326 this.pageNumberSet_ = this.printTicketStore_.getPageNumberSet(); | 326 this.pageRange_ = this.printTicketStore_.getPageRange().clone(); |
327 }, | 327 }, |
328 | 328 |
329 /** | 329 /** |
330 * Called when the print preview should be reloaded. | 330 * Called when the print preview should be reloaded. |
331 * @param {cr.Event} event Contains the preview UID and request ID. | 331 * @param {cr.Event} event Contains the preview UID and request ID. |
332 * @private | 332 * @private |
333 */ | 333 */ |
334 onPreviewReload_: function(event) { | 334 onPreviewReload_: function(event) { |
335 if (this.inFlightRequestId_ != event.previewResponseId) { | 335 if (this.inFlightRequestId_ != event.previewResponseId) { |
336 return; // Ignore old response. | 336 return; // Ignore old response. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // current one. | 394 // current one. |
395 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); | 395 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); |
396 } | 396 } |
397 }; | 397 }; |
398 | 398 |
399 // Export | 399 // Export |
400 return { | 400 return { |
401 PreviewGenerator: PreviewGenerator | 401 PreviewGenerator: PreviewGenerator |
402 }; | 402 }; |
403 }); | 403 }); |
OLD | NEW |