mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Move Servo-specific ToCss to style_traits
This commit is contained in:
parent
60e09add4d
commit
5dbc8d02c9
6 changed files with 53 additions and 38 deletions
1
components/servo/Cargo.lock
generated
1
components/servo/Cargo.lock
generated
|
@ -2429,6 +2429,7 @@ dependencies = [
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"serde_derive 0.8.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -7,11 +7,7 @@
|
||||||
//! [values]: https://drafts.csswg.org/css-values/
|
//! [values]: https://drafts.csswg.org/css-values/
|
||||||
|
|
||||||
pub use cssparser::RGBA;
|
pub use cssparser::RGBA;
|
||||||
|
pub use style_traits::ToCss as LocalToCss;
|
||||||
use app_units::Au;
|
|
||||||
use cssparser::CssStringWriter;
|
|
||||||
use std::fmt::{self, Write};
|
|
||||||
use url::Url;
|
|
||||||
|
|
||||||
macro_rules! define_numbered_css_keyword_enum {
|
macro_rules! define_numbered_css_keyword_enum {
|
||||||
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
($name: ident: $( $css: expr => $variant: ident = $value: expr ),+,) => {
|
||||||
|
@ -48,38 +44,6 @@ macro_rules! define_numbered_css_keyword_enum {
|
||||||
pub mod computed;
|
pub mod computed;
|
||||||
pub mod specified;
|
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 type CSSFloat = f32;
|
||||||
|
|
||||||
pub const FONT_MEDIUM_PX: i32 = 16;
|
pub const FONT_MEDIUM_PX: i32 = 16;
|
||||||
|
|
|
@ -22,3 +22,4 @@ heapsize_derive = {version = "0.1", optional = true}
|
||||||
rustc-serialize = "0.3"
|
rustc-serialize = "0.3"
|
||||||
serde = {version = "0.8", optional = true}
|
serde = {version = "0.8", optional = true}
|
||||||
serde_derive = {version = "0.8", optional = true}
|
serde_derive = {version = "0.8", optional = true}
|
||||||
|
url = "1.2"
|
||||||
|
|
|
@ -23,6 +23,7 @@ extern crate euclid;
|
||||||
extern crate rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
#[cfg(feature = "servo")] extern crate serde;
|
#[cfg(feature = "servo")] extern crate serde;
|
||||||
#[cfg(feature = "servo")] #[macro_use] extern crate serde_derive;
|
#[cfg(feature = "servo")] #[macro_use] extern crate serde_derive;
|
||||||
|
extern crate url;
|
||||||
|
|
||||||
/// Opaque type stored in type-unsafe work queues for parallel layout.
|
/// Opaque type stored in type-unsafe work queues for parallel layout.
|
||||||
/// Must be transmutable to and from TNode.
|
/// Must be transmutable to and from TNode.
|
||||||
|
@ -61,3 +62,4 @@ pub mod cursor;
|
||||||
pub mod values;
|
pub mod values;
|
||||||
pub mod viewport;
|
pub mod viewport;
|
||||||
|
|
||||||
|
pub use values::ToCss;
|
||||||
|
|
|
@ -2,6 +2,53 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use app_units::Au;
|
||||||
|
use cssparser::CssStringWriter;
|
||||||
|
use std::fmt::{self, Write};
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
|
/// The real ToCss trait can't be implemented for types in crates that don't
|
||||||
|
/// depend on each other.
|
||||||
|
pub trait ToCss {
|
||||||
|
/// 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 ToCss for Au {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
write!(dest, "{}px", self.to_f64_px())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToCss 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(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! impl_to_css_for_predefined_type {
|
||||||
|
($name: ty) => {
|
||||||
|
impl<'a> ToCss for $name {
|
||||||
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
|
::cssparser::ToCss::to_css(self, dest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! define_css_keyword_enum {
|
macro_rules! define_css_keyword_enum {
|
||||||
($name: ident: $( $css: expr => $variant: ident ),+,) => {
|
($name: ident: $( $css: expr => $variant: ident ),+,) => {
|
||||||
|
@ -61,7 +108,6 @@ macro_rules! __define_css_keyword_enum__actual {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub mod specified {
|
pub mod specified {
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
|
||||||
|
|
1
ports/geckolib/Cargo.lock
generated
1
ports/geckolib/Cargo.lock
generated
|
@ -373,6 +373,7 @@ dependencies = [
|
||||||
"cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"cssparser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"euclid 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"url 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue