Skip to content
Snippets Groups Projects
Unverified Commit 7f4ab06f authored by trop[bot]'s avatar trop[bot] Committed by GitHub
Browse files

fix: convert system colors to device color space in systemPreferences (#28173)


Co-authored-by: default avatarSamuel Attard <sattard@slack-corp.com>
parent c11d6813
No related merge requests found
......@@ -26,9 +26,11 @@
#include "shell/browser/mac/dict_util.h"
#include "shell/browser/mac/electron_application.h"
#include "shell/browser/ui/cocoa/NSColor+Hex.h"
#include "shell/common/color_util.h"
#include "shell/common/gin_converters/gurl_converter.h"
#include "shell/common/gin_converters/value_converter.h"
#include "shell/common/process_util.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/native_theme/native_theme.h"
namespace gin {
......@@ -388,7 +390,8 @@ std::string SystemPreferences::GetAccentColor() {
if (@available(macOS 10.14, *))
sysColor = [NSColor controlAccentColor];
return base::SysNSStringToUTF8([sysColor RGBAValue]);
return ToRGBAHex(skia::NSSystemColorToSkColor(sysColor),
false /* include_hash */);
}
std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
......@@ -417,7 +420,7 @@ std::string SystemPreferences::GetSystemColor(gin_helper::ErrorThrower thrower,
return "";
}
return base::SysNSStringToUTF8([sysColor hexadecimalValue]);
return ToRGBHex(skia::NSSystemColorToSkColor(sysColor));
}
bool SystemPreferences::CanPromptTouchID() {
......@@ -575,7 +578,7 @@ std::string SystemPreferences::GetColor(gin_helper::ErrorThrower thrower,
}
if (sysColor)
return base::SysNSStringToUTF8([sysColor hexadecimalValue]);
return ToRGBHex(skia::NSSystemColorToSkColor(sysColor));
return "";
}
......
......@@ -51,4 +51,14 @@ std::string ToRGBHex(SkColor color) {
SkColorGetG(color), SkColorGetB(color));
}
std::string ToRGBAHex(SkColor color, bool include_hash) {
std::string color_str = base::StringPrintf(
"%02X%02X%02X%02X", SkColorGetR(color), SkColorGetG(color),
SkColorGetB(color), SkColorGetA(color));
if (include_hash) {
return "#" + color_str;
}
return color_str;
}
} // namespace electron
......@@ -17,6 +17,8 @@ SkColor ParseHexColor(const std::string& color_string);
// Convert color to RGB hex value like "#ABCDEF"
std::string ToRGBHex(SkColor color);
std::string ToRGBAHex(SkColor color, bool include_hash = true);
} // namespace electron
#endif // SHELL_COMMON_COLOR_UTIL_H_
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment