diff options
author | Martin Robinson <mrobinson@igalia.com> | 2020-06-09 11:39:43 +0200 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2020-06-17 16:35:06 +0200 |
commit | e901fa2c39bc930201f5e251bb65e276a846634c (patch) | |
tree | 541e31dd3616ba4cc65c8a903fb1f2aade4550d0 | |
parent | 6d9b2eef296fe3281fc098a5ea238c8053c3f893 (diff) | |
download | servo-e901fa2c39bc930201f5e251bb65e276a846634c.tar.gz servo-e901fa2c39bc930201f5e251bb65e276a846634c.zip |
Cancel animations for nodes which are removed from the DOM
This includes nodes which are being reparented.
8 files changed, 32 insertions, 31 deletions
diff --git a/components/script/animations.rs b/components/script/animations.rs index bddbac14966..c383048b3a8 100644 --- a/components/script/animations.rs +++ b/components/script/animations.rs @@ -99,6 +99,27 @@ impl Animations { self.unroot_unused_nodes(&sets); } + /// Cancel animations for the given node, if any exist. + pub(crate) fn cancel_animations_for_node(&self, node: &Node) { + let mut animations = self.sets.sets.write(); + let mut cancel_animations_for = |key| { + animations.get_mut(&key).map(|set| { + set.cancel_all_animations(); + }); + }; + + let opaque_node = node.to_opaque(); + cancel_animations_for(AnimationSetKey::new_for_non_pseudo(opaque_node)); + cancel_animations_for(AnimationSetKey::new_for_pseudo( + opaque_node, + PseudoElement::Before, + )); + cancel_animations_for(AnimationSetKey::new_for_pseudo( + opaque_node, + PseudoElement::After, + )); + } + /// Processes any new animations that were discovered after reflow. Collect messages /// that trigger events for any animations that changed state. pub(crate) fn do_post_reflow_update(&self, window: &Window, now: f64) { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 1d0aabc3d51..1092a070837 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -3855,6 +3855,10 @@ impl Document { .borrow() .do_post_reflow_update(&self.window, self.current_animation_timeline_value()); } + + pub(crate) fn cancel_animations_for_node(&self, node: &Node) { + self.animations.borrow().cancel_animations_for_node(node); + } } impl Element { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index f17c22163d0..9bfe91e3470 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -281,6 +281,11 @@ impl Node { } } + pub fn clean_up_layout_data(&self) { + self.owner_doc().cancel_animations_for_node(self); + self.style_and_layout_data.borrow_mut().take(); + } + /// Clean up flags and unbind from tree. pub fn complete_remove_subtree(root: &Node, context: &UnbindContext) { for node in root.traverse_preorder(ShadowIncluding::Yes) { @@ -295,6 +300,8 @@ impl Node { ); } for node in root.traverse_preorder(ShadowIncluding::Yes) { + node.clean_up_layout_data(); + // This needs to be in its own loop, because unbind_from_tree may // rely on the state of IS_IN_DOC of the context node's descendants, // e.g. when removing a <form>. diff --git a/tests/wpt/metadata-layout-2020/css/css-transitions/disconnected-element-001.html.ini b/tests/wpt/metadata-layout-2020/css/css-transitions/disconnected-element-001.html.ini deleted file mode 100644 index cd98f4d3d67..00000000000 --- a/tests/wpt/metadata-layout-2020/css/css-transitions/disconnected-element-001.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[disconnected-element-001.html] - expected: TIMEOUT - [Transitions are canceled when an element is re-parented to the same node] - expected: NOTRUN - - [Transitions are canceled when an element is re-parented] - expected: TIMEOUT - diff --git a/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-001.html.ini b/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-001.html.ini index e5df375eb69..c3934925c0e 100644 --- a/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-001.html.ini +++ b/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-001.html.ini @@ -212,9 +212,6 @@ [text-indent length(in) / events] expected: FAIL - [visibility visibility(keyword) / events] - expected: FAIL - [text-indent length(pc) / events] expected: FAIL @@ -227,9 +224,6 @@ [text-indent length(cm) / events] expected: FAIL - [visibility visibility(keyword) / values] - expected: FAIL - [outline-width length(cm) / events] expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-001.html.ini b/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-001.html.ini index e8f745a7c29..7be56752050 100644 --- a/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-001.html.ini +++ b/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-001.html.ini @@ -104,9 +104,6 @@ [vertical-align length(cm) / values] expected: FAIL - [visibility visibility(keyword) / events] - expected: FAIL - [vertical-align length(ex) / values] expected: FAIL diff --git a/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-002.html.ini b/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-002.html.ini index 16485691aa8..d6dae7bbac6 100644 --- a/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-002.html.ini +++ b/tests/wpt/metadata-layout-2020/css/css-transitions/properties-value-inherit-002.html.ini @@ -212,9 +212,6 @@ [text-indent length(in) / events] expected: FAIL - [visibility visibility(keyword) / events] - expected: FAIL - [text-indent length(pc) / events] expected: FAIL @@ -227,9 +224,6 @@ [text-indent length(cm) / events] expected: FAIL - [visibility visibility(keyword) / values] - expected: FAIL - [outline-width length(cm) / events] expected: FAIL diff --git a/tests/wpt/metadata/css/css-transitions/disconnected-element-001.html.ini b/tests/wpt/metadata/css/css-transitions/disconnected-element-001.html.ini deleted file mode 100644 index cd98f4d3d67..00000000000 --- a/tests/wpt/metadata/css/css-transitions/disconnected-element-001.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[disconnected-element-001.html] - expected: TIMEOUT - [Transitions are canceled when an element is re-parented to the same node] - expected: NOTRUN - - [Transitions are canceled when an element is re-parented] - expected: TIMEOUT - |