Skip to content
Permalink
Browse files

style: Use more compact and ffi-friendly types for some svg props.

No functional change yet.

Differential Revision: https://phabricator.services.mozilla.com/D36805
  • Loading branch information...
emilio committed Jul 5, 2019
1 parent a0df9f7 commit f0b5d02901e16f38ec62236cf6a3a45c1108eafa
@@ -447,17 +447,13 @@ where
}
}

impl<T> ToAnimatedZero for Box<[T]>
impl<T> ToAnimatedZero for crate::OwnedSlice<T>
where
T: ToAnimatedZero,
{
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
let v = self
.iter()
.map(|v| v.to_animated_zero())
.collect::<Result<Vec<_>, _>>()?;
Ok(v.into_boxed_slice())
self.iter().map(|v| v.to_animated_zero()).collect()
}
}

@@ -62,16 +62,16 @@ impl SVGWidth {
}

/// [ <length> | <percentage> | <number> ]# | context-value
pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeLengthPercentage>;
pub type SVGStrokeDashArray = generic::GenericSVGStrokeDashArray<NonNegativeLengthPercentage>;

impl Default for SVGStrokeDashArray {
fn default() -> Self {
generic::SVGStrokeDashArray::Values(vec![])
generic::SVGStrokeDashArray::Values(Default::default())
}
}

/// <opacity-value> | context-fill-opacity | context-stroke-opacity
pub type SVGOpacity = generic::SVGOpacity<Opacity>;
pub type SVGOpacity = generic::GenericSVGOpacity<Opacity>;

impl Default for SVGOpacity {
fn default() -> Self {
@@ -171,14 +171,17 @@ pub enum SVGLength<L> {
ToResolvedValue,
ToShmem,
)]
pub enum SVGStrokeDashArray<L> {
#[repr(C, u8)]
pub enum GenericSVGStrokeDashArray<L> {
/// `[ <length> | <percentage> | <number> ]#`
#[css(comma)]
Values(#[css(if_empty = "none", iterable)] Vec<L>),
Values(#[css(if_empty = "none", iterable)] crate::OwnedSlice<L>),
/// `context-value`
ContextValue,
}

pub use self::GenericSVGStrokeDashArray as SVGStrokeDashArray;

/// An SVG opacity value accepts `context-{fill,stroke}-opacity` in
/// addition to opacity value.
#[derive(
@@ -197,7 +200,8 @@ pub enum SVGStrokeDashArray<L> {
ToResolvedValue,
ToShmem,
)]
pub enum SVGOpacity<OpacityType> {
#[repr(C, u8)]
pub enum GenericSVGOpacity<OpacityType> {
/// `<opacity-value>`
Opacity(OpacityType),
/// `context-fill-opacity`
@@ -207,3 +211,5 @@ pub enum SVGOpacity<OpacityType> {
#[animation(error)]
ContextStrokeOpacity,
}

pub use self::GenericSVGOpacity as SVGOpacity;
@@ -80,14 +80,14 @@ impl Parse for SVGStrokeDashArray {
NonNegativeLengthPercentage::parse_quirky(context, i, AllowQuirks::Always)
})
}) {
return Ok(generic::SVGStrokeDashArray::Values(values));
return Ok(generic::SVGStrokeDashArray::Values(values.into()));
}

try_match_ident_ignore_ascii_case! { input,
"context-value" if is_context_value_enabled() => {
Ok(generic::SVGStrokeDashArray::ContextValue)
},
"none" => Ok(generic::SVGStrokeDashArray::Values(vec![])),
"none" => Ok(generic::SVGStrokeDashArray::Values(Default::default())),
}
}
}

0 comments on commit f0b5d02

Please sign in to comment.
You can’t perform that action at this time.