From 892bfe9349b1af660a2614000c8aba22485cff5c Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 9 Jan 2025 17:23:20 +0000 Subject: [PATCH] LibWeb/CSS: Use CalcSV's context to determine what percentages are This lets us implement the `matches_number()` and `matches_dimension()` methods of `CSSNumericType` to spec, instead of being an ad-hoc hack. --- Libraries/LibWeb/CSS/CSSNumericType.cpp | 80 +++++++++++-------- Libraries/LibWeb/CSS/CSSNumericType.h | 26 +++--- .../CSS/StyleValues/CalculatedStyleValue.cpp | 30 +++---- .../CSS/StyleValues/CalculatedStyleValue.h | 24 +++--- .../LibWeb/GenerateCSSMathFunctions.cpp | 15 ++-- 5 files changed, 97 insertions(+), 78 deletions(-) diff --git a/Libraries/LibWeb/CSS/CSSNumericType.cpp b/Libraries/LibWeb/CSS/CSSNumericType.cpp index 40780b5cefdd2..7064acb032494 100644 --- a/Libraries/LibWeb/CSS/CSSNumericType.cpp +++ b/Libraries/LibWeb/CSS/CSSNumericType.cpp @@ -5,11 +5,9 @@ */ #include "CSSNumericType.h" -#include #include #include #include -#include #include #include @@ -374,26 +372,47 @@ Optional CSSNumericType::entry_with_value_1_while_all_ return result; } +static bool matches(CSSNumericType::BaseType base_type, ValueType value_type) +{ + switch (base_type) { + case CSSNumericType::BaseType::Length: + return value_type == ValueType::Length; + case CSSNumericType::BaseType::Angle: + return value_type == ValueType::Angle; + case CSSNumericType::BaseType::Time: + return value_type == ValueType::Time; + case CSSNumericType::BaseType::Frequency: + return value_type == ValueType::Frequency; + case CSSNumericType::BaseType::Resolution: + return value_type == ValueType::Resolution; + case CSSNumericType::BaseType::Flex: + return value_type == ValueType::Flex; + case CSSNumericType::BaseType::Percent: + return value_type == ValueType::Percentage; + case CSSNumericType::BaseType::__Count: + default: + return false; + } +} + // https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-match -bool CSSNumericType::matches_dimension(BaseType type) const +bool CSSNumericType::matches_dimension(BaseType type, Optional percentages_resolve_as) const { // A type matches if its only non-zero entry is «[ "length" → 1 ]». // Similarly for ,