LibWeb: Resolve unresolved style values when animating properties

This commit is contained in:
Matthew Olsson 2024-03-17 17:32:01 -07:00 committed by Andreas Kling
parent b2fb9cc7d3
commit 3dd9f2715f
Notes: sideshowbarker 2024-07-17 03:03:37 +09:00
3 changed files with 17 additions and 12 deletions

View File

@ -894,26 +894,27 @@ static CSS::RequiredInvalidationAfterStyleChange compute_required_invalidation(H
void KeyframeEffect::update_style_properties() void KeyframeEffect::update_style_properties()
{ {
if (!target()) auto target = this->target();
if (!target)
return; return;
if (pseudo_element_type().has_value()) { if (pseudo_element_type().has_value()) {
// StyleProperties are not saved for pseudo-elements so there is nothing to patch // StyleProperties are not saved for pseudo-elements so there is nothing to patch
target()->invalidate_style(); target->invalidate_style();
return; return;
} }
auto* style = target()->computed_css_values(); auto* style = target->computed_css_values();
if (!style) if (!style)
return; return;
auto animated_properties_before_update = style->animated_property_values(); auto animated_properties_before_update = style->animated_property_values();
auto& document = target()->document(); auto& document = target->document();
document.style_computer().collect_animation_into(*this, *style, CSS::StyleComputer::AnimationRefresh::Yes); document.style_computer().collect_animation_into(*target, pseudo_element_type(), *this, *style, CSS::StyleComputer::AnimationRefresh::Yes);
// Traversal of the subtree is necessary to update the animated properties inherited from the target element. // Traversal of the subtree is necessary to update the animated properties inherited from the target element.
target()->for_each_in_subtree_of_type<DOM::Element>([&](auto& element) { target->for_each_in_subtree_of_type<DOM::Element>([&](auto& element) {
auto* element_style = element.computed_css_values(); auto* element_style = element.computed_css_values();
if (!element_style || !element.layout_node()) if (!element_style || !element.layout_node())
return IterationDecision::Continue; return IterationDecision::Continue;
@ -931,8 +932,8 @@ void KeyframeEffect::update_style_properties()
auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values()); auto invalidation = compute_required_invalidation(animated_properties_before_update, style->animated_property_values());
if (target()->layout_node()) if (target->layout_node())
target()->layout_node()->apply_style(*style); target->layout_node()->apply_style(*style);
if (invalidation.relayout) if (invalidation.relayout)
document.set_needs_layout(); document.set_needs_layout();

View File

@ -1293,7 +1293,7 @@ static ValueComparingRefPtr<StyleValue const> interpolate_property(DOM::Element&
} }
} }
void StyleComputer::collect_animation_into(JS::NonnullGCPtr<Animations::KeyframeEffect> effect, StyleProperties& style_properties, AnimationRefresh refresh) const void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::Selector::PseudoElement::Type> pseudo_element, JS::NonnullGCPtr<Animations::KeyframeEffect> effect, StyleProperties& style_properties, AnimationRefresh refresh) const
{ {
auto animation = effect->associated_animation(); auto animation = effect->associated_animation();
if (!animation) if (!animation)
@ -1350,7 +1350,11 @@ void StyleComputer::collect_animation_into(JS::NonnullGCPtr<Animations::Keyframe
return {}; return {};
return style_properties.maybe_null_property(it.key); return style_properties.maybe_null_property(it.key);
}, },
[&](RefPtr<StyleValue const> value) { return value; }); [&](RefPtr<StyleValue const> value) -> RefPtr<StyleValue const> {
if (value->is_unresolved())
return Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { element.document() }, element, pseudo_element, it.key, value->as_unresolved());
return value;
});
}; };
auto resolved_start_property = resolve_property(it.value); auto resolved_start_property = resolve_property(it.value);
@ -1565,7 +1569,7 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element
if (auto effect = animation->effect(); effect && effect->is_keyframe_effect()) { if (auto effect = animation->effect(); effect && effect->is_keyframe_effect()) {
auto& keyframe_effect = *static_cast<Animations::KeyframeEffect*>(effect.ptr()); auto& keyframe_effect = *static_cast<Animations::KeyframeEffect*>(effect.ptr());
if (keyframe_effect.pseudo_element_type() == pseudo_element) if (keyframe_effect.pseudo_element_type() == pseudo_element)
collect_animation_into(keyframe_effect, style); collect_animation_into(element, pseudo_element, keyframe_effect, style);
} }
} }

View File

@ -92,7 +92,7 @@ public:
No, No,
Yes, Yes,
}; };
void collect_animation_into(JS::NonnullGCPtr<Animations::KeyframeEffect> animation, StyleProperties& style_properties, AnimationRefresh = AnimationRefresh::No) const; void collect_animation_into(DOM::Element&, Optional<CSS::Selector::PseudoElement::Type>, JS::NonnullGCPtr<Animations::KeyframeEffect> animation, StyleProperties& style_properties, AnimationRefresh = AnimationRefresh::No) const;
private: private:
enum class ComputeStyleMode { enum class ComputeStyleMode {