Bug 1278136 - Part 1: Add nsLayoutUtils::HasInEffectAnimationOfProperty. r? draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Mon, 20 Jun 2016 14:56:15 +0900
changeset 379961 ed10219ff483c49a0bc7660993474abfdc405454
parent 379960 f132e91f63611eb0c0febb14aab92b4e2ec3dd80
child 379962 2398bff33d947407f032bac98f447a6b6a188d94
child 379963 310d8c17b3667cd123419b9a3f2f48e5cfbcae46
push id21100
push userhiikezoe@mozilla-japan.org
push dateMon, 20 Jun 2016 05:56:38 +0000
bugs1278136
milestone50.0a1
Bug 1278136 - Part 1: Add nsLayoutUtils::HasInEffectAnimationOfProperty. r? We want to know that an nsIFrame has a transform or opacity animations regardless of its state, e.g., running on the main-thead, paused or finished but in fill:forwards state, to create a stacking context for the animation. MozReview-Commit-ID: mNYsd5RO3u
layout/base/nsLayoutUtils.cpp
layout/base/nsLayoutUtils.h
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -449,70 +449,79 @@ BackgroundClipTextEnabledPrefChangeCallb
   if (sIndexOfTextInBGClipTable >= 0) {
     nsCSSProps::kBackgroundClipKTable[sIndexOfTextInBGClipTable].mKeyword =
       isBGClipTextEnabled ? eCSSKeyword_text : eCSSKeyword_UNKNOWN;
   }
 }
 
 template<typename TestType>
 static bool
-HasMatchingCurrentAnimations(const nsIFrame* aFrame, TestType&& aTest)
+HasMatchingAnimations(const nsIFrame* aFrame, TestType&& aTest)
 {
   EffectSet* effects = EffectSet::GetEffectSet(aFrame);
   if (!effects) {
     return false;
   }
 
   for (KeyframeEffectReadOnly* effect : *effects) {
-    if (!effect->IsCurrent()) {
-      continue;
-    }
-
     if (aTest(*effect)) {
       return true;
     }
   }
 
   return false;
 }
 
 bool
 nsLayoutUtils::HasCurrentAnimationOfProperty(const nsIFrame* aFrame,
                                              nsCSSProperty aProperty)
 {
-  return HasMatchingCurrentAnimations(aFrame,
+  return HasMatchingAnimations(aFrame,
     [&aProperty](KeyframeEffectReadOnly& aEffect)
     {
-      return aEffect.HasAnimationOfProperty(aProperty);
+      return aEffect.IsCurrent() && aEffect.HasAnimationOfProperty(aProperty);
     }
   );
 }
 
 bool
 nsLayoutUtils::HasCurrentTransitions(const nsIFrame* aFrame)
 {
-  return HasMatchingCurrentAnimations(aFrame,
+  return HasMatchingAnimations(aFrame,
     [](KeyframeEffectReadOnly& aEffect)
     {
       // Since |aEffect| is current, it must have an associated Animation
       // so we don't need to null-check the result of GetAnimation().
-      return aEffect.GetAnimation()->AsCSSTransition();
+      return aEffect.IsCurrent() && aEffect.GetAnimation()->AsCSSTransition();
     }
   );
 }
 
 bool
 nsLayoutUtils::HasCurrentAnimationsForProperties(const nsIFrame* aFrame,
                                                  const nsCSSProperty* aProperties,
                                                  size_t aPropertyCount)
 {
-  return HasMatchingCurrentAnimations(aFrame,
+  return HasMatchingAnimations(aFrame,
     [&aProperties, &aPropertyCount](KeyframeEffectReadOnly& aEffect)
     {
-      return aEffect.HasAnimationOfProperties(aProperties, aPropertyCount);
+      return aEffect.IsCurrent() &&
+        aEffect.HasAnimationOfProperties(aProperties, aPropertyCount);
+    }
+  );
+}
+
+bool
+nsLayoutUtils::HasInEffectAnimationOfProperty(const nsIFrame* aFrame,
+                                              nsCSSProperty aProperty)
+{
+  return HasMatchingAnimations(aFrame,
+    [&aProperty](KeyframeEffectReadOnly& aEffect)
+    {
+      return aEffect.IsInEffect() && aEffect.HasAnimationOfProperty(aProperty);
     }
   );
 }
 
 static float
 GetSuitableScale(float aMaxScale, float aMinScale,
                  nscoord aVisibleDimension, nscoord aDisplayDimension)
 {
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2249,16 +2249,23 @@ public:
    * Returns true if the frame has any current animations or transitions
    * for any of the specified properties.
    */
   static bool HasCurrentAnimationsForProperties(const nsIFrame* aFrame,
                                                 const nsCSSProperty* aProperties,
                                                 size_t aPropertyCount);
 
   /**
+   * Returns true if the frame has in-effect (i.e. running or finished but
+   * fill:forwards) animations or transitions for the property.
+   */
+  static bool HasInEffectAnimationOfProperty(const nsIFrame* aFrame,
+                                             nsCSSProperty aProperty);
+
+  /**
    * Checks if off-main-thread animations are enabled.
    */
   static bool AreAsyncAnimationsEnabled();
 
   /**
    * Checks if we should warn about animations that can't be async
    */
   static bool IsAnimationLoggingEnabled();