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..c88ecf05b7342551414177db78570a126f3e6746 |
| --- /dev/null |
| +++ b/Source/core/animation/ListStyleInterpolation.h |
| @@ -0,0 +1,139 @@ |
| +// 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>> create(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> startNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename InterpolationType::NonInterpolableType>()); |
|
dstockwell
2015/02/02 06:10:11
Move these allocations closer to line 32, since we
evemj (not active)
2015/02/03 00:25:55
Done.
I got compile errors when I tried to change
|
| + OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> endNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename InterpolationType::NonInterpolableType>()); |
| + |
| + 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; |
|
dstockwell
2015/02/02 06:10:11
Should this method be called maybeCreate?
evemj (not active)
2015/02/03 00:25:55
Done.
|
| + } |
| + } |
| + |
| + OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolableValue(start, *startNonInterpolableData.get()); |
| + OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableValue(end, *endNonInterpolableData.get()); |
| + |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationType, NonInterpolableData>(startValue.release(), endValue.release(), id, startNonInterpolableData.release(), range)); |
| + } |
| + |
| + 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) |
|
dstockwell
2015/02/02 06:10:11
put each initialization on a separate line
dstockwell
2015/02/02 06:10:11
put each initialization on a separate line
evemj (not active)
2015/02/03 00:25:55
Done.
|
| + { |
| + } |
| + |
| + 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(); |
|
dstockwell
2015/02/02 06:10:11
Can we reserve capacity on a CSSValueList?
evemj (not active)
2015/02/03 00:25:55
I don't think so (or at least I couldn't find a me
|
| + |
| + ASSERT(nonInterpolableData.size() != 0); |
|
dstockwell
2015/02/02 06:10:11
Need to assert that it's the same length as listVa
evemj (not active)
2015/02/03 00:25:55
Done.
|
| + |
| + 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>> create(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
| + { |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationType, 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, 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) |
| + { |
| + if (start.isValueList() && end.isValueList() && toCSSValueList(start).length() == toCSSValueList(end).length()) |
|
dstockwell
2015/02/02 06:10:11
We should either move this check inside ListStyleI
evemj (not active)
2015/02/03 00:25:55
Done.
|
| + return ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>::create(start, end, id, range); |
| + return nullptr; |
| + } |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // ListStyleInterpolation_h |