aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2022-07-26 22:43:26 +0000
committerMartin Robinson <mrobinson@igalia.com>2023-10-02 14:37:19 +0000
commitf1e04f76f0064d85a83e5cbe46bb0aa7ca351a09 (patch)
treeef7e4d0ed0135a49a737529f6d858b6107f73db2
parent59da4326fd763d74ee2e15207bd47d61161ff378 (diff)
downloadservo-f1e04f76f0064d85a83e5cbe46bb0aa7ca351a09.tar.gz
servo-f1e04f76f0064d85a83e5cbe46bb0aa7ca351a09.zip
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
-rw-r--r--components/style/properties/shorthands/position.mako.rs65
1 files changed, 36 insertions, 29 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<W>(&self, dest: &mut CssWriter<W>) -> 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 template-column value is not Explicit.
- if let GenericGridTemplateComponent::TrackList(ref list) = *self.grid_template_columns {
- if !list.is_explicit() {
- return Ok(());
- }
- }
+ return Ok(());
+ }
- dest.write_str("auto-flow")?;
- if self.grid_auto_flow.contains(GridAutoFlow::DENSE) {
- dest.write_str(" dense")?;
- }
+ // 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(());
+ }
- if !self.grid_auto_rows.is_initial() {
- dest.write_str(" ")?;
- self.grid_auto_rows.to_css(dest)?;
+ // 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(" / ")?;
- 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(())
}
}