LibWeb: Update to_color to take ColorResolutionContext

Using a generic context argument will allow us to resolve colors in
places where we have all the required information but not in the form of
a layout node as was expected previously.
This commit is contained in:
Callum Law 2025-07-19 11:31:07 +12:00 committed by Sam Atkins
commit 46153910ec
Notes: github-actions[bot] 2025-08-04 10:30:51 +00:00
31 changed files with 129 additions and 127 deletions

View file

@ -26,12 +26,12 @@ bool CSSLabLike::equals(CSSStyleValue const& other) const
return m_properties == other_lab_like.m_properties;
}
Optional<Color> CSSOKLab::to_color(Optional<Layout::NodeWithStyle const&>, CalculationResolutionContext const& resolution_context) const
Optional<Color> CSSOKLab::to_color(ColorResolutionContext color_resolution_context) const
{
auto const l_val = resolve_with_reference_value(m_properties.l, 1.0, resolution_context);
auto const a_val = resolve_with_reference_value(m_properties.a, 0.4, resolution_context);
auto const b_val = resolve_with_reference_value(m_properties.b, 0.4, resolution_context);
auto const alpha_val = resolve_alpha(m_properties.alpha, resolution_context);
auto const l_val = resolve_with_reference_value(m_properties.l, 1.0, color_resolution_context.calculation_resolution_context);
auto const a_val = resolve_with_reference_value(m_properties.a, 0.4, color_resolution_context.calculation_resolution_context);
auto const b_val = resolve_with_reference_value(m_properties.b, 0.4, color_resolution_context.calculation_resolution_context);
auto const alpha_val = resolve_alpha(m_properties.alpha, color_resolution_context.calculation_resolution_context);
if (!l_val.has_value() || !a_val.has_value() || !b_val.has_value() || !alpha_val.has_value())
return {};
@ -59,12 +59,12 @@ String CSSOKLab::to_string(SerializationMode mode) const
return MUST(builder.to_string());
}
Optional<Color> CSSLab::to_color(Optional<Layout::NodeWithStyle const&>, CalculationResolutionContext const& resolution_context) const
Optional<Color> CSSLab::to_color(ColorResolutionContext color_resolution_context) const
{
auto l_val = resolve_with_reference_value(m_properties.l, 100, resolution_context);
auto a_val = resolve_with_reference_value(m_properties.a, 125, resolution_context);
auto b_val = resolve_with_reference_value(m_properties.b, 125, resolution_context);
auto alpha_val = resolve_alpha(m_properties.alpha, resolution_context);
auto l_val = resolve_with_reference_value(m_properties.l, 100, color_resolution_context.calculation_resolution_context);
auto a_val = resolve_with_reference_value(m_properties.a, 125, color_resolution_context.calculation_resolution_context);
auto b_val = resolve_with_reference_value(m_properties.b, 125, color_resolution_context.calculation_resolution_context);
auto alpha_val = resolve_alpha(m_properties.alpha, color_resolution_context.calculation_resolution_context);
if (!l_val.has_value() || !a_val.has_value() || !b_val.has_value() || !alpha_val.has_value())
return {};