Skip to content

Commit

Permalink
style: Use more compact and ffi-friendly types for some svg props.
Browse files Browse the repository at this point in the history
No functional change yet.

Differential Revision: https://phabricator.services.mozilla.com/D36805
  • Loading branch information
emilio committed Jul 8, 2019
1 parent a0df9f7 commit f0b5d02
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
8 changes: 2 additions & 6 deletions components/style/values/animated/mod.rs
Expand Up @@ -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()
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/style/values/computed/svg.rs
Expand Up @@ -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 {
Expand Down
12 changes: 9 additions & 3 deletions components/style/values/generics/svg.rs
Expand Up @@ -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(
Expand All @@ -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`
Expand All @@ -207,3 +211,5 @@ pub enum SVGOpacity<OpacityType> {
#[animation(error)]
ContextStrokeOpacity,
}

pub use self::GenericSVGOpacity as SVGOpacity;
4 changes: 2 additions & 2 deletions components/style/values/specified/svg.rs
Expand Up @@ -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())),
}
}
}
Expand Down

0 comments on commit f0b5d02

Please sign in to comment.