LibWeb: Separate CSSAnimation::animationName from Animation::id

This commit is contained in:
Callum Law 2025-10-30 21:10:36 +13:00 committed by Alexander Kalenik
parent 2447b8a759
commit a95cde3660
Notes: github-actions[bot] 2025-11-02 22:55:20 +00:00
5 changed files with 40 additions and 3 deletions

View file

@ -19,7 +19,8 @@ class CSSAnimation : public Animations::Animation {
public:
static GC::Ref<CSSAnimation> create(JS::Realm&);
FlyString const& animation_name() const { return id(); }
FlyString const& animation_name() const { return m_animation_name; }
void set_animation_name(FlyString const& animation_name) { m_animation_name = animation_name; }
virtual Animations::AnimationClass animation_class() const override;
virtual Optional<int> class_specific_composite_order(GC::Ref<Animations::Animation> other) const override;
@ -30,6 +31,9 @@ private:
virtual void initialize(JS::Realm&) override;
virtual bool is_css_animation() const override { return true; }
// https://drafts.csswg.org/css-animations-2/#dom-cssanimation-animationname
FlyString m_animation_name;
};
}

View file

@ -1235,7 +1235,7 @@ void StyleComputer::process_animation_definitions(ComputedProperties const& comp
// An animation applies to an element if its name appears as one of the identifiers in the computed value of the
// animation-name property and the animation uses a valid @keyframes rule
auto animation = CSSAnimation::create(document.realm());
animation->set_id(animation_properties.name);
animation->set_animation_name(animation_properties.name);
animation->set_timeline(document.timeline());
animation->set_owning_element(element);

View file

@ -2816,7 +2816,7 @@ void Document::dispatch_events_for_animation_if_necessary(GC::Ref<Animations::An
name,
{
{ .bubbles = true },
css_animation.id(),
css_animation.animation_name(),
elapsed_time_seconds,
}),
.animation = css_animation,

View file

@ -0,0 +1,6 @@
Harness status: OK
Found 1 tests
1 Pass
Pass Animation.id for CSS Animations

View file

@ -0,0 +1,27 @@
<!doctype html>
<meta charset=utf-8>
<title>CSSAnimation.id</title>
<!-- TODO: Add a more specific link for this once it is specified. -->
<link rel="help" href="https://drafts.csswg.org/css-animations-2/#cssanimation">
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="support/testcommon.js"></script>
<style>
@keyframes abc { }
</style>
<div id="log"></div>
<script>
'use strict';
test(t => {
const div = addDiv(t);
div.style.animation = 'abc 100s';
const animation = div.getAnimations()[0];
assert_equals(animation.id, '', 'id for CSS Animation is initially empty');
animation.id = 'anim'
assert_equals(animation.id, 'anim', 'animation.id reflects the value set');
}, 'Animation.id for CSS Animations');
</script>
</html>