mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use Rust types for some misc properties.
-moz-tab-size, border-image-outset and border-image-slice. This is not a particularly interesting patch, just removes some code. We can remove way more code when a few related properties are also ported. Differential Revision: https://phabricator.services.mozilla.com/D19825
This commit is contained in:
parent
eefd440656
commit
6118e4d993
16 changed files with 149 additions and 184 deletions
|
@ -11,9 +11,10 @@ use crate::font_metrics::FontMetricsQueryResult;
|
|||
use crate::parser::{Parse, ParserContext};
|
||||
use crate::values::computed::{self, CSSPixelLength, Context};
|
||||
use crate::values::generics::length as generics;
|
||||
use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize};
|
||||
use crate::values::generics::length::{MaxSize as GenericMaxSize, Size as GenericSize, GenericLengthOrNumber};
|
||||
use crate::values::generics::transform::IsZeroLength;
|
||||
use crate::values::generics::NonNegative;
|
||||
use crate::values::specified::NonNegativeNumber;
|
||||
use crate::values::specified::calc::CalcNode;
|
||||
use crate::values::{Auto, CSSFloat, Either, Normal};
|
||||
use app_units::Au;
|
||||
|
@ -1023,30 +1024,7 @@ pub type LengthOrNormal = Either<Length, Normal>;
|
|||
pub type LengthOrAuto = Either<Length, Auto>;
|
||||
|
||||
/// Either a `<length>` or a `<number>`.
|
||||
pub type LengthOrNumber = Either<Length, Number>;
|
||||
|
||||
impl LengthOrNumber {
|
||||
/// Parse a non-negative LengthOrNumber.
|
||||
pub fn parse_non_negative<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// We try to parse as a Number first because, for cases like
|
||||
// LengthOrNumber, we want "0" to be parsed as a plain Number rather
|
||||
// than a Length (0px); this matches the behaviour of all major browsers
|
||||
if let Ok(v) = input.try(|i| Number::parse_non_negative(context, i)) {
|
||||
return Ok(Either::Second(v));
|
||||
}
|
||||
|
||||
Length::parse_non_negative(context, input).map(Either::First)
|
||||
}
|
||||
|
||||
/// Returns `0`.
|
||||
#[inline]
|
||||
pub fn zero() -> Self {
|
||||
Either::Second(Number::new(0.))
|
||||
}
|
||||
}
|
||||
pub type LengthOrNumber = GenericLengthOrNumber<Length, Number>;
|
||||
|
||||
/// A specified value for `min-width`, `min-height`, `width` or `height` property.
|
||||
pub type Size = GenericSize<NonNegativeLengthPercentage>;
|
||||
|
@ -1123,3 +1101,6 @@ impl MaxSize {
|
|||
Ok(GenericMaxSize::LengthPercentage(length))
|
||||
}
|
||||
}
|
||||
|
||||
/// A specified non-negative `<length>` | `<number>`.
|
||||
pub type NonNegativeLengthOrNumber = GenericLengthOrNumber<NonNegativeLength, NonNegativeNumber>;
|
||||
|
|
|
@ -19,8 +19,9 @@ use crate::values::serialize_atom_identifier;
|
|||
use crate::values::specified::calc::CalcNode;
|
||||
use crate::{Atom, Namespace, Prefix};
|
||||
use cssparser::{Parser, Token};
|
||||
use num_traits::One;
|
||||
use num_traits::{Zero, One};
|
||||
use std::f32;
|
||||
use std::ops::Add;
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::values::specified::AllowedNumericType;
|
||||
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss};
|
||||
|
@ -58,7 +59,7 @@ pub use self::gecko::ScrollSnapPoint;
|
|||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||
pub use self::image::{GradientItem, GradientKind, Image, ImageLayer, MozImageRect};
|
||||
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
|
||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber};
|
||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber, NonNegativeLengthOrNumber};
|
||||
pub use self::length::{LengthPercentage, LengthPercentageOrAuto};
|
||||
pub use self::length::{MaxSize, Size};
|
||||
pub use self::length::{NoCalcLength, ViewportPercentageLength};
|
||||
|
@ -71,14 +72,14 @@ pub use self::outline::OutlineStyle;
|
|||
pub use self::percentage::Percentage;
|
||||
pub use self::position::{GridAutoFlow, GridTemplateAreas, Position};
|
||||
pub use self::position::{PositionComponent, ZIndex};
|
||||
pub use self::rect::LengthOrNumberRect;
|
||||
pub use self::rect::NonNegativeLengthOrNumberRect;
|
||||
pub use self::resolution::Resolution;
|
||||
pub use self::svg::MozContextProperties;
|
||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||
pub use self::svg_path::SVGPathData;
|
||||
pub use self::table::XSpan;
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign};
|
||||
pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextAlign};
|
||||
pub use self::text::{OverflowWrap, TextEmphasisPosition, TextEmphasisStyle};
|
||||
pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing};
|
||||
pub use self::time::Time;
|
||||
|
@ -271,6 +272,26 @@ impl IsParallelTo for (Number, Number, Number) {
|
|||
|
||||
impl SpecifiedValueInfo for Number {}
|
||||
|
||||
impl Add for Number {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, other: Self) -> Self {
|
||||
Self::new(self.get() + other.get())
|
||||
}
|
||||
}
|
||||
|
||||
impl Zero for Number {
|
||||
#[inline]
|
||||
fn zero() -> Self {
|
||||
Self::new(0.)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_zero(&self) -> bool {
|
||||
self.get() == 0.
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Number> for f32 {
|
||||
#[inline]
|
||||
fn from(n: Number) -> Self {
|
||||
|
|
|
@ -4,22 +4,8 @@
|
|||
|
||||
//! Specified types for CSS borders.
|
||||
|
||||
use crate::parser::ParserContext;
|
||||
use crate::values::generics::rect::Rect;
|
||||
use crate::values::specified::length::LengthOrNumber;
|
||||
use cssparser::Parser;
|
||||
use style_traits::ParseError;
|
||||
use crate::values::specified::length::NonNegativeLengthOrNumber;
|
||||
|
||||
/// A specified rectangle made of four `<length-or-number>` values.
|
||||
pub type LengthOrNumberRect = Rect<LengthOrNumber>;
|
||||
|
||||
impl LengthOrNumberRect {
|
||||
/// Parses a `LengthOrNumberRect`, rejecting negative values.
|
||||
#[inline]
|
||||
pub fn parse_non_negative<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Rect::parse_with(context, input, LengthOrNumber::parse_non_negative)
|
||||
}
|
||||
}
|
||||
pub type NonNegativeLengthOrNumberRect = Rect<NonNegativeLengthOrNumber>;
|
||||
|
|
|
@ -13,11 +13,10 @@ use crate::values::computed::text::TextOverflow as ComputedTextOverflow;
|
|||
use crate::values::computed::{Context, ToComputedValue};
|
||||
use crate::values::generics::text::InitialLetter as GenericInitialLetter;
|
||||
use crate::values::generics::text::LineHeight as GenericLineHeight;
|
||||
use crate::values::generics::text::MozTabSize as GenericMozTabSize;
|
||||
use crate::values::generics::text::Spacing;
|
||||
use crate::values::specified::length::{FontRelativeLength, Length};
|
||||
use crate::values::specified::length::{LengthPercentage, NoCalcLength};
|
||||
use crate::values::specified::length::{NonNegativeLength, NonNegativeLengthPercentage};
|
||||
use crate::values::specified::length::{NonNegativeLengthPercentage};
|
||||
use crate::values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number};
|
||||
use cssparser::{Parser, Token};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
|
@ -835,25 +834,6 @@ impl From<TextEmphasisPosition> for u8 {
|
|||
}
|
||||
}
|
||||
|
||||
/// A specified value for the `-moz-tab-size` property.
|
||||
pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>;
|
||||
|
||||
impl Parse for MozTabSize {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(number) = input.try(|i| NonNegativeNumber::parse(context, i)) {
|
||||
// Numbers need to be parsed first because `0` must be recognised
|
||||
// as the number `0` and not the length `0px`.
|
||||
return Ok(GenericMozTabSize::Number(number));
|
||||
}
|
||||
Ok(GenericMozTabSize::Length(NonNegativeLength::parse(
|
||||
context, input,
|
||||
)?))
|
||||
}
|
||||
}
|
||||
|
||||
/// Values for the `overflow-wrap` property.
|
||||
#[repr(u8)]
|
||||
#[derive(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue