mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
style: Move line-clamp out of mako and do some adjacent clean-up
No behavior change, but simplifies the following patch. Differential Revision: https://phabricator.services.mozilla.com/D155180
This commit is contained in:
parent
3fa76ff2e8
commit
a44db17432
12 changed files with 101 additions and 99 deletions
|
@ -378,6 +378,7 @@ trivial_to_animated_value!(ComputedAngle);
|
|||
trivial_to_animated_value!(ComputedUrl);
|
||||
trivial_to_animated_value!(bool);
|
||||
trivial_to_animated_value!(f32);
|
||||
trivial_to_animated_value!(i32);
|
||||
// Note: This implementation is for ToAnimatedValue of ShapeSource.
|
||||
//
|
||||
// SVGPathData uses Box<[T]>. If we want to derive ToAnimatedValue for all the
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
|
||||
//! Computed types for box properties.
|
||||
|
||||
use crate::values::animated::{Animate, Procedure};
|
||||
use crate::values::computed::length::{LengthPercentage, NonNegativeLength};
|
||||
use crate::values::computed::{Context, Number, ToComputedValue};
|
||||
use crate::values::computed::{Context, Integer, Number, ToComputedValue};
|
||||
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use crate::values::generics::box_::Perspective as GenericPerspective;
|
||||
use crate::values::generics::box_::VerticalAlign as GenericVerticalAlign;
|
||||
use crate::values::generics::box_::ContainIntrinsicSize as GenericContainIntrinsicSize;
|
||||
use crate::values::generics::box_::{GenericLineClamp, GenericPerspective, GenericVerticalAlign, GenericContainIntrinsicSize};
|
||||
use crate::values::specified::box_ as specified;
|
||||
|
||||
pub use crate::values::specified::box_::{
|
||||
|
@ -30,6 +29,22 @@ pub type AnimationIterationCount = GenericAnimationIterationCount<Number>;
|
|||
/// A computed value for the `contain-intrinsic-size` property.
|
||||
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
||||
|
||||
/// A computed value for the `line-clamp` property.
|
||||
pub type LineClamp = GenericLineClamp<Integer>;
|
||||
|
||||
impl Animate for LineClamp {
|
||||
#[inline]
|
||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||
if self.is_none() != other.is_none() {
|
||||
return Err(());
|
||||
}
|
||||
if self.is_none() {
|
||||
return Ok(Self::none())
|
||||
}
|
||||
Ok(Self(self.0.animate(&other.0, procedure)?.max(1)))
|
||||
}
|
||||
}
|
||||
|
||||
impl AnimationIterationCount {
|
||||
/// Returns the value `1.0`.
|
||||
#[inline]
|
||||
|
|
|
@ -47,7 +47,7 @@ pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
|||
pub use self::border::{BorderImageSlice, BorderImageWidth};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, ContainerName, ContainerType};
|
||||
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, ContentVisibility, ContainIntrinsicSize, Float};
|
||||
pub use self::box_::{Display, Overflow, OverflowAnchor, TransitionProperty};
|
||||
pub use self::box_::{Display, LineClamp, Overflow, OverflowAnchor, TransitionProperty};
|
||||
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
|
||||
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
|
||||
pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName};
|
||||
|
@ -101,7 +101,6 @@ pub use self::ui::{Cursor, MozForceBrokenImageIcon, UserSelect};
|
|||
pub use super::specified::TextTransform;
|
||||
pub use super::specified::ViewportVariant;
|
||||
pub use super::specified::{BorderStyle, TextDecorationLine};
|
||||
pub use super::{Auto, Either, None_};
|
||||
pub use app_units::Au;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
|
@ -876,9 +875,6 @@ impl From<CSSInteger> for PositiveInteger {
|
|||
}
|
||||
}
|
||||
|
||||
/// A computed positive `<integer>` value or `none`.
|
||||
pub type PositiveIntegerOrNone = Either<PositiveInteger, None_>;
|
||||
|
||||
/// rect(...) | auto
|
||||
pub type ClipRect = generics::GenericClipRect<LengthOrAuto>;
|
||||
|
||||
|
|
|
@ -107,7 +107,6 @@ pub enum GenericContainIntrinsicSize<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,
|
||||
|
@ -123,6 +122,55 @@ impl<L: ToCss> ToCss for ContainIntrinsicSize<L> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Note that we only implement -webkit-line-clamp as a single, longhand
|
||||
/// property for now, but the spec defines line-clamp as a shorthand for
|
||||
/// separate max-lines, block-ellipsis, and continue properties.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-overflow-3/#line-clamp
|
||||
#[derive(
|
||||
Clone,
|
||||
ComputeSquaredDistance,
|
||||
Copy,
|
||||
Debug,
|
||||
MallocSizeOf,
|
||||
PartialEq,
|
||||
SpecifiedValueInfo,
|
||||
ToComputedValue,
|
||||
ToAnimatedValue,
|
||||
ToAnimatedZero,
|
||||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
#[repr(transparent)]
|
||||
#[value_info(other_values = "auto")]
|
||||
pub struct GenericLineClamp<I>(pub I);
|
||||
|
||||
pub use self::GenericLineClamp as LineClamp;
|
||||
|
||||
impl<I: crate::Zero> LineClamp<I> {
|
||||
/// Returns the `none` value.
|
||||
pub fn none() -> Self {
|
||||
Self(crate::Zero::zero())
|
||||
}
|
||||
|
||||
/// Returns whether we're the `none` value.
|
||||
pub fn is_none(&self) -> bool {
|
||||
self.0.is_zero()
|
||||
}
|
||||
}
|
||||
|
||||
impl<I: crate::Zero + ToCss> ToCss for LineClamp<I> {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.is_none() {
|
||||
return dest.write_str("none");
|
||||
}
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-animations/#animation-iteration-count
|
||||
#[derive(
|
||||
Clone,
|
||||
|
@ -135,13 +183,15 @@ impl<L: ToCss> ToCss for ContainIntrinsicSize<L> {
|
|||
ToResolvedValue,
|
||||
ToShmem,
|
||||
)]
|
||||
pub enum AnimationIterationCount<Number> {
|
||||
pub enum GenericAnimationIterationCount<Number> {
|
||||
/// A `<number>` value.
|
||||
Number(Number),
|
||||
/// The `infinite` keyword.
|
||||
Infinite,
|
||||
}
|
||||
|
||||
pub use self::GenericAnimationIterationCount as AnimationIterationCount;
|
||||
|
||||
/// A generic value for the `perspective` property.
|
||||
#[derive(
|
||||
Animate,
|
||||
|
|
|
@ -48,9 +48,6 @@ pub fn normalize(v: CSSFloat) -> CSSFloat {
|
|||
/// A CSS integer value.
|
||||
pub type CSSInteger = i32;
|
||||
|
||||
define_keyword_type!(None_, "none");
|
||||
define_keyword_type!(Auto, "auto");
|
||||
|
||||
/// Serialize an identifier which is represented as an atom.
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn serialize_atom_identifier<W>(ident: &Atom, dest: &mut W) -> fmt::Result
|
||||
|
|
|
@ -8,11 +8,10 @@ use crate::custom_properties::Name as CustomPropertyName;
|
|||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::properties::{LonghandId, PropertyDeclarationId};
|
||||
use crate::properties::{PropertyId, ShorthandId};
|
||||
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use crate::values::generics::box_::Perspective as GenericPerspective;
|
||||
use crate::values::generics::box_::{GenericAnimationIterationCount, GenericPerspective, GenericLineClamp};
|
||||
use crate::values::generics::box_::{GenericContainIntrinsicSize, GenericVerticalAlign, VerticalAlignKeyword};
|
||||
use crate::values::specified::length::{LengthPercentage, NonNegativeLength};
|
||||
use crate::values::specified::{AllowQuirks, Number};
|
||||
use crate::values::specified::{AllowQuirks, Number, Integer};
|
||||
use crate::values::{CustomIdent, KeyframesName, TimelineName};
|
||||
use crate::Atom;
|
||||
use cssparser::Parser;
|
||||
|
@ -615,6 +614,9 @@ impl Debug for Display {
|
|||
/// A specified value for the `contain-intrinsic-size` property.
|
||||
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
||||
|
||||
/// A specified value for the `line-clamp` property.
|
||||
pub type LineClamp = GenericLineClamp<Integer>;
|
||||
|
||||
/// A specified value for the `vertical-align` property.
|
||||
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
||||
|
||||
|
@ -1443,6 +1445,21 @@ impl Parse for ContainIntrinsicSize {
|
|||
}
|
||||
}
|
||||
|
||||
impl Parse for LineClamp {
|
||||
/// none | <positive-integer>
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(i) = input.try_parse(|i| crate::values::specified::PositiveInteger::parse(context, i))
|
||||
{
|
||||
return Ok(Self(i.0))
|
||||
}
|
||||
input.expect_ident_matching("none")?;
|
||||
Ok(Self::none())
|
||||
}
|
||||
}
|
||||
|
||||
/// https://drafts.csswg.org/css-contain-2/#content-visibility
|
||||
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
|
||||
#[derive(
|
||||
|
|
|
@ -13,7 +13,7 @@ use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as Generic
|
|||
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
|
||||
use super::generics::transform::IsParallelTo;
|
||||
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative};
|
||||
use super::{CSSFloat, CSSInteger, Either, None_};
|
||||
use super::{CSSFloat, CSSInteger};
|
||||
use crate::context::QuirksMode;
|
||||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::serialize_atom_identifier;
|
||||
|
@ -38,7 +38,7 @@ pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
|
|||
pub use self::border::{BorderRadius, BorderSideWidth, BorderSpacing, BorderStyle};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, Display};
|
||||
pub use self::box_::{Appearance, BreakBetween, BreakWithin, ContainerName, ContainerType};
|
||||
pub use self::box_::{Clear, ContentVisibility, ContainIntrinsicSize, Float, Overflow, OverflowAnchor};
|
||||
pub use self::box_::{Clear, ContentVisibility, ContainIntrinsicSize, LineClamp, Float, Overflow, OverflowAnchor};
|
||||
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
|
||||
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
|
||||
pub use self::box_::{ScrollSnapStrictness, ScrollSnapType, ScrollTimelineName};
|
||||
|
@ -708,9 +708,6 @@ impl Parse for PositiveInteger {
|
|||
}
|
||||
}
|
||||
|
||||
/// A specified positive `<integer>` value or `none`.
|
||||
pub type PositiveIntegerOrNone = Either<PositiveInteger, None_>;
|
||||
|
||||
/// The specified value of a grid `<track-breadth>`
|
||||
pub type TrackBreadth = GenericTrackBreadth<LengthPercentage>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue