Skip to content

Truly independent web browser

LibWeb: Read animated custom properties in container style queries

Jelle Raaijmakers93e314777a67
diff --git a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs
index d0fe20091e4..b120014ffd2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/container_queries.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/container_queries.rs
@@ -501,11 +501,14 @@ impl RetainedState {
// as the container's record computes them.
let mut style_context = None;
if requirements & CONTAINER_QUERY_REQUIRES_STYLE != 0 {
- let store = match self
- .computed_group_sets
- .style_record_custom_property_environment(inputs.style_record)
- .unwrap_or_default()
- {
+ let environment = match self.element_custom_property_data.get(&candidate) {
+ Some(held) if held.sampled_over.is_some() => held.identity,
+ _ => self
+ .computed_group_sets
+ .style_record_custom_property_environment(inputs.style_record)
+ .unwrap_or_default(),
+ };
+ let store = match environment {
0 => None,
identity => Some(&**self.custom_property_environments.store(identity)?),
};
diff --git a/Tests/LibWeb/Text/expected/css/animated-custom-property-style-container-query.txt b/Tests/LibWeb/Text/expected/css/animated-custom-property-style-container-query.txt
new file mode 100644
index 00000000000..023802d5298
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/animated-custom-property-style-container-query.txt
@@ -0,0 +1,5 @@
+0ms: rgb(255, 0, 0)
+500ms: rgb(0, 0, 255)
+0ms: rgb(255, 0, 0)
+500ms: rgb(0, 0, 255)
+cancelled: rgb(0, 0, 0)
diff --git a/Tests/LibWeb/Text/input/css/animated-custom-property-style-container-query.html b/Tests/LibWeb/Text/input/css/animated-custom-property-style-container-query.html
new file mode 100644
index 00000000000..2a4bdf6688d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/animated-custom-property-style-container-query.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ @property --clock {
+ syntax: "<integer>";
+ inherits: true;
+ initial-value: -1;
+ }
+ @keyframes cycle-clock {
+ 0% { --clock: 0; }
+ 50% { --clock: 1; }
+ }
+ #container {
+ animation: 1s steps(1, jump-end) cycle-clock infinite paused;
+ }
+ #target {
+ @container style(--clock: 0) { color: red; }
+ @container style(--clock: 1) { color: blue; }
+ }
+</style>
+<div id="container"><p id="target">Text</p></div>
+<script>
+ test(() => {
+ const animation = document.getElementById("container").getAnimations()[0];
+ const target = document.getElementById("target");
+ for (const currentTime of [0, 500, 0, 500]) {
+ animation.currentTime = currentTime;
+ println(`${currentTime}ms: ${getComputedStyle(target).color}`);
+ }
+ animation.cancel();
+ println(`cancelled: ${getComputedStyle(target).color}`);
+ });
+</script>