From 30184370b1a5f1acf69b90641c090118f4f6c602 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Wed, 16 Jan 2019 19:26:14 +0100 Subject: [PATCH] style: Implement the inset-block/inline shorthands. Bug: 1520229 Reviewed-by: emilio --- .../properties/shorthands/position.mako.rs | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/components/style/properties/shorthands/position.mako.rs b/components/style/properties/shorthands/position.mako.rs index cb9ceb38622..4b2dfd1ea32 100644 --- a/components/style/properties/shorthands/position.mako.rs +++ b/components/style/properties/shorthands/position.mako.rs @@ -762,3 +762,46 @@ } } + +% for axis in ["block", "inline"]: + <% + spec = "https://drafts.csswg.org/css-logical/#propdef-inset-%s" % axis + %> + <%helpers:shorthand + name="inset-${axis}" + sub_properties="${' '.join( + 'inset-%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! { + inset_${axis}_start: start_value, + inset_${axis}_end: end_value, + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { + self.inset_${axis}_start.to_css(dest)?; + + if self.inset_${axis}_end != self.inset_${axis}_start { + dest.write_str(" ")?; + self.inset_${axis}_end.to_css(dest)?; + } + + Ok(()) + } + } + +% endfor