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 |
11 // The total page count of the previewed document regardless of which pages the | 11 // The total page count of the previewed document regardless of which pages the |
12 // user has selected. | 12 // user has selected. |
13 var totalPageCount = -1; | 13 var totalPageCount = -1; |
14 | 14 |
15 // The previously selected pages by the user. It is used in | 15 // The previously selected pages by the user. It is used in |
16 // onPageSelectionMayHaveChanged() to make sure that a new preview is not | 16 // onPageSelectionMayHaveChanged() to make sure that a new preview is not |
17 // requested more often than necessary. | 17 // requested more often than necessary. |
18 var previouslySelectedPages = []; | 18 var previouslySelectedPages = []; |
19 | 19 |
20 // The previously selected layout mode. It is used in order to prevent the | 20 // The previously selected layout mode. It is used in order to prevent the |
21 // preview from updating when the user clicks on the already selected layout | 21 // preview from updating when the user clicks on the already selected layout |
22 // mode. | 22 // mode. |
23 var previouslySelectedLayout = null; | 23 var previouslySelectedLayout = null; |
24 | 24 |
25 // Timer id of the page range textfield. It is used to reset the timer whenever | 25 // Timer id of the page range textfield. It is used to reset the timer whenever |
26 // needed. | 26 // needed. |
27 var timerId; | 27 var timerId; |
28 | 28 |
29 // Store the last selected printer index. | |
30 var lastSelectedPrinterIndex = 0; | |
31 | |
29 /** | 32 /** |
30 * Window onload handler, sets up the page and starts print preview by getting | 33 * Window onload handler, sets up the page and starts print preview by getting |
31 * the printer list. | 34 * the printer list. |
32 */ | 35 */ |
33 function onLoad() { | 36 function onLoad() { |
34 initializeAnimation(); | 37 initializeAnimation(); |
35 | 38 |
36 $('printer-list').disabled = true; | 39 $('printer-list').disabled = true; |
37 $('print-button').disabled = true; | 40 $('print-button').disabled = true; |
38 $('print-button').addEventListener('click', printFile); | 41 $('print-button').addEventListener('click', printFile); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 function updateControlsWithSelectedPrinterCapabilities() { | 92 function updateControlsWithSelectedPrinterCapabilities() { |
90 var printerList = $('printer-list'); | 93 var printerList = $('printer-list'); |
91 var selectedPrinter = printerList.selectedIndex; | 94 var selectedPrinter = printerList.selectedIndex; |
92 if (selectedPrinter < 0) | 95 if (selectedPrinter < 0) |
93 return; | 96 return; |
94 | 97 |
95 var printerName = printerList.options[selectedPrinter].textContent; | 98 var printerName = printerList.options[selectedPrinter].textContent; |
96 if (printerName == localStrings.getString('printToPDF')) { | 99 if (printerName == localStrings.getString('printToPDF')) { |
97 updateWithPrinterCapabilities({'disableColorOption': true, | 100 updateWithPrinterCapabilities({'disableColorOption': true, |
98 'setColorAsDefault': true}); | 101 'setColorAsDefault': true}); |
102 } else if (printerName == localStrings.getString('managePrinters')) { | |
103 printerList.selectedIndex = lastSelectedPrinterIndex; | |
104 chrome.send('managePrinters'); | |
105 return; | |
99 } else { | 106 } else { |
100 // This message will call back to 'updateWithPrinterCapabilities' | 107 // This message will call back to 'updateWithPrinterCapabilities' |
101 // function. | 108 // function. |
102 chrome.send('getPrinterCapabilities', [printerName]); | 109 chrome.send('getPrinterCapabilities', [printerName]); |
103 } | 110 } |
111 | |
112 if (lastSelectedPrinterIndex != selectedPrinter) | |
Lei Zhang
2011/04/27 23:46:36
no need for this if statement.
kmadhusu
2011/04/28 00:08:26
Done.
| |
113 lastSelectedPrinterIndex = selectedPrinter; | |
104 } | 114 } |
105 | 115 |
106 /** | 116 /** |
107 * Updates the controls with printer capabilities information. | 117 * Updates the controls with printer capabilities information. |
108 * @param {Object} settingInfo printer setting information. | 118 * @param {Object} settingInfo printer setting information. |
109 */ | 119 */ |
110 function updateWithPrinterCapabilities(settingInfo) { | 120 function updateWithPrinterCapabilities(settingInfo) { |
111 var disableColorOption = settingInfo.disableColorOption; | 121 var disableColorOption = settingInfo.disableColorOption; |
112 var setColorAsDefault = settingInfo.setColorAsDefault; | 122 var setColorAsDefault = settingInfo.setColorAsDefault; |
113 var colorOption = $('color'); | 123 var colorOption = $('color'); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
321 } | 331 } |
322 | 332 |
323 /** | 333 /** |
324 * Fill the printer list drop down. | 334 * Fill the printer list drop down. |
325 * Called from PrintPreviewHandler::SendPrinterList(). | 335 * Called from PrintPreviewHandler::SendPrinterList(). |
326 * @param {Array} printers Array of printer names. | 336 * @param {Array} printers Array of printer names. |
327 * @param {number} defaultPrinterIndex The index of the default printer. | 337 * @param {number} defaultPrinterIndex The index of the default printer. |
328 */ | 338 */ |
329 function setPrinters(printers, defaultPrinterIndex) { | 339 function setPrinters(printers, defaultPrinterIndex) { |
330 var printerList = $('printer-list'); | 340 var printerList = $('printer-list'); |
331 for (var i = 0; i < printers.length; ++i) { | 341 for (var i = 0; i < printers.length; ++i) |
332 var option = document.createElement('option'); | 342 addDestinationListOption(printers[i], i == defaultPrinterIndex); |
333 option.textContent = printers[i]; | |
334 printerList.add(option); | |
335 if (i == defaultPrinterIndex) | |
336 option.selected = true; | |
337 } | |
338 | 343 |
339 // Adding option for saving PDF to disk. | 344 // Adding option for saving PDF to disk. |
340 var option = document.createElement('option'); | 345 addDestinationListOption(localStrings.getString('printToPDF'), false); |
341 option.textContent = localStrings.getString('printToPDF'); | 346 |
342 printerList.add(option); | 347 // Add an option to manage printers. |
348 addDestinationListOption(localStrings.getString('managePrinters'), false); | |
Lei Zhang
2011/04/27 23:46:36
nit: can you keep the new line after this?
kmadhusu
2011/04/28 00:08:26
Done.
| |
343 printerList.disabled = false; | 349 printerList.disabled = false; |
344 | 350 |
345 updateControlsWithSelectedPrinterCapabilities(); | 351 updateControlsWithSelectedPrinterCapabilities(); |
346 | 352 |
347 // Once the printer list is populated, generate the initial preview. | 353 // Once the printer list is populated, generate the initial preview. |
348 requestPrintPreview(); | 354 requestPrintPreview(); |
349 } | 355 } |
350 | 356 |
351 /** | 357 /** |
358 * Adds an option to the destination list. | |
Lei Zhang
2011/04/27 23:46:36
nit: the printer destination list.
kmadhusu
2011/04/28 00:08:26
Done.
| |
359 * @param {String} optionText specifies the option text content. | |
360 * @param {boolean} is_default is true if the option needs to be selected. | |
361 */ | |
362 function addDestinationListOption(optionText, is_default) { | |
363 var option = document.createElement('option'); | |
364 option.textContent = optionText; | |
365 $('printer-list').add(option); | |
366 if (is_default) | |
367 option.selected = true; | |
368 } | |
369 | |
370 /** | |
352 * Sets the color mode for the PDF plugin. | 371 * Sets the color mode for the PDF plugin. |
353 * Called from PrintPreviewHandler::ProcessColorSetting(). | 372 * Called from PrintPreviewHandler::ProcessColorSetting(). |
354 * @param {boolean} color is true if the PDF plugin should display in color. | 373 * @param {boolean} color is true if the PDF plugin should display in color. |
355 */ | 374 */ |
356 function setColor(color) { | 375 function setColor(color) { |
357 if (!hasCompatiblePDFPlugin) { | 376 if (!hasCompatiblePDFPlugin) { |
358 return; | 377 return; |
359 } | 378 } |
360 var pdfViewer = $('pdf-viewer'); | 379 var pdfViewer = $('pdf-viewer'); |
361 if (!pdfViewer) { | 380 if (!pdfViewer) { |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
717 * Returns true if the contents of the two arrays are equal. | 736 * Returns true if the contents of the two arrays are equal. |
718 */ | 737 */ |
719 function areArraysEqual(array1, array2) { | 738 function areArraysEqual(array1, array2) { |
720 if (array1.length != array2.length) | 739 if (array1.length != array2.length) |
721 return false; | 740 return false; |
722 for (var i = 0; i < array1.length; i++) | 741 for (var i = 0; i < array1.length; i++) |
723 if(array1[i] != array2[i]) | 742 if(array1[i] != array2[i]) |
724 return false; | 743 return false; |
725 return true; | 744 return true; |
726 } | 745 } |
OLD | NEW |