Make list-style-image use UrlOrNone.

MozReview-Commit-ID: 6E82Tq5nrfC
This commit is contained in:
Cameron McCormack 2016-10-12 16:39:50 +08:00
parent 75e97c02dc
commit 47b4648e62
2 changed files with 7 additions and 81 deletions

View file

@ -26,83 +26,9 @@ ${helpers.single_keyword("list-style-type", """
gecko_constant_prefix="NS_STYLE_LIST_STYLE",
animatable=False)}
<%helpers:longhand name="list-style-image" animatable="False">
use cssparser::{ToCss, Token};
use std::fmt;
use url::Url;
use values::LocalToCss;
use values::NoViewportPercentage;
impl NoViewportPercentage for SpecifiedValue {}
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum SpecifiedValue {
None,
Url(Url),
}
impl ToCss for SpecifiedValue {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
SpecifiedValue::None => dest.write_str("none"),
SpecifiedValue::Url(ref url) => url.to_css(dest),
}
}
}
pub mod computed_value {
use cssparser::{ToCss, Token};
use std::fmt;
use url::Url;
use values::LocalToCss;
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct T(pub Option<Url>);
impl ToCss for T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match self.0 {
None => dest.write_str("none"),
Some(ref url) => url.to_css(dest),
}
}
}
}
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::Url(ref url) => computed_value::T(Some(url.clone())),
}
}
#[inline]
fn from_computed_value(computed: &computed_value::T) -> Self {
match *computed {
computed_value::T(None) => SpecifiedValue::None,
computed_value::T(Some(ref url)) => SpecifiedValue::Url(url.clone()),
}
}
}
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 {
Ok(SpecifiedValue::Url(context.parse_url(&*try!(input.expect_url()))))
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
computed_value::T(None)
}
</%helpers:longhand>
${helpers.predefined_type("list-style-image", "UrlOrNone", "computed_value::T::None",
needs_context=True,
animatable="False")}
<%helpers:longhand name="quotes" animatable="False">
use std::borrow::Cow;