diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-04 23:37:47 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-04 23:37:47 +0000 |
commit | 19f09a635b8972b4831ba92d228c45e6438d6553 (patch) | |
tree | bd823fd8ec0d55d727d2a0bf4ae8c25ad20a69df | |
parent | 92c01741c76c821f2fc9434827dfd9455a971a30 (diff) | |
download | chromium_src-19f09a635b8972b4831ba92d228c45e6438d6553.zip chromium_src-19f09a635b8972b4831ba92d228c45e6438d6553.tar.gz chromium_src-19f09a635b8972b4831ba92d228c45e6438d6553.tar.bz2 |
Cleanup: Make the PrintingContext::UpdatePrintSettings code more consistent across platfroms.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6932021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@84154 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/printing/print_dialog_gtk.cc | 84 | ||||
-rw-r--r-- | printing/printing_context_mac.mm | 15 | ||||
-rw-r--r-- | printing/printing_context_win.cc | 34 |
3 files changed, 69 insertions, 64 deletions
diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc index 596ec9d..68354e4 100644 --- a/chrome/browser/printing/print_dialog_gtk.cc +++ b/chrome/browser/printing/print_dialog_gtk.cc @@ -160,60 +160,56 @@ void PrintDialogGtk::UseDefaultSettings() { bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings, const printing::PageRanges& ranges) { + bool collate; + bool color; + bool landscape; + bool print_to_pdf; + int copies; + int duplex_mode; std::string printer_name; - settings.GetString(printing::kSettingPrinterName, &printer_name); - scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); - printer_ = printer_list->GetPrinterWithName(printer_name.c_str()); - if (printer_) { - g_object_ref(printer_); - gtk_print_settings_set_printer(gtk_settings_, - gtk_printer_get_name(printer_)); + if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) || + !settings.GetBoolean(printing::kSettingCollate, &collate) || + !settings.GetBoolean(printing::kSettingColor, &color) || + !settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) || + !settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) || + !settings.GetInteger(printing::kSettingCopies, &copies) || + !settings.GetString(printing::kSettingPrinterName, &printer_name)) { + return false; } - bool landscape; - if (!settings.GetBoolean(printing::kSettingLandscape, &landscape)) - return false; + if (!print_to_pdf) { + scoped_ptr<GtkPrinterList> printer_list(new GtkPrinterList); + printer_ = printer_list->GetPrinterWithName(printer_name.c_str()); + if (printer_) { + g_object_ref(printer_); + gtk_print_settings_set_printer(gtk_settings_, + gtk_printer_get_name(printer_)); + } + gtk_print_settings_set_n_copies(gtk_settings_, copies); + gtk_print_settings_set_collate(gtk_settings_, collate); + gtk_print_settings_set(gtk_settings_, kCUPSColorModel, + color ? kColor : kGrayscale); + const char* cups_duplex_mode; + switch (duplex_mode) { + case printing::LONG_EDGE: + cups_duplex_mode = kDuplexNoTumble; + break; + case printing::SHORT_EDGE: + cups_duplex_mode = kDuplexTumble; + break; + default: + cups_duplex_mode = kDuplexNone; + break; + } + gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode); + } gtk_print_settings_set_orientation( gtk_settings_, landscape ? GTK_PAGE_ORIENTATION_LANDSCAPE : GTK_PAGE_ORIENTATION_PORTRAIT); - int copies; - if (!settings.GetInteger(printing::kSettingCopies, &copies)) - return false; - gtk_print_settings_set_n_copies(gtk_settings_, copies); - - bool collate; - if (!settings.GetBoolean(printing::kSettingCollate, &collate)) - return false; - gtk_print_settings_set_collate(gtk_settings_, collate); - - bool is_color; - if (!settings.GetBoolean(printing::kSettingColor, &is_color)) - return false; - - gtk_print_settings_set(gtk_settings_, kCUPSColorModel, - is_color ? kColor : kGrayscale); - int mode; - if (!settings.GetInteger(printing::kSettingDuplexMode, &mode)) - return false; - - const char* cups_duplex_mode; - switch (mode) { - case printing::LONG_EDGE: - cups_duplex_mode = kDuplexNoTumble; - break; - case printing::SHORT_EDGE: - cups_duplex_mode = kDuplexTumble; - break; - default: - cups_duplex_mode = kDuplexNone; - break; - } - gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode); - InitPrintSettings(ranges); return true; } diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm index 9333967..416a968 100644 --- a/printing/printing_context_mac.mm +++ b/printing/printing_context_mac.mm @@ -91,18 +91,21 @@ PrintingContext::Result PrintingContextMac::UpdatePrintSettings( ResetSettings(); print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]); + bool collate; + bool color; bool landscape; - std::string device_name; + bool print_to_pdf; int copies; - bool collate; int duplex_mode; - bool color; + std::string device_name; + if (!job_settings.GetBoolean(kSettingLandscape, &landscape) || - !job_settings.GetString(kSettingDeviceName, &device_name) || - !job_settings.GetInteger(kSettingCopies, &copies) || !job_settings.GetBoolean(kSettingCollate, &collate) || + !job_settings.GetBoolean(kSettingColor, &color) || + !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || - !job_settings.GetBoolean(kSettingColor, &color)) { + !job_settings.GetInteger(kSettingCopies, &copies) || + !job_settings.GetString(kSettingDeviceName, &device_name)) { return OnError(); } diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc index 7a64df6..eb7cc32 100644 --- a/printing/printing_context_win.cc +++ b/printing/printing_context_win.cc @@ -6,6 +6,8 @@ #include <winspool.h> +#include <algorithm> + #include "base/i18n/file_util_icu.h" #include "base/i18n/time_formatting.h" #include "base/message_loop.h" @@ -305,22 +307,27 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings( const PageRanges& ranges) { DCHECK(!in_print_job_); - bool is_landscape, is_collate, is_color, is_printToPDF; + bool collate; + bool color; + bool landscape; + bool print_to_pdf; + int copies; + int duplex_mode; string16 printer_name; - int copies, duplex_mode; - if (!job_settings.GetBoolean(kSettingLandscape, &is_landscape) || - !job_settings.GetString(kSettingPrinterName, &printer_name) || - !job_settings.GetInteger(kSettingCopies, &copies) || - !job_settings.GetBoolean(kSettingCollate, &is_collate) || + + if (!job_settings.GetBoolean(kSettingLandscape, &landscape) || + !job_settings.GetBoolean(kSettingCollate, &collate) || + !job_settings.GetBoolean(kSettingColor, &color) || + !job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) || !job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) || - !job_settings.GetBoolean(kSettingColor, &is_color) || - !job_settings.GetBoolean(kSettingPrintToPDF, &is_printToPDF)) { + !job_settings.GetInteger(kSettingCopies, &copies) || + !job_settings.GetString(kSettingPrinterName, &printer_name)) { return OnError(); } - if (is_printToPDF) { + if (print_to_pdf) { // Pseudo printer: handle orientation and ranges only. - settings_.SetOrientation(is_landscape); + settings_.SetOrientation(landscape); settings_.ranges = ranges; return OK; } @@ -356,10 +363,10 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings( return OnError(); } - dev_mode->dmColor = is_color ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME; + dev_mode->dmColor = color ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME; dev_mode->dmCopies = std::max(copies, 1); if (dev_mode->dmCopies > 1) // do not change collate unless multiple copies - dev_mode->dmCollate = is_collate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE; + dev_mode->dmCollate = collate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE; switch (duplex_mode) { case LONG_EDGE: dev_mode->dmDuplex = DMDUP_VERTICAL; @@ -371,8 +378,7 @@ PrintingContext::Result PrintingContextWin::UpdatePrintSettings( dev_mode->dmDuplex = DMDUP_SIMPLEX; break; } - dev_mode->dmOrientation = is_landscape ? DMORIENT_LANDSCAPE : - DMORIENT_PORTRAIT; + dev_mode->dmOrientation = landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT; // Update data using DocumentProperties. if (DocumentProperties(NULL, printer, printer_name_wide, dev_mode, dev_mode, |