mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Bug 1331213: Allow parsing media query expressions without colons. r=heycam
This is used for stuff like @media (monochrome), etc. MozReview-Commit-ID: ANhZLXDURDj Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
parent
2dceb4502f
commit
197f21f3a7
1 changed files with 22 additions and 9 deletions
|
@ -99,7 +99,7 @@ unsafe impl Send for Device {}
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Expression {
|
pub struct Expression {
|
||||||
feature: &'static nsMediaFeature,
|
feature: &'static nsMediaFeature,
|
||||||
value: MediaExpressionValue,
|
value: Option<MediaExpressionValue>,
|
||||||
range: nsMediaExpression_Range
|
range: nsMediaExpression_Range
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,11 +113,15 @@ impl ToCss for Expression {
|
||||||
nsMediaExpression_Range::eMax => dest.write_str("max-")?,
|
nsMediaExpression_Range::eMax => dest.write_str("max-")?,
|
||||||
nsMediaExpression_Range::eEqual => {},
|
nsMediaExpression_Range::eEqual => {},
|
||||||
}
|
}
|
||||||
// NB: CSSStringWriter not needed, features are under control.
|
|
||||||
write!(dest, "{}", Atom::from(unsafe { *self.feature.mName }))?;
|
|
||||||
dest.write_str(": ")?;
|
|
||||||
|
|
||||||
self.value.to_css(dest)?;
|
// NB: CSSStringWriter not needed, feature names are under control.
|
||||||
|
write!(dest, "{}", Atom::from(unsafe { *self.feature.mName }))?;
|
||||||
|
|
||||||
|
if let Some(ref val) = self.value {
|
||||||
|
dest.write_str(": ")?;
|
||||||
|
val.to_css(dest)?;
|
||||||
|
}
|
||||||
|
|
||||||
dest.write_str(")")
|
dest.write_str(")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -214,7 +218,6 @@ fn starts_with_ignore_ascii_case(string: &str, prefix: &str) -> bool {
|
||||||
string[0..prefix.len()].eq_ignore_ascii_case(prefix)
|
string[0..prefix.len()].eq_ignore_ascii_case(prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(warnings)]
|
|
||||||
fn find_feature<F>(mut f: F) -> Option<&'static nsMediaFeature>
|
fn find_feature<F>(mut f: F) -> Option<&'static nsMediaFeature>
|
||||||
where F: FnMut(&'static nsMediaFeature) -> bool,
|
where F: FnMut(&'static nsMediaFeature) -> bool,
|
||||||
{
|
{
|
||||||
|
@ -239,7 +242,7 @@ fn find_feature<F>(mut f: F) -> Option<&'static nsMediaFeature>
|
||||||
impl Expression {
|
impl Expression {
|
||||||
/// Trivially construct a new expression.
|
/// Trivially construct a new expression.
|
||||||
fn new(feature: &'static nsMediaFeature,
|
fn new(feature: &'static nsMediaFeature,
|
||||||
value: MediaExpressionValue,
|
value: Option<MediaExpressionValue>,
|
||||||
range: nsMediaExpression_Range) -> Self {
|
range: nsMediaExpression_Range) -> Self {
|
||||||
Expression {
|
Expression {
|
||||||
feature: feature,
|
feature: feature,
|
||||||
|
@ -253,12 +256,10 @@ impl Expression {
|
||||||
/// ```
|
/// ```
|
||||||
/// (media-feature: media-value)
|
/// (media-feature: media-value)
|
||||||
/// ```
|
/// ```
|
||||||
#[allow(warnings)]
|
|
||||||
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
|
pub fn parse(input: &mut Parser) -> Result<Self, ()> {
|
||||||
try!(input.expect_parenthesis_block());
|
try!(input.expect_parenthesis_block());
|
||||||
input.parse_nested_block(|input| {
|
input.parse_nested_block(|input| {
|
||||||
let ident = try!(input.expect_ident());
|
let ident = try!(input.expect_ident());
|
||||||
try!(input.expect_colon());
|
|
||||||
|
|
||||||
let mut flags = 0;
|
let mut flags = 0;
|
||||||
let mut feature_name = &*ident;
|
let mut feature_name = &*ident;
|
||||||
|
@ -295,6 +296,17 @@ impl Expression {
|
||||||
return Err(());
|
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 {
|
let value = match feature.mValueType {
|
||||||
nsMediaFeature_ValueType::eLength => {
|
nsMediaFeature_ValueType::eLength => {
|
||||||
MediaExpressionValue::Length(
|
MediaExpressionValue::Length(
|
||||||
|
@ -337,6 +349,7 @@ impl Expression {
|
||||||
nsMediaFeature_ValueType::eEnumerated => {
|
nsMediaFeature_ValueType::eEnumerated => {
|
||||||
let index = unsafe {
|
let index = unsafe {
|
||||||
let _table = feature.mData.mKeywordTable.as_ref();
|
let _table = feature.mData.mKeywordTable.as_ref();
|
||||||
|
// TODO
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
MediaExpressionValue::Enumerated(index)
|
MediaExpressionValue::Enumerated(index)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue