Bug 1195523: Use type-safe LinkedList instead of PRCList to manage AnimationCollection objects. r=birtles

This commit is contained in:
Daniel Holbert 2015-08-17 21:13:14 -07:00
parent 6f4d57d3e8
commit 6211954db9
2 changed files with 16 additions and 27 deletions

View File

@ -54,7 +54,6 @@ CommonAnimationManager::CommonAnimationManager(nsPresContext *aPresContext)
: mPresContext(aPresContext)
, mIsObservingRefreshDriver(false)
{
PR_INIT_CLIST(&mElementCollections);
}
CommonAnimationManager::~CommonAnimationManager()
@ -82,17 +81,15 @@ CommonAnimationManager::AddElementCollection(AnimationCollection* aCollection)
mIsObservingRefreshDriver = true;
}
PR_INSERT_BEFORE(aCollection, &mElementCollections);
mElementCollections.insertBack(aCollection);
}
void
CommonAnimationManager::RemoveAllElementCollections()
{
while (!PR_CLIST_IS_EMPTY(&mElementCollections)) {
AnimationCollection* head =
static_cast<AnimationCollection*>(PR_LIST_HEAD(&mElementCollections));
head->Destroy();
}
while (AnimationCollection* head = mElementCollections.getFirst()) {
head->Destroy(); // Note: this removes 'head' from mElementCollections.
}
}
void
@ -121,10 +118,9 @@ CommonAnimationManager::MaybeStartOrStopObservingRefreshDriver()
bool
CommonAnimationManager::NeedsRefresh() const
{
for (PRCList *l = PR_LIST_HEAD(&mElementCollections);
l != &mElementCollections;
l = PR_NEXT_LINK(l)) {
if (static_cast<AnimationCollection*>(l)->mNeedsRefreshes) {
for (const AnimationCollection* collection = mElementCollections.getFirst();
collection; collection = collection->getNext()) {
if (collection->mNeedsRefreshes) {
return true;
}
}
@ -284,11 +280,8 @@ CommonAnimationManager::AddStyleUpdatesTo(RestyleTracker& aTracker)
{
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
PRCList* next = PR_LIST_HEAD(&mElementCollections);
while (next != &mElementCollections) {
AnimationCollection* collection = static_cast<AnimationCollection*>(next);
next = PR_NEXT_LINK(next);
for (AnimationCollection* collection = mElementCollections.getFirst();
collection; collection = collection->getNext()) {
collection->EnsureStyleRuleFor(now);
dom::Element* elementToRestyle = collection->GetElementToRestyle();
@ -324,7 +317,7 @@ CommonAnimationManager::GetAnimations(dom::Element *aElement,
nsCSSPseudoElements::Type aPseudoType,
bool aCreateIfNeeded)
{
if (!aCreateIfNeeded && PR_CLIST_IS_EMPTY(&mElementCollections)) {
if (!aCreateIfNeeded && mElementCollections.isEmpty()) {
// Early return for the most common case.
return nullptr;
}
@ -371,11 +364,8 @@ void
CommonAnimationManager::FlushAnimations(FlushFlags aFlags)
{
TimeStamp now = mPresContext->RefreshDriver()->MostRecentRefresh();
for (PRCList *l = PR_LIST_HEAD(&mElementCollections);
l != &mElementCollections;
l = PR_NEXT_LINK(l)) {
AnimationCollection* collection = static_cast<AnimationCollection*>(l);
for (AnimationCollection* collection = mElementCollections.getFirst();
collection; collection = collection->getNext()) {
if (collection->mStyleRuleRefreshTime == now) {
continue;
}

View File

@ -9,11 +9,11 @@
#include "nsIStyleRuleProcessor.h"
#include "nsIStyleRule.h"
#include "nsRefreshDriver.h"
#include "prclist.h"
#include "nsChangeHint.h"
#include "nsCSSProperty.h"
#include "nsDisplayList.h" // For nsDisplayItem::Type
#include "mozilla/EventDispatcher.h"
#include "mozilla/LinkedList.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/dom/Animation.h"
@ -179,7 +179,7 @@ public:
GetAnimationCollection(const nsIFrame* aFrame);
protected:
PRCList mElementCollections;
LinkedList<AnimationCollection> mElementCollections;
nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
bool mIsObservingRefreshDriver;
};
@ -234,7 +234,7 @@ private:
typedef InfallibleTArray<nsRefPtr<dom::Animation>> AnimationPtrArray;
struct AnimationCollection : public PRCList
struct AnimationCollection : public LinkedListElement<AnimationCollection>
{
AnimationCollection(dom::Element *aElement, nsIAtom *aElementProperty,
CommonAnimationManager *aManager)
@ -250,14 +250,13 @@ struct AnimationCollection : public PRCList
#endif
{
MOZ_COUNT_CTOR(AnimationCollection);
PR_INIT_CLIST(this);
}
~AnimationCollection()
{
MOZ_ASSERT(mCalledPropertyDtor,
"must call destructor through element property dtor");
MOZ_COUNT_DTOR(AnimationCollection);
PR_REMOVE_LINK(this);
remove();
mManager->ElementCollectionRemoved();
}