From b37f270c650e193e5cc2a6dbde346c0ffc877111 Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Fri, 21 Jul 2017 13:01:56 +0800 Subject: [PATCH] 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 --- .../style/properties/longhand/border.mako.rs | 2 +- .../style/properties/longhand/outline.mako.rs | 2 +- components/style/values/animated/mod.rs | 25 +++++++++++++------ components/style/values/computed/length.rs | 14 +++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/components/style/properties/longhand/border.mako.rs b/components/style/properties/longhand/border.mako.rs index d9a24263d55..db5fd47b2bd 100644 --- a/components/style/properties/longhand/border.mako.rs +++ b/components/style/properties/longhand/border.mako.rs @@ -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 diff --git a/components/style/properties/longhand/outline.mako.rs b/components/style/properties/longhand/outline.mako.rs index 0b5957d8814..f08537f6545 100644 --- a/components/style/properties/longhand/outline.mako.rs +++ b/components/style/properties/longhand/outline.mako.rs @@ -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 diff --git a/components/style/values/animated/mod.rs b/components/style/values/animated/mod.rs index 05e828d785f..6a3ef1d1f4b 100644 --- a/components/style/values/animated/mod.rs +++ b/components/style/values/animated/mod.rs @@ -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()) } } diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 292292f93d6..4ebd9dc3ea7 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -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 {