Truly independent web browser
LibWeb: Keep inherited custom properties under an animated ancestor
sideshowbarker12e1529c73b2
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rsindex b2d9cd2c1d2..5d21939de2e 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/custom_properties.rs@@ -418,8 +418,13 @@ impl RetainedState {};// A store whose own values all stay with the element hands down what it was handed, which// keeps one store through a chain of elements declaring only such values.+ // NB: A caller that doesn't know what the element was handed gets the chain the store+ // inherits through instead, which still holds every custom property of its ancestors.if inheritable.own_values.is_empty() {- return handed_down.map(std::borrow::Cow::Borrowed);+ return match handed_down {+ Some(handed_down) => Some(std::borrow::Cow::Borrowed(handed_down)),+ None => inheritable.parent().cloned().map(std::borrow::Cow::Owned),+ };}Some(std::borrow::Cow::Owned(inheritable))}diff --git a/Tests/LibWeb/Text/expected/css/animated-custom-property-keeps-inherited-custom-properties.txt b/Tests/LibWeb/Text/expected/css/animated-custom-property-keeps-inherited-custom-properties.txtnew file mode 100644index 00000000000..36e4af68dd2--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/animated-custom-property-keeps-inherited-custom-properties.txt@@ -0,0 +1,2 @@+before: 20px+during the transition: 20pxdiff --git a/Tests/LibWeb/Text/input/css/animated-custom-property-keeps-inherited-custom-properties.html b/Tests/LibWeb/Text/input/css/animated-custom-property-keeps-inherited-custom-properties.htmlnew file mode 100644index 00000000000..3f73677bf42--- /dev/null+++ b/Tests/LibWeb/Text/input/css/animated-custom-property-keeps-inherited-custom-properties.html@@ -0,0 +1,56 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+@property --color {+ syntax: "<color>";+ inherits: false;+ initial-value: transparent;+}++@property --duration {+ syntax: "*";+ inherits: false;+}++/* Enough custom properties on the root that its descendants reach them through the stores of their ancestors, rather+ than holding copies of them. */+:root {+ --a: 1px;+ --b: 2px;+ --c: 3px;+ --d: 4px;+ --e: 5px;+ --f: 6px;+ --g: 7px;+ --h: 8px;+ --size: 20px;+}++#ancestor {+ --duration: 1s;+ transition-duration: 1s;+}++#ancestor.colored {+ --color: green;+}++#target {+ height: var(--size);+}+</style>+<div id="ancestor" class="colored"><div><div id="target"></div></div></div>+<script>+ // A transition of a custom property on an ancestor that hands down none of its own custom properties keeps its+ // descendants' access to the custom properties above it.+ asyncTest(async done => {+ const target = document.getElementById("target");+ println(`before: ${getComputedStyle(target).height}`);+ await animationFrame();+ document.getElementById("ancestor").classList.remove("colored");+ await animationFrame();+ await animationFrame();+ println(`during the transition: ${getComputedStyle(target).height}`);+ done();+ });+</script>