Bug 1354501 - Introduce a new function to queue a single animation event. r?birtles
Web animation event (i.e. finish and cancel event) is solely queued.
MozReview-Commit-ID: h1g3NfcY3c
--- a/dom/animation/AnimationEventDispatcher.cpp
+++ b/dom/animation/AnimationEventDispatcher.cpp
@@ -36,23 +36,35 @@ AnimationEventDispatcher::Disconnect()
"alive if we haven't disassociated from the refresh driver");
mPresContext->RefreshDriver()->CancelPendingAnimationEvents(this);
mIsObserving = false;
}
mPresContext = nullptr;
}
void
+AnimationEventDispatcher::QueueEvent(AnimationEventInfo&& aEvent)
+{
+ mPendingEvents.AppendElement(std::move(aEvent));
+ mIsSorted = false;
+ ScheduleDispatch();
+}
+
+void
AnimationEventDispatcher::QueueEvents(nsTArray<AnimationEventInfo>&& aEvents)
{
- MOZ_ASSERT(mPresContext,
- "The pres context should be valid");
-
mPendingEvents.AppendElements(std::move(aEvents));
mIsSorted = false;
+ ScheduleDispatch();
+}
+
+void
+AnimationEventDispatcher::ScheduleDispatch()
+{
+ MOZ_ASSERT(mPresContext, "The pres context should be valid");
if (!mIsObserving) {
mPresContext->RefreshDriver()->ScheduleAnimationEventDispatch(this);
mIsObserving = true;
}
}
} // namespace mozilla
--- a/dom/animation/AnimationEventDispatcher.h
+++ b/dom/animation/AnimationEventDispatcher.h
@@ -102,16 +102,17 @@ public:
{
}
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AnimationEventDispatcher)
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(AnimationEventDispatcher)
void Disconnect();
+ void QueueEvent(AnimationEventInfo&& aEvent);
void QueueEvents(nsTArray<AnimationEventInfo>&& aEvents);
// This will call SortEvents automatically if it has not already been
// called.
void DispatchEvents()
{
mIsObserving = false;
if (!mPresContext || mPendingEvents.IsEmpty()) {
@@ -188,16 +189,17 @@ private:
}
// FIXME: Replace with mPendingEvents.StableSort when bug 1147091 is
// fixed.
std::stable_sort(mPendingEvents.begin(), mPendingEvents.end(),
AnimationEventInfoLessThan());
mIsSorted = true;
}
+ void ScheduleDispatch();
nsPresContext* mPresContext;
typedef nsTArray<AnimationEventInfo> EventArray;
EventArray mPendingEvents;
bool mIsSorted;
bool mIsObserving;
};