KeyframeEffectStack.cpp [plain text]
#include "config.h"
#include "KeyframeEffectStack.h"
#include "CSSAnimation.h"
#include "CSSTransition.h"
#include "KeyframeEffect.h"
#include "WebAnimation.h"
#include "WebAnimationUtilities.h"
namespace WebCore {
KeyframeEffectStack::KeyframeEffectStack()
{
}
KeyframeEffectStack::~KeyframeEffectStack()
{
}
bool KeyframeEffectStack::addEffect(KeyframeEffect& effect)
{
if (!effect.targetElementOrPseudoElement() || !effect.animation() || !effect.animation()->timeline() || !effect.animation()->isRelevant())
return false;
m_effects.append(makeWeakPtr(&effect));
m_isSorted = false;
return true;
}
void KeyframeEffectStack::removeEffect(KeyframeEffect& effect)
{
m_effects.removeFirst(&effect);
}
bool KeyframeEffectStack::requiresPseudoElement() const
{
for (auto& effect : m_effects) {
if (effect->requiresPseudoElement())
return true;
}
return false;
}
bool KeyframeEffectStack::isCurrentlyAffectingProperty(CSSPropertyID property) const
{
for (auto& effect : m_effects) {
if (effect->isCurrentlyAffectingProperty(property) || effect->isRunningAcceleratedAnimationForProperty(property))
return true;
}
return false;
}
Vector<WeakPtr<KeyframeEffect>> KeyframeEffectStack::sortedEffects()
{
ensureEffectsAreSorted();
return m_effects;
}
void KeyframeEffectStack::ensureEffectsAreSorted()
{
if (m_isSorted || m_effects.size() < 2)
return;
std::stable_sort(m_effects.begin(), m_effects.end(), [&](auto& lhs, auto& rhs) {
RELEASE_ASSERT(lhs.get());
RELEASE_ASSERT(rhs.get());
auto* lhsAnimation = lhs->animation();
auto* rhsAnimation = rhs->animation();
RELEASE_ASSERT(lhsAnimation);
RELEASE_ASSERT(rhsAnimation);
return compareAnimationsByCompositeOrder(*lhsAnimation, *rhsAnimation);
});
m_isSorted = true;
}
void KeyframeEffectStack::setCSSAnimationList(RefPtr<const AnimationList>&& cssAnimationList)
{
m_cssAnimationList = WTFMove(cssAnimationList);
m_isSorted = false;
}
}