Skip to main content

style/values/specified/
flex.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5//! Specified types for CSS values related to flexbox.
6
7use crate::parser::{Parse, ParserContext};
8use crate::values::generics::flex::FlexBasis as GenericFlexBasis;
9use crate::values::specified::Size;
10use cssparser::Parser;
11use style_traits::ParseError;
12
13/// A specified value for the `flex-basis` property.
14pub type FlexBasis = GenericFlexBasis<Size>;
15
16impl FlexBasis {
17    /// `auto`
18    #[inline]
19    pub fn auto() -> Self {
20        GenericFlexBasis::Size(Size::auto())
21    }
22
23    /// `0%`
24    #[inline]
25    pub fn zero_percent() -> Self {
26        GenericFlexBasis::Size(Size::zero_percent())
27    }
28}
29
30impl Parse for FlexBasis {
31    fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
32        let v = input.try_parse(|i| {
33            Ok(try_match_ident_ignore_ascii_case! {i, "content" => Self::Content, })
34        });
35        if v.is_ok() {
36            return v;
37        }
38        Ok(Self::Size(Size::parse_size_for_flex_basis_width(
39            context, input,
40        )?))
41    }
42}