Auto merge of #17293 - servo:derive-all-the-things, r=emilio

Derive two more ToCss impls

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17293)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-13 06:36:12 -07:00 committed by GitHub
commit 682af8bb19
5 changed files with 34 additions and 56 deletions

View file

@ -17,7 +17,7 @@ use values::computed::position::Position;
use values::generics::image::{CompatMode, ColorStop as GenericColorStop, EndingShape as GenericEndingShape}; use values::generics::image::{CompatMode, ColorStop as GenericColorStop, EndingShape as GenericEndingShape};
use values::generics::image::{Gradient as GenericGradient, GradientItem as GenericGradientItem}; use values::generics::image::{Gradient as GenericGradient, GradientItem as GenericGradientItem};
use values::generics::image::{Image as GenericImage, GradientKind as GenericGradientKind}; use values::generics::image::{Image as GenericImage, GradientKind as GenericGradientKind};
use values::generics::image::{ImageRect as GenericImageRect, LineDirection as GenericLineDirection}; use values::generics::image::{LineDirection as GenericLineDirection, MozImageRect as GenericMozImageRect};
use values::specified::image::LineDirection as SpecifiedLineDirection; use values::specified::image::LineDirection as SpecifiedLineDirection;
use values::specified::position::{X, Y}; use values::specified::position::{X, Y};
@ -26,7 +26,7 @@ pub type ImageLayer = Either<None_, Image>;
/// Computed values for an image according to CSS-IMAGES. /// Computed values for an image according to CSS-IMAGES.
/// https://drafts.csswg.org/css-images/#image-values /// https://drafts.csswg.org/css-images/#image-values
pub type Image = GenericImage<Gradient, ImageRect>; pub type Image = GenericImage<Gradient, MozImageRect>;
/// Computed values for a CSS gradient. /// Computed values for a CSS gradient.
/// https://drafts.csswg.org/css-images/#gradients /// https://drafts.csswg.org/css-images/#gradients
@ -65,8 +65,8 @@ pub type GradientItem = GenericGradientItem<RGBA, LengthOrPercentage>;
/// A computed color stop. /// A computed color stop.
pub type ColorStop = GenericColorStop<RGBA, LengthOrPercentage>; pub type ColorStop = GenericColorStop<RGBA, LengthOrPercentage>;
/// Computed values for ImageRect. /// Computed values for MozImageRect.
pub type ImageRect = GenericImageRect<NumberOrPercentage>; pub type MozImageRect = GenericMozImageRect<NumberOrPercentage>;
impl GenericLineDirection for LineDirection { impl GenericLineDirection for LineDirection {
fn points_downwards(&self) -> bool { fn points_downwards(&self) -> bool {

View file

@ -28,7 +28,7 @@ pub use self::background::BackgroundSize;
pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth};
pub use self::border::{BorderRadius, BorderCornerRadius}; pub use self::border::{BorderRadius, BorderCornerRadius};
pub use self::color::{Color, RGBAColor}; pub use self::color::{Color, RGBAColor};
pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect}; pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, MozImageRect};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use self::gecko::ScrollSnapPoint; pub use self::gecko::ScrollSnapPoint;
pub use self::rect::LengthOrNumberRect; pub use self::rect::LengthOrNumberRect;

View file

@ -18,13 +18,13 @@ use values::specified::url::SpecifiedUrl;
/// [image]: https://drafts.csswg.org/css-images/#image-values /// [image]: https://drafts.csswg.org/css-images/#image-values
#[derive(Clone, PartialEq, ToComputedValue)] #[derive(Clone, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum Image<Gradient, ImageRect> { pub enum Image<Gradient, MozImageRect> {
/// A `<url()>` image. /// A `<url()>` image.
Url(SpecifiedUrl), Url(SpecifiedUrl),
/// A `<gradient>` image. /// A `<gradient>` image.
Gradient(Gradient), Gradient(Gradient),
/// A `-moz-image-rect` image /// A `-moz-image-rect` image
Rect(ImageRect), Rect(MozImageRect),
/// A `-moz-element(# <element-id>)` /// A `-moz-element(# <element-id>)`
Element(Atom), Element(Atom),
/// A paint worklet image. /// A paint worklet image.
@ -69,7 +69,7 @@ pub enum GradientKind<LineDirection, Length, LengthOrPercentage, Position> {
} }
/// A radial gradient's ending shape. /// A radial gradient's ending shape.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)] #[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum EndingShape<Length, LengthOrPercentage> { pub enum EndingShape<Length, LengthOrPercentage> {
/// A circular gradient. /// A circular gradient.
@ -89,7 +89,7 @@ pub enum Circle<Length> {
} }
/// An ellipse shape. /// An ellipse shape.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)] #[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue, ToCss)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))] #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum Ellipse<LengthOrPercentage> { pub enum Ellipse<LengthOrPercentage> {
/// An ellipse pair of radii. /// An ellipse pair of radii.
@ -151,11 +151,12 @@ impl ToCss for PaintWorklet {
/// Values for `moz-image-rect`. /// Values for `moz-image-rect`.
/// ///
/// `-moz-image-rect(<uri>, top, right, bottom, left);` /// `-moz-image-rect(<uri>, top, right, bottom, left)`
#[derive(Clone, Debug, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[allow(missing_docs)] #[allow(missing_docs)]
pub struct ImageRect<NumberOrPercentage> { #[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[css(function)]
#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)]
pub struct MozImageRect<NumberOrPercentage> {
pub url: SpecifiedUrl, pub url: SpecifiedUrl,
pub top: NumberOrPercentage, pub top: NumberOrPercentage,
pub bottom: NumberOrPercentage, pub bottom: NumberOrPercentage,
@ -285,30 +286,26 @@ pub trait LineDirection {
where W: fmt::Write; where W: fmt::Write;
} }
impl<L, LoP> ToCss for EndingShape<L, LoP> impl<L> ToCss for Circle<L>
where L: ToCss, LoP: ToCss, where
L: ToCss,
{ {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
match *self { match *self {
EndingShape::Circle(Circle::Extent(ShapeExtent::FarthestCorner)) | Circle::Extent(ShapeExtent::FarthestCorner) |
EndingShape::Circle(Circle::Extent(ShapeExtent::Cover)) => { Circle::Extent(ShapeExtent::Cover) => {
dest.write_str("circle") dest.write_str("circle")
}, },
EndingShape::Circle(Circle::Extent(keyword)) => { Circle::Extent(keyword) => {
dest.write_str("circle ")?; dest.write_str("circle ")?;
keyword.to_css(dest) keyword.to_css(dest)
}, },
EndingShape::Circle(Circle::Radius(ref length)) => { Circle::Radius(ref length) => {
length.to_css(dest) length.to_css(dest)
}, },
EndingShape::Ellipse(Ellipse::Extent(keyword)) => {
keyword.to_css(dest)
},
EndingShape::Ellipse(Ellipse::Radii(ref x, ref y)) => {
x.to_css(dest)?;
dest.write_str(" ")?;
y.to_css(dest)
},
} }
} }
} }
@ -337,21 +334,3 @@ impl<C, L> ToCss for ColorStop<C, L>
Ok(()) Ok(())
} }
} }
impl<C> ToCss for ImageRect<C>
where C: ToCss,
{
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
dest.write_str("-moz-image-rect(")?;
self.url.to_css(dest)?;
dest.write_str(", ")?;
self.top.to_css(dest)?;
dest.write_str(", ")?;
self.right.to_css(dest)?;
dest.write_str(", ")?;
self.bottom.to_css(dest)?;
dest.write_str(", ")?;
self.left.to_css(dest)?;
dest.write_str(")")
}
}

View file

@ -21,9 +21,8 @@ use values::{Either, None_};
use values::generics::image::{Circle, CompatMode, Ellipse, ColorStop as GenericColorStop}; use values::generics::image::{Circle, CompatMode, Ellipse, ColorStop as GenericColorStop};
use values::generics::image::{EndingShape as GenericEndingShape, Gradient as GenericGradient}; use values::generics::image::{EndingShape as GenericEndingShape, Gradient as GenericGradient};
use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind}; use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind};
use values::generics::image::{Image as GenericImage, ImageRect as GenericImageRect}; use values::generics::image::{Image as GenericImage, LineDirection as GenericsLineDirection};
use values::generics::image::{LineDirection as GenericsLineDirection, ShapeExtent}; use values::generics::image::{MozImageRect as GenericMozImageRect, PaintWorklet, ShapeExtent};
use values::generics::image::PaintWorklet;
use values::generics::position::Position as GenericPosition; use values::generics::position::Position as GenericPosition;
use values::specified::{Angle, Color, Length, LengthOrPercentage}; use values::specified::{Angle, Color, Length, LengthOrPercentage};
use values::specified::{Number, NumberOrPercentage, Percentage, RGBAColor}; use values::specified::{Number, NumberOrPercentage, Percentage, RGBAColor};
@ -35,7 +34,7 @@ pub type ImageLayer = Either<None_, Image>;
/// Specified values for an image according to CSS-IMAGES. /// Specified values for an image according to CSS-IMAGES.
/// https://drafts.csswg.org/css-images/#image-values /// https://drafts.csswg.org/css-images/#image-values
pub type Image = GenericImage<Gradient, ImageRect>; pub type Image = GenericImage<Gradient, MozImageRect>;
/// Specified values for a CSS gradient. /// Specified values for a CSS gradient.
/// https://drafts.csswg.org/css-images/#gradients /// https://drafts.csswg.org/css-images/#gradients
@ -80,7 +79,7 @@ pub type ColorStop = GenericColorStop<RGBAColor, LengthOrPercentage>;
/// Specified values for `moz-image-rect` /// Specified values for `moz-image-rect`
/// -moz-image-rect(<uri>, top, right, bottom, left); /// -moz-image-rect(<uri>, top, right, bottom, left);
pub type ImageRect = GenericImageRect<NumberOrPercentage>; pub type MozImageRect = GenericMozImageRect<NumberOrPercentage>;
impl Parse for Image { impl Parse for Image {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Image, ParseError<'i>> { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Image, ParseError<'i>> {
@ -108,14 +107,14 @@ impl Parse for Image {
} }
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
{ {
if let Ok(mut image_rect) = input.try(|input| ImageRect::parse(context, input)) { if let Ok(mut image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
image_rect.url.build_image_value(); image_rect.url.build_image_value();
return Ok(GenericImage::Rect(image_rect)); return Ok(GenericImage::Rect(image_rect));
} }
} }
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
{ {
if let Ok(image_rect) = input.try(|input| ImageRect::parse(context, input)) { if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
return Ok(GenericImage::Rect(image_rect)); return Ok(GenericImage::Rect(image_rect));
} }
} }
@ -705,7 +704,7 @@ impl Parse for PaintWorklet {
} }
} }
impl Parse for ImageRect { impl Parse for MozImageRect {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
input.try(|i| i.expect_function_matching("-moz-image-rect"))?; input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
input.parse_nested_block(|i| { input.parse_nested_block(|i| {
@ -720,7 +719,7 @@ impl Parse for ImageRect {
i.expect_comma()?; i.expect_comma()?;
let left = NumberOrPercentage::parse_non_negative(context, i)?; let left = NumberOrPercentage::parse_non_negative(context, i)?;
Ok(ImageRect { Ok(MozImageRect {
url: url, url: url,
top: top, top: top,
right: right, right: right,

View file

@ -36,7 +36,7 @@ pub use self::rect::LengthOrNumberRect;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use self::gecko::ScrollSnapPoint; pub use self::gecko::ScrollSnapPoint;
pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient}; pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient};
pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer}; pub use self::image::{GradientItem, GradientKind, Image, MozImageRect, ImageLayer};
pub use self::length::AbsoluteLength; pub use self::length::AbsoluteLength;
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage}; pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto}; pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};