fix: default to system accent color on invalid user color (#47800)
fix: default to system accent color on invalid user color"
This commit is contained in:
parent
45899d1cd7
commit
e17cbc96e2
11 changed files with 38 additions and 41 deletions
|
@ -28,7 +28,7 @@ bool IsHexFormatWithAlpha(const std::string& str) {
|
|||
|
||||
namespace electron {
|
||||
|
||||
SkColor ParseCSSColor(const std::string& color_string) {
|
||||
std::optional<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 converted_color_str;
|
||||
|
@ -42,7 +42,7 @@ SkColor ParseCSSColor(const std::string& color_string) {
|
|||
|
||||
SkColor color;
|
||||
if (!content::ParseCssColorString(converted_color_str, &color))
|
||||
color = SK_ColorWHITE;
|
||||
return std::nullopt;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#ifndef ELECTRON_SHELL_COMMON_COLOR_UTIL_H_
|
||||
#define ELECTRON_SHELL_COMMON_COLOR_UTIL_H_
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
|
@ -22,7 +23,7 @@ namespace electron {
|
|||
|
||||
// Parses a CSS-style color string from hex, rgb(), rgba(),
|
||||
// hsl(), hsla(), or color name formats.
|
||||
SkColor ParseCSSColor(const std::string& color_string);
|
||||
std::optional<SkColor> ParseCSSColor(const std::string& color_string);
|
||||
|
||||
// Convert color to RGB hex value like "#RRGGBB".
|
||||
std::string ToRGBHex(SkColor color);
|
||||
|
|
|
@ -226,7 +226,7 @@ bool Converter<WrappedSkColor>::FromV8(v8::Isolate* isolate,
|
|||
std::string str;
|
||||
if (!gin::ConvertFromV8(isolate, val, &str))
|
||||
return false;
|
||||
*out = electron::ParseCSSColor(str);
|
||||
*out = electron::ParseCSSColor(str).value_or(SK_ColorWHITE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue