Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // 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.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ListStyleInterpolation_h | |
| 6 #define ListStyleInterpolation_h | |
| 7 | |
| 8 #include "core/animation/StyleInterpolation.h" | |
| 9 #include "core/css/CSSPrimitiveValue.h" | |
| 10 #include "core/css/CSSValueList.h" | |
| 11 #include "core/css/resolver/StyleBuilder.h" | |
| 12 #include "platform/Length.h" | |
| 13 | |
|
jadeg
2015/01/21 05:36:34
Do you need this platform/Length.h?
evemj (not active)
2015/01/28 00:41:13
Done.
| |
| 14 namespace blink { | |
| 15 | |
| 16 template<typename T, typename NI> | |
|
samli
2015/01/23 03:23:36
template <typename..
| |
| 17 class ListStyleInterpolationImpl : public StyleInterpolation { | |
| 18 public: | |
| 19 static bool canCreateFrom(const CSSValue& value) | |
| 20 { | |
| 21 return value.isValueList(); | |
| 22 } | |
| 23 | |
| 24 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, NI>> create(cons t CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange ran ge = 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
| |
| 25 { | |
| 26 Vector<typename T::NonInterpolableType> nonInterpolableData; | |
| 27 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.
| |
| 28 | |
| 29 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { | |
| 30 if (!T::canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueLis t(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.
| |
| 31 return nullptr; | |
| 32 } | |
| 33 } | |
| 34 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, NI>(listToIn terpolableValue(start, nonInterpolableData), listToInterpolableValue(end, nonInt erpolableDataToo), id, nonInterpolableData, range)); | |
| 35 } | |
| 36 | |
| 37 virtual void apply(StyleResolverState& state) const override | |
| 38 { | |
| 39 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_nonInterpolableData, m_range).get()); | |
| 40 } | |
| 41 | |
| 42 private: | |
| 43 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, Vector<typename T::NonInterpolableType> nonInterpolableData, InterpolationRange range = RangeAl l) | |
| 44 : StyleInterpolation(start, end, id), m_range(range), m_nonInterpolableD ata(nonInterpolableData) | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 InterpolationRange m_range; | |
| 49 | |
| 50 Vector<typename T::NonInterpolableType> m_nonInterpolableData; | |
| 51 | |
| 52 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename T::NonInterpolableType> &nonInterpolableData ) | |
| 53 { | |
| 54 const CSSValueList& listValue = toCSSValueList(value); | |
| 55 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); | |
| 56 typename T::NonInterpolableType elementData; | |
| 57 for (size_t i = 0; i < listValue.length(); i++) { | |
| 58 result->set(i, T::toInterpolableValue(*listValue.item(i), elementDat a)); | |
| 59 nonInterpolableData.append(elementData); | |
| 60 } | |
| 61 return result.release(); | |
| 62 } | |
| 63 | |
| 64 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, Vector<typename T::NonInterpolableType> nonInterpolableData, Inte rpolationRange range = RangeAll) | |
| 65 { | |
| 66 InterpolableList* listValue = toInterpolableList(value); | |
| 67 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); | |
| 68 | |
| 69 for (size_t i = 0; i < listValue->length(); i++) | |
| 70 result->append(T::fromInterpolableValue(*(listValue->get(i)), nonInt erpolableData[i], range)); | |
| 71 return result.release(); | |
| 72 } | |
| 73 | |
| 74 friend class ListStyleInterpolationTest; | |
| 75 }; | |
| 76 | |
| 77 template<typename T> | |
| 78 class ListStyleInterpolationImpl<T, void> : public StyleInterpolation { | |
| 79 public: | |
| 80 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, void>> create(co nst CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange r ange = RangeAll) | |
| 81 { | |
| 82 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, void>(listTo InterpolableValue(start), listToInterpolableValue(end), id, range)); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll) | |
| 87 : StyleInterpolation(start, end, id), m_range(range) | |
| 88 { | |
| 89 } | |
| 90 | |
| 91 InterpolationRange m_range; | |
| 92 | |
| 93 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value) | |
| 94 { | |
| 95 const CSSValueList& listValue = toCSSValueList(value); | |
| 96 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); | |
| 97 for (size_t i = 0; i < listValue.length(); i++) { | |
| 98 result->set(i, T::toInterpolableValue(*listValue.item(i))); | |
| 99 } | |
|
samli
2015/01/23 03:23:36
For consistency with below, remove braces.
evemj (not active)
2015/01/28 00:41:13
Done.
| |
| 100 return result.release(); | |
| 101 } | |
| 102 | |
| 103 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll) | |
| 104 { | |
| 105 InterpolableList* listValue = toInterpolableList(value); | |
| 106 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); | |
| 107 | |
| 108 for (size_t i = 0; i < listValue->length(); i++) | |
| 109 result->append(T::fromInterpolableValue(*(listValue->get(i)), range) ); | |
| 110 return result.release(); | |
| 111 } | |
| 112 | |
| 113 virtual void apply(StyleResolverState& state) const override | |
| 114 { | |
| 115 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get()); | |
| 116 } | |
| 117 | |
| 118 friend class ListStyleInterpolationTest; | |
|
jadeg
2015/01/21 05:36:34
Is there a way to make one of these classes inheri
| |
| 119 | |
| 120 }; | |
| 121 | |
| 122 template<typename T> | |
| 123 class ListStyleInterpolation { | |
| 124 public: | |
| 125 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, typename T::NonI nterpolableType>> maybeCreateFromList(const CSSValue& start, const CSSValue& en d, CSSPropertyID id, InterpolationRange range = RangeAll) | |
| 126 { | |
| 127 if (start.isValueList() && end.isValueList()) { | |
| 128 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.
| |
| 129 return ListStyleInterpolationImpl<T, typename T::NonInterpolable Type>::create(start, end, id, range); | |
| 130 } | |
| 131 } | |
| 132 return nullptr; | |
| 133 } | |
| 134 }; | |
| 135 | |
| 136 } // namespace blink | |
| 137 | |
| 138 #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
| |
| OLD | NEW |