Bug 1232561 part 3 - Move AnimValuesStyleRule to a separate file; r=heycam
authorBrian Birtles <birtles@gmail.com>
Wed, 06 Jan 2016 11:04:06 +0900
changeset 315642 32728ff57fcf51fb0d4f7281e3c57c22165015d4
parent 315641 8ab3174e31a51247c328344154c0511767c58b2a
child 315643 df95b504dc3baac86cc2014a9ea305aa1544cf10
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1232561
milestone46.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 1232561 part 3 - Move AnimValuesStyleRule to a separate file; r=heycam As we gradually move logic from layout/style/AnimationCommon.cpp to dom/animation/EffectSet and EffectCompositor it makes sense to let this class live in its own file inside dom/animation where it is used.
dom/animation/AnimValuesStyleRule.cpp
dom/animation/AnimValuesStyleRule.h
dom/animation/EffectSet.h
dom/animation/moz.build
layout/style/AnimationCommon.cpp
layout/style/AnimationCommon.h
new file mode 100644
--- /dev/null
+++ b/dom/animation/AnimValuesStyleRule.cpp
@@ -0,0 +1,81 @@
+/* -*- 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 "AnimValuesStyleRule.h"
+#include "nsRuleData.h"
+#include "nsStyleContext.h"
+
+namespace mozilla {
+
+NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
+
+void
+AnimValuesStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
+{
+  nsStyleContext *contextParent = aRuleData->mStyleContext->GetParent();
+  if (contextParent && contextParent->HasPseudoElementData()) {
+    // Don't apply transitions or animations to things inside of
+    // pseudo-elements.
+    // FIXME (Bug 522599): Add tests for this.
+
+    // Prevent structs from being cached on the rule node since we're inside
+    // a pseudo-element, as we could determine cacheability differently
+    // when walking the rule tree for a style context that is not inside
+    // a pseudo-element.  Note that nsRuleNode::GetStyle##name_ and GetStyleData
+    // will never look at cached structs when we're animating things inside
+    // a pseduo-element, so that we don't incorrectly return a struct that
+    // is only appropriate for non-pseudo-elements.
+    aRuleData->mConditions.SetUncacheable();
+    return;
+  }
+
+  for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
+    PropertyValuePair &cv = mPropertyValuePairs[i];
+    if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
+                             nsCSSProps::kSIDTable[cv.mProperty]))
+    {
+      nsCSSValue *prop = aRuleData->ValueFor(cv.mProperty);
+      if (prop->GetUnit() == eCSSUnit_Null) {
+#ifdef DEBUG
+        bool ok =
+#endif
+          StyleAnimationValue::UncomputeValue(cv.mProperty, cv.mValue, *prop);
+        MOZ_ASSERT(ok, "could not store computed value");
+      }
+    }
+  }
+}
+
+bool
+AnimValuesStyleRule::MightMapInheritedStyleData()
+{
+  return mStyleBits & NS_STYLE_INHERITED_STRUCT_MASK;
+}
+
+#ifdef DEBUG
+void
+AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
+{
+  nsAutoCString str;
+  for (int32_t index = aIndent; --index >= 0; ) {
+    str.AppendLiteral("  ");
+  }
+  str.AppendLiteral("[anim values] { ");
+  for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
+    const PropertyValuePair &pair = mPropertyValuePairs[i];
+    str.Append(nsCSSProps::GetStringValue(pair.mProperty));
+    str.AppendLiteral(": ");
+    nsAutoString value;
+    StyleAnimationValue::UncomputeValue(pair.mProperty, pair.mValue, value);
+    AppendUTF16toUTF8(value, str);
+    str.AppendLiteral("; ");
+  }
+  str.AppendLiteral("}\n");
+  fprintf_stderr(out, "%s", str.get());
+}
+#endif
+
+} // namespace mozilla
new file mode 100644
--- /dev/null
+++ b/dom/animation/AnimValuesStyleRule.h
@@ -0,0 +1,79 @@
+/* -*- 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_AnimValuesStyleRule_h
+#define mozilla_AnimValuesStyleRule_h
+
+#include "mozilla/StyleAnimationValue.h"
+#include "nsCSSProperty.h"
+#include "nsCSSPropertySet.h"
+#include "nsIStyleRule.h"
+#include "nsISupportsImpl.h" // For NS_DECL_ISUPPORTS
+#include "nsRuleNode.h" // For nsCachedStyleData
+#include "nsTArray.h" // For nsTArray
+
+namespace mozilla {
+
+/**
+ * A style rule that maps property-StyleAnimationValue pairs.
+ */
+class AnimValuesStyleRule final : public nsIStyleRule
+{
+public:
+  AnimValuesStyleRule()
+    : mStyleBits(0) {}
+
+  // nsISupports implementation
+  NS_DECL_ISUPPORTS
+
+  // nsIStyleRule implementation
+  void MapRuleInfoInto(nsRuleData* aRuleData) override;
+  bool MightMapInheritedStyleData() override;
+#ifdef DEBUG
+  void List(FILE* out = stdout, int32_t aIndent = 0) const override;
+#endif
+
+  void AddValue(nsCSSProperty aProperty, StyleAnimationValue &aStartValue)
+  {
+    PropertyValuePair v = { aProperty, aStartValue };
+    mPropertyValuePairs.AppendElement(v);
+    mStyleBits |=
+      nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
+  }
+
+  // Caller must fill in returned value.
+  StyleAnimationValue* AddEmptyValue(nsCSSProperty aProperty)
+  {
+    PropertyValuePair *p = mPropertyValuePairs.AppendElement();
+    p->mProperty = aProperty;
+    mStyleBits |=
+      nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
+    return &p->mValue;
+  }
+
+  struct PropertyValuePair {
+    nsCSSProperty mProperty;
+    StyleAnimationValue mValue;
+  };
+
+  void AddPropertiesToSet(nsCSSPropertySet& aSet) const
+  {
+    for (size_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
+      const PropertyValuePair &cv = mPropertyValuePairs[i];
+      aSet.AddProperty(cv.mProperty);
+    }
+  }
+
+private:
+  ~AnimValuesStyleRule() {}
+
+  InfallibleTArray<PropertyValuePair> mPropertyValuePairs;
+  uint32_t mStyleBits;
+};
+
+} // namespace mozilla
+
+#endif // mozilla_AnimValuesStyleRule_h
--- a/dom/animation/EffectSet.h
+++ b/dom/animation/EffectSet.h
@@ -2,19 +2,19 @@
 /* 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_EffectSet_h
 #define mozilla_EffectSet_h
 
+#include "mozilla/AnimValuesStyleRule.h"
 #include "mozilla/EffectCompositor.h"
 #include "mozilla/EnumeratedArray.h"
-#include "AnimationCommon.h" // For AnimValuesStyleRule
 #include "nsCSSPseudoElements.h" // For nsCSSPseudoElements::Type
 #include "nsHashKeys.h" // For nsPtrHashKey
 #include "nsTHashtable.h" // For nsTHashtable
 
 class nsPresContext;
 
 namespace mozilla {
 
--- a/dom/animation/moz.build
+++ b/dom/animation/moz.build
@@ -13,27 +13,29 @@ EXPORTS.mozilla.dom += [
     'AnimationTimeline.h',
     'DocumentTimeline.h',
     'KeyframeEffect.h',
 ]
 
 EXPORTS.mozilla += [
     'AnimationComparator.h',
     'AnimationUtils.h',
+    'AnimValuesStyleRule.h',
     'ComputedTimingFunction.h',
     'EffectCompositor.h',
     'EffectSet.h',
     'PendingAnimationTracker.h',
 ]
 
 UNIFIED_SOURCES += [
     'Animation.cpp',
     'AnimationEffectReadOnly.cpp',
     'AnimationTimeline.cpp',
     'AnimationUtils.cpp',
+    'AnimValuesStyleRule.cpp',
     'ComputedTimingFunction.cpp',
     'DocumentTimeline.cpp',
     'EffectCompositor.cpp',
     'EffectSet.cpp',
     'KeyframeEffect.cpp',
     'PendingAnimationTracker.cpp',
 ]
 
--- a/layout/style/AnimationCommon.cpp
+++ b/layout/style/AnimationCommon.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "AnimationCommon.h"
 #include "nsTransitionManager.h"
 #include "nsAnimationManager.h"
 
 #include "ActiveLayerTracker.h"
 #include "gfxPlatform.h"
-#include "nsRuleData.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"
@@ -337,84 +336,16 @@ CommonAnimationManager::ClearIsRunningOn
     return;
   }
 
   for (KeyframeEffectReadOnly* effect : *effects) {
     effect->SetIsRunningOnCompositor(aProperty, false);
   }
 }
 
-NS_IMPL_ISUPPORTS(AnimValuesStyleRule, nsIStyleRule)
-
-/* virtual */ void
-AnimValuesStyleRule::MapRuleInfoInto(nsRuleData* aRuleData)
-{
-  nsStyleContext *contextParent = aRuleData->mStyleContext->GetParent();
-  if (contextParent && contextParent->HasPseudoElementData()) {
-    // Don't apply transitions or animations to things inside of
-    // pseudo-elements.
-    // FIXME (Bug 522599): Add tests for this.
-
-    // Prevent structs from being cached on the rule node since we're inside
-    // a pseudo-element, as we could determine cacheability differently
-    // when walking the rule tree for a style context that is not inside
-    // a pseudo-element.  Note that nsRuleNode::GetStyle##name_ and GetStyleData
-    // will never look at cached structs when we're animating things inside
-    // a pseduo-element, so that we don't incorrectly return a struct that
-    // is only appropriate for non-pseudo-elements.
-    aRuleData->mConditions.SetUncacheable();
-    return;
-  }
-
-  for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
-    PropertyValuePair &cv = mPropertyValuePairs[i];
-    if (aRuleData->mSIDs & nsCachedStyleData::GetBitForSID(
-                             nsCSSProps::kSIDTable[cv.mProperty]))
-    {
-      nsCSSValue *prop = aRuleData->ValueFor(cv.mProperty);
-      if (prop->GetUnit() == eCSSUnit_Null) {
-#ifdef DEBUG
-        bool ok =
-#endif
-          StyleAnimationValue::UncomputeValue(cv.mProperty, cv.mValue, *prop);
-        MOZ_ASSERT(ok, "could not store computed value");
-      }
-    }
-  }
-}
-
-/* virtual */ bool
-AnimValuesStyleRule::MightMapInheritedStyleData()
-{
-  return mStyleBits & NS_STYLE_INHERITED_STRUCT_MASK;
-}
-
-#ifdef DEBUG
-/* virtual */ void
-AnimValuesStyleRule::List(FILE* out, int32_t aIndent) const
-{
-  nsAutoCString str;
-  for (int32_t index = aIndent; --index >= 0; ) {
-    str.AppendLiteral("  ");
-  }
-  str.AppendLiteral("[anim values] { ");
-  for (uint32_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
-    const PropertyValuePair &pair = mPropertyValuePairs[i];
-    str.Append(nsCSSProps::GetStringValue(pair.mProperty));
-    str.AppendLiteral(": ");
-    nsAutoString value;
-    StyleAnimationValue::UncomputeValue(pair.mProperty, pair.mValue, value);
-    AppendUTF16toUTF8(value, str);
-    str.AppendLiteral("; ");
-  }
-  str.AppendLiteral("}\n");
-  fprintf_stderr(out, "%s", str.get());
-}
-#endif
-
 /*static*/ nsString
 AnimationCollection::PseudoTypeAsString(nsCSSPseudoElements::Type aPseudoType)
 {
   switch (aPseudoType) {
     case nsCSSPseudoElements::ePseudo_before:
       return NS_LITERAL_STRING("::before");
     case nsCSSPseudoElements::ePseudo_after:
       return NS_LITERAL_STRING("::after");
--- a/layout/style/AnimationCommon.h
+++ b/layout/style/AnimationCommon.h
@@ -3,38 +3,36 @@
  * 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 "nsIStyleRuleProcessor.h"
-#include "nsIStyleRule.h"
 #include "nsChangeHint.h"
 #include "nsCSSProperty.h"
 #include "nsDisplayList.h" // For nsDisplayItem::Type
 #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 "nsStyleStruct.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/FloatingPoint.h"
 #include "nsContentUtils.h"
 #include "nsCSSPseudoElements.h"
 #include "nsCycleCollectionParticipant.h"
-#include "nsCSSPropertySet.h"
 
 class nsIFrame;
+class nsIStyleRule;
 class nsPresContext;
 
 namespace mozilla {
 
 class RestyleTracker;
 struct AnimationCollection;
 
 class CommonAnimationManager : public nsIStyleRuleProcessor {
@@ -130,73 +128,16 @@ public:
 
   void ClearIsRunningOnCompositor(const nsIFrame *aFrame,
                                   nsCSSProperty aProperty);
 protected:
   LinkedList<AnimationCollection> mElementCollections;
   nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
 };
 
-/**
- * A style rule that maps property-StyleAnimationValue pairs.
- */
-class AnimValuesStyleRule final : public nsIStyleRule
-{
-public:
-  AnimValuesStyleRule()
-    : mStyleBits(0) {}
-
-  // nsISupports implementation
-  NS_DECL_ISUPPORTS
-
-  // nsIStyleRule implementation
-  virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
-  virtual bool MightMapInheritedStyleData() override;
-#ifdef DEBUG
-  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
-#endif
-
-  void AddValue(nsCSSProperty aProperty, StyleAnimationValue &aStartValue)
-  {
-    PropertyValuePair v = { aProperty, aStartValue };
-    mPropertyValuePairs.AppendElement(v);
-    mStyleBits |=
-      nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
-  }
-
-  // Caller must fill in returned value.
-  StyleAnimationValue* AddEmptyValue(nsCSSProperty aProperty)
-  {
-    PropertyValuePair *p = mPropertyValuePairs.AppendElement();
-    p->mProperty = aProperty;
-    mStyleBits |=
-      nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]);
-    return &p->mValue;
-  }
-
-  struct PropertyValuePair {
-    nsCSSProperty mProperty;
-    StyleAnimationValue mValue;
-  };
-
-  void AddPropertiesToSet(nsCSSPropertySet& aSet) const
-  {
-    for (size_t i = 0, i_end = mPropertyValuePairs.Length(); i < i_end; ++i) {
-      const PropertyValuePair &cv = mPropertyValuePairs[i];
-      aSet.AddProperty(cv.mProperty);
-    }
-  }
-
-private:
-  ~AnimValuesStyleRule() {}
-
-  InfallibleTArray<PropertyValuePair> mPropertyValuePairs;
-  uint32_t mStyleBits;
-};
-
 typedef InfallibleTArray<RefPtr<dom::Animation>> AnimationPtrArray;
 
 struct AnimationCollection : public LinkedListElement<AnimationCollection>
 {
   AnimationCollection(dom::Element *aElement, nsIAtom *aElementProperty,
                       CommonAnimationManager *aManager)
     : mElement(aElement)
     , mElementProperty(aElementProperty)