Move Servo-specific ToCss to style_traits

This commit is contained in:
Ravi Shankar 2016-11-06 16:22:11 +05:30
parent 60e09add4d
commit 5dbc8d02c9
6 changed files with 53 additions and 38 deletions

View file

@ -7,11 +7,7 @@
//! [values]: https://drafts.csswg.org/css-values/
pub use cssparser::RGBA;
use app_units::Au;
use cssparser::CssStringWriter;
use std::fmt::{self, Write};
use url::Url;
pub use style_traits::ToCss as LocalToCss;
macro_rules! define_numbered_css_keyword_enum {
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
@ -48,38 +44,6 @@ macro_rules! define_numbered_css_keyword_enum {
pub mod computed;
pub mod specified;
/// The real ToCss trait can't be implemented for types in crates that don't
/// depend on each other.
pub trait LocalToCss {
/// Serialize `self` in CSS syntax, writing to `dest`.
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write;
/// Serialize `self` in CSS syntax and return a string.
///
/// (This is a convenience wrapper for `to_css` and probably should not be overridden.)
#[inline]
fn to_css_string(&self) -> String {
let mut s = String::new();
self.to_css(&mut s).unwrap();
s
}
}
impl LocalToCss for Au {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{}px", self.to_f64_px())
}
}
impl LocalToCss for Url {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
try!(dest.write_str("url(\""));
try!(write!(CssStringWriter::new(dest), "{}", self));
try!(dest.write_str("\")"));
Ok(())
}
}
pub type CSSFloat = f32;
pub const FONT_MEDIUM_PX: i32 = 16;