Bug 1468364 - Part 1. Calculate the created time of animation every creating the AnimationPlayerActor. r?daisuke
This patch will drop animationCreatedTimeMap in order to calculate created time
every creating the AnimationPlayerActor, as result of it, we can adjust the
current time even if AnimationsActor has the different current times of
animation.
MozReview-Commit-ID: DZ7m5wZcJF7
--- a/devtools/server/actors/animation.js
+++ b/devtools/server/actors/animation.js
@@ -613,30 +613,25 @@ exports.AnimationsActor = protocol.Actor
this.onWillNavigate = this.onWillNavigate.bind(this);
this.onNavigate = this.onNavigate.bind(this);
this.onAnimationMutation = this.onAnimationMutation.bind(this);
this.allAnimationsPaused = false;
this.targetActor.on("will-navigate", this.onWillNavigate);
this.targetActor.on("navigate", this.onNavigate);
-
- this.animationCreatedTimeMap = new Map();
},
destroy: function() {
Actor.prototype.destroy.call(this);
this.targetActor.off("will-navigate", this.onWillNavigate);
this.targetActor.off("navigate", this.onNavigate);
this.stopAnimationPlayerUpdates();
this.targetActor = this.observer = this.actors = this.walker = null;
-
- this.animationCreatedTimeMap.clear();
- this.animationCreatedTimeMap = null;
},
/**
* Clients can optionally call this with a reference to their WalkerActor.
* If they do, then AnimationPlayerActor's forms are going to also include
* NodeActor IDs when the corresponding NodeActors do exist.
* This, in turns, is helpful for clients to avoid having to go back once more
* to the server to get a NodeActor for a particular animation.
@@ -652,18 +647,16 @@ exports.AnimationsActor = protocol.Actor
* Note that calling this method a second time will destroy all previously
* retrieved AnimationPlayerActors. Indeed, the lifecycle of these actors
* is managed here on the server and tied to getAnimationPlayersForNode
* being called.
* @param {NodeActor} nodeActor The NodeActor as defined in
* /devtools/server/actors/inspector
*/
getAnimationPlayersForNode: function(nodeActor) {
- this.updateAllAnimationsCreatedTime();
-
const animations = nodeActor.rawNode.getAnimations({subtree: true});
// Destroy previously stored actors
if (this.actors) {
for (const actor of this.actors) {
actor.destroy();
}
}
@@ -742,17 +735,16 @@ exports.AnimationsActor = protocol.Actor
if (index !== -1) {
eventData.push({
type: "removed",
player: this.actors[index]
});
this.actors.splice(index, 1);
}
- this.updateAnimationCreatedTime(player);
const createdTime = this.getCreatedTime(player);
const actor = AnimationPlayerActor(this, player, createdTime);
this.actors.push(actor);
eventData.push({
type: "added",
player: actor
});
readyPromises.push(player.ready);
@@ -960,49 +952,18 @@ exports.AnimationsActor = protocol.Actor
},
/**
* Return created fime of given animaiton.
*
* @param {Object} animation
*/
getCreatedTime(animation) {
- return this.animationCreatedTimeMap.get(animation);
- },
-
- /**
- * Update all animation created time map.
- */
- updateAllAnimationsCreatedTime() {
- const currentAnimations = this.getAllAnimations(this.targetActor.window.document);
-
- // Remove invalid animations.
- for (const previousAnimation of this.animationCreatedTimeMap.keys()) {
- if (!currentAnimations.includes(previousAnimation)) {
- this.animationCreatedTimeMap.delete(previousAnimation);
- }
- }
-
- for (const animation of currentAnimations) {
- this.updateAnimationCreatedTime(animation);
- }
- },
-
- /**
- * Update animation created time map.
- *
- * @param {Object} animation
- */
- updateAnimationCreatedTime(animation) {
- if (!this.animationCreatedTimeMap.has(animation)) {
- const createdTime =
- animation.startTime ||
- animation.timeline.currentTime - animation.currentTime / animation.playbackRate;
- this.animationCreatedTimeMap.set(animation, createdTime);
- }
+ return animation.startTime ||
+ animation.timeline.currentTime - animation.currentTime / animation.playbackRate;
},
/**
* Wait for next animation frame.
*
* @param {Array} actors
* @return {Promise} which waits for next frame
*/