Bug 1178662 part 3 - Separate SetTimeline function in order to call from style. r?birtles draft
authorMantaroh Yoshinaga <mantaroh@gmail.com>
Tue, 31 May 2016 09:42:37 +0900
changeset 373069 128e8395ed3f2093e4e5abd68f61e7660be2acf7
parent 373068 f08656a34ae1fa55c36d7d8d38707541ac360ba2
child 373070 f04d8697524b7e31ebc789ed70413f4d9c563163
push id19674
push usermantaroh@gmail.com
push dateTue, 31 May 2016 00:42:59 +0000
reviewersbirtles
bugs1178662
milestone49.0a1
Bug 1178662 part 3 - Separate SetTimeline function in order to call from style. r?birtles MozReview-Commit-ID: 9KbsbPuAMW7
dom/animation/Animation.cpp
dom/animation/Animation.h
layout/style/nsAnimationManager.cpp
layout/style/nsTransitionManager.cpp
--- a/dom/animation/Animation.cpp
+++ b/dom/animation/Animation.cpp
@@ -108,17 +108,17 @@ Animation::Constructor(const GlobalObjec
       AnimationUtils::GetCurrentRealmDocument(aGlobal.Context());
     if (!document) {
       aRv.Throw(NS_ERROR_FAILURE);
       return nullptr;
     }
     timeline = document->Timeline();
   }
 
-  animation->SetTimeline(timeline);
+  animation->SetTimelineNoUpdate(timeline);
   animation->SetEffect(aEffect);
 
   return animation.forget();
 }
 
 void
 Animation::SetId(const nsAString& aId)
 {
@@ -146,32 +146,36 @@ Animation::SetEffect(KeyframeEffectReadO
   }
 
   UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
 }
 
 void
 Animation::SetTimeline(AnimationTimeline* aTimeline)
 {
+  SetTimelineNoUpdate(aTimeline);
+  PostUpdate();
+}
+
+void
+Animation::SetTimelineNoUpdate(AnimationTimeline* aTimeline)
+{
   if (mTimeline == aTimeline) {
     return;
   }
 
   if (mTimeline) {
     mTimeline->NotifyAnimationUpdated(*this);
   }
 
   mTimeline = aTimeline;
 
   // FIXME(spec): Once we implement the seeking defined in the spec
   // surely this should be SeekFlag::DidSeek but the spec says otherwise.
   UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
-
-  // FIXME: When we expose this method to script we'll need to call PostUpdate
-  // (but *not* when this method gets called from style).
 }
 
 // https://w3c.github.io/web-animations/#set-the-animation-start-time
 void
 Animation::SetStartTime(const Nullable<TimeDuration>& aNewStartTime)
 {
   if (aNewStartTime == mStartTime) {
     return;
--- a/dom/animation/Animation.h
+++ b/dom/animation/Animation.h
@@ -140,16 +140,17 @@ public:
    * in future we will likely have to flush style in
    * CSSAnimation::PauseFromJS so we leave it for now.
    */
   void PauseFromJS(ErrorResult& aRv) { Pause(aRv); }
 
   // Wrapper functions for Animation DOM methods when called from style.
 
   virtual void CancelFromStyle() { CancelNoUpdate(); }
+  void SetTimelineNoUpdate(AnimationTimeline* aTimeline);
 
   virtual void Tick();
   bool NeedsTicks() const
   {
     AnimationPlayState playState = PlayState();
     return playState == AnimationPlayState::Running ||
            playState == AnimationPlayState::Pending;
   }
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -644,17 +644,17 @@ CSSAnimationBuilder::Build(nsPresContext
   effect->SetKeyframes(Move(keyframes), mStyleContext);
 
   RefPtr<CSSAnimation> animation =
     new CSSAnimation(aPresContext->Document()->GetScopeObject(),
                      aSrc.GetName());
   animation->SetOwningElement(
     OwningElementRef(*mTarget, mStyleContext->GetPseudoType()));
 
-  animation->SetTimeline(mTimeline);
+  animation->SetTimelineNoUpdate(mTimeline);
   animation->SetEffect(effect);
 
   if (isStylePaused) {
     animation->PauseFromStyle();
   } else {
     animation->PlayFromStyle();
   }
 
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -761,17 +761,17 @@ nsTransitionManager::ConsiderStartingTra
   MOZ_ASSERT(mPresContext->RestyleManager()->IsGecko(),
              "ServoRestyleManager should not use nsTransitionManager "
              "for transitions");
 
   RefPtr<CSSTransition> animation =
     new CSSTransition(mPresContext->Document()->GetScopeObject());
   animation->SetOwningElement(
     OwningElementRef(*aElement, aNewStyleContext->GetPseudoType()));
-  animation->SetTimeline(timeline);
+  animation->SetTimelineNoUpdate(timeline);
   animation->SetCreationSequence(
     mPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration());
   // The order of the following two calls is important since PlayFromStyle
   // will add the animation to the PendingAnimationTracker of its effect's
   // document. When we come to make effect writeable (bug 1049975) we should
   // remove this dependency.
   animation->SetEffect(pt);
   animation->PlayFromStyle();