diff --git a/layout/style/AnimationCommon.cpp b/layout/style/AnimationCommon.cpp index 238af444b3e..1c6f056e6b0 100644 --- a/layout/style/AnimationCommon.cpp +++ b/layout/style/AnimationCommon.cpp @@ -52,6 +52,7 @@ namespace css { CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext) : mPresContext(aPresContext) + , mIsObservingRefreshDriver(false) { PR_INIT_CLIST(&mElementCollections); } @@ -70,6 +71,21 @@ CommonAnimationManager::Disconnect() mPresContext = nullptr; } +void +CommonAnimationManager::AddElementCollection(AnimationPlayerCollection* + aCollection) +{ + if (!mIsObservingRefreshDriver) { + NS_ASSERTION(aCollection->mNeedsRefreshes, + "Added data which doesn't need refreshing?"); + // We need to observe the refresh driver. + mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style); + mIsObservingRefreshDriver = true; + } + + PR_INSERT_BEFORE(aCollection, &mElementCollections); +} + void CommonAnimationManager::RemoveAllElementCollections() { @@ -81,6 +97,26 @@ CommonAnimationManager::RemoveAllElementCollections() } } +void +CommonAnimationManager::CheckNeedsRefresh() +{ + for (PRCList *l = PR_LIST_HEAD(&mElementCollections); + l != &mElementCollections; + l = PR_NEXT_LINK(l)) { + if (static_cast(l)->mNeedsRefreshes) { + if (!mIsObservingRefreshDriver) { + mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style); + mIsObservingRefreshDriver = true; + } + return; + } + } + if (mIsObservingRefreshDriver) { + mIsObservingRefreshDriver = false; + mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style); + } +} + AnimationPlayerCollection* CommonAnimationManager::GetAnimationsForCompositor(nsIContent* aContent, nsIAtom* aElementProperty, diff --git a/layout/style/AnimationCommon.h b/layout/style/AnimationCommon.h index 3c483bb7eab..f6e7876cca3 100644 --- a/layout/style/AnimationCommon.h +++ b/layout/style/AnimationCommon.h @@ -75,17 +75,20 @@ public: nsCSSProperty aProperty, nsStyleContext* aStyleContext, mozilla::StyleAnimationValue& aComputedValue); + protected: virtual ~CommonAnimationManager(); // For ElementCollectionRemoved friend struct mozilla::AnimationPlayerCollection; - virtual void - AddElementCollection(AnimationPlayerCollection* aCollection) = 0; - virtual void ElementCollectionRemoved() = 0; + void AddElementCollection(AnimationPlayerCollection* aCollection); + void ElementCollectionRemoved() { CheckNeedsRefresh(); } void RemoveAllElementCollections(); + // Check to see if we should stop or start observing the refresh driver + void CheckNeedsRefresh(); + // When this returns a value other than nullptr, it also, // as a side-effect, notifies the ActiveLayerTracker. static AnimationPlayerCollection* @@ -95,6 +98,7 @@ protected: PRCList mElementCollections; nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect) + bool mIsObservingRefreshDriver; }; /** @@ -185,9 +189,8 @@ struct AnimationPlayerCollection : public PRCList void Tick(); // This updates mNeedsRefreshes so the caller may need to check - // for changes to values (for example, nsAnimationManager provides - // CheckNeedsRefresh to register or unregister from observing the refresh - // driver when this value changes). + // for changes to values (for example, calling CheckNeedsRefresh to register + // or unregister from observing the refresh driver when this value changes). void EnsureStyleRuleFor(TimeStamp aRefreshTime, EnsureStyleRuleFlags aFlags); bool CanThrottleTransformChanges(mozilla::TimeStamp aTime); diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index 6ad7bcfdc93..f4ff43b8ea3 100644 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -760,42 +760,6 @@ nsAnimationManager::WillRefresh(mozilla::TimeStamp aTime) FlushAnimations(Can_Throttle); } -void -nsAnimationManager::AddElementCollection( - AnimationPlayerCollection* aCollection) -{ - if (!mObservingRefreshDriver) { - NS_ASSERTION( - static_cast(aCollection)->mNeedsRefreshes, - "Added data which doesn't need refreshing?"); - // We need to observe the refresh driver. - mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style); - mObservingRefreshDriver = true; - } - - PR_INSERT_BEFORE(aCollection, &mElementCollections); -} - -void -nsAnimationManager::CheckNeedsRefresh() -{ - for (PRCList *l = PR_LIST_HEAD(&mElementCollections); - l != &mElementCollections; - l = PR_NEXT_LINK(l)) { - if (static_cast(l)->mNeedsRefreshes) { - if (!mObservingRefreshDriver) { - mPresContext->RefreshDriver()->AddRefreshObserver(this, Flush_Style); - mObservingRefreshDriver = true; - } - return; - } - } - if (mObservingRefreshDriver) { - mObservingRefreshDriver = false; - mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style); - } -} - void nsAnimationManager::FlushAnimations(FlushFlags aFlags) { diff --git a/layout/style/nsAnimationManager.h b/layout/style/nsAnimationManager.h index c9d9d432509..4108c416f31 100644 --- a/layout/style/nsAnimationManager.h +++ b/layout/style/nsAnimationManager.h @@ -147,7 +147,6 @@ class nsAnimationManager MOZ_FINAL public: explicit nsAnimationManager(nsPresContext *aPresContext) : mozilla::css::CommonAnimationManager(aPresContext) - , mObservingRefreshDriver(false) { } @@ -227,19 +226,6 @@ public: nsIStyleRule* GetAnimationRule(mozilla::dom::Element* aElement, nsCSSPseudoElements::Type aPseudoType); -protected: - virtual void ElementCollectionRemoved() MOZ_OVERRIDE - { - CheckNeedsRefresh(); - } - virtual void - AddElementCollection(mozilla::AnimationPlayerCollection* aData) MOZ_OVERRIDE; - - /** - * Check to see if we should stop or start observing the refresh driver - */ - void CheckNeedsRefresh(); - private: void BuildAnimations(nsStyleContext* aStyleContext, mozilla::dom::Element* aTarget, @@ -257,8 +243,6 @@ private: void DoDispatchEvents(); mozilla::EventArray mPendingEvents; - - bool mObservingRefreshDriver; }; #endif /* !defined(nsAnimationManager_h_) */ diff --git a/layout/style/nsTransitionManager.cpp b/layout/style/nsTransitionManager.cpp index eedc8017e8a..17ecb01294b 100644 --- a/layout/style/nsTransitionManager.cpp +++ b/layout/style/nsTransitionManager.cpp @@ -74,29 +74,6 @@ ElementPropertyTransition::CurrentValuePortion() const * nsTransitionManager * *****************************************************************************/ -void -nsTransitionManager::ElementCollectionRemoved() -{ - // If we have no transitions or animations left, remove ourselves from - // the refresh driver. - if (PR_CLIST_IS_EMPTY(&mElementCollections)) { - mPresContext->RefreshDriver()->RemoveRefreshObserver(this, Flush_Style); - } -} - -void -nsTransitionManager::AddElementCollection( - AnimationPlayerCollection* aCollection) -{ - if (PR_CLIST_IS_EMPTY(&mElementCollections)) { - // We need to observe the refresh driver. - nsRefreshDriver *rd = mPresContext->RefreshDriver(); - rd->AddRefreshObserver(this, Flush_Style); - } - - PR_INSERT_BEFORE(aCollection, &mElementCollections); -} - already_AddRefed nsTransitionManager::StyleContextChanged(dom::Element *aElement, nsStyleContext *aOldStyleContext, diff --git a/layout/style/nsTransitionManager.h b/layout/style/nsTransitionManager.h index 8508fe6b097..5d539dd4a20 100644 --- a/layout/style/nsTransitionManager.h +++ b/layout/style/nsTransitionManager.h @@ -152,11 +152,6 @@ public: nsCSSPseudoElements::Type aPseudoType, nsRuleWalker* aRuleWalker); -protected: - virtual void ElementCollectionRemoved() MOZ_OVERRIDE; - virtual void - AddElementCollection(AnimationPlayerCollection* aCollection) MOZ_OVERRIDE; - private: void ConsiderStartingTransition(nsCSSProperty aProperty,