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

@ -4,50 +4,26 @@
<%namespace name="helpers" file="/helpers.mako.rs" />
${helpers.four_sides_shorthand("padding", "padding-%s", "specified::NonNegativeLengthPercentage::parse",
spec="https://drafts.csswg.org/css-box-3/#propdef-padding",
allow_quirks=True)}
${helpers.four_sides_shorthand(
"padding",
"padding-%s",
"specified::NonNegativeLengthPercentage::parse",
spec="https://drafts.csswg.org/css-box-3/#propdef-padding",
allow_quirks=True,
)}
% for axis in ["block", "inline"]:
<%
spec = "https://drafts.csswg.org/css-logical/#propdef-padding-%s" % axis
%>
<%helpers:shorthand
name="padding-${axis}"
sub_properties="${' '.join(
'padding-%s-%s' % (axis, side)
for side in ['start', 'end']
)}"
spec="${spec}">
${helpers.two_properties_shorthand(
"padding-block",
"padding-block-start",
"padding-block-end",
"specified::NonNegativeLengthPercentage::parse",
spec="https://drafts.csswg.org/css-logical/#propdef-padding-block"
)}
use crate::parser::Parse;
use crate::values::specified::length::NonNegativeLengthPercentage;
pub fn parse_value<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Longhands, ParseError<'i>> {
let start_value = NonNegativeLengthPercentage::parse(context, input)?;
let end_value =
input.try(|input| NonNegativeLengthPercentage::parse(context, input))
.unwrap_or_else(|_| start_value.clone());
Ok(expanded! {
padding_${axis}_start: start_value,
padding_${axis}_end: end_value,
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
self.padding_${axis}_start.to_css(dest)?;
if self.padding_${axis}_end != self.padding_${axis}_start {
dest.write_str(" ")?;
self.padding_${axis}_end.to_css(dest)?;
}
Ok(())
}
}
</%helpers:shorthand>
% endfor
${helpers.two_properties_shorthand(
"padding-inline",
"padding-inline-start",
"padding-inline-end",
"specified::NonNegativeLengthPercentage::parse",
spec="https://drafts.csswg.org/css-logical/#propdef-padding-inline"
)}