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..f4d5ffb82fb706a8162aabb84257100afa93d1a3 |
| --- /dev/null |
| +++ b/Source/core/animation/ListStyleInterpolation.h |
| @@ -0,0 +1,138 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
samli
2015/01/23 03:23:36
2015
evemj (not active)
2015/01/28 00:41:13
Done.
|
| +// 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" |
| +#include "platform/Length.h" |
| + |
|
jadeg
2015/01/21 05:36:34
Do you need this platform/Length.h?
evemj (not active)
2015/01/28 00:41:13
Done.
|
| +namespace blink { |
| + |
| +template<typename T, typename NI> |
|
samli
2015/01/23 03:23:36
template <typename..
|
| +class ListStyleInterpolationImpl : public StyleInterpolation { |
| +public: |
| + static bool canCreateFrom(const CSSValue& value) |
| + { |
| + return value.isValueList(); |
| + } |
| + |
| + static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, NI>> create(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) |
|
jadeg
2015/01/21 05:36:34
This seems like a strange way to assign a value?
samli
2015/01/23 03:23:36
Seems fine.
samli
2015/01/23 03:23:36
<T, NI> >
use git cl format
Timothy Loh
2015/01/27 03:36:53
Using >> is fine nowadays
|
| + { |
| + Vector<typename T::NonInterpolableType> nonInterpolableData; |
| + Vector<typename T::NonInterpolableType> nonInterpolableDataToo; |
|
samli
2015/01/23 03:23:36
Rename it to startNonInterpolableData, endNonInter
evemj (not active)
2015/01/28 00:41:13
Done.
|
| + |
| + for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| + if (!T::canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueList(end).item(i))) { |
|
jadeg
2015/01/21 05:36:34
Can you put a , in an if statement?
samli
2015/01/23 03:23:36
It's not in the if statement.
|
| + return nullptr; |
| + } |
| + } |
| + return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, NI>(listToInterpolableValue(start, nonInterpolableData), listToInterpolableValue(end, nonInterpolableDataToo), id, nonInterpolableData, 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) |
| + { |
| + 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))); |
| + } |
|
samli
2015/01/23 03:23:36
For consistency with below, remove braces.
evemj (not active)
2015/01/28 00:41:13
Done.
|
| + 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; |
|
jadeg
2015/01/21 05:36:34
Is there a way to make one of these classes inheri
|
| + |
| +}; |
| + |
| +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()) { |
| + if (toCSSValueList(start).length() == toCSSValueList(end).length()) { |
|
samli
2015/01/23 03:23:36
Combine into one if statement
evemj (not active)
2015/01/28 00:41:13
Done.
|
| + return ListStyleInterpolationImpl<T, typename T::NonInterpolableType>::create(start, end, id, range); |
| + } |
| + } |
| + return nullptr; |
| + } |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // ListStyleInterpolation_h |
|
jadeg
2015/01/21 05:36:34
Need newline at end (pedantic i know)
evemj (not active)
2015/01/28 00:41:13
I think the codereview page doesn't show the new l
|