mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Move extremum lengths to the individual Size / MaxSize types
This will prevent growing them when introducing fit-content(<length>). This can _almost_ be derived, if it wasn't because of the quirky stuff. I think the macro is probably good enough for now but let me know if you disagree. Differential Revision: https://phabricator.services.mozilla.com/D106713
This commit is contained in:
parent
320f12aa07
commit
291b3ee573
4 changed files with 44 additions and 58 deletions
|
@ -185,7 +185,10 @@ impl Size {
|
|||
GenericSize::Auto => false,
|
||||
GenericSize::LengthPercentage(ref lp) => lp.is_definitely_zero(),
|
||||
#[cfg(feature = "gecko")]
|
||||
GenericSize::ExtremumLength(..) => false,
|
||||
GenericSize::MinContent |
|
||||
GenericSize::MaxContent |
|
||||
GenericSize::MozFitContent |
|
||||
GenericSize::MozAvailable => false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -495,37 +498,6 @@ pub type NonNegativeLengthPercentageOrNormal =
|
|||
/// Either a non-negative `<length>` or a `<number>`.
|
||||
pub type NonNegativeLengthOrNumber = GenericLengthOrNumber<NonNegativeLength, NonNegativeNumber>;
|
||||
|
||||
/// A type for possible values for min- and max- flavors of width, height,
|
||||
/// block-size, and inline-size.
|
||||
#[allow(missing_docs)]
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(
|
||||
Clone,
|
||||
Copy,
|
||||
Debug,
|
||||
Eq,
|
||||
FromPrimitive,
|
||||
MallocSizeOf,
|
||||
Parse,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToComputedValue,
|
||||
ToCss,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(u8)]
|
||||
pub enum ExtremumLength {
|
||||
#[parse(aliases = "-moz-max-content")]
|
||||
MaxContent,
|
||||
#[parse(aliases = "-moz-min-content")]
|
||||
MinContent,
|
||||
MozFitContent,
|
||||
MozAvailable,
|
||||
}
|
||||
|
||||
/// A computed value for `min-width`, `min-height`, `width` or `height` property.
|
||||
pub type Size = GenericSize<NonNegativeLengthPercentage>;
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ pub use self::font::{FontVariantAlternates, FontWeight};
|
|||
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
|
||||
pub use self::font::{MathDepth, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
||||
pub use self::image::{Gradient, Image, LineDirection, MozImageRect};
|
||||
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength};
|
||||
pub use self::length::{CSSPixelLength, NonNegativeLength};
|
||||
pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber};
|
||||
pub use self::length::{LengthOrAuto, LengthPercentageOrAuto, MaxSize, Size};
|
||||
pub use self::length::{NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto};
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
#[cfg(feature = "gecko")]
|
||||
use crate::values::computed::ExtremumLength;
|
||||
use crate::Zero;
|
||||
use cssparser::Parser;
|
||||
use style_traits::ParseError;
|
||||
|
@ -151,9 +150,14 @@ impl<LengthPercentage: Parse> Parse for LengthPercentageOrAuto<LengthPercentage>
|
|||
pub enum GenericSize<LengthPercent> {
|
||||
LengthPercentage(LengthPercent),
|
||||
Auto,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[animation(error)]
|
||||
ExtremumLength(ExtremumLength),
|
||||
MaxContent,
|
||||
#[animation(error)]
|
||||
MinContent,
|
||||
#[animation(error)]
|
||||
MozFitContent,
|
||||
#[animation(error)]
|
||||
MozAvailable,
|
||||
}
|
||||
|
||||
pub use self::GenericSize as Size;
|
||||
|
@ -194,9 +198,16 @@ impl<LengthPercentage> Size<LengthPercentage> {
|
|||
pub enum GenericMaxSize<LengthPercent> {
|
||||
LengthPercentage(LengthPercent),
|
||||
None,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[animation(error)]
|
||||
ExtremumLength(ExtremumLength),
|
||||
#[parse(aliases = "-moz-max-content")]
|
||||
MaxContent,
|
||||
#[animation(error)]
|
||||
#[parse(aliases = "-moz-min-content")]
|
||||
MinContent,
|
||||
#[animation(error)]
|
||||
MozFitContent,
|
||||
#[animation(error)]
|
||||
MozAvailable,
|
||||
}
|
||||
|
||||
pub use self::GenericMaxSize as MaxSize;
|
||||
|
|
|
@ -1226,6 +1226,27 @@ impl Parse for Size {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! parse_size_non_length {
|
||||
($size:ident, $input:expr, $auto_or_none:expr => $auto_or_none_ident:ident) => {{
|
||||
let size = $input.try_parse(|input| {
|
||||
Ok(try_match_ident_ignore_ascii_case! { input,
|
||||
#[cfg(feature = "gecko")]
|
||||
"min-content" | "-moz-min-content" => $size::MinContent,
|
||||
#[cfg(feature = "gecko")]
|
||||
"max-content" | "-moz-max-content" => $size::MaxContent,
|
||||
#[cfg(feature = "gecko")]
|
||||
"-moz-fit-content" => $size::MozFitContent,
|
||||
#[cfg(feature = "gecko")]
|
||||
"-moz-available" => $size::MozAvailable,
|
||||
$auto_or_none => $size::$auto_or_none_ident,
|
||||
})
|
||||
});
|
||||
if size.is_ok() {
|
||||
return size;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
impl Size {
|
||||
/// Parses, with quirks.
|
||||
pub fn parse_quirky<'i, 't>(
|
||||
|
@ -1233,16 +1254,7 @@ impl Size {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) {
|
||||
return Ok(GenericSize::ExtremumLength(l));
|
||||
}
|
||||
}
|
||||
|
||||
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(GenericSize::Auto);
|
||||
}
|
||||
parse_size_non_length!(Size, input, "auto" => Auto);
|
||||
|
||||
let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?;
|
||||
Ok(GenericSize::LengthPercentage(length))
|
||||
|
@ -1274,16 +1286,7 @@ impl MaxSize {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) {
|
||||
return Ok(GenericMaxSize::ExtremumLength(l));
|
||||
}
|
||||
}
|
||||
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(GenericMaxSize::None);
|
||||
}
|
||||
parse_size_non_length!(MaxSize, input, "none" => None);
|
||||
|
||||
let length = NonNegativeLengthPercentage::parse_quirky(context, input, allow_quirks)?;
|
||||
Ok(GenericMaxSize::LengthPercentage(length))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue