Skip to content

Commit

Permalink
style: Implement the border-{block,inline}-{color,style,width} shorth…
Browse files Browse the repository at this point in the history
…ands.

Bug: 1520236
Reviewed-by: emilio
  • Loading branch information
Mats Palmgren authored and emilio committed Jan 20, 2019
1 parent 424eb94 commit 50babf8
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions components/style/properties/shorthands/border.mako.rs
Expand Up @@ -356,6 +356,50 @@ pub fn parse_border<'i, 't>(
}
</%helpers:shorthand>

% 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<Longhands, ParseError<'i>> {
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<W>(&self, dest: &mut CssWriter<W>) -> 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(())
}
}
</%helpers:shorthand>
% endfor
% endfor

% for axis in ["block", "inline"]:
<%
spec = "https://drafts.csswg.org/css-logical/#propdef-border-%s" % (axis)
Expand Down

0 comments on commit 50babf8

Please sign in to comment.