| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 this.tracker_.add( | 198 this.tracker_.add( |
| 199 this.nativeLayer_, | 199 this.nativeLayer_, |
| 200 print_preview.NativeLayer.EventType.PAGE_LAYOUT_READY, | 200 print_preview.NativeLayer.EventType.PAGE_LAYOUT_READY, |
| 201 this.onPageLayoutReady_.bind(this)); | 201 this.onPageLayoutReady_.bind(this)); |
| 202 this.tracker_.add( | 202 this.tracker_.add( |
| 203 this.nativeLayer_, | 203 this.nativeLayer_, |
| 204 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, | 204 print_preview.NativeLayer.EventType.PAGE_COUNT_READY, |
| 205 this.onPageCountReady_.bind(this)); | 205 this.onPageCountReady_.bind(this)); |
| 206 this.tracker_.add( | 206 this.tracker_.add( |
| 207 this.nativeLayer_, | 207 this.nativeLayer_, |
| 208 print_preview.NativeLayer.EventType.PREVIEW_RELOAD, | |
| 209 this.onPreviewReload_.bind(this)); | |
| 210 this.tracker_.add( | |
| 211 this.nativeLayer_, | |
| 212 print_preview.NativeLayer.EventType.PAGE_PREVIEW_READY, | 208 print_preview.NativeLayer.EventType.PAGE_PREVIEW_READY, |
| 213 this.onPagePreviewReady_.bind(this)); | 209 this.onPagePreviewReady_.bind(this)); |
| 214 this.tracker_.add( | 210 this.tracker_.add( |
| 215 this.nativeLayer_, | 211 this.nativeLayer_, |
| 216 print_preview.NativeLayer.EventType.PREVIEW_GENERATION_DONE, | 212 print_preview.NativeLayer.EventType.PREVIEW_GENERATION_DONE, |
| 217 this.onPreviewGenerationDone_.bind(this)); | 213 this.onPreviewGenerationDone_.bind(this)); |
| 218 this.tracker_.add( | 214 this.tracker_.add( |
| 219 this.nativeLayer_, | 215 this.nativeLayer_, |
| 220 print_preview.NativeLayer.EventType.PREVIEW_GENERATION_FAIL, | 216 print_preview.NativeLayer.EventType.PREVIEW_GENERATION_FAIL, |
| 221 this.onPreviewGenerationFail_.bind(this)); | 217 this.onPreviewGenerationFail_.bind(this)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 */ | 329 */ |
| 334 onPageCountReady_: function(event) { | 330 onPageCountReady_: function(event) { |
| 335 if (this.inFlightRequestId_ != event.previewResponseId) { | 331 if (this.inFlightRequestId_ != event.previewResponseId) { |
| 336 return; // Ignore old response. | 332 return; // Ignore old response. |
| 337 } | 333 } |
| 338 this.documentInfo_.updatePageCount(event.pageCount); | 334 this.documentInfo_.updatePageCount(event.pageCount); |
| 339 this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges(); | 335 this.pageRanges_ = this.printTicketStore_.pageRange.getPageRanges(); |
| 340 }, | 336 }, |
| 341 | 337 |
| 342 /** | 338 /** |
| 343 * Called when the print preview should be reloaded. | |
| 344 * @param {Event} event Contains the preview UID and request ID. | |
| 345 * @private | |
| 346 */ | |
| 347 onPreviewReload_: function(event) { | |
| 348 if (this.inFlightRequestId_ != event.previewResponseId) { | |
| 349 return; // Ignore old response. | |
| 350 } | |
| 351 var pageNumberSet = this.printTicketStore_.pageRange.getPageNumberSet(); | |
| 352 this.dispatchPreviewStartEvent_( | |
| 353 event.previewUid, pageNumberSet.getPageNumberAt(0) - 1); | |
| 354 for (var i = 0; i < pageNumberSet.size; i++) { | |
| 355 var pageNumber = pageNumberSet.getPageNumberAt(i); | |
| 356 this.dispatchPageReadyEvent_(i, pageNumber, event.previewUid); | |
| 357 } | |
| 358 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.DOCUMENT_READY); | |
| 359 }, | |
| 360 | |
| 361 /** | |
| 362 * Called when a page's preview has been generated. Dispatches a | 339 * Called when a page's preview has been generated. Dispatches a |
| 363 * PAGE_READY event. | 340 * PAGE_READY event. |
| 364 * @param {Event} event Contains the page index and preview UID. | 341 * @param {Event} event Contains the page index and preview UID. |
| 365 * @private | 342 * @private |
| 366 */ | 343 */ |
| 367 onPagePreviewReady_: function(event) { | 344 onPagePreviewReady_: function(event) { |
| 368 if (this.inFlightRequestId_ != event.previewResponseId) { | 345 if (this.inFlightRequestId_ != event.previewResponseId) { |
| 369 return; // Ignore old response. | 346 return; // Ignore old response. |
| 370 } | 347 } |
| 371 var pageNumber = event.pageIndex + 1; | 348 var pageNumber = event.pageIndex + 1; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 // current one. | 384 // current one. |
| 408 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); | 385 cr.dispatchSimpleEvent(this, PreviewGenerator.EventType.FAIL); |
| 409 } | 386 } |
| 410 }; | 387 }; |
| 411 | 388 |
| 412 // Export | 389 // Export |
| 413 return { | 390 return { |
| 414 PreviewGenerator: PreviewGenerator | 391 PreviewGenerator: PreviewGenerator |
| 415 }; | 392 }; |
| 416 }); | 393 }); |
| OLD | NEW |