diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index 810382acd64..b65ea7a8926 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -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, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 8bd5ec4680d..3c2d24fae10 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -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 diff --git a/components/style/servo/restyle_damage.rs b/components/style/servo/restyle_damage.rs index 59a03a3f085..828ba2443cf 100644 --- a/components/style/servo/restyle_damage.rs +++ b/components/style/servo/restyle_damage.rs @@ -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) } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 8ea37343341..ec1b5fd1d3a 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -19992,6 +19992,12 @@ {} ] ], + "mozilla/upstream/css_variables_setProperty_recompute.html": [ + [ + "/_mozilla/mozilla/upstream/css_variables_setProperty_recompute.html", + {} + ] + ], "mozilla/variadic-interface.html": [ [ "/_mozilla/mozilla/variadic-interface.html", @@ -31665,6 +31671,10 @@ "dfb31d3f9c4f24913055924c375f08b990b63e49", "testharness" ], + "mozilla/upstream/css_variables_setProperty_recompute.html": [ + "2e9326948f5115b3b63564fd26bae326bc8e2187", + "testharness" + ], "mozilla/variadic-interface.html": [ "9edd5150d36fabae42077a034655a8457eb75bff", "testharness" diff --git a/tests/wpt/mozilla/tests/mozilla/upstream/css_variables_setProperty_recompute.html b/tests/wpt/mozilla/tests/mozilla/upstream/css_variables_setProperty_recompute.html new file mode 100644 index 00000000000..916a1119efb --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/upstream/css_variables_setProperty_recompute.html @@ -0,0 +1,29 @@ + + +