LibWeb/CSS: Add a Property -> CalculationContext factory method

We have this code duplicated in multiple places, and we'll want to
handle registered custom properties too at some point, so wrap it in a
reusable `CalculationContext::for_property()` method.

Noticed while doing this that ValueParsingContext will eventually need
to take a PropertyNameAndID, not a PropertyID, so I've added a FIXME.
This commit is contained in:
Sam Atkins 2025-10-10 16:04:51 +01:00
commit 0afa93e639
Notes: github-actions[bot] 2025-10-13 09:01:24 +00:00
6 changed files with 19 additions and 15 deletions

View file

@ -22,6 +22,7 @@
#include <LibWeb/CSS/CSSUnitValue.h>
#include <LibWeb/CSS/Percentage.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/PropertyNameAndID.h>
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
@ -34,6 +35,16 @@
namespace Web::CSS {
CalculationContext CalculationContext::for_property(PropertyNameAndID const& property)
{
// FIXME: Handle registered custom properties, which may limit which types they accept.
return {
.percentages_resolve_as = property_resolves_percentages_relative_to(property.id()),
.resolve_numbers_as_integers = property_accepts_type(property.id(), ValueType::Integer),
.accepted_type_ranges = property_accepted_type_ranges(property.id()),
};
}
static Optional<NumericType> add_the_types(Vector<NonnullRefPtr<CalculationNode const>> const& nodes)
{
Optional<NumericType> left_type;