style: Add support for parsing the contain-intrinsic-size property from the CSS-sizing specification

Differential Revision: https://phabricator.services.mozilla.com/D151001
This commit is contained in:
Ziran Sun 2022-07-06 11:47:51 +00:00 committed by Martin Robinson
parent b0693b2f4d
commit 6fec9d6f8c
7 changed files with 101 additions and 3 deletions

View file

@ -463,3 +463,18 @@ ${helpers.predefined_type(
gecko_pref="layout.css.aspect-ratio.enabled", gecko_pref="layout.css.aspect-ratio.enabled",
servo_restyle_damage="reflow", servo_restyle_damage="reflow",
)} )}
% for (size, logical) in ALL_SIZES:
// FIXME: Bug 1778296, "contain-intrinsic-*" properties should be animatable.
${helpers.predefined_type(
"contain-intrinsic-" + size,
"ContainIntrinsicSize",
"computed::ContainIntrinsicSize::None",
engines="gecko",
logical_group="contain-intrinsic-size",
logical=logical,
gecko_pref="layout.css.contain-intrinsic-size.enabled",
spec="https://drafts.csswg.org/css-sizing-4/#intrinsic-size-override",
animation_value_type="none",
)}
% endfor

View file

@ -861,3 +861,12 @@ ${helpers.two_properties_shorthand(
engines="gecko servo", engines="gecko servo",
spec="https://drafts.csswg.org/css-logical/#propdef-inset-inline" spec="https://drafts.csswg.org/css-logical/#propdef-inset-inline"
)} )}
${helpers.two_properties_shorthand(
"contain-intrinsic-size",
"contain-intrinsic-width",
"contain-intrinsic-height",
engines="gecko",
gecko_pref="layout.css.contain-intrinsic-size.enabled",
spec="https://drafts.csswg.org/css-sizing-4/#intrinsic-size-override",
)}

View file

@ -9,6 +9,7 @@ use crate::values::computed::{Context, Number, ToComputedValue};
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use crate::values::generics::box_::Perspective as GenericPerspective; use crate::values::generics::box_::Perspective as GenericPerspective;
use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign; use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign;
use crate::values::generics::box_::ContainIntrinsicSize as GenericContainIntrinsicSize;
use crate::values::specified::box_ as specified; use crate::values::specified::box_ as specified;
pub use crate::values::specified::box_::{ pub use crate::values::specified::box_::{
@ -26,6 +27,9 @@ pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
/// A computed value for the `animation-iteration-count` property. /// A computed value for the `animation-iteration-count` property.
pub type AnimationIterationCount = GenericAnimationIterationCount<Number>; pub type AnimationIterationCount = GenericAnimationIterationCount<Number>;
/// A computed value for the `contain-intrinsic-size` property.
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
impl AnimationIterationCount { impl AnimationIterationCount {
/// Returns the value `1.0`. /// Returns the value `1.0`.
#[inline] #[inline]

View file

@ -46,7 +46,7 @@ pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth}; pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
pub use self::border::{BorderImageSlice, BorderImageWidth}; pub use self::border::{BorderImageSlice, BorderImageWidth};
pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, ContainerName, ContainerType}; pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, ContainerName, ContainerType};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, ContentVisibility, Float}; pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, ContentVisibility, ContainIntrinsicSize, Float};
pub use self::box_::{Display, Overflow, OverflowAnchor, TransitionProperty}; pub use self::box_::{Display, Overflow, OverflowAnchor, TransitionProperty};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter}; pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop}; pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};

View file

@ -5,6 +5,8 @@
//! Generic types for box properties. //! Generic types for box properties.
use crate::values::animated::ToAnimatedZero; use crate::values::animated::ToAnimatedZero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
#[derive( #[derive(
Animate, Animate,
@ -76,6 +78,49 @@ impl<L> ToAnimatedZero for VerticalAlign<L> {
} }
} }
/// https://drafts.csswg.org/css-sizing-4/#intrinsic-size-override
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToResolvedValue,
ToShmem,
)]
#[value_info(other_values = "auto")]
#[repr(C, u8)]
pub enum GenericContainIntrinsicSize<L> {
/// The keyword `none`.
None,
/// A non-negative length.
Length(L),
/// "auto <Length>"
AutoLength(L),
}
pub use self::GenericContainIntrinsicSize as ContainIntrinsicSize;
impl<L: ToCss> ToCss for ContainIntrinsicSize<L> {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: Write,
{
match *self {
Self::None => dest.write_str("none"),
Self::Length(ref l) => l.to_css(dest),
Self::AutoLength(ref l) => {
dest.write_str("auto ")?;
l.to_css(dest)
}
}
}
}
/// https://drafts.csswg.org/css-animations/#animation-iteration-count /// https://drafts.csswg.org/css-animations/#animation-iteration-count
#[derive( #[derive(
Clone, Clone,

View file

@ -10,7 +10,7 @@ use crate::properties::{LonghandId, PropertyDeclarationId};
use crate::properties::{PropertyId, ShorthandId}; use crate::properties::{PropertyId, ShorthandId};
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount; use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use crate::values::generics::box_::Perspective as GenericPerspective; use crate::values::generics::box_::Perspective as GenericPerspective;
use crate::values::generics::box_::{GenericVerticalAlign, VerticalAlignKeyword}; use crate::values::generics::box_::{GenericContainIntrinsicSize, GenericVerticalAlign, VerticalAlignKeyword};
use crate::values::specified::length::{LengthPercentage, NonNegativeLength}; use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
use crate::values::specified::{AllowQuirks, Number}; use crate::values::specified::{AllowQuirks, Number};
use crate::values::{CustomIdent, KeyframesName, TimelineName}; use crate::values::{CustomIdent, KeyframesName, TimelineName};
@ -621,6 +621,9 @@ impl Debug for Display {
} }
} }
/// A specified value for the `contain-intrinsic-size` property.
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
/// A specified value for the `vertical-align` property. /// A specified value for the `vertical-align` property.
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>; pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
@ -1427,6 +1430,28 @@ bitflags! {
} }
} }
impl Parse for ContainIntrinsicSize {
/// none | <length> | auto <length>
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(l) = input.try_parse(|i| NonNegativeLength::parse(context, i))
{
return Ok(Self::Length(l));
}
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
let l = NonNegativeLength::parse(context, input)?;
return Ok(Self::AutoLength(l));
}
input.expect_ident_matching("none")?;
Ok(Self::None)
}
}
/// https://drafts.csswg.org/css-contain-2/#content-visibility /// https://drafts.csswg.org/css-contain-2/#content-visibility
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive( #[derive(

View file

@ -38,7 +38,7 @@ pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing, BorderStyle}; pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing, BorderStyle};
pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, Display}; pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, Display};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, ContainerName, ContainerType}; pub use self::box_::{Appearance, BreakBetween, BreakWithin, ContainerName, ContainerType};
pub use self::box_::{Clear, ContentVisibility, Float, Overflow, OverflowAnchor}; pub use self::box_::{Clear, ContentVisibility, ContainIntrinsicSize, Float, Overflow, OverflowAnchor};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter}; pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop}; pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName}; pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName};