diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index 542ab95172a..56748d55d2b 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -800,11 +800,9 @@ impl Fragment { ); } }, - Image::Rect(_) => { - // TODO: Implement `-moz-image-rect` - }, - Image::Element(_) => { - // TODO: Implement `-moz-element` + Image::Rect(ref rect) => { + // This is a (boxed) empty enum on non-Gecko + match **rect {} }, } } diff --git a/components/style/traversal.rs b/components/style/traversal.rs index 360f5b6a25c..f73a533b718 100644 --- a/components/style/traversal.rs +++ b/components/style/traversal.rs @@ -679,7 +679,7 @@ where element.finish_restyle(context, data, new_styles, important_rules_changed) } -#[cfg(feature = "servo")] +#[cfg(feature = "servo-layout-2013")] fn notify_paint_worklet(context: &StyleContext, data: &ElementData) where E: TElement, @@ -719,7 +719,7 @@ where } } -#[cfg(feature = "gecko")] +#[cfg(not(feature = "servo-layout-2013"))] fn notify_paint_worklet(_context: &StyleContext, _data: &ElementData) where E: TElement, diff --git a/components/style/values/computed/image.rs b/components/style/values/computed/image.rs index 841f3293c1a..bd59acac547 100644 --- a/components/style/values/computed/image.rs +++ b/components/style/values/computed/image.rs @@ -9,10 +9,11 @@ use crate::values::computed::position::Position; use crate::values::computed::url::ComputedImageUrl; +#[cfg(feature = "gecko")] +use crate::values::computed::NumberOrPercentage; use crate::values::computed::{Angle, Color, Context}; use crate::values::computed::{ - LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, NumberOrPercentage, - ToComputedValue, + LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, ToComputedValue, }; use crate::values::generics::image::{self as generic, GradientCompatMode}; use crate::values::specified::image::LineDirection as SpecifiedLineDirection; @@ -63,8 +64,13 @@ pub type GradientItem = generic::GenericGradientItem; pub type ColorStop = generic::ColorStop; /// Computed values for `-moz-image-rect(...)`. +#[cfg(feature = "gecko")] pub type MozImageRect = generic::MozImageRect; +/// Empty enum on non-gecko +#[cfg(not(feature = "gecko"))] +pub type MozImageRect = crate::values::specified::image::MozImageRect; + impl generic::LineDirection for LineDirection { fn points_downwards(&self, compat_mode: GradientCompatMode) -> bool { match *self { diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index ab2a906ae10..a6b45bc82ad 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -53,17 +53,24 @@ impl ImageLayer { pub enum GenericImage { /// A `` image. Url(ImageUrl), + /// A `` image. Gradients are rather large, and not nearly as /// common as urls, so we box them here to keep the size of this enum sane. Gradient(Box), + /// A `-moz-image-rect` image. Also fairly large and rare. + // not cfg’ed out on non-Gecko to avoid `error[E0392]: parameter `MozImageRect` is never used` + // Instead we make MozImageRect an empty enum Rect(Box), + /// A `-moz-element(# )` + #[cfg(feature = "gecko")] #[css(function = "-moz-element")] Element(Atom), + /// A paint worklet image. /// - #[cfg(feature = "servo")] + #[cfg(feature = "servo-layout-2013")] PaintWorklet(PaintWorklet), } @@ -323,8 +330,9 @@ where Image::Url(ref url) => url.to_css(dest), Image::Gradient(ref gradient) => gradient.to_css(dest), Image::Rect(ref rect) => rect.to_css(dest), - #[cfg(feature = "servo")] + #[cfg(feature = "servo-layout-2013")] Image::PaintWorklet(ref paint_worklet) => paint_worklet.to_css(dest), + #[cfg(feature = "gecko")] Image::Element(ref selector) => { dest.write_str("-moz-element(#")?; serialize_atom_identifier(selector, dest)?; diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 126a4cc69d1..14a2a9ad9c8 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -9,7 +9,6 @@ use crate::custom_properties::SpecifiedValue; use crate::parser::{Parse, ParserContext}; -use crate::stylesheets::CorsMode; use crate::values::generics::image::PaintWorklet; use crate::values::generics::image::{ self as generic, Circle, Ellipse, GradientCompatMode, ShapeExtent, @@ -119,8 +118,24 @@ pub type ColorStop = generic::ColorStop; /// Specified values for `moz-image-rect` /// -moz-image-rect(, top, right, bottom, left); +#[cfg(feature = "gecko")] pub type MozImageRect = generic::MozImageRect; +#[cfg(not(feature = "gecko"))] +#[derive( + Clone, + Debug, + MallocSizeOf, + PartialEq, + SpecifiedValueInfo, + ToComputedValue, + ToCss, + ToResolvedValue, + ToShmem, +)] +/// Empty enum on non-Gecko +pub enum MozImageRect {} + impl Parse for Image { fn parse<'i, 't>( context: &ParserContext, @@ -132,16 +147,21 @@ impl Parse for Image { if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) { return Ok(generic::Image::Gradient(Box::new(gradient))); } - #[cfg(feature = "servo")] + #[cfg(feature = "servo-layout-2013")] { if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) { return Ok(generic::Image::PaintWorklet(paint_worklet)); } } - if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) { - return Ok(generic::Image::Rect(Box::new(image_rect))); + #[cfg(feature = "gecko")] + { + if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) { + return Ok(generic::Image::Rect(Box::new(image_rect))); + } + Ok(generic::Image::Element(Image::parse_element(input)?)) } - Ok(generic::Image::Element(Image::parse_element(input)?)) + #[cfg(not(feature = "gecko"))] + Err(input.new_error_for_next_token()) } } @@ -155,6 +175,7 @@ impl Image { } /// Parses a `-moz-element(# )`. + #[cfg(feature = "gecko")] fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { input.try(|i| i.expect_function_matching("-moz-element"))?; let location = input.current_source_location(); @@ -856,6 +877,15 @@ impl Parse for PaintWorklet { } impl Parse for MozImageRect { + #[cfg(not(feature = "gecko"))] + fn parse<'i, 't>( + _context: &ParserContext, + input: &mut Parser<'i, 't>, + ) -> Result> { + Err(input.new_error_for_next_token()) + } + + #[cfg(feature = "gecko")] fn parse<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, @@ -866,7 +896,7 @@ impl Parse for MozImageRect { let url = SpecifiedImageUrl::parse_from_string( string.as_ref().to_owned(), context, - CorsMode::None, + crate::stylesheets::CorsMode::None, ); i.expect_comma()?; let top = NumberOrPercentage::parse_non_negative(context, i)?;