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