diff --git a/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp b/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp index 5479155d12..b2a2ad8ddf 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSNumericType.cpp @@ -413,6 +413,32 @@ bool CSSNumericType::matches_number_percentage() const return true; } +bool CSSNumericType::matches_dimension() const +{ + // This isn't a spec algorithm. + // A type should match `` if there are no non-zero entries, + // or it has a single non-zero entry (other than percent) which is equal to 1. + + auto number_of_one_exponents = 0; + + for (auto i = 0; i < to_underlying(BaseType::__Count); ++i) { + auto base_type = static_cast(i); + auto type_exponent = exponent(base_type); + if (!type_exponent.has_value()) + continue; + + if (type_exponent == 1) { + if (base_type == BaseType::Percent) + return false; + number_of_one_exponents++; + } else if (type_exponent != 0) { + return false; + } + } + + return number_of_one_exponents == 0 || number_of_one_exponents == 1; +} + ErrorOr CSSNumericType::dump() const { StringBuilder builder; diff --git a/Userland/Libraries/LibWeb/CSS/CSSNumericType.h b/Userland/Libraries/LibWeb/CSS/CSSNumericType.h index c584efefab..e283870f8b 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSNumericType.h +++ b/Userland/Libraries/LibWeb/CSS/CSSNumericType.h @@ -79,6 +79,8 @@ public: bool matches_time() const { return matches_dimension(BaseType::Time); } bool matches_time_percentage() const { return matches_dimension_percentage(BaseType::Time); } + bool matches_dimension() const; + Optional const& exponent(BaseType type) const { return m_type_exponents[to_underlying(type)]; } void set_exponent(BaseType type, i32 exponent) { m_type_exponents[to_underlying(type)] = exponent; }