Add place-content shorthand property

This commit is contained in:
tamamu 2017-04-10 02:58:02 +09:00
parent d77d752990
commit d6f4c8c6dd
2 changed files with 66 additions and 0 deletions

View file

@ -137,3 +137,52 @@
}
</%helpers:shorthand>
<%helpers:shorthand name="place-content" sub_properties="align-content justify-content"
spec="https://drafts.csswg.org/css-align/#propdef-place-content"
products="gecko">
use properties::longhands::align_content;
use properties::longhands::justify_content;
% if product == "servo":
impl From<align_content::SpecifiedValue> for justify_content::SpecifiedValue {
fn from(align: align_content::SpecifiedValue) ->
justify_content::SpecifiedValue {
match align {
align_content::SpecifiedValue::stretch =>
justify_content::SpecifiedValue::stretch,
align_content::SpecifiedValue::flex_start =>
justify_content::SpecifiedValue::flex_start,
align_content::SpecifiedValue::flex_end =>
justify_content::SpecifiedValue::flex_end,
align_content::SpecifiedValue::center =>
justify_content::SpecifiedValue::center,
align_content::SpecifiedValue::space_between =>
justify_content::SpecifiedValue::space_between,
align_content::SpecifiedValue::space_around =>
justify_content::SpecifiedValue::space_around,
}
}
}
% endif
pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
let align = align_content::parse(context, input)?;
let justify = input.try(|input| justify_content::parse(context, input))
.unwrap_or(justify_content::SpecifiedValue::from(align));
Ok(Longhands {
align_content: align,
justify_content: justify,
})
}
impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
self.align_content.to_css(dest)?;
dest.write_str(" ")?;
self.justify_content.to_css(dest)
}
}
</%helpers:shorthand>

View file

@ -1246,4 +1246,21 @@ mod shorthand_serialization {
assert_eq!(counter_increment.to_css_string(), counter_increment_css);
}
}
#[test]
fn place_content_serialize_all_available_properties() {
use style::properties::longhands::align_content::SpecifiedValue as AlignContent;
use style::properties::longhands::justify_content::SpecifiedValue as JustifyContent;
let mut properties = Vec::new();
let align = AlignContent::stretch;
let justify = JustifyContent::center;
properties.push(PropertyDeclaration::AlignContent(align));
properties.push(PropertyDeclaration::JustifyContent(justify));
let serialization = shorthand_properties_to_string(properties);
assert_eq!(serialization, "place-content: stretch center;");
}
}