Bug 1239945 part 3 - Move AnimationCollection to a separate file; r=dholbert
authorBrian Birtles <birtles@gmail.com>
Wed, 24 Feb 2016 16:08:20 +0900
changeset 321850 4e3a832dbdba397425a226050a6195b54fd95393
parent 321849 1f552b246eb40e792ad456cff0642f85a01da04b
child 321851 f0a24d67478b23e1f7f2e51e9f9938f2fb0f57b3
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1239945
milestone47.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 1239945 part 3 - Move AnimationCollection to a separate file; r=dholbert In this bug we will trim off unnecessary functionality from the animation managers and make AnimationCollection into an independent data type so in this patch we separate it into its own file. It is also generally easier to navigate the source code and eliminate cyclic dependencies between header files when there is a rough correspondance between class names and file names (e.g. rather than having #include "AnimationCommon.h" // For mozilla::AnimationCollection). This patch also makes a few simplifications to include dependencies since they're a bit of a mess (making it hard to move code around). The changes to IncrementalClearCOMRuleArray.cpp are due to the changes to the unified build introduced by adding AnimationCollection.cpp exposing a missing include from that file.
layout/style/AnimationCollection.cpp
layout/style/AnimationCollection.h
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
layout/style/IncrementalClearCOMRuleArray.cpp
layout/style/moz.build
layout/style/nsTransitionManager.h
new file mode 100644
--- /dev/null
+++ b/layout/style/AnimationCollection.cpp
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/AnimationCollection.h"
+
+#include "mozilla/RestyleManagerHandle.h"
+#include "mozilla/RestyleManagerHandleInlines.h"
+#include "nsPresContext.h"
+
+namespace mozilla {
+
+/* static */ void
+AnimationCollection::PropertyDtor(void* aObject, nsIAtom* aPropertyName,
+                                  void* aPropertyValue, void* aData)
+{
+  AnimationCollection* collection =
+    static_cast<AnimationCollection*>(aPropertyValue);
+#ifdef DEBUG
+  MOZ_ASSERT(!collection->mCalledPropertyDtor, "can't call dtor twice");
+  collection->mCalledPropertyDtor = true;
+#endif
+  {
+    nsAutoAnimationMutationBatch mb(collection->mElement->OwnerDoc());
+
+    for (size_t animIdx = collection->mAnimations.Length(); animIdx-- != 0; ) {
+      collection->mAnimations[animIdx]->CancelFromStyle();
+    }
+  }
+  delete collection;
+}
+
+/* static */ nsString
+AnimationCollection::PseudoTypeAsString(CSSPseudoElementType aPseudoType)
+{
+  switch (aPseudoType) {
+    case CSSPseudoElementType::before:
+      return NS_LITERAL_STRING("::before");
+    case CSSPseudoElementType::after:
+      return NS_LITERAL_STRING("::after");
+    default:
+      MOZ_ASSERT(aPseudoType == CSSPseudoElementType::NotPseudo,
+                 "Unexpected pseudo type");
+      return EmptyString();
+  }
+}
+
+void
+AnimationCollection::UpdateCheckGeneration(nsPresContext* aPresContext)
+{
+  if (aPresContext->RestyleManager()->IsServo()) {
+    // stylo: ServoRestyleManager does not support animations yet.
+    return;
+  }
+  mCheckGeneration =
+    aPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration();
+}
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/layout/style/AnimationCollection.h
@@ -0,0 +1,117 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_AnimationCollection_h
+#define mozilla_AnimationCollection_h
+
+#include "mozilla/dom/Animation.h"
+#include "mozilla/dom/Element.h"
+#include "mozilla/Assertions.h"
+#include "mozilla/LinkedList.h"
+#include "mozilla/RefPtr.h"
+#include "nsCSSPseudoElements.h"
+#include "nsDOMMutationObserver.h"
+#include "nsTArray.h"
+
+class nsIAtom;
+class nsPresContext;
+
+namespace mozilla {
+
+class CommonAnimationManager;
+typedef InfallibleTArray<RefPtr<dom::Animation>> AnimationPtrArray;
+
+struct AnimationCollection : public LinkedListElement<AnimationCollection>
+{
+  AnimationCollection(dom::Element *aElement, nsIAtom *aElementProperty,
+                      CommonAnimationManager *aManager)
+    : mElement(aElement)
+    , mElementProperty(aElementProperty)
+    , mManager(aManager)
+    , mCheckGeneration(0)
+#ifdef DEBUG
+    , mCalledPropertyDtor(false)
+#endif
+  {
+    MOZ_COUNT_CTOR(AnimationCollection);
+  }
+  ~AnimationCollection()
+  {
+    MOZ_ASSERT(mCalledPropertyDtor,
+               "must call destructor through element property dtor");
+    MOZ_COUNT_DTOR(AnimationCollection);
+    remove();
+  }
+
+  void Destroy()
+  {
+    // This will call our destructor.
+    mElement->DeleteProperty(mElementProperty);
+  }
+
+  static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
+                           void *aPropertyValue, void *aData);
+
+public:
+  bool IsForElement() const { // rather than for a pseudo-element
+    return mElementProperty == nsGkAtoms::animationsProperty ||
+           mElementProperty == nsGkAtoms::transitionsProperty;
+  }
+
+  bool IsForBeforePseudo() const {
+    return mElementProperty == nsGkAtoms::animationsOfBeforeProperty ||
+           mElementProperty == nsGkAtoms::transitionsOfBeforeProperty;
+  }
+
+  bool IsForAfterPseudo() const {
+    return mElementProperty == nsGkAtoms::animationsOfAfterProperty ||
+           mElementProperty == nsGkAtoms::transitionsOfAfterProperty;
+  }
+
+  CSSPseudoElementType PseudoElementType() const
+  {
+    if (IsForElement()) {
+      return CSSPseudoElementType::NotPseudo;
+    }
+    if (IsForBeforePseudo()) {
+      return CSSPseudoElementType::before;
+    }
+    MOZ_ASSERT(IsForAfterPseudo(),
+               "::before & ::after should be the only pseudo-elements here");
+    return CSSPseudoElementType::after;
+  }
+
+  static nsString PseudoTypeAsString(CSSPseudoElementType aPseudoType);
+
+  dom::Element *mElement;
+
+  // the atom we use in mElement's prop table (must be a static atom,
+  // i.e., in an atom list)
+  nsIAtom *mElementProperty;
+
+  CommonAnimationManager *mManager;
+
+  AnimationPtrArray mAnimations;
+
+  // For CSS transitions only, we record the most recent generation
+  // for which we've done the transition update, so that we avoid doing
+  // it more than once per style change.
+  // (Note that we also store an animation generation on each EffectSet in
+  // order to track when we need to update animations on layers.)
+  uint64_t mCheckGeneration;
+
+  // Update mCheckGeneration to RestyleManager's count
+  void UpdateCheckGeneration(nsPresContext* aPresContext);
+
+private:
+#ifdef DEBUG
+  bool mCalledPropertyDtor;
+#endif
+};
+
+} // namespace mozilla
+
+#endif // mozilla_AnimationCollection_h
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -7,29 +7,26 @@
 #include "nsTransitionManager.h"
 #include "nsAnimationManager.h"
 
 #include "ActiveLayerTracker.h"
 #include "gfxPlatform.h"
 #include "nsCSSPropertySet.h"
 #include "nsCSSValue.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsDOMMutationObserver.h"
 #include "nsStyleContext.h"
 #include "nsIFrame.h"
 #include "nsLayoutUtils.h"
 #include "FrameLayerBuilder.h"
 #include "nsDisplayList.h"
 #include "mozilla/AnimationUtils.h"
 #include "mozilla/EffectCompositor.h"
 #include "mozilla/EffectSet.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/KeyframeEffect.h"
-#include "mozilla/RestyleManagerHandle.h"
-#include "mozilla/RestyleManagerHandleInlines.h"
 #include "nsRuleProcessorData.h"
 #include "nsStyleSet.h"
 #include "nsStyleChangeList.h"
 
 using mozilla::dom::Animation;
 using mozilla::dom::KeyframeEffectReadOnly;
 
 namespace mozilla {
@@ -147,62 +144,16 @@ CommonAnimationManager::ExtractComputedV
                  StyleAnimationValue::eUnit_Enumerated,
                "unexpected unit");
     aComputedValue.SetIntValue(aComputedValue.GetIntValue(),
                                StyleAnimationValue::eUnit_Visibility);
   }
   return result;
 }
 
-/*static*/ nsString
-AnimationCollection::PseudoTypeAsString(CSSPseudoElementType aPseudoType)
-{
-  switch (aPseudoType) {
-    case CSSPseudoElementType::before:
-      return NS_LITERAL_STRING("::before");
-    case CSSPseudoElementType::after:
-      return NS_LITERAL_STRING("::after");
-    default:
-      MOZ_ASSERT(aPseudoType == CSSPseudoElementType::NotPseudo,
-                 "Unexpected pseudo type");
-      return EmptyString();
-  }
-}
-
-/*static*/ void
-AnimationCollection::PropertyDtor(void *aObject, nsIAtom *aPropertyName,
-                                  void *aPropertyValue, void *aData)
-{
-  AnimationCollection* collection =
-    static_cast<AnimationCollection*>(aPropertyValue);
-#ifdef DEBUG
-  MOZ_ASSERT(!collection->mCalledPropertyDtor, "can't call dtor twice");
-  collection->mCalledPropertyDtor = true;
-#endif
-  {
-    nsAutoAnimationMutationBatch mb(collection->mElement->OwnerDoc());
-
-    for (size_t animIdx = collection->mAnimations.Length(); animIdx-- != 0; ) {
-      collection->mAnimations[animIdx]->CancelFromStyle();
-    }
-  }
-  delete collection;
-}
-
-void
-AnimationCollection::UpdateCheckGeneration(
-  nsPresContext* aPresContext)
-{
-  if (aPresContext->RestyleManager()->IsServo()) {
-    // stylo: ServoRestyleManager does not support animations yet.
-    return;
-  }
-  mCheckGeneration =
-    aPresContext->RestyleManager()->AsGecko()->GetAnimationGeneration();
-}
 
 nsPresContext*
 OwningElementRef::GetRenderedPresContext() const
 {
   if (!mElement) {
     return nullptr;
   }
 
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -2,40 +2,38 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_css_AnimationCommon_h
 #define mozilla_css_AnimationCommon_h
 
 #include <algorithm> // For <std::stable_sort>
-#include "nsChangeHint.h"
-#include "nsCSSProperty.h"
-#include "nsDisplayList.h" // For nsDisplayItem::Type
+#include "mozilla/AnimationCollection.h"
 #include "mozilla/AnimationComparator.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/LinkedList.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/StyleAnimationValue.h"
 #include "mozilla/dom/Animation.h"
-#include "mozilla/dom/Element.h"
-#include "mozilla/dom/Nullable.h"
-#include "mozilla/Attributes.h"
+#include "mozilla/Attributes.h" // For MOZ_NON_OWNING_REF
 #include "mozilla/Assertions.h"
-#include "mozilla/FloatingPoint.h"
 #include "nsContentUtils.h"
+#include "nsCSSProperty.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCycleCollectionParticipant.h"
 
 class nsIFrame;
 class nsPresContext;
 
 namespace mozilla {
 
-struct AnimationCollection;
+namespace dom {
+class Element;
+}
 
 class CommonAnimationManager {
 public:
   explicit CommonAnimationManager(nsPresContext *aPresContext);
 
   // NOTE:  This can return null after Disconnect().
   nsPresContext* PresContext() const { return mPresContext; }
 
@@ -73,105 +71,16 @@ public:
   AnimationCollection*
   GetAnimationCollection(const nsIFrame* aFrame);
 
 protected:
   LinkedList<AnimationCollection> mElementCollections;
   nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
 };
 
-typedef InfallibleTArray<RefPtr<dom::Animation>> AnimationPtrArray;
-
-struct AnimationCollection : public LinkedListElement<AnimationCollection>
-{
-  AnimationCollection(dom::Element *aElement, nsIAtom *aElementProperty,
-                      CommonAnimationManager *aManager)
-    : mElement(aElement)
-    , mElementProperty(aElementProperty)
-    , mManager(aManager)
-    , mCheckGeneration(0)
-#ifdef DEBUG
-    , mCalledPropertyDtor(false)
-#endif
-  {
-    MOZ_COUNT_CTOR(AnimationCollection);
-  }
-  ~AnimationCollection()
-  {
-    MOZ_ASSERT(mCalledPropertyDtor,
-               "must call destructor through element property dtor");
-    MOZ_COUNT_DTOR(AnimationCollection);
-    remove();
-  }
-
-  void Destroy()
-  {
-    // This will call our destructor.
-    mElement->DeleteProperty(mElementProperty);
-  }
-
-  static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
-                           void *aPropertyValue, void *aData);
-
-public:
-  bool IsForElement() const { // rather than for a pseudo-element
-    return mElementProperty == nsGkAtoms::animationsProperty ||
-           mElementProperty == nsGkAtoms::transitionsProperty;
-  }
-
-  bool IsForBeforePseudo() const {
-    return mElementProperty == nsGkAtoms::animationsOfBeforeProperty ||
-           mElementProperty == nsGkAtoms::transitionsOfBeforeProperty;
-  }
-
-  bool IsForAfterPseudo() const {
-    return mElementProperty == nsGkAtoms::animationsOfAfterProperty ||
-           mElementProperty == nsGkAtoms::transitionsOfAfterProperty;
-  }
-
-  CSSPseudoElementType PseudoElementType() const
-  {
-    if (IsForElement()) {
-      return CSSPseudoElementType::NotPseudo;
-    }
-    if (IsForBeforePseudo()) {
-      return CSSPseudoElementType::before;
-    }
-    MOZ_ASSERT(IsForAfterPseudo(),
-               "::before & ::after should be the only pseudo-elements here");
-    return CSSPseudoElementType::after;
-  }
-
-  static nsString PseudoTypeAsString(CSSPseudoElementType aPseudoType);
-
-  dom::Element *mElement;
-
-  // the atom we use in mElement's prop table (must be a static atom,
-  // i.e., in an atom list)
-  nsIAtom *mElementProperty;
-
-  CommonAnimationManager *mManager;
-
-  AnimationPtrArray mAnimations;
-
-  // For CSS transitions only, we record the most recent generation
-  // for which we've done the transition update, so that we avoid doing
-  // it more than once per style change.
-  // (Note that we also store an animation generation on each EffectSet in
-  // order to track when we need to update animations on layers.)
-  uint64_t mCheckGeneration;
-  // Update mCheckGeneration to RestyleManager's count
-  void UpdateCheckGeneration(nsPresContext* aPresContext);
-
-private:
-#ifdef DEBUG
-  bool mCalledPropertyDtor;
-#endif
-};
-
 /**
  * Utility class for referencing the element that created a CSS animation or
  * transition. It is non-owning (i.e. it uses a raw pointer) since it is only
  * expected to be set by the owned animation while it actually being managed
  * by the owning element.
  *
  * This class also abstracts the comparison of an element/pseudo-class pair
  * for the sake of composite ordering since this logic is common to both CSS
--- a/layout/style/IncrementalClearCOMRuleArray.cpp
+++ b/layout/style/IncrementalClearCOMRuleArray.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/IncrementalClearCOMRuleArray.h"
 
+#include <algorithm> // For std::min
 #include "nsCycleCollector.h"
 #include "mozilla/DeferredFinalize.h"
 #include "nsTArray.h"
 #include "nsCCUncollectableMarker.h"
 
 using namespace mozilla;
 
 typedef nsCOMArray<css::Rule> RuleArray;
--- a/layout/style/moz.build
+++ b/layout/style/moz.build
@@ -75,16 +75,17 @@ EXPORTS += [
     'nsStyleStruct.h',
     'nsStyleStructFwd.h',
     'nsStyleStructInlines.h',
     'nsStyleTransformMatrix.h',
     'nsStyleUtil.h',
 ]
 
 EXPORTS.mozilla += [
+    'AnimationCollection.h',
     'CSSStyleSheet.h',
     'CSSVariableDeclarations.h',
     'CSSVariableResolver.h',
     'CSSVariableValues.h',
     'HandleRefPtr.h',
     'IncrementalClearCOMRuleArray.h',
     'LayerAnimationInfo.h',
     'RuleNodeCacheConditions.h',
@@ -121,16 +122,17 @@ EXPORTS.mozilla.css += [
     'Loader.h',
     'NameSpaceRule.h',
     'Rule.h',
     'SheetParsingMode.h',
     'StyleRule.h',
 ]
 
 UNIFIED_SOURCES += [
+    'AnimationCollection.cpp',
     'AnimationCommon.cpp',
     'CounterStyleManager.cpp',
     'CSS.cpp',
     'CSSLexer.cpp',
     'CSSRuleList.cpp',
     'CSSStyleSheet.cpp',
     'CSSVariableDeclarations.cpp',
     'CSSVariableResolver.cpp',
--- a/layout/style/nsTransitionManager.h
+++ b/layout/style/nsTransitionManager.h
@@ -3,22 +3,21 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* Code to start and animate CSS transitions. */
 
 #ifndef nsTransitionManager_h_
 #define nsTransitionManager_h_
 
-#include "mozilla/Attributes.h"
 #include "mozilla/ContentEvents.h"
 #include "mozilla/EffectCompositor.h" // For EffectCompositor::CascadeLevel
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/dom/Animation.h"
-#include "mozilla/dom/KeyframeEffect.h"
+#include "mozilla/dom/KeyframeEffect.h" // For KeyframeEffectReadOnly
 #include "AnimationCommon.h"
 #include "nsCSSProps.h"
 
 class nsIGlobalObject;
 class nsStyleContext;
 class nsPresContext;
 class nsCSSPropertySet;