| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 var localStrings = new LocalStrings(); | 5 var localStrings = new LocalStrings(); |
| 6 | 6 |
| 7 // The total page count of the previewed document regardless of which pages the | 7 // The total page count of the previewed document regardless of which pages the |
| 8 // user has selected. | 8 // user has selected. |
| 9 var totalPageCount = -1; | 9 var totalPageCount = -1; |
| 10 | 10 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 updateCopiesButtonsState(); | 486 updateCopiesButtonsState(); |
| 487 } | 487 } |
| 488 | 488 |
| 489 /** | 489 /** |
| 490 * Update the print preview when new preview data is available. | 490 * Update the print preview when new preview data is available. |
| 491 * Create the PDF plugin as needed. | 491 * Create the PDF plugin as needed. |
| 492 * Called from PrintPreviewUI::PreviewDataIsAvailable(). | 492 * Called from PrintPreviewUI::PreviewDataIsAvailable(). |
| 493 * @param {number} pageCount The expected total pages count. | 493 * @param {number} pageCount The expected total pages count. |
| 494 * @param {string} jobTitle The print job title. | 494 * @param {string} jobTitle The print job title. |
| 495 * @param {boolean} modifiable If the preview is modifiable. | 495 * @param {boolean} modifiable If the preview is modifiable. |
| 496 * | 496 * @param {string} previewUIId Preview UI identifier. |
| 497 */ | 497 */ |
| 498 function updatePrintPreview(pageCount, jobTitle, modifiable) { | 498 function updatePrintPreview(pageCount, jobTitle, modifiable, previewUIId) { |
| 499 var tempPrintSettings = new PrintSettings(); | 499 var tempPrintSettings = new PrintSettings(); |
| 500 tempPrintSettings.save(); | 500 tempPrintSettings.save(); |
| 501 | 501 |
| 502 previewModifiable = modifiable; | 502 previewModifiable = modifiable; |
| 503 | 503 |
| 504 if (totalPageCount == -1) | 504 if (totalPageCount == -1) |
| 505 totalPageCount = pageCount; | 505 totalPageCount = pageCount; |
| 506 | 506 |
| 507 if (previouslySelectedPages.length == 0) | 507 if (previouslySelectedPages.length == 0) |
| 508 for (var i = 0; i < totalPageCount; i++) | 508 for (var i = 0; i < totalPageCount; i++) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 522 return; | 522 return; |
| 523 } | 523 } |
| 524 } | 524 } |
| 525 | 525 |
| 526 if (getSelectedPagesValidityLevel() != 1) | 526 if (getSelectedPagesValidityLevel() != 1) |
| 527 pageRangesFieldChanged(); | 527 pageRangesFieldChanged(); |
| 528 | 528 |
| 529 // Update the current tab title. | 529 // Update the current tab title. |
| 530 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); | 530 document.title = localStrings.getStringF('printPreviewTitleFormat', jobTitle); |
| 531 | 531 |
| 532 createPDFPlugin(); | 532 createPDFPlugin(previewUIId); |
| 533 updatePrintSummary(); | 533 updatePrintSummary(); |
| 534 updatePrintButtonState(); | 534 updatePrintButtonState(); |
| 535 addEventListeners(); | 535 addEventListeners(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 /** | 538 /** |
| 539 * Create the PDF plugin or reload the existing one. | 539 * Create the PDF plugin or reload the existing one. |
| 540 * @param {string} previewUIId Preview UI identifier. |
| 540 */ | 541 */ |
| 541 function createPDFPlugin() { | 542 function createPDFPlugin(previewUIId) { |
| 542 // Enable the print button. | 543 // Enable the print button. |
| 543 if (!$('printer-list').disabled) { | 544 if (!$('printer-list').disabled) { |
| 544 $('print-button').disabled = false; | 545 $('print-button').disabled = false; |
| 545 } | 546 } |
| 546 | 547 |
| 547 var pdfViewer = $('pdf-viewer'); | 548 var pdfViewer = $('pdf-viewer'); |
| 548 if (pdfViewer) { | 549 if (pdfViewer) { |
| 549 // Older version of the PDF plugin may not have this method. | 550 // Older version of the PDF plugin may not have this method. |
| 550 // TODO(thestig) Eventually remove this check. | 551 // TODO(thestig) Eventually remove this check. |
| 551 if (pdfViewer.goToPage) { | 552 if (pdfViewer.goToPage) { |
| 552 // Need to call this before the reload(), where the plugin resets its | 553 // Need to call this before the reload(), where the plugin resets its |
| 553 // internal page count. | 554 // internal page count. |
| 554 pdfViewer.goToPage('0'); | 555 pdfViewer.goToPage('0'); |
| 555 } | 556 } |
| 556 pdfViewer.reload(); | 557 pdfViewer.reload(); |
| 557 pdfViewer.grayscale(!isColor()); | 558 pdfViewer.grayscale(!isColor()); |
| 558 return; | 559 return; |
| 559 } | 560 } |
| 560 | 561 |
| 561 var pdfPlugin = document.createElement('embed'); | 562 var pdfPlugin = document.createElement('embed'); |
| 562 pdfPlugin.setAttribute('id', 'pdf-viewer'); | 563 pdfPlugin.setAttribute('id', 'pdf-viewer'); |
| 563 pdfPlugin.setAttribute('type', 'application/pdf'); | 564 pdfPlugin.setAttribute('type', 'application/pdf'); |
| 564 pdfPlugin.setAttribute('src', 'chrome://print/print.pdf'); | 565 pdfPlugin.setAttribute('src', 'chrome://print/print.pdf/' + previewUIId); |
| 565 var mainView = $('mainview'); | 566 var mainView = $('mainview'); |
| 566 mainView.appendChild(pdfPlugin); | 567 mainView.appendChild(pdfPlugin); |
| 567 pdfPlugin.onload('onPDFLoad()'); | 568 pdfPlugin.onload('onPDFLoad()'); |
| 568 | 569 |
| 569 // Older version of the PDF plugin may not have this method. | 570 // Older version of the PDF plugin may not have this method. |
| 570 // TODO(thestig) Eventually remove this check. | 571 // TODO(thestig) Eventually remove this check. |
| 571 if (pdfPlugin.removePrintButton) { | 572 if (pdfPlugin.removePrintButton) { |
| 572 pdfPlugin.removePrintButton(); | 573 pdfPlugin.removePrintButton(); |
| 573 } | 574 } |
| 574 | 575 |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 985 this.isLandscape = ''; | 986 this.isLandscape = ''; |
| 986 } | 987 } |
| 987 | 988 |
| 988 /** | 989 /** |
| 989 * Takes a snapshot of the print settings. | 990 * Takes a snapshot of the print settings. |
| 990 */ | 991 */ |
| 991 PrintSettings.prototype.save = function() { | 992 PrintSettings.prototype.save = function() { |
| 992 this.deviceName = getSelectedPrinterName(); | 993 this.deviceName = getSelectedPrinterName(); |
| 993 this.isLandscape = isLandscape(); | 994 this.isLandscape = isLandscape(); |
| 994 } | 995 } |
| OLD | NEW |