aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2017-09-23 16:22:42 -0700
committerManish Goregaokar <manishsmail@gmail.com>2017-09-23 16:22:42 -0700
commitce7d82e9c49ce84acebcf5e3a28fc74f5b97fead (patch)
tree2bce801415444b6940f2da909e835e96212d0079
parent35aad086191c7c4561067a1f774b3ae2d69bc375 (diff)
downloadservo-ce7d82e9c49ce84acebcf5e3a28fc74f5b97fead.tar.gz
servo-ce7d82e9c49ce84acebcf5e3a28fc74f5b97fead.zip
stylo: Animate font-size as NonNegativeLength
-rw-r--r--components/style/properties/longhand/font.mako.rs2
-rw-r--r--components/style/values/computed/font.rs20
-rw-r--r--components/style/values/computed/length.rs10
3 files changed, 30 insertions, 2 deletions
diff --git a/components/style/properties/longhand/font.mako.rs b/components/style/properties/longhand/font.mako.rs
index 5b7b62be04a..79ab5ff33db 100644
--- a/components/style/properties/longhand/font.mako.rs
+++ b/components/style/properties/longhand/font.mako.rs
@@ -596,7 +596,7 @@ ${helpers.single_keyword_system("font-variant-caps",
}
</%helpers:longhand>
-<%helpers:longhand name="font-size" animation_value_type="ComputedValue"
+<%helpers:longhand name="font-size" animation_value_type="NonNegativeLength"
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER"
allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
use app_units::Au;
diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs
index 5ba0a0e4953..8edca57bda9 100644
--- a/components/style/values/computed/font.rs
+++ b/components/style/values/computed/font.rs
@@ -7,10 +7,11 @@
use app_units::Au;
use std::fmt;
use style_traits::ToCss;
+use values::animated::ToAnimatedValue;
use values::computed::NonNegativeLength;
use values::specified::font as specified;
-#[derive(Animate, ComputeSquaredDistance, ToAnimatedValue, ToAnimatedZero)]
+#[derive(Animate, ComputeSquaredDistance, ToAnimatedZero)]
#[derive(Clone, Copy, Debug, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
@@ -74,3 +75,20 @@ impl ToCss for FontSize {
self.size.to_css(dest)
}
}
+
+impl ToAnimatedValue for FontSize {
+ type AnimatedValue = NonNegativeLength;
+
+ #[inline]
+ fn to_animated_value(self) -> Self::AnimatedValue {
+ self.size
+ }
+
+ #[inline]
+ fn from_animated_value(animated: Self::AnimatedValue) -> Self {
+ FontSize {
+ size: animated.clamp(),
+ keyword_info: None,
+ }
+ }
+}
diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs
index a0d70b45a34..c6cea9429c8 100644
--- a/components/style/values/computed/length.rs
+++ b/components/style/values/computed/length.rs
@@ -791,6 +791,16 @@ impl NonNegativeLength {
self.0.px()
}
+ #[inline]
+ /// Ensures it is positive
+ pub fn clamp(self) -> Self {
+ if (self.0).0 < 0. {
+ Self::zero()
+ } else {
+ self
+ }
+ }
+
/// Scale this NonNegativeLength.
/// We scale NonNegativeLength by zero if the factor is negative because it doesn't
/// make sense to scale a negative factor on a non-negative length.