Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(425)

Unified Diff: ui/native_theme/native_theme_mac.mm

Issue 658033002: MacViews: Handle System colors that have no alpha channel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@task
Patch Set: update comment Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/native_theme/native_theme_mac.mm
diff --git a/ui/native_theme/native_theme_mac.mm b/ui/native_theme/native_theme_mac.mm
index 60c049cb27d95d5822bf4310969dfb0381a46c61..6b87f57161a8e8375dbdcaf74c90d0992f2887d2 100644
--- a/ui/native_theme/native_theme_mac.mm
+++ b/ui/native_theme/native_theme_mac.mm
@@ -97,15 +97,17 @@ SkColor NSSystemColorToSkColor(NSColor* color) {
// windowBackgroundColor; need to first convert colorspace." Hence the
// conversion first to CGColor.
CGColorRef cg_color = [color CGColor];
- if (CGColorGetNumberOfComponents(cg_color) == 4)
+ const size_t component_count = CGColorGetNumberOfComponents(cg_color);
+ if (component_count == 4)
return gfx::CGColorRefToSkColor(cg_color);
- CHECK_EQ(2u, CGColorGetNumberOfComponents(cg_color));
- // Two components means a grayscale channel and an alpha channel, which
+ CHECK(component_count == 1 || component_count == 2);
+ // 1-2 components means a grayscale channel and maybe an alpha channel, which
// CGColorRefToSkColor will not like. But RGB is additive, so the conversion
// is easy (RGB to grayscale is less easy).
const CGFloat* components = CGColorGetComponents(cg_color);
- return SkColorSetARGB(SkScalarRoundToInt(255.0 * components[1]),
+ CGFloat alpha = component_count == 2 ? components[1] : 1.0;
+ return SkColorSetARGB(SkScalarRoundToInt(255.0 * alpha),
SkScalarRoundToInt(255.0 * components[0]),
SkScalarRoundToInt(255.0 * components[0]),
SkScalarRoundToInt(255.0 * components[0]));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698