Chromium Code Reviews| Index: Source/core/animation/ListStyleInterpolation.h |
| diff --git a/Source/core/animation/ListStyleInterpolation.h b/Source/core/animation/ListStyleInterpolation.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..abafe5daefa6103191aafa2fbaf943d46d6d2825 |
| --- /dev/null |
| +++ b/Source/core/animation/ListStyleInterpolation.h |
| @@ -0,0 +1,132 @@ |
| +// 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. |
| + |
| +#ifndef ListStyleInterpolation_h |
| +#define ListStyleInterpolation_h |
| + |
| +#include "core/animation/StyleInterpolation.h" |
| +#include "core/css/CSSPrimitiveValue.h" |
| +#include "core/css/CSSValueList.h" |
| +#include "core/css/resolver/StyleBuilder.h" |
| + |
| +namespace blink { |
| + |
| +template<typename T, typename NI> |
|
shans
2015/01/29 03:13:11
the 'NI' parameter doesn't appear to be used. It l
evemj (not active)
2015/02/02 03:56:01
Need the NI parameter so that template can be spec
|
| +class ListStyleInterpolationImpl : public StyleInterpolation { |
| +public: |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, NI>> create(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + Vector<typename T::NonInterpolableType> startNonInterpolableData; |
| + Vector<typename T::NonInterpolableType> endNonInterpolableData; |
| + |
| + const CSSValueList& startList = toCSSValueList(start); |
| + const CSSValueList& endList = toCSSValueList(end); |
| + |
| + for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| + if (!T::canCreateFrom(*startList.item(i), *endList.item(i))) { |
| + return nullptr; |
| + } |
| + } |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, NI>(listToInterpolableValue(start, startNonInterpolableData), listToInterpolableValue(end, endNonInterpolableData), id, startNonInterpolableData, range)); |
| + } |
| + |
| + virtual void apply(StyleResolverState& state) const override |
| + { |
| + StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cachedValue.get(), m_nonInterpolableData, m_range).get()); |
| + } |
| + |
| +private: |
| + ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, Vector<typename T::NonInterpolableType> nonInterpolableData, InterpolationRange range = RangeAll) |
| + : StyleInterpolation(start, end, id), m_range(range), m_nonInterpolableData(nonInterpolableData) |
| + { |
| + } |
| + |
| + InterpolationRange m_range; |
| + |
| + Vector<typename T::NonInterpolableType> m_nonInterpolableData; |
| + |
| + static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(const CSSValue& value, Vector<typename T::NonInterpolableType> &nonInterpolableData) |
| + { |
| + const CSSValueList& listValue = toCSSValueList(value); |
| + nonInterpolableData.reserveCapacity(listValue.length()); |
| + OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(listValue.length()); |
| + typename T::NonInterpolableType elementData; |
| + for (size_t i = 0; i < listValue.length(); i++) { |
| + result->set(i, T::toInterpolableValue(*listValue.item(i), elementData)); |
| + nonInterpolableData.append(elementData); |
| + } |
| + return result.release(); |
| + } |
| + |
| + static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(InterpolableValue* value, const Vector<typename T::NonInterpolableType>& nonInterpolableData, InterpolationRange range = RangeAll) |
| + { |
| + InterpolableList* listValue = toInterpolableList(value); |
| + RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSeparated(); |
| + |
| + for (size_t i = 0; i < listValue->length(); i++) |
| + result->append(T::fromInterpolableValue(*(listValue->get(i)), nonInterpolableData[i], range)); |
| + return result.release(); |
| + } |
| + |
| + friend class ListStyleInterpolationTest; |
| +}; |
| + |
| +template<typename T> |
| +class ListStyleInterpolationImpl<T, void> : public StyleInterpolation { |
| +public: |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, void>> create(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, void>(listToInterpolableValue(start), listToInterpolableValue(end), id, range)); |
| + } |
| + |
| +private: |
| + ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + : StyleInterpolation(start, end, id), m_range(range) |
| + { |
| + } |
| + |
| + InterpolationRange m_range; |
| + |
| + static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(const CSSValue& value) |
| + { |
| + const CSSValueList& listValue = toCSSValueList(value); |
| + OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(listValue.length()); |
| + for (size_t i = 0; i < listValue.length(); i++) |
| + result->set(i, T::toInterpolableValue(*listValue.item(i))); |
| + return result.release(); |
| + } |
| + |
| + static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(InterpolableValue* value, InterpolationRange range = RangeAll) |
| + { |
| + InterpolableList* listValue = toInterpolableList(value); |
| + RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSeparated(); |
| + |
| + for (size_t i = 0; i < listValue->length(); i++) |
| + result->append(T::fromInterpolableValue(*(listValue->get(i)), range)); |
| + return result.release(); |
| + } |
| + |
| + virtual void apply(StyleResolverState& state) const override |
| + { |
| + StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cachedValue.get(), m_range).get()); |
| + } |
| + |
| + friend class ListStyleInterpolationTest; |
| + |
| +}; |
| + |
| +template<typename T> |
| +class ListStyleInterpolation { |
| +public: |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, typename T::NonInterpolableType>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + if (start.isValueList() && end.isValueList() && toCSSValueList(start).length() == toCSSValueList(end).length()) |
| + return ListStyleInterpolationImpl<T, typename T::NonInterpolableType>::create(start, end, id, range); |
| + return nullptr; |
| + } |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // ListStyleInterpolation_h |