style: Rename Expression to MediaFeatureExpression.

Which is more appropriate, given it represents a `<media-feature>` per spec, and
expression is a bit overloaded :)

Bug: 1422225
Reviewed-by: xidorn
MozReview-Commit-ID: Fed1nJhHxDu
This commit is contained in:
Emilio Cobos Álvarez 2018-06-15 21:29:57 -07:00
parent ef14e65636
commit e7cc548c35
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
5 changed files with 31 additions and 32 deletions

View file

@ -292,16 +292,16 @@ enum RangeOrOperator {
Operator(Operator), Operator(Operator),
} }
/// A expression for gecko contains a reference to the media feature, the value /// A range expression for gecko contains a reference to the media feature, the
/// the media query contained, and the range to evaluate. /// value the media query contained, and the range to evaluate.
#[derive(Clone, Debug, MallocSizeOf)] #[derive(Clone, Debug, MallocSizeOf)]
pub struct Expression { pub struct MediaFeatureExpression {
feature: &'static nsMediaFeature, feature: &'static nsMediaFeature,
value: Option<MediaExpressionValue>, value: Option<MediaExpressionValue>,
range_or_operator: Option<RangeOrOperator>, range_or_operator: Option<RangeOrOperator>,
} }
impl ToCss for Expression { impl ToCss for MediaFeatureExpression {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where where
W: fmt::Write, W: fmt::Write,
@ -341,8 +341,8 @@ impl ToCss for Expression {
} }
} }
impl PartialEq for Expression { impl PartialEq for MediaFeatureExpression {
fn eq(&self, other: &Expression) -> bool { fn eq(&self, other: &Self) -> bool {
self.feature.mName == other.feature.mName && self.value == other.value && self.feature.mName == other.feature.mName && self.value == other.value &&
self.range_or_operator == other.range_or_operator self.range_or_operator == other.range_or_operator
} }
@ -379,7 +379,10 @@ pub enum MediaExpressionValue {
} }
impl MediaExpressionValue { impl MediaExpressionValue {
fn from_css_value(for_expr: &Expression, css_value: &nsCSSValue) -> Option<Self> { fn from_css_value(
for_expr: &MediaFeatureExpression,
css_value: &nsCSSValue,
) -> Option<Self> {
// NB: If there's a null value, that means that we don't support the // NB: If there's a null value, that means that we don't support the
// feature. // feature.
if css_value.mUnit == nsCSSUnit::eCSSUnit_Null { if css_value.mUnit == nsCSSUnit::eCSSUnit_Null {
@ -437,7 +440,7 @@ impl MediaExpressionValue {
} }
impl MediaExpressionValue { impl MediaExpressionValue {
fn to_css<W>(&self, dest: &mut CssWriter<W>, for_expr: &Expression) -> fmt::Result fn to_css<W>(&self, dest: &mut CssWriter<W>, for_expr: &MediaFeatureExpression) -> fmt::Result
where where
W: fmt::Write, W: fmt::Write,
{ {
@ -615,7 +618,7 @@ fn consume_operation_or_colon(
})) }))
} }
impl Expression { impl MediaFeatureExpression {
/// Trivially construct a new expression. /// Trivially construct a new expression.
fn new( fn new(
feature: &'static nsMediaFeature, feature: &'static nsMediaFeature,
@ -746,11 +749,7 @@ impl Expression {
)); ));
} }
return Ok(Expression::new( return Ok(Self::new(feature, None, None));
feature,
None,
None,
));
} }
Ok(operator) => operator, Ok(operator) => operator,
}; };
@ -785,7 +784,7 @@ impl Expression {
.new_custom_error(StyleParseErrorKind::MediaQueryExpectedFeatureValue) .new_custom_error(StyleParseErrorKind::MediaQueryExpectedFeatureValue)
})?; })?;
Ok(Expression::new(feature, Some(value), range_or_operator)) Ok(Self::new(feature, Some(value), range_or_operator))
}) })
} }

View file

@ -13,7 +13,7 @@ use selectors::parser::SelectorParseErrorKind;
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use str::string_as_ascii_lowercase; use str::string_as_ascii_lowercase;
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use super::Expression; use super::MediaFeatureExpression;
use values::CustomIdent; use values::CustomIdent;
/// <https://drafts.csswg.org/mediaqueries/#mq-prefix> /// <https://drafts.csswg.org/mediaqueries/#mq-prefix>
@ -65,8 +65,8 @@ pub struct MediaQuery {
pub qualifier: Option<Qualifier>, pub qualifier: Option<Qualifier>,
/// The media type for this query, that can be known, unknown, or "all". /// The media type for this query, that can be known, unknown, or "all".
pub media_type: MediaQueryType, pub media_type: MediaQueryType,
/// The set of expressions that this media query contains. /// The set of range expressions that this media query contains.
pub expressions: Vec<Expression>, pub expressions: Vec<MediaFeatureExpression>,
} }
impl ToCss for MediaQuery { impl ToCss for MediaQuery {
@ -143,7 +143,7 @@ impl MediaQuery {
} }
// Without a media type, require at least one expression. // Without a media type, require at least one expression.
expressions.push(Expression::parse(context, input)?); expressions.push(MediaFeatureExpression::parse(context, input)?);
MediaQueryType::All MediaQueryType::All
}, },
@ -161,7 +161,7 @@ impl MediaQuery {
expressions, expressions,
}); });
} }
expressions.push(Expression::parse(context, input)?) expressions.push(MediaFeatureExpression::parse(context, input)?)
} }
} }
} }

View file

@ -13,6 +13,6 @@ pub use self::media_list::MediaList;
pub use self::media_query::{MediaQuery, MediaQueryType, MediaType, Qualifier}; pub use self::media_query::{MediaQuery, MediaQueryType, MediaType, Qualifier};
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
pub use servo::media_queries::{Device, Expression}; pub use servo::media_queries::{Device, MediaFeatureExpression};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko::media_queries::{Device, Expression}; pub use gecko::media_queries::{Device, MediaFeatureExpression};

View file

@ -170,9 +170,9 @@ pub enum ExpressionKind {
/// <http://dev.w3.org/csswg/mediaqueries-3/#media1> /// <http://dev.w3.org/csswg/mediaqueries-3/#media1>
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[cfg_attr(feature = "servo", derive(MallocSizeOf))]
pub struct Expression(pub ExpressionKind); pub struct MediaFeatureExpression(pub ExpressionKind);
impl Expression { impl MediaFeatureExpression {
/// The kind of expression we're, just for unit testing. /// The kind of expression we're, just for unit testing.
/// ///
/// Eventually this will become servo-only. /// Eventually this will become servo-only.
@ -196,7 +196,7 @@ impl Expression {
let name = input.expect_ident_cloned()?; let name = input.expect_ident_cloned()?;
input.expect_colon()?; input.expect_colon()?;
// TODO: Handle other media features // TODO: Handle other media features
Ok(Expression(match_ignore_ascii_case! { &name, Ok(MediaFeatureExpression(match_ignore_ascii_case! { &name,
"min-width" => { "min-width" => {
ExpressionKind::Width(Range::Min(specified::Length::parse_non_negative(context, input)?)) ExpressionKind::Width(Range::Min(specified::Length::parse_non_negative(context, input)?))
}, },
@ -206,7 +206,7 @@ impl Expression {
"width" => { "width" => {
ExpressionKind::Width(Range::Eq(specified::Length::parse_non_negative(context, input)?)) ExpressionKind::Width(Range::Eq(specified::Length::parse_non_negative(context, input)?))
}, },
_ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone()))) _ => return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name)))
})) }))
}) })
} }
@ -228,7 +228,7 @@ impl Expression {
} }
} }
impl ToCss for Expression { impl ToCss for MediaFeatureExpression {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where where
W: Write, W: Write,
@ -246,8 +246,8 @@ impl ToCss for Expression {
/// An enumeration that represents a ranged value. /// An enumeration that represents a ranged value.
/// ///
/// Only public for testing, implementation details of `Expression` may change /// Only public for testing, implementation details of `MediaFeatureExpression`
/// for Stylo. /// may change for Stylo.
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[cfg_attr(feature = "servo", derive(MallocSizeOf))]
pub enum Range<T> { pub enum Range<T> {

View file

@ -8,7 +8,7 @@ use app_units::Au;
use cssparser::{Delimiter, Parser, Token}; use cssparser::{Delimiter, Parser, Token};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI}; use gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use media_queries::{Device, Expression as MediaExpression}; use media_queries::{Device, MediaFeatureExpression};
use parser::{Parse, ParserContext}; use parser::{Parse, ParserContext};
use selectors::context::QuirksMode; use selectors::context::QuirksMode;
use style_traits::ParseError; use style_traits::ParseError;
@ -21,7 +21,7 @@ use values::specified::{Length, NoCalcLength, ViewportPercentageLength};
pub struct SourceSize { pub struct SourceSize {
// FIXME(emilio): This should be a `MediaCondition`, and support `and` and // FIXME(emilio): This should be a `MediaCondition`, and support `and` and
// `or`. // `or`.
condition: MediaExpression, condition: MediaFeatureExpression,
value: Length, value: Length,
} }
@ -30,7 +30,7 @@ impl Parse for SourceSize {
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> { ) -> Result<Self, ParseError<'i>> {
let condition = MediaExpression::parse(context, input)?; let condition = MediaFeatureExpression::parse(context, input)?;
let value = Length::parse_non_negative(context, input)?; let value = Length::parse_non_negative(context, input)?;
Ok(Self { condition, value }) Ok(Self { condition, value })