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 var printButton = $('print-button'); |
326 var cancelButton = $('cancel-button'); | |
327 printButton.classList.add('loading'); | |
328 $('print-summary').innerHTML = 'Printing...'; | |
dpapad
2011/05/24 00:13:25
I will localize this once I get the ok for the ani
| |
329 cancelButton.classList.add('loading'); | |
330 | |
331 if (getSelectedPrinterName() != PRINT_TO_PDF) | |
332 window.setTimeout(function() { chrome.send('print', [getSettingsJSON()]); }, | |
333 1000); | |
334 else | |
335 chrome.send('print', [getSettingsJSON()]); | |
317 } | 336 } |
318 | 337 |
319 /** | 338 /** |
320 * Asks the browser to generate a preview PDF based on current print settings. | 339 * Asks the browser to generate a preview PDF based on current print settings. |
321 */ | 340 */ |
322 function requestPrintPreview() { | 341 function requestPrintPreview() { |
323 isPreviewStillLoading = true; | 342 isPreviewStillLoading = true; |
324 setControlsDisabled(true); | 343 setControlsDisabled(true); |
325 $('dancing-dots').classList.remove('invisible'); | 344 $('dancing-dots').classList.remove('invisible'); |
326 chrome.send('getPreview', [getSettingsJSON()]); | 345 chrome.send('getPreview', [getSettingsJSON()]); |
327 } | 346 } |
328 | 347 |
329 /** | 348 /** |
330 * Fill the printer list drop down. | 349 * Fill the printer list drop down. |
331 * Called from PrintPreviewHandler::SendPrinterList(). | 350 * Called from PrintPreviewHandler::SendPrinterList(). |
332 * @param {Array} printers Array of printer info objects. | 351 * @param {Array} printers Array of printer info objects. |
333 * @param {number} defaultPrinterIndex The index of the default printer. | 352 * @param {number} defaultPrinterIndex The index of the default printer. |
334 */ | 353 */ |
335 function setPrinters(printers, defaultPrinterIndex) { | 354 function setPrinters(printers, defaultPrinterIndex) { |
336 var printerList = $('printer-list'); | 355 var printerList = $('printer-list'); |
337 for (var i = 0; i < printers.length; ++i) { | 356 for (var i = 0; i < printers.length; ++i) { |
338 addDestinationListOption(printers[i].printerName, printers[i].deviceName, | 357 addDestinationListOption(printers[i].printerName, printers[i].deviceName, |
339 i == defaultPrinterIndex, false); | 358 i == defaultPrinterIndex, false); |
340 } | 359 } |
341 addDestinationListOption('','',false, true); | 360 |
361 if (printers.length != 0) | |
362 addDestinationListOption('','', false, true); | |
342 | 363 |
343 // Adding option for saving PDF to disk. | 364 // Adding option for saving PDF to disk. |
344 addDestinationListOption(localStrings.getString('printToPDF'), | 365 addDestinationListOption(localStrings.getString('printToPDF'), |
345 PRINT_TO_PDF, false, false); | 366 PRINT_TO_PDF, false, false); |
346 addDestinationListOption('','',false, true); | 367 addDestinationListOption('','', false, true); |
347 | 368 |
348 // Add an option to manage printers. | 369 // Add an option to manage printers. |
349 addDestinationListOption(localStrings.getString('managePrinters'), | 370 addDestinationListOption(localStrings.getString('managePrinters'), |
350 MANAGE_PRINTERS, false, false); | 371 MANAGE_PRINTERS, false, false); |
351 | 372 |
352 printerList.disabled = false; | 373 printerList.disabled = false; |
353 updateControlsWithSelectedPrinterCapabilities(); | 374 updateControlsWithSelectedPrinterCapabilities(); |
354 } | 375 } |
355 | 376 |
356 /** | 377 /** |
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 copiesField.value = 1; | 922 copiesField.value = 1; |
902 else { | 923 else { |
903 var newValue = getCopies() + sign * 1; | 924 var newValue = getCopies() + sign * 1; |
904 if (newValue < copiesField.min || newValue > copiesField.max) | 925 if (newValue < copiesField.min || newValue > copiesField.max) |
905 return; | 926 return; |
906 copiesField.value = newValue; | 927 copiesField.value = newValue; |
907 } | 928 } |
908 copiesFieldChanged(); | 929 copiesFieldChanged(); |
909 } | 930 } |
910 | 931 |
OLD | NEW |