style: Serialize a 0/0 ratio as 0/0 in all value stages.

Based on the update of github.com/w3c/csswg-drafts/issues/5084,
a 0/0 ratio will serialize as 0/0 in all value stages.

Differential Revision: https://phabricator.services.mozilla.com/D93182
This commit is contained in:
Boris Chiou 2020-10-12 15:05:46 +00:00 committed by Emilio Cobos Álvarez
parent 436632f378
commit 61685ca9b3
3 changed files with 17 additions and 10 deletions

View file

@ -15,7 +15,7 @@ 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 crate::{One, Zero};
use std::cmp::{Ordering, PartialOrd};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ToCss};
@ -89,6 +89,16 @@ impl 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.