diff --git a/components/style/properties/shorthands/margin.mako.rs b/components/style/properties/shorthands/margin.mako.rs index 86e3b56a226..4e74427cd13 100644 --- a/components/style/properties/shorthands/margin.mako.rs +++ b/components/style/properties/shorthands/margin.mako.rs @@ -8,3 +8,46 @@ ${helpers.four_sides_shorthand("margin", "margin-%s", "specified::LengthPercenta spec="https://drafts.csswg.org/css-box/#propdef-margin", allowed_in_page_rule=True, allow_quirks=True)} + +% for axis in ["block", "inline"]: + <% + spec = "https://drafts.csswg.org/css-logical/#propdef-margin-%s" % axis + %> + <%helpers:shorthand + name="margin-${axis}" + sub_properties="${' '.join( + 'margin-%s-%s' % (axis, side) + for side in ['start', 'end'] + )}" + spec="${spec}"> + + use crate::parser::Parse; + use crate::values::specified::length::LengthPercentageOrAuto; + pub fn parse_value<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + let start_value = LengthPercentageOrAuto::parse(context, input)?; + let end_value = + input.try(|input| LengthPercentageOrAuto::parse(context, input)).unwrap_or_else(|_| start_value.clone()); + + Ok(expanded! { + margin_${axis}_start: start_value, + margin_${axis}_end: end_value, + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { + self.margin_${axis}_start.to_css(dest)?; + + if self.margin_${axis}_end != self.margin_${axis}_start { + dest.write_str(" ")?; + self.margin_${axis}_end.to_css(dest)?; + } + + Ok(()) + } + } + +% endfor