mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Stylo: Let SpecifiedUrl be able to carry ImageValue.
This commit is contained in:
parent
eb7314b412
commit
2fe55e82d3
4 changed files with 49 additions and 4 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
use cssparser::CssStringWriter;
|
use cssparser::CssStringWriter;
|
||||||
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
|
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
|
||||||
|
use gecko_bindings::structs::root::mozilla::css::ImageValue;
|
||||||
use gecko_bindings::sugar::refptr::RefPtr;
|
use gecko_bindings::sugar::refptr::RefPtr;
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
@ -24,6 +25,10 @@ pub struct SpecifiedUrl {
|
||||||
|
|
||||||
/// The URL extra data.
|
/// The URL extra data.
|
||||||
pub extra_data: RefPtr<URLExtraData>,
|
pub extra_data: RefPtr<URLExtraData>,
|
||||||
|
|
||||||
|
/// Cache ImageValue, if any, so that we can reuse it while rematching a
|
||||||
|
/// a property with this specified url value.
|
||||||
|
pub image_value: Option<RefPtr<ImageValue>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SpecifiedUrl {
|
impl SpecifiedUrl {
|
||||||
|
@ -37,6 +42,7 @@ impl SpecifiedUrl {
|
||||||
Ok(SpecifiedUrl {
|
Ok(SpecifiedUrl {
|
||||||
serialization: Arc::new(url.into_owned()),
|
serialization: Arc::new(url.into_owned()),
|
||||||
extra_data: context.url_data.clone(),
|
extra_data: context.url_data.clone(),
|
||||||
|
image_value: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,6 +82,21 @@ impl SpecifiedUrl {
|
||||||
mExtraData: self.extra_data.get(),
|
mExtraData: self.extra_data.get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Build and carry an image value on request.
|
||||||
|
pub fn build_image_value(&mut self) {
|
||||||
|
use gecko_bindings::bindings::Gecko_ImageValue_Create;
|
||||||
|
|
||||||
|
debug_assert_eq!(self.image_value, None);
|
||||||
|
self.image_value = {
|
||||||
|
unsafe {
|
||||||
|
let ptr = Gecko_ImageValue_Create(self.for_ffi());
|
||||||
|
// We do not expect Gecko_ImageValue_Create returns null.
|
||||||
|
debug_assert!(!ptr.is_null());
|
||||||
|
Some(RefPtr::from_addrefed(ptr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for SpecifiedUrl {
|
impl ToCss for SpecifiedUrl {
|
||||||
|
|
|
@ -2441,6 +2441,7 @@ ${helpers.single_keyword("-moz-appearance",
|
||||||
|
|
||||||
${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
|
${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
|
boxed="True" if product == "gecko" else "False",
|
||||||
animation_value_type="none",
|
animation_value_type="none",
|
||||||
gecko_ffi_name="mBinding",
|
gecko_ffi_name="mBinding",
|
||||||
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
|
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
|
||||||
|
|
|
@ -120,16 +120,19 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd",
|
||||||
|
|
||||||
${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)",
|
${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
|
boxed="True" if product == "gecko" else "False",
|
||||||
animation_value_type="none",
|
animation_value_type="none",
|
||||||
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
|
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
|
||||||
|
|
||||||
${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)",
|
${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
|
boxed="True" if product == "gecko" else "False",
|
||||||
animation_value_type="none",
|
animation_value_type="none",
|
||||||
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
|
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
|
||||||
|
|
||||||
${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
|
${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
|
boxed="True" if product == "gecko" else "False",
|
||||||
animation_value_type="none",
|
animation_value_type="none",
|
||||||
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
|
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}
|
||||||
|
|
||||||
|
|
|
@ -82,14 +82,34 @@ pub type ImageRect = GenericImageRect<NumberOrPercentage>;
|
||||||
|
|
||||||
impl Parse for Image {
|
impl Parse for Image {
|
||||||
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Image, ()> {
|
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Image, ()> {
|
||||||
if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
#[cfg(feature = "gecko")]
|
||||||
return Ok(GenericImage::Url(url));
|
{
|
||||||
|
if let Ok(mut url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||||
|
url.build_image_value();
|
||||||
|
return Ok(GenericImage::Url(url));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(feature = "servo")]
|
||||||
|
{
|
||||||
|
if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||||
|
return Ok(GenericImage::Url(url));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
||||||
return Ok(GenericImage::Gradient(gradient));
|
return Ok(GenericImage::Gradient(gradient));
|
||||||
}
|
}
|
||||||
if let Ok(image_rect) = input.try(|input| ImageRect::parse(context, input)) {
|
#[cfg(feature = "gecko")]
|
||||||
return Ok(GenericImage::Rect(image_rect));
|
{
|
||||||
|
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| ImageRect::parse(context, input)) {
|
||||||
|
return Ok(GenericImage::Rect(image_rect));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(GenericImage::Element(Image::parse_element(input)?))
|
Ok(GenericImage::Element(Image::parse_element(input)?))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue