From 50babf81f8a514a644170303deaf7bc3f6b65941 Mon Sep 17 00:00:00 2001 From: Mats Palmgren Date: Thu, 17 Jan 2019 20:02:41 +0100 Subject: [PATCH] style: Implement the border-{block,inline}-{color,style,width} shorthands. Bug: 1520236 Reviewed-by: emilio --- .../properties/shorthands/border.mako.rs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/components/style/properties/shorthands/border.mako.rs b/components/style/properties/shorthands/border.mako.rs index 9495608239c6..255464892a4f 100644 --- a/components/style/properties/shorthands/border.mako.rs +++ b/components/style/properties/shorthands/border.mako.rs @@ -356,6 +356,50 @@ pub fn parse_border<'i, 't>( } +% for axis in ["block", "inline"]: + % for prop in ["width", "style", "color"]: + <% + spec = "https://drafts.csswg.org/css-logical/#propdef-border-%s-%s" % (axis, prop) + %> + <%helpers:shorthand + name="border-${axis}-${prop}" + sub_properties="${' '.join( + 'border-%s-%s-%s' % (axis, side, prop) + for side in ['start', 'end'] + )}" + spec="${spec}"> + + use crate::properties::longhands::border_${axis}_start_${prop}; + pub fn parse_value<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + let start_value = border_${axis}_start_${prop}::parse(context, input)?; + let end_value = + input.try(|input| border_${axis}_start_${prop}::parse(context, input)).unwrap_or_else(|_| start_value.clone()); + + Ok(expanded! { + border_${axis}_start_${prop}: start_value, + border_${axis}_end_${prop}: end_value, + }) + } + + impl<'a> ToCss for LonghandsToSerialize<'a> { + fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { + self.border_${axis}_start_${prop}.to_css(dest)?; + + if self.border_${axis}_end_${prop} != self.border_${axis}_start_${prop} { + dest.write_str(" ")?; + self.border_${axis}_end_${prop}.to_css(dest)?; + } + + Ok(()) + } + } + + % endfor +% endfor + % for axis in ["block", "inline"]: <% spec = "https://drafts.csswg.org/css-logical/#propdef-border-%s" % (axis)