mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 16:25:38 +00:00
Bug 1415780 - Make AnimationEventDispatcher refcountable. r=birtles
In a subsequent patch in this patch series, we want to make nsPresContext have an AnimationEventDispatcher as RefPtr<>. Instead, if we were trying to make nsPresContext have the AnimationEventDispatcher as data object (not RefPtr<>) just like we did in CommonAnimationManager, we will fall into header inclusion hell since Element.h includes nsPresContext.h and AnimationEventDispatcher.h ends up including Element.h. Even if we could solve the inclusion hell, we will suffer from Rust bindgen issues for some reasons. MozReview-Commit-ID: B0nX2JzIRJD --HG-- extra : rebase_source : cd010ca5fe5b1f9fa8f519fdab0dc47d6e519bef
This commit is contained in:
parent
f2ce7c4704
commit
f61cc0132a
30
dom/animation/AnimationEventDispatcher.cpp
Normal file
30
dom/animation/AnimationEventDispatcher.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* -*- 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/AnimationEventDispatcher.h"
|
||||
|
||||
#include "mozilla/EventDispatcher.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(AnimationEventDispatcher)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AnimationEventDispatcher)
|
||||
tmp->ClearEventQueue();
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AnimationEventDispatcher)
|
||||
for (auto& info : tmp->mPendingEvents) {
|
||||
ImplCycleCollectionTraverse(cb, info.mElement,
|
||||
"mozilla::AnimationEventDispatcher.mPendingEvents.mElement");
|
||||
ImplCycleCollectionTraverse(cb, info.mAnimation,
|
||||
"mozilla::AnimationEventDispatcher.mPendingEvents.mAnimation");
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AnimationEventDispatcher, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationEventDispatcher, Release)
|
||||
|
||||
} // namespace mozilla
|
||||
|
@ -99,6 +99,9 @@ class AnimationEventDispatcher final
|
||||
public:
|
||||
AnimationEventDispatcher() : mIsSorted(true) { }
|
||||
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationEventDispatcher)
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(AnimationEventDispatcher)
|
||||
|
||||
void QueueEvents(nsTArray<AnimationEventInfo>&& aEvents)
|
||||
{
|
||||
mPendingEvents.AppendElements(Move(aEvents));
|
||||
@ -161,18 +164,9 @@ public:
|
||||
}
|
||||
bool HasQueuedEvents() const { return !mPendingEvents.IsEmpty(); }
|
||||
|
||||
// Methods for supporting cycle-collection
|
||||
void Traverse(nsCycleCollectionTraversalCallback* aCallback,
|
||||
const char* aName)
|
||||
{
|
||||
for (AnimationEventInfo& info : mPendingEvents) {
|
||||
ImplCycleCollectionTraverse(*aCallback, info.mElement, aName);
|
||||
ImplCycleCollectionTraverse(*aCallback, info.mAnimation, aName);
|
||||
}
|
||||
}
|
||||
void Unlink() { ClearEventQueue(); }
|
||||
private:
|
||||
~AnimationEventDispatcher() = default;
|
||||
|
||||
protected:
|
||||
class AnimationEventInfoLessThan
|
||||
{
|
||||
public:
|
||||
@ -197,21 +191,6 @@ protected:
|
||||
bool mIsSorted;
|
||||
};
|
||||
|
||||
inline void
|
||||
ImplCycleCollectionUnlink(AnimationEventDispatcher& aField)
|
||||
{
|
||||
aField.Unlink();
|
||||
}
|
||||
|
||||
inline void
|
||||
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||
AnimationEventDispatcher& aField,
|
||||
const char* aName,
|
||||
uint32_t aFlags = 0)
|
||||
{
|
||||
aField.Traverse(&aCallback, aName);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_AnimationEventDispatcher_h
|
||||
|
@ -47,6 +47,7 @@ UNIFIED_SOURCES += [
|
||||
'AnimationEffectReadOnly.cpp',
|
||||
'AnimationEffectTiming.cpp',
|
||||
'AnimationEffectTimingReadOnly.cpp',
|
||||
'AnimationEventDispatcher.cpp',
|
||||
'AnimationPerformanceWarning.cpp',
|
||||
'AnimationTimeline.cpp',
|
||||
'AnimationUtils.cpp',
|
||||
|
@ -33,6 +33,7 @@ public:
|
||||
explicit CommonAnimationManager(nsPresContext *aPresContext)
|
||||
: mPresContext(aPresContext)
|
||||
{
|
||||
mEventDispatcher = new AnimationEventDispatcher();
|
||||
}
|
||||
|
||||
// NOTE: This can return null after Disconnect().
|
||||
@ -74,11 +75,11 @@ public:
|
||||
*/
|
||||
void QueueEvents(nsTArray<AnimationEventInfo>&& aEvents)
|
||||
{
|
||||
mEventDispatcher.QueueEvents(Move(aEvents));
|
||||
mEventDispatcher->QueueEvents(Move(aEvents));
|
||||
}
|
||||
|
||||
void SortEvents() { mEventDispatcher.SortEvents(); }
|
||||
void ClearEventQueue() { mEventDispatcher.ClearEventQueue(); }
|
||||
void SortEvents() { mEventDispatcher->SortEvents(); }
|
||||
void ClearEventQueue() { mEventDispatcher->ClearEventQueue(); }
|
||||
|
||||
protected:
|
||||
virtual ~CommonAnimationManager()
|
||||
@ -101,7 +102,7 @@ protected:
|
||||
LinkedList<AnimationCollection<AnimationType>> mElementCollections;
|
||||
nsPresContext *mPresContext; // weak (non-null from ctor to Disconnect)
|
||||
|
||||
mozilla::AnimationEventDispatcher mEventDispatcher;
|
||||
RefPtr<mozilla::AnimationEventDispatcher> mEventDispatcher;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -313,7 +313,7 @@ public:
|
||||
void DispatchEvents()
|
||||
{
|
||||
RefPtr<nsAnimationManager> kungFuDeathGrip(this);
|
||||
mEventDispatcher.DispatchEvents(mPresContext);
|
||||
mEventDispatcher->DispatchEvents(mPresContext);
|
||||
}
|
||||
|
||||
// Utility function to walk through |aIter| to find the Keyframe with
|
||||
|
@ -366,7 +366,7 @@ public:
|
||||
void DispatchEvents()
|
||||
{
|
||||
RefPtr<nsTransitionManager> kungFuDeathGrip(this);
|
||||
mEventDispatcher.DispatchEvents(mPresContext);
|
||||
mEventDispatcher->DispatchEvents(mPresContext);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
Loading…
Reference in New Issue
Block a user