mirror of
https://github.com/servo/servo.git
synced 2025-08-12 00:45:33 +01:00
style: Clamp to non-negative value after doing interpolation for circle(), ellipse(), and inset().
Replace LengthOrPercentage with NonNegativeLengthOrPercentage on ShapeRadius, Circle, Ellipse. And derive ToAnimatedValue for ShapeSource and its related types, so we clamp its interpolated results into non-negative values. (i.e. The radius of circle()/ellipse() and the border-radius of inset().) Note: We may get negative values when using a negative easing function, so the clamp is necessary to avoid the incorrect result or any undefined behavior. Differential Revision: https://phabricator.services.mozilla.com/D14654
This commit is contained in:
parent
627559546d
commit
f0f3eb3194
10 changed files with 110 additions and 27 deletions
|
@ -32,19 +32,26 @@ pub type ClippingShape = generic::ClippingShape<BasicShape, SpecifiedUrl>;
|
|||
pub type FloatAreaShape = generic::FloatAreaShape<BasicShape, Image>;
|
||||
|
||||
/// A specified basic shape.
|
||||
pub type BasicShape = generic::BasicShape<HorizontalPosition, VerticalPosition, LengthOrPercentage, NonNegativeLengthOrPercentage>;
|
||||
pub type BasicShape = generic::BasicShape<
|
||||
HorizontalPosition,
|
||||
VerticalPosition,
|
||||
LengthOrPercentage,
|
||||
NonNegativeLengthOrPercentage,
|
||||
>;
|
||||
|
||||
/// The specified value of `inset()`
|
||||
pub type InsetRect = generic::InsetRect<LengthOrPercentage, NonNegativeLengthOrPercentage>;
|
||||
|
||||
/// A specified circle.
|
||||
pub type Circle = generic::Circle<HorizontalPosition, VerticalPosition, LengthOrPercentage>;
|
||||
pub type Circle =
|
||||
generic::Circle<HorizontalPosition, VerticalPosition, NonNegativeLengthOrPercentage>;
|
||||
|
||||
/// A specified ellipse.
|
||||
pub type Ellipse = generic::Ellipse<HorizontalPosition, VerticalPosition, LengthOrPercentage>;
|
||||
pub type Ellipse =
|
||||
generic::Ellipse<HorizontalPosition, VerticalPosition, NonNegativeLengthOrPercentage>;
|
||||
|
||||
/// The specified value of `ShapeRadius`
|
||||
pub type ShapeRadius = generic::ShapeRadius<LengthOrPercentage>;
|
||||
pub type ShapeRadius = generic::ShapeRadius<NonNegativeLengthOrPercentage>;
|
||||
|
||||
/// The specified value of `Polygon`
|
||||
pub type Polygon = generic::Polygon<LengthOrPercentage>;
|
||||
|
@ -309,7 +316,7 @@ impl Parse for ShapeRadius {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(lop) = input.try(|i| LengthOrPercentage::parse_non_negative(context, i)) {
|
||||
if let Ok(lop) = input.try(|i| NonNegativeLengthOrPercentage::parse(context, i)) {
|
||||
return Ok(generic::ShapeRadius::Length(lop));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue