summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/printing/print_dialog_gtk.cc22
-rw-r--r--chrome/browser/resources/print_preview/color_settings.js16
-rw-r--r--chrome/browser/resources/print_preview/print_preview.js5
-rw-r--r--chrome/browser/ui/webui/print_preview_handler.cc33
-rw-r--r--chrome/renderer/mock_render_thread.cc2
-rw-r--r--chrome/renderer/print_web_view_helper_browsertest.cc2
-rw-r--r--printing/print_job_constants.h7
-rw-r--r--printing/printing_context_mac.h2
-rw-r--r--printing/printing_context_mac.mm15
-rw-r--r--printing/printing_context_win.cc10
10 files changed, 89 insertions, 25 deletions
diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc
index 3e803ed..4c3bb82 100644
--- a/chrome/browser/printing/print_dialog_gtk.cc
+++ b/chrome/browser/printing/print_dialog_gtk.cc
@@ -29,6 +29,7 @@ using printing::PrintSettings;
namespace {
// CUPS ColorModel attribute and values.
+const char kCMYK[] = "CMYK";
const char kCUPSColorModel[] = "cups-ColorModel";
const char kColor[] = "Color";
const char kGrayscale[] = "Grayscale";
@@ -157,7 +158,7 @@ void PrintDialogGtk::UseDefaultSettings() {
bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings,
const printing::PageRanges& ranges) {
bool collate;
- bool color;
+ int color;
bool landscape;
bool print_to_pdf;
int copies;
@@ -166,7 +167,7 @@ bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings,
if (!settings.GetBoolean(printing::kSettingLandscape, &landscape) ||
!settings.GetBoolean(printing::kSettingCollate, &collate) ||
- !settings.GetBoolean(printing::kSettingColor, &color) ||
+ !settings.GetInteger(printing::kSettingColor, &color) ||
!settings.GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf) ||
!settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode) ||
!settings.GetInteger(printing::kSettingCopies, &copies) ||
@@ -184,8 +185,21 @@ bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings,
}
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* color_mode;
+ switch (color) {
+ case printing::COLOR:
+ color_mode = kColor;
+ break;
+ case printing::CMYK:
+ color_mode = kCMYK;
+ break;
+ default:
+ color_mode = kGrayscale;
+ break;
+ }
+ gtk_print_settings_set(gtk_settings_, kCUPSColorModel, color_mode);
+
const char* cups_duplex_mode;
switch (duplex_mode) {
case printing::LONG_EDGE:
diff --git a/chrome/browser/resources/print_preview/color_settings.js b/chrome/browser/resources/print_preview/color_settings.js
index c0547e9..dc02ab0 100644
--- a/chrome/browser/resources/print_preview/color_settings.js
+++ b/chrome/browser/resources/print_preview/color_settings.js
@@ -14,6 +14,10 @@ cr.define('print_preview', function() {
this.colorOption_ = $('color-option');
this.colorRadioButton_ = $('color');
this.bwRadioButton_ = $('bw');
+ this.GRAY = 1;
+ this.COLOR = 2;
+ this.CMYK = 3; // cmyk - Cyan, magenta, yellow, black
+ this.printerColorModelForColor_ = this.COLOR;
}
cr.addSingletonGetter(ColorSettings);
@@ -36,11 +40,13 @@ cr.define('print_preview', function() {
},
/**
- * Checks whether |this.colorRadioButton_| is checked.
- * @return {boolean} true if |this.colorRadioButton_| is checked.
+ * Returns the color mode for print preview.
+ * @return {Number} Returns the printer color space
*/
- isColor: function() {
- return this.colorRadioButton_.checked;
+ get colorMode() {
+ if (this.bwRadioButton_.checked)
+ return this.GRAY;
+ return this.printerColorModelForColor_;
},
/**
@@ -71,6 +77,8 @@ cr.define('print_preview', function() {
this.colorOption_.setAttribute('aria-hidden', disableColorOption);
var setColorAsDefault = e.printerCapabilities.setColorAsDefault;
+ this.printerColorModelForColor_ =
+ e.printerCapabilities.printerColorModelForColor;
this.colorRadioButton_.checked = setColorAsDefault;
this.bwRadioButton_.checked = !setColorAsDefault;
setColor(this.colorRadioButton_.checked);
diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js
index 1ebbaae..f1ce284e 100644
--- a/chrome/browser/resources/print_preview/print_preview.js
+++ b/chrome/browser/resources/print_preview/print_preview.js
@@ -237,6 +237,7 @@ function updateControlsWithSelectedPrinterCapabilities() {
'disableColorOption': true,
'setColorAsDefault': true,
'setDuplexAsDefault': false,
+ 'printerColorModelForColor': colorSettings.COLOR,
'disableCopiesOption': true});
} else {
// This message will call back to 'updateWithPrinterCapabilities'
@@ -344,7 +345,7 @@ function getSettings() {
'copies': copiesSettings.numberOfCopies,
'collate': copiesSettings.isCollated(),
'landscape': layoutSettings.isLandscape(),
- 'color': colorSettings.isColor(),
+ 'color': colorSettings.colorMode,
'printToPDF': printToPDF,
'isFirstRequest' : false,
'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(),
@@ -1024,7 +1025,7 @@ function createPDFPlugin(srcDataIndex) {
pdfViewer.goToPage('0');
pdfViewer.resetPrintPreviewUrl(srcURL);
pdfViewer.reload();
- pdfViewer.grayscale(!colorSettings.isColor());
+ pdfViewer.grayscale(colorSettings.colorMode == colorSettings.GRAY);
return;
}
diff --git a/chrome/browser/ui/webui/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview_handler.cc
index b9f0478..42597a5 100644
--- a/chrome/browser/ui/webui/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview_handler.cc
@@ -58,9 +58,13 @@ namespace {
const char kDisableColorOption[] = "disableColorOption";
const char kSetColorAsDefault[] = "setColorAsDefault";
const char kSetDuplexAsDefault[] = "setDuplexAsDefault";
+const char kPrinterColorModelForColor[] = "printerColorModelForColor";
#if defined(USE_CUPS)
const char kColorDevice[] = "ColorDevice";
+const char kColorModel[] = "ColorModel";
+const char kColorModelForColor[] = "Color";
+const char kCMYK[] = "CMYK";
const char kDuplex[] = "Duplex";
const char kDuplexNone[] = "None";
#elif defined(OS_WIN)
@@ -163,9 +167,11 @@ void ReportPrintSettingsStats(const DictionaryValue& settings) {
if (settings.GetInteger(printing::kSettingDuplexMode, &duplex_mode))
ReportPrintSettingHistogram(duplex_mode ? DUPLEX : SIMPLEX);
- bool is_color;
- if (settings.GetBoolean(printing::kSettingColor, &is_color))
- ReportPrintSettingHistogram(is_color ? COLOR : BLACK_AND_WHITE);
+ int color_mode;
+ if (settings.GetInteger(printing::kSettingColor, &color_mode)) {
+ ReportPrintSettingHistogram(color_mode == printing::GRAY ? BLACK_AND_WHITE :
+ COLOR);
+ }
}
printing::BackgroundPrintingManager* GetBackgroundPrintingManager() {
@@ -274,6 +280,7 @@ class PrintSystemTaskProxy
printing::PrinterCapsAndDefaults printer_info;
bool supports_color = true;
bool set_duplex_as_default = false;
+ int printer_color_space = printing::GRAY;
if (!print_backend_->GetPrinterCapsAndDefaults(printer_name,
&printer_info)) {
return;
@@ -309,6 +316,17 @@ class PrintSystemTaskProxy
if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0)
set_duplex_as_default = true;
+ if (supports_color) {
+ // Identify the color space (COLOR/CMYK) for this printer.
+ ppd_option_t* color_model = ppdFindOption(ppd, kColorModel);
+ if (color_model != NULL) {
+ if (ppdFindChoice(color_model, kColorModelForColor))
+ printer_color_space = printing::COLOR;
+ else if (ppdFindChoice(color_model, kCMYK))
+ printer_color_space = printing::CMYK;
+ }
+ }
+
ppdClose(ppd);
}
file_util::Delete(ppd_file_path, false);
@@ -319,6 +337,9 @@ class PrintSystemTaskProxy
// http://msdn.microsoft.com/en-us/windows/hardware/gg463431.
supports_color = (printer_info.printer_capabilities.find(kPskColor) !=
std::string::npos);
+ if (supports_color)
+ printer_color_space = printing::COLOR;
+
set_duplex_as_default =
(printer_info.printer_defaults.find(kPskDuplexFeature) !=
std::string::npos) &&
@@ -337,6 +358,7 @@ class PrintSystemTaskProxy
PrintPreviewHandler::last_used_color_setting_);
}
settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default);
+ settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this,
@@ -568,7 +590,10 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
return;
// Storing last used color setting.
- settings->GetBoolean(printing::kSettingColor, &last_used_color_setting_);
+ int color_mode;
+ if (!settings->GetInteger(printing::kSettingColor, &color_mode))
+ color_mode = printing::GRAY;
+ last_used_color_setting_ = (color_mode != printing::GRAY);
bool print_to_pdf = false;
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);
diff --git a/chrome/renderer/mock_render_thread.cc b/chrome/renderer/mock_render_thread.cc
index c6fc519..0e074d6 100644
--- a/chrome/renderer/mock_render_thread.cc
+++ b/chrome/renderer/mock_render_thread.cc
@@ -241,7 +241,7 @@ void MockRenderThread::OnUpdatePrintSettings(
std::string dummy_string;
if (!job_settings.GetBoolean(printing::kSettingLandscape, NULL) ||
!job_settings.GetBoolean(printing::kSettingCollate, NULL) ||
- !job_settings.GetBoolean(printing::kSettingColor, NULL) ||
+ !job_settings.GetInteger(printing::kSettingColor, NULL) ||
!job_settings.GetBoolean(printing::kSettingPrintToPDF, NULL) ||
!job_settings.GetBoolean(printing::kIsFirstRequest, NULL) ||
!job_settings.GetString(printing::kSettingDeviceName, &dummy_string) ||
diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc
index 2566e16..de9d016 100644
--- a/chrome/renderer/print_web_view_helper_browsertest.cc
+++ b/chrome/renderer/print_web_view_helper_browsertest.cc
@@ -40,7 +40,7 @@ const char kPrintPreviewHTML[] =
void CreatePrintSettingsDictionary(DictionaryValue* dict) {
dict->SetBoolean(printing::kSettingLandscape, false);
dict->SetBoolean(printing::kSettingCollate, false);
- dict->SetBoolean(printing::kSettingColor, false);
+ dict->SetInteger(printing::kSettingColor, printing::GRAY);
dict->SetBoolean(printing::kSettingPrintToPDF, true);
dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX);
dict->SetInteger(printing::kSettingCopies, 1);
diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h
index 7240340..99b2892 100644
--- a/printing/print_job_constants.h
+++ b/printing/print_job_constants.h
@@ -67,6 +67,13 @@ enum VerticalHeaderFooterPosition {
BOTTOM
};
+// Print job color mode values.
+enum ColorMode {
+ GRAY = 1,
+ COLOR,
+ CMYK,
+};
+
} // namespace printing
#endif // PRINTING_PRINT_JOB_CONSTANTS_H_
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h
index e7e6342..2fd0c18 100644
--- a/printing/printing_context_mac.h
+++ b/printing/printing_context_mac.h
@@ -75,7 +75,7 @@ class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
// Sets output color mode in PMPrintSettings.
// Returns true if color mode is set.
- bool SetOutputIsColor(bool color);
+ bool SetOutputColor(int color_mode);
// The native print info object.
scoped_nsobject<NSPrintInfo> print_info_;
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index f839802..8ba4db8 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -17,6 +17,7 @@
static const CFStringRef kColorModel = CFSTR("ColorModel");
static const CFStringRef kGrayColor = CFSTR("Gray");
+static const CFStringRef kCMYK = CFSTR("CMYK");
namespace printing {
@@ -107,7 +108,7 @@ PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
print_info_.reset([[NSPrintInfo sharedPrintInfo] copy]);
bool collate;
- bool color;
+ int color;
bool landscape;
bool print_to_pdf;
int copies;
@@ -116,7 +117,7 @@ PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
if (!job_settings.GetBoolean(kSettingLandscape, &landscape) ||
!job_settings.GetBoolean(kSettingCollate, &collate) ||
- !job_settings.GetBoolean(kSettingColor, &color) ||
+ !job_settings.GetInteger(kSettingColor, &color) ||
!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) ||
!job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) ||
!job_settings.GetInteger(kSettingCopies, &copies) ||
@@ -141,7 +142,7 @@ PrintingContext::Result PrintingContextMac::UpdatePrinterSettings(
return OnError();
}
- if (!SetOutputIsColor(color))
+ if (!SetOutputColor(color))
return OnError();
}
@@ -245,10 +246,14 @@ bool PrintingContextMac::SetDuplexModeInPrintSettings(DuplexMode mode) {
return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr;
}
-bool PrintingContextMac::SetOutputIsColor(bool color) {
+bool PrintingContextMac::SetOutputColor(int color_mode) {
PMPrintSettings pmPrintSettings =
static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]);
- CFStringRef output_color = color ? NULL : kGrayColor;
+ CFStringRef output_color = NULL;
+ if (color_mode == printing::GRAY)
+ output_color = kGrayColor;
+ else if (color_mode == printing::CMYK)
+ output_color = kCMYK;
return PMPrintSettingsSetValue(pmPrintSettings,
kColorModel,
diff --git a/printing/printing_context_win.cc b/printing/printing_context_win.cc
index ef45060..c2ace8e 100644
--- a/printing/printing_context_win.cc
+++ b/printing/printing_context_win.cc
@@ -308,7 +308,7 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
DCHECK(!in_print_job_);
bool collate;
- bool color;
+ int color;
bool landscape;
bool print_to_pdf;
int copies;
@@ -317,7 +317,7 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
if (!job_settings.GetBoolean(kSettingLandscape, &landscape) ||
!job_settings.GetBoolean(kSettingCollate, &collate) ||
- !job_settings.GetBoolean(kSettingColor, &color) ||
+ !job_settings.GetInteger(kSettingColor, &color) ||
!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf) ||
!job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) ||
!job_settings.GetInteger(kSettingCopies, &copies) ||
@@ -365,7 +365,11 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
return OnError();
}
- dev_mode->dmColor = color ? DMCOLOR_COLOR : DMCOLOR_MONOCHROME;
+ if (color == printing::GRAY)
+ dev_mode->dmColor = DMCOLOR_MONOCHROME;
+ else
+ dev_mode->dmColor = DMCOLOR_COLOR;
+
dev_mode->dmCopies = std::max(copies, 1);
if (dev_mode->dmCopies > 1) // do not change collate unless multiple copies
dev_mode->dmCollate = collate ? DMCOLLATE_TRUE : DMCOLLATE_FALSE;