LibWeb: Allow passing a resolution context to CSSStyleValue::to_color

This will be used for resolving any calculated style values within the
various `CSSColorValue` sub-classes.

No functionality changes.
This commit is contained in:
Callum Law 2025-06-29 12:56:28 +12:00 committed by Sam Atkins
parent b468923372
commit 62d138ebf7
Notes: github-actions[bot] 2025-07-04 12:20:15 +00:00
33 changed files with 105 additions and 105 deletions

View file

@ -7,15 +7,16 @@
#include "CSSHWB.h"
#include <AK/TypeCasts.h>
#include <LibWeb/CSS/Serialize.h>
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
namespace Web::CSS {
Color CSSHWB::to_color(Optional<Layout::NodeWithStyle const&>) const
Color CSSHWB::to_color(Optional<Layout::NodeWithStyle const&>, CalculationResolutionContext const& resolution_context) const
{
auto const h_val = resolve_hue(m_properties.h).value_or(0);
auto const w_val = clamp(resolve_with_reference_value(m_properties.w, 100.0).value_or(0), 0, 100) / 100.0f;
auto const b_val = clamp(resolve_with_reference_value(m_properties.b, 100.0).value_or(0), 0, 100) / 100.0f;
auto const alpha_val = resolve_alpha(m_properties.alpha).value_or(1);
auto const h_val = resolve_hue(m_properties.h, resolution_context).value_or(0);
auto const w_val = clamp(resolve_with_reference_value(m_properties.w, 100.0, resolution_context).value_or(0), 0, 100) / 100.0f;
auto const b_val = clamp(resolve_with_reference_value(m_properties.b, 100.0, resolution_context).value_or(0), 0, 100) / 100.0f;
auto const alpha_val = resolve_alpha(m_properties.alpha, resolution_context).value_or(1);
if (w_val + b_val >= 1.0f) {
auto to_byte = [](float value) {
@ -45,7 +46,7 @@ bool CSSHWB::equals(CSSStyleValue const& other) const
String CSSHWB::to_string(SerializationMode) const
{
// FIXME: Do this properly, taking unresolved calculated values into account.
return serialize_a_srgb_value(to_color({}));
return serialize_a_srgb_value(to_color({}, {}));
}
}