mirror of
https://github.com/servo/servo.git
synced 2025-10-04 02:29:12 +01:00
style: Share computed animation-iteration-count representation between Servo and Gecko
This removes the special AnimationIterationCount -> f32 conversion from gecko.mako.rs which will be useful to simplify coordinated properties. Differential Revision: https://phabricator.services.mozilla.com/D167123
This commit is contained in:
parent
fa297196ef
commit
b96f8f748c
5 changed files with 67 additions and 73 deletions
|
@ -6,8 +6,7 @@
|
|||
|
||||
use crate::values::animated::{Animate, Procedure};
|
||||
use crate::values::computed::length::{LengthPercentage, NonNegativeLength};
|
||||
use crate::values::computed::{Context, Integer, Number, ToComputedValue};
|
||||
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
|
||||
use crate::values::computed::{Context, Integer, ToComputedValue};
|
||||
use crate::values::generics::box_::{
|
||||
GenericContainIntrinsicSize, GenericLineClamp, GenericPerspective, GenericVerticalAlign,
|
||||
};
|
||||
|
@ -22,11 +21,59 @@ pub use crate::values::specified::box_::{
|
|||
WillChange,
|
||||
};
|
||||
|
||||
use std::fmt::{self, Write};
|
||||
use style_traits::{ToCss, CssWriter};
|
||||
|
||||
/// A computed value for the `vertical-align` property.
|
||||
pub type VerticalAlign = GenericVerticalAlign<LengthPercentage>;
|
||||
|
||||
/// A computed value for the `animation-iteration-count` property.
|
||||
pub type AnimationIterationCount = GenericAnimationIterationCount<Number>;
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToResolvedValue, ToShmem)]
|
||||
#[repr(C)]
|
||||
pub struct AnimationIterationCount(pub f32);
|
||||
|
||||
impl ToComputedValue for specified::AnimationIterationCount {
|
||||
type ComputedValue = AnimationIterationCount;
|
||||
|
||||
#[inline]
|
||||
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
||||
AnimationIterationCount(match *self {
|
||||
specified::AnimationIterationCount::Number(n) => n.to_computed_value(context).0,
|
||||
specified::AnimationIterationCount::Infinite => std::f32::INFINITY,
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
||||
use crate::values::specified::NonNegativeNumber;
|
||||
if computed.0.is_infinite() {
|
||||
specified::AnimationIterationCount::Infinite
|
||||
} else {
|
||||
specified::AnimationIterationCount::Number(NonNegativeNumber::new(computed.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AnimationIterationCount {
|
||||
/// Returns the value `1.0`.
|
||||
#[inline]
|
||||
pub fn one() -> Self {
|
||||
Self(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for AnimationIterationCount {
|
||||
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
||||
where
|
||||
W: Write,
|
||||
{
|
||||
if self.0.is_infinite() {
|
||||
dest.write_str("infinite")
|
||||
} else {
|
||||
self.0.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A computed value for the `contain-intrinsic-size` property.
|
||||
pub type ContainIntrinsicSize = GenericContainIntrinsicSize<NonNegativeLength>;
|
||||
|
@ -47,14 +94,6 @@ impl Animate for LineClamp {
|
|||
}
|
||||
}
|
||||
|
||||
impl AnimationIterationCount {
|
||||
/// Returns the value `1.0`.
|
||||
#[inline]
|
||||
pub fn one() -> Self {
|
||||
GenericAnimationIterationCount::Number(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
/// A computed value for the `perspective` property.
|
||||
pub type Perspective = GenericPerspective<NonNegativeLength>;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue