Skip to content

Commit

Permalink
style: Add 'row-gap' and 'gap' properties; make 'grid-[column|row]-ga…
Browse files Browse the repository at this point in the history
…p' and 'grid-gap' alias the respective unprefixed properties.

This also makes 'normal' the initial value for the grid-*
properties, per:
w3c/csswg-drafts#2294 (comment)

Bug: 1398482
Reviewed-by: emilio
  • Loading branch information
Mats Palmgren authored and emilio committed Apr 28, 2018
1 parent e5878b9 commit 62c6f58
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
11 changes: 0 additions & 11 deletions components/style/properties/longhand/column.mako.rs
Expand Up @@ -31,17 +31,6 @@ ${helpers.predefined_type(



${helpers.predefined_type(
"column-gap",
"length::NonNegativeLengthOrPercentageOrNormal",
"Either::Second(Normal)",
extra_prefixes="moz",
servo_pref="layout.columns.enabled",
animation_value_type="NonNegativeLengthOrPercentageOrNormal",
spec="https://drafts.csswg.org/css-multicol/#propdef-column-gap",
servo_restyle_damage = "reflow",
)}

${helpers.single_keyword("column-fill", "balance auto", extra_prefixes="moz",
products="gecko", animation_value_type="discrete",
spec="https://drafts.csswg.org/css-multicol/#propdef-column-fill")}
Expand Down
27 changes: 20 additions & 7 deletions components/style/properties/longhand/position.mako.rs
Expand Up @@ -302,13 +302,6 @@ ${helpers.predefined_type("object-position",
animation_value_type="ComputedValue")}

% for kind in ["row", "column"]:
${helpers.predefined_type("grid-%s-gap" % kind,
"NonNegativeLengthOrPercentage",
"computed::NonNegativeLengthOrPercentage::zero()",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-%s-gap" % kind,
animation_value_type="NonNegativeLengthOrPercentage",
products="gecko")}

% for range in ["start", "end"]:
${helpers.predefined_type("grid-%s-%s" % (kind, range),
"GridLine",
Expand Down Expand Up @@ -355,3 +348,23 @@ ${helpers.predefined_type("grid-template-areas",
products="gecko",
animation_value_type="discrete",
spec="https://drafts.csswg.org/css-grid/#propdef-grid-template-areas")}

${helpers.predefined_type("column-gap",
"length::NonNegativeLengthOrPercentageOrNormal",
"Either::Second(Normal)",
alias="grid-column-gap",
extra_prefixes="moz",
servo_pref="layout.columns.enabled",
spec="https://drafts.csswg.org/css-align-3/#propdef-column-gap",
animation_value_type="NonNegativeLengthOrPercentageOrNormal",
servo_restyle_damage = "reflow")}

// no need for -moz- prefixed alias for this property
${helpers.predefined_type("row-gap",
"length::NonNegativeLengthOrPercentageOrNormal",
"Either::Second(Normal)",
alias="grid-row-gap",
servo_pref="layout.columns.enabled",
spec="https://drafts.csswg.org/css-align-3/#propdef-row-gap",
animation_value_type="NonNegativeLengthOrPercentageOrNormal",
servo_restyle_damage = "reflow")}
22 changes: 11 additions & 11 deletions components/style/properties/shorthand/position.mako.rs
Expand Up @@ -108,30 +108,30 @@
}
</%helpers:shorthand>

<%helpers:shorthand name="grid-gap" sub_properties="grid-row-gap grid-column-gap"
spec="https://drafts.csswg.org/css-grid/#propdef-grid-gap"
<%helpers:shorthand name="gap" alias="grid-gap" sub_properties="row-gap column-gap"
spec="https://drafts.csswg.org/css-align-3/#gap-shorthand"
products="gecko">
use properties::longhands::{grid_row_gap, grid_column_gap};
use properties::longhands::{row_gap, column_gap};

pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Longhands, ParseError<'i>> {
let row_gap = grid_row_gap::parse(context, input)?;
let column_gap = input.try(|input| grid_column_gap::parse(context, input)).unwrap_or(row_gap.clone());
let r_gap = row_gap::parse(context, input)?;
let c_gap = input.try(|input| column_gap::parse(context, input)).unwrap_or(r_gap.clone());

Ok(expanded! {
grid_row_gap: row_gap,
grid_column_gap: column_gap,
row_gap: r_gap,
column_gap: c_gap,
})
}

impl<'a> ToCss for LonghandsToSerialize<'a> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
if self.grid_row_gap == self.grid_column_gap {
self.grid_row_gap.to_css(dest)
if self.row_gap == self.column_gap {
self.row_gap.to_css(dest)
} else {
self.grid_row_gap.to_css(dest)?;
self.row_gap.to_css(dest)?;
dest.write_str(" ")?;
self.grid_column_gap.to_css(dest)
self.column_gap.to_css(dest)
}
}
}
Expand Down

0 comments on commit 62c6f58

Please sign in to comment.