mirror of
https://github.com/servo/servo.git
synced 2025-09-01 02:28:21 +01:00
Bug 1300731 - stylo: Implement mask-image; r?heycam
This commit is contained in:
parent
075a430b99
commit
7138ad7d7e
6 changed files with 283 additions and 144 deletions
|
@ -28,9 +28,7 @@ ${helpers.predefined_type("background-color", "CSSColor",
|
|||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match self.0 {
|
||||
None => dest.write_str("none"),
|
||||
Some(computed::Image::Url(ref url, ref _extra_data)) => url.to_css(dest),
|
||||
Some(computed::Image::LinearGradient(ref gradient)) =>
|
||||
gradient.to_css(dest)
|
||||
Some(ref image) => image.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,3 +147,96 @@ ${helpers.single_keyword("mask-composite",
|
|||
vector=True,
|
||||
products="gecko",
|
||||
animatable=False)}
|
||||
|
||||
<%helpers:vector_longhand name="mask-image" products="gecko" animatable="False">
|
||||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
use url::Url;
|
||||
use values::specified::{Image, UrlExtraData};
|
||||
use values::LocalToCss;
|
||||
use values::NoViewportPercentage;
|
||||
|
||||
pub mod computed_value {
|
||||
use cssparser::ToCss;
|
||||
use std::fmt;
|
||||
use url::Url;
|
||||
use values::{computed, LocalToCss};
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum T {
|
||||
Image(computed::Image),
|
||||
Url(Url, computed::UrlExtraData),
|
||||
None
|
||||
}
|
||||
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
T::None => dest.write_str("none"),
|
||||
T::Image(ref image) => image.to_css(dest),
|
||||
T::Url(ref url, _) => url.to_css(dest),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl NoViewportPercentage for SpecifiedValue {}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub enum SpecifiedValue {
|
||||
Image(Image),
|
||||
Url(Url, UrlExtraData),
|
||||
None
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Image(ref image) => image.to_css(dest),
|
||||
SpecifiedValue::Url(ref url, _) => url.to_css(dest),
|
||||
SpecifiedValue::None => dest.write_str("none"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::None
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue::None
|
||||
}
|
||||
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
|
||||
Ok(SpecifiedValue::None)
|
||||
} else {
|
||||
let image = try!(Image::parse(context, input));
|
||||
match image {
|
||||
Image::Url(url, data) => {
|
||||
if url.fragment().is_some() {
|
||||
Ok(SpecifiedValue::Url(url, data))
|
||||
} else {
|
||||
Ok(SpecifiedValue::Image(Image::Url(url, data)))
|
||||
}
|
||||
}
|
||||
image => Ok(SpecifiedValue::Image(image))
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> computed_value::T {
|
||||
match *self {
|
||||
SpecifiedValue::None => computed_value::T::None,
|
||||
SpecifiedValue::Image(ref image) =>
|
||||
computed_value::T::Image(image.to_computed_value(context)),
|
||||
SpecifiedValue::Url(ref url, ref data) =>
|
||||
computed_value::T::Url(url.clone(), data.clone()),
|
||||
}
|
||||
}
|
||||
}
|
||||
</%helpers:vector_longhand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue