1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #import "ui/base/cocoa/nscolor_additions.h"
7 #include "base/mac/foundation_util.h"
8 #import "base/mac/sdk_forward_declarations.h"
9 #include "base/macros.h"
11 @implementation NSColor (ChromeAdditions)
13 - (CGColorRef)cr_CGColor {
14 // Redirect to -[NSColor CGColor] if available because it caches.
15 static BOOL redirect =
16 [NSColor instancesRespondToSelector:@selector(CGColor)];
18 return [self CGColor];
20 const NSInteger numberOfComponents = [self numberOfComponents];
21 std::vector<CGFloat> components(numberOfComponents, 0.0);
22 [self getComponents:components.data()];
23 auto color = CGColorCreate([[self colorSpace] CGColorSpace],
25 base::mac::CFTypeRefToNSObjectAutorelease(color);