style: Use the owned slice type for basic shape polygon coordinates.

This enables destructors for tagged unions in cbindgen, implemented in:

 * https://github.com/eqrion/cbindgen/pull/333

Which allow us to properly generate a destructor for the cbindgen-generated
StyleBasicShape (which now contains an OwnedSlice).

For now, we still use the glue code to go from Box<BasicShape> to
UniquePtr<BasicShape>. But that will change in the future when we generate even
more stuff and remove all the glue.

I could add support for copy-constructor generation to cbindgen for tagged
enums, but I'm not sure if it'll end up being needed, and copy-constructing
unions in C++ is always very tricky.

Differential Revision: https://phabricator.services.mozilla.com/D29769
This commit is contained in:
Emilio Cobos Álvarez 2019-05-09 11:24:57 +00:00
parent 330bccd659
commit 559235edad
9 changed files with 79 additions and 218 deletions

View file

@ -16,7 +16,6 @@ use crate::values::computed::Image;
use crate::values::specified::SVGPathData;
use crate::values::CSSFloat;
use app_units::Au;
use euclid::Point2D;
use smallvec::SmallVec;
use std::cmp;
@ -241,16 +240,10 @@ impl Animate for Au {
}
}
impl<T> Animate for Point2D<T>
where
T: Animate,
{
impl<T: Animate> Animate for Box<T> {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok(Point2D::new(
self.x.animate(&other.x, procedure)?,
self.y.animate(&other.y, procedure)?,
))
Ok(Box::new((**self).animate(&other, procedure)?))
}
}
@ -288,6 +281,24 @@ where
}
}
impl<T> ToAnimatedValue for Box<T>
where
T: ToAnimatedValue,
{
type AnimatedValue = Box<<T as ToAnimatedValue>::AnimatedValue>;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
Box::new((*self).to_animated_value())
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
Box::new(T::from_animated_value(*animated))
}
}
impl<T> ToAnimatedValue for Box<[T]>
where
T: ToAnimatedValue,
@ -328,7 +339,7 @@ where
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
Box::from_animated_value(animated.into_box()).into()
Self::from(Box::from_animated_value(animated.into_box()))
}
}