From fd184f6b4a991d2cc2feef3cb7d1e0477d827437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Naz=C4=B1m=20Can=20Alt=C4=B1nova?= Date: Mon, 17 Jul 2017 23:18:56 -0700 Subject: [PATCH] Serialize 'minmax(auto, )' as '' --- components/style/values/generics/grid.rs | 32 +++++++++++++++++++++--- tests/unit/style/parsing/position.rs | 2 +- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index 00049814482..fbbc6a4d532 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -203,7 +203,7 @@ impl ToComputedValue for TrackBreadth { /// /// https://drafts.csswg.org/css-grid/#typedef-track-size #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Debug, HasViewportPercentage, PartialEq, ToCss)] +#[derive(Clone, Debug, HasViewportPercentage, PartialEq)] pub enum TrackSize { /// A flexible `` Breadth(TrackBreadth), @@ -211,12 +211,10 @@ pub enum TrackSize { /// and a flexible `` /// /// https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-minmax - #[css(comma, function)] Minmax(TrackBreadth, TrackBreadth), /// A `fit-content` function. /// /// https://drafts.csswg.org/css-grid/#valdef-grid-template-columns-fit-content - #[css(function)] FitContent(L), } @@ -259,6 +257,34 @@ impl TrackSize { } } +impl ToCss for TrackSize { + fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { + match *self { + TrackSize::Breadth(ref breadth) => breadth.to_css(dest), + TrackSize::Minmax(ref min, ref max) => { + // According to gecko minmax(auto, ) is equivalent to , + // and both are serialized as . + if let TrackBreadth::Keyword(TrackKeyword::Auto) = *min { + if let TrackBreadth::Flex(_) = *max { + return max.to_css(dest); + } + } + + dest.write_str("minmax(")?; + min.to_css(dest)?; + dest.write_str(", ")?; + max.to_css(dest)?; + dest.write_str(")") + }, + TrackSize::FitContent(ref lop) => { + dest.write_str("fit-content(")?; + lop.to_css(dest)?; + dest.write_str(")") + }, + } + } +} + impl ToComputedValue for TrackSize { type ComputedValue = TrackSize; diff --git a/tests/unit/style/parsing/position.rs b/tests/unit/style/parsing/position.rs index 9029e401355..87f11b90cfb 100644 --- a/tests/unit/style/parsing/position.rs +++ b/tests/unit/style/parsing/position.rs @@ -237,7 +237,7 @@ fn test_computed_grid_template_rows_colums() { assert_computed_serialization(grid_template_rows::parse, "10px repeat(2, 1fr auto minmax(200px, 1fr))", - "10px minmax(auto, 1fr) auto minmax(200px, 1fr) minmax(auto, 1fr) auto minmax(200px, 1fr)"); + "10px 1fr auto minmax(200px, 1fr) 1fr auto minmax(200px, 1fr)"); assert_computed_serialization(grid_template_rows::parse, "subgrid [a] [] repeat(auto-fill, [])", "subgrid [a] [] repeat(auto-fill, [])");