Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: #ARGB to #RGBA conversion #33707

Merged
merged 3 commits into from Apr 13, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 8 additions & 11 deletions shell/common/color_util.cc
Expand Up @@ -16,7 +16,7 @@

namespace {

bool IsHexFormat(const std::string& str) {
bool IsHexFormatWithAlpha(const std::string& str) {
// Must be either #ARGB or #AARRGGBB.
bool is_hex_length = str.length() == 5 || str.length() == 9;
if (str[0] != '#' || !is_hex_length)
Expand All @@ -35,16 +35,13 @@ namespace electron {
SkColor ParseCSSColor(const std::string& color_string) {
// ParseCssColorString expects RGBA and we historically use ARGB
// so we need to convert before passing to ParseCssColorString.
std::string color_str = color_string;
if (IsHexFormat(color_str)) {
if (color_str.length() == 5) {
// #ARGB => #RGBA
std::swap(color_str[1], color_str[4]);
} else {
// #AARRGGBB => #RRGGBBAA
std::swap(color_str[1], color_str[7]);
std::swap(color_str[2], color_str[8]);
}
std::string color_str;
codebytere marked this conversation as resolved.
Show resolved Hide resolved
if (IsHexFormatWithAlpha(color_string)) {
std::string temp = color_string;
int len = color_string.length() == 5 ? 1 : 2;
color_str = temp.erase(1, len) + color_string.substr(1, len);
codebytere marked this conversation as resolved.
Show resolved Hide resolved
} else {
color_str = color_string;
codebytere marked this conversation as resolved.
Show resolved Hide resolved
}

SkColor color;
Expand Down