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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 const LONG_EDGE = 1; | 283 const LONG_EDGE = 1; |
284 return !isTwoSided() ? SIMPLEX : LONG_EDGE; | 284 return !isTwoSided() ? SIMPLEX : LONG_EDGE; |
285 } | 285 } |
286 | 286 |
287 /** | 287 /** |
288 * Creates a JSON string based on the values in the printer settings. | 288 * Creates a JSON string based on the values in the printer settings. |
289 * | 289 * |
290 * @return {string} JSON string with print job settings. | 290 * @return {string} JSON string with print job settings. |
291 */ | 291 */ |
292 function getSettingsJSON() { | 292 function getSettingsJSON() { |
293 var printerList = $('printer-list') | |
294 var selectedPrinter = printerList.selectedIndex; | |
295 var deviceName = ''; | |
296 if (selectedPrinter >= 0) | |
297 deviceName = printerList.options[selectedPrinter].value; | |
298 var printAll = $('all-pages').checked; | 293 var printAll = $('all-pages').checked; |
| 294 var deviceName = getSelectedPrinterName(); |
299 var printToPDF = (deviceName == PRINT_TO_PDF); | 295 var printToPDF = (deviceName == PRINT_TO_PDF); |
300 | 296 |
301 return JSON.stringify({'deviceName': deviceName, | 297 return JSON.stringify({'deviceName': deviceName, |
302 'pageRange': getSelectedPageRanges(), | 298 'pageRange': getSelectedPageRanges(), |
303 'printAll': printAll, | 299 'printAll': printAll, |
304 'duplex': getDuplexMode(), | 300 'duplex': getDuplexMode(), |
305 'copies': getCopies(), | 301 'copies': getCopies(), |
306 'collate': isCollated(), | 302 'collate': isCollated(), |
307 'landscape': isLandscape(), | 303 'landscape': isLandscape(), |
308 'color': isColor(), | 304 'color': isColor(), |
309 'printToPDF': printToPDF}); | 305 'printToPDF': printToPDF}); |
310 } | 306 } |
311 | 307 |
312 /** | 308 /** |
| 309 * Returns the name of the selected printer or the empty string if no |
| 310 * printer is selected. |
| 311 */ |
| 312 function getSelectedPrinterName() { |
| 313 var printerList = $('printer-list') |
| 314 var selectedPrinter = printerList.selectedIndex; |
| 315 var deviceName = ''; |
| 316 if (selectedPrinter >= 0) |
| 317 deviceName = printerList.options[selectedPrinter].value; |
| 318 return deviceName; |
| 319 } |
| 320 |
| 321 /** |
313 * Asks the browser to print the preview PDF based on current print settings. | 322 * Asks the browser to print the preview PDF based on current print settings. |
314 */ | 323 */ |
315 function printFile() { | 324 function printFile() { |
316 chrome.send('print', [getSettingsJSON()]); | 325 $('print-button').classList.add('loading'); |
| 326 $('cancel-button').classList.add('loading'); |
| 327 $('print-summary').innerHTML = localStrings.getString('printing'); |
| 328 |
| 329 if (getSelectedPrinterName() != PRINT_TO_PDF) { |
| 330 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, |
| 331 1000); |
| 332 } else |
| 333 chrome.send('print', [getSettingsJSON()]); |
317 } | 334 } |
318 | 335 |
319 /** | 336 /** |
320 * Asks the browser to generate a preview PDF based on current print settings. | 337 * Asks the browser to generate a preview PDF based on current print settings. |
321 */ | 338 */ |
322 function requestPrintPreview() { | 339 function requestPrintPreview() { |
323 isPreviewStillLoading = true; | 340 isPreviewStillLoading = true; |
324 setControlsDisabled(true); | 341 setControlsDisabled(true); |
325 $('dancing-dots').classList.remove('invisible'); | 342 $('dancing-dots').classList.remove('invisible'); |
326 chrome.send('getPreview', [getSettingsJSON()]); | 343 chrome.send('getPreview', [getSettingsJSON()]); |
327 } | 344 } |
328 | 345 |
329 /** | 346 /** |
330 * Fill the printer list drop down. | 347 * Fill the printer list drop down. |
331 * Called from PrintPreviewHandler::SendPrinterList(). | 348 * Called from PrintPreviewHandler::SendPrinterList(). |
332 * @param {Array} printers Array of printer info objects. | 349 * @param {Array} printers Array of printer info objects. |
333 * @param {number} defaultPrinterIndex The index of the default printer. | 350 * @param {number} defaultPrinterIndex The index of the default printer. |
334 */ | 351 */ |
335 function setPrinters(printers, defaultPrinterIndex) { | 352 function setPrinters(printers, defaultPrinterIndex) { |
336 var printerList = $('printer-list'); | 353 var printerList = $('printer-list'); |
337 for (var i = 0; i < printers.length; ++i) { | 354 for (var i = 0; i < printers.length; ++i) { |
338 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 355 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
339 i == defaultPrinterIndex, false); | 356 i == defaultPrinterIndex, false); |
340 } | 357 } |
341 addDestinationListOption('','',false, true); | 358 |
| 359 if (printers.length != 0) |
| 360 addDestinationListOption('', '', false, true); |
342 | 361 |
343 // Adding option for saving PDF to disk. | 362 // Adding option for saving PDF to disk. |
344 addDestinationListOption(localStrings.getString('printToPDF'), | 363 addDestinationListOption(localStrings.getString('printToPDF'), |
345 PRINT_TO_PDF, false, false); | 364 PRINT_TO_PDF, false, false); |
346 addDestinationListOption('','',false, true); | 365 addDestinationListOption('', '', false, true); |
347 | 366 |
348 // Add an option to manage printers. | 367 // Add an option to manage printers. |
349 addDestinationListOption(localStrings.getString('managePrinters'), | 368 addDestinationListOption(localStrings.getString('managePrinters'), |
350 MANAGE_PRINTERS, false, false); | 369 MANAGE_PRINTERS, false, false); |
351 | 370 |
352 printerList.disabled = false; | 371 printerList.disabled = false; |
353 updateControlsWithSelectedPrinterCapabilities(); | 372 updateControlsWithSelectedPrinterCapabilities(); |
354 } | 373 } |
355 | 374 |
356 /** | 375 /** |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 copiesField.value = 1; | 920 copiesField.value = 1; |
902 else { | 921 else { |
903 var newValue = getCopies() + sign * 1; | 922 var newValue = getCopies() + sign * 1; |
904 if (newValue < copiesField.min || newValue > copiesField.max) | 923 if (newValue < copiesField.min || newValue > copiesField.max) |
905 return; | 924 return; |
906 copiesField.value = newValue; | 925 copiesField.value = newValue; |
907 } | 926 } |
908 copiesFieldChanged(); | 927 copiesFieldChanged(); |
909 } | 928 } |
910 | 929 |
OLD | NEW |