mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Make animation functions as generic as possible.
This commit is contained in:
parent
058bfb39ae
commit
f389cf61c4
2 changed files with 14 additions and 12 deletions
|
@ -51,10 +51,10 @@ impl PropertyAnimation {
|
|||
/// 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
|
||||
/// one (for a single transition property) to arbitrarily many (for `all`).
|
||||
pub fn from_transition(transition_index: usize,
|
||||
old_style: &ServoComputedValues,
|
||||
new_style: &mut ServoComputedValues)
|
||||
-> Vec<PropertyAnimation> {
|
||||
pub fn from_transition<C: ComputedValues>(transition_index: usize,
|
||||
old_style: &C,
|
||||
new_style: &mut C)
|
||||
-> Vec<PropertyAnimation> {
|
||||
let mut result = vec![];
|
||||
let box_style = new_style.as_servo().get_box();
|
||||
let transition_property = box_style.transition_property.0[transition_index];
|
||||
|
@ -88,12 +88,12 @@ impl PropertyAnimation {
|
|||
result
|
||||
}
|
||||
|
||||
fn from_transition_property(transition_property: TransitionProperty,
|
||||
timing_function: TransitionTimingFunction,
|
||||
duration: Time,
|
||||
old_style: &ServoComputedValues,
|
||||
new_style: &ServoComputedValues)
|
||||
-> Option<PropertyAnimation> {
|
||||
fn from_transition_property<C: ComputedValues>(transition_property: TransitionProperty,
|
||||
timing_function: TransitionTimingFunction,
|
||||
duration: Time,
|
||||
old_style: &C,
|
||||
new_style: &C)
|
||||
-> Option<PropertyAnimation> {
|
||||
let animated_property = AnimatedProperty::from_transition_property(&transition_property,
|
||||
old_style,
|
||||
new_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 {
|
||||
TransitionTimingFunction::CubicBezier(p1, p2) => {
|
||||
// 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());
|
||||
for property_animation in property_animations {
|
||||
// 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.
|
||||
let now = time::precise_time_s();
|
||||
|
|
|
@ -121,6 +121,7 @@ pub struct KeyframesStep {
|
|||
}
|
||||
|
||||
impl KeyframesStep {
|
||||
#[inline]
|
||||
fn new(percentage: KeyframePercentage,
|
||||
declarations: Arc<Vec<PropertyDeclaration>>) -> Self {
|
||||
KeyframesStep {
|
||||
|
@ -156,6 +157,7 @@ fn get_animated_properties(keyframe: &Keyframe) -> Vec<TransitionProperty> {
|
|||
ret.push(property);
|
||||
}
|
||||
}
|
||||
|
||||
ret
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue