mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Add support for -moz-image-rect
This commit is contained in:
parent
645971b387
commit
494238ab29
7 changed files with 169 additions and 9 deletions
|
@ -611,6 +611,9 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
i);
|
i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Some(computed::Image::ImageRect(_)) => {
|
||||||
|
// TODO: Implement `-moz-image-rect`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1076,6 +1079,9 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
Some(computed::Image::Gradient(..)) => {
|
Some(computed::Image::Gradient(..)) => {
|
||||||
// TODO(gw): Handle border-image with gradient.
|
// TODO(gw): Handle border-image with gradient.
|
||||||
}
|
}
|
||||||
|
Some(computed::Image::ImageRect(..)) => {
|
||||||
|
// TODO: Handle border-image with `-moz-image-rect`.
|
||||||
|
}
|
||||||
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
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
#![allow(unsafe_code)]
|
#![allow(unsafe_code)]
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use gecko::values::convert_rgba_to_nscolor;
|
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::structs::{nsStyleCoord_CalcValue, nsStyleImage};
|
use gecko_bindings::structs::{nsStyleCoord_CalcValue, nsStyleImage};
|
||||||
use gecko_bindings::structs::nsresult;
|
use gecko_bindings::structs::nsresult;
|
||||||
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
|
use gecko_bindings::sugar::ns_style_coord::{CoordDataValue, CoordDataMut};
|
||||||
|
@ -118,6 +119,28 @@ impl nsStyleImage {
|
||||||
*cacheable = false;
|
*cacheable = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Image::ImageRect(ref image_rect) if with_url => {
|
||||||
|
unsafe {
|
||||||
|
Gecko_SetUrlImageValue(self, image_rect.url.for_ffi());
|
||||||
|
Gecko_InitializeImageCropRect(self);
|
||||||
|
|
||||||
|
// We unfortunately must make any url() value uncacheable, since
|
||||||
|
// the applicable declarations cache is not per document, but
|
||||||
|
// global, and the imgRequestProxy objects we store in the style
|
||||||
|
// structs don't like to be tracked by more than one document.
|
||||||
|
//
|
||||||
|
// FIXME(emilio): With the scoped TLS thing this is no longer
|
||||||
|
// true, remove this line in a follow-up!
|
||||||
|
*cacheable = false;
|
||||||
|
|
||||||
|
// Set CropRect
|
||||||
|
let ref mut rect = *self.mCropRect.mPtr;
|
||||||
|
image_rect.top.to_gecko_style_coord(&mut rect.data_at_mut(0));
|
||||||
|
image_rect.right.to_gecko_style_coord(&mut rect.data_at_mut(1));
|
||||||
|
image_rect.bottom.to_gecko_style_coord(&mut rect.data_at_mut(2));
|
||||||
|
image_rect.left.to_gecko_style_coord(&mut rect.data_at_mut(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -678,6 +678,9 @@ extern "C" {
|
||||||
pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage,
|
pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage,
|
||||||
other: *const nsStyleImage);
|
other: *const nsStyleImage);
|
||||||
}
|
}
|
||||||
|
extern "C" {
|
||||||
|
pub fn Gecko_InitializeImageCropRect(image: *mut nsStyleImage);
|
||||||
|
}
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn Gecko_CreateGradient(shape: u8, size: u8, repeating: bool,
|
pub fn Gecko_CreateGradient(shape: u8, size: u8, repeating: bool,
|
||||||
legacy_syntax: bool, stops: u32)
|
legacy_syntax: bool, stops: u32)
|
||||||
|
|
|
@ -11,7 +11,7 @@ use cssparser::Color as CSSColor;
|
||||||
use std::f32::consts::PI;
|
use std::f32::consts::PI;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::computed::{Angle, Context, Length, LengthOrPercentage, ToComputedValue};
|
use values::computed::{Angle, Context, Length, LengthOrPercentage, NumberOrPercentage, ToComputedValue};
|
||||||
use values::computed::position::Position;
|
use values::computed::position::Position;
|
||||||
use values::specified::{self, HorizontalDirection, SizeKeyword, VerticalDirection};
|
use values::specified::{self, HorizontalDirection, SizeKeyword, VerticalDirection};
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
@ -28,6 +28,9 @@ impl ToComputedValue for specified::Image {
|
||||||
},
|
},
|
||||||
specified::Image::Gradient(ref gradient) => {
|
specified::Image::Gradient(ref gradient) => {
|
||||||
Image::Gradient(gradient.to_computed_value(context))
|
Image::Gradient(gradient.to_computed_value(context))
|
||||||
|
},
|
||||||
|
specified::Image::ImageRect(ref image_rect) => {
|
||||||
|
Image::ImageRect(image_rect.to_computed_value(context))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +45,12 @@ impl ToComputedValue for specified::Image {
|
||||||
specified::Image::Gradient(
|
specified::Image::Gradient(
|
||||||
ToComputedValue::from_computed_value(linear_gradient)
|
ToComputedValue::from_computed_value(linear_gradient)
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
Image::ImageRect(ref image_rect) => {
|
||||||
|
specified::Image::ImageRect(
|
||||||
|
ToComputedValue::from_computed_value(image_rect)
|
||||||
|
)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +63,7 @@ impl ToComputedValue for specified::Image {
|
||||||
pub enum Image {
|
pub enum Image {
|
||||||
Url(SpecifiedUrl),
|
Url(SpecifiedUrl),
|
||||||
Gradient(Gradient),
|
Gradient(Gradient),
|
||||||
|
ImageRect(ImageRect),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for Image {
|
impl fmt::Debug for Image {
|
||||||
|
@ -70,6 +79,7 @@ impl fmt::Debug for Image {
|
||||||
GradientKind::Radial(_, _) => write!(f, "radial-gradient({:?})", grad),
|
GradientKind::Radial(_, _) => write!(f, "radial-gradient({:?})", grad),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Image::ImageRect(ref image_rect) => write!(f, "{:?}", image_rect),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,7 +88,8 @@ impl ToCss for Image {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
match *self {
|
match *self {
|
||||||
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -336,6 +347,59 @@ impl ToComputedValue for specified::GradientEndingShape {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Computed values for ImageRect
|
||||||
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub struct ImageRect {
|
||||||
|
pub url: SpecifiedUrl,
|
||||||
|
pub top: NumberOrPercentage,
|
||||||
|
pub bottom: NumberOrPercentage,
|
||||||
|
pub right: NumberOrPercentage,
|
||||||
|
pub left: NumberOrPercentage,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for ImageRect {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
dest.write_str("-moz-image-rect(")?;
|
||||||
|
self.url.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.top.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.right.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.bottom.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.left.to_css(dest)?;
|
||||||
|
dest.write_str(")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToComputedValue for specified::ImageRect {
|
||||||
|
type ComputedValue = ImageRect;
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn to_computed_value(&self, context: &Context) -> ImageRect {
|
||||||
|
ImageRect {
|
||||||
|
url: self.url.to_computed_value(context),
|
||||||
|
top: self.top.to_computed_value(context),
|
||||||
|
right: self.right.to_computed_value(context),
|
||||||
|
bottom: self.bottom.to_computed_value(context),
|
||||||
|
left: self.left.to_computed_value(context),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[inline]
|
||||||
|
fn from_computed_value(computed: &ImageRect) -> Self {
|
||||||
|
specified::ImageRect {
|
||||||
|
url: ToComputedValue::from_computed_value(&computed.url),
|
||||||
|
top: ToComputedValue::from_computed_value(&computed.top),
|
||||||
|
right: ToComputedValue::from_computed_value(&computed.right),
|
||||||
|
bottom: ToComputedValue::from_computed_value(&computed.bottom),
|
||||||
|
left: ToComputedValue::from_computed_value(&computed.left),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-images/#valdef-radial-gradient-size
|
/// https://drafts.csswg.org/css-images/#valdef-radial-gradient-size
|
||||||
#[derive(Clone, PartialEq)]
|
#[derive(Clone, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
|
|
@ -15,7 +15,7 @@ use super::{CSSFloat, CSSInteger, RGBA, specified};
|
||||||
use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
|
use super::specified::grid::{TrackBreadth as GenericTrackBreadth, TrackSize as GenericTrackSize};
|
||||||
|
|
||||||
pub use cssparser::Color as CSSColor;
|
pub use cssparser::Color as CSSColor;
|
||||||
pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, GradientKind, Image};
|
pub use self::image::{AngleOrCorner, EndingShape as GradientShape, Gradient, GradientKind, Image, ImageRect};
|
||||||
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{LengthOrKeyword, LengthOrPercentageOrKeyword};
|
||||||
pub use super::{Auto, Either, None_};
|
pub use super::{Auto, Either, None_};
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
|
|
|
@ -13,7 +13,7 @@ use parser::{Parse, ParserContext};
|
||||||
use servo_url::ServoUrl;
|
use servo_url::ServoUrl;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
use values::specified::{Angle, CSSColor, Length, LengthOrPercentage};
|
use values::specified::{Angle, CSSColor, Length, LengthOrPercentage, NumberOrPercentage};
|
||||||
use values::specified::position::Position;
|
use values::specified::position::Position;
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ pub enum Image {
|
||||||
Url(SpecifiedUrl),
|
Url(SpecifiedUrl),
|
||||||
/// A `<gradient>` image.
|
/// A `<gradient>` image.
|
||||||
Gradient(Gradient),
|
Gradient(Gradient),
|
||||||
|
/// A `-moz-image-rect` image
|
||||||
|
ImageRect(ImageRect),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for Image {
|
impl ToCss for Image {
|
||||||
|
@ -33,6 +35,7 @@ impl ToCss for Image {
|
||||||
match *self {
|
match *self {
|
||||||
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),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,8 +46,11 @@ impl Image {
|
||||||
if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
if let Ok(url) = input.try(|input| SpecifiedUrl::parse(context, input)) {
|
||||||
return Ok(Image::Url(url));
|
return Ok(Image::Url(url));
|
||||||
}
|
}
|
||||||
|
if let Ok(gradient) = input.try(|input| Gradient::parse_function(context, input)) {
|
||||||
|
return Ok(Image::Gradient(gradient));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(Image::Gradient(try!(Gradient::parse_function(context, input))))
|
Ok(Image::ImageRect(ImageRect::parse(context, input)?))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an already specified image value from an already resolved URL
|
/// Creates an already specified image value from an already resolved URL
|
||||||
|
@ -236,6 +242,64 @@ impl GradientKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Specified values for `moz-image-rect`
|
||||||
|
/// -moz-image-rect(<uri>, top, right, bottom, left);
|
||||||
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
|
#[allow(missing_docs)]
|
||||||
|
pub struct ImageRect {
|
||||||
|
pub url: SpecifiedUrl,
|
||||||
|
pub top: NumberOrPercentage,
|
||||||
|
pub bottom: NumberOrPercentage,
|
||||||
|
pub right: NumberOrPercentage,
|
||||||
|
pub left: NumberOrPercentage,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss for ImageRect {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
dest.write_str("-moz-image-rect(")?;
|
||||||
|
self.url.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.top.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.right.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.bottom.to_css(dest)?;
|
||||||
|
dest.write_str(", ")?;
|
||||||
|
self.left.to_css(dest)?;
|
||||||
|
dest.write_str(")")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for ImageRect {
|
||||||
|
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||||
|
match_ignore_ascii_case! { &try!(input.expect_function()),
|
||||||
|
"-moz-image-rect" => {
|
||||||
|
input.parse_nested_block(|input| {
|
||||||
|
let url = SpecifiedUrl::parse(context, input)?;
|
||||||
|
input.expect_comma()?;
|
||||||
|
let top = NumberOrPercentage::parse(context, input)?;
|
||||||
|
input.expect_comma()?;
|
||||||
|
let right = NumberOrPercentage::parse(context, input)?;
|
||||||
|
input.expect_comma()?;
|
||||||
|
let bottom = NumberOrPercentage::parse(context, input)?;
|
||||||
|
input.expect_comma()?;
|
||||||
|
let left = NumberOrPercentage::parse(context, input)?;
|
||||||
|
|
||||||
|
Ok(ImageRect {
|
||||||
|
url: url,
|
||||||
|
top: top,
|
||||||
|
right: right,
|
||||||
|
bottom: bottom,
|
||||||
|
left: left,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_ => Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_two_length(context: &ParserContext, input: &mut Parser)
|
fn parse_two_length(context: &ParserContext, input: &mut Parser)
|
||||||
-> Result<(LengthOrPercentage, LengthOrPercentage), ()> {
|
-> Result<(LengthOrPercentage, LengthOrPercentage), ()> {
|
||||||
let first = try!(LengthOrPercentage::parse(context, input));
|
let first = try!(LengthOrPercentage::parse(context, input));
|
||||||
|
|
|
@ -26,8 +26,8 @@ pub use self::align::{AlignItems, AlignJustifyContent, AlignJustifySelf, Justify
|
||||||
pub use self::color::Color;
|
pub use self::color::Color;
|
||||||
pub use self::grid::{GridLine, TrackKeyword};
|
pub use self::grid::{GridLine, TrackKeyword};
|
||||||
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
|
||||||
pub use self::image::{GradientKind, HorizontalDirection, Image, LengthOrKeyword, LengthOrPercentageOrKeyword};
|
pub use self::image::{GradientKind, HorizontalDirection, Image, ImageRect, LengthOrKeyword};
|
||||||
pub use self::image::{SizeKeyword, VerticalDirection};
|
pub use self::image::{LengthOrPercentageOrKeyword, SizeKeyword, VerticalDirection};
|
||||||
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
|
pub use self::length::{FontRelativeLength, ViewportPercentageLength, CharacterWidth, Length, CalcLengthOrPercentage};
|
||||||
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
pub use self::length::{Percentage, LengthOrNone, LengthOrNumber, LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||||
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength, CalcUnit};
|
pub use self::length::{LengthOrPercentageOrNone, LengthOrPercentageOrAutoOrContent, NoCalcLength, CalcUnit};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue