style: Derive more length stuff, and shrink MaxLength / MozLength's repr(C) representation.

This patch:

 * Makes LengthPercentageOrAuto generic, and removes a bunch of code fo
   LengthPercentageOrNone, which was used only for servo and now can use the
   normal MaxLength (with a cfg() guard for the ExtremumLength variant).

 * Shrinks MaxLength / MozLength's repr(C) reperesentation by reducing enum
   nesting. The shrinking is in preparation for using them from C++ too, though
   that'd be a different bug.

 * Moves NonNegative usage to the proper places so that stuff for them can be
   derived.

I did this on top of bug 1523071 to prove both that it could be possible and
that stuff wasn't too messy. It got a bit messy, but just because of a bug I
had fixed in bindgen long time ago already, so this updates bindgen's patch
version to grab a fix instead of ugly workarounds :)

Differential Revision: https://phabricator.services.mozilla.com/D17762
This commit is contained in:
Emilio Cobos Álvarez 2019-01-27 01:03:44 +01:00
parent 8dad956513
commit a68bc29b96
17 changed files with 337 additions and 520 deletions

View file

@ -4,10 +4,8 @@
//! Animation implementation for various length-related types.
use super::{Animate, Procedure, ToAnimatedValue};
use super::{Animate, Procedure};
use crate::values::computed::length::LengthPercentage;
use crate::values::computed::MaxLength as ComputedMaxLength;
use crate::values::computed::MozLength as ComputedMozLength;
use crate::values::computed::Percentage;
/// <https://drafts.csswg.org/css-transitions/#animtype-lpcalc>
@ -38,51 +36,3 @@ impl Animate for LengthPercentage {
))
}
}
// FIXME(emilio): These should use NonNegative<> instead.
impl ToAnimatedValue for ComputedMaxLength {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
use crate::values::computed::LengthPercentageOrNone;
use crate::values::generics::length::MaxLength as GenericMaxLength;
match animated {
GenericMaxLength::LengthPercentageOrNone(lpn) => {
let result = match lpn {
LengthPercentageOrNone::LengthPercentage(len) => {
LengthPercentageOrNone::LengthPercentage(len.clamp_to_non_negative())
},
LengthPercentageOrNone::None => lpn,
};
GenericMaxLength::LengthPercentageOrNone(result)
},
_ => animated,
}
}
}
impl ToAnimatedValue for ComputedMozLength {
type AnimatedValue = Self;
#[inline]
fn to_animated_value(self) -> Self {
self
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
use crate::values::generics::length::MozLength as GenericMozLength;
match animated {
GenericMozLength::LengthPercentageOrAuto(lpa) => {
GenericMozLength::LengthPercentageOrAuto(lpa.clamp_to_non_negative())
},
_ => animated,
}
}
}