Skip to content

Commit

Permalink
Bug 1331213: Allow parsing media query expressions without colons. r=…
Browse files Browse the repository at this point in the history
…heycam

This is used for stuff like @media (monochrome), etc.

MozReview-Commit-ID: ANhZLXDURDj
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
  • Loading branch information
emilio committed Jan 17, 2017
1 parent 2dceb45 commit 197f21f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions components/style/gecko/media_queries.rs
Expand Up @@ -99,7 +99,7 @@ unsafe impl Send for Device {}
#[derive(Debug, Clone)]
pub struct Expression {
feature: &'static nsMediaFeature,
value: MediaExpressionValue,
value: Option<MediaExpressionValue>,
range: nsMediaExpression_Range
}

Expand All @@ -113,11 +113,15 @@ impl ToCss for Expression {
nsMediaExpression_Range::eMax => dest.write_str("max-")?,
nsMediaExpression_Range::eEqual => {},
}
// NB: CSSStringWriter not needed, features are under control.

// NB: CSSStringWriter not needed, feature names are under control.
write!(dest, "{}", Atom::from(unsafe { *self.feature.mName }))?;
dest.write_str(": ")?;

self.value.to_css(dest)?;
if let Some(ref val) = self.value {
dest.write_str(": ")?;
val.to_css(dest)?;
}

dest.write_str(")")
}
}
Expand Down Expand Up @@ -214,7 +218,6 @@ fn starts_with_ignore_ascii_case(string: &str, prefix: &str) -> bool {
string[0..prefix.len()].eq_ignore_ascii_case(prefix)
}

#[allow(warnings)]
fn find_feature<F>(mut f: F) -> Option<&'static nsMediaFeature>
where F: FnMut(&'static nsMediaFeature) -> bool,
{
Expand All @@ -239,7 +242,7 @@ fn find_feature<F>(mut f: F) -> Option<&'static nsMediaFeature>
impl Expression {
/// Trivially construct a new expression.
fn new(feature: &'static nsMediaFeature,
value: MediaExpressionValue,
value: Option<MediaExpressionValue>,
range: nsMediaExpression_Range) -> Self {
Expression {
feature: feature,
Expand All @@ -253,12 +256,10 @@ impl Expression {
/// ```
/// (media-feature: media-value)
/// ```
#[allow(warnings)]
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
try!(input.expect_parenthesis_block());
input.parse_nested_block(|input| {
let ident = try!(input.expect_ident());
try!(input.expect_colon());

let mut flags = 0;
let mut feature_name = &*ident;
Expand Down Expand Up @@ -295,6 +296,17 @@ impl Expression {
return Err(());
}

// If there's no colon, this is a media query of the form
// '(<feature>)', that is, there's no value specified.
//
// FIXME(emilio): We need to check for range operators too here when
// we support them, see:
//
// https://drafts.csswg.org/mediaqueries/#mq-ranges
if input.try(|i| i.expect_colon()).is_err() {
return Ok(Expression::new(feature, None, range));
}

let value = match feature.mValueType {
nsMediaFeature_ValueType::eLength => {
MediaExpressionValue::Length(
Expand Down Expand Up @@ -337,6 +349,7 @@ impl Expression {
nsMediaFeature_ValueType::eEnumerated => {
let index = unsafe {
let _table = feature.mData.mKeywordTable.as_ref();
// TODO
0
};
MediaExpressionValue::Enumerated(index)
Expand Down

0 comments on commit 197f21f

Please sign in to comment.