From f1e04f76f0064d85a83e5cbe46bb0aa7ca351a09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Tue, 26 Jul 2022 22:43:26 +0000 Subject: [PATCH] style: Properly fail to serialize grid shorthand when not roundtripping Other browsers also don't roundtrip properly, but they fail less severely. Differential Revision: https://phabricator.services.mozilla.com/D152794 --- .../properties/shorthands/position.mako.rs | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/components/style/properties/shorthands/position.mako.rs b/components/style/properties/shorthands/position.mako.rs index 7e2255e7dd1..b5899593bfd 100644 --- a/components/style/properties/shorthands/position.mako.rs +++ b/components/style/properties/shorthands/position.mako.rs @@ -621,7 +621,6 @@ impl<'a> LonghandsToSerialize<'a> { /// Returns true if other sub properties except template-{rows,columns} are initial. fn is_grid_template(&self) -> bool { - *self.grid_template_areas == GridTemplateAreas::None && self.grid_auto_rows.is_initial() && self.grid_auto_columns.is_initial() && *self.grid_auto_flow == grid_auto_flow::get_initial_value() @@ -630,13 +629,19 @@ impl<'a> ToCss for LonghandsToSerialize<'a> { fn to_css(&self, dest: &mut CssWriter) -> fmt::Result where W: fmt::Write { - if *self.grid_template_areas != GridTemplateAreas::None || - (!self.grid_template_rows.is_initial() && - !self.grid_template_columns.is_initial()) || - self.is_grid_template() { - return super::grid_template::serialize_grid_template(self.grid_template_rows, - self.grid_template_columns, - self.grid_template_areas, dest); + if self.is_grid_template() { + return super::grid_template::serialize_grid_template( + self.grid_template_rows, + self.grid_template_columns, + self.grid_template_areas, + dest + ); + } + + if *self.grid_template_areas != GridTemplateAreas::None { + // No other syntax can set the template areas, so fail to + // serialize. + return Ok(()); } if self.grid_auto_flow.contains(GridAutoFlow::COLUMN) { @@ -663,33 +668,35 @@ dest.write_str(" ")?; self.grid_auto_columns.to_css(dest)?; } - } else { - // It should fail to serialize if other branch of the if condition's values are set. - if !self.grid_auto_columns.is_initial() || - !self.grid_template_rows.is_initial() { + + return Ok(()); + } + + // It should fail to serialize if other branch of the if condition's values are set. + if !self.grid_auto_columns.is_initial() || + !self.grid_template_rows.is_initial() { + return Ok(()); + } + + // It should fail to serialize if template-column value is not Explicit. + if let GenericGridTemplateComponent::TrackList(ref list) = *self.grid_template_columns { + if !list.is_explicit() { return Ok(()); } - - // It should fail to serialize if template-column value is not Explicit. - if let GenericGridTemplateComponent::TrackList(ref list) = *self.grid_template_columns { - if !list.is_explicit() { - return Ok(()); - } - } - - dest.write_str("auto-flow")?; - if self.grid_auto_flow.contains(GridAutoFlow::DENSE) { - dest.write_str(" dense")?; - } - - if !self.grid_auto_rows.is_initial() { - dest.write_str(" ")?; - self.grid_auto_rows.to_css(dest)?; - } - - dest.write_str(" / ")?; - self.grid_template_columns.to_css(dest)?; } + + dest.write_str("auto-flow")?; + if self.grid_auto_flow.contains(GridAutoFlow::DENSE) { + dest.write_str(" dense")?; + } + + if !self.grid_auto_rows.is_initial() { + dest.write_str(" ")?; + self.grid_auto_rows.to_css(dest)?; + } + + dest.write_str(" / ")?; + self.grid_template_columns.to_css(dest)?; Ok(()) } }