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),
}
/// A expression for gecko contains a reference to the media feature, the value
/// the media query contained, and the range to evaluate.
/// A range expression for gecko contains a reference to the media feature, the
/// value the media query contained, and the range to evaluate.
#[derive(Clone, Debug, MallocSizeOf)]
pub struct Expression {
pub struct MediaFeatureExpression {
feature: &'static nsMediaFeature,
value: Option<MediaExpressionValue>,
range_or_operator: Option<RangeOrOperator>,
}
impl ToCss for Expression {
impl ToCss for MediaFeatureExpression {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
@ -341,8 +341,8 @@ impl ToCss for Expression {
}
}
impl PartialEq for Expression {
fn eq(&self, other: &Expression) -> bool {
impl PartialEq for MediaFeatureExpression {
fn eq(&self, other: &Self) -> bool {
self.feature.mName == other.feature.mName && self.value == other.value &&
self.range_or_operator == other.range_or_operator
}
@ -379,7 +379,10 @@ pub enum 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
// feature.
if css_value.mUnit == nsCSSUnit::eCSSUnit_Null {
@ -437,7 +440,7 @@ 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
W: fmt::Write,
{
@ -615,7 +618,7 @@ fn consume_operation_or_colon(
}))
}
impl Expression {
impl MediaFeatureExpression {
/// Trivially construct a new expression.
fn new(
feature: &'static nsMediaFeature,
@ -746,11 +749,7 @@ impl Expression {
));
}
return Ok(Expression::new(
feature,
None,
None,
));
return Ok(Self::new(feature, None, None));
}
Ok(operator) => operator,
};
@ -785,7 +784,7 @@ impl Expression {
.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 str::string_as_ascii_lowercase;
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
use super::Expression;
use super::MediaFeatureExpression;
use values::CustomIdent;
/// <https://drafts.csswg.org/mediaqueries/#mq-prefix>
@ -65,8 +65,8 @@ pub struct MediaQuery {
pub qualifier: Option<Qualifier>,
/// The media type for this query, that can be known, unknown, or "all".
pub media_type: MediaQueryType,
/// The set of expressions that this media query contains.
pub expressions: Vec<Expression>,
/// The set of range expressions that this media query contains.
pub expressions: Vec<MediaFeatureExpression>,
}
impl ToCss for MediaQuery {
@ -143,7 +143,7 @@ impl MediaQuery {
}
// Without a media type, require at least one expression.
expressions.push(Expression::parse(context, input)?);
expressions.push(MediaFeatureExpression::parse(context, input)?);
MediaQueryType::All
},
@ -161,7 +161,7 @@ impl MediaQuery {
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};
#[cfg(feature = "servo")]
pub use servo::media_queries::{Device, Expression};
pub use servo::media_queries::{Device, MediaFeatureExpression};
#[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>
#[derive(Clone, Debug, PartialEq)]
#[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.
///
/// Eventually this will become servo-only.
@ -196,7 +196,7 @@ impl Expression {
let name = input.expect_ident_cloned()?;
input.expect_colon()?;
// TODO: Handle other media features
Ok(Expression(match_ignore_ascii_case! { &name,
Ok(MediaFeatureExpression(match_ignore_ascii_case! { &name,
"min-width" => {
ExpressionKind::Width(Range::Min(specified::Length::parse_non_negative(context, input)?))
},
@ -206,7 +206,7 @@ impl Expression {
"width" => {
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
where
W: Write,
@ -246,8 +246,8 @@ impl ToCss for Expression {
/// An enumeration that represents a ranged value.
///
/// Only public for testing, implementation details of `Expression` may change
/// for Stylo.
/// Only public for testing, implementation details of `MediaFeatureExpression`
/// may change for Stylo.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
pub enum Range<T> {

View file

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