From efe1a5d2562190ff6b650214ad9d6f13c105df2e Mon Sep 17 00:00:00 2001 From: Ravi Shankar Date: Tue, 21 Mar 2017 14:22:20 +0530 Subject: [PATCH] Add functions for checking and --- components/style/values/specified/grid.rs | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index 82acf232298..5b8225a1147 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -127,6 +127,19 @@ pub enum TrackBreadth { Keyword(TrackKeyword), } +impl TrackBreadth { + /// Check whether this is a `` (i.e., it only has ``) + /// + /// https://drafts.csswg.org/css-grid/#typedef-fixed-breadth + #[inline] + pub fn is_fixed(&self) -> bool { + match *self { + TrackBreadth::Breadth(ref _lop) => true, + _ => false, + } + } +} + /// Parse a single flexible length. pub fn parse_flex(input: &mut Parser) -> Result { match try!(input.next()) { @@ -214,6 +227,32 @@ pub enum TrackSize { FitContent(L), } +impl TrackSize { + /// Check whether this is a `` + /// + /// https://drafts.csswg.org/css-grid/#typedef-fixed-size + pub fn is_fixed(&self) -> bool { + match *self { + TrackSize::Breadth(ref breadth) => breadth.is_fixed(), + // For minmax function, it could be either + // minmax(, ) or minmax(, ), + // and since both variants are a subset of minmax(, ), we only + // need to make sure that they're fixed. So, we don't have to modify the parsing function. + TrackSize::MinMax(ref breadth_1, ref breadth_2) => { + if breadth_1.is_fixed() { + return true // the second value is always a + } + + match *breadth_1 { + TrackBreadth::Flex(_) => false, // should be at this point + _ => breadth_2.is_fixed(), + } + }, + TrackSize::FitContent(_) => false, + } + } +} + impl Default for TrackSize { fn default() -> Self { TrackSize::Breadth(TrackBreadth::Keyword(TrackKeyword::Auto))