From 8eec24cd46594ccb11133c90ba50ebf747d7f4b5 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 13 Jun 2017 18:00:29 +0200 Subject: [PATCH] Revert "Derive ToCss for MozImageRect" This reverts commit fe19c3810cd20a2a48dd054386f95462a3513e4c. --- components/style/values/computed/image.rs | 8 +++--- components/style/values/computed/mod.rs | 2 +- components/style/values/generics/image.rs | 31 +++++++++++++++++----- components/style/values/specified/image.rs | 17 ++++++------ components/style/values/specified/mod.rs | 2 +- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 9eb6e52059d..3718be2fbd3 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -17,7 +17,7 @@ use values::computed::position::Position; 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::{Image as GenericImage, GradientKind as GenericGradientKind}; -use values::generics::image::{LineDirection as GenericLineDirection, MozImageRect as GenericMozImageRect}; +use values::generics::image::{ImageRect as GenericImageRect, LineDirection as GenericLineDirection}; use values::specified::image::LineDirection as SpecifiedLineDirection; use values::specified::position::{X, Y}; @@ -26,7 +26,7 @@ pub type ImageLayer = Either; /// Computed values for an image according to CSS-IMAGES. /// https://drafts.csswg.org/css-images/#image-values -pub type Image = GenericImage; +pub type Image = GenericImage; /// Computed values for a CSS gradient. /// https://drafts.csswg.org/css-images/#gradients @@ -65,8 +65,8 @@ pub type GradientItem = GenericGradientItem; /// A computed color stop. pub type ColorStop = GenericColorStop; -/// Computed values for MozImageRect. -pub type MozImageRect = GenericMozImageRect; +/// Computed values for ImageRect. +pub type ImageRect = GenericImageRect; impl GenericLineDirection for LineDirection { fn points_downwards(&self) -> bool { diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 33ff52a07ae..ff682255d99 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -28,7 +28,7 @@ pub use self::background::BackgroundSize; pub use self::border::{BorderImageSlice, BorderImageWidth, BorderImageSideWidth}; pub use self::border::{BorderRadius, BorderCornerRadius}; pub use self::color::{Color, RGBAColor}; -pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, MozImageRect}; +pub use self::image::{Gradient, GradientItem, ImageLayer, LineDirection, Image, ImageRect}; #[cfg(feature = "gecko")] pub use self::gecko::ScrollSnapPoint; pub use self::rect::LengthOrNumberRect; diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index 0f7549e4a56..20094e75935 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -18,13 +18,13 @@ use values::specified::url::SpecifiedUrl; /// [image]: https://drafts.csswg.org/css-images/#image-values #[derive(Clone, PartialEq, ToComputedValue)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -pub enum Image { +pub enum Image { /// A `` image. Url(SpecifiedUrl), /// A `` image. Gradient(Gradient), /// A `-moz-image-rect` image - Rect(MozImageRect), + Rect(ImageRect), /// A `-moz-element(# )` Element(Atom), /// A paint worklet image. @@ -151,12 +151,11 @@ impl ToCss for PaintWorklet { /// Values for `moz-image-rect`. /// -/// `-moz-image-rect(, top, right, bottom, left)` -#[allow(missing_docs)] +/// `-moz-image-rect(, top, right, bottom, left);` +#[derive(Clone, Debug, PartialEq, ToComputedValue)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[css(function)] -#[derive(Clone, Debug, PartialEq, ToComputedValue, ToCss)] -pub struct MozImageRect { +#[allow(missing_docs)] +pub struct ImageRect { pub url: SpecifiedUrl, pub top: NumberOrPercentage, pub bottom: NumberOrPercentage, @@ -334,3 +333,21 @@ impl ToCss for ColorStop Ok(()) } } + +impl ToCss for ImageRect + where C: ToCss, +{ + fn to_css(&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(")") + } +} diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 15a6bb88ad8..6b091d6aea9 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -21,8 +21,9 @@ use values::{Either, None_}; use values::generics::image::{Circle, CompatMode, Ellipse, ColorStop as GenericColorStop}; use values::generics::image::{EndingShape as GenericEndingShape, Gradient as GenericGradient}; use values::generics::image::{GradientItem as GenericGradientItem, GradientKind as GenericGradientKind}; -use values::generics::image::{Image as GenericImage, LineDirection as GenericsLineDirection}; -use values::generics::image::{MozImageRect as GenericMozImageRect, PaintWorklet, ShapeExtent}; +use values::generics::image::{Image as GenericImage, ImageRect as GenericImageRect}; +use values::generics::image::{LineDirection as GenericsLineDirection, ShapeExtent}; +use values::generics::image::PaintWorklet; use values::generics::position::Position as GenericPosition; use values::specified::{Angle, Color, Length, LengthOrPercentage}; use values::specified::{Number, NumberOrPercentage, Percentage, RGBAColor}; @@ -34,7 +35,7 @@ pub type ImageLayer = Either; /// Specified values for an image according to CSS-IMAGES. /// https://drafts.csswg.org/css-images/#image-values -pub type Image = GenericImage; +pub type Image = GenericImage; /// Specified values for a CSS gradient. /// https://drafts.csswg.org/css-images/#gradients @@ -79,7 +80,7 @@ pub type ColorStop = GenericColorStop; /// Specified values for `moz-image-rect` /// -moz-image-rect(, top, right, bottom, left); -pub type MozImageRect = GenericMozImageRect; +pub type ImageRect = GenericImageRect; impl Parse for Image { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { @@ -107,14 +108,14 @@ impl Parse for Image { } #[cfg(feature = "gecko")] { - if let Ok(mut image_rect) = input.try(|input| MozImageRect::parse(context, input)) { + if let Ok(mut image_rect) = input.try(|input| ImageRect::parse(context, input)) { image_rect.url.build_image_value(); return Ok(GenericImage::Rect(image_rect)); } } #[cfg(feature = "servo")] { - if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) { + if let Ok(image_rect) = input.try(|input| ImageRect::parse(context, input)) { return Ok(GenericImage::Rect(image_rect)); } } @@ -704,7 +705,7 @@ impl Parse for PaintWorklet { } } -impl Parse for MozImageRect { +impl Parse for ImageRect { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { input.try(|i| i.expect_function_matching("-moz-image-rect"))?; input.parse_nested_block(|i| { @@ -719,7 +720,7 @@ impl Parse for MozImageRect { i.expect_comma()?; let left = NumberOrPercentage::parse_non_negative(context, i)?; - Ok(MozImageRect { + Ok(ImageRect { url: url, top: top, right: right, diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 6f46bf847ae..80ce0db08d0 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -36,7 +36,7 @@ pub use self::rect::LengthOrNumberRect; #[cfg(feature = "gecko")] pub use self::gecko::ScrollSnapPoint; pub use self::image::{ColorStop, EndingShape as GradientEndingShape, Gradient}; -pub use self::image::{GradientItem, GradientKind, Image, MozImageRect, ImageLayer}; +pub use self::image::{GradientItem, GradientKind, Image, ImageRect, ImageLayer}; pub use self::length::AbsoluteLength; pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage}; pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};