1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
|
/*
* Copyright (C) 2018 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "AcceleratedEffect.h"
#include "Animation.h"
#include "AnimationEffect.h"
#include "AnimationEffectPhase.h"
#include "BlendingKeyframes.h"
#include "CSSPropertyBlendingClient.h"
#include "CompositeOperation.h"
#include "CompositeOperationOrAuto.h"
#include "Document.h"
#include "EffectTiming.h"
#include "Element.h"
#include "IterationCompositeOperation.h"
#include "KeyframeEffectOptions.h"
#include "KeyframeInterpolation.h"
#include "RenderStyle.h"
#include "Styleable.h"
#include "WebAnimationTypes.h"
#include <wtf/Ref.h>
#include <wtf/text/AtomString.h>
#include <wtf/text/AtomStringHash.h>
namespace WebCore {
class Element;
class FilterOperations;
class MutableStyleProperties;
class RenderStyle;
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
class AcceleratedEffect;
#endif
namespace Style {
struct ResolutionContext;
}
class KeyframeEffect final : public AnimationEffect, public CSSPropertyBlendingClient, public KeyframeInterpolation {
WTF_MAKE_TZONE_OR_ISO_ALLOCATED(KeyframeEffect);
public:
static ExceptionOr<Ref<KeyframeEffect>> create(JSC::JSGlobalObject&, Document&, Element*, JSC::Strong<JSC::JSObject>&&, std::optional<std::variant<double, KeyframeEffectOptions>>&&);
static Ref<KeyframeEffect> create(Ref<KeyframeEffect>&&);
static Ref<KeyframeEffect> create(const Element&, const std::optional<Style::PseudoElementIdentifier>&);
using KeyframeOffset = std::variant<std::nullptr_t, double, TimelineRangeOffset, String>;
struct BasePropertyIndexedKeyframe {
std::variant<std::nullptr_t, Vector<KeyframeOffset>, double, TimelineRangeOffset, String> offset = Vector<KeyframeOffset>();
std::variant<Vector<String>, String> easing = Vector<String>();
std::variant<Vector<CompositeOperationOrAuto>, CompositeOperationOrAuto> composite = Vector<CompositeOperationOrAuto>();
};
struct BaseKeyframe {
KeyframeOffset offset;
String easing { "linear"_s };
CompositeOperationOrAuto composite { CompositeOperationOrAuto::Auto };
};
struct PropertyAndValues {
CSSPropertyID property;
AtomString customProperty;
Vector<String> values;
};
struct KeyframeLikeObject {
BasePropertyIndexedKeyframe baseProperties;
Vector<PropertyAndValues> propertiesAndValues;
};
struct BaseComputedKeyframe : BaseKeyframe {
double computedOffset;
};
struct ComputedKeyframe : BaseComputedKeyframe {
UncheckedKeyHashMap<CSSPropertyID, String> styleStrings;
UncheckedKeyHashMap<AtomString, String> customStyleStrings;
};
struct ParsedKeyframe : ComputedKeyframe {
RefPtr<TimingFunction> timingFunction;
Ref<MutableStyleProperties> style;
ParsedKeyframe();
~ParsedKeyframe();
};
const Vector<ParsedKeyframe>& parsedKeyframes() const { return m_parsedKeyframes; }
Element* target() const { return m_target.get(); }
void setTarget(RefPtr<Element>&&);
bool targetsPseudoElement() const;
const String pseudoElement() const;
ExceptionOr<void> setPseudoElement(const String&);
const std::optional<const Styleable> targetStyleable() const;
Vector<ComputedKeyframe> getKeyframes();
ExceptionOr<void> setBindingsKeyframes(JSC::JSGlobalObject&, Document&, JSC::Strong<JSC::JSObject>&&);
ExceptionOr<void> setKeyframes(JSC::JSGlobalObject&, Document&, JSC::Strong<JSC::JSObject>&&);
IterationCompositeOperation iterationComposite() const { return m_iterationCompositeOperation; }
void setIterationComposite(IterationCompositeOperation);
CompositeOperation composite() const { return m_compositeOperation; }
void setComposite(CompositeOperation);
CompositeOperation bindingsComposite() const;
void setBindingsComposite(CompositeOperation);
void getAnimatedStyle(std::unique_ptr<RenderStyle>& animatedStyle);
OptionSet<AnimationImpact> apply(RenderStyle& targetStyle, const Style::ResolutionContext&, std::optional<Seconds> = std::nullopt);
void invalidate();
void animationRelevancyDidChange();
void transformRelatedPropertyDidChange();
enum class RecomputationReason : uint8_t { LogicalPropertyChange, Other };
std::optional<RecomputationReason> recomputeKeyframesIfNecessary(const RenderStyle* previousUnanimatedStyle, const RenderStyle& unanimatedStyle, const Style::ResolutionContext&);
void applyPendingAcceleratedActions();
void applyPendingAcceleratedActionsOrUpdateTimingProperties();
void willChangeRenderer();
Document* document() const final;
RenderElement* renderer() const final;
const RenderStyle& currentStyle() const final;
bool triggersStackingContext() const { return m_triggersStackingContext; }
bool isRunningAccelerated() const;
// FIXME: These ignore the fact that some timing functions can prevent acceleration.
bool isAboutToRunAccelerated() const { return m_acceleratedPropertiesState != AcceleratedProperties::None && m_lastRecordedAcceleratedAction != AcceleratedAction::Stop; }
std::optional<unsigned> transformFunctionListPrefix() const override;
void computeStyleOriginatedAnimationBlendingKeyframes(const RenderStyle* oldStyle, const RenderStyle& newStyle, const Style::ResolutionContext&);
const BlendingKeyframes& blendingKeyframes() const { return m_blendingKeyframes; }
const UncheckedKeyHashSet<AnimatableCSSProperty>& animatedProperties();
bool animatesProperty(const AnimatableCSSProperty&) const;
const UncheckedKeyHashSet<AnimatableCSSProperty>& acceleratedProperties() const { return m_acceleratedProperties; }
const UncheckedKeyHashSet<AnimatableCSSProperty>& acceleratedPropertiesWithImplicitKeyframe() const { return m_acceleratedPropertiesWithImplicitKeyframe; }
bool computeExtentOfTransformAnimation(LayoutRect&) const;
bool computeTransformedExtentViaTransformList(const FloatRect&, const RenderStyle&, LayoutRect&) const;
bool computeTransformedExtentViaMatrix(const FloatRect&, const RenderStyle&, LayoutRect&) const;
bool forceLayoutIfNeeded();
enum class Accelerated : bool { No, Yes };
bool isCurrentlyAffectingProperty(CSSPropertyID, Accelerated = Accelerated::No) const;
bool isRunningAcceleratedAnimationForProperty(CSSPropertyID) const;
bool isRunningAcceleratedTransformRelatedAnimation() const;
bool requiresPseudoElement() const;
bool hasImplicitKeyframes() const;
void keyframesRuleDidChange();
void customPropertyRegistrationDidChange(const AtomString&);
bool canBeAccelerated() const;
bool accelerationWasPrevented() const { return m_runningAccelerated == RunningAccelerated::Prevented; }
bool preventsAcceleration() const;
void effectStackNoLongerPreventsAcceleration();
void effectStackNoLongerAllowsAcceleration();
void effectStackNoLongerAllowsAccelerationDuringAcceleratedActionApplication();
void wasAddedToEffectStack();
void wasRemovedFromEffectStack();
void lastStyleChangeEventStyleDidChange(const RenderStyle* previousStyle, const RenderStyle* currentStyle);
void acceleratedPropertiesOverriddenByCascadeDidChange();
static String CSSPropertyIDToIDLAttributeName(CSSPropertyID);
WebAnimationType animationType() const { return m_animationType; }
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
const AcceleratedEffect* acceleratedRepresentation() const { return m_acceleratedRepresentation.get(); }
void setAcceleratedRepresentation(const AcceleratedEffect* acceleratedRepresentation) { m_acceleratedRepresentation = acceleratedRepresentation; }
#endif
private:
KeyframeEffect(Element*, const std::optional<Style::PseudoElementIdentifier>&);
enum class AcceleratedAction : uint8_t { Play, Pause, UpdateProperties, TransformChange, Stop };
enum class AcceleratedProperties : uint8_t { None, Some, All };
enum class RunningAccelerated : uint8_t { NotStarted, Yes, Prevented, Failed };
class CanBeAcceleratedMutationScope {
WTF_MAKE_NONCOPYABLE(CanBeAcceleratedMutationScope);
public:
CanBeAcceleratedMutationScope(KeyframeEffect*);
~CanBeAcceleratedMutationScope();
private:
RefPtr<KeyframeEffect> m_effect;
bool m_couldOriginallyPreventAcceleration;
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
bool m_couldOriginallyBeAccelerated;
#endif
};
void updateEffectStackMembership();
void copyPropertiesFromSource(Ref<KeyframeEffect>&&);
void didChangeTargetStyleable(const std::optional<const Styleable>&);
ExceptionOr<void> processKeyframes(JSC::JSGlobalObject&, Document&, JSC::Strong<JSC::JSObject>&&);
void addPendingAcceleratedAction(AcceleratedAction);
bool isCompletelyAccelerated() const { return m_acceleratedPropertiesState == AcceleratedProperties::All; }
void updateAcceleratedActions();
void setAnimatedPropertiesInStyle(RenderStyle&, const ComputedEffectTiming&);
const TimingFunction* timingFunctionForKeyframeAtIndex(size_t) const;
const TimingFunction* timingFunctionForBlendingKeyframe(const BlendingKeyframe&) const;
Ref<const Animation> backingAnimationForCompositedRenderer();
void computedNeedsForcedLayout();
void computeStackingContextImpact();
void computeSomeKeyframesUseStepsOrLinearTimingFunctionWithPoints();
void clearBlendingKeyframes();
void updateBlendingKeyframes(RenderStyle& elementStyle, const Style::ResolutionContext&);
void computeCSSAnimationBlendingKeyframes(const RenderStyle& unanimatedStyle, const Style::ResolutionContext&);
void computeCSSTransitionBlendingKeyframes(const RenderStyle& oldStyle, const RenderStyle& newStyle);
void computeAcceleratedPropertiesState();
void setBlendingKeyframes(BlendingKeyframes&&);
void checkForMatchingTransformFunctionLists();
void computeHasImplicitKeyframeForAcceleratedProperty();
void computeHasKeyframeComposingAcceleratedProperty();
void computeHasAcceleratedPropertyOverriddenByCascadeProperty();
void computeHasReferenceFilter();
void computeHasSizeDependentTransform();
void analyzeAcceleratedProperties();
void updateIsAssociatedWithProgressBasedTimeline();
void abilityToBeAcceleratedDidChange();
void updateAcceleratedAnimationIfNecessary();
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
class StackMembershipMutationScope {
WTF_MAKE_NONCOPYABLE(StackMembershipMutationScope);
public:
StackMembershipMutationScope(KeyframeEffect&);
~StackMembershipMutationScope();
private:
RefPtr<KeyframeEffect> m_effect;
RefPtr<Element> m_originalTarget;
std::optional<Style::PseudoElementIdentifier> m_originalPseudoElementIdentifier;
};
bool threadedAnimationResolutionEnabled() const;
void updateAssociatedThreadedEffectStack(const std::optional<const Styleable>& = std::nullopt);
#endif
// AnimationEffect
bool isKeyframeEffect() const final { return true; }
void animationDidTick() final;
void animationDidChangeTimingProperties() final;
void animationWasCanceled() final;
void animationSuspensionStateDidChange(bool) final;
void animationTimelineDidChange(const AnimationTimeline*) final;
void animationDidFinish() final;
void setAnimation(WebAnimation*) final;
Seconds timeToNextTick(const BasicEffectTiming&) final;
bool ticksContinuouslyWhileActive() const final;
std::optional<double> progressUntilNextStep(double) const final;
bool preventsAnimationReadiness() const final;
void animationProgressBasedTimelineSourceDidChangeMetrics(const TimelineRange&) final;
const ViewTimeline* activeViewTimeline();
void updateComputedKeyframeOffsetsIfNeeded();
// KeyframeInterpolation
CompositeOperation compositeOperation() const final { return m_compositeOperation; }
IterationCompositeOperation iterationCompositeOperation() const final { return m_iterationCompositeOperation; }
const KeyframeInterpolation::Keyframe& keyframeAtIndex(size_t) const final;
size_t numberOfKeyframes() const final { return m_blendingKeyframes.size(); }
const TimingFunction* timingFunctionForKeyframe(const KeyframeInterpolation::Keyframe&) const final;
bool isPropertyAdditiveOrCumulative(KeyframeInterpolation::Property) const final;
WeakPtr<Document, WeakPtrImplWithEventTargetData> m_document;
AtomString m_keyframesName;
BlendingKeyframes m_blendingKeyframes { emptyAtom() };
UncheckedKeyHashSet<AnimatableCSSProperty> m_animatedProperties;
UncheckedKeyHashSet<AnimatableCSSProperty> m_acceleratedProperties;
UncheckedKeyHashSet<AnimatableCSSProperty> m_acceleratedPropertiesWithImplicitKeyframe;
Vector<ParsedKeyframe> m_parsedKeyframes;
Vector<AcceleratedAction> m_pendingAcceleratedActions;
RefPtr<Element> m_target;
std::optional<Style::PseudoElementIdentifier> m_pseudoElementIdentifier { };
#if ENABLE(THREADED_ANIMATION_RESOLUTION)
WeakPtr<AcceleratedEffect> m_acceleratedRepresentation;
#endif
AcceleratedAction m_lastRecordedAcceleratedAction { AcceleratedAction::Stop };
WebAnimationType m_animationType { WebAnimationType::WebAnimation };
IterationCompositeOperation m_iterationCompositeOperation { IterationCompositeOperation::Replace };
CompositeOperation m_compositeOperation { CompositeOperation::Replace };
AcceleratedProperties m_acceleratedPropertiesState { AcceleratedProperties::None };
AnimationEffectPhase m_phaseAtLastApplication { AnimationEffectPhase::Idle };
RunningAccelerated m_runningAccelerated { RunningAccelerated::NotStarted };
bool m_needsForcedLayout { false };
bool m_triggersStackingContext { false };
size_t m_transformFunctionListsMatchPrefix { 0 };
bool m_inTargetEffectStack { false };
bool m_someKeyframesUseLinearTimingFunctionWithPoints { false };
bool m_someKeyframesUseStepsTimingFunction { false };
bool m_hasImplicitKeyframeForAcceleratedProperty { false };
bool m_hasKeyframeComposingAcceleratedProperty { false };
bool m_hasAcceleratedPropertyOverriddenByCascadeProperty { false };
bool m_hasReferenceFilter { false };
bool m_animatesSizeAndSizeDependentTransform { false };
bool m_isAssociatedWithProgressBasedTimeline { false };
bool m_needsComputedKeyframeOffsetsUpdate { false };
};
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_ANIMATION_EFFECT(KeyframeEffect, isKeyframeEffect());
|