mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Parse -moz-image-rect()
and -moz-element()
only in Gecko
This commit is contained in:
parent
709e06928a
commit
062c1872f0
5 changed files with 59 additions and 17 deletions
|
@ -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 {}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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<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 {
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
|
||||
|
@ -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)?;
|
||||
|
|
|
@ -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<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,
|
||||
|
@ -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(# <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();
|
||||
|
@ -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>,
|
||||
|
@ -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)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue