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<'i, 't>(
32        context: &ParserContext,
33        input: &mut Parser<'i, 't>,
34    ) -> Result<Self, ParseError<'i>> {
35        let v = input.try_parse(|i| {
36            Ok(try_match_ident_ignore_ascii_case! {i, "content" => Self::Content, })
37        });
38        if v.is_ok() {
39            return v;
40        }
41        Ok(Self::Size(Size::parse_size_for_flex_basis_width(
42            context, input,
43        )?))
44    }
45}