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

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

Issue 863863004: Implemented additive animations for length (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed AnimationStackTest Created 5 years, 10 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
Index: Source/core/animation/InterpolationFactory.cpp
diff --git a/Source/core/animation/StringKeyframe.cpp b/Source/core/animation/InterpolationFactory.cpp
similarity index 70%
copy from Source/core/animation/StringKeyframe.cpp
copy to Source/core/animation/InterpolationFactory.cpp
index 3e4311302a6c4d41bb32bd674e8976be1a2ddb23..0d3c02424deecd5a522311bfd7a15a555187c506 100644
--- a/Source/core/animation/StringKeyframe.cpp
+++ b/Source/core/animation/InterpolationFactory.cpp
@@ -1,9 +1,9 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "config.h"
-#include "core/animation/StringKeyframe.h"
+#include "core/animation/InterpolationFactory.h"
#include "core/animation/ColorStyleInterpolation.h"
#include "core/animation/ConstantStyleInterpolation.h"
@@ -18,65 +18,12 @@
#include "core/animation/SVGLengthStyleInterpolation.h"
#include "core/animation/ShadowStyleInterpolation.h"
#include "core/animation/VisibilityStyleInterpolation.h"
-#include "core/animation/css/CSSAnimations.h"
#include "core/css/CSSPropertyMetadata.h"
#include "core/css/resolver/StyleResolver.h"
-#include "core/layout/style/LayoutStyle.h"
namespace blink {
-StringKeyframe::StringKeyframe(const StringKeyframe& copyFrom)
- : Keyframe(copyFrom.m_offset, copyFrom.m_composite, copyFrom.m_easing)
- , m_propertySet(copyFrom.m_propertySet->mutableCopy())
-{
-}
-
-void StringKeyframe::setPropertyValue(CSSPropertyID property, const String& value, StyleSheetContents* styleSheetContents)
-{
- ASSERT(property != CSSPropertyInvalid);
- if (CSSAnimations::isAllowedAnimation(property))
- m_propertySet->setProperty(property, value, false, styleSheetContents);
-}
-
-PropertySet StringKeyframe::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 (unsigned i = 0; i < m_propertySet->propertyCount(); ++i)
- properties.add(m_propertySet->propertyAt(i).id());
- return properties;
-}
-
-PassRefPtrWillBeRawPtr<Keyframe> StringKeyframe::clone() const
-{
- return adoptRefWillBeNoop(new StringKeyframe(*this));
-}
-PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::createPropertySpecificKeyframe(CSSPropertyID property) const
-{
- return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset(), &easing(), propertyValue(property), composite()));
-}
-
-void StringKeyframe::trace(Visitor* visitor)
-{
- visitor->trace(m_propertySet);
- Keyframe::trace(visitor);
-}
-
-StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, CSSValue* value, AnimationEffect::CompositeOperation op)
- : Keyframe::PropertySpecificKeyframe(offset, easing, op)
- , m_value(value)
-{ }
-
-StringKeyframe::PropertySpecificKeyframe::PropertySpecificKeyframe(double offset, PassRefPtr<TimingFunction> easing, CSSValue* value)
- : Keyframe::PropertySpecificKeyframe(offset, easing, AnimationEffect::CompositeReplace)
- , m_value(value)
-{
- ASSERT(!isNull(m_offset));
-}
-
-namespace {
-InterpolationRange setRange(CSSPropertyID id)
+static InterpolationRange setRange(CSSPropertyID id)
{
switch (id) {
case CSSPropertyOrphans:
@@ -104,13 +51,35 @@ InterpolationRange setRange(CSSPropertyID id)
}
}
-} // namespace
+static void ensureAnimatableValueCaches(
+ CSSPropertyID property,
+ CSSValue& fromCSSValue,
+ CSSValue& toCSSValue,
+ RefPtrWillBeRawPtr<AnimatableValue>* fromAnimatableValueCache,
+ RefPtrWillBeRawPtr<AnimatableValue>* toAnimatableValueCache,
+ Element* element)
+{
+ if (!*fromAnimatableValueCache)
+ *fromAnimatableValueCache = StyleResolver::createAnimatableValueSnapshot(*element, property, fromCSSValue);
+
+ RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValueSnapshot(*element, property, toCSSValue);
+ *toAnimatableValueCache = to;
+}
-// FIXME: Refactor this into a generic piece that lives in InterpolationEffect, and a template parameter specific converter.
-PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::maybeCreateInterpolation(CSSPropertyID property, Keyframe::PropertySpecificKeyframe& end, Element* element) const
+// FIXME: Remove the use of AnimatableValues and Elements here.
+PassRefPtrWillBeRawPtr<Interpolation> InterpolationFactory::maybeCreateInterpolation(
+ CSSPropertyID property,
+ CSSValue* fromCSSValue,
+ CSSValue* toCSSValue,
+ AnimationEffect::CompositeOperation fromComposite,
+ AnimationEffect::CompositeOperation toComposite,
+ RefPtrWillBeRawPtr<AnimatableValue>* fromAnimatableValueCache,
+ RefPtrWillBeRawPtr<AnimatableValue>* toAnimatableValueCache,
+ Element* element)
{
- CSSValue* fromCSSValue = m_value.get();
- CSSValue* toCSSValue = toStringPropertySpecificKeyframe(end).value();
+ ASSERT(fromCSSValue);
+ ASSERT(toCSSValue);
+
InterpolationRange range = RangeAll;
bool fallBackToLegacy = false;
@@ -119,7 +88,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
if (!CSSPropertyMetadata::isAnimatableProperty(property)) {
if (fromCSSValue == toCSSValue)
- return ConstantStyleInterpolation::create(fromCSSValue, property);
+ return ConstantStyleInterpolation::create(fromCSSValue, property, fromComposite, toComposite);
return nullptr;
}
@@ -174,7 +143,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
case CSSPropertyWordSpacing:
case CSSPropertyWebkitColumnRuleWidth:
if (LengthStyleInterpolation::canCreateFrom(*fromCSSValue) && LengthStyleInterpolation::canCreateFrom(*toCSSValue))
- return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range);
+ return LengthStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, range, fromComposite, toComposite);
// FIXME: Handle keywords e.g. 'none'.
if (property == CSSPropertyPerspective)
@@ -204,8 +173,14 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
case CSSPropertyStrokeMiterlimit:
case CSSPropertyZoom:
if (DoubleStyleInterpolation::canCreateFrom(*fromCSSValue) && DoubleStyleInterpolation::canCreateFrom(*toCSSValue)) {
- if (property == CSSPropertyOpacity)
- StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(property, end, element, *fromCSSValue, *toCSSValue);
+ if (property == CSSPropertyOpacity) {
+ // FIXME: Remove the use of AnimatableValues and Elements here.
+ ASSERT(element);
+ ASSERT(fromAnimatableValueCache);
+ ASSERT(toAnimatableValueCache);
+
+ ensureAnimatableValueCaches(property, *fromCSSValue, *toCSSValue, fromAnimatableValueCache, toAnimatableValueCache, element);
+ }
return DoubleStyleInterpolation::create(*fromCSSValue, *toCSSValue, property, toCSSPrimitiveValue(fromCSSValue)->primitiveType(), setRange(property));
}
break;
@@ -323,7 +298,7 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
}
if (fromCSSValue == toCSSValue)
- return ConstantStyleInterpolation::create(fromCSSValue, property);
+ return ConstantStyleInterpolation::create(fromCSSValue, property, fromComposite, toComposite);
if (forceDefaultInterpolation)
return nullptr;
@@ -332,22 +307,20 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
|| toCSSValue->isUnsetValue() || toCSSValue->isInheritedValue() || toCSSValue->isInitialValue())
fallBackToLegacy = true;
+ ASSERT(element);
if (fallBackToLegacy) {
+ ASSERT(fromAnimatableValueCache);
+ ASSERT(toAnimatableValueCache);
+
if (DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(*fromCSSValue) || DeferredLegacyStyleInterpolation::interpolationRequiresStyleResolve(*toCSSValue)) {
// FIXME: Handle these cases outside of DeferredLegacyStyleInterpolation.
return DeferredLegacyStyleInterpolation::create(fromCSSValue, toCSSValue, property);
}
- // FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
- // FIXME: Remove this cache
- ASSERT(element);
- if (!m_animatableValueCache)
- m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*element, property, *fromCSSValue);
-
- RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSValue);
- toStringPropertySpecificKeyframe(end).m_animatableValueCache = to;
+ // FIXME: Remove the use of AnimatableValues and Elements here.
+ ensureAnimatableValueCaches(property, *fromCSSValue, *toCSSValue, fromAnimatableValueCache, toAnimatableValueCache, element);
- return LegacyStyleInterpolation::create(m_animatableValueCache.get(), to.release(), property);
+ return LegacyStyleInterpolation::create((*fromAnimatableValueCache).get(), (*toAnimatableValueCache).get(), property);
}
ASSERT(AnimatableValue::usesDefaultInterpolation(
@@ -355,36 +328,24 @@ PassRefPtrWillBeRawPtr<Interpolation> StringKeyframe::PropertySpecificKeyframe::
StyleResolver::createAnimatableValueSnapshot(*element, property, *toCSSValue).get()));
return nullptr;
-
-}
-// FIXME: Remove the use of AnimatableValues, RenderStyles and Elements here.
-// FIXME: Remove this cache
-void StringKeyframe::PropertySpecificKeyframe::ensureAnimatableValueCaches(CSSPropertyID property, Keyframe::PropertySpecificKeyframe& end, Element* element, CSSValue& fromCSSValue, CSSValue& toCSSValue) const
-{
- ASSERT(element);
- if (!m_animatableValueCache)
- m_animatableValueCache = StyleResolver::createAnimatableValueSnapshot(*element, property, fromCSSValue);
- RefPtrWillBeRawPtr<AnimatableValue> to = StyleResolver::createAnimatableValueSnapshot(*element, property, toCSSValue);
- toStringPropertySpecificKeyframe(end).m_animatableValueCache = to;
}
-PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::PropertySpecificKeyframe::neutralKeyframe(double offset, PassRefPtr<TimingFunction> easing) const
+PassRefPtrWillBeRawPtr<Interpolation> InterpolationFactory::createConstantInterpolation(
+ CSSPropertyID property,
+ CSSValue* value,
+ AnimationEffect::CompositeOperation fromComposite,
+ AnimationEffect::CompositeOperation toComposite)
{
- return adoptPtrWillBeNoop(new PropertySpecificKeyframe(offset, easing, 0, AnimationEffect::CompositeAdd));
-}
+ RefPtrWillBeRawPtr<Interpolation> interpolation = InterpolationFactory::maybeCreateInterpolation(
+ property,
+ value,
+ value,
+ fromComposite,
+ toComposite);
-PassOwnPtrWillBeRawPtr<Keyframe::PropertySpecificKeyframe> StringKeyframe::PropertySpecificKeyframe::cloneWithOffset(double offset) const
-{
- Keyframe::PropertySpecificKeyframe* theClone = new PropertySpecificKeyframe(offset, m_easing, m_value.get());
- toStringPropertySpecificKeyframe(theClone)->m_animatableValueCache = m_animatableValueCache;
- return adoptPtrWillBeNoop(theClone);
-}
+ ASSERT(interpolation);
-void StringKeyframe::PropertySpecificKeyframe::trace(Visitor* visitor)
-{
- visitor->trace(m_value);
- visitor->trace(m_animatableValueCache);
- Keyframe::PropertySpecificKeyframe::trace(visitor);
+ return interpolation.release();
}
}

Powered by Google App Engine
This is Rietveld 408576698