mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb/CSS: Add support for the a98-rgb
color space in color()
This makes us pass the following WPT tests: - css/css-color/a98rgb-001.html - css/css-color/a98rgb-002.html - css/css-color/a98rgb-003.html - css/css-color/a98rgb-004.html - css/css-color/predefined-007.html - css/css-color/predefined-008.html
This commit is contained in:
parent
c0ae3aa884
commit
a59d9a3986
Notes:
github-actions[bot]
2024-11-16 09:31:06 +00:00
Author: https://github.com/LucasChollet
Commit: a59d9a3986
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2374
13 changed files with 146 additions and 1 deletions
|
@ -15,6 +15,8 @@ namespace {
|
|||
|
||||
CSSColorValue::ColorType color_type_from_string_view(StringView color_space)
|
||||
{
|
||||
if (color_space == "a98-rgb"sv)
|
||||
return CSSColorValue::ColorType::A98RGB;
|
||||
if (color_space == "srgb"sv)
|
||||
return CSSColorValue::ColorType::sRGB;
|
||||
if (color_space == "srgb-linear"sv)
|
||||
|
@ -65,6 +67,9 @@ Color CSSColor::to_color(Optional<Layout::NodeWithStyle const&>) const
|
|||
auto const c3 = resolve_with_reference_value(m_properties.channels[2], 1).value_or(0);
|
||||
auto const alpha_val = resolve_alpha(m_properties.alpha).value_or(1);
|
||||
|
||||
if (color_type() == ColorType::A98RGB)
|
||||
return Color::from_a98rgb(c1, c2, c3, alpha_val);
|
||||
|
||||
if (color_type() == ColorType::sRGB) {
|
||||
auto const to_u8 = [](float c) -> u8 { return round_to<u8>(clamp(255 * c, 0, 255)); };
|
||||
return Color(to_u8(c1), to_u8(c2), to_u8(c3), to_u8(alpha_val));
|
||||
|
|
|
@ -21,7 +21,7 @@ public:
|
|||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
|
||||
virtual String to_string() const override;
|
||||
|
||||
static constexpr Array s_supported_color_space = { "srgb"sv, "srgb-linear"sv, "xyz"sv, "xyz-d50"sv, "xyz-d65"sv };
|
||||
static constexpr Array s_supported_color_space = { "a98-rgb"sv, "srgb"sv, "srgb-linear"sv, "xyz"sv, "xyz-d50"sv, "xyz-d65"sv };
|
||||
|
||||
private:
|
||||
CSSColor(ColorType color_type, ValueComparingNonnullRefPtr<CSSStyleValue> c1, ValueComparingNonnullRefPtr<CSSStyleValue> c2, ValueComparingNonnullRefPtr<CSSStyleValue> c3, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||
|
|
|
@ -24,6 +24,7 @@ public:
|
|||
|
||||
enum class ColorType {
|
||||
RGB, // This is used by CSSRGB for rgb(...) and rgba(...).
|
||||
A98RGB,
|
||||
HSL,
|
||||
HWB,
|
||||
Lab,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue