Allow empty keyframe and keyframes with non-animatable properties.

We need to create CSS animations that have empty keyframe or keyframes
which have only invalid properties or non-animatable properties to fire
animation events for such animations.
This commit is contained in:
Hiroyuki Ikezoe 2017-01-23 13:14:24 +09:00
parent 8421ae6077
commit a80725c91b
4 changed files with 67 additions and 31 deletions

View file

@ -266,50 +266,51 @@ fn get_animated_properties(keyframe: &Keyframe) -> Vec<TransitionProperty> {
impl KeyframesAnimation {
/// Create a keyframes animation from a given list of keyframes.
///
/// This will return `None` if the list of keyframes is empty, or there are
/// no animated properties obtained from the keyframes.
/// This will return a keyframe animation with empty steps and
/// properties_changed if the list of keyframes is empty, or there are no
// animated properties obtained from the keyframes.
///
/// Otherwise, this will compute and sort the steps used for the animation,
/// and return the animation object.
pub fn from_keyframes(keyframes: &[Arc<RwLock<Keyframe>>]) -> Option<Self> {
pub fn from_keyframes(keyframes: &[Arc<RwLock<Keyframe>>]) -> Self {
let mut result = KeyframesAnimation {
steps: vec![],
properties_changed: vec![],
};
if keyframes.is_empty() {
return None;
return result;
}
let animated_properties = get_animated_properties(&keyframes[0].read());
if animated_properties.is_empty() {
return None;
result.properties_changed = get_animated_properties(&keyframes[0].read());
if result.properties_changed.is_empty() {
return result;
}
let mut steps = vec![];
for keyframe in keyframes {
let keyframe = keyframe.read();
for percentage in keyframe.selector.0.iter() {
steps.push(KeyframesStep::new(*percentage, KeyframesStepValue::Declarations {
result.steps.push(KeyframesStep::new(*percentage, KeyframesStepValue::Declarations {
block: keyframe.block.clone(),
}));
}
}
// Sort by the start percentage, so we can easily find a frame.
steps.sort_by_key(|step| step.start_percentage);
result.steps.sort_by_key(|step| step.start_percentage);
// Prepend autogenerated keyframes if appropriate.
if steps[0].start_percentage.0 != 0. {
steps.insert(0, KeyframesStep::new(KeyframePercentage::new(0.),
KeyframesStepValue::ComputedValues));
if result.steps[0].start_percentage.0 != 0. {
result.steps.insert(0, KeyframesStep::new(KeyframePercentage::new(0.),
KeyframesStepValue::ComputedValues));
}
if steps.last().unwrap().start_percentage.0 != 1. {
steps.push(KeyframesStep::new(KeyframePercentage::new(1.),
KeyframesStepValue::ComputedValues));
if result.steps.last().unwrap().start_percentage.0 != 1. {
result.steps.push(KeyframesStep::new(KeyframePercentage::new(1.),
KeyframesStepValue::ComputedValues));
}
Some(KeyframesAnimation {
steps: steps,
properties_changed: animated_properties,
})
result
}
}