Implement the correct ToCss for UrlSource. r?emilio
draft
Implement the correct ToCss for UrlSource. r?emilio
MozReview-Commit-ID: ILRxVzXvMLV
--- a/servo/components/style/font_face.rs
+++ b/servo/components/style/font_face.rs
@@ -19,16 +19,17 @@ use parser::{ParserContext, ParserErrorC
#[cfg(feature = "gecko")]
use properties::longhands::font_language_override;
use selectors::parser::SelectorParseErrorKind;
use shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
use std::fmt::{self, Write};
use str::CssStringWriter;
use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
use style_traits::{StyleParseErrorKind, ToCss};
+use style_traits::values::SequenceWriter;
use values::computed::font::FamilyName;
#[cfg(feature = "gecko")]
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
use values::specified::url::SpecifiedUrl;
/// A source for a font-face rule.
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
@@ -44,25 +45,41 @@ impl OneOrMoreSeparated for Source {
type S = Comma;
}
/// A `UrlSource` represents a font-face source that has been specified with a
/// `url()` function.
///
/// <https://drafts.csswg.org/css-fonts/#src-desc>
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
-#[derive(Clone, Debug, Eq, PartialEq, ToCss)]
+#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UrlSource {
/// The specified url.
pub url: SpecifiedUrl,
/// The format hints specified with the `format()` function.
- #[css(skip)]
pub format_hints: Vec<String>,
}
+impl ToCss for UrlSource {
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
+ self.url.to_css(dest)?;
+ if !self.format_hints.is_empty() {
+ dest.write_str(" format(")?;
+ {
+ let mut writer = SequenceWriter::new(dest, ", ");
+ for hint in self.format_hints.iter() {
+ writer.item(hint)?;
+ }
+ }
+ dest.write_char(')')?;
+ }
+ Ok(())
+ }
+}
+
/// A font-display value for a @font-face rule.
/// The font-display descriptor determines how a font face is displayed based
/// on whether and when it is downloaded and ready to use.
#[allow(missing_docs)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq)]
#[derive(ToComputedValue, ToCss)]
pub enum FontDisplay {