mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Use NonNegative more in the border code.
This ended up not being so small of a patch as I'd have thought, since it propagated a bit. But most of it is mechanical. Interesting part is NonNegativeNumberOrPercentage and the actual uses of the NonNegative stuff and during parsing. This looks like it'd fix a few correctness issues during interpolation for all the types except for BorderRadius and co (which handled it manually). I should write tests for those in a different patch. Differential Revision: https://phabricator.services.mozilla.com/D14673
This commit is contained in:
parent
19035590ce
commit
ca1ad003bd
14 changed files with 161 additions and 106 deletions
|
@ -543,6 +543,15 @@ pub enum NumberOrPercentage {
|
|||
Number(Number),
|
||||
}
|
||||
|
||||
impl NumberOrPercentage {
|
||||
fn clamp_to_non_negative(self) -> Self {
|
||||
match self {
|
||||
NumberOrPercentage::Percentage(p) => NumberOrPercentage::Percentage(p.clamp_to_non_negative()),
|
||||
NumberOrPercentage::Number(n) => NumberOrPercentage::Number(n.max(0.)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToComputedValue for specified::NumberOrPercentage {
|
||||
type ComputedValue = NumberOrPercentage;
|
||||
|
||||
|
@ -572,6 +581,31 @@ impl ToComputedValue for specified::NumberOrPercentage {
|
|||
}
|
||||
}
|
||||
|
||||
/// A non-negative <number-percentage>.
|
||||
pub type NonNegativeNumberOrPercentage = NonNegative<NumberOrPercentage>;
|
||||
|
||||
impl NonNegativeNumberOrPercentage {
|
||||
/// Returns the `100%` value.
|
||||
#[inline]
|
||||
pub fn hundred_percent() -> Self {
|
||||
NonNegative(NumberOrPercentage::Percentage(Percentage::hundred()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for NonNegativeNumberOrPercentage {
|
||||
type AnimatedValue = NumberOrPercentage;
|
||||
|
||||
#[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())
|
||||
}
|
||||
}
|
||||
|
||||
/// A type used for opacity.
|
||||
pub type Opacity = CSSFloat;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue