Skip to content

Commit

Permalink
Bug 1374233 - Part 8: Implement ToAnimatedValue for BorderCornerRadius.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BorisChiou committed Aug 4, 2017
1 parent e72a0f1 commit b37f270
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion components/style/properties/longhand/border.mako.rs
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion components/style/properties/longhand/outline.mako.rs
Expand Up @@ -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

Expand Down
25 changes: 17 additions & 8 deletions components/style/values/animated/mod.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
}
}

Expand Down
14 changes: 14 additions & 0 deletions components/style/values/computed/length.rs
Expand Up @@ -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 {
Expand Down

0 comments on commit b37f270

Please sign in to comment.