Emit TransitionEnd events in the layout thread and process it in the script thread

This commit is contained in:
Keith Yeung 2016-09-03 07:27:39 -07:00
parent 752c6e6019
commit 668163ec5c
21 changed files with 103 additions and 62 deletions

View file

@ -10,7 +10,7 @@ use gfx::display_list::OpaqueNode;
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use script_layout_interface::restyle_damage::RestyleDamage;
use script_traits::{AnimationState, LayoutMsg as ConstellationMsg};
use script_traits::{AnimationState, ConstellationControlMsg, LayoutMsg as ConstellationMsg};
use std::collections::HashMap;
use std::sync::mpsc::Receiver;
use style::animation::{Animation, update_style_for_animation};
@ -21,6 +21,7 @@ use style::timer::Timer;
/// Also expire any old animations that have completed, inserting them into
/// `expired_animations`.
pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
script_chan: &IpcSender<ConstellationControlMsg>,
running_animations: &mut HashMap<OpaqueNode, Vec<Animation>>,
expired_animations: &mut HashMap<OpaqueNode, Vec<Animation>>,
new_animations_receiver: &Receiver<Animation>,
@ -70,7 +71,7 @@ pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
let mut animations_still_running = vec![];
for mut running_animation in running_animations.drain(..) {
let still_running = !running_animation.is_expired() && match running_animation {
Animation::Transition(_, started_at, ref frame, _expired) => {
Animation::Transition(_, _, started_at, ref frame, _expired) => {
now < started_at + frame.duration
}
Animation::Keyframes(_, _, ref mut state) => {
@ -85,6 +86,13 @@ pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
continue
}
if let Animation::Transition(_, unsafe_node, _, ref frame, _) = running_animation {
script_chan.send(ConstellationControlMsg::TransitionEnd(unsafe_node,
frame.property_animation.property_name(),
frame.duration))
.unwrap();
}
expired_animations.entry(*key)
.or_insert_with(Vec::new)
.push(running_animation);