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.targetStyleable() || !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::hasEffectWithImplicitKeyframes() const
{
for (auto& effect : m_effects) {
if (effect->hasImplicitKeyframes())
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;
}
OptionSet<AnimationImpact> KeyframeEffectStack::applyKeyframeEffects(RenderStyle& targetStyle, const RenderStyle& previousLastStyleChangeEventStyle)
{
OptionSet<AnimationImpact> impact;
auto transformRelatedPropertyChanged = [&]() -> bool {
return !arePointingToEqualData(targetStyle.translate(), previousLastStyleChangeEventStyle.translate())
|| !arePointingToEqualData(targetStyle.scale(), previousLastStyleChangeEventStyle.scale())
|| !arePointingToEqualData(targetStyle.rotate(), previousLastStyleChangeEventStyle.rotate())
|| targetStyle.transform() != previousLastStyleChangeEventStyle.transform();
}();
for (const auto& effect : sortedEffects()) {
ASSERT(effect->animation());
effect->animation()->resolve(targetStyle);
if (effect->isRunningAccelerated() || effect->isAboutToRunAccelerated())
impact.add(AnimationImpact::RequiresRecomposite);
if (effect->triggersStackingContext())
impact.add(AnimationImpact::ForcesStackingContext);
if (transformRelatedPropertyChanged && effect->isRunningAcceleratedTransformRelatedAnimation())
effect->transformRelatedPropertyDidChange();
}
return impact;
}
void KeyframeEffectStack::stopAcceleratingTransformRelatedProperties(UseAcceleratedAction useAcceleratedAction)
{
for (auto& effect : m_effects)
effect->stopAcceleratingTransformRelatedProperties(useAcceleratedAction);
}
}