Skip to content

Commit a80af93

Browse files
mattco98awesomekling
authored andcommitted
LibWeb: Support subtree option in Animatable.getAnimations()
1 parent e2cb25e commit a80af93

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
num animations without subtree: 1
2+
num animations with subtree: 4
3+
Anim for element parent is in the correct order: true
4+
Anim for element child1 is in the correct order: true
5+
Anim for element child2 is in the correct order: true
6+
Anim for element child3 is in the correct order: true
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<div id="parent">
3+
<div id="child1"></div>
4+
<div id="child2">
5+
<div id="child3"></div>
6+
</div>
7+
</div>
8+
<script src="../../include.js"></script>
9+
<script>
10+
test(() => {
11+
const elements = ["parent", "child1", "child2", "child3"];
12+
for (const id of elements)
13+
document.getElementById(id).animate({}, { duration: Infinity });
14+
15+
const parent = document.getElementById("parent");
16+
const subtreeAnimations = parent.getAnimations({ subtree: true });
17+
println(`num animations without subtree: ${parent.getAnimations({ subtree: false }).length}`);
18+
println(`num animations with subtree: ${subtreeAnimations.length}`);
19+
20+
for (let i = 0; i < elements.length; i++) {
21+
const elem = document.getElementById(elements[i]);
22+
const correctOrder = Object.is(subtreeAnimations[i], elem.getAnimations()[0]);
23+
println(`Anim for element ${elements[i]} is in the correct order: ${correctOrder}`);
24+
}
25+
})
26+
</script>

Userland/Libraries/LibWeb/Animations/Animatable.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<Animation>> Animatable::animate(Optional<JS
5555
}
5656

5757
// https://www.w3.org/TR/web-animations-1/#dom-animatable-getanimations
58-
Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(Web::Animations::GetAnimationsOptions options)
58+
Vector<JS::NonnullGCPtr<Animation>> Animatable::get_animations(GetAnimationsOptions options)
5959
{
6060
// Returns the set of relevant animations for this object, or, if an options parameter is passed with subtree set to
6161
// 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::
7171
m_is_sorted_by_composite_order = true;
7272
}
7373

74-
// FIXME: Support subtree
75-
(void)options;
76-
7774
Vector<JS::NonnullGCPtr<Animation>> relevant_animations;
7875
for (auto const& animation : m_associated_animations) {
7976
if (animation->is_relevant())
8077
relevant_animations.append(*animation);
8178
}
8279

80+
if (options.subtree) {
81+
JS::NonnullGCPtr target { *static_cast<DOM::Element*>(this) };
82+
target->for_each_child_of_type<DOM::Element>([&](auto& child) {
83+
relevant_animations.extend(child.get_animations(options));
84+
return IterationDecision::Continue;
85+
});
86+
}
87+
8388
return relevant_animations;
8489
}
8590

0 commit comments

Comments
 (0)