From 71c69ac6b828dc66d98d7523681b7284a1e59b34 Mon Sep 17 00:00:00 2001 From: lanyue-llk <270302213+lanyue-llk@users.noreply.github.com> Date: Tue, 29 Sep 2026 22:53:04 +0800 Subject: [PATCH 1/4] feat(style): expose resolved content provenance --- style/properties/cascade.rs | 5 ++++ style/properties/computed_value_flags.rs | 9 +++++++ style/stylesheets/keyframes_rule.rs | 31 ++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/style/properties/cascade.rs b/style/properties/cascade.rs index 0c02965be6..373decf7cb 100644 --- a/style/properties/cascade.rs +++ b/style/properties/cascade.rs @@ -1155,6 +1155,11 @@ impl<'a> Cascade<'a> { }; self.seen.longhands.insert(longhand_id); + if longhand_id == LonghandId::Visibility && !can_skip_apply { + context + .builder + .add_flags(ComputedValueFlags::HAS_OWN_VISIBILITY); + } if origin.is_author_origin() { self.author_specified.insert(longhand_id); } diff --git a/style/properties/computed_value_flags.rs b/style/properties/computed_value_flags.rs index 80944d87e4..eaea3fef36 100644 --- a/style/properties/computed_value_flags.rs +++ b/style/properties/computed_value_flags.rs @@ -137,6 +137,15 @@ bitflags! { /// Whether this style uses `sibling-index()`. const USES_SIBLING_INDEX = 1 << 27; + + /// Whether the winning `visibility` declaration establishes a value + /// on this element instead of inheriting from its parent. + /// + /// This is set after variable substitution and cascade rollback have + /// selected the declaration, so consumers do not need to replay the + /// cascade to distinguish an inherited hidden value from an explicit + /// hidden boundary. + const HAS_OWN_VISIBILITY = 1 << 28; } } diff --git a/style/stylesheets/keyframes_rule.rs b/style/stylesheets/keyframes_rule.rs index a7b4f182ff..bf464c0317 100644 --- a/style/stylesheets/keyframes_rule.rs +++ b/style/stylesheets/keyframes_rule.rs @@ -543,6 +543,37 @@ fn get_animated_properties( } impl KeyframesAnimation { + /// Return the declaration selected at the final animation offset for a + /// longhand, after keyframes with the same offset have been ordered. + /// + /// This intentionally returns no declaration when the final step uses the + /// underlying computed value. Callers can then use that underlying value + /// without re-parsing stylesheet text or reimplementing keyframe ordering. + pub fn final_declared_property<'a>( + &'a self, + guard: &'a SharedRwLockReadGuard, + property: LonghandId, + ) -> Option<&'a PropertyDeclaration> { + self.steps + .iter() + .rev() + .take_while(|step| step.start_offset.percentage.0 == 1.0) + .find_map(|step| match step.value { + KeyframesStepValue::Declarations { ref block } => block + .read_with(guard) + .get(PropertyDeclarationId::Longhand(property)) + .map(|(declaration, _)| declaration) + .filter(|declaration| { + !matches!( + declaration, + PropertyDeclaration::CSSWideKeyword(..) + | PropertyDeclaration::WithVariables(..) + ) + }), + KeyframesStepValue::ComputedValues => None, + }) + } + /// Create a keyframes animation from a given list of keyframes. /// /// This will return a keyframe animation with empty steps if the list of From 5fca2f725b72ef7b60dfd5f86364c47673b437d7 Mon Sep 17 00:00:00 2001 From: lanyue-llk <270302213+lanyue-llk@users.noreply.github.com> Date: Tue, 29 Sep 2026 22:59:23 +0800 Subject: [PATCH 2/4] fix(style): compute final keyframe opacity --- style/servo/animation.rs | 39 +++++++++++++++++++++++++++++ style/stylesheets/keyframes_rule.rs | 31 ----------------------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/style/servo/animation.rs b/style/servo/animation.rs index 38a72b966c..dcfa08d9b8 100644 --- a/style/servo/animation.rs +++ b/style/servo/animation.rs @@ -29,6 +29,7 @@ use crate::stylesheets::layer_rule::LayerOrder; use crate::values::animated::{Animate, Procedure}; use crate::values::computed::TimingFunction; use crate::values::generics::easing::BeforeFlag; +use crate::values::generics::easing::TimingKeyword; use crate::values::specified::TransitionBehavior; use crate::Atom; use debug_unreachable::debug_unreachable; @@ -556,6 +557,44 @@ impl ComputedKeyframe { } } +/// Resolve the final opacity produced by an already-selected keyframes rule. +/// +/// This uses the same keyframe grouping, variable substitution, underlying +/// value synthesis, and computed-value conversion as running animations. +/// Consumers can inspect a final static state without re-parsing stylesheet +/// text or reproducing keyframe cascade order. +pub fn final_keyframe_opacity( + element: E, + animation: &KeyframesAnimation, + context: &SharedStyleContext, + base_style: &Arc, + resolver: &mut StyleResolverForElement, +) -> Option +where + E: TElement, +{ + let opacity = PropertyDeclarationId::Longhand(LonghandId::Opacity); + if !animation.properties_changed.contains(opacity) { + return None; + } + let mut properties = PropertyDeclarationIdSet::default(); + properties.insert(opacity); + let steps = ComputedKeyframe::generate_for_keyframes( + element, + animation, + context, + base_style, + TimingFunction::Keyword(TimingKeyword::Ease), + resolver, + properties, + 1, + ); + match steps.last()?.values.first()? { + AnimationValueOrReference::AnimationValue(AnimationValue::Opacity(value)) => Some(*value), + _ => None, + } +} + /// A CSS Animation #[derive(Clone, MallocSizeOf)] pub struct Animation { diff --git a/style/stylesheets/keyframes_rule.rs b/style/stylesheets/keyframes_rule.rs index bf464c0317..a7b4f182ff 100644 --- a/style/stylesheets/keyframes_rule.rs +++ b/style/stylesheets/keyframes_rule.rs @@ -543,37 +543,6 @@ fn get_animated_properties( } impl KeyframesAnimation { - /// Return the declaration selected at the final animation offset for a - /// longhand, after keyframes with the same offset have been ordered. - /// - /// This intentionally returns no declaration when the final step uses the - /// underlying computed value. Callers can then use that underlying value - /// without re-parsing stylesheet text or reimplementing keyframe ordering. - pub fn final_declared_property<'a>( - &'a self, - guard: &'a SharedRwLockReadGuard, - property: LonghandId, - ) -> Option<&'a PropertyDeclaration> { - self.steps - .iter() - .rev() - .take_while(|step| step.start_offset.percentage.0 == 1.0) - .find_map(|step| match step.value { - KeyframesStepValue::Declarations { ref block } => block - .read_with(guard) - .get(PropertyDeclarationId::Longhand(property)) - .map(|(declaration, _)| declaration) - .filter(|declaration| { - !matches!( - declaration, - PropertyDeclaration::CSSWideKeyword(..) - | PropertyDeclaration::WithVariables(..) - ) - }), - KeyframesStepValue::ComputedValues => None, - }) - } - /// Create a keyframes animation from a given list of keyframes. /// /// This will return a keyframe animation with empty steps if the list of From 168a3f2fd930c3caf99788f084b9c80331983457 Mon Sep 17 00:00:00 2001 From: lanyue-llk <270302213+lanyue-llk@users.noreply.github.com> Date: Wed, 30 Sep 2026 11:20:11 +0800 Subject: [PATCH 3/4] fix(style): preserve final opacity contribution --- style/servo/animation.rs | 50 ++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/style/servo/animation.rs b/style/servo/animation.rs index dcfa08d9b8..9524a8137e 100644 --- a/style/servo/animation.rs +++ b/style/servo/animation.rs @@ -557,25 +557,55 @@ impl ComputedKeyframe { } } -/// Resolve the final opacity produced by an already-selected keyframes rule. +/// The opacity contribution of an already-selected keyframes rule at its final +/// offset. +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum FinalKeyframeOpacity { + /// The animation does not animate opacity. + NoEffect, + /// The final keyframe omits opacity, so the effect stack supplies the + /// underlying value. + Underlying, + /// The final keyframe explicitly replaces opacity with this computed value. + Replace(f32), + /// The final contribution could not be resolved. + Unknown, +} + +/// Resolve the final opacity contribution of an already-selected keyframes rule. /// /// This uses the same keyframe grouping, variable substitution, underlying -/// value synthesis, and computed-value conversion as running animations. -/// Consumers can inspect a final static state without re-parsing stylesheet -/// text or reproducing keyframe cascade order. +/// value synthesis, and computed-value conversion as running animations. It +/// preserves whether the final value was explicit or supplied by the +/// underlying effect stack. pub fn final_keyframe_opacity( element: E, animation: &KeyframesAnimation, context: &SharedStyleContext, base_style: &Arc, resolver: &mut StyleResolverForElement, -) -> Option +) -> FinalKeyframeOpacity where E: TElement, { let opacity = PropertyDeclarationId::Longhand(LonghandId::Opacity); if !animation.properties_changed.contains(opacity) { - return None; + return FinalKeyframeOpacity::NoEffect; + } + let final_step_declares_opacity = animation.steps.iter().rev().any(|step| { + if step.start_offset.percentage.0 != 1.0 { + return false; + } + let KeyframesStepValue::Declarations { ref block } = step.value else { + return false; + }; + block + .read_with(&context.guards.author) + .normal_declaration_iter() + .any(|declaration| declaration.id() == opacity) + }); + if !final_step_declares_opacity { + return FinalKeyframeOpacity::Underlying; } let mut properties = PropertyDeclarationIdSet::default(); properties.insert(opacity); @@ -589,9 +619,11 @@ where properties, 1, ); - match steps.last()?.values.first()? { - AnimationValueOrReference::AnimationValue(AnimationValue::Opacity(value)) => Some(*value), - _ => None, + match steps.last().and_then(|step| step.values.first()) { + Some(AnimationValueOrReference::AnimationValue(AnimationValue::Opacity(value))) => { + FinalKeyframeOpacity::Replace(*value) + }, + _ => FinalKeyframeOpacity::Unknown, } } From e2baa14adb66df48a56416a93511690d27bfd600 Mon Sep 17 00:00:00 2001 From: lanyue-llk <270302213+lanyue-llk@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:11:51 +0800 Subject: [PATCH 4/4] refactor(style): retain only cascade visibility provenance needed by export --- style/servo/animation.rs | 71 ---------------------------------------- 1 file changed, 71 deletions(-) diff --git a/style/servo/animation.rs b/style/servo/animation.rs index 9524a8137e..38a72b966c 100644 --- a/style/servo/animation.rs +++ b/style/servo/animation.rs @@ -29,7 +29,6 @@ use crate::stylesheets::layer_rule::LayerOrder; use crate::values::animated::{Animate, Procedure}; use crate::values::computed::TimingFunction; use crate::values::generics::easing::BeforeFlag; -use crate::values::generics::easing::TimingKeyword; use crate::values::specified::TransitionBehavior; use crate::Atom; use debug_unreachable::debug_unreachable; @@ -557,76 +556,6 @@ impl ComputedKeyframe { } } -/// The opacity contribution of an already-selected keyframes rule at its final -/// offset. -#[derive(Clone, Copy, Debug, PartialEq)] -pub enum FinalKeyframeOpacity { - /// The animation does not animate opacity. - NoEffect, - /// The final keyframe omits opacity, so the effect stack supplies the - /// underlying value. - Underlying, - /// The final keyframe explicitly replaces opacity with this computed value. - Replace(f32), - /// The final contribution could not be resolved. - Unknown, -} - -/// Resolve the final opacity contribution of an already-selected keyframes rule. -/// -/// This uses the same keyframe grouping, variable substitution, underlying -/// value synthesis, and computed-value conversion as running animations. It -/// preserves whether the final value was explicit or supplied by the -/// underlying effect stack. -pub fn final_keyframe_opacity( - element: E, - animation: &KeyframesAnimation, - context: &SharedStyleContext, - base_style: &Arc, - resolver: &mut StyleResolverForElement, -) -> FinalKeyframeOpacity -where - E: TElement, -{ - let opacity = PropertyDeclarationId::Longhand(LonghandId::Opacity); - if !animation.properties_changed.contains(opacity) { - return FinalKeyframeOpacity::NoEffect; - } - let final_step_declares_opacity = animation.steps.iter().rev().any(|step| { - if step.start_offset.percentage.0 != 1.0 { - return false; - } - let KeyframesStepValue::Declarations { ref block } = step.value else { - return false; - }; - block - .read_with(&context.guards.author) - .normal_declaration_iter() - .any(|declaration| declaration.id() == opacity) - }); - if !final_step_declares_opacity { - return FinalKeyframeOpacity::Underlying; - } - let mut properties = PropertyDeclarationIdSet::default(); - properties.insert(opacity); - let steps = ComputedKeyframe::generate_for_keyframes( - element, - animation, - context, - base_style, - TimingFunction::Keyword(TimingKeyword::Ease), - resolver, - properties, - 1, - ); - match steps.last().and_then(|step| step.values.first()) { - Some(AnimationValueOrReference::AnimationValue(AnimationValue::Opacity(value))) => { - FinalKeyframeOpacity::Replace(*value) - }, - _ => FinalKeyframeOpacity::Unknown, - } -} - /// A CSS Animation #[derive(Clone, MallocSizeOf)] pub struct Animation {