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

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

Issue 273683005: Web Animations API: Deferred computation of interpolated values (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix crashing shadow animation tests 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/InterpolableValuePromise.cpp
diff --git a/Source/core/animation/InterpolableValuePromise.cpp b/Source/core/animation/InterpolableValuePromise.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0d3ee762f72750342db508c1c2aa032bc2f35455
--- /dev/null
+++ b/Source/core/animation/InterpolableValuePromise.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/InterpolableValuePromise.h"
+
+#include "core/css/CSSShadowValue.h"
+#include "core/css/Pair.h"
+#include "core/css/Rect.h"
+#include "core/css/resolver/StyleResolver.h"
+
+namespace WebCore {
+
+DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValuePromise);
+
+InterpolableValuePromise::InterpolableValuePromise(Element& element, CSSPropertyID id, PassRefPtrWillBeRawPtr<CSSValue> value)
+{
+ if (requiresLateBinding(*value))
+ m_cssValue = value;
+ else
+ m_interpolableAnimatableValue = InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnimatableValue(element, id, value.get()));
+}
+
+void InterpolableValuePromise::trace(Visitor* visitor)
+{
+ visitor->trace(m_cssValue);
+ visitor->trace(m_interpolableAnimatableValue);
+}
+
+PassOwnPtrWillBeRawPtr<InterpolableValue> InterpolableValuePromise::extract(StyleResolverState& state, CSSPropertyID id)
+{
+ if (m_interpolableAnimatableValue)
+ return m_interpolableAnimatableValue->clone();
+
+ // FIXME: Avoid creating InterpolableAnimatableValues.
+ return InterpolableAnimatableValue::create(StyleResolver::applyAndSnapshotAnimatableValue(*state.element(), id, m_cssValue.get(), state.style()));
+}
+
+PassRefPtrWillBeRawPtr<AnimatableValue> InterpolableValuePromise::extractAnimatableValue()
+{
+ return m_interpolableAnimatableValue ? m_interpolableAnimatableValue->value() : 0;
+}
+
+bool InterpolableValuePromise::requiresLateBinding(const CSSPrimitiveValue& primitiveValue)
shans 2014/05/08 16:12:58 I think we decided we should come up with a better
+{
+ 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 requiresLateBinding(*pair->first())
+ || requiresLateBinding(*pair->second());
+ }
+
+ if (Rect* rect = primitiveValue.getRectValue()) {
+ return requiresLateBinding(*rect->top())
+ || requiresLateBinding(*rect->right())
+ || requiresLateBinding(*rect->bottom())
+ || requiresLateBinding(*rect->left());
+ }
+
+ if (Quad* quad = primitiveValue.getQuadValue()) {
+ return requiresLateBinding(*quad->top())
+ || requiresLateBinding(*quad->right())
+ || requiresLateBinding(*quad->bottom())
+ || requiresLateBinding(*quad->left());
+ }
+
+ switch (primitiveValue.getValueID()) {
+ case CSSValueBolder:
+ case CSSValueCurrentcolor:
+ case CSSValueHigher:
+ case CSSValueLarger:
+ case CSSValueLighter:
+ case CSSValueLower:
+ case CSSValueSmaller:
+ return true;
+ default:
+ return false;
+ }
+}
+
+bool InterpolableValuePromise::requiresLateBinding(const CSSValue& value)
+{
+ if (value.isPrimitiveValue())
+ return requiresLateBinding(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 (requiresLateBinding(*valueList.item(index)))
+ return true;
+ }
+ return false;
+ }
+
+ if (value.isShadowValue()) {
+ const CSSShadowValue& shadowValue = toCSSShadowValue(value);
+ return (shadowValue.x && requiresLateBinding(*shadowValue.x))
+ || (shadowValue.y && requiresLateBinding(*shadowValue.y))
+ || (shadowValue.blur && requiresLateBinding(*shadowValue.blur))
+ || (shadowValue.spread && requiresLateBinding(*shadowValue.spread))
+ || (shadowValue.style && requiresLateBinding(*shadowValue.style))
+ || (shadowValue.color && requiresLateBinding(*shadowValue.color));
+ }
+
+ return false;
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698