mod background;
mod border;
mod font;
mod four_sides;
#[cfg(test)]
mod tests;
use crate::properties::{PropertyId, PropertyList, PropertyValue};
use crate::Result;
pub struct ShorthandExpander;
impl ShorthandExpander {
pub fn expand(
properties: &mut PropertyList,
name: &str,
value: &PropertyValue,
) -> Result<bool> {
match name {
"margin" => {
four_sides::expand_four_sides(
properties,
value,
PropertyId::MarginTop,
PropertyId::MarginRight,
PropertyId::MarginBottom,
PropertyId::MarginLeft,
)?;
Ok(true)
}
"padding" => {
four_sides::expand_four_sides(
properties,
value,
PropertyId::PaddingTop,
PropertyId::PaddingRight,
PropertyId::PaddingBottom,
PropertyId::PaddingLeft,
)?;
Ok(true)
}
"border-width" => {
four_sides::expand_four_sides(
properties,
value,
PropertyId::BorderTopWidth,
PropertyId::BorderRightWidth,
PropertyId::BorderBottomWidth,
PropertyId::BorderLeftWidth,
)?;
Ok(true)
}
"border-color" => {
four_sides::expand_four_sides(
properties,
value,
PropertyId::BorderTopColor,
PropertyId::BorderRightColor,
PropertyId::BorderBottomColor,
PropertyId::BorderLeftColor,
)?;
Ok(true)
}
"border-style" => {
four_sides::expand_four_sides(
properties,
value,
PropertyId::BorderTopStyle,
PropertyId::BorderRightStyle,
PropertyId::BorderBottomStyle,
PropertyId::BorderLeftStyle,
)?;
Ok(true)
}
"border" => {
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderTopWidth,
PropertyId::BorderTopStyle,
PropertyId::BorderTopColor,
)?;
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderRightWidth,
PropertyId::BorderRightStyle,
PropertyId::BorderRightColor,
)?;
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderBottomWidth,
PropertyId::BorderBottomStyle,
PropertyId::BorderBottomColor,
)?;
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderLeftWidth,
PropertyId::BorderLeftStyle,
PropertyId::BorderLeftColor,
)?;
Ok(true)
}
"border-top" => {
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderTopWidth,
PropertyId::BorderTopStyle,
PropertyId::BorderTopColor,
)?;
Ok(true)
}
"border-right" => {
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderRightWidth,
PropertyId::BorderRightStyle,
PropertyId::BorderRightColor,
)?;
Ok(true)
}
"border-bottom" => {
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderBottomWidth,
PropertyId::BorderBottomStyle,
PropertyId::BorderBottomColor,
)?;
Ok(true)
}
"border-left" => {
border::expand_border_shorthand(
properties,
value,
PropertyId::BorderLeftWidth,
PropertyId::BorderLeftStyle,
PropertyId::BorderLeftColor,
)?;
Ok(true)
}
"font" => {
font::expand_font_shorthand(properties, value)?;
Ok(true)
}
"background" => {
background::expand_background_shorthand(properties, value)?;
Ok(true)
}
_ => Ok(false),
}
}
}