Bug 1067769 - Part 2: Avoid doing RequestRestyle and mutation batch for null target draft
authorBoris Chiou <boris.chiou@gmail.com>
Thu, 14 Apr 2016 17:00:55 +0800
changeset 350871 b71883aa1ea200d813834aae0e38499816c62411
parent 350869 22b1625e127b3242cb57ebfb486bc839f8b386a2
child 350965 68852dc1cbfcd0e470aa5d12c99cf9a2752a6972
child 350967 e3b3ebcb8d2f72c263452eea7eb01e74fc97470b
push id15433
push userbmo:boris.chiou@gmail.com
push dateThu, 14 Apr 2016 10:37:52 +0000
bugs1067769
milestone48.0a1
Bug 1067769 - Part 2: Avoid doing RequestRestyle and mutation batch for null target We don't need to restyle if mTarget is nullptr, so skip it. For AnimationMutationBatch, we also skip it if mTarget is nullptr. Note: AnimationColletion, nsAnimationManager and nsTransitionManger are for CSS Animations and CSS Transtions, so the effect should have an effective target. Therefore, I think we don't have to revise them. MozReview-Commit-ID: Egzr1QVEa0v
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -182,17 +182,17 @@ KeyframeEffectReadOnly::NotifyAnimationT
   // Bug 1216843: When we implement iteration composite modes, we need to
   // also detect if the current iteration has changed.
   if (mAnimation && GetComputedTiming().mProgress != mProgressOnLastCompose) {
     EffectCompositor::RestyleType restyleType =
       CanThrottle() ?
       EffectCompositor::RestyleType::Throttled :
       EffectCompositor::RestyleType::Standard;
     nsPresContext* presContext = GetPresContext();
-    if (presContext) {
+    if (presContext && mTarget) {
       presContext->EffectCompositor()->
         RequestRestyle(mTarget, mPseudoType, restyleType,
                        mAnimation->CascadeLevel());
     }
 
     // If we're not relevant, we will have been removed from the EffectSet.
     // As a result, when the restyle we requested above is fulfilled, our
     // ComposeStyle will not get called and mProgressOnLastCompose will not
@@ -569,17 +569,17 @@ KeyframeEffectReadOnly::UpdateProperties
     EffectSet* effectSet = EffectSet::GetEffectSet(mTarget, mPseudoType);
     if (effectSet) {
       effectSet->MarkCascadeNeedsUpdate();
     }
   }
 
   if (mAnimation) {
     nsPresContext* presContext = GetPresContext();
-    if (presContext) {
+    if (presContext && mTarget) {
       presContext->EffectCompositor()->
         RequestRestyle(mTarget, mPseudoType,
                        EffectCompositor::RestyleType::Layer,
                        mAnimation->CascadeLevel());
     }
   }
 }
 
@@ -1117,16 +1117,18 @@ KeyframeEffectReadOnly::CanThrottle() co
   }
 
   return true;
 }
 
 bool
 KeyframeEffectReadOnly::CanThrottleTransformChanges(nsIFrame& aFrame) const
 {
+  MOZ_ASSERT(mTarget);
+
   // If we know that the animation cannot cause overflow,
   // we can just disable flushes for this animation.
 
   // If we don't show scrollbars, we don't care about overflow.
   if (LookAndFeel::GetInt(LookAndFeel::eIntID_ShowHideScrollbars) == 0) {
     return true;
   }
 
@@ -1371,27 +1373,28 @@ KeyframeEffect::Constructor(
 {
   return ConstructKeyframeEffect<KeyframeEffect>(aGlobal, aTarget, aFrames,
                                                  aOptions, aRv);
 }
 
 void KeyframeEffect::NotifySpecifiedTimingUpdated()
 {
   // Use the same document for a pseudo element and its parent element.
-  nsAutoAnimationMutationBatch mb(mTarget->OwnerDoc());
+  // Use nullptr if we don't have mTarget, so disable the mutation batch.
+  nsAutoAnimationMutationBatch mb(mTarget ? mTarget->OwnerDoc() : nullptr);
 
   if (mAnimation) {
     mAnimation->NotifyEffectTimingUpdated();
 
     if (mAnimation->IsRelevant()) {
       nsNodeUtils::AnimationChanged(mAnimation);
     }
 
     nsPresContext* presContext = GetPresContext();
-    if (presContext) {
+    if (presContext && mTarget) {
       presContext->EffectCompositor()->
         RequestRestyle(mTarget, mPseudoType,
                        EffectCompositor::RestyleType::Layer,
                        mAnimation->CascadeLevel());
     }
   }
 }