Truly independent web browser
LibWeb: Recompute an animated element when its environment moves
Andreas Kling3aefd1dfd4d5
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rsindex 4b228d393c4..2ce7439d159 100644--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs@@ -2456,7 +2456,8 @@ pub(crate) fn publish_rule_declarations(/// Moves a node's record to the custom-property environment C++ refreshed it to, keeping the/// store behind the environment, and returns the new record's identity; zero when the node holds-/// no base record to move.+/// no record to move. Only a base record moves: an environment move computes an element holding a+/// record that composes animated values again instead of having C++ refresh it.////// # Safety/// `host` must be a live document host, on its document's thread, and `store` must be null or adiff --git a/Libraries/LibWeb/Rust/src/css/style/environment_move.rs b/Libraries/LibWeb/Rust/src/css/style/environment_move.rsindex bb109e191e5..94dc7c26f5f 100644--- a/Libraries/LibWeb/Rust/src/css/style/environment_move.rs+++ b/Libraries/LibWeb/Rust/src/css/style/environment_move.rs@@ -229,8 +229,13 @@ impl StyleEngine {(held.identity, held.sampled_over.is_some(), held.declares)});// An animation overlay samples over what the element's style resolves to, which a- // computation moves.- if is_animation_overlay {+ // computation moves. So does a record composing animated values: only a base record moves+ // to another environment by itself, and the host would otherwise hold an environment its+ // record does not name.+ if is_animation_overlay+ || computed::FinalStyleRecordID::from_raw(held_style_record)+ .is_some_and(computed::FinalStyleRecordID::is_animation_overlay)+ {act(EnvironmentMoveAction::Recompute(element));return None;}diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rsindex 0b334f9fb32..acc65fb1ee3 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs@@ -1214,9 +1214,16 @@ impl RetainedState {/// reaction C++ settled by refreshing the data alone publishes. The host installs it in the/// middle of a batch, so it is never a record the engine assigned for a row the host has yet to/// apply, which moves more than the environment. The new record's identity, or nothing when the- /// node holds no base record to move.+ /// node holds no record to move.pub(crate) fn republish_record_environment(&mut self, node: StyleNodeID, environment: u64) -> Option<u64> {let held_style_record = computed::FinalStyleRecordID::from_raw(*self.held_style_records.get(&node)?)?;+ // Only a base record moves to another environment by itself, so an environment move computes an element holding+ // one that composes animated values again instead. Left unmoved, the record would not name the environment the+ // host holds, and the host would refuse every record the engine computes for a child of the element.+ assert!(+ !held_style_record.is_animation_overlay(),+ "a record composing animated values cannot move to another environment"+ );self.computed_group_sets.republish_style_record_with_environment(node, held_style_record, environment).map(|style_record| style_record.raw())diff --git a/Tests/LibWeb/Text/expected/css/custom-property-move-recomputes-animated-element.txt b/Tests/LibWeb/Text/expected/css/custom-property-move-recomputes-animated-element.txtnew file mode 100644index 00000000000..7395066f4cc--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/custom-property-move-recomputes-animated-element.txt@@ -0,0 +1,3 @@+animated:+animated after root change: 15px+child: 25diff --git a/Tests/LibWeb/Text/input/css/custom-property-move-recomputes-animated-element.html b/Tests/LibWeb/Text/input/css/custom-property-move-recomputes-animated-element.htmlnew file mode 100644index 00000000000..6c021200461--- /dev/null+++ b/Tests/LibWeb/Text/input/css/custom-property-move-recomputes-animated-element.html@@ -0,0 +1,21 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ @keyframes fade { from { opacity: 0.5; } to { opacity: 0.6; } }+ #animated { --width: 10px; animation: fade 1000s infinite; }+</style>+<div id="animated"></div>+<script>+ test(() => {+ const animated = document.getElementById("animated");+ println("animated: " + getComputedStyle(animated).getPropertyValue("--root-width"));+ // The root's environment moves under an element that declares custom properties and holds an animated style.+ document.documentElement.style.setProperty("--root-width", "15px");+ println("animated after root change: " + getComputedStyle(animated).getPropertyValue("--root-width"));+ // A child styled for the first time inherits what the animated element holds now.+ const child = document.createElement("div");+ child.style.width = "calc(var(--width) + var(--root-width))";+ animated.appendChild(child);+ println("child: " + child.offsetWidth);+ });+</script>