| 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];
|
| +}
|
|
|