| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * Window onload handler, sets up the page and starts print preview by getting | 37 * Window onload handler, sets up the page and starts print preview by getting |
| 38 * the printer list. | 38 * the printer list. |
| 39 */ | 39 */ |
| 40 function onLoad() { | 40 function onLoad() { |
| 41 $('system-dialog-link').addEventListener('click', showSystemDialog); | 41 $('system-dialog-link').addEventListener('click', showSystemDialog); |
| 42 $('cancel-button').addEventListener('click', handleCancelButtonClick); | 42 $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| 43 | 43 |
| 44 if (!checkCompatiblePluginExists()) { | 44 if (!checkCompatiblePluginExists()) { |
| 45 displayErrorMessage(localStrings.getString('noPlugin'), false); | 45 displayErrorMessageWithButton(localStrings.getString('noPlugin'), |
| 46 localStrings.getString('launchNativeDialog'), |
| 47 showSystemDialog); |
| 46 $('mainview').parentElement.removeChild($('dummy-viewer')); | 48 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 47 return; | 49 return; |
| 48 } | 50 } |
| 49 $('mainview').parentElement.removeChild($('dummy-viewer')); | 51 $('mainview').parentElement.removeChild($('dummy-viewer')); |
| 50 | 52 |
| 51 $('printer-list').disabled = true; | 53 $('printer-list').disabled = true; |
| 52 $('print-button').disabled = true; | 54 $('print-button').disabled = true; |
| 53 showLoadingAnimation(); | 55 showLoadingAnimation(); |
| 54 chrome.send('getDefaultPrinter'); | 56 chrome.send('getDefaultPrinter'); |
| 55 } | 57 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 function showSystemDialog() { | 136 function showSystemDialog() { |
| 135 chrome.send('showSystemDialog'); | 137 chrome.send('showSystemDialog'); |
| 136 } | 138 } |
| 137 | 139 |
| 138 /** | 140 /** |
| 139 * Disables the controls which need the initiator tab to generate preview | 141 * Disables the controls which need the initiator tab to generate preview |
| 140 * data. This function is called when the initiator tab is closed. | 142 * data. This function is called when the initiator tab is closed. |
| 141 * @param {string} initiatorTabURL The URL of the initiator tab. | 143 * @param {string} initiatorTabURL The URL of the initiator tab. |
| 142 */ | 144 */ |
| 143 function onInitiatorTabClosed(initiatorTabURL) { | 145 function onInitiatorTabClosed(initiatorTabURL) { |
| 144 $('reopen-page').addEventListener('click', function() { | 146 displayErrorMessageWithButton( |
| 145 window.location = initiatorTabURL; | 147 localStrings.getString('initiatorTabClosed'), |
| 146 }); | 148 localStrings.getString('reopenPage'), |
| 147 displayErrorMessage(localStrings.getString('initiatorTabClosed'), true); | 149 function() { window.location = initiatorTabURL; }); |
| 148 } | 150 } |
| 149 | 151 |
| 150 /** | 152 /** |
| 151 * Gets the selected printer capabilities and updates the controls accordingly. | 153 * Gets the selected printer capabilities and updates the controls accordingly. |
| 152 */ | 154 */ |
| 153 function updateControlsWithSelectedPrinterCapabilities() { | 155 function updateControlsWithSelectedPrinterCapabilities() { |
| 154 var printerList = $('printer-list'); | 156 var printerList = $('printer-list'); |
| 155 var selectedIndex = printerList.selectedIndex; | 157 var selectedIndex = printerList.selectedIndex; |
| 156 if (selectedIndex < 0) | 158 if (selectedIndex < 0) |
| 157 return; | 159 return; |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 var pdfViewer = $('pdf-viewer'); | 432 var pdfViewer = $('pdf-viewer'); |
| 431 if (!pdfViewer) { | 433 if (!pdfViewer) { |
| 432 return; | 434 return; |
| 433 } | 435 } |
| 434 pdfViewer.grayscale(!color); | 436 pdfViewer.grayscale(!color); |
| 435 } | 437 } |
| 436 | 438 |
| 437 /** | 439 /** |
| 438 * Display an error message in the center of the preview area. | 440 * Display an error message in the center of the preview area. |
| 439 * @param {string} errorMessage The error message to be displayed. | 441 * @param {string} errorMessage The error message to be displayed. |
| 440 * @param {boolean} showButton Indivates whether the "Reopen the page" button | |
| 441 * should be displayed. | |
| 442 */ | 442 */ |
| 443 function displayErrorMessage(errorMessage, showButton) { | 443 function displayErrorMessage(errorMessage) { |
| 444 $('overlay-layer').classList.remove('invisible'); | 444 $('overlay-layer').classList.remove('invisible'); |
| 445 $('dancing-dots-text').classList.add('hidden'); | 445 $('dancing-dots-text').classList.add('hidden'); |
| 446 $('error-text').innerHTML = errorMessage; | 446 $('error-text').innerHTML = errorMessage; |
| 447 $('error-text').classList.remove('hidden'); | 447 $('error-text').classList.remove('hidden'); |
| 448 if (showButton) | |
| 449 $('reopen-page').classList.remove('hidden'); | |
| 450 else | |
| 451 $('reopen-page').classList.add('hidden'); | |
| 452 | |
| 453 removeEventListeners(); | 448 removeEventListeners(); |
| 454 var pdfViewer = $('pdf-viewer'); | 449 var pdfViewer = $('pdf-viewer'); |
| 455 if (pdfViewer) | 450 if (pdfViewer) |
| 456 $('mainview').removeChild(pdfViewer); | 451 $('mainview').removeChild(pdfViewer); |
| 457 } | 452 } |
| 458 | 453 |
| 459 /** | 454 /** |
| 455 * Display an error message in the center of the preview area followed by a |
| 456 * button. |
| 457 * @param {string} errorMessage The error message to be displayed. |
| 458 * @param {string} buttonText The text to be displayed within the button. |
| 459 * @param {string} buttonListener The listener to be executed when the button is |
| 460 * clicked. |
| 461 */ |
| 462 function displayErrorMessageWithButton( |
| 463 errorMessage, buttonText, buttonListener) { |
| 464 var errorButton = $('error-button'); |
| 465 errorButton.innerHTML = buttonText; |
| 466 errorButton.onclick = buttonListener; |
| 467 errorButton.classList.remove('hidden'); |
| 468 displayErrorMessage(errorMessage); |
| 469 } |
| 470 |
| 471 /** |
| 460 * Display an error message when print preview fails. | 472 * Display an error message when print preview fails. |
| 461 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). | 473 * Called from PrintPreviewMessageHandler::OnPrintPreviewFailed(). |
| 462 */ | 474 */ |
| 463 function printPreviewFailed() { | 475 function printPreviewFailed() { |
| 464 displayErrorMessage(localStrings.getString('previewFailed'), false); | 476 displayErrorMessage(localStrings.getString('previewFailed')); |
| 465 } | 477 } |
| 466 | 478 |
| 467 /** | 479 /** |
| 468 * Called when the PDF plugin loads its document. | 480 * Called when the PDF plugin loads its document. |
| 469 */ | 481 */ |
| 470 function onPDFLoad() { | 482 function onPDFLoad() { |
| 471 if (isLandscape()) | 483 if (isLandscape()) |
| 472 $('pdf-viewer').fitToWidth(); | 484 $('pdf-viewer').fitToWidth(); |
| 473 else | 485 else |
| 474 $('pdf-viewer').fitToHeight(); | 486 $('pdf-viewer').fitToHeight(); |
| (...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 this.isLandscape = ''; | 967 this.isLandscape = ''; |
| 956 } | 968 } |
| 957 | 969 |
| 958 /** | 970 /** |
| 959 * Takes a snapshot of the print settings. | 971 * Takes a snapshot of the print settings. |
| 960 */ | 972 */ |
| 961 PrintSettings.prototype.save = function() { | 973 PrintSettings.prototype.save = function() { |
| 962 this.deviceName = getSelectedPrinterName(); | 974 this.deviceName = getSelectedPrinterName(); |
| 963 this.isLandscape = isLandscape(); | 975 this.isLandscape = isLandscape(); |
| 964 } | 976 } |
| OLD | NEW |