Skip to content

Commit

Permalink
chore: address review cleanup comments
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 25, 2022
1 parent 61dc70b commit 6790e31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -772,7 +772,7 @@ WebContents::WebContents(v8::Isolate* isolate,
// and we then need to pull it back out and check it here.
std::string background_color;
options.GetHidden(options::kBackgroundColor, &background_color);
bool transparent = ParseHexColor(background_color) == SK_ColorTRANSPARENT;
bool transparent = ParseCSSColor(background_color) == SK_ColorTRANSPARENT;

content::WebContents::CreateParams params(session->browser_context());
auto* view = new OffScreenWebContentsView(
Expand Down
19 changes: 13 additions & 6 deletions shell/common/color_util.cc
Expand Up @@ -4,8 +4,10 @@

#include "shell/common/color_util.h"

#include <cmath>
#include <vector>

#include "base/cxx17_backports.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "content/public/common/color_parser.h"
Expand All @@ -14,9 +16,8 @@
namespace electron {

std::string SkColorToColorString(SkColor color, const std::string& format) {
double alpha_double = (double)(SkColorGetA(color)) / 255.0;
double alpha =
alpha_double <= 0.0 ? 0.0 : alpha_double >= 1.0 ? 1.0 : alpha_double;
const double alpha_double = double(SkColorGetA(color)) / 255.0;
const double alpha = base::clamp(alpha_double, 0.0, 1.0);

if (format == "hsl" || format == "hsla") {
color_utils::HSL hsl;
Expand All @@ -32,13 +33,19 @@ std::string SkColorToColorString(SkColor color, const std::string& format) {
return base::StringPrintf("hsl(%ld, %ld%%, %ld%%)", lround(hsl.h * 360),
lround(hsl.s * 100), lround(hsl.l * 100));
}
} else if (format == "rgba") {
}

if (format == "rgba") {
return base::StringPrintf("rgba(%d, %d, %d, %.1f)", SkColorGetR(color),
SkColorGetG(color), SkColorGetB(color), alpha);
} else if (format == "rgb") {
}

if (format == "rgb") {
return base::StringPrintf("rgb(%d, %d, %d)", SkColorGetR(color),
SkColorGetG(color), SkColorGetB(color));
} else if (alpha != 1.0) {
}

if (alpha != 1.0) {
return ToRGBAHex(color, true);
}

Expand Down

0 comments on commit 6790e31

Please sign in to comment.