From 68165113c620020c51aec1ef947655b2ab2b7c4d Mon Sep 17 00:00:00 2001
From: Oriol Brufau <obrufau@igalia.com>
Date: Wed, 19 Mar 2025 15:01:42 +0100
Subject: [PATCH] Enable the `fit-content()` sizing function

Also remove a bunch of dead code.

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
---
 style/values/computed/length.rs  | 71 --------------------------------
 style/values/generics/length.rs  |  2 -
 style/values/specified/length.rs |  4 --
 stylo_static_prefs/src/lib.rs    |  3 ++
 4 files changed, 3 insertions(+), 77 deletions(-)

diff --git a/style/values/computed/length.rs b/style/values/computed/length.rs
index b7e78183e7..7c41b07025 100644
--- a/style/values/computed/length.rs
+++ b/style/values/computed/length.rs
@@ -176,77 +176,6 @@ impl NonNegativeLengthPercentageOrAuto {
     computed_length_percentage_or_auto!(NonNegativeLengthPercentage);
 }
 
-#[cfg(feature = "servo")]
-impl MaxSize {
-    /// Convert the computed value into used value.
-    #[inline]
-    pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
-        match *self {
-            Self::None | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
-                None
-            },
-            Self::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
-            Self::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
-        }
-    }
-
-    /// Convert the computed value into used value if there is enough information.
-    #[inline]
-    pub fn maybe_to_used_value(&self, percentage_basis: Option<Au>) -> Option<Au> {
-        match *self {
-            Self::None | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
-                None
-            },
-            Self::LengthPercentage(ref lp) => lp.maybe_to_used_value(percentage_basis),
-            Self::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
-        }
-    }
-}
-
-impl Size {
-    /// Convert the computed value into used value.
-    #[inline]
-    #[cfg(feature = "servo")]
-    pub fn to_used_value(&self, percentage_basis: Au) -> Option<Au> {
-        match *self {
-            Self::Auto | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
-                None
-            },
-            Self::LengthPercentage(ref lp) => Some(lp.to_used_value(percentage_basis)),
-            Self::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
-        }
-    }
-
-    /// Convert the computed value into used value if there is enough information.
-    #[inline]
-    #[cfg(feature = "servo")]
-    pub fn maybe_to_used_value(&self, percentage_basis: Option<Au>) -> Option<Au> {
-        match *self {
-            Self::Auto | Self::MinContent | Self::MaxContent | Self::FitContent | Self::Stretch => {
-                None
-            },
-            Self::LengthPercentage(ref lp) => lp.maybe_to_used_value(percentage_basis),
-            Self::AnchorSizeFunction(_) => unreachable!("anchor-size() should be disabled"),
-        }
-    }
-
-    /// Returns true if the computed value is absolute 0 or 0%.
-    #[inline]
-    pub fn is_definitely_zero(&self) -> bool {
-        match *self {
-            Self::Auto => false,
-            Self::LengthPercentage(ref lp) => lp.is_definitely_zero(),
-            Self::MinContent |
-            Self::MaxContent |
-            Self::FitContent |
-            Self::Stretch |
-            Self::AnchorSizeFunction(_) => false,
-            #[cfg(feature = "gecko")]
-            Self::MozAvailable | Self::WebkitFillAvailable | Self::FitContentFunction(_) => false,
-        }
-    }
-}
-
 /// The computed `<length>` value.
 #[derive(
     Animate,
diff --git a/style/values/generics/length.rs b/style/values/generics/length.rs
index ecfb278619..2000bb84c1 100644
--- a/style/values/generics/length.rs
+++ b/style/values/generics/length.rs
@@ -169,7 +169,6 @@ pub enum GenericSize<LengthPercent> {
     WebkitFillAvailable,
     #[animation(error)]
     Stretch,
-    #[cfg(feature = "gecko")]
     #[animation(error)]
     #[css(function = "fit-content")]
     FitContentFunction(LengthPercent),
@@ -246,7 +245,6 @@ pub enum GenericMaxSize<LengthPercent> {
     WebkitFillAvailable,
     #[animation(error)]
     Stretch,
-    #[cfg(feature = "gecko")]
     #[animation(error)]
     #[css(function = "fit-content")]
     FitContentFunction(LengthPercent),
diff --git a/style/values/specified/length.rs b/style/values/specified/length.rs
index ddbc6dca22..a77cb943f1 100644
--- a/style/values/specified/length.rs
+++ b/style/values/specified/length.rs
@@ -2050,12 +2050,10 @@ fn is_stretch_enabled() -> bool {
     static_prefs::pref!("layout.css.stretch-size-keyword.enabled")
 }
 
-#[cfg(feature = "gecko")]
 fn is_fit_content_function_enabled() -> bool {
     static_prefs::pref!("layout.css.fit-content-function.enabled")
 }
 
-#[cfg(feature = "gecko")]
 macro_rules! parse_fit_content_function {
     ($size:ident, $input:expr, $context:expr, $allow_quirks:expr) => {
         if is_fit_content_function_enabled() {
@@ -2079,7 +2077,6 @@ impl Size {
         allow_quirks: AllowQuirks,
     ) -> Result<Self, ParseError<'i>> {
         parse_size_non_length!(Size, input, "auto" => Auto);
-        #[cfg(feature = "gecko")]
         parse_fit_content_function!(Size, input, context, allow_quirks);
 
         if let Ok(length) =
@@ -2119,7 +2116,6 @@ impl MaxSize {
         allow_quirks: AllowQuirks,
     ) -> Result<Self, ParseError<'i>> {
         parse_size_non_length!(MaxSize, input, "none" => None);
-        #[cfg(feature = "gecko")]
         parse_fit_content_function!(MaxSize, input, context, allow_quirks);
 
         if let Ok(length) =
diff --git a/stylo_static_prefs/src/lib.rs b/stylo_static_prefs/src/lib.rs
index 97c27c3ac9..1e622d2cf9 100644
--- a/stylo_static_prefs/src/lib.rs
+++ b/stylo_static_prefs/src/lib.rs
@@ -24,6 +24,9 @@ macro_rules! pref {
     ("layout.css.basic-shape-xywh.enabled") => {
         true
     };
+    ("layout.css.fit-content-function.enabled") => {
+        true
+    };
     ("layout.css.relative-color-syntax.enabled") => {
         true
     };