| 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..2e96b99104bbd2ef2c5d056704b8f0e7c80c4d18
|
| --- /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)
|
| +{
|
| + 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 requiresLateBinding(*shadowValue.x)
|
| + || requiresLateBinding(*shadowValue.y)
|
| + || requiresLateBinding(*shadowValue.blur)
|
| + || requiresLateBinding(*shadowValue.spread)
|
| + || requiresLateBinding(*shadowValue.style)
|
| + || requiresLateBinding(*shadowValue.color);
|
| + }
|
| +
|
| + return false;
|
| +}
|
| +
|
| +}
|
|
|