| 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 12 matching lines...) Expand all Loading... |
| 23 // Used to disable some printing options when the preview is not modifiable. | 23 // Used to disable some printing options when the preview is not modifiable. |
| 24 var previewModifiable = false; | 24 var previewModifiable = false; |
| 25 | 25 |
| 26 // Destination list special value constants. | 26 // Destination list special value constants. |
| 27 const PRINT_TO_PDF = 'Print To PDF'; | 27 const PRINT_TO_PDF = 'Print To PDF'; |
| 28 const MANAGE_PRINTERS = 'Manage Printers'; | 28 const MANAGE_PRINTERS = 'Manage Printers'; |
| 29 | 29 |
| 30 // State of the print preview settings. | 30 // State of the print preview settings. |
| 31 var printSettings = new PrintSettings(); | 31 var printSettings = new PrintSettings(); |
| 32 | 32 |
| 33 // The name of the default or last used printer. |
| 34 var defaultOrLastUsedPrinterName = ''; |
| 35 |
| 33 /** | 36 /** |
| 34 * 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 |
| 35 * the printer list. | 38 * the printer list. |
| 36 */ | 39 */ |
| 37 function onLoad() { | 40 function onLoad() { |
| 38 $('system-dialog-link').addEventListener('click', showSystemDialog); | 41 $('system-dialog-link').addEventListener('click', showSystemDialog); |
| 39 $('cancel-button').addEventListener('click', handleCancelButtonClick); | 42 $('cancel-button').addEventListener('click', handleCancelButtonClick); |
| 40 | 43 |
| 41 if (!checkCompatiblePluginExists()) { | 44 if (!checkCompatiblePluginExists()) { |
| 42 displayErrorMessage(localStrings.getString('noPlugin'), false); | 45 displayErrorMessage(localStrings.getString('noPlugin'), false); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 351 } |
| 349 | 352 |
| 350 /** | 353 /** |
| 351 * Set the default printer. If there is one, generate a print preview. | 354 * Set the default printer. If there is one, generate a print preview. |
| 352 * @param {string} printer Name of the default printer. Empty if none. | 355 * @param {string} printer Name of the default printer. Empty if none. |
| 353 */ | 356 */ |
| 354 function setDefaultPrinter(printer) { | 357 function setDefaultPrinter(printer) { |
| 355 // Add a placeholder value so the printer list looks valid. | 358 // Add a placeholder value so the printer list looks valid. |
| 356 addDestinationListOption('', '', true, true); | 359 addDestinationListOption('', '', true, true); |
| 357 if (printer) { | 360 if (printer) { |
| 358 $('printer-list')[0].value = printer; | 361 defaultOrLastUsedPrinterName = printer; |
| 362 $('printer-list')[0].value = defaultOrLastUsedPrinterName; |
| 359 updateControlsWithSelectedPrinterCapabilities(); | 363 updateControlsWithSelectedPrinterCapabilities(); |
| 360 } | 364 } |
| 361 chrome.send('getPrinters'); | 365 chrome.send('getPrinters'); |
| 362 } | 366 } |
| 363 | 367 |
| 364 /** | 368 /** |
| 365 * Fill the printer list drop down. | 369 * Fill the printer list drop down. |
| 366 * Called from PrintPreviewHandler::SendPrinterList(). | 370 * Called from PrintPreviewHandler::SendPrinterList(). |
| 367 * @param {Array} printers Array of printer info objects. | 371 * @param {Array} printers Array of printer info objects. |
| 368 * @param {number} defaultPrinterIndex The index of the default printer. | |
| 369 */ | 372 */ |
| 370 function setPrinters(printers, defaultPrinterIndex) { | 373 function setPrinters(printers) { |
| 371 var printerList = $('printer-list'); | 374 var printerList = $('printer-list'); |
| 372 // If there exists a dummy printer value, then setDefaultPrinter() already | 375 // If there exists a dummy printer value, then setDefaultPrinter() already |
| 373 // requested a preview, so no need to do it again. | 376 // requested a preview, so no need to do it again. |
| 374 var needPreview = (printerList[0].value == ''); | 377 var needPreview = (printerList[0].value == ''); |
| 375 for (var i = 0; i < printers.length; ++i) { | 378 for (var i = 0; i < printers.length; ++i) { |
| 376 // Check if we are looking at the default printer. | 379 var isDefault = (printers[i].deviceName == defaultOrLastUsedPrinterName); |
| 377 if (i == defaultPrinterIndex) { | |
| 378 // If the default printer from setDefaultPrinter() does not match the | |
| 379 // enumerated value, (re)generate the print preview. | |
| 380 if (printers[i].deviceName != printerList[0].value) | |
| 381 needPreview = true; | |
| 382 } | |
| 383 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 380 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
| 384 i == defaultPrinterIndex, false); | 381 isDefault, false); |
| 385 } | 382 } |
| 386 | 383 |
| 387 // Remove the dummy printer added in setDefaultPrinter(). | 384 // Remove the dummy printer added in setDefaultPrinter(). |
| 388 printerList.remove(0); | 385 printerList.remove(0); |
| 389 | 386 |
| 390 if (printers.length != 0) | 387 if (printers.length != 0) |
| 391 addDestinationListOption('', '', false, true); | 388 addDestinationListOption('', '', false, true); |
| 392 | 389 |
| 393 // Adding option for saving PDF to disk. | 390 // Adding option for saving PDF to disk. |
| 394 addDestinationListOption(localStrings.getString('printToPDF'), | 391 addDestinationListOption(localStrings.getString('printToPDF'), |
| 395 PRINT_TO_PDF, false, false); | 392 PRINT_TO_PDF, |
| 393 defaultOrLastUsedPrinterName == PRINT_TO_PDF, |
| 394 false); |
| 396 addDestinationListOption('', '', false, true); | 395 addDestinationListOption('', '', false, true); |
| 397 | 396 |
| 398 // Add an option to manage printers. | 397 // Add an option to manage printers. |
| 399 addDestinationListOption(localStrings.getString('managePrinters'), | 398 addDestinationListOption(localStrings.getString('managePrinters'), |
| 400 MANAGE_PRINTERS, false, false); | 399 MANAGE_PRINTERS, false, false); |
| 401 | 400 |
| 402 printerList.disabled = false; | 401 printerList.disabled = false; |
| 403 | 402 |
| 404 if (needPreview) | 403 if (needPreview) |
| 405 updateControlsWithSelectedPrinterCapabilities(); | 404 updateControlsWithSelectedPrinterCapabilities(); |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 this.isLandscape = ''; | 963 this.isLandscape = ''; |
| 965 } | 964 } |
| 966 | 965 |
| 967 /** | 966 /** |
| 968 * Takes a snapshot of the print settings. | 967 * Takes a snapshot of the print settings. |
| 969 */ | 968 */ |
| 970 PrintSettings.prototype.save = function() { | 969 PrintSettings.prototype.save = function() { |
| 971 this.deviceName = getSelectedPrinterName(); | 970 this.deviceName = getSelectedPrinterName(); |
| 972 this.isLandscape = isLandscape(); | 971 this.isLandscape = isLandscape(); |
| 973 } | 972 } |
| OLD | NEW |