Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/resources/print_preview.js

Issue 6903083: PrintPreview:[MAC & WIN] Added code to show the native printer management dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed review comments Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
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 // Indicates whether a preview has been requested but not received yet. 29 // Indicates whether a preview has been requested but not received yet.
30 var isPreviewStillLoading = false; 30 var isPreviewStillLoading = false;
31 31
32 // Currently selected printer capabilities. 32 // Currently selected printer capabilities.
33 var printerCapabilities; 33 var printerCapabilities;
34 34
35 // Store the last selected printer index.
36 var lastSelectedPrinterIndex = 0;
37
35 /** 38 /**
36 * Window onload handler, sets up the page and starts print preview by getting 39 * Window onload handler, sets up the page and starts print preview by getting
37 * the printer list. 40 * the printer list.
38 */ 41 */
39 function onLoad() { 42 function onLoad() {
40 initializeAnimation(); 43 initializeAnimation();
41 44
42 $('printer-list').disabled = true; 45 $('printer-list').disabled = true;
43 $('print-button').disabled = true; 46 $('print-button').disabled = true;
44 $('print-button').addEventListener('click', printFile); 47 $('print-button').addEventListener('click', printFile);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 function updateControlsWithSelectedPrinterCapabilities() { 98 function updateControlsWithSelectedPrinterCapabilities() {
96 var printerList = $('printer-list'); 99 var printerList = $('printer-list');
97 var selectedPrinter = printerList.selectedIndex; 100 var selectedPrinter = printerList.selectedIndex;
98 if (selectedPrinter < 0) 101 if (selectedPrinter < 0)
99 return; 102 return;
100 103
101 var printerName = printerList.options[selectedPrinter].textContent; 104 var printerName = printerList.options[selectedPrinter].textContent;
102 if (printerName == localStrings.getString('printToPDF')) { 105 if (printerName == localStrings.getString('printToPDF')) {
103 updateWithPrinterCapabilities({'disableColorOption': true, 106 updateWithPrinterCapabilities({'disableColorOption': true,
104 'setColorAsDefault': true}); 107 'setColorAsDefault': true});
108 } else if (printerName == localStrings.getString('managePrinters')) {
109 printerList.selectedIndex = lastSelectedPrinterIndex;
110 chrome.send('managePrinters');
111 return;
105 } else { 112 } else {
106 // This message will call back to 'updateWithPrinterCapabilities' 113 // This message will call back to 'updateWithPrinterCapabilities'
107 // function. 114 // function.
108 chrome.send('getPrinterCapabilities', [printerName]); 115 chrome.send('getPrinterCapabilities', [printerName]);
109 } 116 }
117
118 lastSelectedPrinterIndex = selectedPrinter;
110 } 119 }
111 120
112 /** 121 /**
113 * Updates the controls with printer capabilities information. 122 * Updates the controls with printer capabilities information.
114 * @param {Object} settingInfo printer setting information. 123 * @param {Object} settingInfo printer setting information.
115 */ 124 */
116 function updateWithPrinterCapabilities(settingInfo) { 125 function updateWithPrinterCapabilities(settingInfo) {
117 printerCapabilities = settingInfo; 126 printerCapabilities = settingInfo;
118 127
119 if (isPreviewStillLoading) 128 if (isPreviewStillLoading)
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 338 }
330 339
331 /** 340 /**
332 * Fill the printer list drop down. 341 * Fill the printer list drop down.
333 * Called from PrintPreviewHandler::SendPrinterList(). 342 * Called from PrintPreviewHandler::SendPrinterList().
334 * @param {Array} printers Array of printer names. 343 * @param {Array} printers Array of printer names.
335 * @param {number} defaultPrinterIndex The index of the default printer. 344 * @param {number} defaultPrinterIndex The index of the default printer.
336 */ 345 */
337 function setPrinters(printers, defaultPrinterIndex) { 346 function setPrinters(printers, defaultPrinterIndex) {
338 var printerList = $('printer-list'); 347 var printerList = $('printer-list');
339 for (var i = 0; i < printers.length; ++i) { 348 for (var i = 0; i < printers.length; ++i)
340 var option = document.createElement('option'); 349 addDestinationListOption(printers[i], i == defaultPrinterIndex);
341 option.textContent = printers[i];
342 printerList.add(option);
343 if (i == defaultPrinterIndex)
344 option.selected = true;
345 }
346 350
347 // Adding option for saving PDF to disk. 351 // Adding option for saving PDF to disk.
348 var option = document.createElement('option'); 352 addDestinationListOption(localStrings.getString('printToPDF'), false);
349 option.textContent = localStrings.getString('printToPDF'); 353
350 printerList.add(option); 354 // Add an option to manage printers.
355 addDestinationListOption(localStrings.getString('managePrinters'), false);
356
351 printerList.disabled = false; 357 printerList.disabled = false;
352 358
353 updateControlsWithSelectedPrinterCapabilities(); 359 updateControlsWithSelectedPrinterCapabilities();
354 360
355 // Once the printer list is populated, generate the initial preview. 361 // Once the printer list is populated, generate the initial preview.
356 requestPrintPreview(); 362 requestPrintPreview();
357 } 363 }
358 364
359 /** 365 /**
366 * Adds an option to the printer destination list.
367 * @param {String} optionText specifies the option text content.
368 * @param {boolean} is_default is true if the option needs to be selected.
369 */
370 function addDestinationListOption(optionText, is_default) {
371 var option = document.createElement('option');
372 option.textContent = optionText;
373 $('printer-list').add(option);
374 if (is_default)
375 option.selected = true;
376 }
377
378 /**
360 * Sets the color mode for the PDF plugin. 379 * Sets the color mode for the PDF plugin.
361 * Called from PrintPreviewHandler::ProcessColorSetting(). 380 * Called from PrintPreviewHandler::ProcessColorSetting().
362 * @param {boolean} color is true if the PDF plugin should display in color. 381 * @param {boolean} color is true if the PDF plugin should display in color.
363 */ 382 */
364 function setColor(color) { 383 function setColor(color) {
365 if (!hasCompatiblePDFPlugin) { 384 if (!hasCompatiblePDFPlugin) {
366 return; 385 return;
367 } 386 }
368 var pdfViewer = $('pdf-viewer'); 387 var pdfViewer = $('pdf-viewer');
369 if (!pdfViewer) { 388 if (!pdfViewer) {
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 * Returns true if the contents of the two arrays are equal. 748 * Returns true if the contents of the two arrays are equal.
730 */ 749 */
731 function areArraysEqual(array1, array2) { 750 function areArraysEqual(array1, array2) {
732 if (array1.length != array2.length) 751 if (array1.length != array2.length)
733 return false; 752 return false;
734 for (var i = 0; i < array1.length; i++) 753 for (var i = 0; i < array1.length; i++)
735 if(array1[i] != array2[i]) 754 if(array1[i] != array2[i])
736 return false; 755 return false;
737 return true; 756 return true;
738 } 757 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/printer_manager_dialog_win.cc ('k') | chrome/browser/ui/webui/print_preview_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698