Bug 1430884 - Flatten CanThrottleIfNotVisible function with early returns. r?birtles draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Fri, 22 Jun 2018 13:27:20 +0900
changeset 809448 de2debd37de01bf29005642823b807e63b773afe
parent 809447 7ff1a1cc8ab7eaba6509249a949e9f00b1f418dc
child 809449 907b0c2eea90d45454412c51ff13c33620ffe5db
child 809458 93a59ea8a1b7c3bd6bb3aea9f95de6ce18dd49dc
child 809461 1ee79e14f2191348d883366e7d2f6f61ef61e6b5
child 809476 a1d3a2ff238be484dd3cbb4dd082488ec429cc2c
push id113680
push userhikezoe@mozilla.com
push dateFri, 22 Jun 2018 04:33:20 +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 is no overflow change hints, we don't need to worry 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