Index: chrome/browser/ui/webui/print_preview_handler.cc |
diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc |
index a627293bfbd9fc445e075e805cb46a92d27a680f..bda5d97418871cb16377cea24716a4a3d419502a 100644 |
--- a/chrome/browser/ui/webui/print_preview_handler.cc |
+++ b/chrome/browser/ui/webui/print_preview_handler.cc |
@@ -151,18 +151,28 @@ namespace { |
const char kDisableColorOption[] = "disableColorOption"; |
const char kSetColorAsDefault[] = "setColorAsDefault"; |
const char kSetDuplexAsDefault[] = "setDuplexAsDefault"; |
+const char kPrinterColorModelForBlack[] = "printerColorModelForBlack"; |
const char kPrinterColorModelForColor[] = "printerColorModelForColor"; |
const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue"; |
#if defined(USE_CUPS) |
const char kColorDevice[] = "ColorDevice"; |
const char kColorModel[] = "ColorModel"; |
-const char kColorModelForColor[] = "Color"; |
-const char kCMYK[] = "CMYK"; |
+const char kColorMode[] = "ColorMode"; |
+const char kProcessColorModel[] = "ProcessColorModel"; |
+ |
const char kDuplex[] = "Duplex"; |
const char kDuplexNone[] = "None"; |
+ |
+// Foomatic ppd attributes and values. |
+const char kFoomaticId[] = "FoomaticIDs"; |
+const char kPrintoutMode[] = "PrintoutMode"; |
+const char kDraftGray[] = "Draft.Gray"; |
+const char kHighGray[] = "High.Gray"; |
#elif defined(OS_WIN) |
const char kPskColor[] = "psk:Color"; |
+const char kPskGray[] = "psk:Grayscale"; |
+const char kPskMonochrome[] = "psk:Monochrome"; |
const char kPskDuplexFeature[] = "psk:JobDuplexAllDocumentsContiguously"; |
const char kPskTwoSided[] = "psk:TwoSided"; |
#endif |
@@ -248,6 +258,15 @@ int GetPageCountFromSettingsDictionary(const DictionaryValue& settings) { |
return count; |
} |
+// Returns true if |color_mode| is a valid color model. |
+bool isColorModeSelected(int color_mode) { |
+ return (color_mode != printing::GRAY && |
+ color_mode != printing::BLACK && |
+ color_mode != printing::PRINTOUTMODE_NORMAL_GRAY && |
+ color_mode != printing::COLORMODE_MONOCHROME && |
+ color_mode != printing::PROCESSCOLORMODEL_GREYSCALE); |
+} |
+ |
// Track the popularity of print settings and report the stats. |
void ReportPrintSettingsStats(const DictionaryValue& settings) { |
bool landscape; |
@@ -264,8 +283,8 @@ void ReportPrintSettingsStats(const DictionaryValue& settings) { |
int color_mode; |
if (settings.GetInteger(printing::kSettingColor, &color_mode)) { |
- ReportPrintSettingHistogram(color_mode == printing::GRAY ? BLACK_AND_WHITE : |
- COLOR); |
+ ReportPrintSettingHistogram( |
+ isColorModeSelected(color_mode) ? COLOR : BLACK_AND_WHITE); |
} |
} |
@@ -373,9 +392,12 @@ class PrintSystemTaskProxy |
void GetPrinterCapabilities(const std::string& printer_name) { |
VLOG(1) << "Get printer capabilities start for " << printer_name; |
printing::PrinterCapsAndDefaults printer_info; |
- bool supports_color = true; |
+ |
+ bool set_color_as_default = false; |
+ bool disable_color_options = false; |
bool set_duplex_as_default = false; |
- int printer_color_space = printing::GRAY; |
+ int printer_color_space_for_color = printing::COLOR; |
vandebo (ex-Chrome)
2011/10/07 18:23:30
Move both of these down to line 448 - just before
kmadhusu
2011/10/10 23:34:26
This is also used by windows code.
|
+ int printer_color_space_for_black = printing::GRAY; |
int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE; |
if (!print_backend_->GetPrinterCapsAndDefaults(printer_name, |
&printer_info)) { |
@@ -401,9 +423,11 @@ class PrintSystemTaskProxy |
#if !defined(OS_MACOSX) |
printing_internal::mark_lpoptions(printer_name, &ppd); |
#endif |
+ bool is_color_device = false; |
ppd_attr_t* attr = ppdFindAttr(ppd, kColorDevice, NULL); |
if (attr && attr->value) |
- supports_color = ppd->color_device; |
+ is_color_device = ppd->color_device; |
+ disable_color_options = !is_color_device; |
ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex); |
if (duplex_choice) { |
@@ -421,14 +445,154 @@ class PrintSystemTaskProxy |
} |
} |
- if (supports_color) { |
+ set_color_as_default = is_color_device; |
+ if (is_color_device) { |
// Identify the color space (COLOR/CMYK) for this printer. |
ppd_option_t* color_model = ppdFindOption(ppd, kColorModel); |
if (color_model) { |
vandebo (ex-Chrome)
2011/10/07 18:23:30
I would pull each of these blocks into a method...
kmadhusu
2011/10/10 23:34:26
Done.
|
- if (ppdFindChoice(color_model, kColorModelForColor)) |
- printer_color_space = printing::COLOR; |
- else if (ppdFindChoice(color_model, kCMYK)) |
- printer_color_space = printing::CMYK; |
+ if (ppdFindChoice(color_model, printing::kBlack)) |
vandebo (ex-Chrome)
2011/10/07 18:23:30
Does this need to happen even if it's not a color
kmadhusu
2011/10/10 23:34:26
No. I have seen Black and Gray only as ColorModel
|
+ printer_color_space_for_black = printing::BLACK; |
+ else if (!ppdFindChoice(color_model, printing::kGray)) { |
+ disable_color_options = true; |
+ } |
+ |
+ if (ppdFindChoice(color_model, printing::kColor)) |
+ printer_color_space_for_color = printing::COLOR; |
+ else if (ppdFindChoice(color_model, printing::kCMYK)) |
+ printer_color_space_for_color = printing::CMYK; |
+ else if (ppdFindChoice(color_model, printing::kRGB)) |
+ printer_color_space_for_color = printing::RGB; |
+ else if (ppdFindChoice(color_model, printing::kRGBA)) |
+ printer_color_space_for_color = printing::RGBA; |
+ else if (ppdFindChoice(color_model, printing::kRGB16)) |
+ printer_color_space_for_color = printing::RGB16; |
+ else if (ppdFindChoice(color_model, printing::kCMY)) |
+ printer_color_space_for_color = printing::CMY; |
+ else if (ppdFindChoice(color_model, printing::kKCMY)) |
+ printer_color_space_for_color = printing::KCMY; |
+ else if (ppdFindChoice(color_model, printing::kCMY_K)) |
+ printer_color_space_for_color = printing::CMY_K; |
+ } else { |
+ disable_color_options = true; |
+ } |
+ } |
+ |
+ // If this is a foomatic ppd, color values are present in |
+ // PrintoutMode attribute. |
+ ppd_attr_t* foomatic_id_attr = ppdFindAttr(ppd, kFoomaticId, NULL); |
+ if (foomatic_id_attr && foomatic_id_attr->value) { |
+ ppd_option_t* printout_mode = ppdFindOption(ppd, kPrintoutMode); |
+ if (printout_mode) { |
+ disable_color_options = false; |
+ printer_color_space_for_color = printing::PRINTOUTMODE_NORMAL; |
+ printer_color_space_for_black = printing::PRINTOUTMODE_NORMAL; |
+ |
+ // Check to see if NORMAL_GRAY value is supported by PrintoutMode. |
+ // If NORMAL_GRAY is not supported, NORMAL value is used to |
+ // represent grayscale. If NORMAL_GRAY is supported, NORMAL is used to |
+ // represent color. |
+ if (ppdFindChoice(printout_mode, printing::kNormalGray)) |
+ printer_color_space_for_black = printing::PRINTOUTMODE_NORMAL_GRAY; |
+ |
+ // Get the default marked choice to identify the default color setting |
+ // value. |
+ ppd_choice_t* printout_mode_choice = |
+ ppdFindMarkedChoice(ppd, kPrintoutMode); |
+ if (!printout_mode_choice) { |
+ printout_mode_choice = ppdFindChoice(printout_mode, |
+ printout_mode->defchoice); |
+ } |
+ |
+ if (printout_mode_choice) { |
+ if ((base::strcasecmp(printout_mode_choice->choice, |
+ printing::kNormalGray) == 0) || |
+ (base::strcasecmp(printout_mode_choice->choice, |
+ kHighGray) == 0) || |
+ (base::strcasecmp(printout_mode_choice->choice, |
+ kDraftGray) == 0)) { |
+ printer_color_space_for_black = |
+ printing::PRINTOUTMODE_NORMAL_GRAY; |
+ set_color_as_default = false; |
+ } |
+ } |
+ disable_color_options = printer_color_space_for_black == |
+ printing::PRINTOUTMODE_NORMAL; |
+ } |
+ } |
+ |
+ // Samsung printers use "ColorMode" attribute in their ppds. |
+ ppd_option_t* color_mode_option = ppdFindOption(ppd, kColorMode); |
+ if (color_mode_option) { |
+ disable_color_options = false; |
+ printer_color_space_for_color = printing::COLORMODE_COLOR; |
+ printer_color_space_for_black = printing::COLORMODE_MONOCHROME; |
+ if (!(ppdFindChoice(color_mode_option, printing::kColor) && |
+ ppdFindChoice(color_mode_option, printing::kMonochrome))) { |
+ disable_color_options = true; |
+ } |
+ |
+ ppd_choice_t* mode_choice = ppdFindMarkedChoice(ppd, kColorMode); |
+ if (!mode_choice) { |
+ mode_choice = ppdFindChoice(color_mode_option, |
+ color_mode_option->defchoice); |
+ } |
+ |
+ if (mode_choice) { |
+ set_color_as_default = |
+ (base::strcasecmp(mode_choice->choice, printing::kColor) == 0); |
+ } |
+ } |
+ |
+ // HP printers use "Color/Color Model" attribute in their ppds. |
+ color_mode_option = ppdFindOption(ppd, printing::kColor); |
+ if (color_mode_option) { |
+ disable_color_options = false; |
+ printer_color_space_for_color = printing::HP_COLOR_COLOR; |
+ printer_color_space_for_black = printing::HP_COLOR_BLACK; |
+ if (!(ppdFindChoice(color_mode_option, printing::kColor) && |
+ ppdFindChoice(color_mode_option, printing::kBlack))) { |
+ disable_color_options = true; |
+ } |
+ |
+ ppd_choice_t* mode_choice = ppdFindMarkedChoice(ppd, kColorMode); |
+ if (!mode_choice) { |
+ mode_choice = ppdFindChoice(color_mode_option, |
+ color_mode_option->defchoice); |
+ } |
+ |
+ if (mode_choice) { |
+ set_color_as_default = |
+ (base::strcasecmp(mode_choice->choice, printing::kColor) == 0); |
+ } |
+ } |
+ |
+ // Canon printers use "ProcessColorModel" attribute in their ppds. |
+ color_mode_option = ppdFindOption(ppd, kProcessColorModel); |
+ if (color_mode_option) { |
+ disable_color_options = false; |
+ if (ppdFindChoice(color_mode_option, printing::kRGB)) |
+ printer_color_space_for_color = printing::PROCESSCOLORMODEL_RGB; |
+ else if (ppdFindChoice(color_mode_option, printing::kCMYK)) |
+ printer_color_space_for_color = printing::PROCESSCOLORMODEL_CMYK; |
+ else |
+ disable_color_options = true; |
+ |
+ if (ppdFindChoice(color_mode_option, printing::kGreyscale)) |
+ printer_color_space_for_black = printing::PROCESSCOLORMODEL_GREYSCALE; |
+ else |
+ disable_color_options = true; |
+ |
+ ppd_choice_t* mode_choice = ppdFindMarkedChoice(ppd, |
+ kProcessColorModel); |
+ if (!mode_choice) { |
+ mode_choice = ppdFindChoice(color_mode_option, |
+ color_mode_option->defchoice); |
+ } |
+ |
+ if (mode_choice) { |
+ set_color_as_default = |
+ (base::strcasecmp(mode_choice->choice, |
+ printing::kGreyscale) != 0); |
} |
} |
ppdClose(ppd); |
@@ -439,10 +603,16 @@ class PrintSystemTaskProxy |
// Therefore we don't need to parse the whole XML file, we just need to |
// search the string. The spec can be found at: |
// http://msdn.microsoft.com/en-us/windows/hardware/gg463431. |
+ bool supports_color = false; |
+ bool supports_grayscale = true; |
supports_color = (printer_info.printer_capabilities.find(kPskColor) != |
std::string::npos); |
- if (supports_color) |
- printer_color_space = printing::COLOR; |
+ |
+ supports_grayscale = |
+ (printer_info.printer_capabilities.find(kPskGray) != |
+ std::string::npos) || |
+ (printer_info.printer_capabilities.find(kPskMonochrome) != |
+ std::string::npos); |
set_duplex_as_default = |
(printer_info.printer_defaults.find(kPskDuplexFeature) != |
@@ -459,20 +629,24 @@ class PrintSystemTaskProxy |
default_duplex_setting_value = printing::SIMPLEX; |
} |
} |
+ disable_color_options = !supports_color || !supports_grayscale; |
vandebo (ex-Chrome)
2011/10/07 18:23:30
Can you use this logic above?
kmadhusu
2011/10/10 23:34:26
Done.
|
+ set_color_as_default = supports_color; |
#else |
NOTIMPLEMENTED(); |
#endif |
- |
DictionaryValue settings_info; |
- settings_info.SetBoolean(kDisableColorOption, !supports_color); |
- if (!supports_color) { |
- settings_info.SetBoolean(kSetColorAsDefault, false); |
+ settings_info.SetBoolean(kDisableColorOption, disable_color_options); |
+ if (disable_color_options) { |
+ settings_info.SetBoolean(kSetColorAsDefault, set_color_as_default); |
} else { |
- settings_info.SetBoolean(kSetColorAsDefault, |
- PrintPreviewHandler::last_used_color_setting_); |
+ settings_info.SetBoolean(kSetColorAsDefault, |
+ PrintPreviewHandler::last_used_color_setting_); |
} |
settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default); |
- settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space); |
+ settings_info.SetInteger(kPrinterColorModelForColor, |
+ printer_color_space_for_color); |
+ settings_info.SetInteger(kPrinterColorModelForBlack, |
+ printer_color_space_for_black); |
settings_info.SetInteger(kPrinterDefaultDuplexValue, |
default_duplex_setting_value); |
BrowserThread::PostTask( |
@@ -722,7 +896,7 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
int color_mode; |
if (!settings->GetInteger(printing::kSettingColor, &color_mode)) |
color_mode = printing::GRAY; |
- last_used_color_setting_ = (color_mode != printing::GRAY); |
+ last_used_color_setting_ = isColorModeSelected(color_mode); |
bool print_to_pdf = false; |
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |