mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1614648 - Make GradientItem and ColorStop support angular color stops. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D62544 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
9003451702
commit
5f5b496d2d
@ -529,8 +529,10 @@ static void ClampColorStops(nsTArray<ColorStop>& aStops) {
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
static Color GetSpecifiedColor(const StyleGradientItem& aItem,
|
||||
const ComputedStyle& aStyle) {
|
||||
template <typename T>
|
||||
static Color GetSpecifiedColor(
|
||||
const StyleGenericGradientItem<StyleColor, T>& aItem,
|
||||
const ComputedStyle& aStyle) {
|
||||
if (aItem.IsInterpolationHint()) {
|
||||
return Color();
|
||||
}
|
||||
@ -541,7 +543,8 @@ static Color GetSpecifiedColor(const StyleGradientItem& aItem,
|
||||
}
|
||||
|
||||
static Maybe<double> GetSpecifiedGradientPosition(
|
||||
const StyleGradientItem& aItem, CSSCoord aLineLength) {
|
||||
const StyleGenericGradientItem<StyleColor, StyleLengthPercentage>& aItem,
|
||||
CSSCoord aLineLength) {
|
||||
if (aItem.IsSimpleColorStop()) {
|
||||
return Nothing();
|
||||
}
|
||||
@ -573,7 +576,7 @@ static nsTArray<ColorStop> ComputeColorStops(ComputedStyle* aComputedStyle,
|
||||
Maybe<size_t> firstUnsetPosition;
|
||||
auto span = aGradient.items.AsSpan();
|
||||
for (size_t i = 0; i < aGradient.items.Length(); ++i) {
|
||||
const StyleGradientItem& stop = span[i];
|
||||
const auto& stop = span[i];
|
||||
double position;
|
||||
|
||||
Maybe<double> specifiedPosition =
|
||||
|
@ -54,12 +54,6 @@ pub enum LineDirection {
|
||||
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(...)`.
|
||||
#[cfg(feature = "gecko")]
|
||||
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::{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};
|
||||
|
@ -180,7 +180,7 @@ pub enum ShapeExtent {
|
||||
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericGradientItem<Color, LengthPercentage> {
|
||||
pub enum GenericGradientItem<Color, T> {
|
||||
/// A simple color stop, without position.
|
||||
SimpleColorStop(Color),
|
||||
/// A complex color stop, with a position.
|
||||
@ -188,10 +188,10 @@ pub enum GenericGradientItem<Color, LengthPercentage> {
|
||||
/// 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<Color, LengthPercentage> {
|
||||
pub struct ColorStop<Color, T> {
|
||||
/// The color of this stop.
|
||||
pub color: Color,
|
||||
/// 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`.
|
||||
#[inline]
|
||||
pub fn into_item(self) -> GradientItem<Color, LengthPercentage> {
|
||||
pub fn into_item(self) -> GradientItem<Color, T> {
|
||||
match self.position {
|
||||
Some(position) => GradientItem::ComplexColorStop {
|
||||
color: self.color,
|
||||
|
@ -92,12 +92,6 @@ pub enum LineDirection {
|
||||
/// A specified ending shape.
|
||||
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`
|
||||
/// -moz-image-rect(<uri>, 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<T> generic::GradientItem<Color, T>
|
||||
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<T> Parse for generic::ColorStop<Color, T>
|
||||
where
|
||||
T: Parse,
|
||||
{
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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};
|
||||
|
Loading…
Reference in New Issue
Block a user