Bug 1340322 - Part 8: Split off some processes that will be used for servo's computed values in UpdateAnimations(). r?birtles
MozReview-Commit-ID: LkWqhGsMCPf
--- a/layout/style/nsAnimationManager.cpp
+++ b/layout/style/nsAnimationManager.cpp
@@ -1070,61 +1070,72 @@ nsAnimationManager::UpdateAnimations(nsS
mozilla::dom::Element* aElement)
{
MOZ_ASSERT(mPresContext->IsDynamic(),
"Should not update animations for print or print preview");
MOZ_ASSERT(aElement->IsInComposedDoc(),
"Should not update animations that are not attached to the "
"document tree");
+ if (aStyleContext->IsInDisplayNoneSubtree()) {
+ StopAnimationsForElement(aElement, aStyleContext->GetPseudoType());
+ return;
+ }
+
NonOwningAnimationTarget target(aElement, aStyleContext->GetPseudoType());
+ CSSAnimationBuilder builder(aStyleContext, target);
+ const nsStyleDisplay* disp = aStyleContext->StyleDisplay();
+ DoUpdateAnimations(target, *disp, builder);
+}
+
+void
+nsAnimationManager::DoUpdateAnimations(
+ const NonOwningAnimationTarget& aTarget,
+ const nsStyleDisplay& aStyleDisplay,
+ CSSAnimationBuilder& aBuilder)
+{
// Everything that causes our animation data to change triggers a
// style change, which in turn triggers a non-animation restyle.
// Likewise, when we initially construct frames, we're not in a
// style change, but also not in an animation restyle.
- const nsStyleDisplay* disp = aStyleContext->StyleDisplay();
CSSAnimationCollection* collection =
- CSSAnimationCollection::GetAnimationCollection(target.mElement,
- target.mPseudoType);
+ CSSAnimationCollection::GetAnimationCollection(aTarget.mElement,
+ aTarget.mPseudoType);
if (!collection &&
- disp->mAnimationNameCount == 1 &&
- disp->mAnimations[0].GetName().IsEmpty()) {
+ aStyleDisplay.mAnimationNameCount == 1 &&
+ aStyleDisplay.mAnimations[0].GetName().IsEmpty()) {
return;
}
- nsAutoAnimationMutationBatch mb(aElement->OwnerDoc());
+ nsAutoAnimationMutationBatch mb(aTarget.mElement->OwnerDoc());
// Build the updated animations list, extracting matching animations from
// the existing collection as we go.
OwningCSSAnimationPtrArray newAnimations;
- if (!aStyleContext->IsInDisplayNoneSubtree()) {
- CSSAnimationBuilder builder(aStyleContext, target);
-
- newAnimations = BuildAnimations(mPresContext,
- target,
- disp->mAnimations,
- disp->mAnimationNameCount,
- builder,
- collection);
- }
+ newAnimations = BuildAnimations(mPresContext,
+ aTarget,
+ aStyleDisplay.mAnimations,
+ aStyleDisplay.mAnimationNameCount,
+ aBuilder,
+ collection);
if (newAnimations.IsEmpty()) {
if (collection) {
collection->Destroy();
}
return;
}
if (!collection) {
bool createdCollection = false;
collection =
CSSAnimationCollection::GetOrCreateAnimationCollection(
- target.mElement, target.mPseudoType, &createdCollection);
+ aTarget.mElement, aTarget.mPseudoType, &createdCollection);
if (!collection) {
MOZ_ASSERT(!createdCollection, "outparam should agree with return value");
NS_WARNING("allocating collection failed");
return;
}
if (createdCollection) {
AddElementCollection(collection);
@@ -1132,9 +1143,8 @@ nsAnimationManager::UpdateAnimations(nsS
}
collection->mAnimations.SwapElements(newAnimations);
// Cancel removed animations
for (size_t newAnimIdx = newAnimations.Length(); newAnimIdx-- != 0; ) {
newAnimations[newAnimIdx]->CancelFromStyle();
}
}
-
--- a/layout/style/nsAnimationManager.h
+++ b/layout/style/nsAnimationManager.h
@@ -10,16 +10,18 @@
#include "mozilla/EventForwards.h"
#include "AnimationCommon.h"
#include "mozilla/dom/Animation.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/TimeStamp.h"
class nsIGlobalObject;
class nsStyleContext;
+class CSSAnimationBuilder; // tentative, will be removed
+struct nsStyleDisplay;
namespace mozilla {
namespace css {
class Declaration;
} /* namespace css */
namespace dom {
class KeyframeEffectReadOnly;
class Promise;
@@ -350,12 +352,17 @@ public:
// ::before and ::after.
void StopAnimationsForElement(mozilla::dom::Element* aElement,
mozilla::CSSPseudoElementType aPseudoType);
protected:
~nsAnimationManager() override = default;
private:
+ void DoUpdateAnimations(
+ const mozilla::NonOwningAnimationTarget& aTarget,
+ const nsStyleDisplay& aStyleDisplay,
+ CSSAnimationBuilder& aBuilder);
+
mozilla::DelayedEventDispatcher<mozilla::AnimationEventInfo> mEventDispatcher;
};
#endif /* !defined(nsAnimationManager_h_) */