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

@ -1,7 +1,7 @@
/*
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2021, the SerenityOS developers.
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
* Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
*
@ -11,6 +11,7 @@
#include "Interpolation.h"
#include <AK/IntegralMath.h>
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/PropertyNameAndID.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
@ -600,10 +601,7 @@ ValueComparingRefPtr<StyleValue const> interpolate_property(DOM::Element& elemen
auto from = with_keyword_values_resolved(element, property_id, a_from);
auto to = with_keyword_values_resolved(element, property_id, a_to);
CalculationContext calculation_context {
.percentages_resolve_as = property_resolves_percentages_relative_to(property_id),
.accepted_type_ranges = property_accepted_type_ranges(property_id),
};
auto calculation_context = CalculationContext::for_property(PropertyNameAndID::from_id(property_id));
auto animation_type = animation_type_from_longhand_property(property_id);
switch (animation_type) {