| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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/webui/color_utils.h" |
| 6 |
| 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "base/strings/stringprintf.h" |
| 9 #include "content/public/common/manifest.h" |
| 10 |
| 11 std::string ColorUtils::ColorToString(int64_t color) { |
| 12 if (color == content::Manifest::kInvalidOrMissingColor) { |
| 13 return ""; |
| 14 } |
| 15 return SkColorToRGBAString(reinterpret_cast<uint32_t&>(color)); |
| 16 } |
| 17 |
| 18 std::string ColorUtils::SkColorToRGBAString(SkColor color) { |
| 19 // We convert the alpha using DoubleToString because StringPrintf will use |
| 20 // locale specific formatters (e.g., use , instead of . in German). |
| 21 return base::StringPrintf( |
| 22 "rgba(%d,%d,%d,%s)", SkColorGetR(color), SkColorGetG(color), |
| 23 SkColorGetB(color), |
| 24 base::DoubleToString(SkColorGetA(color) / 255.0).c_str()); |
| 25 } |
| 26 |
| 27 std::string ColorUtils::SkColorToRGBComponents(SkColor color) { |
| 28 return base::StringPrintf("%d,%d,%d", SkColorGetR(color), SkColorGetG(color), |
| 29 SkColorGetB(color)); |
| 30 } |
| OLD | NEW |