зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1415780 - Split AnimationEventDipatcher into an independent file. r=birtles
MozReview-Commit-ID: Fcqtu7G400Z --HG-- extra : rebase_source : e90a03ef74a7c53a068227672f9e727d31d11707
This commit is contained in:
Родитель
d3f99e5f1a
Коммит
cd43017099
|
@ -0,0 +1,137 @@
|
||||||
|
/* -*- 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_AnimationEventDispatcher_h
|
||||||
|
#define mozilla_AnimationEventDispatcher_h
|
||||||
|
|
||||||
|
#include <algorithm> // For <std::stable_sort>
|
||||||
|
#include "mozilla/AnimationComparator.h"
|
||||||
|
#include "mozilla/EventDispatcher.h"
|
||||||
|
#include "nsCycleCollectionParticipant.h"
|
||||||
|
|
||||||
|
class nsPresContext;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
|
||||||
|
template <class EventInfo>
|
||||||
|
class AnimationEventDispatcher final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AnimationEventDispatcher() : mIsSorted(true) { }
|
||||||
|
|
||||||
|
void QueueEvents(nsTArray<EventInfo>&& aEvents)
|
||||||
|
{
|
||||||
|
mPendingEvents.AppendElements(Forward<nsTArray<EventInfo>>(aEvents));
|
||||||
|
mIsSorted = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is exposed as a separate method so that when we are dispatching
|
||||||
|
// *both* transition events and animation events we can sort both lists
|
||||||
|
// once using the current state of the document before beginning any
|
||||||
|
// dispatch.
|
||||||
|
void SortEvents()
|
||||||
|
{
|
||||||
|
if (mIsSorted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Replace with mPendingEvents.StableSort when bug 1147091 is
|
||||||
|
// fixed.
|
||||||
|
std::stable_sort(mPendingEvents.begin(), mPendingEvents.end(),
|
||||||
|
EventInfoLessThan());
|
||||||
|
mIsSorted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Takes a reference to the owning manager's pres context so it can
|
||||||
|
// detect if the pres context is destroyed while dispatching one of
|
||||||
|
// the events.
|
||||||
|
//
|
||||||
|
// This will call SortEvents automatically if it has not already been
|
||||||
|
// called.
|
||||||
|
void DispatchEvents(nsPresContext* const & aPresContext)
|
||||||
|
{
|
||||||
|
if (!aPresContext || mPendingEvents.IsEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SortEvents();
|
||||||
|
|
||||||
|
EventArray events;
|
||||||
|
mPendingEvents.SwapElements(events);
|
||||||
|
// mIsSorted will be set to true by SortEvents above, and we leave it
|
||||||
|
// that way since mPendingEvents is now empty
|
||||||
|
for (EventInfo& info : events) {
|
||||||
|
EventDispatcher::Dispatch(info.mElement, aPresContext, &info.mEvent);
|
||||||
|
|
||||||
|
if (!aPresContext) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearEventQueue()
|
||||||
|
{
|
||||||
|
mPendingEvents.Clear();
|
||||||
|
mIsSorted = true;
|
||||||
|
}
|
||||||
|
bool HasQueuedEvents() const { return !mPendingEvents.IsEmpty(); }
|
||||||
|
|
||||||
|
// Methods for supporting cycle-collection
|
||||||
|
void Traverse(nsCycleCollectionTraversalCallback* aCallback,
|
||||||
|
const char* aName)
|
||||||
|
{
|
||||||
|
for (EventInfo& info : mPendingEvents) {
|
||||||
|
ImplCycleCollectionTraverse(*aCallback, info.mElement, aName);
|
||||||
|
ImplCycleCollectionTraverse(*aCallback, info.mAnimation, aName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Unlink() { ClearEventQueue(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
class EventInfoLessThan
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool operator()(const EventInfo& a, const EventInfo& b) const
|
||||||
|
{
|
||||||
|
if (a.mTimeStamp != b.mTimeStamp) {
|
||||||
|
// Null timestamps sort first
|
||||||
|
if (a.mTimeStamp.IsNull() || b.mTimeStamp.IsNull()) {
|
||||||
|
return a.mTimeStamp.IsNull();
|
||||||
|
} else {
|
||||||
|
return a.mTimeStamp < b.mTimeStamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AnimationPtrComparator<RefPtr<dom::Animation>> comparator;
|
||||||
|
return comparator.LessThan(a.mAnimation, b.mAnimation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef nsTArray<EventInfo> EventArray;
|
||||||
|
EventArray mPendingEvents;
|
||||||
|
bool mIsSorted;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <class EventInfo>
|
||||||
|
inline void
|
||||||
|
ImplCycleCollectionUnlink(AnimationEventDispatcher<EventInfo>& aField)
|
||||||
|
{
|
||||||
|
aField.Unlink();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class EventInfo>
|
||||||
|
inline void
|
||||||
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
||||||
|
AnimationEventDispatcher<EventInfo>& aField,
|
||||||
|
const char* aName,
|
||||||
|
uint32_t aFlags = 0)
|
||||||
|
{
|
||||||
|
aField.Traverse(&aCallback, aName);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // mozilla_AnimationEventDispatcher_h
|
|
@ -24,6 +24,7 @@ EXPORTS.mozilla.dom += [
|
||||||
|
|
||||||
EXPORTS.mozilla += [
|
EXPORTS.mozilla += [
|
||||||
'AnimationComparator.h',
|
'AnimationComparator.h',
|
||||||
|
'AnimationEventDispatcher.h',
|
||||||
'AnimationPerformanceWarning.h',
|
'AnimationPerformanceWarning.h',
|
||||||
'AnimationPropertySegment.h',
|
'AnimationPropertySegment.h',
|
||||||
'AnimationTarget.h',
|
'AnimationTarget.h',
|
||||||
|
|
|
@ -7,20 +7,14 @@
|
||||||
#ifndef mozilla_css_AnimationCommon_h
|
#ifndef mozilla_css_AnimationCommon_h
|
||||||
#define mozilla_css_AnimationCommon_h
|
#define mozilla_css_AnimationCommon_h
|
||||||
|
|
||||||
#include <algorithm> // For <std::stable_sort>
|
|
||||||
#include "mozilla/AnimationCollection.h"
|
#include "mozilla/AnimationCollection.h"
|
||||||
#include "mozilla/AnimationComparator.h"
|
#include "mozilla/AnimationEventDispatcher.h"
|
||||||
#include "mozilla/EventDispatcher.h"
|
|
||||||
#include "mozilla/LinkedList.h"
|
#include "mozilla/LinkedList.h"
|
||||||
#include "mozilla/MemoryReporting.h"
|
|
||||||
#include "mozilla/dom/Animation.h"
|
#include "mozilla/dom/Animation.h"
|
||||||
#include "mozilla/AnimationTarget.h"
|
|
||||||
#include "mozilla/Attributes.h" // For MOZ_NON_OWNING_REF
|
#include "mozilla/Attributes.h" // For MOZ_NON_OWNING_REF
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/TimingParams.h"
|
#include "mozilla/TimingParams.h"
|
||||||
#include "nsContentUtils.h"
|
#include "nsContentUtils.h"
|
||||||
#include "nsCSSPseudoElements.h"
|
|
||||||
#include "nsCycleCollectionParticipant.h"
|
|
||||||
|
|
||||||
class nsIFrame;
|
class nsIFrame;
|
||||||
class nsPresContext;
|
class nsPresContext;
|
||||||
|
@ -179,122 +173,6 @@ private:
|
||||||
NonOwningAnimationTarget mTarget;
|
NonOwningAnimationTarget mTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <class EventInfo>
|
|
||||||
class AnimationEventDispatcher
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AnimationEventDispatcher() : mIsSorted(true) { }
|
|
||||||
|
|
||||||
void QueueEvents(nsTArray<EventInfo>&& aEvents)
|
|
||||||
{
|
|
||||||
mPendingEvents.AppendElements(Forward<nsTArray<EventInfo>>(aEvents));
|
|
||||||
mIsSorted = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is exposed as a separate method so that when we are dispatching
|
|
||||||
// *both* transition events and animation events we can sort both lists
|
|
||||||
// once using the current state of the document before beginning any
|
|
||||||
// dispatch.
|
|
||||||
void SortEvents()
|
|
||||||
{
|
|
||||||
if (mIsSorted) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: Replace with mPendingEvents.StableSort when bug 1147091 is
|
|
||||||
// fixed.
|
|
||||||
std::stable_sort(mPendingEvents.begin(), mPendingEvents.end(),
|
|
||||||
EventInfoLessThan());
|
|
||||||
mIsSorted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Takes a reference to the owning manager's pres context so it can
|
|
||||||
// detect if the pres context is destroyed while dispatching one of
|
|
||||||
// the events.
|
|
||||||
//
|
|
||||||
// This will call SortEvents automatically if it has not already been
|
|
||||||
// called.
|
|
||||||
void DispatchEvents(nsPresContext* const & aPresContext)
|
|
||||||
{
|
|
||||||
if (!aPresContext || mPendingEvents.IsEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SortEvents();
|
|
||||||
|
|
||||||
EventArray events;
|
|
||||||
mPendingEvents.SwapElements(events);
|
|
||||||
// mIsSorted will be set to true by SortEvents above, and we leave it
|
|
||||||
// that way since mPendingEvents is now empty
|
|
||||||
for (EventInfo& info : events) {
|
|
||||||
EventDispatcher::Dispatch(info.mElement, aPresContext, &info.mEvent);
|
|
||||||
|
|
||||||
if (!aPresContext) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ClearEventQueue()
|
|
||||||
{
|
|
||||||
mPendingEvents.Clear();
|
|
||||||
mIsSorted = true;
|
|
||||||
}
|
|
||||||
bool HasQueuedEvents() const { return !mPendingEvents.IsEmpty(); }
|
|
||||||
|
|
||||||
// Methods for supporting cycle-collection
|
|
||||||
void Traverse(nsCycleCollectionTraversalCallback* aCallback,
|
|
||||||
const char* aName)
|
|
||||||
{
|
|
||||||
for (EventInfo& info : mPendingEvents) {
|
|
||||||
ImplCycleCollectionTraverse(*aCallback, info.mElement, aName);
|
|
||||||
ImplCycleCollectionTraverse(*aCallback, info.mAnimation, aName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void Unlink() { ClearEventQueue(); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
class EventInfoLessThan
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool operator()(const EventInfo& a, const EventInfo& b) const
|
|
||||||
{
|
|
||||||
if (a.mTimeStamp != b.mTimeStamp) {
|
|
||||||
// Null timestamps sort first
|
|
||||||
if (a.mTimeStamp.IsNull() || b.mTimeStamp.IsNull()) {
|
|
||||||
return a.mTimeStamp.IsNull();
|
|
||||||
} else {
|
|
||||||
return a.mTimeStamp < b.mTimeStamp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
AnimationPtrComparator<RefPtr<dom::Animation>> comparator;
|
|
||||||
return comparator.LessThan(a.mAnimation, b.mAnimation);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef nsTArray<EventInfo> EventArray;
|
|
||||||
EventArray mPendingEvents;
|
|
||||||
bool mIsSorted;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class EventInfo>
|
|
||||||
inline void
|
|
||||||
ImplCycleCollectionUnlink(AnimationEventDispatcher<EventInfo>& aField)
|
|
||||||
{
|
|
||||||
aField.Unlink();
|
|
||||||
}
|
|
||||||
|
|
||||||
template <class EventInfo>
|
|
||||||
inline void
|
|
||||||
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|
||||||
AnimationEventDispatcher<EventInfo>& aField,
|
|
||||||
const char* aName,
|
|
||||||
uint32_t aFlags = 0)
|
|
||||||
{
|
|
||||||
aField.Traverse(&aCallback, aName);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the TransitionPhase or AnimationPhase to use when the animation
|
// Return the TransitionPhase or AnimationPhase to use when the animation
|
||||||
// doesn't have a target effect.
|
// doesn't have a target effect.
|
||||||
template <typename PhaseType>
|
template <typename PhaseType>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче