Auto merge of #16319 - canaltinova:element, r=upsuper

stylo: Add -moz-element support

Implemented -moz-element for background property.
r=upsuper

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #15443 and [Bug 1341761](https://bugzilla.mozilla.org/show_bug.cgi?id=1341761)

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16319)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-04-10 14:08:04 -05:00 committed by GitHub
commit 3620e755a9
5 changed files with 64 additions and 4 deletions

View file

@ -657,6 +657,9 @@ impl FragmentDisplayListBuilding for Fragment {
Some(computed::Image::ImageRect(_)) => { Some(computed::Image::ImageRect(_)) => {
// TODO: Implement `-moz-image-rect` // TODO: Implement `-moz-image-rect`
} }
Some(computed::Image::Element(_)) => {
// TODO: Implement `-moz-element`
}
} }
} }
} }
@ -1154,6 +1157,9 @@ impl FragmentDisplayListBuilding for Fragment {
Some(computed::Image::ImageRect(..)) => { Some(computed::Image::ImageRect(..)) => {
// TODO: Handle border-image with `-moz-image-rect`. // TODO: Handle border-image with `-moz-image-rect`.
} }
Some(computed::Image::Element(..)) => {
// TODO: Handle border-image with `-moz-element`.
}
Some(computed::Image::Url(ref image_url)) => { Some(computed::Image::Url(ref image_url)) => {
if let Some(url) = image_url.url() { if let Some(url) = image_url.url() {
let webrender_image = state.layout_context let webrender_image = state.layout_context

View file

@ -11,7 +11,7 @@
use app_units::Au; use app_units::Au;
use gecko::values::{convert_rgba_to_nscolor, GeckoStyleCoordConvertible}; use gecko::values::{convert_rgba_to_nscolor, GeckoStyleCoordConvertible};
use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue}; use gecko_bindings::bindings::{Gecko_CreateGradient, Gecko_SetGradientImageValue, Gecko_SetUrlImageValue};
use gecko_bindings::bindings::Gecko_InitializeImageCropRect; use gecko_bindings::bindings::{Gecko_InitializeImageCropRect, Gecko_SetImageElement};
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage}; use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
use gecko_bindings::structs::{nsresult, SheetType}; use gecko_bindings::structs::{nsresult, SheetType};
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut}; use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
@ -141,6 +141,11 @@ impl nsStyleImage {
image_rect.left.to_gecko_style_coord(&mut rect.data_at_mut(3)); image_rect.left.to_gecko_style_coord(&mut rect.data_at_mut(3));
} }
} }
Image::Element(ref element) => {
unsafe {
Gecko_SetImageElement(self, element.as_ptr());
}
},
_ => (), _ => (),
} }
} }

View file

@ -722,6 +722,10 @@ extern "C" {
pub fn Gecko_SetUrlImageValue(image: *mut nsStyleImage, pub fn Gecko_SetUrlImageValue(image: *mut nsStyleImage,
uri: ServoBundledURI); uri: ServoBundledURI);
} }
extern "C" {
pub fn Gecko_SetImageElement(image: *mut nsStyleImage,
atom: *mut nsIAtom);
}
extern "C" { extern "C" {
pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage, pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage,
other: *const nsStyleImage); other: *const nsStyleImage);

View file

@ -7,7 +7,8 @@
//! //!
//! [image]: https://drafts.csswg.org/css-images/#image-values //! [image]: https://drafts.csswg.org/css-images/#image-values
use cssparser::Color as CSSColor; use Atom;
use cssparser::{Color as CSSColor, serialize_identifier};
use std::f32::consts::PI; use std::f32::consts::PI;
use std::fmt; use std::fmt;
use style_traits::ToCss; use style_traits::ToCss;
@ -31,6 +32,9 @@ impl ToComputedValue for specified::Image {
}, },
specified::Image::ImageRect(ref image_rect) => { specified::Image::ImageRect(ref image_rect) => {
Image::ImageRect(image_rect.to_computed_value(context)) Image::ImageRect(image_rect.to_computed_value(context))
},
specified::Image::Element(ref selector) => {
Image::Element(selector.clone())
} }
} }
} }
@ -51,6 +55,9 @@ impl ToComputedValue for specified::Image {
ToComputedValue::from_computed_value(image_rect) ToComputedValue::from_computed_value(image_rect)
) )
}, },
Image::Element(ref selector) => {
specified::Image::Element(selector.clone())
},
} }
} }
} }
@ -64,6 +71,7 @@ pub enum Image {
Url(SpecifiedUrl), Url(SpecifiedUrl),
Gradient(Gradient), Gradient(Gradient),
ImageRect(ImageRect), ImageRect(ImageRect),
Element(Atom),
} }
impl fmt::Debug for Image { impl fmt::Debug for Image {
@ -80,6 +88,11 @@ impl fmt::Debug for Image {
} }
}, },
Image::ImageRect(ref image_rect) => write!(f, "{:?}", image_rect), Image::ImageRect(ref image_rect) => write!(f, "{:?}", image_rect),
Image::Element(ref selector) => {
f.write_str("-moz-element(#")?;
serialize_identifier(&*selector.to_string(), f)?;
f.write_str(")")
},
} }
} }
} }
@ -90,6 +103,12 @@ impl ToCss for Image {
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::ImageRect(ref image_rect) => image_rect.to_css(dest), Image::ImageRect(ref image_rect) => image_rect.to_css(dest),
Image::Element(ref selector) => {
dest.write_str("-moz-element(#")?;
// FIXME: We should get rid of these intermediate strings.
serialize_identifier(&*selector.to_string(), dest)?;
dest.write_str(")")
},
} }
} }
} }

View file

@ -7,7 +7,8 @@
//! //!
//! [image]: https://drafts.csswg.org/css-images/#image-values //! [image]: https://drafts.csswg.org/css-images/#image-values
use cssparser::Parser; use Atom;
use cssparser::{Parser, Token, serialize_identifier};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use servo_url::ServoUrl; use servo_url::ServoUrl;
@ -28,6 +29,8 @@ pub enum Image {
Gradient(Gradient), Gradient(Gradient),
/// A `-moz-image-rect` image /// A `-moz-image-rect` image
ImageRect(ImageRect), ImageRect(ImageRect),
/// A `-moz-element(# <element-id>)`
Element(Atom),
} }
impl ToCss for Image { impl ToCss for Image {
@ -36,6 +39,12 @@ impl ToCss for Image {
Image::Url(ref url_value) => url_value.to_css(dest), Image::Url(ref url_value) => url_value.to_css(dest),
Image::Gradient(ref gradient) => gradient.to_css(dest), Image::Gradient(ref gradient) => gradient.to_css(dest),
Image::ImageRect(ref image_rect) => image_rect.to_css(dest), Image::ImageRect(ref image_rect) => image_rect.to_css(dest),
Image::Element(ref selector) => {
dest.write_str("-moz-element(#")?;
// FIXME: We should get rid of these intermediate strings.
serialize_identifier(&*selector.to_string(), dest)?;
dest.write_str(")")
},
} }
} }
} }
@ -49,8 +58,11 @@ impl Image {
if let Ok(gradient) = input.try(|input| Gradient::parse_function(context, input)) { if let Ok(gradient) = input.try(|input| Gradient::parse_function(context, input)) {
return Ok(Image::Gradient(gradient)); return Ok(Image::Gradient(gradient));
} }
if let Ok(image_rect) = input.try(|input| ImageRect::parse(context, input)) {
return Ok(Image::ImageRect(image_rect));
}
Ok(Image::ImageRect(ImageRect::parse(context, input)?)) Ok(Image::Element(Image::parse_element(input)?))
} }
/// Creates an already specified image value from an already resolved URL /// Creates an already specified image value from an already resolved URL
@ -59,6 +71,20 @@ impl Image {
pub fn for_cascade(url: ServoUrl) -> Self { pub fn for_cascade(url: ServoUrl) -> Self {
Image::Url(SpecifiedUrl::for_cascade(url)) Image::Url(SpecifiedUrl::for_cascade(url))
} }
/// Parses a `-moz-element(# <element-id>)`.
fn parse_element(input: &mut Parser) -> Result<Atom, ()> {
if input.try(|i| i.expect_function_matching("-moz-element")).is_ok() {
input.parse_nested_block(|i| {
match i.next()? {
Token::IDHash(id) => Ok(Atom::from(id)),
_ => Err(()),
}
})
} else {
Err(())
}
}
} }
/// Specified values for a CSS gradient. /// Specified values for a CSS gradient.