mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
stylo: Animate font-size as NonNegativeLength
This commit is contained in:
parent
35aad08619
commit
ce7d82e9c4
3 changed files with 30 additions and 2 deletions
|
@ -596,7 +596,7 @@ ${helpers.single_keyword_system("font-variant-caps",
|
||||||
}
|
}
|
||||||
</%helpers:longhand>
|
</%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"
|
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">
|
allow_quirks="True" spec="https://drafts.csswg.org/css-fonts/#propdef-font-size">
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
use values::animated::ToAnimatedValue;
|
||||||
use values::computed::NonNegativeLength;
|
use values::computed::NonNegativeLength;
|
||||||
use values::specified::font as specified;
|
use values::specified::font as specified;
|
||||||
|
|
||||||
#[derive(Animate, ComputeSquaredDistance, ToAnimatedValue, ToAnimatedZero)]
|
#[derive(Animate, ComputeSquaredDistance, ToAnimatedZero)]
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
#[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
|
||||||
|
@ -74,3 +75,20 @@ impl ToCss for FontSize {
|
||||||
self.size.to_css(dest)
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -791,6 +791,16 @@ impl NonNegativeLength {
|
||||||
self.0.px()
|
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.
|
/// Scale this NonNegativeLength.
|
||||||
/// We scale NonNegativeLength by zero if the factor is negative because it doesn't
|
/// 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.
|
/// make sense to scale a negative factor on a non-negative length.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue