summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralekseys@chromium.org <alekseys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-08 02:08:05 +0000
committeralekseys@chromium.org <alekseys@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-08 02:08:05 +0000
commit710286aa83084eec1d30ebd147c1c5d2689064d6 (patch)
treeef332530264fb6b3b546c48b14f64fe363adb1f1
parent3dc75b1cccf30ccce1f13553353c21c21d6a3e34 (diff)
downloadchromium_src-710286aa83084eec1d30ebd147c1c5d2689064d6.zip
chromium_src-710286aa83084eec1d30ebd147c1c5d2689064d6.tar.gz
chromium_src-710286aa83084eec1d30ebd147c1c5d2689064d6.tar.bz2
Generalize printer color model handling, get rid of CUPS specific case. Enable supported paper szes reporting for all platforms.
BUG=239879 NOTRY=true Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=275646 Review URL: https://codereview.chromium.org/324523002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275716 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/print_preview/data/print_ticket_store.js16
-rw-r--r--chrome/browser/resources/print_preview/data/ticket_items/color.js90
-rw-r--r--chrome/browser/resources/print_preview/native_layer.js23
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_handler.cc87
-rw-r--r--chrome/browser/ui/webui/print_preview/print_preview_handler.h6
-rw-r--r--chrome/common/chrome_utility_messages.h9
-rw-r--r--chrome/common/cloud_print/cloud_print_cdd_conversion.cc10
-rw-r--r--chrome/test/data/webui/print_preview.js158
-rw-r--r--printing/backend/print_backend.cc5
-rw-r--r--printing/backend/print_backend.h10
-rw-r--r--printing/backend/print_backend_win.cc2
11 files changed, 226 insertions, 190 deletions
diff --git a/chrome/browser/resources/print_preview/data/print_ticket_store.js b/chrome/browser/resources/print_preview/data/print_ticket_store.js
index 0b902f4..a39a8db 100644
--- a/chrome/browser/resources/print_preview/data/print_ticket_store.js
+++ b/chrome/browser/resources/print_preview/data/print_ticket_store.js
@@ -376,19 +376,13 @@ cr.define('print_preview', function() {
cjt.print.collate = {collate: this.collate.getValue()};
}
if (this.color.isCapabilityAvailable() && this.color.isUserEdited()) {
- var colorType = this.color.getValue() ?
- 'STANDARD_COLOR' : 'STANDARD_MONOCHROME';
- // Find option with this colorType to read its vendor_id.
- var selectedOptions = destination.capabilities.printer.color.option.
- filter(function(option) {
- return option.type == colorType;
- });
- if (selectedOptions.length == 0) {
+ var selectedOption = this.color.getSelectedOption();
+ if (!selectedOption) {
console.error('Could not find correct color option');
} else {
- cjt.print.color = {type: colorType};
- if (selectedOptions[0].hasOwnProperty('vendor_id')) {
- cjt.print.color.vendor_id = selectedOptions[0].vendor_id;
+ cjt.print.color = {type: selectedOption.type};
+ if (selectedOption.hasOwnProperty('vendor_id')) {
+ cjt.print.color.vendor_id = selectedOption.vendor_id;
}
}
}
diff --git a/chrome/browser/resources/print_preview/data/ticket_items/color.js b/chrome/browser/resources/print_preview/data/ticket_items/color.js
index fefe538..e3d5238 100644
--- a/chrome/browser/resources/print_preview/data/ticket_items/color.js
+++ b/chrome/browser/resources/print_preview/data/ticket_items/color.js
@@ -23,6 +23,18 @@ cr.define('print_preview.ticket_items', function() {
destinationStore);
};
+ /*
+ * @private {!Array.<string>} List of capability types considered color.
+ * @const
+ */
+ Color.COLOR_TYPES_ = ['STANDARD_COLOR', 'CUSTOM_COLOR'];
+
+ /*
+ * @private {!Array.<string>} List of capability types considered monochrome.
+ * @const
+ */
+ Color.MONOCHROME_TYPES_ = ['STANDARD_MONOCHROME', 'CUSTOM_MONOCHROME'];
+
Color.prototype = {
__proto__: print_preview.ticket_items.TicketItem.prototype,
@@ -33,56 +45,72 @@ cr.define('print_preview.ticket_items', function() {
/** @override */
isCapabilityAvailable: function() {
- var colorCap = this.getColorCapability_();
- if (!colorCap) {
+ var capability = this.capability;
+ if (!capability) {
return false;
}
var hasColor = false;
var hasMonochrome = false;
- colorCap.option.forEach(function(option) {
- hasColor = hasColor || option.type == 'STANDARD_COLOR';
- hasMonochrome = hasMonochrome || option.type == 'STANDARD_MONOCHROME';
+ capability.option.forEach(function(option) {
+ hasColor = hasColor || (Color.COLOR_TYPES_.indexOf(option.type) >= 0);
+ hasMonochrome = hasMonochrome ||
+ (Color.MONOCHROME_TYPES_.indexOf(option.type) >= 0);
});
return hasColor && hasMonochrome;
},
+ /** @return {Object} Color capability of the selected destination. */
+ get capability() {
+ var dest = this.getSelectedDestInternal();
+ return (dest &&
+ dest.capabilities &&
+ dest.capabilities.printer &&
+ dest.capabilities.printer.color) ||
+ null;
+ },
+
+ /** @return {Object} Color option corresponding to the current value. */
+ getSelectedOption: function() {
+ var capability = this.capability;
+ var options = capability ? capability.option : null;
+ if (options) {
+ var typesToLookFor =
+ this.getValue() ? Color.COLOR_TYPES_ : Color.MONOCHROME_TYPES_;
+ for (var i = 0; i < typesToLookFor.length; i++) {
+ var matchingOptions = options.filter(function(option) {
+ return option.type == typesToLookFor[i];
+ });
+ if (matchingOptions.length > 0) {
+ return matchingOptions[0];
+ }
+ }
+ }
+ return null;
+ },
+
/** @override */
getDefaultValueInternal: function() {
- var colorCap = this.getColorCapability_();
- var defaultOption = this.getDefaultColorOption_(colorCap.option);
- return defaultOption && defaultOption.type == 'STANDARD_COLOR';
+ var capability = this.capability;
+ var defaultOption = capability ?
+ this.getDefaultColorOption_(capability.option) : null;
+ return defaultOption &&
+ (Color.COLOR_TYPES_.indexOf(defaultOption.type) >= 0);
},
/** @override */
getCapabilityNotAvailableValueInternal: function() {
- var colorCap = this.getColorCapability_();
- var defaultOption = colorCap ?
- this.getDefaultColorOption_(colorCap.option) : null;
-
// TODO(rltoscano): Get rid of this check based on destination ID. These
// destinations should really update their CDDs to have only one color
// option that has type 'STANDARD_COLOR'.
var dest = this.getSelectedDestInternal();
- if (!dest) {
- return false;
+ if (dest) {
+ if (dest.id == print_preview.Destination.GooglePromotedId.DOCS ||
+ dest.id == print_preview.Destination.GooglePromotedId.FEDEX ||
+ dest.type == print_preview.Destination.Type.MOBILE) {
+ return true;
+ }
}
- return dest.id == print_preview.Destination.GooglePromotedId.DOCS ||
- dest.id == print_preview.Destination.GooglePromotedId.FEDEX ||
- dest.type == print_preview.Destination.Type.MOBILE ||
- defaultOption && defaultOption.type == 'STANDARD_COLOR';
- },
-
- /**
- * @return {Object} Color capability of the selected destination.
- * @private
- */
- getColorCapability_: function() {
- var dest = this.getSelectedDestInternal();
- return (dest &&
- dest.capabilities &&
- dest.capabilities.printer &&
- dest.capabilities.printer.color) ||
- null;
+ return this.getDefaultValueInternal();
},
/**
diff --git a/chrome/browser/resources/print_preview/native_layer.js b/chrome/browser/resources/print_preview/native_layer.js
index efdd55b..0111ccd 100644
--- a/chrome/browser/resources/print_preview/native_layer.js
+++ b/chrome/browser/resources/print_preview/native_layer.js
@@ -168,6 +168,23 @@ cr.define('print_preview', function() {
},
/**
+ * @param {!print_preview.Destination} destination Destination to print to.
+ * @param {!print_preview.ticket_items.Color} color Color ticket item.
+ * @return {number} Native layer color model.
+ * @private
+ */
+ getNativeColorModel_: function(destination, color) {
+ // For non-local printers native color model is ignored anyway.
+ var option = destination.isLocal ? color.getSelectedOption() : null;
+ var nativeColorModel = parseInt(option ? option.vendor_id : null);
+ if (isNaN(nativeColorModel)) {
+ return color.getValue() ?
+ NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY;
+ }
+ return nativeColorModel;
+ },
+
+ /**
* Requests that a preview be generated. The following events may be
* dispatched in response:
* - PAGE_COUNT_READY
@@ -190,8 +207,7 @@ cr.define('print_preview', function() {
'pageRange': printTicketStore.pageRange.getDocumentPageRanges(),
'mediaSize': printTicketStore.mediaSize.getValue(),
'landscape': printTicketStore.landscape.getValue(),
- 'color': printTicketStore.color.getValue() ?
- NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY,
+ 'color': this.getNativeColorModel_(destination, printTicketStore.color),
'headerFooterEnabled': printTicketStore.headerFooter.getValue(),
'marginsType': printTicketStore.marginsType.getValue(),
'isFirstRequest': requestId == 0,
@@ -263,8 +279,7 @@ cr.define('print_preview', function() {
'pageRange': printTicketStore.pageRange.getDocumentPageRanges(),
'pageCount': printTicketStore.pageRange.getPageNumberSet().size,
'landscape': printTicketStore.landscape.getValue(),
- 'color': printTicketStore.color.getValue() ?
- NativeLayer.ColorMode_.COLOR : NativeLayer.ColorMode_.GRAY,
+ 'color': this.getNativeColorModel_(destination, printTicketStore.color),
'headerFooterEnabled': printTicketStore.headerFooter.getValue(),
'marginsType': printTicketStore.marginsType.getValue(),
'generateDraftData': true, // TODO(rltoscano): What should this be?
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
index 81b0d40..ede72df 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.cc
@@ -22,6 +22,7 @@
#include "base/metrics/histogram.h"
#include "base/path_service.h"
#include "base/prefs/pref_service.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
@@ -190,10 +191,6 @@ const char kLocalPdfPrinterId[] = "Save as PDF";
// Additional printer capability setting keys.
const char kPrinterId[] = "printerId";
const char kPrinterCapabilities[] = "capabilities";
-#if defined(USE_CUPS)
-const char kCUPSsColorModel[] = "cupsColorModel";
-const char kCUPSsBWModel[] = "cupsBWModel";
-#endif
// Get the print job settings dictionary from |args|. The caller takes
// ownership of the returned DictionaryValue. Returns NULL on failure.
@@ -317,7 +314,11 @@ scoped_ptr<base::DictionaryValue> GetPdfCapabilitiesOnFileThread(
orientation.SaveTo(&description);
ColorCapability color;
- color.AddDefaultOption(Color(STANDARD_COLOR), true);
+ {
+ Color standard_color(STANDARD_COLOR);
+ standard_color.vendor_id = base::IntToString(printing::COLOR);
+ color.AddDefaultOption(standard_color, true);
+ }
color.SaveTo(&description);
static const cloud_devices::printer::MediaType kPdfMedia[] = {
@@ -376,11 +377,6 @@ scoped_ptr<base::DictionaryValue> GetLocalPrinterCapabilitiesOnFileThread(
return scoped_ptr<base::DictionaryValue>();
}
-#if defined(USE_CUPS)
- // TODO(alekseys): Use CUSTOM_COLOR/MONOCHROME instead.
- description->SetInteger(kCUPSsColorModel, info.color_model);
- description->SetInteger(kCUPSsBWModel, info.bw_model);
-#endif
return description.Pass();
}
@@ -473,14 +469,6 @@ printing::StickySettings* GetStickySettings() {
} // namespace
-#if defined(USE_CUPS)
-struct PrintPreviewHandler::CUPSPrinterColorModels {
- std::string printer_name;
- printing::ColorModel color_model;
- printing::ColorModel bw_model;
-};
-#endif
-
class PrintPreviewHandler::AccessTokenService
: public OAuth2TokenService::Consumer {
public:
@@ -880,11 +868,6 @@ void PrintPreviewHandler::HandlePrint(const base::ListValue* args) {
// Reset selection only flag for the same reason.
settings->SetBoolean(printing::kSettingShouldPrintSelectionOnly, false);
-#if defined(USE_CUPS)
- if (!open_pdf_in_preview) // We can get here even for cloud printers.
- ConvertColorSettingToCUPSColorModel(settings.get());
-#endif
-
// Set ID to know whether printing is for preview.
settings->SetInteger(printing::kPreviewUIID,
print_preview_ui->GetIDForPrintPreviewUI());
@@ -1229,11 +1212,6 @@ void PrintPreviewHandler::SendAccessToken(const std::string& type,
void PrintPreviewHandler::SendPrinterCapabilities(
const base::DictionaryValue* settings_info) {
VLOG(1) << "Get printer capabilities finished";
-
-#if defined(USE_CUPS)
- SaveCUPSColorSetting(settings_info);
-#endif
-
web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities",
*settings_info);
}
@@ -1410,59 +1388,6 @@ bool PrintPreviewHandler::GetPreviewDataAndTitle(
return true;
}
-#if defined(USE_CUPS)
-void PrintPreviewHandler::SaveCUPSColorSetting(
- const base::DictionaryValue* settings) {
- cups_printer_color_models_.reset(new CUPSPrinterColorModels);
- settings->GetString(kPrinterId, &cups_printer_color_models_->printer_name);
- const base::DictionaryValue* capabilities = NULL;
- if (!settings->GetDictionary(kPrinterCapabilities, &capabilities) ||
- !capabilities) {
- NOTREACHED();
- return;
- }
- capabilities->GetInteger(
- kCUPSsColorModel,
- reinterpret_cast<int*>(&cups_printer_color_models_->color_model));
- capabilities->GetInteger(
- kCUPSsBWModel,
- reinterpret_cast<int*>(&cups_printer_color_models_->bw_model));
-}
-
-void PrintPreviewHandler::ConvertColorSettingToCUPSColorModel(
- base::DictionaryValue* settings) const {
- if (!cups_printer_color_models_)
- return;
-
- // Sanity check the printer name.
- std::string printer_name;
- if (!settings->GetString(printing::kSettingDeviceName, &printer_name) ||
- printer_name != cups_printer_color_models_->printer_name) {
- NOTREACHED();
- return;
- }
-
- int color;
- if (!settings->GetInteger(printing::kSettingColor, &color)) {
- NOTREACHED();
- return;
- }
-
- if (color == printing::GRAY) {
- if (cups_printer_color_models_->bw_model != printing::UNKNOWN_COLOR_MODEL) {
- settings->SetInteger(printing::kSettingColor,
- cups_printer_color_models_->bw_model);
- }
- return;
- }
-
- printing::ColorModel color_model = cups_printer_color_models_->color_model;
- if (color_model != printing::UNKNOWN_COLOR_MODEL)
- settings->SetInteger(printing::kSettingColor, color_model);
-}
-
-#endif // defined(USE_CUPS)
-
#if defined(ENABLE_SERVICE_DISCOVERY)
void PrintPreviewHandler::LocalPrinterChanged(
bool added,
diff --git a/chrome/browser/ui/webui/print_preview/print_preview_handler.h b/chrome/browser/ui/webui/print_preview/print_preview_handler.h
index 70464a8..2a263fa 100644
--- a/chrome/browser/ui/webui/print_preview/print_preview_handler.h
+++ b/chrome/browser/ui/webui/print_preview/print_preview_handler.h
@@ -99,7 +99,6 @@ class PrintPreviewHandler
private:
class AccessTokenService;
- struct CUPSPrinterColorModels;
static bool PrivetPrintingEnabled();
@@ -296,11 +295,6 @@ class PrintPreviewHandler
// Holds token service to get OAuth2 access tokens.
scoped_ptr<AccessTokenService> token_service_;
-#if defined(USE_CUPS)
- // The color capabilities from the last printer queried.
- scoped_ptr<CUPSPrinterColorModels> cups_printer_color_models_;
-#endif
-
#if defined(ENABLE_SERVICE_DISCOVERY)
scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
service_discovery_client_;
diff --git a/chrome/common/chrome_utility_messages.h b/chrome/common/chrome_utility_messages.h
index a926690..b706ee54 100644
--- a/chrome/common/chrome_utility_messages.h
+++ b/chrome/common/chrome_utility_messages.h
@@ -48,14 +48,13 @@ IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(defaults_mime_type)
IPC_STRUCT_TRAITS_END()
-IPC_ENUM_TRAITS(printing::DuplexMode)
+IPC_ENUM_TRAITS_MAX_VALUE(printing::ColorModel, printing::PROCESSCOLORMODEL_RGB)
+IPC_ENUM_TRAITS_MAX_VALUE(printing::DuplexMode, printing::SHORT_EDGE)
-#if defined(OS_WIN)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults::Paper)
IPC_STRUCT_TRAITS_MEMBER(name)
IPC_STRUCT_TRAITS_MEMBER(size_um)
IPC_STRUCT_TRAITS_END()
-#endif
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(collate_capable)
@@ -65,16 +64,12 @@ IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(duplex_default)
IPC_STRUCT_TRAITS_MEMBER(color_changeable)
IPC_STRUCT_TRAITS_MEMBER(color_default)
-#if defined(USE_CUPS)
IPC_STRUCT_TRAITS_MEMBER(color_model)
IPC_STRUCT_TRAITS_MEMBER(bw_model)
-#endif
-#if defined(OS_WIN)
IPC_STRUCT_TRAITS_MEMBER(papers)
IPC_STRUCT_TRAITS_MEMBER(default_paper)
IPC_STRUCT_TRAITS_MEMBER(dpis)
IPC_STRUCT_TRAITS_MEMBER(default_dpi)
-#endif
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS(printing::PwgRasterTransformType);
diff --git a/chrome/common/cloud_print/cloud_print_cdd_conversion.cc b/chrome/common/cloud_print/cloud_print_cdd_conversion.cc
index 549b27d..8c20950 100644
--- a/chrome/common/cloud_print/cloud_print_cdd_conversion.cc
+++ b/chrome/common/cloud_print/cloud_print_cdd_conversion.cc
@@ -4,6 +4,7 @@
#include "chrome/common/cloud_print/cloud_print_cdd_conversion.h"
+#include "base/strings/string_number_conversions.h"
#include "components/cloud_devices/common/printer_description.h"
#include "printing/backend/print_backend.h"
@@ -42,11 +43,14 @@ scoped_ptr<base::DictionaryValue> PrinterSemanticCapsAndDefaultsToCdd(
ColorCapability color;
if (semantic_info.color_default || semantic_info.color_changeable) {
- color.AddDefaultOption(Color(STANDARD_COLOR), semantic_info.color_default);
+ Color standard_color(STANDARD_COLOR);
+ standard_color.vendor_id = base::IntToString(semantic_info.color_model);
+ color.AddDefaultOption(standard_color, semantic_info.color_default);
}
if (!semantic_info.color_default || semantic_info.color_changeable) {
- color.AddDefaultOption(Color(STANDARD_MONOCHROME),
- !semantic_info.color_default);
+ Color standard_monochrome(STANDARD_MONOCHROME);
+ standard_monochrome.vendor_id = base::IntToString(semantic_info.bw_model);
+ color.AddDefaultOption(standard_monochrome, !semantic_info.color_default);
}
color.SaveTo(&description);
diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js
index a7d8bdf..b0b7221 100644
--- a/chrome/test/data/webui/print_preview.js
+++ b/chrome/test/data/webui/print_preview.js
@@ -87,6 +87,18 @@ PrintPreviewWebUITest.prototype = {
}.bind(this));
},
+ setUpPreview: function() {
+ var initialSettingsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
+ initialSettingsSetEvent.initialSettings = this.initialSettings_;
+ this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
+
+ var localDestsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
+ localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
+ this.nativeLayer_.dispatchEvent(localDestsSetEvent);
+ },
+
/**
* Generate a real C++ class; don't typedef.
* @type {?string}
@@ -584,59 +596,139 @@ TEST_F('PrintPreviewWebUITest',
true);
});
-// Test that the color settings are set according to the printer capabilities.
-TEST_F('PrintPreviewWebUITest', 'TestColorSettingsTrue', function() {
- var initialSettingsSetEvent =
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
- initialSettingsSetEvent.initialSettings = this.initialSettings_;
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
+// Test that the color settings, one option, standard monochrome.
+TEST_F('PrintPreviewWebUITest', 'TestColorSettingsMonochrome', function() {
+ this.setUpPreview();
- var localDestsSetEvent =
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
- this.nativeLayer_.dispatchEvent(localDestsSetEvent);
+ // Only one option, standard monochrome.
+ var capsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
+ capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
+ capsSetEvent.settingsInfo.capabilities.printer.color = {
+ "option": [
+ {"is_default": true, "type": "STANDARD_MONOCHROME"}
+ ]
+ };
+ this.nativeLayer_.dispatchEvent(capsSetEvent);
+
+ checkSectionVisible($('color-settings'), false);
+});
+
+// Test that the color settings, one option, custom monochrome.
+TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomMonochrome',
+ function() {
+ this.setUpPreview();
+ // Only one option, standard monochrome.
var capsSetEvent =
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
+ capsSetEvent.settingsInfo.capabilities.printer.color = {
+ "option": [
+ {"is_default": true, "type": "CUSTOM_MONOCHROME", "vendor_id": "42"}
+ ]
+ };
this.nativeLayer_.dispatchEvent(capsSetEvent);
- checkSectionVisible($('color-settings'), true);
+ checkSectionVisible($('color-settings'), false);
+});
- var colorOption = $('color-settings').querySelector('.color-option');
- var bwOption = $('color-settings').querySelector('.bw-option');
- expectTrue(colorOption.checked);
- expectFalse(bwOption.checked);
+// Test that the color settings, one option, standard color.
+TEST_F('PrintPreviewWebUITest', 'TestColorSettingsColor', function() {
+ this.setUpPreview();
+
+ var capsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
+ capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
+ capsSetEvent.settingsInfo.capabilities.printer.color = {
+ "option": [
+ {"is_default": true, "type": "STANDARD_COLOR"}
+ ]
+ };
+ this.nativeLayer_.dispatchEvent(capsSetEvent);
+
+ checkSectionVisible($('color-settings'), false);
});
-//Test that the color settings are set according to the printer capabilities.
-TEST_F('PrintPreviewWebUITest', 'TestColorSettingsFalse', function() {
- var initialSettingsSetEvent =
- new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
- initialSettingsSetEvent.initialSettings = this.initialSettings_;
- this.nativeLayer_.dispatchEvent(initialSettingsSetEvent);
+// Test that the color settings, one option, custom color.
+TEST_F('PrintPreviewWebUITest', 'TestColorSettingsCustomColor', function() {
+ this.setUpPreview();
- var localDestsSetEvent =
- new Event(print_preview.NativeLayer.EventType.LOCAL_DESTINATIONS_SET);
- localDestsSetEvent.destinationInfos = this.localDestinationInfos_;
- this.nativeLayer_.dispatchEvent(localDestsSetEvent);
+ var capsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
+ capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
+ capsSetEvent.settingsInfo.capabilities.printer.color = {
+ "option": [
+ {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "42"}
+ ]
+ };
+ this.nativeLayer_.dispatchEvent(capsSetEvent);
+
+ checkSectionVisible($('color-settings'), false);
+});
+
+// Test that the color settings, two options, both standard, defaults to color.
+TEST_F('PrintPreviewWebUITest', 'TestColorSettingsBothStandardDefaultColor',
+ function() {
+ this.setUpPreview();
var capsSetEvent =
new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
capsSetEvent.settingsInfo.capabilities.printer.color = {
"option": [
- {"is_default": true, "type": "STANDARD_MONOCHROME"}
+ {"type": "STANDARD_MONOCHROME"},
+ {"is_default": true, "type": "STANDARD_COLOR"}
]
};
this.nativeLayer_.dispatchEvent(capsSetEvent);
- checkSectionVisible($('color-settings'), false);
+ checkSectionVisible($('color-settings'), true);
+ expectTrue($('color-settings').querySelector('.color-option').checked);
+ expectFalse($('color-settings').querySelector('.bw-option').checked);
+});
+
+// Test that the color settings, two options, both standard, defaults to
+// monochrome.
+TEST_F('PrintPreviewWebUITest',
+ 'TestColorSettingsBothStandardDefaultMonochrome', function() {
+ this.setUpPreview();
- var colorOption = $('color-settings').querySelector('.color-option');
- var bwOption = $('color-settings').querySelector('.bw-option');
- expectFalse(colorOption.checked);
- expectTrue(bwOption.checked);
+ var capsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
+ capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
+ capsSetEvent.settingsInfo.capabilities.printer.color = {
+ "option": [
+ {"is_default": true, "type": "STANDARD_MONOCHROME"},
+ {"type": "STANDARD_COLOR"}
+ ]
+ };
+ this.nativeLayer_.dispatchEvent(capsSetEvent);
+
+ checkSectionVisible($('color-settings'), true);
+ expectFalse($('color-settings').querySelector('.color-option').checked);
+ expectTrue($('color-settings').querySelector('.bw-option').checked);
+});
+
+// Test that the color settings, two options, both custom, defaults to color.
+TEST_F('PrintPreviewWebUITest',
+ 'TestColorSettingsBothCustomDefaultColor', function() {
+ this.setUpPreview();
+
+ var capsSetEvent =
+ new Event(print_preview.NativeLayer.EventType.CAPABILITIES_SET);
+ capsSetEvent.settingsInfo = getCddTemplate("FooDevice");
+ capsSetEvent.settingsInfo.capabilities.printer.color = {
+ "option": [
+ {"type": "CUSTOM_MONOCHROME", "vendor_id": "42"},
+ {"is_default": true, "type": "CUSTOM_COLOR", "vendor_id": "43"}
+ ]
+ };
+ this.nativeLayer_.dispatchEvent(capsSetEvent);
+
+ checkSectionVisible($('color-settings'), true);
+ expectTrue($('color-settings').querySelector('.color-option').checked);
+ expectFalse($('color-settings').querySelector('.bw-option').checked);
});
// Test to verify that duplex settings are set according to the printer
@@ -666,8 +758,8 @@ TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsTrue', function() {
expectFalse(duplexCheckbox.checked);
});
-//Test to verify that duplex settings are set according to the printer
-//capabilities.
+// Test to verify that duplex settings are set according to the printer
+// capabilities.
TEST_F('PrintPreviewWebUITest', 'TestDuplexSettingsFalse', function() {
var initialSettingsSetEvent =
new Event(print_preview.NativeLayer.EventType.INITIAL_SETTINGS_SET);
diff --git a/printing/backend/print_backend.cc b/printing/backend/print_backend.cc
index d071201..fefa789 100644
--- a/printing/backend/print_backend.cc
+++ b/printing/backend/print_backend.cc
@@ -19,12 +19,9 @@ PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults()
duplex_capable(false),
duplex_default(UNKNOWN_DUPLEX_MODE),
color_changeable(false),
- color_default(false)
-#if defined (OS_POSIX)
- ,
+ color_default(false),
color_model(UNKNOWN_COLOR_MODEL),
bw_model(UNKNOWN_COLOR_MODEL)
-#endif
{}
PrinterSemanticCapsAndDefaults::~PrinterSemanticCapsAndDefaults() {}
diff --git a/printing/backend/print_backend.h b/printing/backend/print_backend.h
index 30e4512..3b307f1 100644
--- a/printing/backend/print_backend.h
+++ b/printing/backend/print_backend.h
@@ -48,28 +48,18 @@ struct PRINTING_EXPORT PrinterSemanticCapsAndDefaults {
bool color_changeable;
bool color_default;
-
- // These are CUPS specific data, which soon be removed altogether. They are
- // not defined under USE_CUPS to do not pull CUPS dependency into common code.
-#if defined(OS_POSIX)
- // TODO(alekseys): Resolve color model within printing context, do not expose
- // it outside of the context.
ColorModel color_model;
ColorModel bw_model;
-#endif
-#if defined(OS_WIN)
struct Paper {
std::string name;
gfx::Size size_um;
};
-
std::vector<Paper> papers;
Paper default_paper;
std::vector<gfx::Size> dpis;
gfx::Size default_dpi;
-#endif
};
struct PRINTING_EXPORT PrinterCapsAndDefaults {
diff --git a/printing/backend/print_backend_win.cc b/printing/backend/print_backend_win.cc
index 75c562a..87c69ee 100644
--- a/printing/backend/print_backend_win.cc
+++ b/printing/backend/print_backend_win.cc
@@ -267,6 +267,8 @@ bool PrintBackendWin::GetPrinterSemanticCapsAndDefaults(
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183552(v=vs.85).aspx
caps.color_changeable =
(DeviceCapabilities(name, port, DC_COLORDEVICE, NULL, NULL) == 1);
+ caps.color_model = printing::COLOR;
+ caps.bw_model = printing::GRAY;
caps.duplex_capable =
(DeviceCapabilities(name, port, DC_DUPLEX, NULL, NULL) == 1);