Bug 1430884 - Flatten CanThrottleIfNotVisible function with early returns. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 25 Jun 2018 11:51:05 +0900
changeset 810067 1b9b49360e0403a59d28efbab4a551fc176f24d3
parent 810066 2bcf595cfc4089102401f16b1a5fc3db27f4551e
child 810068 697158bc522eeab2795f5f884c51c131f943f6b0
push id113878
push userhikezoe@mozilla.com
push dateMon, 25 Jun 2018 04:48:04 +0000
reviewersbirtles
bugs1430884
milestone62.0a1
Bug 1430884 - Flatten CanThrottleIfNotVisible function with early returns. r?birtles MozReview-Commit-ID: 3JQ0sG2oWfN
dom/animation/KeyframeEffect.cpp
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -1194,43 +1194,48 @@ KeyframeEffect::OverflowRegionRefreshInt
 }
 
 bool
 KeyframeEffect::CanThrottleIfNotVisible(nsIFrame& aFrame) const
 {
   // Unless we are newly in-effect, we can throttle the animation if the
   // animation is paint only and the target frame is out of view or the document
   // is in background tabs.
-  if (mInEffectOnLastAnimationTimingUpdate && CanIgnoreIfNotVisible()) {
-    nsIPresShell* presShell = GetPresShell();
-    if (presShell && !presShell->IsActive()) {
-      return true;
-    }
+  if (!mInEffectOnLastAnimationTimingUpdate || !CanIgnoreIfNotVisible()) {
+    return false;
+  }
+
+  nsIPresShell* presShell = GetPresShell();
+  if (presShell && !presShell->IsActive()) {
+    return true;
+  }
+
+  const bool isVisibilityHidden =
+    !aFrame.IsVisibleOrMayHaveVisibleDescendants();
+  if ((!isVisibilityHidden || HasVisibilityChange()) &&
+      !aFrame.IsScrolledOutOfView()) {
+    return false;
+  }
 
-    const bool isVisibilityHidden =
-      !aFrame.IsVisibleOrMayHaveVisibleDescendants();
-    if ((isVisibilityHidden && !HasVisibilityChange()) ||
-        aFrame.IsScrolledOutOfView()) {
-      // Unthrottle the animation if there is a change hint that might affect
-      // the overflow region.
-      if (HasPropertiesThatMightAffectOverflow()) {
-        // Don't throttle finite animations since the animation might suddenly
-        // come into view and if it was throttled it will be out-of-sync.
-        if (HasFiniteActiveDuration()) {
-          return false;
-        }
+  // If there are no overflow change hints, we don't need to worry about
+  // unthrottling the animation periodically to update scrollbar positions for
+  // the overflow region.
+  if (!HasPropertiesThatMightAffectOverflow()) {
+    return true;
+  }
 
-        return isVisibilityHidden
-          ? CanThrottleOverflowChangesInScrollable(aFrame)
-          : CanThrottleOverflowChanges(aFrame);
-      }
-      return true;
-    }
+  // Don't throttle finite animations since the animation might suddenly
+  // come into view and if it was throttled it will be out-of-sync.
+  if (HasFiniteActiveDuration()) {
+    return false;
   }
-  return false;
+
+  return isVisibilityHidden
+    ? CanThrottleOverflowChangesInScrollable(aFrame)
+    : CanThrottleOverflowChanges(aFrame);
 }
 
 bool
 KeyframeEffect::CanThrottle() const
 {
   // Unthrottle if we are not in effect or current. This will be the case when
   // our owning animation has finished, is idle, or when we are in the delay
   // phase (but without a backwards fill). In each case the computed progress