mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibWeb/CSS: Make CSSOKLab inherit from a new CSSLabLike class
This class provides the common base for both CSSOKLab and the future CSSLab classes.
This commit is contained in:
parent
707bcaf604
commit
8efa046e0c
Notes:
github-actions[bot]
2024-10-27 09:28:40 +00:00
Author: https://github.com/LucasChollet
Commit: 8efa046e0c
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1994
5 changed files with 42 additions and 33 deletions
|
@ -11,9 +11,9 @@ source_set("StyleValues") {
|
||||||
"CSSHSL.cpp",
|
"CSSHSL.cpp",
|
||||||
"CSSHWB.cpp",
|
"CSSHWB.cpp",
|
||||||
"CSSKeywordValue.cpp",
|
"CSSKeywordValue.cpp",
|
||||||
|
"CSSLabLike.cpp",
|
||||||
"CSSMathValue.cpp",
|
"CSSMathValue.cpp",
|
||||||
"CSSOKLCH.cpp",
|
"CSSOKLCH.cpp",
|
||||||
"CSSOKLab.cpp",
|
|
||||||
"CSSRGB.cpp",
|
"CSSRGB.cpp",
|
||||||
"ConicGradientStyleValue.cpp",
|
"ConicGradientStyleValue.cpp",
|
||||||
"ContentStyleValue.cpp",
|
"ContentStyleValue.cpp",
|
||||||
|
|
|
@ -119,8 +119,8 @@ set(SOURCES
|
||||||
CSS/StyleValues/CSSHSL.cpp
|
CSS/StyleValues/CSSHSL.cpp
|
||||||
CSS/StyleValues/CSSHWB.cpp
|
CSS/StyleValues/CSSHWB.cpp
|
||||||
CSS/StyleValues/CSSKeywordValue.cpp
|
CSS/StyleValues/CSSKeywordValue.cpp
|
||||||
|
CSS/StyleValues/CSSLabLike.cpp
|
||||||
CSS/StyleValues/CSSMathValue.cpp
|
CSS/StyleValues/CSSMathValue.cpp
|
||||||
CSS/StyleValues/CSSOKLab.cpp
|
|
||||||
CSS/StyleValues/CSSOKLCH.cpp
|
CSS/StyleValues/CSSOKLCH.cpp
|
||||||
CSS/StyleValues/CSSRGB.cpp
|
CSS/StyleValues/CSSRGB.cpp
|
||||||
CSS/StyleValues/DisplayStyleValue.cpp
|
CSS/StyleValues/DisplayStyleValue.cpp
|
||||||
|
|
|
@ -48,8 +48,8 @@
|
||||||
#include <LibWeb/CSS/StyleValues/CSSHSL.h>
|
#include <LibWeb/CSS/StyleValues/CSSHSL.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CSSHWB.h>
|
#include <LibWeb/CSS/StyleValues/CSSHWB.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
|
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/CSSLabLike.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CSSOKLCH.h>
|
#include <LibWeb/CSS/StyleValues/CSSOKLCH.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CSSOKLab.h>
|
|
||||||
#include <LibWeb/CSS/StyleValues/CSSRGB.h>
|
#include <LibWeb/CSS/StyleValues/CSSRGB.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CSSOKLab.h"
|
#include "CSSLabLike.h"
|
||||||
#include <AK/TypeCasts.h>
|
#include <AK/TypeCasts.h>
|
||||||
#include <LibWeb/CSS/Serialize.h>
|
#include <LibWeb/CSS/Serialize.h>
|
||||||
#include <LibWeb/CSS/StyleValues/CSSMathValue.h>
|
#include <LibWeb/CSS/StyleValues/CSSMathValue.h>
|
||||||
|
@ -13,6 +13,17 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
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<CSSLabLike>(other_color);
|
||||||
|
return m_properties == other_lab_like.m_properties;
|
||||||
|
}
|
||||||
|
|
||||||
Color CSSOKLab::to_color(Optional<Layout::NodeWithStyle const&>) const
|
Color CSSOKLab::to_color(Optional<Layout::NodeWithStyle const&>) const
|
||||||
{
|
{
|
||||||
auto const l_val = clamp(resolve_with_reference_value(m_properties.l, 1.0).value_or(0), 0, 1);
|
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<Layout::NodeWithStyle const&>) const
|
||||||
return Color::from_oklab(l_val, a_val, b_val, alpha_val);
|
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<CSSOKLab>(other_color);
|
|
||||||
return m_properties == other_oklab.m_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://www.w3.org/TR/css-color-4/#serializing-oklab-oklch
|
// https://www.w3.org/TR/css-color-4/#serializing-oklab-oklch
|
||||||
String CSSOKLab::to_string() const
|
String CSSOKLab::to_string() const
|
||||||
{
|
{
|
|
@ -11,33 +11,20 @@
|
||||||
|
|
||||||
namespace Web::CSS {
|
namespace Web::CSS {
|
||||||
|
|
||||||
// https://drafts.css-houdini.org/css-typed-om-1/#cssoklab
|
class CSSLabLike : public CSSColorValue {
|
||||||
class CSSOKLab final : public CSSColorValue {
|
|
||||||
public:
|
public:
|
||||||
static ValueComparingNonnullRefPtr<CSSOKLab> create(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingRefPtr<CSSStyleValue> alpha = {})
|
virtual ~CSSLabLike() override = default;
|
||||||
{
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
CSSStyleValue const& l() const { return *m_properties.l; }
|
CSSStyleValue const& l() const { return *m_properties.l; }
|
||||||
CSSStyleValue const& a() const { return *m_properties.a; }
|
CSSStyleValue const& a() const { return *m_properties.a; }
|
||||||
CSSStyleValue const& b() const { return *m_properties.b; }
|
CSSStyleValue const& b() const { return *m_properties.b; }
|
||||||
CSSStyleValue const& alpha() const { return *m_properties.alpha; }
|
CSSStyleValue const& alpha() const { return *m_properties.alpha; }
|
||||||
|
|
||||||
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const override;
|
|
||||||
|
|
||||||
String to_string() const override;
|
|
||||||
|
|
||||||
virtual bool equals(CSSStyleValue const& other) const override;
|
virtual bool equals(CSSStyleValue const& other) const override;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
CSSOKLab(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
CSSLabLike(ColorType color_type, ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||||
: CSSColorValue(ColorType::OKLab)
|
: CSSColorValue(color_type)
|
||||||
, m_properties { .l = move(l), .a = move(a), .b = move(b), .alpha = move(alpha) }
|
, m_properties { .l = move(l), .a = move(a), .b = move(b), .alpha = move(alpha) }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -51,4 +38,26 @@ private:
|
||||||
} m_properties;
|
} m_properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssoklab
|
||||||
|
class CSSOKLab final : public CSSLabLike {
|
||||||
|
public:
|
||||||
|
static ValueComparingNonnullRefPtr<CSSOKLab> create(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingRefPtr<CSSStyleValue> 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<Layout::NodeWithStyle const&>) const override;
|
||||||
|
virtual String to_string() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CSSOKLab(ValueComparingNonnullRefPtr<CSSStyleValue> l, ValueComparingNonnullRefPtr<CSSStyleValue> a, ValueComparingNonnullRefPtr<CSSStyleValue> b, ValueComparingNonnullRefPtr<CSSStyleValue> alpha)
|
||||||
|
: CSSLabLike(ColorType::OKLab, move(l), move(a), move(b), move(alpha))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue