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

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

Issue 7042034: Print Preview: Remembering last used printer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/ui/webui/print_preview_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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
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 var defaultOrLastUsedPrinterName = '';
34
33 /** 35 /**
34 * Window onload handler, sets up the page and starts print preview by getting 36 * Window onload handler, sets up the page and starts print preview by getting
35 * the printer list. 37 * the printer list.
36 */ 38 */
37 function onLoad() { 39 function onLoad() {
38 $('system-dialog-link').addEventListener('click', showSystemDialog); 40 $('system-dialog-link').addEventListener('click', showSystemDialog);
39 $('cancel-button').addEventListener('click', handleCancelButtonClick); 41 $('cancel-button').addEventListener('click', handleCancelButtonClick);
40 42
41 if (!checkCompatiblePluginExists()) { 43 if (!checkCompatiblePluginExists()) {
42 displayErrorMessage(localStrings.getString('noPlugin'), false); 44 displayErrorMessage(localStrings.getString('noPlugin'), false);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 } 350 }
349 351
350 /** 352 /**
351 * Set the default printer. If there is one, generate a print preview. 353 * Set the default printer. If there is one, generate a print preview.
352 * @param {string} printer Name of the default printer. Empty if none. 354 * @param {string} printer Name of the default printer. Empty if none.
353 */ 355 */
354 function setDefaultPrinter(printer) { 356 function setDefaultPrinter(printer) {
355 // Add a placeholder value so the printer list looks valid. 357 // Add a placeholder value so the printer list looks valid.
356 addDestinationListOption('', '', true, true); 358 addDestinationListOption('', '', true, true);
357 if (printer) { 359 if (printer) {
358 $('printer-list')[0].value = printer; 360 defaultOrLastUsedPrinterName = printer;
361 $('printer-list')[0].value = defaultOrLastUsedPrinterName;
359 updateControlsWithSelectedPrinterCapabilities(); 362 updateControlsWithSelectedPrinterCapabilities();
360 } 363 }
361 chrome.send('getPrinters'); 364 chrome.send('getPrinters');
362 } 365 }
363 366
364 /** 367 /**
365 * Fill the printer list drop down. 368 * Fill the printer list drop down.
366 * Called from PrintPreviewHandler::SendPrinterList(). 369 * Called from PrintPreviewHandler::SendPrinterList().
367 * @param {Array} printers Array of printer info objects. 370 * @param {Array} printers Array of printer info objects.
368 * @param {number} defaultPrinterIndex The index of the default printer.
369 */ 371 */
370 function setPrinters(printers, defaultPrinterIndex) { 372 function setPrinters(printers) {
dpapad 2011/06/07 01:07:44 Since we already know the default printer, there i
371 var printerList = $('printer-list'); 373 var printerList = $('printer-list');
372 // If there exists a dummy printer value, then setDefaultPrinter() already 374 // If there exists a dummy printer value, then setDefaultPrinter() already
373 // requested a preview, so no need to do it again. 375 // requested a preview, so no need to do it again.
374 var needPreview = (printerList[0].value == ''); 376 var needPreview = (printerList[0].value == '');
375 for (var i = 0; i < printers.length; ++i) { 377 for (var i = 0; i < printers.length; ++i) {
376 // Check if we are looking at the default printer. 378 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, 379 addDestinationListOption(printers[i].printerName, printers[i].deviceName,
384 i == defaultPrinterIndex, false); 380 isDefault, false);
385 } 381 }
386 382
387 // Remove the dummy printer added in setDefaultPrinter(). 383 // Remove the dummy printer added in setDefaultPrinter().
388 printerList.remove(0); 384 printerList.remove(0);
389 385
390 if (printers.length != 0) 386 if (printers.length != 0)
391 addDestinationListOption('', '', false, true); 387 addDestinationListOption('', '', false, true);
392 388
393 // Adding option for saving PDF to disk. 389 // Adding option for saving PDF to disk.
390 console.log(defaultOrLastUsedPrinterName == PRINT_TO_PDF);
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
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 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/print_preview_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698