LibWeb: Absolutize keyframe values before interpolating

This commit is contained in:
Tim Ledbetter 2025-06-24 11:11:17 +01:00 committed by Sam Atkins
commit b46378085d
Notes: github-actions[bot] 2025-06-24 11:38:03 +00:00
8 changed files with 1428 additions and 4 deletions

View file

@ -819,7 +819,6 @@ static RefPtr<CSSStyleValue const> interpolate_value_impl(DOM::Element& element,
return IntegerStyleValue::create(round_to<i64>(interpolated_value));
}
case CSSStyleValue::Type::Length: {
// FIXME: Absolutize values
auto const& from_length = from.as_length().length();
auto const& to_length = to.as_length().length();
return LengthStyleValue::create(Length(interpolate_raw(from_length.raw_value(), to_length.raw_value(), delta), from_length.type()));
@ -865,7 +864,6 @@ static RefPtr<CSSStyleValue const> interpolate_value_impl(DOM::Element& element,
if (from_rect.top_edge.is_auto() != to_rect.top_edge.is_auto() || from_rect.right_edge.is_auto() != to_rect.right_edge.is_auto() || from_rect.bottom_edge.is_auto() != to_rect.bottom_edge.is_auto() || from_rect.left_edge.is_auto() != to_rect.left_edge.is_auto())
return {};
// FIXME: Absolutize values
return RectStyleValue::create({
Length(interpolate_raw(from_rect.top_edge.raw_value(), to_rect.top_edge.raw_value(), delta), from_rect.top_edge.type()),
Length(interpolate_raw(from_rect.right_edge.raw_value(), to_rect.right_edge.raw_value(), delta), from_rect.right_edge.type()),

View file

@ -1358,7 +1358,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
}
// FIXME: Follow https://drafts.csswg.org/web-animations-1/#ref-for-computed-keyframes in whatever the right place is.
auto compute_keyframe_values = [refresh, &computed_properties, &element, &pseudo_element](auto const& keyframe_values) {
auto compute_keyframe_values = [refresh, &computed_properties, &element, &pseudo_element, this](auto const& keyframe_values) {
HashMap<PropertyID, RefPtr<CSSStyleValue const>> result;
HashMap<PropertyID, PropertyID> longhands_set_by_property_id;
auto property_is_set_by_use_initial = MUST(Bitmap::create(to_underlying(last_longhand_property_id) - to_underlying(first_longhand_property_id) + 1, false));
@ -1400,6 +1400,11 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
return camel_case_string_from_property_id(a) < camel_case_string_from_property_id(b);
};
compute_font(computed_properties, &element, pseudo_element);
Length::FontMetrics font_metrics {
root_element_font_metrics_for_element(element).font_size,
computed_properties.first_available_computed_font().pixel_metrics()
};
for (auto const& [property_id, value] : keyframe_values.properties) {
bool is_use_initial = false;
@ -1445,7 +1450,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
longhands_set_by_property_id.set(physical_longhand_id, property_id);
property_is_set_by_use_initial.set(physical_longhand_id_bitmap_index, is_use_initial);
result.set(physical_longhand_id, { longhand_value });
result.set(physical_longhand_id, { longhand_value.absolutized(viewport_rect(), font_metrics, m_root_element_font_metrics) });
});
}
return result;