diff options
4 files changed, 34 insertions, 4 deletions
diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 0c629df19f5..e601f27c01e 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -1099,9 +1099,14 @@ /// Returns a value representing a `0` length. pub fn zero() -> Self { - use values::specified::length::{LengthOrPercentageOrAuto, NoCalcLength}; - SpecifiedValue(MozLength::LengthOrPercentageOrAuto( - LengthOrPercentageOrAuto::Length(NoCalcLength::zero()))) + use values::specified::length::LengthOrPercentageOrAuto; + SpecifiedValue(MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::zero())) + } + + /// Returns a value representing a `0%` length. + pub fn zero_percent() -> Self { + use values::specified::length::LengthOrPercentageOrAuto; + SpecifiedValue(MozLength::LengthOrPercentageOrAuto(LengthOrPercentageOrAuto::zero_percent())) } } % endif diff --git a/components/style/properties/shorthand/position.mako.rs b/components/style/properties/shorthand/position.mako.rs index 94158701ac6..65586ab1ec2 100644 --- a/components/style/properties/shorthand/position.mako.rs +++ b/components/style/properties/shorthand/position.mako.rs @@ -92,7 +92,11 @@ Ok(expanded! { flex_grow: grow.unwrap_or(Number::new(1.0)), flex_shrink: shrink.unwrap_or(Number::new(1.0)), - flex_basis: basis.unwrap_or(longhands::flex_basis::SpecifiedValue::zero()), + // Per spec, this should be SpecifiedValue::zero(), but all + // browsers currently agree on using `0%`. This is a spec + // change which hasn't been adopted by browsers: + // https://github.com/w3c/csswg-drafts/commit/2c446befdf0f686217905bdd7c92409f6bd3921b + flex_basis: basis.unwrap_or(longhands::flex_basis::SpecifiedValue::zero_percent()), }) } diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 1311b7c7404..6273fec31fd 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -735,6 +735,12 @@ impl Percentage { Self::parse_with_clamping_mode(input, AllowedNumericType::NonNegative) } + /// 0% + #[inline] + pub fn zero() -> Self { + Percentage(0.) + } + /// 100% #[inline] pub fn hundred() -> Self { @@ -999,6 +1005,11 @@ impl LengthOrPercentageOrAuto { pub fn zero() -> Self { LengthOrPercentageOrAuto::Length(NoCalcLength::zero()) } + + /// Returns a value representing `0%`. + pub fn zero_percent() -> Self { + LengthOrPercentageOrAuto::Percentage(Percentage::zero()) + } } impl Parse for LengthOrPercentageOrAuto { @@ -1157,6 +1168,11 @@ impl LengthOrPercentageOrAutoOrContent { pub fn zero() -> Self { LengthOrPercentageOrAutoOrContent::Length(NoCalcLength::zero()) } + + /// Returns a value representing `0%`. + pub fn zero_percent() -> Self { + LengthOrPercentageOrAutoOrContent::Percentage(Percentage::zero()) + } } impl ToCss for LengthOrPercentageOrAutoOrContent { diff --git a/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-shorthand-number.htm.ini b/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-shorthand-number.htm.ini new file mode 100644 index 00000000000..13b8a30d711 --- /dev/null +++ b/tests/wpt/metadata-css/css-flexbox-1_dev/html/flexbox_computedstyle_flex-shorthand-number.htm.ini @@ -0,0 +1,5 @@ +[flexbox_computedstyle_flex-shorthand-number.htm] + type: testharness + [flexbox | computed style | flex: number] + expected: FAIL + |