Introduce CalcLengthOrPercentage::unclamped_length

This is necessary for some operations, notably converting this to something
suitable for gecko.
This commit is contained in:
Anthony Ramine 2017-05-18 19:18:00 +02:00
parent bcf1a6c5e5
commit 307dd74ecf
9 changed files with 32 additions and 20 deletions

View file

@ -88,12 +88,21 @@ impl CalcLengthOrPercentage {
}
}
/// Returns this `calc()` as a `<length>`.
///
/// Panics in debug mode if a percentage is present in the expression.
#[inline]
#[allow(missing_docs)]
pub fn length(&self) -> Au {
debug_assert!(self.percentage.is_none());
self.clamping_mode.clamp(self.length)
}
/// Returns the `<length>` component of this `calc()`, unclamped.
#[inline]
pub fn unclamped_length(&self) -> Au {
self.length
}
#[inline]
#[allow(missing_docs)]
pub fn percentage(&self) -> CSSFloat {
@ -245,7 +254,7 @@ impl LengthOrPercentage {
match *self {
Length(l) => (l, NotNaN::new(0.0).unwrap()),
Percentage(p) => (Au(0), NotNaN::new(p).unwrap()),
Calc(c) => (c.length(), NotNaN::new(c.percentage()).unwrap()),
Calc(c) => (c.unclamped_length(), NotNaN::new(c.percentage()).unwrap()),
}
}