Bug 1900230: Move `Inset` from `length` to `position` module. r=emilio

Depends on D221546

Differential Revision: https://phabricator.services.mozilla.com/D221639
This commit is contained in:
David Shin 2024-09-10 14:11:16 +00:00
Родитель c698a4becf
Коммит b6b6fcd242
9 изменённых файлов: 91 добавлений и 93 удалений

Просмотреть файл

@ -446,7 +446,7 @@ cbindgen-types = [
{ gecko = "StyleGenericLengthPercentageOrNormal", servo = "crate::values::generics::length::LengthPercentageOrNormal" },
{ gecko = "StyleLengthPercentageOrAuto", servo = "crate::values::computed::LengthPercentageOrAuto" },
{ gecko = "StyleNonNegativeLengthPercentageOrAuto", servo = "crate::values::computed::NonNegativeLengthPercentageOrAuto" },
{ gecko = "StyleInset", servo = "crate::values::computed::length::Inset" },
{ gecko = "StyleInset", servo = "crate::values::computed::position::Inset" },
{ gecko = "StyleRect", servo = "crate::values::generics::rect::Rect" },
{ gecko = "StyleIntersectionObserverRootMargin", servo = "crate::values::specified::gecko::IntersectionObserverRootMargin" },
{ gecko = "StyleGenericSize", servo = "crate::values::generics::length::Size" },

Просмотреть файл

@ -6,7 +6,7 @@
use super::{Context, Number, ToComputedValue};
use crate::values::animated::{Context as AnimatedContext, ToAnimatedValue};
use crate::values::computed::{NonNegativeNumber, Percentage, Zoom};
use crate::values::computed::{NonNegativeNumber, Zoom};
use crate::values::generics::length as generics;
use crate::values::generics::length::{
GenericLengthOrNumber, GenericLengthPercentageOrNormal, GenericMaxSize, GenericSize,
@ -116,9 +116,6 @@ macro_rules! computed_length_percentage_or_auto {
};
}
/// A computed type for `inset` properties.
pub type Inset = generics::GenericInset<Percentage, LengthPercentage>;
/// A computed type for `<length-percentage> | auto`.
pub type LengthPercentageOrAuto = generics::GenericLengthPercentageOrAuto<LengthPercentage>;

Просмотреть файл

@ -78,7 +78,6 @@ 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};
pub use self::length::Inset;
#[cfg(feature = "gecko")]
pub use self::list::ListStyleType;
pub use self::list::Quotes;
@ -90,6 +89,7 @@ pub use self::position::AnchorName;
pub use self::position::AnchorScope;
pub use self::position::AspectRatio;
pub use self::position::DashedIdentAndOrTryTactic;
pub use self::position::Inset;
pub use self::position::PositionAnchor;
pub use self::position::PositionTryFallbacks;
pub use self::position::PositionTryOrder;

Просмотреть файл

@ -8,7 +8,7 @@
//! [position]: https://drafts.csswg.org/css-backgrounds-3/#position
use crate::values::computed::{Integer, LengthPercentage, NonNegativeNumber, Percentage};
use crate::values::generics::position::AspectRatio as GenericAspectRatio;
use crate::values::generics::position::{AspectRatio as GenericAspectRatio, GenericInset};
use crate::values::generics::position::Position as GenericPosition;
use crate::values::generics::position::PositionComponent as GenericPositionComponent;
use crate::values::generics::position::PositionOrAuto as GenericPositionOrAuto;
@ -38,6 +38,9 @@ pub type VerticalPosition = LengthPercentage;
/// The computed value of an `anchor()` function.
pub type AnchorFunction = GenericAnchorFunction<Percentage, LengthPercentage>;
/// A computed type for `inset` properties.
pub type Inset = GenericInset<Percentage, LengthPercentage>;
impl Position {
/// `50% 50%`
#[inline]

Просмотреть файл

@ -5,7 +5,6 @@
//! Generic types for CSS values related to length.
use crate::parser::{Parse, ParserContext};
use crate::values::generics::position::GenericAnchorFunction;
#[cfg(feature = "gecko")]
use crate::Zero;
use cssparser::Parser;
@ -322,52 +321,3 @@ impl<LengthPercent> LengthPercentageOrNormal<LengthPercent> {
LengthPercentageOrNormal::Normal
}
}
/// Specified type for `inset` properties, which allows
/// the use of the `anchor()` function.
/// Note(dshin): `LengthPercentageOrAuto` is not used here because
/// having `LengthPercentageOrAuto` and `AnchorFunction` in the enum
/// pays the price of the discriminator for `LengthPercentage | Auto`
/// as well as `LengthPercentageOrAuto | AnchorFunction`. This increases
/// the size of the style struct, which would not be great.
/// On the other hand, we trade for code duplication, so... :(
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToShmem,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
)]
#[repr(C)]
pub enum GenericInset<P, LP> {
/// A `<length-percentage>` value.
LengthPercentage(LP),
/// An `auto` value.
Auto,
/// Inset defined by the anchor element.
///
/// <https://drafts.csswg.org/css-anchor-position-1/#anchor-pos>
AnchorFunction(
#[animation(field_bound)]
#[distance(field_bound)]
Box<GenericAnchorFunction<P, LP>>,
),
}
impl<P, LP> GenericInset<P, LP> {
/// `auto` value.
#[inline]
pub fn auto() -> Self {
Self::Auto
}
}
pub use self::GenericInset as Inset;

Просмотреть файл

@ -247,6 +247,55 @@ impl<N> ToAnimatedZero for AspectRatio<N> {
}
}
/// Specified type for `inset` properties, which allows
/// the use of the `anchor()` function.
/// Note(dshin): `LengthPercentageOrAuto` is not used here because
/// having `LengthPercentageOrAuto` and `AnchorFunction` in the enum
/// pays the price of the discriminator for `LengthPercentage | Auto`
/// as well as `LengthPercentageOrAuto | AnchorFunction`. This increases
/// the size of the style struct, which would not be great.
/// On the other hand, we trade for code duplication, so... :(
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToCss,
ToShmem,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToResolvedValue,
)]
#[repr(C)]
pub enum GenericInset<P, LP> {
/// A `<length-percentage>` value.
LengthPercentage(LP),
/// An `auto` value.
Auto,
/// Inset defined by the anchor element.
///
/// <https://drafts.csswg.org/css-anchor-position-1/#anchor-pos>
AnchorFunction(
#[animation(field_bound)]
#[distance(field_bound)]
Box<GenericAnchorFunction<P, LP>>,
),
}
impl<P, LP> GenericInset<P, LP> {
/// `auto` value.
#[inline]
pub fn auto() -> Self {
Self::Auto
}
}
pub use self::GenericInset as Inset;
/// Anchor function used by inset properties. This resolves
/// to length at computed time.
///

Просмотреть файл

@ -19,7 +19,6 @@ use crate::values::generics::length::{
};
use crate::values::generics::NonNegative;
use crate::values::specified::calc::{self, CalcNode};
use crate::values::specified::position::AnchorFunction;
use crate::values::specified::NonNegativeNumber;
use crate::values::CSSFloat;
use crate::{Zero, ZeroNoPercent};
@ -1812,39 +1811,6 @@ impl ZeroNoPercent for LengthPercentage {
}
}
/// A specified value for inset types.
pub type Inset = generics::GenericInset<Percentage, LengthPercentage>;
impl Inset {
/// Parses an inset type, allowing the unitless length quirk.
/// <https://quirks.spec.whatwg.org/#the-unitless-length-quirk>
#[inline]
pub fn parse_quirky<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
if let Ok(l) = input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
{
return Ok(Self::LengthPercentage(l));
}
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(Self::Auto);
}
let inner = AnchorFunction::parse(context, input)?;
Ok(Self::AnchorFunction(Box::new(inner)))
}
}
impl Parse for Inset {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Self::parse_quirky(context, input, AllowQuirks::No)
}
}
/// A specified type for `<length-percentage> | auto`.
pub type LengthPercentageOrAuto = generics::LengthPercentageOrAuto<LengthPercentage>;

Просмотреть файл

@ -71,7 +71,6 @@ pub use self::length::{NoCalcLength, ViewportPercentageLength, ViewportVariant};
pub use self::length::{
NonNegativeLength, NonNegativeLengthPercentage, NonNegativeLengthPercentageOrAuto,
};
pub use self::length::Inset;
#[cfg(feature = "gecko")]
pub use self::list::ListStyleType;
pub use self::list::Quotes;
@ -82,6 +81,7 @@ pub use self::percentage::{NonNegativePercentage, Percentage};
pub use self::position::AnchorName;
pub use self::position::AnchorScope;
pub use self::position::AspectRatio;
pub use self::position::Inset;
pub use self::position::PositionAnchor;
pub use self::position::PositionTryFallbacks;
pub use self::position::PositionTryOrder;

Просмотреть файл

@ -12,7 +12,7 @@ use crate::selector_map::PrecomputedHashMap;
use crate::str::HTML_SPACE_CHARACTERS;
use crate::values::computed::LengthPercentage as ComputedLengthPercentage;
use crate::values::computed::{Context, Percentage, ToComputedValue};
use crate::values::generics::position::GenericAnchorFunction;
use crate::values::generics::position::{GenericAnchorFunction, GenericInset};
use crate::values::generics::position::Position as GenericPosition;
use crate::values::generics::position::PositionComponent as GenericPositionComponent;
use crate::values::generics::position::PositionOrAuto as GenericPositionOrAuto;
@ -1689,6 +1689,39 @@ impl AspectRatio {
}
}
/// A specified value for inset types.
pub type Inset = GenericInset<specified::Percentage, LengthPercentage>;
impl Inset {
/// Parses an inset type, allowing the unitless length quirk.
/// <https://quirks.spec.whatwg.org/#the-unitless-length-quirk>
#[inline]
pub fn parse_quirky<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
if let Ok(l) = input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
{
return Ok(Self::LengthPercentage(l));
}
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
return Ok(Self::Auto);
}
let inner = AnchorFunction::parse(context, input)?;
Ok(Self::AnchorFunction(Box::new(inner)))
}
}
impl Parse for Inset {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
Self::parse_quirky(context, input, AllowQuirks::No)
}
}
/// A specified value for `anchor()` function.
pub type AnchorFunction = GenericAnchorFunction<specified::Percentage, LengthPercentage>;