diff --git a/components/style/font_face.rs b/components/style/font_face.rs index fe010cf106d..662b0c733ce 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -24,33 +24,16 @@ use style_traits::{ToCss, OneOrMoreCommaSeparated, ParseError, StyleParseError}; use values::specified::url::SpecifiedUrl; /// A source for a font-face rule. -#[derive(Clone, Debug, PartialEq, Eq)] #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] +#[derive(Clone, Debug, Eq, PartialEq, ToCss)] pub enum Source { /// A `url()` source. Url(UrlSource), /// A `local()` source. + #[css(function)] Local(FamilyName), } -impl ToCss for Source { - fn to_css(&self, dest: &mut W) -> fmt::Result - where W: fmt::Write, - { - match *self { - Source::Url(ref url) => { - try!(dest.write_str("url(\"")); - try!(url.to_css(dest)); - }, - Source::Local(ref family) => { - try!(dest.write_str("local(\"")); - try!(family.to_css(dest)); - }, - } - dest.write_str("\")") - } -} - impl OneOrMoreCommaSeparated for Source {} /// A `UrlSource` represents a font-face source that has been specified with a @@ -70,7 +53,7 @@ impl ToCss for UrlSource { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write, { - dest.write_str(self.url.as_str()) + self.url.to_css(dest) } } diff --git a/components/style/gecko/url.rs b/components/style/gecko/url.rs index 28359fba6cd..192d43ef5a1 100644 --- a/components/style/gecko/url.rs +++ b/components/style/gecko/url.rs @@ -4,12 +4,11 @@ //! Common handling for the specified value CSS url() values. -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::fmt::{self, Write}; +use std::fmt; use style_traits::{ToCss, ParseError}; use stylearc::Arc; @@ -100,8 +99,8 @@ impl SpecifiedUrl { impl ToCss for SpecifiedUrl { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - try!(dest.write_str("url(\"")); - try!(CssStringWriter::new(dest).write_str(&*self.serialization)); - dest.write_str("\")") + dest.write_str("url(")?; + self.serialization.to_css(dest)?; + dest.write_str(")") } } diff --git a/components/style/servo/url.rs b/components/style/servo/url.rs index fa019d581e6..972eced90e7 100644 --- a/components/style/servo/url.rs +++ b/components/style/servo/url.rs @@ -4,10 +4,9 @@ //! Common handling for the specified value CSS url() values. -use cssparser::CssStringWriter; use parser::ParserContext; use servo_url::ServoUrl; -use std::fmt::{self, Write}; +use std::fmt; // Note: We use std::sync::Arc rather than stylearc::Arc here because the // nonzero optimization is important in keeping the size of SpecifiedUrl below // the threshold. @@ -111,7 +110,6 @@ impl PartialEq for SpecifiedUrl { impl ToCss for SpecifiedUrl { fn to_css(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { - try!(dest.write_str("url(\"")); let string = match self.original { Some(ref original) => &**original, None => match self.resolved { @@ -123,7 +121,8 @@ impl ToCss for SpecifiedUrl { } }; - try!(CssStringWriter::new(dest).write_str(string)); - dest.write_str("\")") + dest.write_str("url(")?; + string.to_css(dest)?; + dest.write_str(")") } }