mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Root nodes for the duration of their CSS transitions.
This ensures that we can pass a node address as part of the asynchronous transition end notification, making it safe to fire the corresponding DOM event on the node from the script thread. Without explicitly rooting this node when the transition starts, we risk the node being GCed before the transition is complete.
This commit is contained in:
parent
f3c8f7e0d0
commit
dabebdfbf5
11 changed files with 126 additions and 25 deletions
|
@ -9,7 +9,9 @@ use flow::{self, Flow};
|
|||
use gfx::display_list::OpaqueNode;
|
||||
use ipc_channel::ipc::IpcSender;
|
||||
use msg::constellation_msg::PipelineId;
|
||||
use opaque_node::OpaqueNodeMethods;
|
||||
use script_traits::{AnimationState, ConstellationControlMsg, LayoutMsg as ConstellationMsg};
|
||||
use script_traits::UntrustedNodeAddress;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::Receiver;
|
||||
use style::animation::{Animation, update_style_for_animation};
|
||||
|
@ -24,6 +26,7 @@ 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>>,
|
||||
newly_transitioning_nodes: &mut Vec<UntrustedNodeAddress>,
|
||||
new_animations_receiver: &Receiver<Animation>,
|
||||
pipeline_id: PipelineId,
|
||||
timer: &Timer) {
|
||||
|
@ -71,7 +74,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) => {
|
||||
|
@ -86,8 +89,8 @@ 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,
|
||||
if let Animation::Transition(node, _, ref frame, _) = running_animation {
|
||||
script_chan.send(ConstellationControlMsg::TransitionEnd(node.to_untrusted_node_address(),
|
||||
frame.property_animation
|
||||
.property_name().into(),
|
||||
frame.duration))
|
||||
|
@ -112,6 +115,10 @@ pub fn update_animation_state(constellation_chan: &IpcSender<ConstellationMsg>,
|
|||
|
||||
// Add new running animations.
|
||||
for new_running_animation in new_running_animations {
|
||||
if new_running_animation.is_transition() {
|
||||
newly_transitioning_nodes.push(new_running_animation.node().to_untrusted_node_address());
|
||||
}
|
||||
|
||||
running_animations.entry(*new_running_animation.node())
|
||||
.or_insert_with(Vec::new)
|
||||
.push(new_running_animation)
|
||||
|
|
|
@ -94,6 +94,9 @@ pub struct LayoutThreadData {
|
|||
|
||||
/// A queued response for the list of nodes at a given point.
|
||||
pub nodes_from_point_response: Vec<UntrustedNodeAddress>,
|
||||
|
||||
/// A list of nodes that have just started a CSS transition.
|
||||
pub newly_transitioning_nodes: Vec<UntrustedNodeAddress>,
|
||||
}
|
||||
|
||||
pub struct LayoutRPCImpl(pub Arc<Mutex<LayoutThreadData>>);
|
||||
|
@ -204,6 +207,12 @@ impl LayoutRPC for LayoutRPCImpl {
|
|||
let mut rw_data = rw_data.lock().unwrap();
|
||||
mem::replace(&mut rw_data.pending_images, vec![])
|
||||
}
|
||||
|
||||
fn newly_transitioning_nodes(&self) -> Vec<UntrustedNodeAddress> {
|
||||
let &LayoutRPCImpl(ref rw_data) = self;
|
||||
let mut rw_data = rw_data.lock().unwrap();
|
||||
mem::replace(&mut rw_data.newly_transitioning_nodes, vec![])
|
||||
}
|
||||
}
|
||||
|
||||
struct UnioningFragmentBorderBoxIterator {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue