Commit 0ec01b13 authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

printing: Check all color modes in IsColorModelSelected()

Update IsColorModelSelected() to check for all color modes.

Change-Id: I61b4922e1ddb6b9a3f906b9122b1ca4f29c8272e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1901835Reviewed-by: default avatarSean Kau <skau@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718884}
parent 5ee58418
......@@ -46,9 +46,9 @@ constexpr int kMinimumPdfSize = 50;
// Converts a color mode to its Mojo type.
mojom::PrintColorMode ToArcColorMode(int color_mode) {
return printing::IsColorModelSelected(color_mode)
? mojom::PrintColorMode::COLOR
: mojom::PrintColorMode::MONOCHROME;
base::Optional<bool> is_color = printing::IsColorModelSelected(color_mode);
return is_color.value() ? mojom::PrintColorMode::COLOR
: mojom::PrintColorMode::MONOCHROME;
}
// Converts a duplex mode to its Mojo type.
......
......@@ -4,6 +4,8 @@
#include "chrome/browser/chromeos/printing/history/print_job_info_proto_conversions.h"
#include "base/optional.h"
namespace chromeos {
namespace proto = printing::proto;
......@@ -11,9 +13,9 @@ namespace proto = printing::proto;
namespace {
proto::PrintSettings_ColorMode ColorModelToProto(::printing::ColorModel color) {
return ::printing::IsColorModelSelected(color)
? proto::PrintSettings_ColorMode_COLOR
: proto::PrintSettings_ColorMode_BLACK_AND_WHITE;
base::Optional<bool> is_color = ::printing::IsColorModelSelected(color);
return is_color.value() ? proto::PrintSettings_ColorMode_COLOR
: proto::PrintSettings_ColorMode_BLACK_AND_WHITE;
}
proto::PrintSettings_DuplexMode DuplexModeToProto(
......
......@@ -333,9 +333,10 @@ void ReportPrintSettingsStats(const base::Value& print_settings,
ReportPrintSettingHistogram(duplex_mode_opt.value() ? DUPLEX : SIMPLEX);
base::Optional<int> color_mode_opt = print_settings.FindIntKey(kSettingColor);
if (color_mode_opt) {
ReportPrintSettingHistogram(
IsColorModelSelected(color_mode_opt.value()) ? COLOR : BLACK_AND_WHITE);
if (color_mode_opt.has_value()) {
base::Optional<bool> is_color =
IsColorModelSelected(color_mode_opt.value());
ReportPrintSettingHistogram(is_color.value() ? COLOR : BLACK_AND_WHITE);
}
if (preview_settings.FindIntKey(kSettingMarginsType).value_or(0) != 0)
......
......@@ -136,14 +136,38 @@ void GetColorModelForMode(int color_mode,
}
#endif // defined(USE_CUPS)
bool IsColorModelSelected(int color_mode) {
return (color_mode != GRAY && color_mode != BLACK &&
color_mode != PRINTOUTMODE_NORMAL_GRAY &&
color_mode != COLORMODE_MONOCHROME &&
color_mode != PROCESSCOLORMODEL_GREYSCALE &&
color_mode != BROTHER_CUPS_MONO &&
color_mode != BROTHER_BRSCRIPT3_BLACK &&
color_mode != HP_COLOR_BLACK);
base::Optional<bool> IsColorModelSelected(int color_mode) {
switch (color_mode) {
case COLOR:
case CMYK:
case CMY:
case KCMY:
case CMY_K:
case RGB:
case RGB16:
case RGBA:
case COLORMODE_COLOR:
case HP_COLOR_COLOR:
case PRINTOUTMODE_NORMAL:
case PROCESSCOLORMODEL_CMYK:
case PROCESSCOLORMODEL_RGB:
case BROTHER_CUPS_COLOR:
case BROTHER_BRSCRIPT3_COLOR:
return true;
case GRAY:
case BLACK:
case GRAYSCALE:
case COLORMODE_MONOCHROME:
case HP_COLOR_BLACK:
case PRINTOUTMODE_NORMAL_GRAY:
case PROCESSCOLORMODEL_GREYSCALE:
case BROTHER_CUPS_MONO:
case BROTHER_BRSCRIPT3_BLACK:
return false;
default:
NOTREACHED();
return base::nullopt;
}
}
// Global SequenceNumber used for generating unique cookie values.
......
......@@ -9,6 +9,7 @@
#include <string>
#include "base/macros.h"
#include "base/optional.h"
#include "base/strings/string16.h"
#include "printing/page_range.h"
#include "printing/page_setup.h"
......@@ -25,8 +26,9 @@
namespace printing {
// Returns true if |color_mode| is color and not B&W.
PRINTING_EXPORT bool IsColorModelSelected(int color_mode);
// Returns true if |color_mode| is color and not B&W. Must be called with a
// |color_mode| from printing::ColorModel, excluding UNKNOWN_COLOR_MODEL.
PRINTING_EXPORT base::Optional<bool> IsColorModelSelected(int color_mode);
#if defined(USE_CUPS)
// Get the color model setting name and value for the |color_mode|.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment