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

No functional change yet.

Differential Revision: https://phabricator.services.mozilla.com/D36805
This commit is contained in:
Emilio Cobos Álvarez 2019-07-05 22:19:42 +00:00
parent a0df9f76de
commit f0b5d02901
No known key found for this signature in database
GPG key ID: E1152D0994E4BF8A
4 changed files with 16 additions and 14 deletions

View file

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

View file

@ -62,16 +62,16 @@ impl SVGWidth {
} }
/// [ <length> | <percentage> | <number> ]# | context-value /// [ <length> | <percentage> | <number> ]# | context-value
pub type SVGStrokeDashArray = generic::SVGStrokeDashArray<NonNegativeLengthPercentage>; pub type SVGStrokeDashArray = generic::GenericSVGStrokeDashArray<NonNegativeLengthPercentage>;
impl Default for SVGStrokeDashArray { impl Default for SVGStrokeDashArray {
fn default() -> Self { fn default() -> Self {
generic::SVGStrokeDashArray::Values(vec![]) generic::SVGStrokeDashArray::Values(Default::default())
} }
} }
/// <opacity-value> | context-fill-opacity | context-stroke-opacity /// <opacity-value> | context-fill-opacity | context-stroke-opacity
pub type SVGOpacity = generic::SVGOpacity<Opacity>; pub type SVGOpacity = generic::GenericSVGOpacity<Opacity>;
impl Default for SVGOpacity { impl Default for SVGOpacity {
fn default() -> Self { fn default() -> Self {

View file

@ -171,14 +171,17 @@ pub enum SVGLength<L> {
ToResolvedValue, ToResolvedValue,
ToShmem, ToShmem,
)] )]
pub enum SVGStrokeDashArray<L> { #[repr(C, u8)]
pub enum GenericSVGStrokeDashArray<L> {
/// `[ <length> | <percentage> | <number> ]#` /// `[ <length> | <percentage> | <number> ]#`
#[css(comma)] #[css(comma)]
Values(#[css(if_empty = "none", iterable)] Vec<L>), Values(#[css(if_empty = "none", iterable)] crate::OwnedSlice<L>),
/// `context-value` /// `context-value`
ContextValue, ContextValue,
} }
pub use self::GenericSVGStrokeDashArray as SVGStrokeDashArray;
/// An SVG opacity value accepts `context-{fill,stroke}-opacity` in /// An SVG opacity value accepts `context-{fill,stroke}-opacity` in
/// addition to opacity value. /// addition to opacity value.
#[derive( #[derive(
@ -197,7 +200,8 @@ pub enum SVGStrokeDashArray<L> {
ToResolvedValue, ToResolvedValue,
ToShmem, ToShmem,
)] )]
pub enum SVGOpacity<OpacityType> { #[repr(C, u8)]
pub enum GenericSVGOpacity<OpacityType> {
/// `<opacity-value>` /// `<opacity-value>`
Opacity(OpacityType), Opacity(OpacityType),
/// `context-fill-opacity` /// `context-fill-opacity`
@ -207,3 +211,5 @@ pub enum SVGOpacity<OpacityType> {
#[animation(error)] #[animation(error)]
ContextStrokeOpacity, ContextStrokeOpacity,
} }
pub use self::GenericSVGOpacity as SVGOpacity;

View file

@ -80,14 +80,14 @@ impl Parse for SVGStrokeDashArray {
NonNegativeLengthPercentage::parse_quirky(context, i, AllowQuirks::Always) 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, try_match_ident_ignore_ascii_case! { input,
"context-value" if is_context_value_enabled() => { "context-value" if is_context_value_enabled() => {
Ok(generic::SVGStrokeDashArray::ContextValue) Ok(generic::SVGStrokeDashArray::ContextValue)
}, },
"none" => Ok(generic::SVGStrokeDashArray::Values(vec![])), "none" => Ok(generic::SVGStrokeDashArray::Values(Default::default())),
} }
} }
} }