style: Deindent and reuse some more code in single_value_to_css.

This method is a hack on its own, let's try to scope it a bit...
This commit is contained in:
Emilio Cobos Álvarez 2018-02-14 20:23:26 +01:00
parent f3e38aca1b
commit 808102035e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -626,16 +626,23 @@ impl PropertyDeclarationBlock {
computed_values: Option<&ComputedValues>, computed_values: Option<&ComputedValues>,
custom_properties_block: Option<&PropertyDeclarationBlock>, custom_properties_block: Option<&PropertyDeclarationBlock>,
) -> fmt::Result { ) -> fmt::Result {
match property.as_shorthand() { if let Ok(shorthand) = property.as_shorthand() {
Err(_longhand_or_custom) => { return self.shorthand_to_css(shorthand, dest);
if self.declarations.len() == 1 { }
let declaration = &self.declarations[0];
// FIXME(emilio): Should this assert, or assert that the declaration is
// the property we expect?
let declaration = match self.declarations.get(0) {
Some(d) => d,
None => return Err(fmt::Error),
};
let custom_properties = if let Some(cv) = computed_values { let custom_properties = if let Some(cv) = computed_values {
// If there are extra custom properties for this // If there are extra custom properties for this declaration block,
// declaration block, factor them in too. // factor them in too.
if let Some(block) = custom_properties_block { if let Some(block) = custom_properties_block {
// FIXME(emilio): This is not super-efficient // FIXME(emilio): This is not super-efficient here, and all this
// here... // feels like a hack anyway...
block.cascade_custom_properties(cv.custom_properties()) block.cascade_custom_properties(cv.custom_properties())
} else { } else {
cv.custom_properties().cloned() cv.custom_properties().cloned()
@ -645,9 +652,11 @@ impl PropertyDeclarationBlock {
}; };
match (declaration, computed_values) { match (declaration, computed_values) {
// If we have a longhand declaration with variables, those variables will be // If we have a longhand declaration with variables, those variables
// stored as unparsed values. As a temporary measure to produce sensible results // will be stored as unparsed values.
// in Gecko's getKeyframes() implementation for CSS animations, if //
// As a temporary measure to produce sensible results in Gecko's
// getKeyframes() implementation for CSS animations, if
// |computed_values| is supplied, we use it to expand such variable // |computed_values| is supplied, we use it to expand such variable
// declarations. This will be fixed properly in Gecko bug 1391537. // declarations. This will be fixed properly in Gecko bug 1391537.
( (
@ -662,26 +671,6 @@ impl PropertyDeclarationBlock {
}, },
(ref d, _) => d.to_css(dest), (ref d, _) => d.to_css(dest),
} }
} else {
Err(fmt::Error)
}
}
Ok(shorthand) => {
if !self.declarations.iter().all(|decl| decl.shorthands().contains(&shorthand)) {
return Err(fmt::Error)
}
let iter = self.declarations.iter();
match shorthand.get_shorthand_appendable_value(iter) {
Some(AppendableValue::Css { css, .. }) => {
css.append_to(dest)
},
Some(AppendableValue::DeclarationsForShorthand(_, decls)) => {
shorthand.longhands_to_css(decls, &mut CssWriter::new(dest))
}
_ => Ok(())
}
}
}
} }
/// Convert AnimationValueMap to PropertyDeclarationBlock. /// Convert AnimationValueMap to PropertyDeclarationBlock.