diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-29 17:58:44 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-29 17:58:44 -0500 |
commit | 76daf462956a50c3348b6dac516d5f013355a88b (patch) | |
tree | c2ccdb49a03f4430021ec8ea32bdb1abb8b5ddb0 | |
parent | 939716a7bc2ba2fbd8dcfe8b64d2f61edfa99c95 (diff) | |
parent | acb7242304f1d31dd54c1566db696aa1ffb8e042 (diff) | |
download | servo-76daf462956a50c3348b6dac516d5f013355a88b.tar.gz servo-76daf462956a50c3348b6dac516d5f013355a88b.zip |
Auto merge of #17073 - upsuper:flex-basis-zero, r=emilio
Set flex-basis to 0% when omitted in flex shorthand.
This should fix [bug 1331530](https://bugzilla.mozilla.org/show_bug.cgi?id=1331530).
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/17073)
<!-- Reviewable:end -->
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 + |