DocumentTimeline.h [plain text]
#pragma once
#include "AnimationTimeline.h"
#include "DocumentTimelineOptions.h"
#include "Timer.h"
#include <wtf/Ref.h>
#include <wtf/WeakPtr.h>
namespace WebCore {
class AnimationEventBase;
class DocumentTimelinesController;
class RenderElement;
class DocumentTimeline final : public AnimationTimeline
{
public:
static Ref<DocumentTimeline> create(Document&);
static Ref<DocumentTimeline> create(Document&, DocumentTimelineOptions&&);
~DocumentTimeline();
bool isDocumentTimeline() const final { return true; }
Document* document() const { return m_document.get(); }
Optional<Seconds> currentTime() override;
void animationTimingDidChange(WebAnimation&) override;
void removeAnimation(WebAnimation&) override;
void animationWasAddedToElement(WebAnimation&, Element&) final;
void animationWasRemovedFromElement(WebAnimation&, Element&) final;
void transitionDidComplete(RefPtr<CSSTransition>);
bool computeExtentOfAnimation(RenderElement&, LayoutRect&) const;
std::unique_ptr<RenderStyle> animatedStyleForRenderer(RenderElement& renderer);
bool isRunningAnimationOnRenderer(RenderElement&, CSSPropertyID) const;
bool isRunningAcceleratedAnimationOnRenderer(RenderElement&, CSSPropertyID) const;
void animationAcceleratedRunningStateDidChange(WebAnimation&);
bool runningAnimationsForElementAreAllAccelerated(Element&) const;
void detachFromDocument();
void enqueueAnimationEvent(AnimationEventBase&);
enum class ShouldUpdateAnimationsAndSendEvents : uint8_t { Yes, No };
ShouldUpdateAnimationsAndSendEvents documentWillUpdateAnimationsAndSendEvents();
void removeReplacedAnimations();
AnimationEvents prepareForPendingAnimationEventsDispatch();
void documentDidUpdateAnimationsAndSendEvents();
WEBCORE_EXPORT Seconds animationInterval() const;
void suspendAnimations();
void resumeAnimations();
bool animationsAreSuspended() const;
WEBCORE_EXPORT unsigned numberOfActiveAnimationsForTesting() const;
WEBCORE_EXPORT Vector<std::pair<String, double>> acceleratedAnimationsForElement(Element&) const;
WEBCORE_EXPORT unsigned numberOfAnimationTimelineInvalidationsForTesting() const;
private:
DocumentTimeline(Document&, Seconds);
DocumentTimelinesController* controller() const;
void applyPendingAcceleratedAnimations();
void scheduleInvalidationTaskIfNeeded();
void scheduleAnimationResolution();
void clearTickScheduleTimer();
void internalUpdateAnimationsAndSendEvents();
void updateListOfElementsWithRunningAcceleratedAnimationsForElement(Element&);
void scheduleNextTick();
bool animationCanBeRemoved(WebAnimation&);
bool shouldRunUpdateAnimationsAndSendEventsIgnoringSuspensionState() const;
Timer m_tickScheduleTimer;
HashSet<RefPtr<WebAnimation>> m_acceleratedAnimationsPendingRunningStateChange;
HashSet<Element*> m_elementsWithRunningAcceleratedAnimations;
AnimationEvents m_pendingAnimationEvents;
WeakPtr<Document> m_document;
Seconds m_originTime;
unsigned m_numberOfAnimationTimelineInvalidationsForTesting { 0 };
bool m_animationResolutionScheduled { false };
bool m_shouldScheduleAnimationResolutionForNewPendingEvents { true };
};
}
SPECIALIZE_TYPE_TRAITS_ANIMATION_TIMELINE(DocumentTimeline, isDocumentTimeline())