diff --git a/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp b/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp index bf10fc0e5ad..758cd2c9b8c 100644 --- a/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp +++ b/Libraries/LibWeb/CSS/StyleValues/CalculatedStyleValue.cpp @@ -2669,6 +2669,30 @@ bool CalculatedStyleValue::equals(CSSStyleValue const& other) const return m_calculation->equals(*other.as_calculated().m_calculation); } +// https://drafts.csswg.org/css-values-4/#calc-computed-value +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); + + if (!is(*simplified_tree)) + return {}; + + auto value = try_get_value_with_canonical_unit(simplified_tree, m_context, resolution_context); + + VERIFY(value.has_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. + + // https://drafts.csswg.org/css-values/#calc-range + // FIXME: the value resulting from a top-level calculation must be clamped to the range allowed in the target + // 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; +} + Optional CalculatedStyleValue::resolve_angle_deprecated(CalculationResolutionContext const& context) const { auto result = m_calculation->resolve(context); @@ -2677,6 +2701,16 @@ Optional CalculatedStyleValue::resolve_angle_deprecated(CalculationResolu return {}; } +Optional CalculatedStyleValue::resolve_angle(CalculationResolutionContext const& context) const +{ + 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()); + + return {}; +} + Optional CalculatedStyleValue::resolve_flex_deprecated(CalculationResolutionContext const& context) const { auto result = m_calculation->resolve(context); @@ -2685,6 +2719,16 @@ Optional CalculatedStyleValue::resolve_flex_deprecated(CalculationResoluti return {}; } +Optional CalculatedStyleValue::resolve_flex(CalculationResolutionContext const& context) const +{ + 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()); + + return {}; +} + Optional CalculatedStyleValue::resolve_frequency_deprecated(CalculationResolutionContext const& context) const { auto result = m_calculation->resolve(context); @@ -2693,6 +2737,16 @@ Optional CalculatedStyleValue::resolve_frequency_deprecated(Calculati return {}; } +Optional CalculatedStyleValue::resolve_frequency(CalculationResolutionContext const& context) const +{ + 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()); + + return {}; +} + Optional CalculatedStyleValue::resolve_length_deprecated(CalculationResolutionContext const& context) const { auto result = m_calculation->resolve(context); @@ -2701,6 +2755,16 @@ Optional CalculatedStyleValue::resolve_length_deprecated(CalculationReso return {}; } +Optional CalculatedStyleValue::resolve_length(CalculationResolutionContext const& context) const +{ + 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()); + + return {}; +} + Optional CalculatedStyleValue::resolve_percentage_deprecated(CalculationResolutionContext const& context) const { auto result = m_calculation->resolve(context); @@ -2709,6 +2773,16 @@ Optional CalculatedStyleValue::resolve_percentage_deprecated(Calcula return {}; } +Optional CalculatedStyleValue::resolve_percentage(CalculationResolutionContext const& context) const +{ + auto result = resolve_value(context); + + if (result.has_value() && result.value().type().has_value() && result.value().type()->matches_percentage()) + return Percentage { result.value().value() }; + + return {}; +} + Optional CalculatedStyleValue::resolve_resolution_deprecated(CalculationResolutionContext const& context) const { auto result = m_calculation->resolve(context); @@ -2717,6 +2791,16 @@ Optional CalculatedStyleValue::resolve_resolution_deprecated(Calcula return {}; } +Optional CalculatedStyleValue::resolve_resolution(CalculationResolutionContext const& context) const +{ + 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()); + + return {}; +} + Optional