Chromium Code Reviews| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 fadeInElement($('copies-option')); | 195 fadeInElement($('copies-option')); |
| 196 $('hr-before-copies').classList.add('invisible'); | 196 $('hr-before-copies').classList.add('invisible'); |
| 197 } | 197 } |
| 198 | 198 |
| 199 disableColorOption ? fadeOutElement($('color-options')) : | 199 disableColorOption ? fadeOutElement($('color-options')) : |
| 200 fadeInElement($('color-options')); | 200 fadeInElement($('color-options')); |
| 201 | 201 |
| 202 if (colorOption.checked != setColorAsDefault) { | 202 if (colorOption.checked != setColorAsDefault) { |
| 203 colorOption.checked = setColorAsDefault; | 203 colorOption.checked = setColorAsDefault; |
| 204 bwOption.checked = !setColorAsDefault; | 204 bwOption.checked = !setColorAsDefault; |
| 205 setColor(colorOption.checked); | |
|
Lei Zhang
2011/06/10 04:11:47
on first load, this fails because the PDF plugin h
| |
| 206 } | 205 } |
| 207 } | 206 } |
| 208 | 207 |
| 209 /** | 208 /** |
| 210 * Validates the copies text field value. | 209 * Validates the copies text field value. |
| 211 * NOTE: An empty copies field text is considered valid because the blur event | 210 * NOTE: An empty copies field text is considered valid because the blur event |
| 212 * listener of this field will set it back to a default value. | 211 * listener of this field will set it back to a default value. |
| 213 * @return {boolean} true if the number of copies is valid else returns false. | 212 * @return {boolean} true if the number of copies is valid else returns false. |
| 214 */ | 213 */ |
| 215 function isNumberOfCopiesValid() { | 214 function isNumberOfCopiesValid() { |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 | 465 |
| 467 /** | 466 /** |
| 468 * Called when the PDF plugin loads its document. | 467 * Called when the PDF plugin loads its document. |
| 469 */ | 468 */ |
| 470 function onPDFLoad() { | 469 function onPDFLoad() { |
| 471 if (isLandscape()) | 470 if (isLandscape()) |
| 472 $('pdf-viewer').fitToWidth(); | 471 $('pdf-viewer').fitToWidth(); |
| 473 else | 472 else |
| 474 $('pdf-viewer').fitToHeight(); | 473 $('pdf-viewer').fitToHeight(); |
| 475 | 474 |
| 475 setColor($('color').checked); | |
| 476 | |
| 476 hideLoadingAnimation(); | 477 hideLoadingAnimation(); |
| 477 | 478 |
| 478 if (!previewModifiable) | 479 if (!previewModifiable) |
| 479 fadeOutElement($('landscape-option')); | 480 fadeOutElement($('landscape-option')); |
| 480 | 481 |
| 481 updateCopiesButtonsState(); | 482 updateCopiesButtonsState(); |
| 482 } | 483 } |
| 483 | 484 |
| 484 /** | 485 /** |
| 485 * Update the print preview when new preview data is available. | 486 * Update the print preview when new preview data is available. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 * @param {string} previewUid Preview unique identifier. | 536 * @param {string} previewUid Preview unique identifier. |
| 536 */ | 537 */ |
| 537 function createPDFPlugin(previewUid) { | 538 function createPDFPlugin(previewUid) { |
| 538 // Enable the print button. | 539 // Enable the print button. |
| 539 if (!$('printer-list').disabled) { | 540 if (!$('printer-list').disabled) { |
| 540 $('print-button').disabled = false; | 541 $('print-button').disabled = false; |
| 541 } | 542 } |
| 542 | 543 |
| 543 var pdfViewer = $('pdf-viewer'); | 544 var pdfViewer = $('pdf-viewer'); |
| 544 if (pdfViewer) { | 545 if (pdfViewer) { |
| 545 // Older version of the PDF plugin may not have this method. | 546 // Need to call this before the reload(), where the plugin resets its |
| 546 // TODO(thestig) Eventually remove this check. | 547 // internal page count. |
| 547 if (pdfViewer.goToPage) { | 548 pdfViewer.goToPage('0'); |
| 548 // Need to call this before the reload(), where the plugin resets its | 549 |
| 549 // internal page count. | |
| 550 pdfViewer.goToPage('0'); | |
| 551 } | |
| 552 pdfViewer.reload(); | 550 pdfViewer.reload(); |
| 553 pdfViewer.grayscale(!isColor()); | 551 pdfViewer.grayscale(!isColor()); |
| 554 return; | 552 return; |
| 555 } | 553 } |
| 556 | 554 |
| 557 var pdfPlugin = document.createElement('embed'); | 555 var pdfPlugin = document.createElement('embed'); |
| 558 pdfPlugin.setAttribute('id', 'pdf-viewer'); | 556 pdfPlugin.setAttribute('id', 'pdf-viewer'); |
| 559 pdfPlugin.setAttribute('type', 'application/pdf'); | 557 pdfPlugin.setAttribute('type', 'application/pdf'); |
| 560 pdfPlugin.setAttribute('src', 'chrome://print/' + previewUid + '/print.pdf'); | 558 pdfPlugin.setAttribute('src', 'chrome://print/' + previewUid + '/print.pdf'); |
| 561 var mainView = $('mainview'); | 559 var mainView = $('mainview'); |
| 562 mainView.appendChild(pdfPlugin); | 560 mainView.appendChild(pdfPlugin); |
| 563 pdfPlugin.onload('onPDFLoad()'); | 561 pdfPlugin.onload('onPDFLoad()'); |
| 564 | 562 pdfPlugin.removePrintButton(); |
| 565 // Older version of the PDF plugin may not have this method. | |
| 566 // TODO(thestig) Eventually remove this check. | |
| 567 if (pdfPlugin.removePrintButton) { | |
| 568 pdfPlugin.removePrintButton(); | |
| 569 } | |
| 570 | |
| 571 pdfPlugin.grayscale(true); | 563 pdfPlugin.grayscale(true); |
| 572 } | 564 } |
| 573 | 565 |
| 574 /** | 566 /** |
| 575 * Returns true if a compatible pdf plugin exists, false if it doesn't. | 567 * Returns true if a compatible pdf plugin exists, false if it doesn't. |
| 576 */ | 568 */ |
| 577 function checkCompatiblePluginExists() { | 569 function checkCompatiblePluginExists() { |
| 578 var dummyPlugin = $('dummy-viewer') | 570 var dummyPlugin = $('dummy-viewer') |
| 579 return !!dummyPlugin.onload; | 571 return (dummyPlugin.onload && |
| 572 dummyPlugin.goToPage && | |
| 573 dummyPlugin.removePrintButton); | |
| 580 } | 574 } |
| 581 | 575 |
| 582 /** | 576 /** |
| 583 * Updates the state of print button depending on the user selection. | 577 * Updates the state of print button depending on the user selection. |
| 584 * The button is enabled only when the following conditions are true. | 578 * The button is enabled only when the following conditions are true. |
| 585 * 1) The selected page ranges are valid. | 579 * 1) The selected page ranges are valid. |
| 586 * 2) The number of copies is valid (if applicable). | 580 * 2) The number of copies is valid (if applicable). |
| 587 */ | 581 */ |
| 588 function updatePrintButtonState() { | 582 function updatePrintButtonState() { |
| 589 if (getSelectedPrinterName() == PRINT_TO_PDF) { | 583 if (getSelectedPrinterName() == PRINT_TO_PDF) { |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 this.isLandscape = ''; | 949 this.isLandscape = ''; |
| 956 } | 950 } |
| 957 | 951 |
| 958 /** | 952 /** |
| 959 * Takes a snapshot of the print settings. | 953 * Takes a snapshot of the print settings. |
| 960 */ | 954 */ |
| 961 PrintSettings.prototype.save = function() { | 955 PrintSettings.prototype.save = function() { |
| 962 this.deviceName = getSelectedPrinterName(); | 956 this.deviceName = getSelectedPrinterName(); |
| 963 this.isLandscape = isLandscape(); | 957 this.isLandscape = isLandscape(); |
| 964 } | 958 } |
| OLD | NEW |