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.

--HG--
extra : rebase_source : aed0632a19800e0ef9d8fe1d03d0364bf1ccc4dc
This commit is contained in:
Brian Birtles 2016-01-06 11:04:06 +09:00
Родитель a736eafacc
Коммит f4eeb573d0
6 изменённых файлов: 164 добавлений и 130 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -7,9 +7,9 @@
#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

Просмотреть файл

@ -18,6 +18,7 @@ EXPORTS.mozilla.dom += [
EXPORTS.mozilla += [
'AnimationComparator.h',
'AnimationUtils.h',
'AnimValuesStyleRule.h',
'ComputedTimingFunction.h',
'EffectCompositor.h',
'EffectSet.h',
@ -29,6 +30,7 @@ UNIFIED_SOURCES += [
'AnimationEffectReadOnly.cpp',
'AnimationTimeline.cpp',
'AnimationUtils.cpp',
'AnimValuesStyleRule.cpp',
'ComputedTimingFunction.cpp',
'DocumentTimeline.cpp',
'EffectCompositor.cpp',

Просмотреть файл

@ -9,7 +9,6 @@
#include "ActiveLayerTracker.h"
#include "gfxPlatform.h"
#include "nsRuleData.h"
#include "nsCSSPropertySet.h"
#include "nsCSSValue.h"
#include "nsCycleCollectionParticipant.h"
@ -342,74 +341,6 @@ CommonAnimationManager::ClearIsRunningOnCompositor(const nsIFrame* aFrame,
}
}
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)
{

Просмотреть файл

@ -8,7 +8,6 @@
#include <algorithm> // For <std::stable_sort>
#include "nsIStyleRuleProcessor.h"
#include "nsIStyleRule.h"
#include "nsChangeHint.h"
#include "nsCSSProperty.h"
#include "nsDisplayList.h" // For nsDisplayItem::Type
@ -20,16 +19,15 @@
#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 {
@ -135,63 +133,6 @@ protected:
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>