Skip to content

Commit

Permalink
Stylo: Let SpecifiedUrl be able to carry ImageValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
cku committed May 15, 2017
1 parent eb7314b commit 2fe55e8
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 4 deletions.
21 changes: 21 additions & 0 deletions components/style/gecko/url.rs
Expand Up @@ -6,6 +6,7 @@

use cssparser::CssStringWriter;
use gecko_bindings::structs::{ServoBundledURI, URLExtraData};
use gecko_bindings::structs::root::mozilla::css::ImageValue;
use gecko_bindings::sugar::refptr::RefPtr;
use parser::ParserContext;
use std::borrow::Cow;
Expand All @@ -24,6 +25,10 @@ pub struct SpecifiedUrl {

/// The URL extra data.
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 {
Expand All @@ -37,6 +42,7 @@ impl SpecifiedUrl {
Ok(SpecifiedUrl {
serialization: Arc::new(url.into_owned()),
extra_data: context.url_data.clone(),
image_value: None,
})
}

Expand Down Expand Up @@ -76,6 +82,21 @@ impl SpecifiedUrl {
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 {
Expand Down
1 change: 1 addition & 0 deletions components/style/properties/longhand/box.mako.rs
Expand Up @@ -2441,6 +2441,7 @@ ${helpers.single_keyword("-moz-appearance",

${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True" if product == "gecko" else "False",
animation_value_type="none",
gecko_ffi_name="mBinding",
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding)",
Expand Down
3 changes: 3 additions & 0 deletions components/style/properties/longhand/inherited_svg.mako.rs
Expand Up @@ -120,16 +120,19 @@ ${helpers.single_keyword("clip-rule", "nonzero evenodd",

${helpers.predefined_type("marker-start", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True" if product == "gecko" else "False",
animation_value_type="none",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

${helpers.predefined_type("marker-mid", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True" if product == "gecko" else "False",
animation_value_type="none",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

${helpers.predefined_type("marker-end", "UrlOrNone", "Either::Second(None_)",
products="gecko",
boxed="True" if product == "gecko" else "False",
animation_value_type="none",
spec="https://www.w3.org/TR/SVG2/painting.html#VertexMarkerProperties")}

Expand Down
28 changes: 24 additions & 4 deletions components/style/values/specified/image.rs
Expand Up @@ -82,14 +82,34 @@ pub type ImageRect = GenericImageRect<NumberOrPercentage>;

impl Parse for Image {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Image, ()> {
if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
return Ok(GenericImage::Url(url));
#[cfg(feature = "gecko")]
{
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)) {
return Ok(GenericImage::Gradient(gradient));
}
if let Ok(image_rect) = input.try(|input| ImageRect::parse(context, input)) {
return Ok(GenericImage::Rect(image_rect));
#[cfg(feature = "gecko")]
{
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)?))
Expand Down

0 comments on commit 2fe55e8

Please sign in to comment.