style: Make animation functions as generic as possible.

This commit is contained in:
Emilio Cobos Álvarez 2016-06-18 15:52:28 +02:00
parent 058bfb39ae
commit f389cf61c4
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 14 additions and 12 deletions

View file

@ -51,9 +51,9 @@ impl PropertyAnimation {
/// Creates a new property animation for the given transition index and old and new styles. /// Creates a new property animation for the given transition index and old and new styles.
/// Any number of animations may be returned, from zero (if the property did not animate) to /// Any number of animations may be returned, from zero (if the property did not animate) to
/// one (for a single transition property) to arbitrarily many (for `all`). /// one (for a single transition property) to arbitrarily many (for `all`).
pub fn from_transition(transition_index: usize, pub fn from_transition<C: ComputedValues>(transition_index: usize,
old_style: &ServoComputedValues, old_style: &C,
new_style: &mut ServoComputedValues) new_style: &mut C)
-> Vec<PropertyAnimation> { -> Vec<PropertyAnimation> {
let mut result = vec![]; let mut result = vec![];
let box_style = new_style.as_servo().get_box(); let box_style = new_style.as_servo().get_box();
@ -88,11 +88,11 @@ impl PropertyAnimation {
result result
} }
fn from_transition_property(transition_property: TransitionProperty, fn from_transition_property<C: ComputedValues>(transition_property: TransitionProperty,
timing_function: TransitionTimingFunction, timing_function: TransitionTimingFunction,
duration: Time, duration: Time,
old_style: &ServoComputedValues, old_style: &C,
new_style: &ServoComputedValues) new_style: &C)
-> Option<PropertyAnimation> { -> Option<PropertyAnimation> {
let animated_property = AnimatedProperty::from_transition_property(&transition_property, let animated_property = AnimatedProperty::from_transition_property(&transition_property,
old_style, old_style,
@ -111,7 +111,7 @@ impl PropertyAnimation {
} }
} }
pub fn update(&self, style: &mut ServoComputedValues, time: f64) { pub fn update<C: ComputedValues>(&self, style: &mut C, time: f64) {
let progress = match self.timing_function { let progress = match self.timing_function {
TransitionTimingFunction::CubicBezier(p1, p2) => { TransitionTimingFunction::CubicBezier(p1, p2) => {
// See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit. // See `WebCore::AnimationBase::solveEpsilon(double)` in WebKit.
@ -167,7 +167,7 @@ pub fn start_transitions_if_applicable<C: ComputedValues>(new_animations_sender:
let property_animations = PropertyAnimation::from_transition(i, old_style.as_servo(), new_style.as_servo_mut()); let property_animations = PropertyAnimation::from_transition(i, old_style.as_servo(), new_style.as_servo_mut());
for property_animation in property_animations { for property_animation in property_animations {
// Set the property to the initial value. // Set the property to the initial value.
property_animation.update(new_style.as_servo_mut(), 0.0); property_animation.update(new_style, 0.0);
// Kick off the animation. // Kick off the animation.
let now = time::precise_time_s(); let now = time::precise_time_s();

View file

@ -121,6 +121,7 @@ pub struct KeyframesStep {
} }
impl KeyframesStep { impl KeyframesStep {
#[inline]
fn new(percentage: KeyframePercentage, fn new(percentage: KeyframePercentage,
declarations: Arc<Vec<PropertyDeclaration>>) -> Self { declarations: Arc<Vec<PropertyDeclaration>>) -> Self {
KeyframesStep { KeyframesStep {
@ -156,6 +157,7 @@ fn get_animated_properties(keyframe: &Keyframe) -> Vec<TransitionProperty> {
ret.push(property); ret.push(property);
} }
} }
ret ret
} }