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..476c4f93de9519e1a1475418014a8a6daab03a6f |
--- /dev/null |
+++ b/Source/core/animation/ListStyleInterpolation.h |
@@ -0,0 +1,128 @@ |
+// 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> |
+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; |
+ |
+ for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
Eric Willigers
2015/01/28 02:21:23
Consider defining
const CSSValueList& startList
evemj (not active)
2015/01/28 23:01:53
Done.
|
+ if (!T::canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueList(end).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); |
+ 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, Vector<typename T::NonInterpolableType> nonInterpolableData, InterpolationRange range = RangeAll) |
Eric Willigers
2015/01/28 02:21:23
Perhaps
const Vector<typename T::NonInterpolableTy
evemj (not active)
2015/01/28 23:01:53
Done.
|
+ { |
+ 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 |