mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-08-17 01:10:28 +03:00
LibWeb: Support subtree option in Animatable.getAnimations()
This commit is contained in:
parent
e2cb25e35c
commit
a80af938eb
Notes:
sideshowbarker
2024-07-17 11:30:05 +09:00
Author: https://github.com/mattco98 Commit: https://github.com/SerenityOS/serenity/commit/a80af938eb Pull-request: https://github.com/SerenityOS/serenity/pull/24514
@ -0,0 +1,6 @@
|
||||
num animations without subtree: 1
|
||||
num animations with subtree: 4
|
||||
Anim for element parent is in the correct order: true
|
||||
Anim for element child1 is in the correct order: true
|
||||
Anim for element child2 is in the correct order: true
|
||||
Anim for element child3 is in the correct order: true
|
26
Tests/LibWeb/Text/input/WebAnimations/misc/animatable.html
Normal file
26
Tests/LibWeb/Text/input/WebAnimations/misc/animatable.html
Normal file
@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<div id="parent">
|
||||
<div id="child1"></div>
|
||||
<div id="child2">
|
||||
<div id="child3"></div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="../../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const elements = ["parent", "child1", "child2", "child3"];
|
||||
for (const id of elements)
|
||||
document.getElementById(id).animate({}, { duration: Infinity });
|
||||
|
||||
const parent = document.getElementById("parent");
|
||||
const subtreeAnimations = parent.getAnimations({ subtree: true });
|
||||
println(`num animations without subtree: ${parent.getAnimations({ subtree: false }).length}`);
|
||||
println(`num animations with subtree: ${subtreeAnimations.length}`);
|
||||
|
||||
for (let i = 0; i < elements.length; i++) {
|
||||
const elem = document.getElementById(elements[i]);
|
||||
const correctOrder = Object.is(subtreeAnimations[i], elem.getAnimations()[0]);
|
||||
println(`Anim for element ${elements[i]} is in the correct order: ${correctOrder}`);
|
||||
}
|
||||
})
|
||||
</script>
|
@ -55,7 +55,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Animation>> Animatable::animate(Optional<JS
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/web-animations-1/#dom-animatable-getanimations
|
||||
Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(Web::Animations::GetAnimationsOptions options)
|
||||
Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(GetAnimationsOptions options)
|
||||
{
|
||||
// Returns the set of relevant animations for this object, or, if an options parameter is passed with subtree set to
|
||||
// true, returns the set of relevant animations for a subtree for this object.
|
||||
@ -71,15 +71,20 @@ Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(Web::Animations::
|
||||
m_is_sorted_by_composite_order = true;
|
||||
}
|
||||
|
||||
// FIXME: Support subtree
|
||||
(void)options;
|
||||
|
||||
Vector<JS::NonnullGCPtr<Animation>> relevant_animations;
|
||||
for (auto const& animation : m_associated_animations) {
|
||||
if (animation->is_relevant())
|
||||
relevant_animations.append(*animation);
|
||||
}
|
||||
|
||||
if (options.subtree) {
|
||||
JS::NonnullGCPtr target { *static_cast<DOM::Element*>(this) };
|
||||
target->for_each_child_of_type<DOM::Element>([&](auto& child) {
|
||||
relevant_animations.extend(child.get_animations(options));
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
}
|
||||
|
||||
return relevant_animations;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user