mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
style: Add serialization code for MediaCondition.
Bug: 1422225 Reviewed-by: xidorn MozReview-Commit-ID: AxQQottV1hG
This commit is contained in:
parent
0b49a3701a
commit
d2a1895752
1 changed files with 35 additions and 1 deletions
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
use cssparser::{Parser, Token};
|
use cssparser::{Parser, Token};
|
||||||
use parser::ParserContext;
|
use parser::ParserContext;
|
||||||
use style_traits::ParseError;
|
use std::fmt::{self, Write};
|
||||||
|
use style_traits::{CssWriter, ParseError, ToCss};
|
||||||
|
|
||||||
use super::MediaFeatureExpression;
|
use super::MediaFeatureExpression;
|
||||||
|
|
||||||
|
@ -33,6 +34,39 @@ pub enum MediaCondition {
|
||||||
InParens(Box<MediaCondition>),
|
InParens(Box<MediaCondition>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ToCss for MediaCondition {
|
||||||
|
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||||
|
where
|
||||||
|
W: fmt::Write,
|
||||||
|
{
|
||||||
|
match *self {
|
||||||
|
// NOTE(emilio): MediaFeatureExpression already includes the
|
||||||
|
// parenthesis.
|
||||||
|
MediaCondition::Feature(ref f) => f.to_css(dest),
|
||||||
|
MediaCondition::Not(ref c) => {
|
||||||
|
dest.write_str("not ")?;
|
||||||
|
c.to_css(dest)
|
||||||
|
}
|
||||||
|
MediaCondition::InParens(ref c) => {
|
||||||
|
dest.write_char('(')?;
|
||||||
|
c.to_css(dest)?;
|
||||||
|
dest.write_char(')')
|
||||||
|
}
|
||||||
|
MediaCondition::Operation(ref list, op) => {
|
||||||
|
let mut iter = list.iter();
|
||||||
|
iter.next().unwrap().to_css(dest)?;
|
||||||
|
for item in iter {
|
||||||
|
dest.write_char(' ')?;
|
||||||
|
op.to_css(dest)?;
|
||||||
|
dest.write_char(' ')?;
|
||||||
|
item.to_css(dest)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl MediaCondition {
|
impl MediaCondition {
|
||||||
/// Parse a single media condition.
|
/// Parse a single media condition.
|
||||||
pub fn parse<'i, 't>(
|
pub fn parse<'i, 't>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue