diff --git a/dom/animation/KeyframeEffect.cpp b/dom/animation/KeyframeEffect.cpp index 55567f5d5b4f..40375d50575b 100644 --- a/dom/animation/KeyframeEffect.cpp +++ b/dom/animation/KeyframeEffect.cpp @@ -19,6 +19,7 @@ #include "nsCSSProps.h" // For nsCSSProps::PropHasFlags #include "nsCSSPseudoElements.h" // For CSSPseudoElementType #include "nsDOMMutationObserver.h" // For nsAutoAnimationMutationBatch +#include "nsIPresShell.h" // For nsIPresShell namespace mozilla { @@ -1066,9 +1067,13 @@ KeyframeEffectReadOnly::CanThrottle() const } // We can throttle the animation if the animation is paint only and - // the target frame is out of view. - if (CanIgnoreIfNotVisible() && frame->IsScrolledOutOfView()) { - return true; + // the target frame is out of view or the document is in background tabs. + if (CanIgnoreIfNotVisible()) { + nsIPresShell* presShell = GetPresShell(); + if ((presShell && !presShell->IsActive()) || + frame->IsScrolledOutOfView()) { + return true; + } } // First we need to check layer generation and transform overflow @@ -1201,14 +1206,20 @@ KeyframeEffectReadOnly::GetRenderedDocument() const return mTarget->mElement->GetComposedDoc(); } -nsPresContext* -KeyframeEffectReadOnly::GetPresContext() const +nsIPresShell* +KeyframeEffectReadOnly::GetPresShell() const { nsIDocument* doc = GetRenderedDocument(); if (!doc) { return nullptr; } - nsIPresShell* shell = doc->GetShell(); + return doc->GetShell(); +} + +nsPresContext* +KeyframeEffectReadOnly::GetPresContext() const +{ + nsIPresShell* shell = GetPresShell(); if (!shell) { return nullptr; } diff --git a/dom/animation/KeyframeEffect.h b/dom/animation/KeyframeEffect.h index b4c1a50d1138..05b17f434924 100644 --- a/dom/animation/KeyframeEffect.h +++ b/dom/animation/KeyframeEffect.h @@ -37,6 +37,7 @@ class nsCSSPropertySet; class nsIContent; class nsIDocument; class nsIFrame; +class nsIPresShell; class nsPresContext; namespace mozilla { @@ -332,6 +333,7 @@ public: nsIDocument* GetRenderedDocument() const; nsPresContext* GetPresContext() const; + nsIPresShell* GetPresShell() const; // Associates a warning with the animated property on the specified frame // indicating why, for example, the property could not be animated on the