Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(445)

Unified Diff: Source/core/animation/KeyframeEffectModel.cpp

Issue 215883005: Web Animations: Introduce String based KeyframeEffectModel (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/animation/KeyframeEffectModel.h ('k') | Source/core/animation/KeyframeEffectModelTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/animation/KeyframeEffectModel.cpp
diff --git a/Source/core/animation/KeyframeEffectModel.cpp b/Source/core/animation/KeyframeEffectModel.cpp
index a50dff33f5da4fa48202eaab7e6e69438a368c04..ff9e597be44a35166d5612ba87e4a9f7f6205c4d 100644
--- a/Source/core/animation/KeyframeEffectModel.cpp
+++ b/Source/core/animation/KeyframeEffectModel.cpp
@@ -36,72 +36,12 @@
namespace WebCore {
-Keyframe::Keyframe()
- : m_offset(nullValue())
- , m_composite(AnimationEffect::CompositeReplace)
- , m_easing(LinearTimingFunction::preset())
-{ }
-
-Keyframe::Keyframe(const Keyframe& copyFrom)
- : m_offset(copyFrom.m_offset)
- , m_composite(copyFrom.m_composite)
- , m_easing(copyFrom.m_easing)
+bool Keyframe::compareOffsets(const RefPtrWillBeRawPtr<Keyframe>& a, const RefPtrWillBeRawPtr<Keyframe>& b)
{
- ASSERT(m_easing);
- for (PropertyValueMap::const_iterator iter = copyFrom.m_propertyValues.begin(); iter != copyFrom.m_propertyValues.end(); ++iter)
- setPropertyValue(iter->key, iter->value.get());
+ return a->offset() < b->offset();
}
-void Keyframe::setEasing(PassRefPtr<TimingFunction> easing)
-{
- ASSERT(easing);
- m_easing = easing;
-}
-
-void Keyframe::setPropertyValue(CSSPropertyID property, const AnimatableValue* value)
-{
- m_propertyValues.add(property, const_cast<AnimatableValue*>(value));
-}
-
-void Keyframe::clearPropertyValue(CSSPropertyID property)
-{
- m_propertyValues.remove(property);
-}
-
-const AnimatableValue* Keyframe::propertyValue(CSSPropertyID property) const
-{
- ASSERT(m_propertyValues.contains(property));
- return m_propertyValues.get(property);
-}
-
-PropertySet Keyframe::properties() const
-{
- // This is not used in time-critical code, so we probably don't need to
- // worry about caching this result.
- PropertySet properties;
- for (PropertyValueMap::const_iterator iter = m_propertyValues.begin(); iter != m_propertyValues.end(); ++iter)
- properties.add(*iter.keys());
- return properties;
-}
-
-PassRefPtrWillBeRawPtr<Keyframe> Keyframe::cloneWithOffset(double offset) const
-{
- RefPtrWillBeRawPtr<Keyframe> theClone = clone();
- theClone->setOffset(offset);
- return theClone.release();
-}
-
-void Keyframe::trace(Visitor* visitor)
-{
- visitor->trace(m_propertyValues);
-}
-
-KeyframeEffectModel::KeyframeEffectModel(const KeyframeVector& keyframes)
- : m_keyframes(keyframes)
-{
-}
-
-PropertySet KeyframeEffectModel::properties() const
+PropertySet KeyframeEffectModelBase::properties() const
{
PropertySet result;
if (!m_keyframes.size()) {
@@ -117,7 +57,7 @@ PropertySet KeyframeEffectModel::properties() const
return result;
}
-PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation> > > KeyframeEffectModel::sample(int iteration, double fraction, double iterationDuration) const
+PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation> > > KeyframeEffectModelBase::sample(int iteration, double fraction, double iterationDuration) const
{
ASSERT(iteration >= 0);
ASSERT(!isNull(fraction));
@@ -127,7 +67,7 @@ PassOwnPtrWillBeRawPtr<WillBeHeapVector<RefPtrWillBeMember<Interpolation> > > Ke
return m_interpolationEffect->getActiveInterpolations(fraction, iterationDuration);
}
-KeyframeEffectModel::KeyframeVector KeyframeEffectModel::normalizedKeyframes(const KeyframeVector& keyframes)
+KeyframeEffectModelBase::KeyframeVector KeyframeEffectModelBase::normalizedKeyframes(const KeyframeVector& keyframes)
{
// keyframes [beginIndex, endIndex) will remain after removing all keyframes if they are not
// loosely sorted by offset, and after removing keyframes with positional offset outide [0, 1].
@@ -191,7 +131,8 @@ KeyframeEffectModel::KeyframeVector KeyframeEffectModel::normalizedKeyframes(con
return result;
}
-void KeyframeEffectModel::ensureKeyframeGroups() const
+
+void KeyframeEffectModelBase::ensureKeyframeGroups() const
{
if (m_keyframeGroups)
return;
@@ -211,19 +152,18 @@ void KeyframeEffectModel::ensureKeyframeGroups() const
group = groupIter->value.get();
ASSERT(keyframe->composite() == AnimationEffect::CompositeReplace);
- group->appendKeyframe(adoptPtrWillBeNoop(
- new PropertySpecificKeyframe(keyframe->offset(), keyframe->easing(), keyframe->propertyValue(property), keyframe->composite())));
+ group->appendKeyframe(keyframe->createPropertySpecificKeyframe(property));
}
}
// Add synthetic keyframes.
for (KeyframeGroupMap::iterator iter = m_keyframeGroups->begin(); iter != m_keyframeGroups->end(); ++iter) {
- iter->value->addSyntheticKeyframeIfRequired();
+ iter->value->addSyntheticKeyframeIfRequired(this);
iter->value->removeRedundantKeyframes();
}
}
-void KeyframeEffectModel::ensureInterpolationEffect() const
+void KeyframeEffectModelBase::ensureInterpolationEffect() const
{
if (m_interpolationEffect)
return;
@@ -232,26 +172,20 @@ void KeyframeEffectModel::ensureInterpolationEffect() const
for (KeyframeGroupMap::const_iterator iter = m_keyframeGroups->begin(); iter != m_keyframeGroups->end(); ++iter) {
const PropertySpecificKeyframeVector& keyframes = iter->value->keyframes();
ASSERT(keyframes[0]->composite() == AnimationEffect::CompositeReplace);
- const AnimatableValue* start;
- const AnimatableValue* end = keyframes[0]->value();
for (size_t i = 0; i < keyframes.size() - 1; i++) {
ASSERT(keyframes[i + 1]->composite() == AnimationEffect::CompositeReplace);
- start = end;
- end = keyframes[i + 1]->value();
double applyFrom = i ? keyframes[i]->offset() : (-std::numeric_limits<double>::infinity());
double applyTo = i == keyframes.size() - 2 ? std::numeric_limits<double>::infinity() : keyframes[i + 1]->offset();
if (applyTo == 1)
applyTo = std::numeric_limits<double>::infinity();
- m_interpolationEffect->addInterpolation(
- LegacyStyleInterpolation::create(
- AnimatableValue::takeConstRef(start),
- AnimatableValue::takeConstRef(end), iter->key),
+
+ m_interpolationEffect->addInterpolation(keyframes[i]->createInterpolation(iter->key, keyframes[i + 1].get()),
keyframes[i]->easing(), keyframes[i]->offset(), keyframes[i + 1]->offset(), applyFrom, applyTo);
}
}
}
-bool KeyframeEffectModel::isReplaceOnly()
+bool KeyframeEffectModelBase::isReplaceOnly()
{
ensureKeyframeGroups();
for (KeyframeGroupMap::iterator iter = m_keyframeGroups->begin(); iter != m_keyframeGroups->end(); ++iter) {
@@ -264,7 +198,7 @@ bool KeyframeEffectModel::isReplaceOnly()
return true;
}
-void KeyframeEffectModel::trace(Visitor* visitor)
+void KeyframeEffectModelBase::trace(Visitor* visitor)
{
visitor->trace(m_keyframes);
visitor->trace(m_interpolationEffect);
@@ -273,40 +207,20 @@ void KeyframeEffectModel::trace(Visitor* visitor)
#endif
}
-KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, const AnimatableValue* value, CompositeOperation composite)
- : m_offset(offset)
- , m_easing(easing)
- , m_composite(composite)
-{
- m_value = AnimatableValue::takeConstRef(value);
-}
-
-KeyframeEffectModel::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, PassRefPtrWillBeRawPtr<AnimatableValue> value, CompositeOperation composite)
+Keyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, AnimationEffect::CompositeOperation composite)
: m_offset(offset)
, m_easing(easing)
- , m_value(value)
, m_composite(composite)
{
- ASSERT(!isNull(m_offset));
-}
-
-PassOwnPtrWillBeRawPtr<KeyframeEffectModel::PropertySpecificKeyframe> KeyframeEffectModel::PropertySpecificKeyframe::cloneWithOffset(double offset) const
-{
- return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, m_easing, m_value.get(), m_composite));
-}
-
-void KeyframeEffectModel::PropertySpecificKeyframe::trace(Visitor* visitor)
-{
- visitor->trace(m_value);
}
-void KeyframeEffectModel::PropertySpecificKeyframeGroup::appendKeyframe(PassOwnPtrWillBeRawPtr<PropertySpecificKeyframe> keyframe)
+void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::appendKeyframe(PassOwnPtr<PropertySpecificKeyframe> keyframe)
{
ASSERT(m_keyframes.isEmpty() || m_keyframes.last()->offset() <= keyframe->offset());
m_keyframes.append(keyframe);
}
-void KeyframeEffectModel::PropertySpecificKeyframeGroup::removeRedundantKeyframes()
+void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::removeRedundantKeyframes()
{
// As an optimization, removes keyframes in the following categories, as
// they will never be used by sample().
@@ -325,20 +239,26 @@ void KeyframeEffectModel::PropertySpecificKeyframeGroup::removeRedundantKeyframe
ASSERT(m_keyframes.size() >= 2);
}
-void KeyframeEffectModel::PropertySpecificKeyframeGroup::addSyntheticKeyframeIfRequired()
+void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::addSyntheticKeyframeIfRequired(const KeyframeEffectModelBase* context)
{
ASSERT(!m_keyframes.isEmpty());
if (m_keyframes.first()->offset() != 0.0)
- m_keyframes.insert(0, adoptPtrWillBeNoop(new PropertySpecificKeyframe(0, nullptr, AnimatableValue::neutralValue(), CompositeAdd)));
+ m_keyframes.insert(0, m_keyframes.first()->neutralKeyframe(0, nullptr));
if (m_keyframes.last()->offset() != 1.0)
- appendKeyframe(adoptPtrWillBeNoop(new PropertySpecificKeyframe(1, nullptr, AnimatableValue::neutralValue(), CompositeAdd)));
+ appendKeyframe(m_keyframes.last()->neutralKeyframe(1, nullptr));
}
-void KeyframeEffectModel::PropertySpecificKeyframeGroup::trace(Visitor* visitor)
+void KeyframeEffectModelBase::PropertySpecificKeyframeGroup::trace(Visitor* visitor)
{
-#if ENABLE_OILPAN
+#if ENABLE(OILPAN)
visitor->trace(m_keyframes);
#endif
}
+template <>
+bool KeyframeEffectModel<AnimatableValueKeyframe>::isAnimatableValueKeyframeEffectModel() const { return true; }
+
+template <>
+bool KeyframeEffectModel<StringKeyframe>::isStringKeyframeEffectModel() const { return true; }
+
} // namespace
« no previous file with comments | « Source/core/animation/KeyframeEffectModel.h ('k') | Source/core/animation/KeyframeEffectModelTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698