style: Use cbindgen for clip / -moz-image-region.

This also fixes some of the issues with -moz-image-region, where we just minted
an auto out of the blue.

Differential Revision: https://phabricator.services.mozilla.com/D43474
This commit is contained in:
Emilio Cobos Álvarez 2019-08-26 23:09:47 +00:00
parent 53cd37ce39
commit b238698691
5 changed files with 52 additions and 194 deletions

View file

@ -683,11 +683,11 @@ impl From<CSSInteger> for PositiveInteger {
/// A computed positive `<integer>` value or `none`.
pub type PositiveIntegerOrNone = Either<PositiveInteger, None_>;
/// rect(...)
pub type ClipRect = generics::ClipRect<LengthOrAuto>;
/// rect(...) | auto
pub type ClipRect = generics::GenericClipRect<LengthOrAuto>;
/// rect(...) | auto
pub type ClipRectOrAuto = Either<ClipRect, Auto>;
pub type ClipRectOrAuto = generics::GenericClipRectOrAuto<ClipRect>;
/// The computed value of a grid `<track-breadth>`
pub type TrackBreadth = GenericTrackBreadth<LengthPercentage>;
@ -707,18 +707,3 @@ pub type GridLine = GenericGridLine<Integer>;
/// `<grid-template-rows> | <grid-template-columns>`
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthPercentage, Integer>;
impl ClipRectOrAuto {
/// Return an auto (default for clip-rect and image-region) value
pub fn auto() -> Self {
Either::Second(Auto)
}
/// Check if it is auto
pub fn is_auto(&self) -> bool {
match *self {
Either::Second(_) => true,
_ => false,
}
}
}

View file

@ -272,9 +272,47 @@ pub struct ZeroToOne<T>(pub T);
ToShmem,
)]
#[css(function = "rect", comma)]
pub struct ClipRect<LengthOrAuto> {
#[repr(C)]
pub struct GenericClipRect<LengthOrAuto> {
pub top: LengthOrAuto,
pub right: LengthOrAuto,
pub bottom: LengthOrAuto,
pub left: LengthOrAuto,
}
pub use self::GenericClipRect as ClipRect;
/// Either a clip-rect or `auto`.
#[allow(missing_docs)]
#[derive(
Animate,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToAnimatedValue,
ToAnimatedZero,
ToComputedValue,
ToCss,
ToResolvedValue,
ToShmem,
)]
#[repr(C, u8)]
pub enum GenericClipRectOrAuto<R> {
Auto,
Rect(R),
}
pub use self::GenericClipRectOrAuto as ClipRectOrAuto;
impl<L> ClipRectOrAuto<L> {
/// Returns the `auto` value.
#[inline]
pub fn auto() -> Self {
ClipRectOrAuto::Auto
}
}

View file

@ -13,7 +13,7 @@ use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as Generic
use super::generics::grid::{TrackList as GenericTrackList, TrackSize as GenericTrackSize};
use super::generics::transform::IsParallelTo;
use super::generics::{self, GreaterThanOrEqualToOne, NonNegative};
use super::{Auto, CSSFloat, CSSInteger, Either, None_};
use super::{CSSFloat, CSSInteger, Either, None_};
use crate::context::QuirksMode;
use crate::parser::{Parse, ParserContext};
use crate::values::serialize_atom_identifier;
@ -639,7 +639,7 @@ pub type GridLine = GenericGridLine<Integer>;
pub type GridTemplateComponent = GenericGridTemplateComponent<LengthPercentage, Integer>;
/// rect(...)
pub type ClipRect = generics::ClipRect<LengthOrAuto>;
pub type ClipRect = generics::GenericClipRect<LengthOrAuto>;
impl Parse for ClipRect {
fn parse<'i, 't>(
@ -652,7 +652,7 @@ impl Parse for ClipRect {
impl ClipRect {
/// Parses a rect(<top>, <left>, <bottom>, <right>), allowing quirks.
pub fn parse_quirky<'i, 't>(
fn parse_quirky<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
allow_quirks: AllowQuirks,
@ -696,7 +696,7 @@ impl ClipRect {
}
/// rect(...) | auto
pub type ClipRectOrAuto = Either<ClipRect, Auto>;
pub type ClipRectOrAuto = generics::GenericClipRectOrAuto<ClipRect>;
impl ClipRectOrAuto {
/// Parses a ClipRect or Auto, allowing quirks.
@ -706,10 +706,10 @@ impl ClipRectOrAuto {
allow_quirks: AllowQuirks,
) -> Result<Self, ParseError<'i>> {
if let Ok(v) = input.try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) {
Ok(Either::First(v))
} else {
Auto::parse(context, input).map(Either::Second)
return Ok(generics::GenericClipRectOrAuto::Rect(v))
}
input.expect_ident_matching("auto")?;
Ok(generics::GenericClipRectOrAuto::Auto)
}
}