use crate::parser::{Parse, ParserContext};
use cssparser::Parser;
use style_traits::ParseError;
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C, u8)]
pub enum GenericSVGPaintFallback<C> {
None,
#[css(skip)]
Unset,
Color(C),
}
pub use self::GenericSVGPaintFallback as SVGPaintFallback;
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[animation(no_bound(Url))]
#[repr(C)]
pub struct GenericSVGPaint<Color, Url> {
pub kind: GenericSVGPaintKind<Color, Url>,
pub fallback: GenericSVGPaintFallback<Color>,
}
pub use self::GenericSVGPaint as SVGPaint;
impl<C, U> Default for SVGPaint<C, U> {
fn default() -> Self {
Self {
kind: SVGPaintKind::None,
fallback: SVGPaintFallback::Unset,
}
}
}
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Debug,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[animation(no_bound(U))]
#[repr(C, u8)]
pub enum GenericSVGPaintKind<C, U> {
#[animation(error)]
None,
Color(C),
#[animation(error)]
PaintServer(U),
ContextFill,
ContextStroke,
}
pub use self::GenericSVGPaintKind as SVGPaintKind;
impl<C: Parse, U: Parse> Parse for SVGPaint<C, U> {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let kind = SVGPaintKind::parse(context, input)?;
if matches!(kind, SVGPaintKind::None | SVGPaintKind::Color(..)) {
return Ok(SVGPaint {
kind,
fallback: SVGPaintFallback::Unset,
});
}
let fallback = input
.try_parse(|i| SVGPaintFallback::parse(context, i))
.unwrap_or(SVGPaintFallback::Unset);
Ok(SVGPaint { kind, fallback })
}
}
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C, u8)]
pub enum GenericSVGLength<L> {
LengthPercentage(L),
#[animation(error)]
ContextValue,
}
pub use self::GenericSVGLength as SVGLength;
#[derive(
Clone,
Debug,
MallocSizeOf,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C, u8)]
pub enum GenericSVGStrokeDashArray<L> {
#[css(comma)]
Values(#[css(if_empty = "none", iterable)] crate::OwnedSlice<L>),
ContextValue,
}
pub use self::GenericSVGStrokeDashArray as SVGStrokeDashArray;
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
PartialEq,
Parse,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C, u8)]
pub enum GenericSVGOpacity<OpacityType> {
Opacity(OpacityType),
#[animation(error)]
ContextFillOpacity,
#[animation(error)]
ContextStrokeOpacity,
}
pub use self::GenericSVGOpacity as SVGOpacity;