style: Cleanup a few shorthand properties.

Differential Revision: https://phabricator.services.mozilla.com/D17082
This commit is contained in:
Emilio Cobos Álvarez 2019-01-23 17:38:55 +01:00
parent af1bbd7b06
commit 45a416b996
5 changed files with 139 additions and 231 deletions

View file

@ -793,6 +793,58 @@
% endif
</%def>
// A shorthand of kind `<property-1> <property-2>?` where both properties have
// the same type.
<%def name="two_properties_shorthand(
name,
first_property,
second_property,
parser_function,
needs_context=True,
**kwargs
)">
<%call expr="self.shorthand(name, sub_properties=' '.join([first_property, second_property]), **kwargs)">
#[allow(unused_imports)]
use crate::parser::Parse;
use crate::values::specified;
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let parse_one = |_c: &ParserContext, input: &mut Parser<'i, 't>| {
% if needs_context:
${parser_function}(_c, input)
% else:
${parser_function}(input)
% endif
};
let first = parse_one(context, input)?;
let second =
input.try(|input| parse_one(context, input)).unwrap_or_else(|_| first.clone());
Ok(expanded! {
${to_rust_ident(first_property)}: first,
${to_rust_ident(second_property)}: second,
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
let first = &self.${to_rust_ident(first_property)};
let second = &self.${to_rust_ident(second_property)};
first.to_css(dest)?;
if first != second {
dest.write_str(" ")?;
second.to_css(dest)?;
}
Ok(())
}
}
</%call>
</%def>
<%def name="four_sides_shorthand(name, sub_property_pattern, parser_function,
needs_context=True, allow_quirks=False, **kwargs)">
<% sub_properties=' '.join(sub_property_pattern % side for side in PHYSICAL_SIDES) %>