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

@ -27,6 +27,7 @@ use crate::values::computed::{LengthPercentageOrAuto, NonNegativeLengthPercentag
use crate::values::generics::box_::VerticalAlign;
use crate::values::generics::grid::{TrackListValue, TrackSize};
use crate::values::generics::image::{CompatMode, GradientItem, Image as GenericImage};
use crate::values::generics::length::LengthPercentageOrAuto as GenericLengthPercentageOrAuto;
use crate::values::generics::rect::Rect;
use crate::values::generics::NonNegative;
use app_units::Au;
@ -62,19 +63,19 @@ impl From<nsStyleCoord_CalcValue> for LengthPercentage {
}
}
impl LengthPercentageOrAuto {
impl NonNegativeLengthPercentageOrAuto {
/// Convert this value in an appropriate `nsStyleCoord::CalcValue`.
pub fn to_calc_value(&self) -> Option<nsStyleCoord_CalcValue> {
match *self {
LengthPercentageOrAuto::LengthPercentage(len) => Some(From::from(len)),
LengthPercentageOrAuto::Auto => None,
GenericLengthPercentageOrAuto::LengthPercentage(ref len) => Some(From::from(len.0)),
GenericLengthPercentageOrAuto::Auto => None,
}
}
}
impl From<nsStyleCoord_CalcValue> for LengthPercentageOrAuto {
fn from(other: nsStyleCoord_CalcValue) -> LengthPercentageOrAuto {
LengthPercentageOrAuto::LengthPercentage(LengthPercentage::from(other))
GenericLengthPercentageOrAuto::LengthPercentage(LengthPercentage::from(other))
}
}
@ -82,7 +83,7 @@ impl From<nsStyleCoord_CalcValue> for LengthPercentageOrAuto {
// disappear as we move more stuff to cbindgen.
impl From<nsStyleCoord_CalcValue> for NonNegativeLengthPercentageOrAuto {
fn from(other: nsStyleCoord_CalcValue) -> Self {
NonNegative(LengthPercentageOrAuto::LengthPercentage(
GenericLengthPercentageOrAuto::LengthPercentage(NonNegative(
LengthPercentage::with_clamping_mode(
Au(other.mLength).into(),
if other.mHasPercent {