From b3c099bd68a4969835155a72a62673b308b17143 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Tue, 2 Sep 2025 13:58:20 +0100 Subject: [PATCH] LibWeb/CSS: Use dimension_for_unit() when we don't need the exact unit A small code reduction, and means that NumericType will catch if new dimensions are added, and attr() will just work in that case. --- Libraries/LibWeb/CSS/NumericType.cpp | 56 +++++++++---------- .../Parser/ArbitrarySubstitutionFunctions.cpp | 7 +-- 2 files changed, 28 insertions(+), 35 deletions(-) diff --git a/Libraries/LibWeb/CSS/NumericType.cpp b/Libraries/LibWeb/CSS/NumericType.cpp index 0e2f0ef585b..46c40638f6d 100644 --- a/Libraries/LibWeb/CSS/NumericType.cpp +++ b/Libraries/LibWeb/CSS/NumericType.cpp @@ -55,40 +55,38 @@ Optional NumericType::create_from_unit(StringView unit) return NumericType { BaseType::Percent, 1 }; } - // unit is a unit - if (string_to_length_unit(unit).has_value()) { - // Return «[ "length" → 1 ]» - return NumericType { BaseType::Length, 1 }; - } + if (auto dimension = dimension_for_unit(unit); dimension.has_value()) { + switch (*dimension) { + // unit is a unit + case DimensionType::Length: + // Return «[ "length" → 1 ]» + return NumericType { BaseType::Length, 1 }; - // unit is an unit - if (string_to_angle_unit(unit).has_value()) { - // Return «[ "angle" → 1 ]» - return NumericType { BaseType::Angle, 1 }; - } + // unit is an unit + case DimensionType::Angle: + // Return «[ "angle" → 1 ]» + return NumericType { BaseType::Angle, 1 }; - // unit is a