OLD | NEW |
(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 } |
OLD | NEW |