Bug 1430884 - Flatten CanThrottleIfNotVisible function with early returns. r?birtles
MozReview-Commit-ID: 3JQ0sG2oWfN
--- 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