mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #20124 - servo:perspective, r=emilio
Replace LengthOrNone by a specific type for the perspective property <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20124) <!-- Reviewable:end -->
This commit is contained in:
commit
6df0dc5b27
12 changed files with 113 additions and 68 deletions
|
@ -13,9 +13,10 @@ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
|||
use values::CustomIdent;
|
||||
use values::KeyframesName;
|
||||
use values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use values::generics::box_::Perspective as GenericPerspective;
|
||||
use values::generics::box_::VerticalAlign as GenericVerticalAlign;
|
||||
use values::specified::{AllowQuirks, Number};
|
||||
use values::specified::length::LengthOrPercentage;
|
||||
use values::specified::length::{LengthOrPercentage, NonNegativeLength};
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
|
||||
|
@ -588,3 +589,18 @@ impl Parse for Contain {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `perspective` property.
|
||||
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
||||
|
||||
impl Parse for Perspective {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(GenericPerspective::None);
|
||||
}
|
||||
Ok(GenericPerspective::Length(NonNegativeLength::parse(context, input)?))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::ops::{Add, Mul};
|
|||
use style_traits::{ParseError, StyleParseErrorKind};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use super::{AllowQuirks, Number, ToComputedValue, Percentage};
|
||||
use values::{Auto, CSSFloat, Either, None_, Normal};
|
||||
use values::{Auto, CSSFloat, Either, Normal};
|
||||
use values::computed::{self, CSSPixelLength, Context, ExtremumLength};
|
||||
use values::generics::NonNegative;
|
||||
use values::specified::NonNegativeNumber;
|
||||
|
@ -640,21 +640,19 @@ impl Length {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Parse> Either<Length, T> {
|
||||
/// Parse a non-negative length
|
||||
#[inline]
|
||||
pub fn parse_non_negative_length<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|input| T::parse(context, input)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
/// A wrapper of Length, whose value must be >= 0.
|
||||
pub type NonNegativeLength = NonNegative<Length>;
|
||||
|
||||
impl Parse for NonNegativeLength {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(NonNegative(Length::parse_non_negative(context, input)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<NoCalcLength> for NonNegativeLength {
|
||||
#[inline]
|
||||
fn from(len: NoCalcLength) -> Self {
|
||||
|
@ -669,17 +667,6 @@ impl From<Length> for NonNegativeLength {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Parse> Parse for Either<NonNegativeLength, T> {
|
||||
#[inline]
|
||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|input| T::parse(context, input)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
Length::parse_internal(context, input, AllowedNumericType::NonNegative, AllowQuirks::No)
|
||||
.map(NonNegative::<Length>).map(Either::First)
|
||||
}
|
||||
}
|
||||
|
||||
impl NonNegativeLength {
|
||||
/// Returns a `zero` length.
|
||||
#[inline]
|
||||
|
@ -701,7 +688,10 @@ pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>;
|
|||
pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>;
|
||||
|
||||
/// Either a NonNegativeLength or a NonNegativeNumber value.
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeLength, NonNegativeNumber>;
|
||||
///
|
||||
/// The order is important, because `0` must be parsed as the number `0` and not
|
||||
/// the length `0px`.
|
||||
pub type NonNegativeLengthOrNumber = Either<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
/// A length or a percentage value.
|
||||
#[allow(missing_docs)]
|
||||
|
@ -1072,9 +1062,6 @@ impl NonNegativeLengthOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
/// Either a `<length>` or the `none` keyword.
|
||||
pub type LengthOrNone = Either<Length, None_>;
|
||||
|
||||
/// Either a `<length>` or the `normal` keyword.
|
||||
pub type LengthOrNormal = Either<Length, Normal>;
|
||||
|
||||
|
|
|
@ -39,8 +39,9 @@ pub use self::font::{FontSize, FontSizeAdjust, FontSynthesis, FontWeight, FontVa
|
|||
pub use self::font::{FontFamily, FontLanguageOverride, FontVariationSettings, FontVariantEastAsian};
|
||||
pub use self::font::{FontVariantLigatures, FontVariantNumeric, FontFeatureSettings};
|
||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XTextZoom, XLang};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, Display, OverscrollBehavior, Contain};
|
||||
pub use self::box_::{OverflowClipBox, ScrollSnapType, TouchAction, VerticalAlign, WillChange};
|
||||
pub use self::box_::{AnimationIterationCount, AnimationName, Contain, Display};
|
||||
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective};
|
||||
pub use self::box_::{ScrollSnapType, TouchAction, VerticalAlign, WillChange};
|
||||
pub use self::color::{Color, ColorPropertyValue, RGBAColor};
|
||||
pub use self::counters::{Content, ContentItem, CounterIncrement, CounterReset};
|
||||
pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
||||
|
@ -51,7 +52,7 @@ pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
|||
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
||||
pub use self::inherited_box::ImageOrientation;
|
||||
pub use self::length::{AbsoluteLength, CalcLengthOrPercentage, CharacterWidth};
|
||||
pub use self::length::{FontRelativeLength, Length, LengthOrNone, LengthOrNumber};
|
||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
|
||||
pub use self::length::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
pub use self::length::{LengthOrPercentageOrNone, MaxLength, MozLength};
|
||||
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue