mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
style: Use rust types for gradient stops.
This doesn't clean up all that much, yet, but it's a step in the right direction. Differential Revision: https://phabricator.services.mozilla.com/D29168
This commit is contained in:
parent
e40500622e
commit
8123007717
4 changed files with 52 additions and 63 deletions
|
@ -135,13 +135,23 @@ pub enum ShapeExtent {
|
|||
#[derive(
|
||||
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
|
||||
)]
|
||||
pub enum GradientItem<Color, LengthPercentage> {
|
||||
/// A color stop.
|
||||
ColorStop(ColorStop<Color, LengthPercentage>),
|
||||
#[repr(C, u8)]
|
||||
pub enum GenericGradientItem<Color, LengthPercentage> {
|
||||
/// A simple color stop, without position.
|
||||
SimpleColorStop(Color),
|
||||
/// A complex color stop, with a position.
|
||||
ComplexColorStop {
|
||||
/// The color for the stop.
|
||||
color: Color,
|
||||
/// The position for the stop.
|
||||
position: LengthPercentage,
|
||||
},
|
||||
/// An interpolation hint.
|
||||
InterpolationHint(LengthPercentage),
|
||||
}
|
||||
|
||||
pub use self::GenericGradientItem as GradientItem;
|
||||
|
||||
/// A color stop.
|
||||
/// <https://drafts.csswg.org/css-images/#typedef-color-stop-list>
|
||||
#[derive(
|
||||
|
@ -154,6 +164,20 @@ pub struct ColorStop<Color, LengthPercentage> {
|
|||
pub position: Option<LengthPercentage>,
|
||||
}
|
||||
|
||||
impl<Color, LengthPercentage> ColorStop<Color, LengthPercentage> {
|
||||
/// Convert the color stop into an appropriate `GradientItem`.
|
||||
#[inline]
|
||||
pub fn into_item(self) -> GradientItem<Color, LengthPercentage> {
|
||||
match self.position {
|
||||
Some(position) => GradientItem::ComplexColorStop {
|
||||
color: self.color,
|
||||
position,
|
||||
},
|
||||
None => GradientItem::SimpleColorStop(self.color),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Specified values for a paint worklet.
|
||||
/// <https://drafts.css-houdini.org/css-paint-api/>
|
||||
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue