Bug 1468364 - Part 1. Calculate the created time of animation every creating the AnimationPlayerActor. r?daisuke draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Mon, 02 Jul 2018 14:52:47 +0900
changeset 813013 4e5cfd2f3b0e7845483f1957debe2d61b098e520
parent 812962 3cfc350101967376909ad3c729f9779ae0ab7a94
child 813014 46f5e1c0c8f9dc24905d4ce71b0abf2ad2704d8c
child 813017 7d2c4889201d1441511906758bfc339e663997c2
push id114733
push userbmo:mantaroh@gmail.com
push dateMon, 02 Jul 2018 05:58:49 +0000
reviewersdaisuke
bugs1468364
milestone63.0a1
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
devtools/server/actors/animation.js
--- 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
    */