diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn index 7c27a995daf..0ec2c8f0151 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/StyleValues/BUILD.gn @@ -11,9 +11,9 @@ source_set("StyleValues") { "CSSHSL.cpp", "CSSHWB.cpp", "CSSKeywordValue.cpp", + "CSSLabLike.cpp", "CSSMathValue.cpp", "CSSOKLCH.cpp", - "CSSOKLab.cpp", "CSSRGB.cpp", "ConicGradientStyleValue.cpp", "ContentStyleValue.cpp", diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 3d0a45fc3c4..a351798e2e5 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -119,8 +119,8 @@ set(SOURCES CSS/StyleValues/CSSHSL.cpp CSS/StyleValues/CSSHWB.cpp CSS/StyleValues/CSSKeywordValue.cpp + CSS/StyleValues/CSSLabLike.cpp CSS/StyleValues/CSSMathValue.cpp - CSS/StyleValues/CSSOKLab.cpp CSS/StyleValues/CSSOKLCH.cpp CSS/StyleValues/CSSRGB.cpp CSS/StyleValues/DisplayStyleValue.cpp diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index 6f98a75071a..91909abc57d 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -48,8 +48,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSOKLab.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSLabLike.cpp similarity index 85% rename from Userland/Libraries/LibWeb/CSS/StyleValues/CSSOKLab.cpp rename to Userland/Libraries/LibWeb/CSS/StyleValues/CSSLabLike.cpp index 4bd5fe10dd6..ccdcbf2e767 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSOKLab.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSLabLike.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "CSSOKLab.h" +#include "CSSLabLike.h" #include #include #include @@ -13,6 +13,17 @@ namespace Web::CSS { +bool CSSLabLike::equals(CSSStyleValue const& other) const +{ + if (type() != other.type()) + return false; + auto const& other_color = other.as_color(); + if (color_type() != other_color.color_type()) + return false; + auto const& other_lab_like = verify_cast(other_color); + return m_properties == other_lab_like.m_properties; +} + Color CSSOKLab::to_color(Optional) const { auto const l_val = clamp(resolve_with_reference_value(m_properties.l, 1.0).value_or(0), 0, 1); @@ -23,17 +34,6 @@ Color CSSOKLab::to_color(Optional) const return Color::from_oklab(l_val, a_val, b_val, alpha_val); } -bool CSSOKLab::equals(CSSStyleValue const& other) const -{ - if (type() != other.type()) - return false; - auto const& other_color = other.as_color(); - if (color_type() != other_color.color_type()) - return false; - auto const& other_oklab = verify_cast(other_color); - return m_properties == other_oklab.m_properties; -} - // https://www.w3.org/TR/css-color-4/#serializing-oklab-oklch String CSSOKLab::to_string() const { diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSOKLab.h b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSLabLike.h similarity index 77% rename from Userland/Libraries/LibWeb/CSS/StyleValues/CSSOKLab.h rename to Userland/Libraries/LibWeb/CSS/StyleValues/CSSLabLike.h index 2d5b4ea0e61..783a03cfa9d 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValues/CSSOKLab.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/CSSLabLike.h @@ -11,33 +11,20 @@ namespace Web::CSS { -// https://drafts.css-houdini.org/css-typed-om-1/#cssoklab -class CSSOKLab final : public CSSColorValue { +class CSSLabLike : public CSSColorValue { public: - static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr l, ValueComparingNonnullRefPtr a, ValueComparingNonnullRefPtr b, ValueComparingRefPtr alpha = {}) - { - // alpha defaults to 1 - if (!alpha) - return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), NumberStyleValue::create(1))); - - return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), alpha.release_nonnull())); - } - virtual ~CSSOKLab() override = default; + virtual ~CSSLabLike() override = default; CSSStyleValue const& l() const { return *m_properties.l; } CSSStyleValue const& a() const { return *m_properties.a; } CSSStyleValue const& b() const { return *m_properties.b; } CSSStyleValue const& alpha() const { return *m_properties.alpha; } - virtual Color to_color(Optional) const override; - - String to_string() const override; - virtual bool equals(CSSStyleValue const& other) const override; -private: - CSSOKLab(ValueComparingNonnullRefPtr l, ValueComparingNonnullRefPtr a, ValueComparingNonnullRefPtr b, ValueComparingNonnullRefPtr alpha) - : CSSColorValue(ColorType::OKLab) +protected: + CSSLabLike(ColorType color_type, ValueComparingNonnullRefPtr l, ValueComparingNonnullRefPtr a, ValueComparingNonnullRefPtr b, ValueComparingNonnullRefPtr alpha) + : CSSColorValue(color_type) , m_properties { .l = move(l), .a = move(a), .b = move(b), .alpha = move(alpha) } { } @@ -51,4 +38,26 @@ private: } m_properties; }; +// https://drafts.css-houdini.org/css-typed-om-1/#cssoklab +class CSSOKLab final : public CSSLabLike { +public: + static ValueComparingNonnullRefPtr create(ValueComparingNonnullRefPtr l, ValueComparingNonnullRefPtr a, ValueComparingNonnullRefPtr b, ValueComparingRefPtr alpha = {}) + { + // alpha defaults to 1 + if (!alpha) + return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), NumberStyleValue::create(1))); + + return adopt_ref(*new (nothrow) CSSOKLab(move(l), move(a), move(b), alpha.release_nonnull())); + } + + virtual Color to_color(Optional) const override; + virtual String to_string() const override; + +private: + CSSOKLab(ValueComparingNonnullRefPtr l, ValueComparingNonnullRefPtr a, ValueComparingNonnullRefPtr b, ValueComparingNonnullRefPtr alpha) + : CSSLabLike(ColorType::OKLab, move(l), move(a), move(b), move(alpha)) + { + } +}; + }