AnimationTimeline.h [plain text]
#pragma once
#include "CSSValue.h"
#include "RenderStyle.h"
#include "WebAnimation.h"
#include <wtf/Forward.h>
#include <wtf/HashMap.h>
#include <wtf/ListHashSet.h>
#include <wtf/Optional.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
#include <wtf/Seconds.h>
namespace WebCore {
class CSSAnimation;
class CSSTransition;
class DeclarativeAnimation;
class Element;
class AnimationTimeline : public RefCounted<AnimationTimeline> {
public:
bool isDocumentTimeline() const { return m_classType == DocumentTimelineClass; }
void forgetAnimation(WebAnimation*);
virtual void animationTimingDidChange(WebAnimation&);
virtual void removeAnimation(WebAnimation&);
Optional<double> bindingsCurrentTime();
virtual Optional<Seconds> currentTime() { return m_currentTime; }
enum class Ordering { Sorted, Unsorted };
Vector<RefPtr<WebAnimation>> animationsForElement(Element&, Ordering ordering = Ordering::Unsorted) const;
void elementWasRemoved(Element&);
void removeAnimationsForElement(Element&);
void cancelDeclarativeAnimationsForElement(Element&);
virtual void animationWasAddedToElement(WebAnimation&, Element&);
virtual void animationWasRemovedFromElement(WebAnimation&, Element&);
void removeDeclarativeAnimationFromListsForOwningElement(WebAnimation&, Element&);
void updateCSSAnimationsForElement(Element&, const RenderStyle* currentStyle, const RenderStyle& afterChangeStyle);
void updateCSSTransitionsForElement(Element&, const RenderStyle& currentStyle, const RenderStyle& afterChangeStyle);
using ElementToAnimationsMap = HashMap<Element*, ListHashSet<RefPtr<WebAnimation>>>;
using PropertyToTransitionMap = HashMap<CSSPropertyID, RefPtr<CSSTransition>>;
virtual ~AnimationTimeline();
protected:
enum ClassType {
DocumentTimelineClass
};
ClassType classType() const { return m_classType; }
explicit AnimationTimeline(ClassType);
ListHashSet<WebAnimation*> m_allAnimations;
ListHashSet<RefPtr<WebAnimation>> m_animations;
HashMap<Element*, PropertyToTransitionMap> m_elementToCompletedCSSTransitionByCSSPropertyID;
private:
RefPtr<WebAnimation> cssAnimationForElementAndProperty(Element&, CSSPropertyID);
PropertyToTransitionMap& ensureRunningTransitionsByProperty(Element&);
void cancelDeclarativeAnimation(DeclarativeAnimation&);
ClassType m_classType;
Optional<Seconds> m_currentTime;
ElementToAnimationsMap m_elementToAnimationsMap;
ElementToAnimationsMap m_elementToCSSAnimationsMap;
ElementToAnimationsMap m_elementToCSSTransitionsMap;
HashMap<Element*, HashMap<String, RefPtr<CSSAnimation>>> m_elementToCSSAnimationByName;
HashMap<Element*, PropertyToTransitionMap> m_elementToRunningCSSTransitionByCSSPropertyID;
};
}
#define SPECIALIZE_TYPE_TRAITS_ANIMATION_TIMELINE(ToValueTypeName, predicate) \
SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \
static bool isType(const WebCore::AnimationTimeline& value) { return value.predicate; } \
SPECIALIZE_TYPE_TRAITS_END()