Skip to content

Truly independent web browser

LibWeb: Replace cyclic keyframe values of unregistered custom properties

Callum Law10a4a057d9a9
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 5259864a0c6..03be3a965bc 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -9245,7 +9245,6 @@ impl PreparedAnimationBatch {
intervals: &[CustomPropertyInterval],
registry: &Registry,
inherited: Option<&crate::css::custom_properties::CustomPropertyStore>,
- cyclic_declarations: &mut Vec<crate::css::retained_fly_string::RetainedUtf16FlyString>,
) -> bool {
let mut has_cyclic_interval = false;
for interval in intervals {
@@ -9255,10 +9254,6 @@ impl PreparedAnimationBatch {
// SAFETY: The interval retains the name while it is borrowed for the lookup.
let name = unsafe { ak::Utf16FlyString::from_raw_borrowed(interval.name.raw()) };
let registered = registry.is_registered(&name);
- if !registered {
- cyclic_declarations.push(interval.name.clone());
- continue;
- }
let fallback = registry.invalid_at_computed_value_time(&interval.name, inherited);
for (plan, keyframes) in self.resolved.value_plans.iter().zip(&mut self.keyframes_by_value) {
if plan.custom_name_id != interval.custom_name_id || plan.effect_index != interval.effect_index {
@@ -9269,13 +9264,15 @@ impl PreparedAnimationBatch {
// AD-HOC: Compose a registered custom property's selected interval as unset if it has a cyclic endpoint
// and two explicit keyframe values, matching Chromium. Keep unset as a marker until all effects
// are composed so later additive effects do not add the inherited or initial value.
- let fallback = if keyframes.iter().all(|keyframe| !keyframe.is_implicit) {
+ let fallback = if registered && keyframes.iter().all(|keyframe| !keyframe.is_implicit) {
RetainedStyleValueData::shared_keyword(crate::css::css_enums::keyword::UNSET)
} else {
&fallback
};
- for keyframe in keyframes {
- keyframe.value = fallback.clone();
+ for (keyframe, cyclic) in keyframes.iter_mut().zip(interval.cyclic) {
+ if cyclic || registered {
+ keyframe.value = fallback.clone();
+ }
}
}
has_cyclic_interval = true;
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 86d935e9105..ec5ada3256d 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -7318,7 +7318,7 @@ fn finish_animation_sample(
.cast::<crate::css::custom_properties::CustomPropertyStore>()
.as_ref()
};
- let mut cyclic_declarations = engine.check_custom_property_animation_cycles(
+ let cyclic_declarations = engine.check_custom_property_animation_cycles(
node,
cycle_pseudo,
input.stores.base,
@@ -7329,12 +7329,7 @@ fn finish_animation_sample(
// NB: Preparations containing custom properties are not cached, so this sample owns its preparation.
let preparation =
std::sync::Arc::get_mut(&mut preparation).expect("custom-property preparations are not shared");
- if preparation.replace_cyclic_custom_property_endpoints(
- &custom_properties.intervals,
- registry,
- inherited,
- &mut cyclic_declarations,
- ) {
+ if preparation.replace_cyclic_custom_property_endpoints(&custom_properties.intervals, registry, inherited) {
retained = anim::evaluate_prepared_animations(preparation, &mut batch)
.into_iter()
.map(|(custom_name_id, value)| (custom_properties.name(custom_name_id).clone(), value))
@@ -7349,10 +7344,7 @@ fn finish_animation_sample(
}
for name in cyclic_declarations {
let value = registry.invalid_at_computed_value_time(&name, inherited);
- match retained.iter_mut().find(|(animated, _)| *animated == name) {
- Some((_, animated)) => *animated = value,
- None => retained.push((name, value)),
- }
+ retained.push((name, value));
}
// The element's own custom properties that read an animated one move with it, whether or
// not they resolved to what it inherits.
diff --git a/Tests/LibWeb/Text/expected/css/custom-property-animation-cycle-one-endpoint.txt b/Tests/LibWeb/Text/expected/css/custom-property-animation-cycle-one-endpoint.txt
new file mode 100644
index 00000000000..92fa922cd62
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/custom-property-animation-cycle-one-endpoint.txt
@@ -0,0 +1,3 @@
+the cyclic endpoint is invalid: true
+the literal endpoint remains valid: true
+breaking the cycle preserves the literal endpoint: true
diff --git a/Tests/LibWeb/Text/input/css/custom-property-animation-cycle-one-endpoint.html b/Tests/LibWeb/Text/input/css/custom-property-animation-cycle-one-endpoint.html
new file mode 100644
index 00000000000..54fc2f8aa83
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/custom-property-animation-cycle-one-endpoint.html
@@ -0,0 +1,33 @@
+<!doctype html>
+<style>
+ @property --other {
+ syntax: "<custom-ident>";
+ inherits: true;
+ initial-value: base;
+ }
+ @keyframes mixed {
+ from {
+ --value: var(--other);
+ }
+ to {
+ --value: safe;
+ }
+ }
+ #target {
+ --other: var(--value);
+ animation: mixed 1s linear paused;
+ }
+</style>
+<div id="target"></div>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ const target = document.getElementById("target");
+ const value = () => getComputedStyle(target).getPropertyValue("--value");
+ println(`the cyclic endpoint is invalid: ${value() === ""}`);
+ target.getAnimations()[0].currentTime = 900;
+ println(`the literal endpoint remains valid: ${value() === "safe"}`);
+ target.style.setProperty("--other", "base");
+ println(`breaking the cycle preserves the literal endpoint: ${value() === "safe"}`);
+ });
+</script>