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

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

Issue 273683005: Web Animations API: Deferred computation of interpolated values (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing test file Created 6 years, 7 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/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;
+}
+
+bool LegacyStyleInterpolation::interpolationRequiresStyleResolve(const CSSPrimitiveValue& primitiveValue)
+{
+ if (primitiveValue.isCalculated()) {
+ CSSLengthArray lengthArray;
+ CSSPrimitiveValue::zeroLengthArray(lengthArray);
+ primitiveValue.accumulateLengthArray(lengthArray);
+ return lengthArray[CSSPrimitiveValue::UnitTypeFontSize]
+ || lengthArray[CSSPrimitiveValue::UnitTypeFontXSize]
+ || lengthArray[CSSPrimitiveValue::UnitTypeRootFontSize]
+ || lengthArray[CSSPrimitiveValue::UnitTypeZeroCharacterWidth]
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportWidth]
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportHeight]
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportMin]
+ || lengthArray[CSSPrimitiveValue::UnitTypeViewportMax];
+ }
+
+ 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:
+ return false;
+ }
+}
+
+void LegacyStyleInterpolation::trace(Visitor* visitor)
+{
+ StyleInterpolation::trace(visitor);
+ visitor->trace(m_startCSSValue);
+ visitor->trace(m_endCSSValue);
+}
+
+}
« no previous file with comments | « Source/core/animation/LegacyStyleInterpolation.h ('k') | Source/core/animation/LegacyStyleInterpolationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698