Simplify properties template a bit.

This commit is contained in:
Simon Sapin 2013-08-23 20:06:21 +01:00
parent a931c8d4a0
commit 254c522ab4

View file

@ -102,61 +102,27 @@ pub mod longhands {
// CSS 2.1, Section 8 - Box model // CSS 2.1, Section 8 - Box model
${predefined_function("margin-top", "specified::LengthOrPercentageOrAuto", % for side in ["top", "right", "bottom", "left"]:
"specified::LengthOrPercentageOrAuto::parse")} ${predefined_type("margin-" + side, "specified::LengthOrPercentageOrAuto")}
${predefined_function("margin-right", "specified::LengthOrPercentageOrAuto", % endfor
"specified::LengthOrPercentageOrAuto::parse")}
${predefined_function("margin-bottom", "specified::LengthOrPercentageOrAuto",
"specified::LengthOrPercentageOrAuto::parse")}
${predefined_function("margin-left", "specified::LengthOrPercentageOrAuto",
"specified::LengthOrPercentageOrAuto::parse")}
${predefined_function("padding-top", % for side in ["top", "right", "bottom", "left"]:
"specified::LengthOrPercentage", ${predefined_function("padding-" + side,
"specified::LengthOrPercentage::parse_non_negative")} "specified::LengthOrPercentage",
${predefined_function("padding-right", "specified::LengthOrPercentage::parse_non_negative")}
"specified::LengthOrPercentage", % endfor
"specified::LengthOrPercentage::parse_non_negative")}
${predefined_function("padding-bottom",
"specified::LengthOrPercentage",
"specified::LengthOrPercentage::parse_non_negative")}
${predefined_function("padding-left",
"specified::LengthOrPercentage",
"specified::LengthOrPercentage::parse_non_negative")}
${predefined_type("border-top-color", "CSSColor")} % for side in ["top", "right", "bottom", "left"]:
${predefined_type("border-right-color", "CSSColor")} ${predefined_type("border-%s-color" % side, "CSSColor")}
${predefined_type("border-bottom-color", "CSSColor")} % endfor
${predefined_type("border-left-color", "CSSColor")}
pub enum BorderStyle { // dotted dashed double groove ridge insed outset hidden
BorderStyleSolid, ${single_keyword("border-top-style", "none solid")}
// Uncomment when supported % for side in ["right", "bottom", "left"]:
// BorderStyleDotted, ${predefined_function("border-%s-style" % side,
// BorderStyleDashed, "border_top_style::SpecifiedValue",
// BorderStyleDouble, "border_top_style::from_component_value")}
// BorderStyleGroove, % endfor
// BorderStyleRidge,
// BorderStyleInset,
// BorderStyleOutset,
// BorderStyleHidden,
BorderStyleNone,
}
impl BorderStyle {
pub fn parse(input: &ComponentValue) -> Option<BorderStyle> {
do get_ident_lower(input).chain |keyword| {
match keyword.as_slice() {
"solid" => Some(BorderStyleSolid),
"none" => Some(BorderStyleNone),
_ => None,
}
}
}
}
${predefined_type("border-top-style", "BorderStyle")}
${predefined_type("border-right-style", "BorderStyle")}
${predefined_type("border-bottom-style", "BorderStyle")}
${predefined_type("border-left-style", "BorderStyle")}
pub fn parse_border_width(component_value: &ComponentValue) -> Option<specified::Length> { pub fn parse_border_width(component_value: &ComponentValue) -> Option<specified::Length> {
match component_value { match component_value {
@ -169,10 +135,9 @@ pub mod longhands {
_ => specified::Length::parse_non_negative(component_value) _ => specified::Length::parse_non_negative(component_value)
} }
} }
${predefined_function("border-top-width", "specified::Length", "parse_border_width")} % for side in ["top", "right", "bottom", "left"]:
${predefined_function("border-right-width", "specified::Length", "parse_border_width")} ${predefined_function("border-%s-width" % side, "specified::Length", "parse_border_width")}
${predefined_function("border-bottom-width", "specified::Length", "parse_border_width")} % endfor
${predefined_function("border-left-width", "specified::Length", "parse_border_width")}
// CSS 2.1, Section 9 - Visual formatting model // CSS 2.1, Section 9 - Visual formatting model
@ -465,11 +430,14 @@ pub mod shorthands {
</%self:shorthand> </%self:shorthand>
${four_sides_shorthand("border-color", "border-%s-color", "CSSColor::parse")} ${four_sides_shorthand("border-color", "border-%s-color", "CSSColor::parse")}
${four_sides_shorthand("border-style", "border-%s-style", "BorderStyle::parse")} ${four_sides_shorthand("border-style", "border-%s-style",
"border_top_style::from_component_value")}
${four_sides_shorthand("border-width", "border-%s-width", "parse_border_width")} ${four_sides_shorthand("border-width", "border-%s-width", "parse_border_width")}
pub fn parse_border(input: &[ComponentValue]) -> Option<(Option<CSSColor>, Option<BorderStyle>, pub fn parse_border(input: &[ComponentValue])
Option<specified::Length>)> { -> Option<(Option<CSSColor>,
Option<border_top_style::SpecifiedValue>,
Option<specified::Length>)> {
let mut color = None; let mut color = None;
let mut style = None; let mut style = None;
let mut width = None; let mut width = None;
@ -482,7 +450,7 @@ pub mod shorthands {
} }
} }
if style.is_none() { if style.is_none() {
match BorderStyle::parse(component_value) { match border_top_style::from_component_value(component_value) {
Some(s) => { style = Some(s); any = true; loop }, Some(s) => { style = Some(s); any = true; loop },
None => () None => ()
} }
@ -498,42 +466,34 @@ pub mod shorthands {
if any { Some((color, style, width)) } else { None } if any { Some((color, style, width)) } else { None }
} }
<%def name="border_side(side)">
<%self:shorthand name="border-${side}" sub_properties="border-${side}-color % for side in ["top", "right", "bottom", "left"]:
border-${side}-style <%self:shorthand name="border-${side}" sub_properties="${' '.join(
border-${side}-width"> 'border-%s-%s' % (side, prop)
for prop in ['color', 'style', 'width']
)}">
do parse_border(input).map_move |(color, style, width)| { do parse_border(input).map_move |(color, style, width)| {
Longhands { border_${side}_color: color, border_${side}_style: style, Longhands {
border_${side}_width: width } % for prop in ["color", "style", "width"]:
${"border_%s_%s: %s," % (side, prop, prop)}
% endfor
}
} }
</%self:shorthand> </%self:shorthand>
</%def> % endfor
${border_side("top")} <%self:shorthand name="border" sub_properties="${' '.join(
${border_side("right")} 'border-%s-%s' % (side, prop)
${border_side("bottom")} for side in ['top', 'right', 'bottom', 'left']
${border_side("left")} for prop in ['color', 'style', 'width']
)}">
<%self:shorthand name="border" sub_properties="
border-top-color
border-top-width
border-top-style
border-right-color
border-right-width
border-right-style
border-bottom-color
border-bottom-width
border-bottom-style
border-left-color
border-left-width
border-left-style
">
do parse_border(input).map_move |(color, style, width)| { do parse_border(input).map_move |(color, style, width)| {
Longhands { Longhands {
border_top_color: color, border_top_style: style, border_top_width: width, % for side in ["top", "right", "bottom", "left"]:
border_right_color: color, border_right_style: style, border_right_width: width, % for prop in ["color", "style", "width"]:
border_bottom_color: color, border_bottom_style: style, border_bottom_width: width, ${"border_%s_%s: %s," % (side, prop, prop)}
border_left_color: color, border_left_style: style, border_left_width: width, % endfor
% endfor
} }
} }
</%self:shorthand> </%self:shorthand>