LibWeb/CSS: Rename CSSColorValue -> ColorStyleValue

The typed-om class will be a separate thing.
This commit is contained in:
Sam Atkins 2025-08-08 11:24:15 +01:00 committed by Tim Ledbetter
commit 6cad3f1921
Notes: github-actions[bot] 2025-08-08 14:20:25 +00:00
35 changed files with 97 additions and 99 deletions

View file

@ -12,7 +12,7 @@
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/PercentageOr.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {

View file

@ -6,13 +6,13 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#csshsl
class CSSHSL final : public CSSColorValue {
class CSSHSL final : public ColorStyleValue {
public:
static ValueComparingNonnullRefPtr<CSSHSL const> create(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> s, ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingRefPtr<StyleValue const> alpha, ColorSyntax color_syntax)
{
@ -37,7 +37,7 @@ public:
private:
CSSHSL(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> s, ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingNonnullRefPtr<StyleValue const> alpha, ColorSyntax color_syntax)
: CSSColorValue(ColorType::HSL, color_syntax)
: ColorStyleValue(ColorType::HSL, color_syntax)
, m_properties { .h = move(h), .s = move(s), .l = move(l), .alpha = move(alpha) }
{
}

View file

@ -6,13 +6,13 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#csshwb
class CSSHWB final : public CSSColorValue {
class CSSHWB final : public ColorStyleValue {
public:
static ValueComparingNonnullRefPtr<CSSHWB const> create(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> w, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingRefPtr<StyleValue const> alpha = {})
{
@ -37,7 +37,7 @@ public:
private:
CSSHWB(ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> w, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingNonnullRefPtr<StyleValue const> alpha)
: CSSColorValue(ColorType::HWB, ColorSyntax::Modern)
: ColorStyleValue(ColorType::HWB, ColorSyntax::Modern)
, m_properties { .h = move(h), .w = move(w), .b = move(b), .alpha = move(alpha) }
{
}

View file

@ -6,12 +6,12 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
namespace Web::CSS {
class CSSLCHLike : public CSSColorValue {
class CSSLCHLike : public ColorStyleValue {
public:
template<DerivedFrom<CSSLCHLike> T>
static ValueComparingNonnullRefPtr<T const> create(ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingNonnullRefPtr<StyleValue const> c, ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingRefPtr<StyleValue const> alpha = {})
@ -33,7 +33,7 @@ public:
protected:
CSSLCHLike(ColorType color_type, ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingNonnullRefPtr<StyleValue const> c, ValueComparingNonnullRefPtr<StyleValue const> h, ValueComparingNonnullRefPtr<StyleValue const> alpha)
: CSSColorValue(color_type, ColorSyntax::Modern)
: ColorStyleValue(color_type, ColorSyntax::Modern)
, m_properties { .l = move(l), .c = move(c), .h = move(h), .alpha = move(alpha) }
{
}

View file

@ -6,12 +6,12 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
namespace Web::CSS {
class CSSLabLike : public CSSColorValue {
class CSSLabLike : public ColorStyleValue {
public:
template<typename T>
static ValueComparingNonnullRefPtr<T const> create(ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingNonnullRefPtr<StyleValue const> a, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingRefPtr<StyleValue const> alpha = {})
@ -34,7 +34,7 @@ public:
protected:
CSSLabLike(ColorType color_type, ValueComparingNonnullRefPtr<StyleValue const> l, ValueComparingNonnullRefPtr<StyleValue const> a, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingNonnullRefPtr<StyleValue const> alpha)
: CSSColorValue(color_type, ColorSyntax::Modern)
: ColorStyleValue(color_type, ColorSyntax::Modern)
, m_properties { .l = move(l), .a = move(a), .b = move(b), .alpha = move(alpha) }
{
}

View file

@ -6,12 +6,12 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
namespace Web::CSS {
// https://drafts.csswg.org/css-color-5/#funcdef-light-dark
class CSSLightDark final : public CSSColorValue {
class CSSLightDark final : public ColorStyleValue {
public:
virtual ~CSSLightDark() override = default;
@ -26,7 +26,7 @@ public:
private:
CSSLightDark(ValueComparingNonnullRefPtr<StyleValue const> light, ValueComparingNonnullRefPtr<StyleValue const> dark)
: CSSColorValue(CSSColorValue::ColorType::LightDark, ColorSyntax::Modern)
: ColorStyleValue(ColorStyleValue::ColorType::LightDark, ColorSyntax::Modern)
, m_properties { .light = move(light), .dark = move(dark) }
{
}

View file

@ -6,13 +6,13 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#cssrgb
class CSSRGB final : public CSSColorValue {
class CSSRGB final : public ColorStyleValue {
public:
static ValueComparingNonnullRefPtr<CSSRGB const> create(ValueComparingNonnullRefPtr<StyleValue const> r, ValueComparingNonnullRefPtr<StyleValue const> g, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingRefPtr<StyleValue const> alpha, ColorSyntax color_syntax, Optional<FlyString> name = {})
{
@ -37,7 +37,7 @@ public:
private:
CSSRGB(ValueComparingNonnullRefPtr<StyleValue const> r, ValueComparingNonnullRefPtr<StyleValue const> g, ValueComparingNonnullRefPtr<StyleValue const> b, ValueComparingNonnullRefPtr<StyleValue const> alpha, ColorSyntax color_syntax, Optional<FlyString> name = {})
: CSSColorValue(ColorType::RGB, color_syntax)
: ColorStyleValue(ColorType::RGB, color_syntax)
, m_properties { .r = move(r), .g = move(g), .b = move(b), .alpha = move(alpha), .name = name }
{
}

View file

@ -15,44 +15,44 @@ namespace Web::CSS {
namespace {
CSSColorValue::ColorType color_type_from_string_view(StringView color_space)
ColorStyleValue::ColorType color_type_from_string_view(StringView color_space)
{
if (color_space == "a98-rgb"sv)
return CSSColorValue::ColorType::A98RGB;
return ColorStyleValue::ColorType::A98RGB;
if (color_space == "display-p3"sv)
return CSSColorValue::ColorType::DisplayP3;
return ColorStyleValue::ColorType::DisplayP3;
if (color_space == "srgb"sv)
return CSSColorValue::ColorType::sRGB;
return ColorStyleValue::ColorType::sRGB;
if (color_space == "srgb-linear"sv)
return CSSColorValue::ColorType::sRGBLinear;
return ColorStyleValue::ColorType::sRGBLinear;
if (color_space == "prophoto-rgb"sv)
return CSSColorValue::ColorType::ProPhotoRGB;
return ColorStyleValue::ColorType::ProPhotoRGB;
if (color_space == "rec2020"sv)
return CSSColorValue::ColorType::Rec2020;
return ColorStyleValue::ColorType::Rec2020;
if (color_space == "xyz-d50"sv)
return CSSColorValue::ColorType::XYZD50;
return ColorStyleValue::ColorType::XYZD50;
if (color_space == "xyz"sv || color_space == "xyz-d65")
return CSSColorValue::ColorType::XYZD65;
return ColorStyleValue::ColorType::XYZD65;
VERIFY_NOT_REACHED();
}
StringView string_view_from_color_type(CSSColorValue::ColorType color_type)
StringView string_view_from_color_type(ColorStyleValue::ColorType color_type)
{
if (color_type == CSSColorValue::ColorType::A98RGB)
if (color_type == ColorStyleValue::ColorType::A98RGB)
return "a98-rgb"sv;
if (color_type == CSSColorValue::ColorType::DisplayP3)
if (color_type == ColorStyleValue::ColorType::DisplayP3)
return "display-p3"sv;
if (color_type == CSSColorValue::ColorType::sRGB)
if (color_type == ColorStyleValue::ColorType::sRGB)
return "srgb"sv;
if (color_type == CSSColorValue::ColorType::sRGBLinear)
if (color_type == ColorStyleValue::ColorType::sRGBLinear)
return "srgb-linear"sv;
if (color_type == CSSColorValue::ColorType::ProPhotoRGB)
if (color_type == ColorStyleValue::ColorType::ProPhotoRGB)
return "prophoto-rgb"sv;
if (color_type == CSSColorValue::ColorType::Rec2020)
if (color_type == ColorStyleValue::ColorType::Rec2020)
return "rec2020"sv;
if (color_type == CSSColorValue::ColorType::XYZD50)
if (color_type == ColorStyleValue::ColorType::XYZD50)
return "xyz-d50"sv;
if (color_type == CSSColorValue::ColorType::XYZD65)
if (color_type == ColorStyleValue::ColorType::XYZD65)
return "xyz-d65"sv;
VERIFY_NOT_REACHED();
}

View file

@ -6,12 +6,11 @@
#pragma once
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
namespace Web::CSS {
// https://drafts.css-houdini.org/css-typed-om-1/#csscolor
class ColorFunctionStyleValue final : public CSSColorValue {
class ColorFunctionStyleValue final : public ColorStyleValue {
public:
virtual ~ColorFunctionStyleValue() override = default;
@ -27,7 +26,7 @@ public:
private:
ColorFunctionStyleValue(ColorType color_type, ValueComparingNonnullRefPtr<StyleValue const> c1, ValueComparingNonnullRefPtr<StyleValue const> c2, ValueComparingNonnullRefPtr<StyleValue const> c3, ValueComparingNonnullRefPtr<StyleValue const> alpha)
: CSSColorValue(color_type, ColorSyntax::Modern)
: ColorStyleValue(color_type, ColorSyntax::Modern)
, m_properties { .channels = { move(c1), move(c2), move(c3) }, .alpha = move(alpha) }
{
}

View file

@ -17,7 +17,7 @@ ValueComparingNonnullRefPtr<ColorMixStyleValue const> ColorMixStyleValue::create
}
ColorMixStyleValue::ColorMixStyleValue(ColorInterpolationMethod color_interpolation_method, ColorMixComponent first_component, ColorMixComponent second_component)
: CSSColorValue(ColorType::ColorMix, ColorSyntax::Modern)
: ColorStyleValue(ColorType::ColorMix, ColorSyntax::Modern)
, m_properties {
.color_interpolation_method = move(color_interpolation_method),
.first_component = move(first_component),

View file

@ -7,11 +7,11 @@
#pragma once
#include <LibWeb/CSS/CalculatedOr.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
namespace Web::CSS {
class ColorMixStyleValue final : public CSSColorValue {
class ColorMixStyleValue final : public ColorStyleValue {
public:
virtual ~ColorMixStyleValue() override = default;

View file

@ -7,7 +7,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "CSSColorValue.h"
#include "ColorStyleValue.h"
#include <LibJS/Runtime/AbstractOperations.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
@ -19,7 +19,7 @@
namespace Web::CSS {
ValueComparingNonnullRefPtr<CSSColorValue const> CSSColorValue::create_from_color(Color color, ColorSyntax color_syntax, Optional<FlyString> name)
ValueComparingNonnullRefPtr<ColorStyleValue const> ColorStyleValue::create_from_color(Color color, ColorSyntax color_syntax, Optional<FlyString> name)
{
return CSSRGB::create(
NumberStyleValue::create(color.red()),
@ -30,7 +30,7 @@ ValueComparingNonnullRefPtr<CSSColorValue const> CSSColorValue::create_from_colo
name);
}
Optional<double> CSSColorValue::resolve_hue(StyleValue const& style_value, CalculationResolutionContext const& resolution_context)
Optional<double> ColorStyleValue::resolve_hue(StyleValue const& style_value, CalculationResolutionContext const& resolution_context)
{
// <number> | <angle> | none
auto normalized = [](double number) {
@ -74,7 +74,7 @@ Optional<double> CSSColorValue::resolve_hue(StyleValue const& style_value, Calcu
return 0;
}
Optional<double> CSSColorValue::resolve_with_reference_value(StyleValue const& style_value, float one_hundred_percent_value, CalculationResolutionContext const& resolution_context)
Optional<double> ColorStyleValue::resolve_with_reference_value(StyleValue const& style_value, float one_hundred_percent_value, CalculationResolutionContext const& resolution_context)
{
// <percentage> | <number> | none
auto normalize_percentage = [one_hundred_percent_value](Percentage const& percentage) {
@ -111,7 +111,7 @@ Optional<double> CSSColorValue::resolve_with_reference_value(StyleValue const& s
return 0;
}
Optional<double> CSSColorValue::resolve_alpha(StyleValue const& style_value, CalculationResolutionContext const& resolution_context)
Optional<double> ColorStyleValue::resolve_alpha(StyleValue const& style_value, CalculationResolutionContext const& resolution_context)
{
// <number> | <percentage> | none
auto normalized = [](double number) {
@ -153,7 +153,7 @@ Optional<double> CSSColorValue::resolve_alpha(StyleValue const& style_value, Cal
return 1;
}
void CSSColorValue::serialize_color_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component, float one_hundred_percent_value, Optional<double> clamp_min, Optional<double> clamp_max) const
void ColorStyleValue::serialize_color_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component, float one_hundred_percent_value, Optional<double> clamp_min, Optional<double> clamp_max) const
{
if (component.to_keyword() == Keyword::None) {
builder.append("none"sv);
@ -185,7 +185,7 @@ void CSSColorValue::serialize_color_component(StringBuilder& builder, Serializat
builder.append(resolved_string);
}
void CSSColorValue::serialize_alpha_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component) const
void ColorStyleValue::serialize_alpha_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component) const
{
if (component.to_keyword() == Keyword::None) {
builder.append("none"sv);
@ -206,7 +206,7 @@ void CSSColorValue::serialize_alpha_component(StringBuilder& builder, Serializat
builder.appendff("{}", maybe_resolved_value.value());
}
void CSSColorValue::serialize_hue_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component) const
void ColorStyleValue::serialize_hue_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component) const
{
if (component.to_keyword() == Keyword::None) {
builder.append("none"sv);

View file

@ -20,11 +20,10 @@ enum class ColorSyntax : u8 {
Modern,
};
// https://drafts.css-houdini.org/css-typed-om-1/#csscolorvalue
class CSSColorValue : public StyleValue {
class ColorStyleValue : public StyleValue {
public:
static ValueComparingNonnullRefPtr<CSSColorValue const> create_from_color(Color color, ColorSyntax color_syntax, Optional<FlyString> name = {});
virtual ~CSSColorValue() override = default;
static ValueComparingNonnullRefPtr<ColorStyleValue const> create_from_color(Color color, ColorSyntax color_syntax, Optional<FlyString> name = {});
virtual ~ColorStyleValue() override = default;
virtual bool has_color() const override { return true; }
@ -51,7 +50,7 @@ public:
ColorSyntax color_syntax() const { return m_color_syntax; }
protected:
explicit CSSColorValue(ColorType color_type, ColorSyntax color_syntax)
explicit ColorStyleValue(ColorType color_type, ColorSyntax color_syntax)
: StyleValue(Type::Color)
, m_color_type(color_type)
, m_color_syntax(color_syntax)

View file

@ -13,7 +13,7 @@
#include <LibWeb/CSS/Angle.h>
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/Painting/GradientPainting.h>
namespace Web::CSS {

View file

@ -7,7 +7,7 @@
#pragma once
#include <AK/OwnPtr.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValue.h>
namespace Web::CSS {

View file

@ -19,9 +19,9 @@
#include <LibWeb/CSS/StyleValues/BasicShapeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
#include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>

View file

@ -38,8 +38,8 @@ namespace Web::CSS {
__ENUMERATE_CSS_STYLE_VALUE_TYPE(BorderImageSlice, border_image_slice, BorderImageSliceStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(BorderRadius, border_radius, BorderRadiusStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Calculated, calculated, CalculatedStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Color, color, CSSColorValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(ColorScheme, color_scheme, ColorSchemeStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Color, color, ColorStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(ConicGradient, conic_gradient, ConicGradientStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Content, content, ContentStyleValue) \
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Counter, counter, CounterStyleValue) \