Skip to content

Commit

Permalink
Parse -moz-image-rect() and -moz-element() only in Gecko
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonSapin committed Jan 7, 2020
1 parent 709e069 commit 062c187
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
8 changes: 3 additions & 5 deletions components/layout/display_list/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions components/style/traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E>(context: &StyleContext<E>, data: &ElementData)
where
E: TElement,
Expand Down Expand Up @@ -719,7 +719,7 @@ where
}
}

#[cfg(feature = "gecko")]
#[cfg(not(feature = "servo-layout-2013"))]
fn notify_paint_worklet<E>(_context: &StyleContext<E>, _data: &ElementData)
where
E: TElement,
Expand Down
10 changes: 8 additions & 2 deletions components/style/values/computed/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,8 +64,13 @@ pub type GradientItem = generic::GenericGradientItem<Color, LengthPercentage>;
pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;

/// Computed values for `-moz-image-rect(...)`.
#[cfg(feature = "gecko")]
pub type MozImageRect = generic::MozImageRect<NumberOrPercentage, ComputedImageUrl>;

/// 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 {
Expand Down
12 changes: 10 additions & 2 deletions components/style/values/generics/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,24 @@ impl<I> ImageLayer<I> {
pub enum GenericImage<Gradient, MozImageRect, ImageUrl> {
/// A `<url()>` image.
Url(ImageUrl),

/// A `<gradient>` 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<Gradient>),

/// 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<MozImageRect>),

/// A `-moz-element(# <element-id>)`
#[cfg(feature = "gecko")]
#[css(function = "-moz-element")]
Element(Atom),

/// A paint worklet image.
/// <https://drafts.css-houdini.org/css-paint-api/>
#[cfg(feature = "servo")]
#[cfg(feature = "servo-layout-2013")]
PaintWorklet(PaintWorklet),
}

Expand Down Expand Up @@ -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)?;
Expand Down
42 changes: 36 additions & 6 deletions components/style/values/specified/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -119,8 +118,24 @@ pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;

/// Specified values for `moz-image-rect`
/// -moz-image-rect(<uri>, top, right, bottom, left);
#[cfg(feature = "gecko")]
pub type MozImageRect = generic::MozImageRect<NumberOrPercentage, SpecifiedImageUrl>;

#[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,
Expand All @@ -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())
}
}

Expand All @@ -155,6 +175,7 @@ impl Image {
}

/// Parses a `-moz-element(# <element-id>)`.
#[cfg(feature = "gecko")]
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
input.try(|i| i.expect_function_matching("-moz-element"))?;
let location = input.current_source_location();
Expand Down Expand Up @@ -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<Self, ParseError<'i>> {
Err(input.new_error_for_next_token())
}

#[cfg(feature = "gecko")]
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
Expand All @@ -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)?;
Expand Down

0 comments on commit 062c187

Please sign in to comment.