mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Make GradientItem and ColorStop support angular color stops.
Differential Revision: https://phabricator.services.mozilla.com/D62544
This commit is contained in:
parent
5cedc45858
commit
0e3c122890
6 changed files with 26 additions and 32 deletions
|
@ -54,12 +54,6 @@ pub enum LineDirection {
|
||||||
Corner(HorizontalPositionKeyword, VerticalPositionKeyword),
|
Corner(HorizontalPositionKeyword, VerticalPositionKeyword),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A computed gradient item.
|
|
||||||
pub type GradientItem = generic::GenericGradientItem<Color, LengthPercentage>;
|
|
||||||
|
|
||||||
/// A computed color stop.
|
|
||||||
pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;
|
|
||||||
|
|
||||||
/// Computed values for `-moz-image-rect(...)`.
|
/// Computed values for `-moz-image-rect(...)`.
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
pub type MozImageRect = generic::GenericMozImageRect<NumberOrPercentage, ComputedImageUrl>;
|
pub type MozImageRect = generic::GenericMozImageRect<NumberOrPercentage, ComputedImageUrl>;
|
||||||
|
|
|
@ -57,7 +57,7 @@ pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis};
|
||||||
pub use self::font::{FontVariantAlternates, FontWeight};
|
pub use self::font::{FontVariantAlternates, FontWeight};
|
||||||
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
|
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
|
||||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
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::{CSSPixelLength, ExtremumLength, NonNegativeLength};
|
||||||
pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber};
|
pub use self::length::{Length, LengthOrNumber, LengthPercentage, NonNegativeLengthOrNumber};
|
||||||
pub use self::length::{LengthOrAuto, LengthPercentageOrAuto, MaxSize, Size};
|
pub use self::length::{LengthOrAuto, LengthPercentageOrAuto, MaxSize, Size};
|
||||||
|
|
|
@ -180,7 +180,7 @@ pub enum ShapeExtent {
|
||||||
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
|
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
|
||||||
)]
|
)]
|
||||||
#[repr(C, u8)]
|
#[repr(C, u8)]
|
||||||
pub enum GenericGradientItem<Color, LengthPercentage> {
|
pub enum GenericGradientItem<Color, T> {
|
||||||
/// A simple color stop, without position.
|
/// A simple color stop, without position.
|
||||||
SimpleColorStop(Color),
|
SimpleColorStop(Color),
|
||||||
/// A complex color stop, with a position.
|
/// A complex color stop, with a position.
|
||||||
|
@ -188,10 +188,10 @@ pub enum GenericGradientItem<Color, LengthPercentage> {
|
||||||
/// The color for the stop.
|
/// The color for the stop.
|
||||||
color: Color,
|
color: Color,
|
||||||
/// The position for the stop.
|
/// The position for the stop.
|
||||||
position: LengthPercentage,
|
position: T,
|
||||||
},
|
},
|
||||||
/// An interpolation hint.
|
/// An interpolation hint.
|
||||||
InterpolationHint(LengthPercentage),
|
InterpolationHint(T),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use self::GenericGradientItem as GradientItem;
|
pub use self::GenericGradientItem as GradientItem;
|
||||||
|
@ -201,17 +201,17 @@ pub use self::GenericGradientItem as GradientItem;
|
||||||
#[derive(
|
#[derive(
|
||||||
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
|
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
|
||||||
)]
|
)]
|
||||||
pub struct ColorStop<Color, LengthPercentage> {
|
pub struct ColorStop<Color, T> {
|
||||||
/// The color of this stop.
|
/// The color of this stop.
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
/// The position of this stop.
|
/// The position of this stop.
|
||||||
pub position: Option<LengthPercentage>,
|
pub position: Option<T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Color, LengthPercentage> ColorStop<Color, LengthPercentage> {
|
impl<Color, T> ColorStop<Color, T> {
|
||||||
/// Convert the color stop into an appropriate `GradientItem`.
|
/// Convert the color stop into an appropriate `GradientItem`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_item(self) -> GradientItem<Color, LengthPercentage> {
|
pub fn into_item(self) -> GradientItem<Color, T> {
|
||||||
match self.position {
|
match self.position {
|
||||||
Some(position) => GradientItem::ComplexColorStop {
|
Some(position) => GradientItem::ComplexColorStop {
|
||||||
color: self.color,
|
color: self.color,
|
||||||
|
|
|
@ -92,12 +92,6 @@ pub enum LineDirection {
|
||||||
/// A specified ending shape.
|
/// A specified ending shape.
|
||||||
pub type EndingShape = generic::EndingShape<NonNegativeLength, NonNegativeLengthPercentage>;
|
pub type EndingShape = generic::EndingShape<NonNegativeLength, NonNegativeLengthPercentage>;
|
||||||
|
|
||||||
/// A specified gradient item.
|
|
||||||
pub type GradientItem = generic::GradientItem<Color, LengthPercentage>;
|
|
||||||
|
|
||||||
/// A computed color stop.
|
|
||||||
pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;
|
|
||||||
|
|
||||||
/// Specified values for `moz-image-rect`
|
/// Specified values for `moz-image-rect`
|
||||||
/// -moz-image-rect(<uri>, top, right, bottom, left);
|
/// -moz-image-rect(<uri>, top, right, bottom, left);
|
||||||
#[cfg(all(feature = "gecko", not(feature = "cbindgen")))]
|
#[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::Linear => GradientKind::parse_linear(context, i, &mut compat_mode)?,
|
||||||
Shape::Radial => GradientKind::parse_radial(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))
|
Ok((shape, items))
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -778,7 +772,10 @@ impl ShapeExtent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GradientItem {
|
impl<T> generic::GradientItem<Color, T>
|
||||||
|
where
|
||||||
|
T: Parse,
|
||||||
|
{
|
||||||
fn parse_comma_separated<'i, 't>(
|
fn parse_comma_separated<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
|
@ -789,20 +786,20 @@ impl GradientItem {
|
||||||
loop {
|
loop {
|
||||||
input.parse_until_before(Delimiter::Comma, |input| {
|
input.parse_until_before(Delimiter::Comma, |input| {
|
||||||
if seen_stop {
|
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;
|
seen_stop = false;
|
||||||
items.push(generic::GradientItem::InterpolationHint(hint));
|
items.push(generic::GradientItem::InterpolationHint(hint));
|
||||||
return Ok(());
|
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();
|
let stop_color = stop.color.clone();
|
||||||
items.push(stop.into_item());
|
items.push(stop.into_item());
|
||||||
items.push(
|
items.push(
|
||||||
ColorStop {
|
generic::ColorStop {
|
||||||
color: stop_color,
|
color: stop_color,
|
||||||
position: Some(multi_position),
|
position: Some(multi_position),
|
||||||
}
|
}
|
||||||
|
@ -830,14 +827,17 @@ impl GradientItem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for ColorStop {
|
impl<T> Parse for generic::ColorStop<Color, T>
|
||||||
|
where
|
||||||
|
T: Parse,
|
||||||
|
{
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
) -> Result<Self, ParseError<'i>> {
|
) -> Result<Self, ParseError<'i>> {
|
||||||
Ok(ColorStop {
|
Ok(generic::ColorStop {
|
||||||
color: Color::parse(context, input)?,
|
color: Color::parse(context, input)?,
|
||||||
position: input.try(|i| LengthPercentage::parse(context, i)).ok(),
|
position: input.try(|i| T::parse(context, i)).ok(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ use std::ops::{Add, Mul};
|
||||||
use style_traits::values::specified::AllowedNumericType;
|
use style_traits::values::specified::AllowedNumericType;
|
||||||
use style_traits::{ParseError, SpecifiedValueInfo, StyleParseErrorKind};
|
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 super::image::{GradientKind, Image};
|
||||||
pub use crate::values::specified::calc::CalcLengthPercentage;
|
pub use crate::values::specified::calc::CalcLengthPercentage;
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,8 @@ pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis};
|
||||||
pub use self::font::{FontVariantAlternates, FontWeight};
|
pub use self::font::{FontVariantAlternates, FontWeight};
|
||||||
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
|
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
|
||||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
||||||
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use self::image::{EndingShape as GradientEndingShape, Gradient};
|
||||||
pub use self::image::{GradientItem, GradientKind, Image, MozImageRect};
|
pub use self::image::{GradientKind, Image, MozImageRect};
|
||||||
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
|
pub use self::length::{AbsoluteLength, CalcLengthPercentage, CharacterWidth};
|
||||||
pub use self::length::{FontRelativeLength, Length, LengthOrNumber, NonNegativeLengthOrNumber};
|
pub use self::length::{FontRelativeLength, Length, LengthOrNumber, NonNegativeLengthOrNumber};
|
||||||
pub use self::length::{LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
pub use self::length::{LengthOrAuto, LengthPercentage, LengthPercentageOrAuto};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue