mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +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(_) => {
|
Image::Rect(ref rect) => {
|
||||||
// TODO: Implement `-moz-image-rect`
|
// This is a (boxed) empty enum on non-Gecko
|
||||||
},
|
match **rect {}
|
||||||
Image::Element(_) => {
|
|
||||||
// TODO: Implement `-moz-element`
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -679,7 +679,7 @@ where
|
||||||
element.finish_restyle(context, data, new_styles, important_rules_changed)
|
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)
|
fn notify_paint_worklet<E>(context: &StyleContext<E>, data: &ElementData)
|
||||||
where
|
where
|
||||||
E: TElement,
|
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)
|
fn notify_paint_worklet<E>(_context: &StyleContext<E>, _data: &ElementData)
|
||||||
where
|
where
|
||||||
E: TElement,
|
E: TElement,
|
||||||
|
|
|
@ -9,10 +9,11 @@
|
||||||
|
|
||||||
use crate::values::computed::position::Position;
|
use crate::values::computed::position::Position;
|
||||||
use crate::values::computed::url::ComputedImageUrl;
|
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::{Angle, Color, Context};
|
||||||
use crate::values::computed::{
|
use crate::values::computed::{
|
||||||
LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, NumberOrPercentage,
|
LengthPercentage, NonNegativeLength, NonNegativeLengthPercentage, ToComputedValue,
|
||||||
ToComputedValue,
|
|
||||||
};
|
};
|
||||||
use crate::values::generics::image::{self as generic, GradientCompatMode};
|
use crate::values::generics::image::{self as generic, GradientCompatMode};
|
||||||
use crate::values::specified::image::LineDirection as SpecifiedLineDirection;
|
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>;
|
pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;
|
||||||
|
|
||||||
/// Computed values for `-moz-image-rect(...)`.
|
/// Computed values for `-moz-image-rect(...)`.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub type MozImageRect = generic::MozImageRect<NumberOrPercentage, ComputedImageUrl>;
|
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 {
|
impl generic::LineDirection for LineDirection {
|
||||||
fn points_downwards(&self, compat_mode: GradientCompatMode) -> bool {
|
fn points_downwards(&self, compat_mode: GradientCompatMode) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
|
|
|
@ -53,17 +53,24 @@ impl<I> ImageLayer<I> {
|
||||||
pub enum GenericImage<Gradient, MozImageRect, ImageUrl> {
|
pub enum GenericImage<Gradient, MozImageRect, ImageUrl> {
|
||||||
/// A `<url()>` image.
|
/// A `<url()>` image.
|
||||||
Url(ImageUrl),
|
Url(ImageUrl),
|
||||||
|
|
||||||
/// A `<gradient>` image. Gradients are rather large, and not nearly as
|
/// 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.
|
/// common as urls, so we box them here to keep the size of this enum sane.
|
||||||
Gradient(Box<Gradient>),
|
Gradient(Box<Gradient>),
|
||||||
|
|
||||||
/// A `-moz-image-rect` image. Also fairly large and rare.
|
/// 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>),
|
Rect(Box<MozImageRect>),
|
||||||
|
|
||||||
/// A `-moz-element(# <element-id>)`
|
/// A `-moz-element(# <element-id>)`
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
#[css(function = "-moz-element")]
|
#[css(function = "-moz-element")]
|
||||||
Element(Atom),
|
Element(Atom),
|
||||||
|
|
||||||
/// A paint worklet image.
|
/// A paint worklet image.
|
||||||
/// <https://drafts.css-houdini.org/css-paint-api/>
|
/// <https://drafts.css-houdini.org/css-paint-api/>
|
||||||
#[cfg(feature = "servo")]
|
#[cfg(feature = "servo-layout-2013")]
|
||||||
PaintWorklet(PaintWorklet),
|
PaintWorklet(PaintWorklet),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,8 +330,9 @@ where
|
||||||
Image::Url(ref url) => url.to_css(dest),
|
Image::Url(ref url) => url.to_css(dest),
|
||||||
Image::Gradient(ref gradient) => gradient.to_css(dest),
|
Image::Gradient(ref gradient) => gradient.to_css(dest),
|
||||||
Image::Rect(ref rect) => rect.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),
|
Image::PaintWorklet(ref paint_worklet) => paint_worklet.to_css(dest),
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
Image::Element(ref selector) => {
|
Image::Element(ref selector) => {
|
||||||
dest.write_str("-moz-element(#")?;
|
dest.write_str("-moz-element(#")?;
|
||||||
serialize_atom_identifier(selector, dest)?;
|
serialize_atom_identifier(selector, dest)?;
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
use crate::custom_properties::SpecifiedValue;
|
use crate::custom_properties::SpecifiedValue;
|
||||||
use crate::parser::{Parse, ParserContext};
|
use crate::parser::{Parse, ParserContext};
|
||||||
use crate::stylesheets::CorsMode;
|
|
||||||
use crate::values::generics::image::PaintWorklet;
|
use crate::values::generics::image::PaintWorklet;
|
||||||
use crate::values::generics::image::{
|
use crate::values::generics::image::{
|
||||||
self as generic, Circle, Ellipse, GradientCompatMode, ShapeExtent,
|
self as generic, Circle, Ellipse, GradientCompatMode, ShapeExtent,
|
||||||
|
@ -119,8 +118,24 @@ pub type ColorStop = generic::ColorStop<Color, LengthPercentage>;
|
||||||
|
|
||||||
/// 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);
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
pub type MozImageRect = generic::MozImageRect<NumberOrPercentage, SpecifiedImageUrl>;
|
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 {
|
impl Parse for Image {
|
||||||
fn parse<'i, 't>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
|
@ -132,17 +147,22 @@ impl Parse for Image {
|
||||||
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
||||||
return Ok(generic::Image::Gradient(Box::new(gradient)));
|
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)) {
|
if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
|
||||||
return Ok(generic::Image::PaintWorklet(paint_worklet));
|
return Ok(generic::Image::PaintWorklet(paint_worklet));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
|
{
|
||||||
if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
|
if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
|
||||||
return Ok(generic::Image::Rect(Box::new(image_rect)));
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Image {
|
impl Image {
|
||||||
|
@ -155,6 +175,7 @@ impl Image {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a `-moz-element(# <element-id>)`.
|
/// Parses a `-moz-element(# <element-id>)`.
|
||||||
|
#[cfg(feature = "gecko")]
|
||||||
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
|
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
|
||||||
input.try(|i| i.expect_function_matching("-moz-element"))?;
|
input.try(|i| i.expect_function_matching("-moz-element"))?;
|
||||||
let location = input.current_source_location();
|
let location = input.current_source_location();
|
||||||
|
@ -856,6 +877,15 @@ impl Parse for PaintWorklet {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Parse for MozImageRect {
|
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>(
|
fn parse<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
input: &mut Parser<'i, 't>,
|
input: &mut Parser<'i, 't>,
|
||||||
|
@ -866,7 +896,7 @@ impl Parse for MozImageRect {
|
||||||
let url = SpecifiedImageUrl::parse_from_string(
|
let url = SpecifiedImageUrl::parse_from_string(
|
||||||
string.as_ref().to_owned(),
|
string.as_ref().to_owned(),
|
||||||
context,
|
context,
|
||||||
CorsMode::None,
|
crate::stylesheets::CorsMode::None,
|
||||||
);
|
);
|
||||||
i.expect_comma()?;
|
i.expect_comma()?;
|
||||||
let top = NumberOrPercentage::parse_non_negative(context, i)?;
|
let top = NumberOrPercentage::parse_non_negative(context, i)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue