LibWeb: Implement css gradient-interpolation-method

This commit is contained in:
Gingeh 2025-02-19 21:02:12 +11:00 committed by Sam Atkins
commit 31853c13d3
Notes: github-actions[bot] 2025-03-06 11:34:14 +00:00
35 changed files with 499 additions and 101 deletions

View file

@ -13,6 +13,7 @@
#include <LibWeb/CSS/Enums.h>
#include <LibWeb/CSS/PercentageOr.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
namespace Web::CSS {
@ -48,6 +49,112 @@ enum class GradientRepeating {
No
};
enum class GradientSpace : u8 {
sRGB,
sRGBLinear,
DisplayP3,
A98RGB,
ProPhotoRGB,
Rec2020,
Lab,
OKLab,
XYZD50,
XYZD65,
HSL,
HWB,
LCH,
OKLCH,
};
enum class HueMethod : u8 {
Shorter,
Longer,
Increasing,
Decreasing,
};
struct InterpolationMethod {
GradientSpace color_space;
HueMethod hue_method = HueMethod::Shorter;
String to_string() const
{
StringBuilder builder;
switch (color_space) {
case GradientSpace::OKLab:
builder.append("in oklab"sv);
break;
case GradientSpace::sRGB:
builder.append("in srgb"sv);
break;
case GradientSpace::sRGBLinear:
builder.append("in srgb-linear"sv);
break;
case GradientSpace::DisplayP3:
builder.append("in display-p3"sv);
break;
case GradientSpace::A98RGB:
builder.append("in a98-rgb"sv);
break;
case GradientSpace::ProPhotoRGB:
builder.append("in prophoto-rgb"sv);
break;
case GradientSpace::Rec2020:
builder.append("in rec2020"sv);
break;
case GradientSpace::Lab:
builder.append("in lab"sv);
break;
case GradientSpace::XYZD50:
builder.append("in xyz-d50"sv);
break;
case GradientSpace::XYZD65:
builder.append("in xyz-d65"sv);
break;
case GradientSpace::HSL:
builder.append("in hsl"sv);
break;
case GradientSpace::HWB:
builder.append("in hwb"sv);
break;
case GradientSpace::LCH:
builder.append("in lch"sv);
break;
case GradientSpace::OKLCH:
builder.append("in oklch"sv);
break;
}
switch (hue_method) {
case HueMethod::Shorter:
// "shorter" is the default value and isn't serialized
break;
case HueMethod::Longer:
builder.append(" longer hue"sv);
break;
case HueMethod::Increasing:
builder.append(" increasing hue"sv);
break;
case HueMethod::Decreasing:
builder.append(" decreasing hue"sv);
break;
}
return MUST(builder.to_string());
}
static GradientSpace default_color_space(ColorSyntax color_syntax)
{
if (color_syntax == ColorSyntax::Legacy)
return GradientSpace::sRGB;
return GradientSpace::OKLab;
}
bool operator==(InterpolationMethod const&) const = default;
};
template<typename TPosition>
struct ColorStopListElement {
using PositionType = TPosition;