diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 6e4a5131a9b..124a0d3358f 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -647,11 +647,7 @@ void WebContents::MediaStoppedPlaying(const MediaPlayerId& id) { } void WebContents::DidChangeThemeColor(SkColor theme_color) { - std::string hex_theme_color = base::StringPrintf("#%02X%02X%02X", - SkColorGetR(theme_color), - SkColorGetG(theme_color), - SkColorGetB(theme_color)); - Emit("did-change-theme-color", hex_theme_color); + Emit("did-change-theme-color", atom::ToRGBHex(theme_color)); } void WebContents::DocumentLoadedInFrame( diff --git a/atom/common/color_util.cc b/atom/common/color_util.cc index a6640d9e08b..726bc10a183 100644 --- a/atom/common/color_util.cc +++ b/atom/common/color_util.cc @@ -8,6 +8,7 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" +#include "base/strings/stringprintf.h" namespace atom { @@ -45,4 +46,11 @@ SkColor ParseHexColor(const std::string& color_string) { return SkColorSetARGB(bytes[0], bytes[1], bytes[2], bytes[3]); } +std::string ToRGBHex(const SkColor color) { + return base::StringPrintf("#%02X%02X%02X", + SkColorGetR(color), + SkColorGetG(color), + SkColorGetB(color)); +} + } // namespace atom diff --git a/atom/common/color_util.h b/atom/common/color_util.h index 0f2bb9633a7..e1b1fc44475 100644 --- a/atom/common/color_util.h +++ b/atom/common/color_util.h @@ -14,6 +14,9 @@ namespace atom { // Parse hex color like "#FFF" or "#EFEFEF" SkColor ParseHexColor(const std::string& name); +// Convert color to RGB hex value like "#ABCDEF" +std::string ToRGBHex(const SkColor color); + } // namespace atom #endif // ATOM_COMMON_COLOR_UTIL_H_