style: Move Ratio into independent files.

Based on https://drafts.csswg.org/css-values/#ratios, <ratio> should be
a general types in css values, and now the media query and the position use
this type, so let's move it into the independent files.

Differential Revision: https://phabricator.services.mozilla.com/D106218
This commit is contained in:
Boris Chiou 2021-02-25 01:50:55 +00:00 committed by Emilio Cobos Álvarez
parent 35b080e021
commit 52d39fc1bc
12 changed files with 142 additions and 115 deletions

View file

@ -12,11 +12,9 @@ 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::{One, Zero};
use std::cmp::{Ordering, PartialOrd};
use crate::Zero;
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@ -72,34 +70,5 @@ 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())
}
/// Returns the used value. A ratio of 0/0 behaves as the ratio 1/0.
/// https://drafts.csswg.org/css-values-4/#ratios
pub fn used_value(self) -> Self {
if self.0.is_zero() && self.1.is_zero() {
Ratio::new(One::one(), Zero::zero())
} else {
self
}
}
}
/// A computed value for the `aspect-ratio` property.
pub type AspectRatio = GenericAspectRatio<NonNegativeNumber>;