Skip to content

Commit

Permalink
Add place-content shorthand property
Browse files Browse the repository at this point in the history
  • Loading branch information
tamamu committed Apr 9, 2017
1 parent d77d752 commit d6f4c8c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
49 changes: 49 additions & 0 deletions components/style/properties/shorthand/position.mako.rs
Expand Up @@ -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>

17 changes: 17 additions & 0 deletions tests/unit/style/properties/serialization.rs
Expand Up @@ -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;");
}
}

0 comments on commit d6f4c8c

Please sign in to comment.