| 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 // Whether or not the PDF plugin supports all the capabilities needed for | 7 // Whether or not the PDF plugin supports all the capabilities needed for |
| 8 // print preview. | 8 // print preview. |
| 9 var hasCompatiblePDFPlugin = true; | 9 var hasCompatiblePDFPlugin = true; |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // Destination list special value constants. | 42 // Destination list special value constants. |
| 43 const PRINT_TO_PDF = 'Print To PDF'; | 43 const PRINT_TO_PDF = 'Print To PDF'; |
| 44 const MANAGE_PRINTERS = 'Manage Printers'; | 44 const MANAGE_PRINTERS = 'Manage Printers'; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * Window onload handler, sets up the page and starts print preview by getting | 47 * Window onload handler, sets up the page and starts print preview by getting |
| 48 * the printer list. | 48 * the printer list. |
| 49 */ | 49 */ |
| 50 function onLoad() { | 50 function onLoad() { |
| 51 $('system-dialog-link').addEventListener('click', showSystemDialog); |
| 52 $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| 53 $('dummy-viewer').classList.add('hidden'); |
| 54 |
| 55 if(!checkCompatiblePluginExists()) { |
| 56 displayErrorMessage(localStrings.getString('noPlugin')); |
| 57 return; |
| 58 } |
| 59 |
| 51 $('printer-list').disabled = true; | 60 $('printer-list').disabled = true; |
| 52 $('print-button').disabled = true; | 61 $('print-button').disabled = true; |
| 53 $('print-button').addEventListener('click', printFile); | 62 $('print-button').addEventListener('click', printFile); |
| 54 $('cancel-button').addEventListener('click', handleCancelButtonClick); | |
| 55 $('all-pages').addEventListener('click', onPageSelectionMayHaveChanged); | 63 $('all-pages').addEventListener('click', onPageSelectionMayHaveChanged); |
| 56 $('copies').addEventListener('input', copiesFieldChanged); | 64 $('copies').addEventListener('input', copiesFieldChanged); |
| 57 $('print-pages').addEventListener('click', handleIndividualPagesCheckbox); | 65 $('print-pages').addEventListener('click', handleIndividualPagesCheckbox); |
| 58 $('individual-pages').addEventListener('blur', function() { | 66 $('individual-pages').addEventListener('blur', function() { |
| 59 clearTimeout(timerId); | 67 clearTimeout(timerId); |
| 60 onPageSelectionMayHaveChanged(); | 68 onPageSelectionMayHaveChanged(); |
| 61 }); | 69 }); |
| 62 $('individual-pages').addEventListener('focus', addTimerToPageRangeField); | 70 $('individual-pages').addEventListener('focus', addTimerToPageRangeField); |
| 63 $('individual-pages').addEventListener('input', pageRangesFieldChanged); | 71 $('individual-pages').addEventListener('input', pageRangesFieldChanged); |
| 64 $('two-sided').addEventListener('click', handleTwoSidedClick) | 72 $('two-sided').addEventListener('click', handleTwoSidedClick) |
| 65 $('landscape').addEventListener('click', onLayoutModeToggle); | 73 $('landscape').addEventListener('click', onLayoutModeToggle); |
| 66 $('portrait').addEventListener('click', onLayoutModeToggle); | 74 $('portrait').addEventListener('click', onLayoutModeToggle); |
| 67 $('color').addEventListener('click', function() { setColor(true); }); | 75 $('color').addEventListener('click', function() { setColor(true); }); |
| 68 $('bw').addEventListener('click', function() { setColor(false); }); | 76 $('bw').addEventListener('click', function() { setColor(false); }); |
| 69 $('printer-list').addEventListener( | 77 $('printer-list').addEventListener( |
| 70 'change', updateControlsWithSelectedPrinterCapabilities); | 78 'change', updateControlsWithSelectedPrinterCapabilities); |
| 71 $('system-dialog-link').addEventListener('click', showSystemDialog); | |
| 72 $('increment').addEventListener('click', | 79 $('increment').addEventListener('click', |
| 73 function() { onCopiesButtonsClicked(1); }); | 80 function() { onCopiesButtonsClicked(1); }); |
| 74 $('decrement').addEventListener('click', | 81 $('decrement').addEventListener('click', |
| 75 function() { onCopiesButtonsClicked(-1); }); | 82 function() { onCopiesButtonsClicked(-1); }); |
| 76 $('controls').onsubmit = function() { return false; }; | 83 $('controls').onsubmit = function() { return false; }; |
| 77 chrome.send('getPrinters'); | 84 chrome.send('getPrinters'); |
| 78 } | 85 } |
| 79 | 86 |
| 80 /** | 87 /** |
| 81 * Asks the browser to close the preview tab. | 88 * Asks the browser to close the preview tab. |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 function printFile() { | 323 function printFile() { |
| 317 chrome.send('print', [getSettingsJSON()]); | 324 chrome.send('print', [getSettingsJSON()]); |
| 318 } | 325 } |
| 319 | 326 |
| 320 /** | 327 /** |
| 321 * Asks the browser to generate a preview PDF based on current print settings. | 328 * Asks the browser to generate a preview PDF based on current print settings. |
| 322 */ | 329 */ |
| 323 function requestPrintPreview() { | 330 function requestPrintPreview() { |
| 324 isPreviewStillLoading = true; | 331 isPreviewStillLoading = true; |
| 325 setControlsDisabled(true); | 332 setControlsDisabled(true); |
| 326 $('dancing-dots').classList.remove('hidden'); | |
| 327 $('dancing-dots').classList.remove('invisible'); | 333 $('dancing-dots').classList.remove('invisible'); |
| 328 chrome.send('getPreview', [getSettingsJSON()]); | 334 chrome.send('getPreview', [getSettingsJSON()]); |
| 329 } | 335 } |
| 330 | 336 |
| 331 /** | 337 /** |
| 332 * Fill the printer list drop down. | 338 * Fill the printer list drop down. |
| 333 * Called from PrintPreviewHandler::SendPrinterList(). | 339 * Called from PrintPreviewHandler::SendPrinterList(). |
| 334 * @param {Array} printers Array of printer info objects. | 340 * @param {Array} printers Array of printer info objects. |
| 335 * @param {number} defaultPrinterIndex The index of the default printer. | 341 * @param {number} defaultPrinterIndex The index of the default printer. |
| 336 */ | 342 */ |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 389 } |
| 384 pdfViewer.grayscale(!color); | 390 pdfViewer.grayscale(!color); |
| 385 } | 391 } |
| 386 | 392 |
| 387 /** | 393 /** |
| 388 * Display an error message in the center of the preview area. | 394 * Display an error message in the center of the preview area. |
| 389 * @param (string) errorMessage The error message to be displayed. | 395 * @param (string) errorMessage The error message to be displayed. |
| 390 */ | 396 */ |
| 391 function displayErrorMessage(errorMessage) { | 397 function displayErrorMessage(errorMessage) { |
| 392 isPreviewStillLoading = false; | 398 isPreviewStillLoading = false; |
| 399 $('dancing-dots').classList.remove('invisible'); |
| 393 $('dancing-dots-text').classList.add('hidden'); | 400 $('dancing-dots-text').classList.add('hidden'); |
| 394 $('error-text').innerHTML = errorMessage; | 401 $('error-text').innerHTML = errorMessage; |
| 395 $('error-text').classList.remove('hidden'); | 402 $('error-text').classList.remove('hidden'); |
| 396 setControlsDisabled(true); | 403 setControlsDisabled(true); |
| 397 | 404 |
| 398 var pdfViewer = $('pdf-viewer'); | 405 var pdfViewer = $('pdf-viewer'); |
| 399 if (pdfViewer) | 406 if (pdfViewer) |
| 400 $('mainview').removeChild(pdfViewer); | 407 $('mainview').removeChild(pdfViewer); |
| 401 } | 408 } |
| 402 | 409 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 503 // Older version of the PDF plugin may not have this method. | 510 // Older version of the PDF plugin may not have this method. |
| 504 // TODO(thestig) Eventually remove this check. | 511 // TODO(thestig) Eventually remove this check. |
| 505 if (pdfPlugin.removePrintButton) { | 512 if (pdfPlugin.removePrintButton) { |
| 506 pdfPlugin.removePrintButton(); | 513 pdfPlugin.removePrintButton(); |
| 507 } | 514 } |
| 508 | 515 |
| 509 pdfPlugin.grayscale(true); | 516 pdfPlugin.grayscale(true); |
| 510 } | 517 } |
| 511 | 518 |
| 512 /** | 519 /** |
| 520 * Returns true if a compatible pdf plugin exists, false if it doesn't. |
| 521 */ |
| 522 function checkCompatiblePluginExists() { |
| 523 var dummyPlugin = $('dummy-viewer') |
| 524 return !!dummyPlugin.onload; |
| 525 } |
| 526 |
| 527 /** |
| 513 * Updates the state of print button depending on the user selection. | 528 * Updates the state of print button depending on the user selection. |
| 514 * The button is enabled only when the following conditions are true. | 529 * The button is enabled only when the following conditions are true. |
| 515 * 1) The selected page ranges are valid. | 530 * 1) The selected page ranges are valid. |
| 516 * 2) The number of copies is valid. | 531 * 2) The number of copies is valid. |
| 517 */ | 532 */ |
| 518 function updatePrintButtonState() { | 533 function updatePrintButtonState() { |
| 519 $('print-button').disabled = (!isNumberOfCopiesValid() || | 534 $('print-button').disabled = (!isNumberOfCopiesValid() || |
| 520 getSelectedPagesValidityLevel() != 1); | 535 getSelectedPagesValidityLevel() != 1); |
| 521 } | 536 } |
| 522 | 537 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 /** | 903 /** |
| 889 * Executed when the 'increment' or 'decrement' button is clicked. | 904 * Executed when the 'increment' or 'decrement' button is clicked. |
| 890 */ | 905 */ |
| 891 function onCopiesButtonsClicked(sign) { | 906 function onCopiesButtonsClicked(sign) { |
| 892 if($('copies').value == 1 && (sign == -1)) | 907 if($('copies').value == 1 && (sign == -1)) |
| 893 return; | 908 return; |
| 894 $('copies').value = getCopies() + sign * 1; | 909 $('copies').value = getCopies() + sign * 1; |
| 895 copiesFieldChanged(); | 910 copiesFieldChanged(); |
| 896 } | 911 } |
| 897 | 912 |
| OLD | NEW |