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

@ -12,9 +12,11 @@ use crate::values::generics::position::AspectRatio as GenericAspectRatio;
use crate::values::generics::position::Position as GenericPosition;
use crate::values::generics::position::PositionComponent as GenericPositionComponent;
use crate::values::generics::position::PositionOrAuto as GenericPositionOrAuto;
use crate::values::generics::position::Ratio as GenericRatio;
use crate::values::generics::position::ZIndex as GenericZIndex;
pub use crate::values::specified::position::{GridAutoFlow, GridTemplateAreas, MasonryAutoFlow};
use crate::Zero;
use std::cmp::{Ordering, PartialOrd};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@ -70,5 +72,24 @@ impl GenericPositionComponent for LengthPercentage {
/// A computed value for the `z-index` property.
pub type ZIndex = GenericZIndex<Integer>;
/// A computed <ratio> value.
pub type Ratio = GenericRatio<NonNegativeNumber>;
impl PartialOrd for Ratio {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
f64::partial_cmp(
&((self.0).0 as f64 * (other.1).0 as f64),
&((self.1).0 as f64 * (other.0).0 as f64),
)
}
}
impl Ratio {
/// Returns a new Ratio.
pub fn new(a: f32, b: f32) -> Self {
GenericRatio(a.into(), b.into())
}
}
/// A computed value for the `aspect-ratio` property.
pub type AspectRatio = GenericAspectRatio<NonNegativeNumber>;

View file

@ -156,7 +156,6 @@ impl<Integer> ZIndex<Integer> {
}
/// A generic value for the `<ratio>` value.
// FIXME: Use this for aspect-ratio in both css-sizing-4 and media-queries in the following patch.
#[derive(
Animate,
Clone,

View file

@ -383,7 +383,7 @@ impl One for NonNegativeNumber {
#[inline]
fn is_one(&self) -> bool {
self.0.get() == 1.0
self.get() == 1.0
}
}
@ -392,6 +392,12 @@ impl NonNegativeNumber {
pub fn new(val: CSSFloat) -> Self {
NonNegative::<Number>(Number::new(val.max(0.)))
}
/// Returns the numeric value.
#[inline]
pub fn get(&self) -> f32 {
self.0.get()
}
}
/// A Number which is >= 1.0.

View file

@ -899,8 +899,11 @@ impl Parse for AspectRatio {
}
}
/// A specified value for the `aspect-ratio` property.
pub type Ratio = GenericRatio<NonNegativeNumber>;
// https://drafts.csswg.org/css-values-4/#ratios
impl Parse for GenericRatio<NonNegativeNumber> {
impl Parse for Ratio {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,