From 7cf2e38bb7957a14093d21b1e2911acf8797c9da Mon Sep 17 00:00:00 2001 From: Brian Birtles Date: Mon, 20 May 2019 05:22:39 +0000 Subject: [PATCH] style: Use update() to update declarations from Servo_DeclarationBlock_SetPropertyToAnimationValue. This method is used when updating the SMIL override style and from Web Animations' Animation.commitStyles method. By using update we accurately return false when no change is made to a declaration block. For SMIL this simply acts as an optimization, meaning we can avoid updating the SMIL override style ub some cases. For Animation.commitStyles, however, this allows us to avoid generating a mutation record. Normally making a redundant change to an attribute *does* generate a mutation record but the style attribute is different. All browsers avoid generating a mutation record for a redundant change to inline style. This is specified in the behavior for setProperty[1] which does not update the style attribute if updated is false. [1] https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty Differential Revision: https://phabricator.services.mozilla.com/D30871 --- components/style/properties/properties.mako.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 1e92066c7656..ed71019b390f 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2337,6 +2337,14 @@ impl SourcePropertyDeclaration { } } + /// Create one with a single PropertyDeclaration. + #[inline] + pub fn with_one(decl: PropertyDeclaration) -> Self { + let mut result = Self::new(); + result.declarations.push(decl); + result + } + /// Similar to Vec::drain: leaves this empty when the return value is dropped. pub fn drain(&mut self) -> SourcePropertyDeclarationDrain { SourcePropertyDeclarationDrain {