style: Add support for 'flex-basis:content' in the style system.

Bug: 1105111
Reviewed-by: xidorn
MozReview-Commit-ID: 5WhgHJJ0mDB
This commit is contained in:
Emilio Cobos Álvarez 2018-03-28 23:40:01 -07:00
parent 3532f64b32
commit 744809a8b2
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
13 changed files with 197 additions and 142 deletions

View file

@ -4,8 +4,23 @@
//! Computed types for CSS values related to flexbox.
use values::computed::length::LengthOrPercentage;
use values::generics::flex::FlexBasis as GenericFlexBasis;
/// The `width` value type.
#[cfg(feature = "servo")]
pub type Width = ::values::computed::NonNegativeLengthOrPercentageOrAuto;
/// The `width` value type.
#[cfg(feature = "gecko")]
pub type Width = ::values::computed::MozLength;
/// A computed value for the `flex-basis` property.
pub type FlexBasis = GenericFlexBasis<LengthOrPercentage>;
pub type FlexBasis = GenericFlexBasis<Width>;
impl FlexBasis {
/// `auto`
#[inline]
pub fn auto() -> Self {
GenericFlexBasis::Width(Width::auto())
}
}

View file

@ -427,10 +427,10 @@ impl LengthOrPercentage {
pub fn clamp_to_non_negative(self) -> Self {
match self {
LengthOrPercentage::Length(length) => {
LengthOrPercentage::Length(Length::new(length.px().max(0.)))
LengthOrPercentage::Length(length.clamp_to_non_negative())
},
LengthOrPercentage::Percentage(percentage) => {
LengthOrPercentage::Percentage(Percentage(percentage.0.max(0.)))
LengthOrPercentage::Percentage(percentage.clamp_to_non_negative())
},
_ => self
}
@ -511,6 +511,31 @@ impl LengthOrPercentageOrAuto {
}
}
/// A wrapper of LengthOrPercentageOrAuto, whose value must be >= 0.
pub type NonNegativeLengthOrPercentageOrAuto = NonNegative<LengthOrPercentageOrAuto>;
impl NonNegativeLengthOrPercentageOrAuto {
/// `auto`
#[inline]
pub fn auto() -> Self {
NonNegative(LengthOrPercentageOrAuto::Auto)
}
}
impl ToAnimatedValue for NonNegativeLengthOrPercentageOrAuto {
type AnimatedValue = LengthOrPercentageOrAuto;
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
self.0
}
#[inline]
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
NonNegative(animated.clamp_to_non_negative())
}
}
impl LengthOrPercentageOrAuto {
/// Returns true if the computed value is absolute 0 or 0%.
///
@ -524,6 +549,15 @@ impl LengthOrPercentageOrAuto {
Calc(_) | Auto => false
}
}
fn clamp_to_non_negative(self) -> Self {
use self::LengthOrPercentageOrAuto::*;
match self {
Length(l) => Length(l.clamp_to_non_negative()),
Percentage(p) => Percentage(p.clamp_to_non_negative()),
_ => self,
}
}
}
impl ToComputedValue for specified::LengthOrPercentageOrAuto {
@ -737,6 +771,11 @@ impl CSSPixelLength {
self.0
}
#[inline]
fn clamp_to_non_negative(self) -> Self {
Self::new(self.px().max(0.))
}
/// Return the length with app_unit i32 type.
#[inline]
pub fn to_i32_au(&self) -> i32 {

View file

@ -60,7 +60,8 @@ pub use super::{Auto, Either, None_};
pub use super::specified::{BorderStyle, TextDecorationLine};
pub use self::length::{CalcLengthOrPercentage, Length, LengthOrNumber, LengthOrPercentage};
pub use self::length::{LengthOrPercentageOrAuto, LengthOrPercentageOrNone, MaxLength, MozLength};
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength, NonNegativeLengthOrPercentage};
pub use self::length::{CSSPixelLength, ExtremumLength, NonNegativeLength};
pub use self::length::{NonNegativeLengthOrPercentage, NonNegativeLengthOrPercentageOrAuto};
pub use self::list::{ListStyleImage, Quotes};
#[cfg(feature = "gecko")]
pub use self::list::ListStyleType;

View file

@ -32,6 +32,12 @@ impl Percentage {
pub fn abs(&self) -> Self {
Percentage(self.0.abs())
}
/// Clamps this percentage to a non-negative percentage.
#[inline]
pub fn clamp_to_non_negative(self) -> Self {
Percentage(self.0.max(0.))
}
}
impl ToCss for Percentage {