mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Propagate changes in custom properties' computed values to descendants.
If ComputedValues.custom_properties differs between the old and new ComputedValues, indicate that we have to propogate changes to descendants by setting child_cascade_requirement to MustCascadeDescendants in cascade_primary. style::matching::TElement::cascade_primary already calls accumulate_damage, which eventually calls ServoRestyleDamage::compute_style_difference in order to check if other properties' computed values changed. If any of those change, we signal that we need to propogate changes for inherited properties. With Properties & Values, some custom properties will not be inherited, and we will need to revisit this.
This commit is contained in:
parent
c1ea54d3c4
commit
32f62a5ac6
5 changed files with 57 additions and 2 deletions
|
@ -66,7 +66,7 @@ pub struct BorrowedSpecifiedValue<'a> {
|
|||
|
||||
/// A computed value is just a set of tokens as well, until we resolve variables
|
||||
/// properly.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct ComputedValue {
|
||||
css: String,
|
||||
|
|
|
@ -1894,6 +1894,13 @@ impl ComputedValues {
|
|||
self.visited_style.clone()
|
||||
}
|
||||
|
||||
// Aah! The << in the return type below is not valid syntax, but we must
|
||||
// escape < that way for Mako.
|
||||
/// Gets a reference to the custom properties map (if one exists).
|
||||
pub fn get_custom_properties(&self) -> Option<<&::custom_properties::ComputedValuesMap> {
|
||||
self.custom_properties.as_ref().map(|x| &**x)
|
||||
}
|
||||
|
||||
/// Get the custom properties map if necessary.
|
||||
///
|
||||
/// Cloning the Arc here is fine because it only happens in the case where
|
||||
|
|
|
@ -64,7 +64,16 @@ impl ServoRestyleDamage {
|
|||
new: &ServoComputedValues)
|
||||
-> StyleDifference {
|
||||
let damage = compute_damage(old, new);
|
||||
let change = if damage.is_empty() { StyleChange::Unchanged } else { StyleChange::Changed };
|
||||
// If computed values for custom properties changed, we should cascade these changes to
|
||||
// children (custom properties are all inherited).
|
||||
// https://www.w3.org/TR/css-variables/#defining-variables
|
||||
// (With Properties & Values, not all custom properties will be inherited!)
|
||||
let variable_values_changed = old.get_custom_properties() != new.get_custom_properties();
|
||||
let change = if damage.is_empty() && !variable_values_changed {
|
||||
StyleChange::Unchanged
|
||||
} else {
|
||||
StyleChange::Changed
|
||||
};
|
||||
StyleDifference::new(damage, change)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue