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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/color_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/color_utils.mm
diff --git a/chrome/browser/ui/cocoa/color_utils.mm b/chrome/browser/ui/cocoa/color_utils.mm
new file mode 100644
index 0000000000000000000000000000000000000000..30deeaf78fdf35465330bc8f5ca3998309a8799f
--- /dev/null
+++ b/chrome/browser/ui/cocoa/color_utils.mm
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/cocoa/color_utils.h"
+
+#include <algorithm>
+
+WebKit::WebColor WebColorFromNSColor(NSColor *color) {
+ CGFloat r, g, b, a;
+ [color getRed:&r green:&g blue:&b alpha:&a];
+
+ return
+ std::max(0, std::min(static_cast<int>(lroundf(255.0f * a)), 255)) << 24 |
+ std::max(0, std::min(static_cast<int>(lroundf(255.0f * r)), 255)) << 16 |
+ std::max(0, std::min(static_cast<int>(lroundf(255.0f * g)), 255)) << 8 |
+ std::max(0, std::min(static_cast<int>(lroundf(255.0f * b)), 255));
+}
+
+NSColor *NSColorFromWebColor(WebKit::WebColor color) {
+ uint8 a = (color >> 24) & 0xFF;
+ uint8 r = (color >> 16) & 0xFF;
+ uint8 g = (color >> 8) & 0xFF;
+ uint8 b = (color >> 0) & 0xFF;
+ return [NSColor colorWithDeviceRed:static_cast<CGFloat>(r) / 255.0
+ green:static_cast<CGFloat>(g) / 255.0
+ blue:static_cast<CGFloat>(b) / 255.0
+ alpha:static_cast<CGFloat>(a) / 255.0];
+}
« 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