diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index cae3a49eb6fc..baae4326c429 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -3318,6 +3318,13 @@ Element::GetAnimations(nsTArray>& aAnimations) doc->FlushPendingNotifications(Flush_Style); } + GetAnimationsUnsorted(aAnimations); + aAnimations.Sort(AnimationPtrComparator>()); +} + +void +Element::GetAnimationsUnsorted(nsTArray>& aAnimations) +{ EffectSet* effects = EffectSet::GetEffectSet(this, nsCSSPseudoElements::ePseudo_NotPseudoElement); if (!effects) { @@ -3335,8 +3342,6 @@ Element::GetAnimations(nsTArray>& aAnimations) "effect set"); aAnimations.AppendElement(animation); } - - aAnimations.Sort(AnimationPtrComparator>()); } NS_IMETHODIMP diff --git a/dom/base/Element.h b/dom/base/Element.h index a527486664ab..ef06d258bd49 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -821,7 +821,9 @@ public: { } + // Note: GetAnimations will flush style while GetAnimationsUnsorted won't. void GetAnimations(nsTArray>& aAnimations); + void GetAnimationsUnsorted(nsTArray>& aAnimations); NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML); virtual void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError); diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index cc2a4b07b490..7b71a86477ea 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -10,10 +10,12 @@ #include "nsDocument.h" +#include "mozilla/AnimationComparator.h" #include "mozilla/ArrayUtils.h" #include "mozilla/AutoRestore.h" #include "mozilla/BinarySearch.h" #include "mozilla/DebugOnly.h" +#include "mozilla/EffectSet.h" #include "mozilla/IntegerRange.h" #include "mozilla/MemoryReporting.h" #include "mozilla/Likely.h" @@ -3134,6 +3136,32 @@ nsDocument::Timeline() return mDocumentTimeline; } +void +nsDocument::GetAnimations(nsTArray>& aAnimations) +{ + FlushPendingNotifications(Flush_Style); + + // Bug 1174575: Until we implement a suitable PseudoElement interface we + // don't have anything to return for the |target| attribute of + // KeyframeEffect(ReadOnly) objects that refer to pseudo-elements. + // Rather than return some half-baked version of these objects (e.g. + // we a null effect attribute) we simply don't provide access to animations + // whose effect refers to a pseudo-element until we can support them + // properly. + for (nsIContent* node = nsINode::GetFirstChild(); + node; + node = node->GetNextNode(this)) { + if (!node->IsElement()) { + continue; + } + + node->AsElement()->GetAnimationsUnsorted(aAnimations); + } + + // Sort animations by priority + aAnimations.Sort(AnimationPtrComparator>()); +} + /* Return true if the document is in the focused top-level window, and is an * ancestor of the focused DOMWindow. */ NS_IMETHODIMP diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h index aa3499604bdd..7e75d573ff82 100644 --- a/dom/base/nsDocument.h +++ b/dom/base/nsDocument.h @@ -787,6 +787,8 @@ public: static bool IsWebAnimationsEnabled(JSContext* aCx, JSObject* aObject); virtual mozilla::dom::DocumentTimeline* Timeline() override; + virtual void GetAnimations( + nsTArray>& aAnimations) override; virtual nsresult SetSubDocumentFor(Element* aContent, nsIDocument* aSubDoc) override; diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 184504a95f0d..266f4a4ccb89 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -103,6 +103,7 @@ class Rule; } // namespace css namespace dom { +class Animation; class AnonymousContent; class Attr; class BoxObject; @@ -2156,6 +2157,9 @@ public: virtual mozilla::dom::DocumentTimeline* Timeline() = 0; + virtual void GetAnimations( + nsTArray>& aAnimations) = 0; + nsresult ScheduleFrameRequestCallback(mozilla::dom::FrameRequestCallback& aCallback, int32_t *aHandle); void CancelFrameRequestCallback(int32_t aHandle); diff --git a/dom/webidl/Document.webidl b/dom/webidl/Document.webidl index a103795fcec9..6241d9fc3933 100644 --- a/dom/webidl/Document.webidl +++ b/dom/webidl/Document.webidl @@ -303,6 +303,8 @@ partial interface Document { partial interface Document { [Func="nsDocument::IsWebAnimationsEnabled"] readonly attribute DocumentTimeline timeline; + [Func="nsDocument::IsWebAnimationsEnabled"] + sequence getAnimations(); }; // Mozilla extensions of various sorts