mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Let aspect-ratio (css-sizing-4) support 'auto | <ratio>'.
In order to test its parsing and serialization, we expose it but protect it behind a pref. Besides, I would like to drop layout.css.aspect-ratio-number.enabled in the next patch because the spec has been updated. It seems we don't have to keep this pref and we should always use Number. Differential Revision: https://phabricator.services.mozilla.com/D74955
This commit is contained in:
parent
bd23e05c47
commit
fc9321bb23
8 changed files with 185 additions and 18 deletions
|
@ -12,13 +12,14 @@ use crate::selector_map::PrecomputedHashMap;
|
|||
use crate::str::HTML_SPACE_CHARACTERS;
|
||||
use crate::values::computed::LengthPercentage as ComputedLengthPercentage;
|
||||
use crate::values::computed::{Context, Percentage, ToComputedValue};
|
||||
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;
|
||||
use crate::values::specified::{AllowQuirks, Integer, LengthPercentage};
|
||||
use crate::Atom;
|
||||
use crate::Zero;
|
||||
use crate::values::specified::{AllowQuirks, Integer, LengthPercentage, NonNegativeNumber};
|
||||
use crate::{Atom, One, Zero};
|
||||
use cssparser::Parser;
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
use servo_arc::Arc;
|
||||
|
@ -877,3 +878,46 @@ impl GridTemplateAreas {
|
|||
|
||||
/// A specified value for the `z-index` property.
|
||||
pub type ZIndex = GenericZIndex<Integer>;
|
||||
|
||||
/// A specified value for the `aspect-ratio` property.
|
||||
pub type AspectRatio = GenericAspectRatio<NonNegativeNumber>;
|
||||
|
||||
// FIXME: Add field_bound for parse custom derive, so we can drop this.
|
||||
impl Parse for AspectRatio {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("auto"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(AspectRatio::Auto);
|
||||
}
|
||||
|
||||
GenericRatio::parse(context, input).map(AspectRatio::Ratio)
|
||||
}
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-values-4/#ratios
|
||||
impl Parse for GenericRatio<NonNegativeNumber> {
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let a = NonNegativeNumber::parse(context, input)?;
|
||||
let b = match input.try_parse(|input| input.expect_delim('/')) {
|
||||
Ok(()) => NonNegativeNumber::parse(context, input)?,
|
||||
_ => One::one(),
|
||||
};
|
||||
|
||||
// The computed value of a <ratio> is the pair of numbers provided, unless
|
||||
// both numbers are zero, in which case the computed value is the pair (1, 0)
|
||||
// (same as 1 / 0).
|
||||
// https://drafts.csswg.org/css-values-4/#ratios
|
||||
if a.is_zero() && b.is_zero() {
|
||||
return Ok(GenericRatio(One::one(), Zero::zero()));
|
||||
}
|
||||
return Ok(GenericRatio(a, b));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue