LibWeb: Remove LightDark and ColorMix from the ColorType enum
This commit is contained in:
parent
e4c29811be
commit
53a0991ff5
9 changed files with 43 additions and 38 deletions
|
|
@ -634,7 +634,8 @@ static RefPtr<StyleValue const> resolve_color_style_value(StyleValue const& styl
|
|||
return style_value;
|
||||
if (style_value.is_color()) {
|
||||
auto& color_style_value = static_cast<ColorStyleValue const&>(style_value);
|
||||
if (first_is_one_of(color_style_value.color_type(), ColorStyleValue::ColorType::Lab, ColorStyleValue::ColorType::OKLab, ColorStyleValue::ColorType::LCH, ColorStyleValue::ColorType::OKLCH))
|
||||
if (auto color_type = color_style_value.color_type();
|
||||
color_type.has_value() && first_is_one_of(*color_type, ColorStyleValue::ColorType::Lab, ColorStyleValue::ColorType::OKLab, ColorStyleValue::ColorType::LCH, ColorStyleValue::ColorType::OKLCH))
|
||||
return style_value;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Web::CSS {
|
|||
|
||||
using ColorType = ColorStyleValue::ColorType;
|
||||
|
||||
static constexpr size_t color_type_count = to_underlying(ColorType::ColorMix) + 1;
|
||||
static constexpr size_t color_type_count = to_underlying(ColorType::XYZD65) + 1;
|
||||
|
||||
namespace {
|
||||
|
||||
|
|
|
|||
|
|
@ -121,7 +121,10 @@ static MissingComponents extract_missing_components(StyleValue const& style_valu
|
|||
return {};
|
||||
|
||||
auto const& color = style_value.as_color();
|
||||
switch (color.color_type()) {
|
||||
auto color_type = color.color_type();
|
||||
if (!color_type.has_value())
|
||||
return {};
|
||||
switch (*color_type) {
|
||||
case ColorStyleValue::ColorType::HSL: {
|
||||
auto const& hsl = as<HSLColorStyleValue>(color);
|
||||
return { is_component_none(hsl.h()), is_component_none(hsl.s()), is_component_none(hsl.l()), is_component_none(hsl.alpha()) };
|
||||
|
|
@ -385,6 +388,9 @@ static Optional<Gfx::ColorComponents> style_value_to_color_components(StyleValue
|
|||
return {};
|
||||
|
||||
auto const& color = style_value.as_color();
|
||||
auto color_type = color.color_type();
|
||||
if (!color_type.has_value())
|
||||
return {};
|
||||
auto resolve_alpha = [&](StyleValue const& alpha_sv) -> Optional<float> {
|
||||
auto result = ColorStyleValue::resolve_alpha(alpha_sv, context);
|
||||
if (!result.has_value())
|
||||
|
|
@ -392,7 +398,7 @@ static Optional<Gfx::ColorComponents> style_value_to_color_components(StyleValue
|
|||
return static_cast<float>(result.value());
|
||||
};
|
||||
|
||||
switch (color.color_type()) {
|
||||
switch (*color_type) {
|
||||
case ColorStyleValue::ColorType::HSL: {
|
||||
auto const& hsl = as<HSLColorStyleValue>(color);
|
||||
auto h = ColorStyleValue::resolve_hue(hsl.h(), context);
|
||||
|
|
@ -620,8 +626,11 @@ static void mark_powerless_hue_after_conversion(
|
|||
StyleValue const& style_value, PolarColorSpace polar_color_space,
|
||||
ComponentCategories const& target_categories)
|
||||
{
|
||||
if (style_value.is_color() && color_type_matches_polar_space(style_value.as_color().color_type(), polar_color_space))
|
||||
return;
|
||||
if (style_value.is_color()) {
|
||||
auto color_type = style_value.as_color().color_type();
|
||||
if (color_type.has_value() && color_type_matches_polar_space(*color_type, polar_color_space))
|
||||
return;
|
||||
}
|
||||
|
||||
bool has_zero_colorfulness = false;
|
||||
for (size_t i = 0; i < 3; ++i) {
|
||||
|
|
@ -676,7 +685,10 @@ static ColorSyntax color_syntax_for_interpolation(StyleValue const& style_value)
|
|||
return ColorSyntax::Legacy;
|
||||
|
||||
auto const& color = style_value.as_color();
|
||||
switch (color.color_type()) {
|
||||
auto color_type = color.color_type();
|
||||
if (!color_type.has_value())
|
||||
return color.color_syntax();
|
||||
switch (*color_type) {
|
||||
case ColorStyleValue::ColorType::RGB:
|
||||
case ColorStyleValue::ColorType::HSL:
|
||||
case ColorStyleValue::ColorType::HWB:
|
||||
|
|
@ -688,8 +700,11 @@ static ColorSyntax color_syntax_for_interpolation(StyleValue const& style_value)
|
|||
|
||||
static ComponentCategories source_categories_for_interpolation(StyleValue const& style_value)
|
||||
{
|
||||
if (style_value.is_color())
|
||||
return categories_for_color_type(style_value.as_color().color_type());
|
||||
if (style_value.is_color()) {
|
||||
if (auto color_type = style_value.as_color().color_type(); color_type.has_value())
|
||||
return categories_for_color_type(*color_type);
|
||||
return { ComponentCategory::NotAnalogous, ComponentCategory::NotAnalogous, ComponentCategory::NotAnalogous };
|
||||
}
|
||||
return { ComponentCategory::Red, ComponentCategory::Green, ComponentCategory::Blue };
|
||||
}
|
||||
|
||||
|
|
@ -742,7 +757,7 @@ static Optional<Gfx::ColorComponents> resolve_interpolation_color_to_srgb(
|
|||
if (color.native_components.has_value()) {
|
||||
color.srgb_components = native_components_to_srgb(
|
||||
color.native_components.value(),
|
||||
style_value.as_color().color_type());
|
||||
style_value.as_color().color_type().value());
|
||||
return color.srgb_components;
|
||||
}
|
||||
|
||||
|
|
@ -792,7 +807,7 @@ static Gfx::ColorComponents convert_interpolation_color_to_rectangular_space(
|
|||
ColorResolutionContext const& color_resolution_context)
|
||||
{
|
||||
if (color.native_components.has_value() && style_value.is_color()
|
||||
&& color_type_matches_rectangular_space(style_value.as_color().color_type(), space)) {
|
||||
&& color_type_matches_rectangular_space(style_value.as_color().color_type().value(), space)) {
|
||||
return color.native_components.value();
|
||||
}
|
||||
|
||||
|
|
@ -808,7 +823,7 @@ static Gfx::ColorComponents convert_interpolation_color_to_polar_space(
|
|||
ColorResolutionContext const& color_resolution_context)
|
||||
{
|
||||
if (color.native_components.has_value() && style_value.is_color()
|
||||
&& color_type_matches_polar_space(style_value.as_color().color_type(), space)) {
|
||||
&& color_type_matches_polar_space(style_value.as_color().color_type().value(), space)) {
|
||||
return color.native_components.value();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ Optional<Color> ColorFunctionStyleValue::to_color(ColorResolutionContext color_r
|
|||
|
||||
auto [c1, c2, c3, alpha] = *resolved;
|
||||
|
||||
switch (color_type()) {
|
||||
switch (*color_type()) {
|
||||
case ColorType::RGB:
|
||||
return Color(clamp_to_byte(c1), clamp_to_byte(c2), clamp_to_byte(c3), fraction_to_byte(alpha));
|
||||
case ColorType::HSL:
|
||||
|
|
@ -148,9 +148,6 @@ Optional<Color> ColorFunctionStyleValue::to_color(ColorResolutionContext color_r
|
|||
return Color::from_xyz50(c1, c2, c3, alpha);
|
||||
case ColorType::XYZD65:
|
||||
return Color::from_xyz65(c1, c2, c3, alpha);
|
||||
case ColorType::LightDark:
|
||||
case ColorType::ColorMix:
|
||||
break;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
|
@ -245,14 +242,14 @@ ValueComparingNonnullRefPtr<StyleValue const> ColorFunctionStyleValue::absolutiz
|
|||
if (!c1.has_value() || !c2.has_value() || !c3.has_value() || !alpha.has_value())
|
||||
VERIFY_NOT_REACHED();
|
||||
|
||||
if (color_type() == ColorType::HSL)
|
||||
if (*color_type() == ColorType::HSL)
|
||||
return hsl_to_absolutized_rgb(*c1, *c2, *c3, *alpha);
|
||||
return hwb_to_absolutized_rgb(*c1, *c2, *c3, *alpha);
|
||||
}
|
||||
|
||||
if (absolutized_c1 == m_channels[0] && absolutized_c2 == m_channels[1] && absolutized_c3 == m_channels[2] && absolutized_alpha == m_alpha)
|
||||
return *this;
|
||||
return create(color_type(), move(absolutized_c1), move(absolutized_c2), move(absolutized_c3), move(absolutized_alpha), color_syntax(), m_name);
|
||||
return create(*color_type(), move(absolutized_c1), move(absolutized_c2), move(absolutized_c3), move(absolutized_alpha), color_syntax(), m_name);
|
||||
}
|
||||
|
||||
bool ColorFunctionStyleValue::equals(StyleValue const& other) const
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public:
|
|||
StyleValue const& alpha() const { return *m_alpha; }
|
||||
Optional<FlyString> const& name() const { return m_name; }
|
||||
|
||||
ColorFunctionDescriptor const& descriptor() const { return color_function_descriptor_for(color_type()); }
|
||||
ColorFunctionDescriptor const& descriptor() const { return color_function_descriptor_for(*color_type()); }
|
||||
|
||||
virtual Optional<Color> to_color(ColorResolutionContext) const override;
|
||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const&) const override;
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ ValueComparingNonnullRefPtr<ColorMixStyleValue const> ColorMixStyleValue::create
|
|||
}
|
||||
|
||||
ColorMixStyleValue::ColorMixStyleValue(RefPtr<StyleValue const> color_interpolation_method, ColorMixComponent first_component, ColorMixComponent second_component)
|
||||
: ColorStyleValue(ColorType::ColorMix, ColorSyntax::Modern)
|
||||
: ColorStyleValue({}, ColorSyntax::Modern)
|
||||
, m_properties {
|
||||
.color_interpolation_method = move(color_interpolation_method),
|
||||
.first_component = move(first_component),
|
||||
|
|
@ -31,13 +31,10 @@ ColorMixStyleValue::ColorMixStyleValue(RefPtr<StyleValue const> color_interpolat
|
|||
|
||||
bool ColorMixStyleValue::equals(StyleValue const& other) const
|
||||
{
|
||||
if (type() != other.type())
|
||||
auto const* other_color_mix = as_if<ColorMixStyleValue>(other);
|
||||
if (!other_color_mix)
|
||||
return false;
|
||||
auto const& other_color = other.as_color();
|
||||
if (color_type() != other_color.color_type())
|
||||
return false;
|
||||
auto const& other_color_mix = as<ColorMixStyleValue>(other_color);
|
||||
return m_properties == other_color_mix.m_properties;
|
||||
return m_properties == other_color_mix->m_properties;
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-color-5/#serial-color-mix
|
||||
|
|
|
|||
|
|
@ -44,10 +44,8 @@ public:
|
|||
Rec2020,
|
||||
XYZD50,
|
||||
XYZD65,
|
||||
LightDark, // This is used by LightDarkStyleValue for light-dark(..., ...).
|
||||
ColorMix,
|
||||
};
|
||||
ColorType color_type() const { return m_color_type; }
|
||||
Optional<ColorType> color_type() const { return m_color_type; }
|
||||
ColorSyntax color_syntax() const { return m_color_syntax; }
|
||||
|
||||
static Optional<double> resolve_hue(StyleValue const&, CalculationResolutionContext const&);
|
||||
|
|
@ -55,7 +53,7 @@ public:
|
|||
static Optional<double> resolve_alpha(StyleValue const&, CalculationResolutionContext const&);
|
||||
|
||||
protected:
|
||||
explicit ColorStyleValue(ColorType color_type, ColorSyntax color_syntax)
|
||||
explicit ColorStyleValue(Optional<ColorType> color_type, ColorSyntax color_syntax)
|
||||
: StyleValue(Type::Color)
|
||||
, m_color_type(color_type)
|
||||
, m_color_syntax(color_syntax)
|
||||
|
|
@ -66,7 +64,7 @@ protected:
|
|||
void serialize_alpha_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component) const;
|
||||
void serialize_hue_component(StringBuilder& builder, SerializationMode mode, StyleValue const& component) const;
|
||||
|
||||
ColorType m_color_type;
|
||||
Optional<ColorType> m_color_type;
|
||||
ColorSyntax m_color_syntax;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -30,13 +30,10 @@ ValueComparingNonnullRefPtr<StyleValue const> LightDarkStyleValue::absolutized(C
|
|||
|
||||
bool LightDarkStyleValue::equals(StyleValue const& other) const
|
||||
{
|
||||
if (type() != other.type())
|
||||
auto const* other_light_dark = as_if<LightDarkStyleValue>(other);
|
||||
if (!other_light_dark)
|
||||
return false;
|
||||
auto const& other_color = other.as_color();
|
||||
if (color_type() != other_color.color_type())
|
||||
return false;
|
||||
auto const& other_light_dark = as<LightDarkStyleValue>(other_color);
|
||||
return m_properties == other_light_dark.m_properties;
|
||||
return m_properties == other_light_dark->m_properties;
|
||||
}
|
||||
|
||||
void LightDarkStyleValue::serialize(StringBuilder& builder, SerializationMode mode) const
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
private:
|
||||
LightDarkStyleValue(ValueComparingNonnullRefPtr<StyleValue const> light, ValueComparingNonnullRefPtr<StyleValue const> dark)
|
||||
: ColorStyleValue(ColorStyleValue::ColorType::LightDark, ColorSyntax::Modern)
|
||||
: ColorStyleValue({}, ColorSyntax::Modern)
|
||||
, m_properties { .light = move(light), .dark = move(dark) }
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue