style: Don't incorrectly clamp values in calc that might not be only lengths.

Expressions with percentages may be negative or positive at computed value time.

So, we can only clamp lengths at computed value time, which is what the other
browsers do.
This commit is contained in:
Emilio Cobos Álvarez 2016-09-01 11:42:30 -07:00
parent fbf77e40fe
commit d02c5b0281
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
12 changed files with 97 additions and 48 deletions

View file

@ -63,6 +63,8 @@ macro_rules! __define_css_keyword_enum__actual {
pub mod specified {
use app_units::Au;
#[repr(u8)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@ -79,5 +81,14 @@ pub mod specified {
AllowedNumericType::NonNegative => value >= 0.,
}
}
#[inline]
pub fn clamp(&self, val: Au) -> Au {
use std::cmp;
match *self {
AllowedNumericType::All => val,
AllowedNumericType::NonNegative => cmp::max(Au(0), val),
}
}
}
}