Skip to content

Commit

Permalink
Add functions for checking <fixed-size> and <fixed-breadth>
Browse files Browse the repository at this point in the history
  • Loading branch information
wafflespeanut committed May 18, 2017
1 parent 53c7b0a commit efe1a5d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions components/style/values/specified/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ pub enum TrackBreadth<L> {
Keyword(TrackKeyword),
}

impl<L> TrackBreadth<L> {
/// Check whether this is a `<fixed-breadth>` (i.e., it only has `<length-percentage>`)
///
/// 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<CSSFloat, ()> {
match try!(input.next()) {
Expand Down Expand Up @@ -214,6 +227,32 @@ pub enum TrackSize<L> {
FitContent(L),
}

impl<L> TrackSize<L> {
/// Check whether this is a `<fixed-size>`
///
/// 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(<fixed-breadth>, <track-breadth>) or minmax(<inflexible-breadth>, <fixed-breadth>),
// and since both variants are a subset of minmax(<inflexible-breadth>, <track-breadth>), 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 <track-breadth>
}

match *breadth_1 {
TrackBreadth::Flex(_) => false, // should be <inflexible-breadth> at this point
_ => breadth_2.is_fixed(),
}
},
TrackSize::FitContent(_) => false,
}
}
}

impl<L> Default for TrackSize<L> {
fn default() -> Self {
TrackSize::Breadth(TrackBreadth::Keyword(TrackKeyword::Auto))
Expand Down

0 comments on commit efe1a5d

Please sign in to comment.