KeyframeEffectReadOnly.h [plain text]
#pragma once
#include "AnimationEffectReadOnly.h"
#include "AnimationEffectTimingProperties.h"
#include "CSSPropertyBlendingClient.h"
#include "CompositeOperation.h"
#include "Element.h"
#include "IterationCompositeOperation.h"
#include "KeyframeEffectOptions.h"
#include "KeyframeList.h"
#include "RenderStyle.h"
#include "StyleProperties.h"
#include <wtf/Ref.h>
namespace WebCore {
class Element;
class KeyframeEffectReadOnly : public AnimationEffectReadOnly
, public CSSPropertyBlendingClient {
public:
static ExceptionOr<Ref<KeyframeEffectReadOnly>> create(JSC::ExecState&, Element*, JSC::Strong<JSC::JSObject>&&, std::optional<Variant<double, KeyframeEffectOptions>>&&);
static ExceptionOr<Ref<KeyframeEffectReadOnly>> create(JSC::ExecState&, Ref<KeyframeEffectReadOnly>&&);
static Ref<KeyframeEffectReadOnly> create(const Element&);
~KeyframeEffectReadOnly() { }
struct BasePropertyIndexedKeyframe {
Variant<std::nullptr_t, Vector<std::optional<double>>, double> offset = Vector<std::optional<double>>();
Variant<Vector<String>, String> easing = Vector<String>();
Variant<std::nullptr_t, Vector<std::optional<CompositeOperation>>, CompositeOperation> composite = Vector<std::optional<CompositeOperation>>();
};
struct BaseKeyframe {
std::optional<double> offset;
String easing { "linear" };
std::optional<CompositeOperation> composite;
};
struct PropertyAndValues {
CSSPropertyID property;
Vector<String> values;
};
struct KeyframeLikeObject {
BasePropertyIndexedKeyframe baseProperties;
Vector<PropertyAndValues> propertiesAndValues;
};
struct ParsedKeyframe {
std::optional<double> offset;
double computedOffset;
std::optional<CompositeOperation> composite;
String easing;
RefPtr<TimingFunction> timingFunction;
Ref<MutableStyleProperties> style;
HashMap<CSSPropertyID, String> unparsedStyle;
ParsedKeyframe()
: style(MutableStyleProperties::create())
{
}
};
struct BaseComputedKeyframe {
std::optional<double> offset;
double computedOffset;
String easing { "linear" };
std::optional<CompositeOperation> composite;
};
Element* target() const { return m_target.get(); }
void setTarget(RefPtr<Element>&&);
Vector<JSC::Strong<JSC::JSObject>> getKeyframes(JSC::ExecState&);
IterationCompositeOperation iterationComposite() const { return m_iterationCompositeOperation; }
CompositeOperation composite() const { return m_compositeOperation; }
void getAnimatedStyle(std::unique_ptr<RenderStyle>& animatedStyle);
void apply(RenderStyle&) override;
void invalidate() override;
void animationDidSeek() final;
void animationSuspensionStateDidChange(bool) final;
void applyPendingAcceleratedActions();
bool isRunningAccelerated() const { return m_lastRecordedAcceleratedAction != AcceleratedAction::Stop; }
RenderElement* renderer() const override;
const RenderStyle& currentStyle() const override;
bool isAccelerated() const override { return m_shouldRunAccelerated; }
bool filterFunctionListsMatch() const override { return m_filterFunctionListsMatch; }
bool transformFunctionListsMatch() const override { return m_transformFunctionListsMatch; }
#if ENABLE(FILTERS_LEVEL_2)
bool backdropFilterFunctionListsMatch() const override { return m_backdropFilterFunctionListsMatch; }
#endif
bool colorFilterFunctionListsMatch() const override { return m_colorFilterFunctionListsMatch; }
void computeDeclarativeAnimationBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle);
bool hasBlendingKeyframes() const { return m_blendingKeyframes.size(); }
const HashSet<CSSPropertyID>& animatedProperties() const { return m_blendingKeyframes.properties(); }
bool computeExtentOfTransformAnimation(LayoutRect&) const;
bool computeTransformedExtentViaTransformList(const FloatRect&, const RenderStyle&, LayoutRect&) const;
bool computeTransformedExtentViaMatrix(const FloatRect&, const RenderStyle&, LayoutRect&) const;
bool forceLayoutIfNeeded();
protected:
void copyPropertiesFromSource(Ref<KeyframeEffectReadOnly>&&);
ExceptionOr<void> processKeyframes(JSC::ExecState&, JSC::Strong<JSC::JSObject>&&);
IterationCompositeOperation m_iterationCompositeOperation { IterationCompositeOperation::Replace };
CompositeOperation m_compositeOperation { CompositeOperation::Replace };
KeyframeEffectReadOnly(ClassType, Ref<AnimationEffectTimingReadOnly>&&, Element*);
private:
enum class AcceleratedAction { Play, Pause, Seek, Stop };
void addPendingAcceleratedAction(AcceleratedAction);
void updateAcceleratedAnimationState();
void setAnimatedPropertiesInStyle(RenderStyle&, double);
TimingFunction* timingFunctionForKeyframeAtIndex(size_t);
Ref<const Animation> backingAnimationForCompositedRenderer() const;
void computedNeedsForcedLayout();
void computeStackingContextImpact();
void updateBlendingKeyframes(RenderStyle&);
void computeCSSAnimationBlendingKeyframes();
void computeCSSTransitionBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle);
void computeShouldRunAccelerated();
void setBlendingKeyframes(KeyframeList&);
void checkForMatchingTransformFunctionLists();
void checkForMatchingFilterFunctionLists();
#if ENABLE(FILTERS_LEVEL_2)
void checkForMatchingBackdropFilterFunctionLists();
#endif
void checkForMatchingColorFilterFunctionLists();
bool checkForMatchingFilterFunctionLists(CSSPropertyID, const std::function<const FilterOperations& (const RenderStyle&)>&) const;
AcceleratedAction m_lastRecordedAcceleratedAction { AcceleratedAction::Stop };
bool m_shouldRunAccelerated { false };
bool m_needsForcedLayout { false };
bool m_triggersStackingContext { false };
bool m_transformFunctionListsMatch { false };
bool m_filterFunctionListsMatch { false };
#if ENABLE(FILTERS_LEVEL_2)
bool m_backdropFilterFunctionListsMatch { false };
#endif
bool m_colorFilterFunctionListsMatch { false };
RefPtr<Element> m_target;
KeyframeList m_blendingKeyframes;
Vector<ParsedKeyframe> m_parsedKeyframes;
Vector<AcceleratedAction> m_pendingAcceleratedActions;
};
}
SPECIALIZE_TYPE_TRAITS_ANIMATION_EFFECT(KeyframeEffectReadOnly, isKeyframeEffectReadOnly());