diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 8610888bef7..dc4bbe464a7 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -54,12 +54,6 @@ pub enum LineDirection { Corner(HorizontalPositionKeyword, VerticalPositionKeyword), } -/// A computed gradient item. -pub type GradientItem = generic::GenericGradientItem; - -/// A computed color stop. -pub type ColorStop = generic::ColorStop; - /// Computed values for `-moz-image-rect(...)`. #[cfg(feature = "gecko")] pub type MozImageRect = generic::GenericMozImageRect; diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index c1c83f829a8..1566ab0f391 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -57,7 +57,7 @@ pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; -pub use self::image::{Gradient, GradientItem, Image, LineDirection, MozImageRect}; +pub use self::image::{Gradient, Image, LineDirection, MozImageRect}; pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength}; pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber}; pub use self::length::{LengthOrAuto, LengthPercentageOrAuto, MaxSize, Size}; diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index 4b79dcb9cb8..f6206a9fb25 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -180,7 +180,7 @@ pub enum ShapeExtent { Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem, )] #[repr(C, u8)] -pub enum GenericGradientItem { +pub enum GenericGradientItem { /// A simple color stop, without position. SimpleColorStop(Color), /// A complex color stop, with a position. @@ -188,10 +188,10 @@ pub enum GenericGradientItem { /// The color for the stop. color: Color, /// The position for the stop. - position: LengthPercentage, + position: T, }, /// An interpolation hint. - InterpolationHint(LengthPercentage), + InterpolationHint(T), } pub use self::GenericGradientItem as GradientItem; @@ -201,17 +201,17 @@ pub use self::GenericGradientItem as GradientItem; #[derive( Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem, )] -pub struct ColorStop { +pub struct ColorStop { /// The color of this stop. pub color: Color, /// The position of this stop. - pub position: Option, + pub position: Option, } -impl ColorStop { +impl ColorStop { /// Convert the color stop into an appropriate `GradientItem`. #[inline] - pub fn into_item(self) -> GradientItem { + pub fn into_item(self) -> GradientItem { match self.position { Some(position) => GradientItem::ComplexColorStop { color: self.color, diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 369b1936f87..13e06d44c57 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -92,12 +92,6 @@ pub enum LineDirection { /// A specified ending shape. pub type EndingShape = generic::EndingShape; -/// A specified gradient item. -pub type GradientItem = generic::GradientItem; - -/// A computed color stop. -pub type ColorStop = generic::ColorStop; - /// Specified values for `moz-image-rect` /// -moz-image-rect(, top, right, bottom, left); #[cfg(all(feature = "gecko", not(feature = "cbindgen")))] @@ -256,7 +250,7 @@ impl Parse for Gradient { Shape::Linear => GradientKind::parse_linear(context, i, &mut compat_mode)?, Shape::Radial => GradientKind::parse_radial(context, i, &mut compat_mode)?, }; - let items = GradientItem::parse_comma_separated(context, i)?; + let items = generic::GradientItem::parse_comma_separated(context, i)?; Ok((shape, items)) })?; @@ -778,7 +772,10 @@ impl ShapeExtent { } } -impl GradientItem { +impl generic::GradientItem +where + T: Parse, +{ fn parse_comma_separated<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, @@ -789,20 +786,20 @@ impl GradientItem { loop { input.parse_until_before(Delimiter::Comma, |input| { if seen_stop { - if let Ok(hint) = input.try(|i| LengthPercentage::parse(context, i)) { + if let Ok(hint) = input.try(|i| T::parse(context, i)) { seen_stop = false; items.push(generic::GradientItem::InterpolationHint(hint)); return Ok(()); } } - let stop = ColorStop::parse(context, input)?; + let stop = generic::ColorStop::parse(context, input)?; - if let Ok(multi_position) = input.try(|i| LengthPercentage::parse(context, i)) { + if let Ok(multi_position) = input.try(|i| T::parse(context, i)) { let stop_color = stop.color.clone(); items.push(stop.into_item()); items.push( - ColorStop { + generic::ColorStop { color: stop_color, position: Some(multi_position), } @@ -830,14 +827,17 @@ impl GradientItem { } } -impl Parse for ColorStop { +impl Parse for generic::ColorStop +where + T: Parse, +{ fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - Ok(ColorStop { + Ok(generic::ColorStop { color: Color::parse(context, input)?, - position: input.try(|i| LengthPercentage::parse(context, i)).ok(), + position: input.try(|i| T::parse(context, i)).ok(), }) } } diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index ff24404c09a..f7d7023a51a 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -28,7 +28,7 @@ use std::ops::{Add, Mul}; use style_traits::values::specified::AllowedNumericType; use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind}; -pub use super::image::{ColorStop, EndingShape as GradientEndingShape, Gradient}; +pub use super::image::{EndingShape as GradientEndingShape, Gradient}; pub use super::image::{GradientKind, Image}; pub use crate::values::specified::calc::CalcLengthPercentage; diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index d45643d6604..aa8bda5c227 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -55,8 +55,8 @@ pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; -pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient}; -pub use self::image::{GradientItem, GradientKind, Image, MozImageRect}; +pub use self::image::{EndingShape as GradientEndingShape, Gradient}; +pub use self::image::{GradientKind, Image, MozImageRect}; pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth}; pub use self::length::{FontRelativeLength, Length, LengthOrNumber, NonNegativeLengthOrNumber}; pub use self::length::{LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};