diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index bcba3eb9bce..3f8c04abaab 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -188,7 +188,8 @@ impl Size { GenericSize::MinContent | GenericSize::MaxContent | GenericSize::MozFitContent | - GenericSize::MozAvailable => false + GenericSize::MozAvailable | + GenericSize::FitContentFunction(_) => false } } } diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index f3e025f80b7..97e9712eabc 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -161,6 +161,9 @@ pub enum GenericSize { #[cfg(feature = "gecko")] #[animation(error)] MozAvailable, + #[animation(error)] + #[css(function = "fit-content")] + FitContentFunction(LengthPercent) } pub use self::GenericSize as Size; @@ -215,6 +218,9 @@ pub enum GenericMaxSize { #[cfg(feature = "gecko")] #[animation(error)] MozAvailable, + #[animation(error)] + #[css(function = "fit-content")] + FitContentFunction(LengthPercent), } pub use self::GenericMaxSize as MaxSize; diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index aaad895dbce..03189e28caf 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1247,6 +1247,30 @@ macro_rules! parse_size_non_length { }}; } +#[cfg(feature = "gecko")] +fn is_fit_content_function_enabled() -> bool { + static_prefs::pref!("layout.css.fit-content-function.enabled") +} +#[cfg(feature = "servo")] +fn is_fit_content_function_enabled() -> bool { + false +} + +macro_rules! parse_fit_content_function { + ($size:ident, $input:expr, $context:expr, $allow_quirks:expr) => { + if is_fit_content_function_enabled() { + if let Ok(length) = $input.try_parse(|input| { + input.expect_function_matching("fit-content")?; + input.parse_nested_block(|i| { + NonNegativeLengthPercentage::parse_quirky($context, i, $allow_quirks) + }) + }) { + return Ok($size::FitContentFunction(length)); + } + } + }; +} + impl Size { /// Parses, with quirks. pub fn parse_quirky<'i, 't>( @@ -1255,6 +1279,7 @@ impl Size { allow_quirks: AllowQuirks, ) -> Result> { parse_size_non_length!(Size, input, "auto" => Auto); + parse_fit_content_function!(Size, input, context, allow_quirks); let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?; Ok(GenericSize::LengthPercentage(length)) @@ -1287,6 +1312,7 @@ impl MaxSize { allow_quirks: AllowQuirks, ) -> Result> { parse_size_non_length!(MaxSize, input, "none" => None); + parse_fit_content_function!(MaxSize, input, context, allow_quirks); let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?; Ok(GenericMaxSize::LengthPercentage(length))