Auto merge of #25033 - servo:intrinsic, r=nox

Add support for inline-block and for computing min/max-content
This commit is contained in:
bors-servo 2019-12-04 16:23:33 -05:00 committed by GitHub
commit e70397d90a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 823 additions and 272 deletions

View file

@ -170,6 +170,12 @@ impl LengthPercentage {
self.length
}
/// Returns the percentage component of this `calc()`
#[inline]
pub fn percentage_component(&self) -> Percentage {
Percentage(self.clamping_mode.clamp(self.percentage.0))
}
/// Return the percentage value as CSSFloat.
#[inline]
pub fn percentage(&self) -> CSSFloat {
@ -186,6 +192,16 @@ impl LengthPercentage {
}
}
/// Returns the length component if this could be represented as a
/// non-calc length.
pub fn as_length(&self) -> Option<Length> {
if !self.has_percentage {
Some(self.length_component())
} else {
None
}
}
/// Returns the percentage component if this could be represented as a
/// non-calc percentage.
pub fn as_percentage(&self) -> Option<Percentage> {

View file

@ -64,6 +64,12 @@ impl Zero for Percentage {
}
}
impl std::ops::AddAssign for Percentage {
fn add_assign(&mut self, other: Self) {
self.0 += other.0
}
}
impl ToCss for Percentage {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where

View file

@ -92,7 +92,7 @@ where
}
/// Maps the length of this value.
pub fn map(&self, f: impl FnOnce(LengthPercentage) -> LengthPercentage) -> Self {
pub fn map<T>(&self, f: impl FnOnce(LengthPercentage) -> T) -> LengthPercentageOrAuto<T> {
match self {
LengthPercentageOrAuto::LengthPercentage(l) => {
LengthPercentageOrAuto::LengthPercentage(f(l.clone()))