mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01: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,
|
spec="https://drafts.csswg.org/css-backgrounds/#border-%s-radius" % corner,
|
||||||
boxed=True,
|
boxed=True,
|
||||||
flags="APPLIES_TO_FIRST_LETTER",
|
flags="APPLIES_TO_FIRST_LETTER",
|
||||||
animation_value_type="ComputedValue")}
|
animation_value_type="BorderCornerRadius")}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
/// -moz-border-*-colors: color, string, enum, none, inherit/initial
|
/// -moz-border-*-colors: color, string, enum, none, inherit/initial
|
||||||
|
|
|
@ -76,7 +76,7 @@ ${helpers.predefined_type("outline-width",
|
||||||
"computed::LengthOrPercentage::zero().into()",
|
"computed::LengthOrPercentage::zero().into()",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
boxed=True,
|
boxed=True,
|
||||||
animation_value_type="ComputedValue",
|
animation_value_type="BorderCornerRadius",
|
||||||
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-outline-radius)")}
|
spec="Nonstandard (https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-outline-radius)")}
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use values::computed::Angle as ComputedAngle;
|
use values::computed::Angle as ComputedAngle;
|
||||||
|
use values::computed::BorderCornerRadius as ComputedBorderCornerRadius;
|
||||||
use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
|
use values::computed::GreaterThanOrEqualToOneNumber as ComputedGreaterThanOrEqualToOneNumber;
|
||||||
use values::computed::NonNegativeAu;
|
use values::computed::NonNegativeAu;
|
||||||
use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
|
use values::computed::NonNegativeLengthOrPercentage as ComputedNonNegativeLengthOrPercentage;
|
||||||
|
@ -160,14 +161,22 @@ impl ToAnimatedValue for ComputedNonNegativeLengthOrPercentage {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
fn from_animated_value(animated: Self::AnimatedValue) -> Self {
|
||||||
use values::computed::{LengthOrPercentage, Percentage};
|
animated.0.clamp_to_non_negative().into()
|
||||||
match animated.0 {
|
}
|
||||||
LengthOrPercentage::Length(au) => LengthOrPercentage::Length(max(au, Au(0))).into(),
|
}
|
||||||
LengthOrPercentage::Percentage(percentage) => {
|
|
||||||
LengthOrPercentage::Percentage(Percentage(percentage.0.max(0.))).into()
|
impl ToAnimatedValue for ComputedBorderCornerRadius {
|
||||||
},
|
type AnimatedValue = Self;
|
||||||
_ => animated
|
|
||||||
}
|
#[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 {
|
impl fmt::Debug for LengthOrPercentage {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue