mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Bug 1374233 - Part 8: Implement ToAnimatedValue for BorderCornerRadius.
BorderCornerRadius should always be non-negative, so we can implemennt ToAnimatedValue for it directly, for properties: 1. border-{*}-radius 2. -moz-outline-{*}-radius MozReview-Commit-ID: HEbeHz9Hfkd
This commit is contained in:
parent
e72a0f126e
commit
b37f270c65
4 changed files with 33 additions and 10 deletions
|
@ -62,7 +62,7 @@ ${helpers.gecko_keyword_conversion(Keyword('border-style',
|
|||
spec="https://drafts.csswg.org/css-backgrounds/#border-%s-radius" % corner,
|
||||
boxed=True,
|
||||
flags="APPLIES_TO_FIRST_LETTER",
|
||||
animation_value_type="ComputedValue")}
|
||||
animation_value_type="BorderCornerRadius")}
|
||||
% endfor
|
||||
|
||||
/// -moz-border-*-colors: color, string, enum, none, inherit/initial
|
||||
|
|
|
@ -76,7 +76,7 @@ ${helpers.predefined_type("outline-width",
|
|||
"computed::LengthOrPercentage::zero().into()",
|
||||
products="gecko",
|
||||
boxed=True,
|
||||
animation_value_type="ComputedValue",
|
||||
animation_value_type="BorderCornerRadius",
|
||||
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-outline-radius)")}
|
||||
% endfor
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
use app_units::Au;
|
||||
use std::cmp::max;
|
||||
use values::computed::Angle as ComputedAngle;
|
||||
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
|
||||
use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
|
||||
use values::computed::NonNegativeAu;
|
||||
use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
|
||||
|
@ -160,14 +161,22 @@ impl ToAnimatedValue for ComputedNonNegativeLengthOrPercentage {
|
|||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
use values::computed::{LengthOrPercentage, Percentage};
|
||||
match animated.0 {
|
||||
LengthOrPercentage::Length(au) => LengthOrPercentage::Length(max(au, Au(0))).into(),
|
||||
LengthOrPercentage::Percentage(percentage) => {
|
||||
LengthOrPercentage::Percentage(Percentage(percentage.0.max(0.))).into()
|
||||
},
|
||||
_ => animated
|
||||
}
|
||||
animated.0.clamp_to_non_negative().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl ToAnimatedValue for ComputedBorderCornerRadius {
|
||||
type AnimatedValue = Self;
|
||||
|
||||
#[inline]
|
||||
fn to_animated_value(self) -> Self {
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||
ComputedBorderCornerRadius::new(animated.0.width.clamp_to_non_negative(),
|
||||
animated.0.height.clamp_to_non_negative())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -351,6 +351,20 @@ impl LengthOrPercentage {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the clamped non-negative values.
|
||||
#[inline]
|
||||
pub fn clamp_to_non_negative(self) -> Self {
|
||||
match self {
|
||||
LengthOrPercentage::Length(length) => {
|
||||
LengthOrPercentage::Length(Au(::std::cmp::max(length.0, 0)))
|
||||
},
|
||||
LengthOrPercentage::Percentage(percentage) => {
|
||||
LengthOrPercentage::Percentage(Percentage(percentage.0.max(0.)))
|
||||
},
|
||||
_ => self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for LengthOrPercentage {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue