diff --git a/servo/components/style/media_queries.rs b/servo/components/style/media_queries.rs index 569265b323f7..522a252a05b5 100644 --- a/servo/components/style/media_queries.rs +++ b/servo/components/style/media_queries.rs @@ -42,7 +42,7 @@ impl Default for MediaList { pub enum Range { Min(T), Max(T), - //Eq(T), // FIXME: Implement parsing support for equality then re-enable this. + Eq(T), } impl Range { @@ -54,7 +54,7 @@ impl Range { match *self { Range::Min(ref width) => Range::Min(width.to_computed_value(&context)), Range::Max(ref width) => Range::Max(width.to_computed_value(&context)), - //Range::Eq(ref width) => Range::Eq(compute_width(width)) + Range::Eq(ref width) => Range::Eq(width.to_computed_value(&context)) } } } @@ -64,7 +64,7 @@ impl Range { match *self { Range::Min(ref width) => { value >= *width }, Range::Max(ref width) => { value <= *width }, - //Range::Eq(ref width) => { value == *width }, + Range::Eq(ref width) => { value == *width }, } } } @@ -127,10 +127,11 @@ impl ToCss for MediaQuery { for (i, &e) in self.expressions.iter().enumerate() { try!(write!(dest, "(")); let (mm, l) = match e { - Expression::Width(Range::Min(ref l)) => ("min", l), - Expression::Width(Range::Max(ref l)) => ("max", l), + Expression::Width(Range::Min(ref l)) => ("min-", l), + Expression::Width(Range::Max(ref l)) => ("max-", l), + Expression::Width(Range::Eq(ref l)) => ("", l), }; - try!(write!(dest, "{}-width: ", mm)); + try!(write!(dest, "{}width: ", mm)); try!(l.to_css(dest)); if i == self.expressions.len() - 1 { try!(write!(dest, ")")); @@ -195,6 +196,9 @@ impl Expression { "max-width" => { Ok(Expression::Width(Range::Max(try!(specified::Length::parse_non_negative(input))))) }, + "width" => { + Ok(Expression::Width(Range::Eq(try!(specified::Length::parse_non_negative(input))))) + }, _ => Err(()) } }) diff --git a/servo/tests/unit/style/media_queries.rs b/servo/tests/unit/style/media_queries.rs index cfe91281aa6f..b85904d14dc2 100644 --- a/servo/tests/unit/style/media_queries.rs +++ b/servo/tests/unit/style/media_queries.rs @@ -13,6 +13,7 @@ use style::media_queries::*; use style::parser::ParserContextExtraData; use style::stylesheets::{Stylesheet, Origin, CssRule}; use style::values::specified; +use style_traits::ToCss; pub struct CSSErrorReporterTest; @@ -242,6 +243,18 @@ fn test_mq_expressions() { } }); + test_media_rule("@media print and (width: 43px) { }", |list, css| { + assert!(list.media_queries.len() == 1, css.to_owned()); + let q = &list.media_queries[0]; + assert!(q.qualifier == None, css.to_owned()); + assert!(q.media_type == MediaQueryType::MediaType(MediaType::Print), css.to_owned()); + assert!(q.expressions.len() == 1, css.to_owned()); + match q.expressions[0] { + Expression::Width(Range::Eq(w)) => assert!(w == specified::Length::Absolute(Au::from_px(43))), + _ => panic!("wrong expression type"), + } + }); + test_media_rule("@media fridge and (max-width: 52px) { }", |list, css| { assert!(list.media_queries.len() == 1, css.to_owned()); let q = &list.media_queries[0]; @@ -255,6 +268,16 @@ fn test_mq_expressions() { }); } +#[test] +fn test_to_css() { + test_media_rule("@media print and (width: 43px) { }", |list, _| { + let q = &list.media_queries[0]; + let mut dest = String::new(); + assert_eq!(Ok(()), q.to_css(&mut dest)); + assert_eq!(dest, "print and (width: 43px)"); + }); +} + #[test] fn test_mq_multiple_expressions() { test_media_rule("@media (min-width: 100px) and (max-width: 200px) { }", |list, css| {