mirror of
https://github.com/servo/servo.git
synced 2025-06-21 23:59:00 +01:00
style: Part 2: Support fit-content() in style
Support fit-content for preferred size, min size, and max size. This patch only implement the style system. For layout part, we will do that in the following patches. Differential Revision: https://phabricator.services.mozilla.com/D107161
This commit is contained in:
parent
77cab0edc3
commit
d103785c4b
3 changed files with 34 additions and 1 deletions
|
@ -188,7 +188,8 @@ impl Size {
|
|||
GenericSize::MinContent |
|
||||
GenericSize::MaxContent |
|
||||
GenericSize::MozFitContent |
|
||||
GenericSize::MozAvailable => false
|
||||
GenericSize::MozAvailable |
|
||||
GenericSize::FitContentFunction(_) => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -161,6 +161,9 @@ pub enum GenericSize<LengthPercent> {
|
|||
#[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<LengthPercent> {
|
|||
#[cfg(feature = "gecko")]
|
||||
#[animation(error)]
|
||||
MozAvailable,
|
||||
#[animation(error)]
|
||||
#[css(function = "fit-content")]
|
||||
FitContentFunction(LengthPercent),
|
||||
}
|
||||
|
||||
pub use self::GenericMaxSize as MaxSize;
|
||||
|
|
|
@ -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<Self, ParseError<'i>> {
|
||||
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<Self, ParseError<'i>> {
|
||||
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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue