mirror of
https://github.com/servo/servo.git
synced 2025-08-26 07:38:21 +01:00
Adding support for correct shorthand serialization
This commit is contained in:
parent
49431be44a
commit
3831c0650c
23 changed files with 1186 additions and 643 deletions
|
@ -13,14 +13,39 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
for side in ['top', 'right', 'bottom', 'left'])}">
|
||||
use super::parse_four_sides;
|
||||
use values::specified;
|
||||
let _unused = context;
|
||||
let (top, right, bottom, left) = try!(parse_four_sides(input, specified::parse_border_width));
|
||||
Ok(Longhands {
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
${to_rust_ident('border-%s-width' % side)}:
|
||||
Some(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue(${side})),
|
||||
% endfor
|
||||
})
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let _unused = context;
|
||||
let (top, right, bottom, left) = try!(parse_four_sides(input, specified::parse_border_width));
|
||||
Ok(Longhands {
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
${to_rust_ident('border-%s-width' % side)}:
|
||||
Some(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue(${side})),
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// extract tuple container values so that the different border widths
|
||||
// can be compared via partial eq
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
let ${side} = match self.border_${side}_width {
|
||||
&DeclaredValue::Value(ref value) => DeclaredValue::Value(value.0),
|
||||
&DeclaredValue::WithVariables {
|
||||
css: ref a, first_token_type: ref b, base_url: ref c, from_shorthand: ref d
|
||||
} => DeclaredValue::WithVariables {
|
||||
// WithVariables should not be reachable during serialization
|
||||
css: a.clone(), first_token_type: b.clone(), base_url: c.clone(), from_shorthand: d.clone()
|
||||
},
|
||||
&DeclaredValue::Initial => DeclaredValue::Initial,
|
||||
&DeclaredValue::Inherit => DeclaredValue::Inherit,
|
||||
};
|
||||
% endfor
|
||||
|
||||
super::serialize_four_sides(dest, &top, &right, &bottom, &left)
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
||||
|
||||
|
@ -61,12 +86,13 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
if any { Ok((color, style, width)) } else { Err(()) }
|
||||
}
|
||||
|
||||
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
<%helpers:shorthand name="border-${side}" sub_properties="${' '.join(
|
||||
'border-%s-%s' % (side, prop)
|
||||
for prop in ['color', 'style', 'width']
|
||||
)}">
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let (color, style, width) = try!(super::parse_border(context, input));
|
||||
Ok(Longhands {
|
||||
border_${side}_color: color,
|
||||
|
@ -74,6 +100,19 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
border_${side}_width:
|
||||
width.map(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue),
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
super::serialize_directional_border(
|
||||
dest,
|
||||
self.border_${side}_width,
|
||||
self.border_${side}_style,
|
||||
self.border_${side}_color
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
</%helpers:shorthand>
|
||||
% endfor
|
||||
|
||||
|
@ -82,15 +121,32 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
for side in ['top', 'right', 'bottom', 'left']
|
||||
for prop in ['color', 'style', 'width']
|
||||
)}">
|
||||
let (color, style, width) = try!(super::parse_border(context, input));
|
||||
Ok(Longhands {
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
border_${side}_color: color.clone(),
|
||||
border_${side}_style: style,
|
||||
border_${side}_width:
|
||||
width.map(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue),
|
||||
% endfor
|
||||
})
|
||||
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let (color, style, width) = try!(super::parse_border(context, input));
|
||||
Ok(Longhands {
|
||||
% for side in ["top", "right", "bottom", "left"]:
|
||||
border_${side}_color: color.clone(),
|
||||
border_${side}_style: style,
|
||||
border_${side}_width:
|
||||
width.map(longhands::${to_rust_ident('border-%s-width' % side)}::SpecifiedValue),
|
||||
% endfor
|
||||
})
|
||||
}
|
||||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
// If all longhands are all present, then all sides should be the same,
|
||||
// so we can just one set of color/style/width
|
||||
super::serialize_directional_border(
|
||||
dest,
|
||||
self.border_${side}_width,
|
||||
self.border_${side}_style,
|
||||
self.border_${side}_color
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
</%helpers:shorthand>
|
||||
|
||||
<%helpers:shorthand name="border-radius" sub_properties="${' '.join(
|
||||
|
@ -99,13 +155,33 @@ pub fn parse_border(context: &ParserContext, input: &mut Parser)
|
|||
)}">
|
||||
use values::specified::basic_shape::BorderRadius;
|
||||
|
||||
let _ignored = context;
|
||||
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
|
||||
let _ignored = context;
|
||||
|
||||
let radii = try!(BorderRadius::parse(input));
|
||||
Ok(Longhands {
|
||||
border_top_left_radius: Some(radii.top_left),
|
||||
border_top_right_radius: Some(radii.top_right),
|
||||
border_bottom_right_radius: Some(radii.bottom_right),
|
||||
border_bottom_left_radius: Some(radii.bottom_left),
|
||||
})
|
||||
let radii = try!(BorderRadius::parse(input));
|
||||
Ok(Longhands {
|
||||
border_top_left_radius: Some(radii.top_left),
|
||||
border_top_right_radius: Some(radii.top_right),
|
||||
border_bottom_right_radius: Some(radii.bottom_right),
|
||||
border_bottom_left_radius: Some(radii.bottom_left),
|
||||
})
|
||||
}
|
||||
|
||||
// TODO: I do not understand how border radius works with respect to the slashes /,
|
||||
// so putting a default generic impl for now
|
||||
// https://developer.mozilla.org/en-US/docs/Web/CSS/border-radius
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
try!(self.border_top_left_radius.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(self.border_top_right_radius.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
try!(self.border_bottom_right_radius.to_css(dest));
|
||||
try!(write!(dest, " "));
|
||||
|
||||
self.border_bottom_left_radius.to_css(dest)
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue