Index: Source/core/animation/LegacyStyleInterpolation.cpp |
diff --git a/Source/core/animation/LegacyStyleInterpolation.cpp b/Source/core/animation/LegacyStyleInterpolation.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..0df30cb5a2965137d12d8716ef9f757b7333f329 |
--- /dev/null |
+++ b/Source/core/animation/LegacyStyleInterpolation.cpp |
@@ -0,0 +1,128 @@ |
+// Copyright 2014 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/LegacyStyleInterpolation.h" |
+ |
+#include "core/css/CSSShadowValue.h" |
+#include "core/css/Pair.h" |
+#include "core/css/Rect.h" |
+#include "core/css/resolver/AnimatedStyleBuilder.h" |
+#include "core/css/resolver/StyleResolver.h" |
+#include "core/css/resolver/StyleResolverState.h" |
+ |
+namespace WebCore { |
+ |
+PassRefPtrWillBeRawPtr<LegacyStyleInterpolation> LegacyStyleInterpolation::create(CSSValue& start, CSSValue& end, CSSPropertyID id, Element& element) |
+{ |
+ if (interpolationRequiresStyleResolve(start) || interpolationRequiresStyleResolve(end)) |
+ return adoptRefWillBeNoop(new LegacyStyleInterpolation(&start, &end, id)); |
+ return create( |
+ InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnimatableValue(element, id, start)), |
+ InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnimatableValue(element, id, end)), |
+ id); |
+} |
+ |
+void LegacyStyleInterpolation::apply(StyleResolverState& state) const |
+{ |
+ if (!m_interpolationRequiresStyleResolve) |
+ return AnimatedStyleBuilder::applyProperty(m_id, state, toInterpolableAnimatableValue(m_cachedValue.get())->value()); |
+ |
+ OwnPtrWillBeRawPtr<InterpolableValue> start = InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnimatableValue(*state.element(), m_id, *m_startCSSValue, state.style())); |
+ OwnPtrWillBeRawPtr<InterpolableValue> end = InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnimatableValue(*state.element(), m_id, *m_endCSSValue, state.style())); |
+ OwnPtrWillBeRawPtr<InterpolableValue> interpolated = start->interpolate(*end, m_cachedFraction); |
+ AnimatedStyleBuilder::applyProperty(m_id, state, toInterpolableAnimatableValue(interpolated.get())->value()); |
+} |
+ |
+bool LegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSValue& value) |
+{ |
+ if (value.isPrimitiveValue()) |
+ return interpolationRequiresStyleResolve(toCSSPrimitiveValue(value)); |
+ |
+ if (value.isInheritedValue()) |
+ return true; |
+ |
+ if (value.isValueList()) { |
+ const CSSValueList& valueList = toCSSValueList(value); |
+ size_t length = valueList.length(); |
+ for (size_t index = 0; index < length; ++index) { |
+ if (interpolationRequiresStyleResolve(*valueList.item(index))) |
+ return true; |
+ } |
+ return false; |
+ } |
+ |
+ if (value.isShadowValue()) { |
+ const CSSShadowValue& shadowValue = toCSSShadowValue(value); |
+ return (shadowValue.x && interpolationRequiresStyleResolve(*shadowValue.x)) |
+ || (shadowValue.y && interpolationRequiresStyleResolve(*shadowValue.y)) |
+ || (shadowValue.blur && interpolationRequiresStyleResolve(*shadowValue.blur)) |
+ || (shadowValue.spread && interpolationRequiresStyleResolve(*shadowValue.spread)) |
+ || (shadowValue.style && interpolationRequiresStyleResolve(*shadowValue.style)) |
+ || (shadowValue.color && interpolationRequiresStyleResolve(*shadowValue.color)); |
+ } |
+ |
+ return false; |
dstockwell
2014/05/09 05:57:09
Which cases aren't handled here? Can this be a swi
|
+} |
+ |
+bool LegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSPrimitiveValue& primitiveValue) |
+{ |
+ if (primitiveValue.isCalculated()) { |
+ CSSLengthArray lengthArray; |
+ CSSPrimitiveValue::zeroLengthArray(lengthArray); |
+ primitiveValue.accumulateLengthArray(lengthArray); |
+ return lengthArray[CSSPrimitiveValue::UnitTypeFontSize] |
dstockwell
2014/05/09 05:57:09
Clearer to use != 0 here.
|
+ || lengthArray[CSSPrimitiveValue::UnitTypeFontXSize] |
+ || lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize] |
+ || lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth] |
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth] |
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight] |
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportMin] |
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportMax]; |
dstockwell
2014/05/09 05:57:09
Presumably this logic should live somewhere else?
|
+ } |
+ |
+ if (primitiveValue.isLength()) |
+ return primitiveValue.isFontRelativeLength() || primitiveValue.isViewportPercentageLength(); |
+ |
+ if (Pair* pair = primitiveValue.getPairValue()) { |
+ return interpolationRequiresStyleResolve(*pair->first()) |
+ || interpolationRequiresStyleResolve(*pair->second()); |
+ } |
+ |
+ if (Rect* rect = primitiveValue.getRectValue()) { |
+ return interpolationRequiresStyleResolve(*rect->top()) |
+ || interpolationRequiresStyleResolve(*rect->right()) |
+ || interpolationRequiresStyleResolve(*rect->bottom()) |
+ || interpolationRequiresStyleResolve(*rect->left()); |
+ } |
+ |
+ if (Quad* quad = primitiveValue.getQuadValue()) { |
+ return interpolationRequiresStyleResolve(*quad->top()) |
+ || interpolationRequiresStyleResolve(*quad->right()) |
+ || interpolationRequiresStyleResolve(*quad->bottom()) |
+ || interpolationRequiresStyleResolve(*quad->left()); |
+ } |
+ |
+ switch (primitiveValue.getValueID()) { |
+ case CSSValueBolder: |
+ case CSSValueCurrentcolor: |
+ case CSSValueHigher: |
+ case CSSValueLarger: |
+ case CSSValueLighter: |
+ case CSSValueLower: |
+ case CSSValueSmaller: |
+ return true; |
+ default: |
dstockwell
2014/05/09 05:57:09
How do we avoid hitting other important cases?
|
+ return false; |
+ } |
+} |
+ |
+void LegacyStyleInterpolation::trace(Visitor* visitor) |
+{ |
+ StyleInterpolation::trace(visitor); |
+ visitor->trace(m_startCSSValue); |
+ visitor->trace(m_endCSSValue); |
+} |
+ |
+} |