style: Replace AspectRatio with computed::position::Ratio in media-queries.

Also, we drop the pref, layout.css.aspect-ratio-number.enabled, becacuse
the spec of css-sizing-4 uses Number now.

Differential Revision: https://phabricator.services.mozilla.com/D75233
This commit is contained in:
Boris Chiou 2020-05-20 21:13:35 +00:00 committed by Emilio Cobos Álvarez
parent fc9321bb23
commit 7022f451e1
7 changed files with 50 additions and 54 deletions

View file

@ -4,9 +4,10 @@
//! Media features.
use super::media_feature_expression::{AspectRatio, RangeOrOperator};
use super::media_feature_expression::RangeOrOperator;
use super::Device;
use crate::parser::ParserContext;
use crate::values::computed::position::Ratio;
use crate::values::computed::{CSSPixelLength, Resolution};
use crate::Atom;
use cssparser::Parser;
@ -45,7 +46,7 @@ pub enum Evaluator {
Float(MediaFeatureEvaluator<f32>),
BoolInteger(MediaFeatureEvaluator<bool>),
/// A non-negative number ratio, such as the one from device-pixel-ratio.
NumberRatio(MediaFeatureEvaluator<AspectRatio>),
NumberRatio(MediaFeatureEvaluator<Ratio>),
/// A resolution.
Resolution(MediaFeatureEvaluator<Resolution>),
/// A keyword value.

View file

@ -15,9 +15,8 @@ use crate::parser::{Parse, ParserContext};
#[cfg(feature = "servo")]
use crate::servo::media_queries::MEDIA_FEATURES;
use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
use crate::values::computed::position::Ratio;
use crate::values::computed::{self, ToComputedValue};
#[cfg(feature = "gecko")]
use crate::values::specified::NonNegativeNumber;
use crate::values::specified::{Integer, Length, Number, Resolution};
use crate::values::{serialize_atom_identifier, CSSFloat};
use crate::{Atom, Zero};
@ -26,30 +25,6 @@ use std::cmp::{Ordering, PartialOrd};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
/// An aspect ratio, with a numerator and denominator.
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToShmem)]
pub struct AspectRatio(pub CSSFloat, pub CSSFloat);
impl ToCss for AspectRatio {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where
W: fmt::Write,
{
self.0.to_css(dest)?;
dest.write_str(" / ")?;
self.1.to_css(dest)
}
}
impl PartialOrd for AspectRatio {
fn partial_cmp(&self, other: &AspectRatio) -> Option<Ordering> {
f64::partial_cmp(
&(self.0 as f64 * other.1 as f64),
&(self.1 as f64 * other.0 as f64),
)
}
}
/// The kind of matching that should be performed on a media feature value.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]
pub enum Range {
@ -460,7 +435,7 @@ pub enum MediaExpressionValue {
BoolInteger(bool),
/// A single non-negative number or two non-negative numbers separated by '/',
/// with optional whitespace on either side of the '/'.
NumberRatio(AspectRatio),
NumberRatio(Ratio),
/// A resolution.
Resolution(Resolution),
/// An enumerated value, defined by the variant keyword table in the
@ -517,24 +492,14 @@ impl MediaExpressionValue {
MediaExpressionValue::Float(number.get())
},
Evaluator::NumberRatio(..) => {
#[cfg(feature = "gecko")]
{
if static_prefs::pref!("layout.css.aspect-ratio-number.enabled") {
let a = NonNegativeNumber::parse(context, input)?.0.get();
let b = match input.try_parse(|input| input.expect_delim('/')) {
Ok(()) => NonNegativeNumber::parse(context, input)?.0.get(),
_ => 1.0,
};
return Ok(MediaExpressionValue::NumberRatio(AspectRatio(a, b)));
}
}
use crate::values::generics::position::Ratio as GenericRatio;
use crate::values::generics::NonNegative;
use crate::values::specified::position::Ratio;
let a = Integer::parse_positive(context, input)?;
input.expect_delim('/')?;
let b = Integer::parse_positive(context, input)?;
MediaExpressionValue::NumberRatio(AspectRatio(
a.value() as CSSFloat,
b.value() as CSSFloat,
let ratio = Ratio::parse(context, input)?;
MediaExpressionValue::NumberRatio(GenericRatio(
NonNegative(ratio.0.get()),
NonNegative(ratio.1.get()),
))
},
Evaluator::Resolution(..) => {