diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 3d4009d750fc..0f4a97528bd9 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -137,3 +137,52 @@ } + +<%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 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 { + 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(&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) + } + } + + diff --git a/tests/unit/style/properties/serialization.rs b/tests/unit/style/properties/serialization.rs index 535a52daa6d2..112fb97e0c6e 100644 --- a/tests/unit/style/properties/serialization.rs +++ b/tests/unit/style/properties/serialization.rs @@ -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;"); + } }