From 5bdc2981e3ad73a879d40de4797a939ea59091a3 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 15 Aug 2025 12:55:58 +0100 Subject: [PATCH] LibWeb/CSS: Rename CSSNumericType to NumericType The CSSNumericType defined in the spec is a simple dictionary which is only used for OM purposes. This NumericType class is used internally and matches the more abstract definition of a "type". --- Libraries/LibWeb/CMakeLists.txt | 2 +- Libraries/LibWeb/CSS/Interpolation.cpp | 16 +-- .../{CSSNumericType.cpp => NumericType.cpp} | 86 +++++------ .../CSS/{CSSNumericType.h => NumericType.h} | 34 +++-- .../LibWeb/CSS/Parser/PropertyParsing.cpp | 2 +- .../CSS/StyleValues/CalculatedStyleValue.cpp | 134 +++++++++--------- .../CSS/StyleValues/CalculatedStyleValue.h | 46 +++--- .../LibWeb/CSS/StyleValues/EdgeStyleValue.cpp | 2 +- Libraries/LibWeb/Forward.h | 1 + .../LibWeb/GenerateCSSMathFunctions.cpp | 4 +- 10 files changed, 163 insertions(+), 164 deletions(-) rename Libraries/LibWeb/CSS/{CSSNumericType.cpp => NumericType.cpp} (87%) rename Libraries/LibWeb/CSS/{CSSNumericType.h => NumericType.h} (78%) diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index cab0761aed1..3be8ef08c7d 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -119,7 +119,6 @@ set(SOURCES CSS/CSSMediaRule.cpp CSS/CSSNamespaceRule.cpp CSS/CSSNestedDeclarations.cpp - CSS/CSSNumericType.cpp CSS/CSSPageRule.cpp CSS/CSSPageDescriptors.cpp CSS/CSSPropertyRule.cpp @@ -153,6 +152,7 @@ set(SOURCES CSS/MediaQueryList.cpp CSS/MediaQueryListEvent.cpp CSS/Number.cpp + CSS/NumericType.cpp CSS/PageSelector.cpp CSS/ParsedFontFace.cpp CSS/Parser/ArbitrarySubstitutionFunctions.cpp diff --git a/Libraries/LibWeb/CSS/Interpolation.cpp b/Libraries/LibWeb/CSS/Interpolation.cpp index bc9b6293e52..6a2fed7b530 100644 --- a/Libraries/LibWeb/CSS/Interpolation.cpp +++ b/Libraries/LibWeb/CSS/Interpolation.cpp @@ -1023,30 +1023,30 @@ static RefPtr interpolate_value_impl(DOM::Element& element, Ca // https://www.w3.org/TR/css-values-4/#mixed-percentages struct NumericBaseTypeAndDefault { - CSSNumericType::BaseType base_type; + NumericType::BaseType base_type; ValueComparingNonnullRefPtr default_value; }; static constexpr auto numeric_base_type_and_default = [](StyleValue const& value) -> Optional { switch (value.type()) { case StyleValue::Type::Angle: { static auto default_angle_value = AngleStyleValue::create(Angle::make_degrees(0)); - return NumericBaseTypeAndDefault { CSSNumericType::BaseType::Angle, default_angle_value }; + return NumericBaseTypeAndDefault { NumericType::BaseType::Angle, default_angle_value }; } case StyleValue::Type::Frequency: { static auto default_frequency_value = FrequencyStyleValue::create(Frequency::make_hertz(0)); - return NumericBaseTypeAndDefault { CSSNumericType::BaseType::Frequency, default_frequency_value }; + return NumericBaseTypeAndDefault { NumericType::BaseType::Frequency, default_frequency_value }; } case StyleValue::Type::Length: { static auto default_length_value = LengthStyleValue::create(Length::make_px(0)); - return NumericBaseTypeAndDefault { CSSNumericType::BaseType::Length, default_length_value }; + return NumericBaseTypeAndDefault { NumericType::BaseType::Length, default_length_value }; } case StyleValue::Type::Percentage: { static auto default_percentage_value = PercentageStyleValue::create(Percentage { 0.0 }); - return NumericBaseTypeAndDefault { CSSNumericType::BaseType::Percent, default_percentage_value }; + return NumericBaseTypeAndDefault { NumericType::BaseType::Percent, default_percentage_value }; } case StyleValue::Type::Time: { static auto default_time_value = TimeStyleValue::create(Time::make_seconds(0)); - return NumericBaseTypeAndDefault { CSSNumericType::BaseType::Time, default_time_value }; + return NumericBaseTypeAndDefault { NumericType::BaseType::Time, default_time_value }; } default: return {}; @@ -1073,7 +1073,7 @@ static RefPtr interpolate_value_impl(DOM::Element& element, Ca auto from_base_type_and_default = numeric_base_type_and_default(from); auto to_base_type_and_default = numeric_base_type_and_default(to); - if (from_base_type_and_default.has_value() && to_base_type_and_default.has_value() && (from_base_type_and_default->base_type == CSSNumericType::BaseType::Percent || to_base_type_and_default->base_type == CSSNumericType::BaseType::Percent)) { + if (from_base_type_and_default.has_value() && to_base_type_and_default.has_value() && (from_base_type_and_default->base_type == NumericType::BaseType::Percent || to_base_type_and_default->base_type == NumericType::BaseType::Percent)) { // This is an interpolation from a numeric unit to a percentage, or vice versa. The trick here is to // interpolate two separate values. For example, consider an interpolation from 30px to 80%. It's quite // hard to understand how this interpolation works, but if instead we rewrite the values as "30px + 0%" and @@ -1089,7 +1089,7 @@ static RefPtr interpolate_value_impl(DOM::Element& element, Ca values.unchecked_append(to_calculation_node(*interpolated_from)); values.unchecked_append(to_calculation_node(*interpolated_to)); auto calc_node = SumCalculationNode::create(move(values)); - return CalculatedStyleValue::create(move(calc_node), CSSNumericType { to_base_type_and_default->base_type, 1 }, calculation_context); + return CalculatedStyleValue::create(move(calc_node), NumericType { to_base_type_and_default->base_type, 1 }, calculation_context); } return {}; diff --git a/Libraries/LibWeb/CSS/CSSNumericType.cpp b/Libraries/LibWeb/CSS/NumericType.cpp similarity index 87% rename from Libraries/LibWeb/CSS/CSSNumericType.cpp rename to Libraries/LibWeb/CSS/NumericType.cpp index 5b2a4361254..45ea328e21e 100644 --- a/Libraries/LibWeb/CSS/CSSNumericType.cpp +++ b/Libraries/LibWeb/CSS/NumericType.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "CSSNumericType.h" +#include "NumericType.h" #include #include #include @@ -14,7 +14,7 @@ namespace Web::CSS { -Optional CSSNumericType::base_type_from_value_type(ValueType value_type) +Optional NumericType::base_type_from_value_type(ValueType value_type) { switch (value_type) { case ValueType::Angle: @@ -38,50 +38,50 @@ Optional CSSNumericType::base_type_from_value_type(Val } // https://drafts.css-houdini.org/css-typed-om-1/#cssnumericvalue-create-a-type -Optional CSSNumericType::create_from_unit(StringView unit) +Optional NumericType::create_from_unit(StringView unit) { // To create a type from a string unit, follow the appropriate branch of the following: // unit is "number" if (unit == "number"sv) { // Return «[ ]» (empty map) - return CSSNumericType {}; + return NumericType {}; } // unit is "percent" if (unit == "percent"sv) { // Return «[ "percent" → 1 ]» - return CSSNumericType { BaseType::Percent, 1 }; + return NumericType { BaseType::Percent, 1 }; } // unit is a unit if (Length::unit_from_name(unit).has_value()) { // Return «[ "length" → 1 ]» - return CSSNumericType { BaseType::Length, 1 }; + return NumericType { BaseType::Length, 1 }; } // unit is an unit if (Angle::unit_from_name(unit).has_value()) { // Return «[ "angle" → 1 ]» - return CSSNumericType { BaseType::Angle, 1 }; + return NumericType { BaseType::Angle, 1 }; } // unit is a