CSSAnimationControllerPrivate.h [plain text]
#pragma once
#include "AnimationBase.h"
#include "Timer.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
namespace WebCore {
class CompositeAnimation;
class Document;
class Frame;
enum SetChanged { DoNotCallSetChanged, CallSetChanged };
class CSSAnimationControllerPrivate {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit CSSAnimationControllerPrivate(Frame&);
~CSSAnimationControllerPrivate();
std::optional<Seconds> updateAnimations(SetChanged callSetChanged = DoNotCallSetChanged);
void updateAnimationTimer(SetChanged callSetChanged = DoNotCallSetChanged);
CompositeAnimation& ensureCompositeAnimation(Element&);
bool clear(Element&);
void updateStyleIfNeededDispatcherFired();
void startUpdateStyleIfNeededDispatcher();
void addEventToDispatch(Element&, const AtomicString& eventType, const String& name, double elapsedTime);
void addElementChangeToDispatch(Element&);
bool hasAnimations() const { return !m_compositeAnimations.isEmpty(); }
bool isSuspended() const { return m_isSuspended; }
void suspendAnimations();
void resumeAnimations();
void animationFrameCallbackFired();
void updateThrottlingState();
Seconds animationInterval() const;
void suspendAnimationsForDocument(Document*);
void resumeAnimationsForDocument(Document*);
bool animationsAreSuspendedForDocument(Document*);
void startAnimationsIfNotSuspended(Document*);
void detachFromDocument(Document*);
bool isRunningAnimationOnRenderer(RenderElement&, CSSPropertyID, AnimationBase::RunningState) const;
bool isRunningAcceleratedAnimationOnRenderer(RenderElement&, CSSPropertyID, AnimationBase::RunningState) const;
bool pauseAnimationAtTime(Element&, const AtomicString& name, double t);
bool pauseTransitionAtTime(Element&, const String& property, double t);
unsigned numberOfActiveAnimations(Document*) const;
std::unique_ptr<RenderStyle> animatedStyleForElement(Element&);
bool computeExtentOfAnimation(Element&, LayoutRect&) const;
double beginAnimationUpdateTime();
void beginAnimationUpdate();
void endAnimationUpdate();
void receivedStartTimeResponse(double);
void addToAnimationsWaitingForStyle(AnimationBase*);
void removeFromAnimationsWaitingForStyle(AnimationBase*);
void addToAnimationsWaitingForStartTimeResponse(AnimationBase*, bool willGetResponse);
void removeFromAnimationsWaitingForStartTimeResponse(AnimationBase*);
void animationWillBeRemoved(AnimationBase*);
void updateAnimationTimerForElement(Element&);
bool allowsNewAnimationsWhileSuspended() const { return m_allowsNewAnimationsWhileSuspended; }
void setAllowsNewAnimationsWhileSuspended(bool);
void setRequiresLayout() { m_requiresLayout = true; }
#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
bool wantsScrollUpdates() const { return !m_animationsDependentOnScroll.isEmpty(); }
void addToAnimationsDependentOnScroll(AnimationBase*);
void removeFromAnimationsDependentOnScroll(AnimationBase*);
void scrollWasUpdated();
float scrollPosition() const { return m_scrollPosition; }
#endif
private:
void animationTimerFired();
void styleAvailable();
void fireEventsAndUpdateStyle();
void startTimeResponse(double t);
HashMap<RefPtr<Element>, RefPtr<CompositeAnimation>> m_compositeAnimations;
Timer m_animationTimer;
Timer m_updateStyleIfNeededDispatcher;
Frame& m_frame;
struct EventToDispatch {
Ref<Element> element;
AtomicString eventType;
String name;
double elapsedTime;
};
Vector<EventToDispatch> m_eventsToDispatch;
Vector<Ref<Element>> m_elementChangesToDispatch;
HashSet<Document*> m_suspendedDocuments;
std::optional<double> m_beginAnimationUpdateTime;
using AnimationsSet = HashSet<RefPtr<AnimationBase>>;
AnimationsSet m_animationsWaitingForStyle;
AnimationsSet m_animationsWaitingForStartTimeResponse;
int m_beginAnimationUpdateCount;
bool m_waitingForAsyncStartNotification;
bool m_isSuspended { false };
bool m_requiresLayout { false };
bool m_allowsNewAnimationsWhileSuspended;
#if ENABLE(CSS_ANIMATIONS_LEVEL_2)
AnimationsSet m_animationsDependentOnScroll;
float m_scrollPosition { 0 };
#endif
};
}