Truly independent web browser
LibWeb: Keep a pseudo-element's animation that hides it by a property
Andreas Klingabd2ffa30ae2
diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Libraries/LibWeb/Animations/KeyframeEffect.cppindex e5b91800e73..1d32c43cdb6 100644--- a/Libraries/LibWeb/Animations/KeyframeEffect.cpp+++ b/Libraries/LibWeb/Animations/KeyframeEffect.cpp@@ -1295,7 +1295,7 @@ bool KeyframeEffect::css_animation_events_are_heard(bool only_iteration_events)static bool is_in_display_none_subtree_ignoring_animations(DOM::AbstractElement abstract_element){- if (abstract_element.pseudo_element().has_value() && abstract_element.element().installed_style(abstract_element.pseudo_element()).display_is_none())+ if (abstract_element.pseudo_element().has_value() && abstract_element.element().installed_style(abstract_element.pseudo_element()).display_is_none_ignoring_animations())return true;return abstract_element.element().has_inclusive_ancestor_with_display_none_ignoring_animations();}diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cppindex bbef0e6562b..e2e94e4e52f 100644--- a/Libraries/LibWeb/DOM/Node.cpp+++ b/Libraries/LibWeb/DOM/Node.cpp@@ -4972,7 +4972,7 @@ bool Node::has_inclusive_ancestor_with_display_none_ignoring_animations() constancestor = ancestor->parent_or_shadow_host();continue;}- if (ancestor_element->installed_style().display_is_none())+ if (ancestor_element->installed_style().display_is_none_ignoring_animations())return true;ancestor = ancestor_element->element_to_inherit_style_from({}).ptr();}diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rsindex c17700408b3..58d3b3ebfe4 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/traversal.rs@@ -1324,6 +1324,36 @@ impl<'a> Scratch<'a> {});};computed.element_dependent |= custom_properties_read_subject;+ // NB: As for an element, what its sampled custom properties make of `display` is not what ends its animations.+ if sampled.is_some() && computed_display_is_none(&computed) {+ let ignoring_animations = state.drive_element(+ context.records,+ node,+ Some((inherited.parent, inherited.color)),+ context.initial,+ &self.cascade.winners,+ &super::cascade::CascadeBelow {+ cascade: &self.cascade,+ state,+ node,+ },+ &mut None,+ &mut Default::default(),+ super::custom_properties::CustomPropertyStores {+ own: substituted.as_ref(),+ inherited: inherited.held.as_ref(),+ substitutions: &self.substitutions,+ subject: &subject,+ },+ &mut self.groups,+ &mut self.absolutized,+ kind,+ context.root_font(),+ group_seeds,+ );+ computed.reads.display_none_is_animated = ignoring_animations+ .is_ok_and(|ignoring_animations| !computed_display_is_none(&ignoring_animations));+ }let registered = state.registered_custom_property_store(node,inherited.handed_down.as_ref(),@@ -1691,15 +1721,7 @@ impl<'a> Scratch<'a> {// owning element.// NB: The sampled custom properties are part of the Animations origin, so what they make of `display` is// not what ends the animations. Only an element they leave with none computes this again.- let display_is_none = |computed: &super::compute::ComputedElement| {- crate::css::style_compute::display_of(- computed- .groups- .value(crate::css::property_metadata::property_id::DISPLAY),- )- .is_none()- };- if sampled.is_some() && display_is_none(&computed) {+ if sampled.is_some() && computed_display_is_none(&computed) {let ignoring_animations = state.drive_element(context.records,node,@@ -1725,8 +1747,8 @@ impl<'a> Scratch<'a> {context.root_font(),group_seeds,);- computed.reads.display_none_is_animated =- ignoring_animations.is_ok_and(|ignoring_animations| !display_is_none(&ignoring_animations));+ computed.reads.display_none_is_animated = ignoring_animations+ .is_ok_and(|ignoring_animations| !computed_display_is_none(&ignoring_animations));}let registered = state.registered_custom_property_store(node,@@ -2740,6 +2762,16 @@ pub(super) enum DemandedPseudoElement {/// Style the pseudo-element of `kind` of `node` for a read of its style, whether or not it/// generates a box, from the rules the element matches for it, over the record `context` holds for/// `node`, which it inherits from. Which pseudo-elements are styled is what `read` says.+/// Whether the computed values of `computed` hold `display: none`.+fn computed_display_is_none(computed: &super::compute::ComputedElement) -> bool {+ crate::css::style_compute::display_of(+ computed+ .groups+ .value(crate::css::property_metadata::property_id::DISPLAY),+ )+ .is_none()+}+pub(super) fn style_pseudo_element(context: &PassContext<'_>,node: StyleNodeID,diff --git a/Tests/LibWeb/Text/expected/css/style-engine/pseudo-element-hidden-by-its-own-sampled-custom-property.txt b/Tests/LibWeb/Text/expected/css/style-engine/pseudo-element-hidden-by-its-own-sampled-custom-property.txtnew file mode 100644index 00000000000..4e29e12b6fe--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/style-engine/pseudo-element-hidden-by-its-own-sampled-custom-property.txt@@ -0,0 +1,8 @@+hidden: pseudo-element 1 animations, display none, opacity 1+hidden: element 1 animations, display none, opacity 1+fading added: pseudo-element 2 animations, display none, opacity 0+fading added: element 2 animations, display none, opacity 0+fading sought: pseudo-element 2 animations, display none, opacity 0.25+fading sought: element 2 animations, display none, opacity 0.25+before the animation shows them: pseudo-element none, element none+after the animation shows them: pseudo-element block, element blockdiff --git a/Tests/LibWeb/Text/input/css/style-engine/pseudo-element-hidden-by-its-own-sampled-custom-property.html b/Tests/LibWeb/Text/input/css/style-engine/pseudo-element-hidden-by-its-own-sampled-custom-property.htmlnew file mode 100644index 00000000000..a77f2cf69f4--- /dev/null+++ b/Tests/LibWeb/Text/input/css/style-engine/pseudo-element-hidden-by-its-own-sampled-custom-property.html@@ -0,0 +1,52 @@+<!DOCTYPE html>+<style>+ @keyframes hide { from, to { --hidden: none; } }+ @keyframes fade { from { opacity: 0; } to { opacity: 1; } }+ @keyframes hide-at-first { from { --hidden: none; } 50%, to { --hidden: block; } }+ #pseudo::after, #revealed-pseudo::after { content: "x"; }+ #pseudo::after, #element { display: var(--hidden, block); }+ #pseudo.hiding::after, #element.hiding { animation: hide 100s paused; }+ #pseudo.fading::after, #element.fading { animation: hide 100s paused, fade 100s linear paused; }+ #revealed-pseudo::after, #revealed-element { display: var(--hidden, block); animation: hide-at-first 100s paused; }+</style>+<div id="pseudo" class="hiding"></div>+<div id="element" class="hiding"></div>+<div id="revealed-pseudo"></div>+<div id="revealed-element"></div>+<script src="../../include.js"></script>+<script>+ // An animation of a custom property its display reads hides a pseudo-element, as it does an element, without its+ // display being none ignoring animations. An animation added beside it starts and samples, and the animation goes+ // on sampling, so that it can show what it hid.+ asyncTest(async done => {+ const frames = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));+ const report = label => {+ const pseudoStyle = getComputedStyle(pseudo, "::after");+ const elementStyle = getComputedStyle(element);+ println(`${label}: pseudo-element ${pseudo.getAnimations({ subtree: true }).length} animations, display ${pseudoStyle.display}, opacity ${pseudoStyle.opacity}`);+ println(`${label}: element ${element.getAnimations().length} animations, display ${elementStyle.display}, opacity ${elementStyle.opacity}`);+ };+ await frames();+ report("hidden");+ for (const target of [pseudo, element])+ target.classList.replace("hiding", "fading");+ await frames();+ report("fading added");+ for (const animation of [...pseudo.getAnimations({ subtree: true }), ...element.getAnimations()]) {+ if (animation.animationName === "fade")+ animation.currentTime = 25000;+ }+ await frames();+ report("fading sought");++ const revealed = document.getElementById("revealed-pseudo");+ const revealedElement = document.getElementById("revealed-element");+ const display = () => `pseudo-element ${getComputedStyle(revealed, "::after").display}, element ${getComputedStyle(revealedElement).display}`;+ println(`before the animation shows them: ${display()}`);+ for (const animation of [...revealed.getAnimations({ subtree: true }), ...revealedElement.getAnimations()])+ animation.currentTime = 75000;+ await frames();+ println(`after the animation shows them: ${display()}`);+ done();+ });+</script>