style: Cleanup the animated value setup.

We have three different enums to represent slightly different things. Reuse them
properly, and kill some code in the animated_properties module while at it.

MozReview-Commit-ID: 5ZAly8f4lWy
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
This commit is contained in:
Emilio Cobos Álvarez 2017-09-23 14:22:55 +02:00
parent 0212c5d230
commit 3215e36b5b
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
12 changed files with 571 additions and 689 deletions

View file

@ -10,8 +10,8 @@ use bezier::Bezier;
use context::SharedStyleContext;
use dom::OpaqueNode;
use font_metrics::FontMetricsProvider;
use properties::{self, CascadeFlags, ComputedValues};
use properties::animated_properties::{AnimatableLonghand, AnimatedProperty, TransitionProperty};
use properties::{self, CascadeFlags, ComputedValues, LonghandId};
use properties::animated_properties::{AnimatedProperty, TransitionProperty};
use properties::longhands::animation_direction::computed_value::single_value::T as AnimationDirection;
use properties::longhands::animation_iteration_count::single_value::computed_value::T as AnimationIterationCount;
use properties::longhands::animation_play_state::computed_value::single_value::T as AnimationPlayState;
@ -271,87 +271,80 @@ impl PropertyAnimation {
/// 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: &ComputedValues,
new_style: &mut ComputedValues)
-> Vec<PropertyAnimation> {
pub fn from_transition(
transition_index: usize,
old_style: &ComputedValues,
new_style: &mut ComputedValues,
) -> Vec<PropertyAnimation> {
let mut result = vec![];
let box_style = new_style.get_box();
let transition_property = box_style.transition_property_at(transition_index);
let timing_function = box_style.transition_timing_function_mod(transition_index);
let duration = box_style.transition_duration_mod(transition_index);
if let TransitionProperty::Unsupported(_) = transition_property {
return result
}
if transition_property.is_shorthand() {
return transition_property.longhands().iter().filter_map(|transition_property| {
PropertyAnimation::from_transition_property(transition_property,
timing_function,
duration,
old_style,
new_style)
}).collect();
}
if transition_property != TransitionProperty::All {
if let Some(property_animation) =
PropertyAnimation::from_transition_property(&transition_property,
timing_function,
duration,
old_style,
new_style) {
result.push(property_animation)
match transition_property {
TransitionProperty::Unsupported(_) => result,
TransitionProperty::Shorthand(ref shorthand_id) => {
shorthand_id.longhands().iter().filter_map(|longhand| {
PropertyAnimation::from_longhand(
&longhand,
timing_function,
duration,
old_style,
new_style,
)
}).collect()
}
return result
}
TransitionProperty::Longhand(ref longhand_id) => {
let animation = PropertyAnimation::from_longhand(
longhand_id,
timing_function,
duration,
old_style,
new_style,
);
TransitionProperty::each(|transition_property| {
if let Some(property_animation) =
PropertyAnimation::from_transition_property(&transition_property,
timing_function,
duration,
old_style,
new_style) {
result.push(property_animation)
if let Some(animation) = animation {
result.push(animation);
}
result
}
});
TransitionProperty::All => {
TransitionProperty::each(|longhand_id| {
let animation = PropertyAnimation::from_longhand(
longhand_id,
timing_function,
duration,
old_style,
new_style,
);
result
if let Some(animation) = animation {
result.push(animation);
}
});
result
}
}
}
fn from_transition_property(transition_property: &TransitionProperty,
timing_function: TimingFunction,
duration: Time,
old_style: &ComputedValues,
new_style: &ComputedValues)
-> Option<PropertyAnimation> {
debug_assert!(!transition_property.is_shorthand() &&
transition_property != &TransitionProperty::All);
fn from_longhand(
longhand: &LonghandId,
timing_function: TimingFunction,
duration: Time,
old_style: &ComputedValues,
new_style: &ComputedValues,
) -> Option<PropertyAnimation> {
let animated_property = AnimatedProperty::from_longhand(
longhand,
old_style,
new_style,
);
// We're not expecting |transition_property| to be a shorthand (including 'all') and
// all other transitionable properties should be animatable longhands (since transitionable
// is a subset of animatable).
let animatable_longhand =
AnimatableLonghand::from_transition_property(transition_property).unwrap();
PropertyAnimation::from_animatable_longhand(&animatable_longhand,
timing_function,
duration,
old_style,
new_style)
}
fn from_animatable_longhand(animatable_longhand: &AnimatableLonghand,
timing_function: TimingFunction,
duration: Time,
old_style: &ComputedValues,
new_style: &ComputedValues)
-> Option<PropertyAnimation> {
let animated_property = AnimatedProperty::from_animatable_longhand(animatable_longhand,
old_style,
new_style);
let animated_property = match animated_property {
Some(p) => p,
None => return None,
};
let property_animation = PropertyAnimation {
property: animated_property,
@ -758,14 +751,18 @@ pub fn update_style_for_animation(context: &SharedStyleContext,
let mut new_style = (*style).clone();
for property in &animation.properties_changed {
for property in animation.properties_changed.iter() {
debug!("update_style_for_animation: scanning prop {:?} for animation \"{}\"",
property, name);
match PropertyAnimation::from_animatable_longhand(property,
timing_function,
Time::from_seconds(relative_duration as f32),
&from_style,
&target_style) {
let animation = PropertyAnimation::from_longhand(
&property,
timing_function,
Time::from_seconds(relative_duration as f32),
&from_style,
&target_style
);
match animation {
Some(property_animation) => {
debug!("update_style_for_animation: got property animation for prop {:?}", property);
debug!("update_style_for_animation: {:?}", property_animation);