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

Side by Side Diff: chrome/browser/ui/cocoa/color_utils.mm

Issue 7687006: Implement input type=color UI (mac part) (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: rebaselined Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/cocoa/color_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "chrome/browser/ui/cocoa/color_utils.h"
6
7 #include <algorithm>
8
9 WebKit::WebColor WebColorFromNSColor(NSColor *color) {
10 CGFloat r, g, b, a;
11 [color getRed:&r green:&g blue:&b alpha:&a];
12
13 return
14 std::max(0, std::min(static_cast<int>(lroundf(255.0f * a)), 255)) << 24 |
15 std::max(0, std::min(static_cast<int>(lroundf(255.0f * r)), 255)) << 16 |
16 std::max(0, std::min(static_cast<int>(lroundf(255.0f * g)), 255)) << 8 |
17 std::max(0, std::min(static_cast<int>(lroundf(255.0f * b)), 255));
18 }
19
20 NSColor *NSColorFromWebColor(WebKit::WebColor color) {
21 uint8 a = (color >> 24) & 0xFF;
22 uint8 r = (color >> 16) & 0xFF;
23 uint8 g = (color >> 8) & 0xFF;
24 uint8 b = (color >> 0) & 0xFF;
25 return [NSColor colorWithDeviceRed:static_cast<CGFloat>(r) / 255.0
26 green:static_cast<CGFloat>(g) / 255.0
27 blue:static_cast<CGFloat>(b) / 255.0
28 alpha:static_cast<CGFloat>(a) / 255.0];
29 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/color_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698