diff options
-rw-r--r-- | components/style/properties/gecko.mako.rs | 13 | ||||
-rw-r--r-- | components/style/properties/longhand/inherited_text.mako.rs | 12 | ||||
-rw-r--r-- | components/style/values/computed/length.rs | 4 | ||||
-rw-r--r-- | components/style/values/computed/mod.rs | 3 | ||||
-rw-r--r-- | components/style/values/computed/text.rs | 4 | ||||
-rw-r--r-- | components/style/values/generics/text.rs | 10 | ||||
-rw-r--r-- | components/style/values/specified/length.rs | 7 | ||||
-rw-r--r-- | components/style/values/specified/mod.rs | 4 | ||||
-rw-r--r-- | components/style/values/specified/text.rs | 20 |
9 files changed, 49 insertions, 28 deletions
diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index ca96e3fcb13..46e42442507 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -64,6 +64,7 @@ use values::computed::effects::{BoxShadow, Filter, SimpleShadow}; use values::computed::outline::OutlineStyle; use values::generics::column::ColumnCount; use values::generics::position::ZIndex; +use values::generics::text::MozTabSize; use values::generics::transform::TransformStyle; use computed_values::border_style; @@ -4792,13 +4793,11 @@ fn static_assert() { #[allow(non_snake_case)] pub fn set__moz_tab_size(&mut self, v: longhands::_moz_tab_size::computed_value::T) { - use values::Either; - match v { - Either::First(non_negative_number) => { + MozTabSize::Number(non_negative_number) => { self.gecko.mTabSize.set_value(CoordDataValue::Factor(non_negative_number.0)); } - Either::Second(non_negative_length) => { + MozTabSize::Length(non_negative_length) => { self.gecko.mTabSize.set(non_negative_length); } } @@ -4806,11 +4805,9 @@ fn static_assert() { #[allow(non_snake_case)] pub fn clone__moz_tab_size(&self) -> longhands::_moz_tab_size::computed_value::T { - use values::Either; - match self.gecko.mTabSize.as_value() { - CoordDataValue::Coord(coord) => Either::Second(Au(coord).into()), - CoordDataValue::Factor(number) => Either::First(From::from(number)), + CoordDataValue::Coord(coord) => MozTabSize::Length(Au(coord).into()), + CoordDataValue::Factor(number) => MozTabSize::Number(From::from(number)), _ => unreachable!(), } } diff --git a/components/style/properties/longhand/inherited_text.mako.rs b/components/style/properties/longhand/inherited_text.mako.rs index 8bebe90c876..fbf656054ca 100644 --- a/components/style/properties/longhand/inherited_text.mako.rs +++ b/components/style/properties/longhand/inherited_text.mako.rs @@ -487,11 +487,13 @@ ${helpers.predefined_type( )} ${helpers.predefined_type( - "-moz-tab-size", "length::NonNegativeLengthOrNumber", - "::values::Either::First(From::from(8.0))", - products="gecko", animation_value_type="::values::computed::length::NonNegativeLengthOrNumber", - spec="https://drafts.csswg.org/css-text-3/#tab-size-property")} - + "-moz-tab-size", + "MozTabSize", + "generics::text::MozTabSize::Number(From::from(8.0))", + products="gecko", + animation_value_type="AnimatedMozTabSize", + spec="https://drafts.csswg.org/css-text-3/#tab-size-property", +)} // CSS Compatibility // https://compat.spec.whatwg.org diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index e52e01fbdc6..3b5e4d0c986 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -15,7 +15,6 @@ use style_traits::values::specified::AllowedNumericType; use super::{Number, ToComputedValue, Context, Percentage}; use values::{Auto, CSSFloat, Either, Normal, specified}; use values::animated::{Animate, Procedure, ToAnimatedValue, ToAnimatedZero}; -use values::computed::NonNegativeNumber; use values::distance::{ComputeSquaredDistance, SquaredDistance}; use values::generics::NonNegative; use values::specified::length::{AbsoluteLength, FontBaseSize, FontRelativeLength}; @@ -898,9 +897,6 @@ pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>; /// Either a computed NonNegativeLength or the `normal` keyword. pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>; -/// Either a computed NonNegativeLength or a NonNegativeNumber value. -pub type NonNegativeLengthOrNumber = Either<NonNegativeNumber, NonNegativeLength>; - /// A type for possible values for min- and max- flavors of width, height, /// block-size, and inline-size. #[allow(missing_docs)] diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index eb97d8ace15..6239e92e4a0 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -78,7 +78,8 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; -pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextAlign, TextOverflow, WordSpacing}; +pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize}; +pub use self::text::{TextAlign, TextOverflow, WordSpacing}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform, TransformOperation}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; diff --git a/components/style/values/computed/text.rs b/components/style/values/computed/text.rs index 5de5e450cb6..011477ca781 100644 --- a/components/style/values/computed/text.rs +++ b/components/style/values/computed/text.rs @@ -13,6 +13,7 @@ use values::computed::{NonNegativeLength, NonNegativeNumber}; use values::computed::length::{Length, LengthOrPercentage}; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; +use values::generics::text::MozTabSize as GenericMozTabSize; use values::generics::text::Spacing; use values::specified::text::{TextOverflowSide, TextDecorationLine}; @@ -147,3 +148,6 @@ impl TextDecorationsInEffect { result } } + +/// A specified value for the `-moz-tab-size` property. +pub type MozTabSize = GenericMozTabSize<NonNegativeNumber, NonNegativeLength>; diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index 94955a58b02..fc121295c47 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -133,3 +133,13 @@ impl<N, L> LineHeight<N, L> { LineHeight::Normal } } + +/// A generic value for the `-moz-tab-size` property. +#[derive(Animate, Clone, ComputeSquaredDistance, Copy, Debug, MallocSizeOf)] +#[derive(PartialEq, ToAnimatedValue, ToAnimatedZero, ToComputedValue, ToCss)] +pub enum MozTabSize<Number, Length> { + /// A number. + Number(Number), + /// A length. + Length(Length), +} diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 3ed3b4f5d30..1149e31c8ec 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -20,7 +20,6 @@ use super::{AllowQuirks, Number, ToComputedValue, Percentage}; use values::{Auto, CSSFloat, Either, Normal}; use values::computed::{self, CSSPixelLength, Context, ExtremumLength}; use values::generics::NonNegative; -use values::specified::NonNegativeNumber; use values::specified::calc::CalcNode; pub use values::specified::calc::CalcLengthOrPercentage; @@ -687,12 +686,6 @@ pub type NonNegativeLengthOrNormal = Either<NonNegativeLength, Normal>; /// Either a NonNegativeLength or the `auto` keyword. pub type NonNegativeLengthOrAuto = Either<NonNegativeLength, Auto>; -/// Either a NonNegativeLength or a NonNegativeNumber value. -/// -/// 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)] #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)] diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 7c22f840bda..35d141b5238 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -72,8 +72,8 @@ pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind}; pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth}; pub use self::svg::MozContextProperties; pub use self::table::XSpan; -pub use self::text::{InitialLetter, LetterSpacing, LineHeight, TextDecorationLine}; -pub use self::text::{TextAlign, TextAlignKeyword, TextOverflow, WordSpacing}; +pub use self::text::{InitialLetter, LetterSpacing, LineHeight, MozTabSize, TextAlign}; +pub use self::text::{TextAlignKeyword, TextDecorationLine, TextOverflow, WordSpacing}; pub use self::time::Time; pub use self::transform::{Rotate, Scale, TimingFunction, Transform}; pub use self::transform::{TransformOrigin, TransformStyle, Translate}; diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index 41ebe0cce86..847cd5848cf 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -15,10 +15,11 @@ use values::computed::text::LineHeight as ComputedLineHeight; use values::computed::text::TextOverflow as ComputedTextOverflow; use values::generics::text::InitialLetter as GenericInitialLetter; use values::generics::text::LineHeight as GenericLineHeight; +use values::generics::text::MozTabSize as GenericMozTabSize; use values::generics::text::Spacing; use values::specified::{AllowQuirks, Integer, NonNegativeNumber, Number}; use values::specified::length::{FontRelativeLength, Length, LengthOrPercentage, NoCalcLength}; -use values::specified::length::NonNegativeLengthOrPercentage; +use values::specified::length::{NonNegativeLength, NonNegativeLengthOrPercentage}; /// A specified type for the `initial-letter` property. pub type InitialLetter = GenericInitialLetter<Number, Integer>; @@ -514,3 +515,20 @@ impl ToComputedValue for TextAlign { TextAlign::Keyword(*computed) } } + +/// 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)?)) + } +} |