From 90948405fc2020eecd5348017a46b3ca7c2751a9 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Wed, 6 Aug 2025 16:16:43 +1200 Subject: [PATCH] LibWeb: Return an intermediate struct from `CSV::resolve_value` Returning this struct will allow us to modify the underlying value of the `CalculationResult` without requiring us to go through the process of constructing a whole new `CalculationResult` to return. --- .../CSS/StyleValues/CalculatedStyleValue.cpp | 44 ++++++++++--------- .../CSS/StyleValues/CalculatedStyleValue.h | 8 +++- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp index 7690996787d..c8dae846660 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp @@ -2742,7 +2742,7 @@ bool CalculatedStyleValue::equals(StyleValue const& other) const } // https://drafts.csswg.org/css-values-4/#calc-computed-value -Optional CalculatedStyleValue::resolve_value(CalculationResolutionContext const& resolution_context) const +Optional CalculatedStyleValue::resolve_value(CalculationResolutionContext const& resolution_context) const { // The calculation tree is again simplified at used value time; with used value time information. auto simplified_tree = simplify_a_calculation_tree(m_calculation, m_context, resolution_context); @@ -2754,6 +2754,8 @@ Optional CalculatedStyleValue::resolve_ VERIFY(value.has_value()); + auto raw_value = value->value(); + // https://drafts.csswg.org/css-values/#calc-ieee // FIXME: NaN does not escape a top-level calculation; it’s censored into a zero value. @@ -2762,7 +2764,7 @@ Optional CalculatedStyleValue::resolve_ // context. Clamping is performed on computed values to the extent possible, and also on used values if // computation was unable to sufficiently simplify the expression to allow range-checking. - return value; + return ResolvedValue { raw_value, value->type() }; } Optional CalculatedStyleValue::resolve_angle_deprecated(CalculationResolutionContext const& context) const @@ -2777,8 +2779,8 @@ Optional CalculatedStyleValue::resolve_angle(CalculationResolutionContext { auto result = resolve_value(context); - if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_angle(m_context.percentages_resolve_as)) - return Angle::make_degrees(result.value().value()); + if (result.has_value() && result->type.has_value() && result->type->matches_angle(m_context.percentages_resolve_as)) + return Angle::make_degrees(result->value); return {}; } @@ -2795,8 +2797,8 @@ Optional CalculatedStyleValue::resolve_flex(CalculationResolutionContext c { auto result = resolve_value(context); - if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_flex(m_context.percentages_resolve_as)) - return Flex::make_fr(result.value().value()); + if (result.has_value() && result->type.has_value() && result->type->matches_flex(m_context.percentages_resolve_as)) + return Flex::make_fr(result->value); return {}; } @@ -2813,8 +2815,8 @@ Optional CalculatedStyleValue::resolve_frequency(CalculationResolutio { auto result = resolve_value(context); - if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_frequency(m_context.percentages_resolve_as)) - return Frequency::make_hertz(result.value().value()); + if (result.has_value() && result->type.has_value() && result->type->matches_frequency(m_context.percentages_resolve_as)) + return Frequency::make_hertz(result->value); return {}; } @@ -2831,8 +2833,8 @@ Optional CalculatedStyleValue::resolve_length(CalculationResolutionConte { auto result = resolve_value(context); - if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_length(m_context.percentages_resolve_as)) - return Length::make_px(result.value().value()); + if (result.has_value() && result->type.has_value() && result->type->matches_length(m_context.percentages_resolve_as)) + return Length::make_px(result->value); return {}; } @@ -2849,8 +2851,8 @@ Optional CalculatedStyleValue::resolve_percentage(CalculationResolut { auto result = resolve_value(context); - if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_percentage()) - return Percentage { result.value().value() }; + if (result.has_value() && result->type.has_value() && result->type->matches_percentage()) + return Percentage { result->value }; return {}; } @@ -2867,8 +2869,8 @@ Optional CalculatedStyleValue::resolve_resolution(CalculationResolut { auto result = resolve_value(context); - if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_resolution(m_context.percentages_resolve_as)) - return Resolution::make_dots_per_pixel(result.value().value()); + if (result.has_value() && result->type.has_value() && result->type->matches_resolution(m_context.percentages_resolve_as)) + return Resolution::make_dots_per_pixel(result->value); return {}; } @@ -2885,8 +2887,8 @@ Optional