Truly independent web browser
LibWeb: Don't compose animations over a style nothing is assigned to
Andreas Kling1fd8ff596039
diff --git a/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Libraries/LibWeb/Animations/AnimationEffect.cppindex eb4f9e12506..715ea7bd544 100644--- a/Libraries/LibWeb/Animations/AnimationEffect.cpp+++ b/Libraries/LibWeb/Animations/AnimationEffect.cpp@@ -180,6 +180,15 @@ void AnimationUpdateContext::publish()// animation style into.if (target->style_node_id() == 0)continue;+ // NB: The engine assigns no record to a pseudo-element that is not rendered, so the style a read of it holds+ // has no record for its animations to compose over, and it reads as it computes to without them.+ if (auto pseudo_element = element.pseudo_element(); pseudo_element.has_value() && !CSS::is_element_reference_pseudo_element(*pseudo_element)) {+ auto& document = target->document();+ Layout::ForcedReadScope read_scope { document };+ Layout::BegunRead const& read = read_scope;+ if (!CSS::StyleEngineFFI::style_engine_assigns_pseudo_element_record(document.style_computer().style_engine().host(), &read, target->style_node_id().value(), CSS::pseudo_element_to_ffi(pseudo_element)))+ continue;+ }// Provisionally started transitions are not associated with the element yet, so they are// never among the collected effects, but their values are already part of the published// style. Collect them first, in composite order below every associated effect, or thisdiff --git a/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs b/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rsindex 1f852c7dab6..186a8ccd1f7 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge/animations.rs@@ -111,6 +111,26 @@ impl FfiAnimationOverlayPublication {}}+/// Whether the engine assigns a record to the pseudo-element `pseudo_kind` of `node`'s element, for its animations to+/// compose over. It assigns none to a pseudo-element that is not rendered, whose record a read of its style alone+/// holds.+#[unsafe(no_mangle)]+pub extern "C" fn style_engine_assigns_pseudo_element_record(+ host: &DocumentHost,+ read: &crate::render_state::BegunRead,+ node: u32,+ pseudo_kind: u8,+) -> bool {+ let Some(node) = StyleNodeID::from_raw(node) else {+ return false;+ };+ with_engine(read, host, |engine| {+ engine+ .computed_group_sets+ .holds_an_installed_record(crate::css::style::computed::ComputedStyleTarget::new(node, pseudo_kind))+ })+}+/// Composes each element's sampled animation overlay over the record it installed, rebuilding only the groups the/// overlay writes (see `RetainedState::build_animation_overlay_payloads`), compares it with that record, and publishes/// it as the target's record, writing what it answers to the same index of `out`: every element in one call of thediff --git a/Tests/LibWeb/Text/expected/css/animation-on-pseudo-element-that-is-not-rendered.txt b/Tests/LibWeb/Text/expected/css/animation-on-pseudo-element-that-is-not-rendered.txtnew file mode 100644index 00000000000..a3ba4691c3b--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/animation-on-pseudo-element-that-is-not-rendered.txt@@ -0,0 +1,6 @@+After animate(), ::before: rgb(0, 128, 0), 1px, 1px+After animate(), ::marker: rgb(0, 128, 0), 1px, 1px+After animate(), ::backdrop: rgb(0, 128, 0), 1px, 1px+After two animation frames, ::before: rgb(0, 128, 0), 1px, 1px+After two animation frames, ::marker: rgb(0, 128, 0), 1px, 1px+After two animation frames, ::backdrop: rgb(0, 128, 0), 1px, 1pxdiff --git a/Tests/LibWeb/Text/input/css/animation-on-pseudo-element-that-is-not-rendered.html b/Tests/LibWeb/Text/input/css/animation-on-pseudo-element-that-is-not-rendered.htmlnew file mode 100644index 00000000000..086f42bfb5e--- /dev/null+++ b/Tests/LibWeb/Text/input/css/animation-on-pseudo-element-that-is-not-rendered.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<style>+ .target::before, .target::marker, .target::backdrop {+ --length: 1px;+ color: rgb(0, 128, 0);+ width: var(--length);+ }+</style>+<div id="before" class="target"></div>+<div id="marker" class="target"></div>+<div id="backdrop" class="target"></div>+<script src="../include.js"></script>+<script>+ asyncTest(async done => {+ const names = ["before", "marker", "backdrop"];+ const dump = label => {+ for (const name of names) {+ const style = getComputedStyle(document.getElementById(name), `::${name}`);+ println(`${label}, ::${name}: ${style.color}, ${style.getPropertyValue("--length")}, ${style.width}`);+ }+ };+ for (const name of names) {+ const keyframes = { color: ["rgb(255, 0, 0)", "rgb(255, 0, 0)"], "--length": ["5px", "5px"] };+ document.getElementById(name).animate(keyframes, { duration: 100000, pseudoElement: `::${name}` });+ }+ dump("After animate()");+ await animationFrame();+ await animationFrame();+ dump("After two animation frames");+ done();+ });+</script>