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..a55d4115b4704a7233a6c432c81b52d21c46da94 |
| --- /dev/null |
| +++ b/Source/core/animation/ListStyleInterpolation.h |
| @@ -0,0 +1,144 @@ |
| +// 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 InterpolationType, typename NonInterpolableData> |
| +class ListStyleInterpolationImpl : public StyleInterpolation { |
| +public: |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, NonInterpolableData>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + if (start.isValueList() && end.isValueList() && toCSSValueList(start).length() == toCSSValueList(end).length()) { |
| + const CSSValueList& startList = toCSSValueList(start); |
| + const CSSValueList& endList = toCSSValueList(end); |
| + |
| + for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| + if (!InterpolationType::canCreateFrom(*startList.item(i), *endList.item(i))) { |
| + return nullptr; |
| + } |
| + } |
| + |
| + OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> endNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename InterpolationType::NonInterpolableType>()); |
|
dstockwell
2015/02/03 02:22:18
I think end/startNonInterpolableData can be just O
evemj (not active)
2015/02/03 03:45:50
Done.
Changed to own ptr and was getting compile
dstockwell
2015/02/03 05:20:40
Ahh, I see! I don't think that's a change we shoul
evemj (not active)
2015/02/03 05:58:45
Hopefully done!
|
| + OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> startNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename InterpolationType::NonInterpolableType>()); |
| + |
| + OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolableValue(start, *startNonInterpolableData.get()); |
| + OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableValue(end, *endNonInterpolableData.get()); |
|
dstockwell
2015/02/03 02:22:18
It seems like we just throw away the endNonInterpo
evemj (not active)
2015/02/03 03:45:50
Done.
Sam and I added a default parameter to list
|
| + |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationType, NonInterpolableData>(startValue.release(), endValue.release(), id, startNonInterpolableData.release(), range)); |
| + } |
| + return nullptr; |
| + } |
| + |
| + virtual void apply(StyleResolverState& state) const override |
| + { |
| + StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cachedValue.get(), *m_nonInterpolableData.get(), m_range).get()); |
| + } |
| + |
| +private: |
| + ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, |
| + PassOwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> nonInterpolableData, InterpolationRange range = RangeAll) |
| + : StyleInterpolation(start, end, id) |
| + , m_range(range) |
| + , m_nonInterpolableData(nonInterpolableData) |
| + { |
| + } |
| + |
| + InterpolationRange m_range; |
| + |
| + OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> m_nonInterpolableData; |
| + |
| + static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(const CSSValue& value, Vector<typename InterpolationType::NonInterpolableType>& nonInterpolableData) |
| + { |
| + const CSSValueList& listValue = toCSSValueList(value); |
| + nonInterpolableData.reserveCapacity(listValue.length()); |
| + OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(listValue.length()); |
| + typename InterpolationType::NonInterpolableType elementData; |
| + for (size_t i = 0; i < listValue.length(); i++) { |
| + result->set(i, InterpolationType::toInterpolableValue(*listValue.item(i), elementData)); |
| + nonInterpolableData.append(elementData); |
| + } |
| + return result.release(); |
| + } |
| + |
| + static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(InterpolableValue* value, const Vector<typename InterpolationType::NonInterpolableType>& nonInterpolableData, InterpolationRange range = RangeAll) |
| + { |
| + InterpolableList* listValue = toInterpolableList(value); |
| + RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSeparated(); |
| + |
| + ASSERT(nonInterpolableData.size() == listValue->length()); |
| + |
| + for (size_t i = 0; i < listValue->length(); i++) |
| + result->append(InterpolationType::fromInterpolableValue(*(listValue->get(i)), nonInterpolableData[i], range)); |
| + return result.release(); |
| + } |
| + |
| + friend class ListStyleInterpolationTest; |
| +}; |
| + |
| +template<typename InterpolationType> |
| +class ListStyleInterpolationImpl<InterpolationType, void> : public StyleInterpolation { |
| +public: |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, void>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + if (start.isValueList() && end.isValueList() && toCSSValueList(start).length() == toCSSValueList(end).length()) |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationType, void>(listToInterpolableValue(start), listToInterpolableValue(end), id, range)); |
| + return nullptr; |
| + } |
| + |
| +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, InterpolationType::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(InterpolationType::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 InterpolationType> |
| +class ListStyleInterpolation { |
| +public: |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + return ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>::maybeCreateFromList(start, end, id, range); |
| + } |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // ListStyleInterpolation_h |