Skip to content

Commit

Permalink
Set flex-basis to 0% when omitted in flex shorthand.
Browse files Browse the repository at this point in the history
  • Loading branch information
upsuper committed May 29, 2017
1 parent aca0943 commit acb7242
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
11 changes: 8 additions & 3 deletions components/style/properties/helpers.mako.rs
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion components/style/properties/shorthand/position.mako.rs
Expand Up @@ -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()),
})
}

Expand Down
16 changes: 16 additions & 0 deletions components/style/values/specified/length.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
@@ -0,0 +1,5 @@
[flexbox_computedstyle_flex-shorthand-number.htm]
type: testharness
[flexbox | computed style | flex: number]
expected: FAIL

0 comments on commit acb7242

Please sign in to comment.