Skip to content

Commit

Permalink
Auto merge of #18609 - Manishearth:fs-anim, r=emilio
Browse files Browse the repository at this point in the history
stylo: Animate font-size as NonNegativeLength

Otherwise it doesn't clamp correctly and fails layout/style/test/test_transitions_per_property.html

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18609)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Sep 24, 2017
2 parents 35aad08 + b238eae commit 216f64e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/style/properties/longhand/font.mako.rs
Expand Up @@ -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;
Expand Down
24 changes: 23 additions & 1 deletion components/style/values/computed/font.rs
Expand Up @@ -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))]
Expand Down Expand Up @@ -74,3 +75,24 @@ impl ToCss for FontSize {
self.size.to_css(dest)
}
}

/// XXXManishearth it might be better to
/// animate this as computed, however this complicates
/// clamping and might not be the right thing to do.
/// We should figure it out.
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,
}
}
}
10 changes: 10 additions & 0 deletions components/style/values/computed/length.rs
Expand Up @@ -791,6 +791,16 @@ impl NonNegativeLength {
self.0.px()
}

#[inline]
/// Ensures it is non negative
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.
Expand Down

0 comments on commit 216f64e

Please sign in to comment.