Skip to content

Commit

Permalink
fix: convert system colors to device color space in systemPreferences (
Browse files Browse the repository at this point in the history
…#28171)

Co-authored-by: Samuel Attard <sattard@slack-corp.com>
  • Loading branch information
trop[bot] and MarshallOfSound authored Mar 13, 2021
1 parent 3445fbf commit 592430f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions shell/browser/api/electron_api_system_preferences_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -384,7 +386,8 @@ AVMediaType ParseMediaType(const std::string& media_type) {
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,
Expand Down Expand Up @@ -413,7 +416,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {
return "";
}

return base::SysNSStringToUTF8([sysColor hexadecimalValue]);
return ToRGBHex(skia::NSSystemColorToSkColor(sysColor));
}

bool SystemPreferences::CanPromptTouchID() {
Expand Down Expand Up @@ -571,7 +574,7 @@ AVMediaType ParseMediaType(const std::string& media_type) {
}

if (sysColor)
return base::SysNSStringToUTF8([sysColor hexadecimalValue]);
return ToRGBHex(skia::NSSystemColorToSkColor(sysColor));
return "";
}

Expand Down
10 changes: 10 additions & 0 deletions shell/common/color_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions shell/common/color_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ SkColor ParseHexColor(const std::string& name);
// 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 comments on commit 592430f

Please sign in to comment.