Bug 1626133 - Separate the portion of Element::GetAnimation which needs script from the part that doesn't. r=birtles
authorEmily McDonough <emcdonough@mozilla.com>
Tue, 31 Mar 2020 01:45:08 +0000
changeset 521196 404f1295f4bc2e9ce2641efb33032a3cbcf77d82
parent 521195 40aaa45ca9cb732ea501830eff808dc40f3bd4b6
child 521197 36699203e9901c2e4f2250c5260cd26f27cca42c
push id37268
push userapavel@mozilla.com
push dateTue, 31 Mar 2020 09:35:27 +0000
treeherdermozilla-central@e1672b3231e9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbirtles
bugs1626133
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1626133 - Separate the portion of Element::GetAnimation which needs script from the part that doesn't. r=birtles Also update the existing caller which doesn't need the flush that was causing the script requirement. Differential Revision: https://phabricator.services.mozilla.com/D68944
dom/base/DocumentOrShadowRoot.cpp
dom/base/Element.cpp
dom/base/Element.h
--- a/dom/base/DocumentOrShadowRoot.cpp
+++ b/dom/base/DocumentOrShadowRoot.cpp
@@ -586,17 +586,17 @@ void DocumentOrShadowRoot::GetAnimations
 
   GetAnimationsOptions options;
   options.mSubtree = true;
 
   for (RefPtr<nsIContent> child = AsNode().GetFirstChild(); child;
        child = child->GetNextSibling()) {
     if (RefPtr<Element> element = Element::FromNode(child)) {
       nsTArray<RefPtr<Animation>> result;
-      element->GetAnimations(options, result, Element::Flush::No);
+      element->GetAnimationsWithoutFlush(options, result);
       aAnimations.AppendElements(std::move(result));
     }
   }
 
   aAnimations.Sort(AnimationPtrComparator<RefPtr<Animation>>());
 }
 
 nsresult DocumentOrShadowRoot::WalkRadioGroup(const nsAString& aName,
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -3282,33 +3282,36 @@ already_AddRefed<Animation> Element::Ani
   if (aError.Failed()) {
     return nullptr;
   }
 
   return animation.forget();
 }
 
 void Element::GetAnimations(const GetAnimationsOptions& aOptions,
-                            nsTArray<RefPtr<Animation>>& aAnimations,
-                            Flush aFlush) {
-  if (aFlush == Flush::Yes) {
-    if (Document* doc = GetComposedDoc()) {
-      // We don't need to explicitly flush throttled animations here, since
-      // updating the animation style of elements will never affect the set of
-      // running animations and it's only the set of running animations that is
-      // important here.
-      //
-      // NOTE: Any changes to the flags passed to the following call should
-      // be reflected in the flags passed in DocumentOrShadowRoot::GetAnimations
-      // too.
-      doc->FlushPendingNotifications(
-          ChangesToFlush(FlushType::Style, false /* flush animations */));
-    }
-  }
-
+                            nsTArray<RefPtr<Animation>>& aAnimations) {
+  if (Document* doc = GetComposedDoc()) {
+    // We don't need to explicitly flush throttled animations here, since
+    // updating the animation style of elements will never affect the set of
+    // running animations and it's only the set of running animations that is
+    // important here.
+    //
+    // NOTE: Any changes to the flags passed to the following call should
+    // be reflected in the flags passed in DocumentOrShadowRoot::GetAnimations
+    // too.
+    doc->FlushPendingNotifications(
+        ChangesToFlush(FlushType::Style, false /* flush animations */));
+  }
+
+  GetAnimationsWithoutFlush(aOptions, aAnimations);
+}
+
+void Element::GetAnimationsWithoutFlush(
+    const GetAnimationsOptions& aOptions,
+    nsTArray<RefPtr<Animation>>& aAnimations) {
   Element* elem = this;
   PseudoStyleType pseudoType = PseudoStyleType::NotPseudo;
   // For animations on generated-content elements, the animations are stored
   // on the parent element.
   if (IsGeneratedContentContainerForBefore()) {
     elem = GetParentElement();
     pseudoType = PseudoStyleType::before;
   } else if (IsGeneratedContentContainerForAfter()) {
--- a/dom/base/Element.h
+++ b/dom/base/Element.h
@@ -1305,22 +1305,22 @@ class Element : public FragmentOrElement
   already_AddRefed<DOMMatrixReadOnly> GetTransformToParent();
   already_AddRefed<DOMMatrixReadOnly> GetTransformToViewport();
 
   already_AddRefed<Animation> Animate(
       JSContext* aContext, JS::Handle<JSObject*> aKeyframes,
       const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
       ErrorResult& aError);
 
-  enum class Flush { Yes, No };
-
   MOZ_CAN_RUN_SCRIPT
   void GetAnimations(const GetAnimationsOptions& aOptions,
-                     nsTArray<RefPtr<Animation>>& aAnimations,
-                     Flush aFlush = Flush::Yes);
+                     nsTArray<RefPtr<Animation>>& aAnimations);
+
+  void GetAnimationsWithoutFlush(const GetAnimationsOptions& aOptions,
+                                 nsTArray<RefPtr<Animation>>& aAnimations);
 
   static void GetAnimationsUnsorted(Element* aElement,
                                     PseudoStyleType aPseudoType,
                                     nsTArray<RefPtr<Animation>>& aAnimations);
 
   virtual void GetInnerHTML(nsAString& aInnerHTML, OOMReporter& aError);
   virtual void SetInnerHTML(const nsAString& aInnerHTML,
                             nsIPrincipal* aSubjectPrincipal,