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

Side by Side 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: Make sure it is not 0 either 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/native_theme/native_theme_mac.h" 5 #include "ui/native_theme/native_theme_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/mac/mac_util.h" 10 #include "base/mac/mac_util.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 if (device_color) 90 if (device_color)
91 return gfx::NSDeviceColorToSkColor(device_color); 91 return gfx::NSDeviceColorToSkColor(device_color);
92 92
93 // Sometimes the conversion is not possible, but we can get an approximation 93 // Sometimes the conversion is not possible, but we can get an approximation
94 // by going through a CGColorRef. Note that simply using NSColor methods for 94 // by going through a CGColorRef. Note that simply using NSColor methods for
95 // accessing components for system colors results in exceptions like 95 // accessing components for system colors results in exceptions like
96 // "-numberOfComponents not valid for the NSColor NSNamedColorSpace System 96 // "-numberOfComponents not valid for the NSColor NSNamedColorSpace System
97 // windowBackgroundColor; need to first convert colorspace." Hence the 97 // windowBackgroundColor; need to first convert colorspace." Hence the
98 // conversion first to CGColor. 98 // conversion first to CGColor.
99 CGColorRef cg_color = [color CGColor]; 99 CGColorRef cg_color = [color CGColor];
100 if (CGColorGetNumberOfComponents(cg_color) == 4) 100 const size_t component_count = CGColorGetNumberOfComponents(cg_color);
101 if (component_count == 4)
101 return gfx::CGColorRefToSkColor(cg_color); 102 return gfx::CGColorRefToSkColor(cg_color);
102 103
103 CHECK_EQ(2u, CGColorGetNumberOfComponents(cg_color)); 104 CHECK(component_count == 1 || component_count == 2);
104 // Two components means a grayscale channel and an alpha channel, which 105 // Two components means a grayscale channel and an alpha channel, which
105 // CGColorRefToSkColor will not like. But RGB is additive, so the conversion 106 // CGColorRefToSkColor will not like. But RGB is additive, so the conversion
106 // is easy (RGB to grayscale is less easy). 107 // is easy (RGB to grayscale is less easy).
Avi (use Gerrit) 2014/10/16 15:13:40 Update comment?
tapted 2014/10/17 04:18:51 Done.
107 const CGFloat* components = CGColorGetComponents(cg_color); 108 const CGFloat* components = CGColorGetComponents(cg_color);
108 return SkColorSetARGB(SkScalarRoundToInt(255.0 * components[1]), 109 CGFloat alpha = component_count == 2 ? components[1] : 1.0;
110 return SkColorSetARGB(SkScalarRoundToInt(255.0 * alpha),
109 SkScalarRoundToInt(255.0 * components[0]), 111 SkScalarRoundToInt(255.0 * components[0]),
110 SkScalarRoundToInt(255.0 * components[0]), 112 SkScalarRoundToInt(255.0 * components[0]),
111 SkScalarRoundToInt(255.0 * components[0])); 113 SkScalarRoundToInt(255.0 * components[0]));
112 } 114 }
113 115
114 } // namespace 116 } // namespace
115 117
116 namespace ui { 118 namespace ui {
117 119
118 // static 120 // static
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 set_scrollbar_button_length(0); 363 set_scrollbar_button_length(0);
362 SetScrollbarColors(kScrollerThumbColor, 364 SetScrollbarColors(kScrollerThumbColor,
363 kScrollerThumbHoverColor, 365 kScrollerThumbHoverColor,
364 kScrollerTrackGradientColors[0]); 366 kScrollerTrackGradientColors[0]);
365 } 367 }
366 368
367 NativeThemeMac::~NativeThemeMac() { 369 NativeThemeMac::~NativeThemeMac() {
368 } 370 }
369 371
370 } // namespace ui 372 } // namespace ui
OLDNEW
« 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