#include "config.h"
#include "CSSTransition.h"
#include "Animation.h"
#include "Element.h"
#include "InspectorInstrumentation.h"
#include "KeyframeEffect.h"
#include "TransitionEvent.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(CSSTransition);
Ref<CSSTransition> CSSTransition::create(Element& owningElement, CSSPropertyID property, MonotonicTime generationTime, const Animation& backingAnimation, const RenderStyle* oldStyle, const RenderStyle& newStyle, Seconds delay, Seconds duration, const RenderStyle& reversingAdjustedStartStyle, double reversingShorteningFactor)
{
ASSERT(oldStyle);
auto result = adoptRef(*new CSSTransition(owningElement, property, generationTime, backingAnimation, *oldStyle, newStyle, reversingAdjustedStartStyle, reversingShorteningFactor));
result->initialize(oldStyle, newStyle);
result->setTimingProperties(delay, duration);
InspectorInstrumentation::didCreateWebAnimation(result.get());
return result;
}
CSSTransition::CSSTransition(Element& element, CSSPropertyID property, MonotonicTime generationTime, const Animation& backingAnimation, const RenderStyle& oldStyle, const RenderStyle& targetStyle, const RenderStyle& reversingAdjustedStartStyle, double reversingShorteningFactor)
: DeclarativeAnimation(element, backingAnimation)
, m_property(property)
, m_generationTime(generationTime)
, m_targetStyle(RenderStyle::clonePtr(targetStyle))
, m_currentStyle(RenderStyle::clonePtr(oldStyle))
, m_reversingAdjustedStartStyle(RenderStyle::clonePtr(reversingAdjustedStartStyle))
, m_reversingShorteningFactor(reversingShorteningFactor)
{
}
void CSSTransition::resolve(RenderStyle& targetStyle)
{
DeclarativeAnimation::resolve(targetStyle);
m_currentStyle = RenderStyle::clonePtr(targetStyle);
}
void CSSTransition::setTimingProperties(Seconds delay, Seconds duration)
{
suspendEffectInvalidation();
auto* animationEffect = effect();
ASSERT(animationEffect);
animationEffect->setFill(FillMode::Backwards);
animationEffect->setDelay(delay);
animationEffect->setIterationDuration(duration);
animationEffect->setTimingFunction(backingAnimation().timingFunction());
animationEffect->updateStaticTimingProperties();
effectTimingDidChange();
unsuspendEffectInvalidation();
}
Ref<AnimationEventBase> CSSTransition::createEvent(const AtomString& eventType, double elapsedTime, const String& pseudoId, Optional<Seconds> timelineTime)
{
return TransitionEvent::create(eventType, getPropertyNameString(m_property), elapsedTime, pseudoId, timelineTime, this);
}
}