Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 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 | |
| 13 namespace blink { | |
| 14 | |
| 15 template<typename InterpolationType, typename NonInterpolableData> | |
| 16 class ListStyleInterpolationImpl : public StyleInterpolation { | |
| 17 public: | |
| 18 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, NonInterpolableData>> create(const CSSValue& start, const CSSValue& end, CSSProp ertyID id, InterpolationRange range = RangeAll) | |
| 19 { | |
| 20 OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableTyp e>> startNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename Interpolat ionType::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
| |
| 21 OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableTyp e>> endNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename Interpolatio nType::NonInterpolableType>()); | |
| 22 | |
| 23 const CSSValueList& startList = toCSSValueList(start); | |
| 24 const CSSValueList& endList = toCSSValueList(end); | |
| 25 | |
| 26 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { | |
| 27 if (!InterpolationType::canCreateFrom(*startList.item(i), *endList.i tem(i))) { | |
| 28 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.
| |
| 29 } | |
| 30 } | |
| 31 | |
| 32 OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolableVal ue(start, *startNonInterpolableData.get()); | |
| 33 OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableValue (end, *endNonInterpolableData.get()); | |
| 34 | |
| 35 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationTy pe, NonInterpolableData>(startValue.release(), endValue.release(), id, startNonI nterpolableData.release(), range)); | |
| 36 } | |
| 37 | |
| 38 virtual void apply(StyleResolverState& state) const override | |
| 39 { | |
| 40 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), *m_nonInterpolableData.get(), m_range).get()); | |
| 41 } | |
| 42 | |
| 43 private: | |
| 44 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, | |
| 45 PassOwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolabl eType>> nonInterpolableData, InterpolationRange range = RangeAll) | |
| 46 : StyleInterpolation(start, end, id), m_range(range), m_nonInterpolableD ata(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.
| |
| 47 { | |
| 48 } | |
| 49 | |
| 50 InterpolationRange m_range; | |
| 51 | |
| 52 OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> m_nonInterpolableData; | |
| 53 | |
| 54 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData) | |
| 55 { | |
| 56 const CSSValueList& listValue = toCSSValueList(value); | |
| 57 nonInterpolableData.reserveCapacity(listValue.length()); | |
| 58 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); | |
| 59 typename InterpolationType::NonInterpolableType elementData; | |
| 60 for (size_t i = 0; i < listValue.length(); i++) { | |
| 61 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i), elementData)); | |
| 62 nonInterpolableData.append(elementData); | |
| 63 } | |
| 64 return result.release(); | |
| 65 } | |
| 66 | |
| 67 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData, InterpolationRange range = RangeAll) | |
| 68 { | |
| 69 InterpolableList* listValue = toInterpolableList(value); | |
| 70 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); | |
|
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
| |
| 71 | |
| 72 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.
| |
| 73 | |
| 74 for (size_t i = 0; i < listValue->length(); i++) | |
| 75 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), nonInterpolableData[i], range)); | |
| 76 return result.release(); | |
| 77 } | |
| 78 | |
| 79 friend class ListStyleInterpolationTest; | |
| 80 }; | |
| 81 | |
| 82 template<typename InterpolationType> | |
| 83 class ListStyleInterpolationImpl<InterpolationType, void> : public StyleInterpol ation { | |
| 84 public: | |
| 85 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, void>> create(const CSSValue& start, const CSSValue& end, CSSPropertyID id, Inte rpolationRange range = RangeAll) | |
| 86 { | |
| 87 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationTy pe, void>(listToInterpolableValue(start), listToInterpolableValue(end), id, rang e)); | |
| 88 } | |
| 89 | |
| 90 private: | |
| 91 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll) | |
| 92 : StyleInterpolation(start, end, id), m_range(range) | |
| 93 { | |
| 94 } | |
| 95 | |
| 96 InterpolationRange m_range; | |
| 97 | |
| 98 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value) | |
| 99 { | |
| 100 const CSSValueList& listValue = toCSSValueList(value); | |
| 101 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); | |
| 102 for (size_t i = 0; i < listValue.length(); i++) | |
| 103 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i))); | |
| 104 return result.release(); | |
| 105 } | |
| 106 | |
| 107 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll) | |
| 108 { | |
| 109 InterpolableList* listValue = toInterpolableList(value); | |
| 110 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); | |
| 111 | |
| 112 for (size_t i = 0; i < listValue->length(); i++) | |
| 113 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), range)); | |
| 114 return result.release(); | |
| 115 } | |
| 116 | |
| 117 virtual void apply(StyleResolverState& state) const override | |
| 118 { | |
| 119 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get()); | |
| 120 } | |
| 121 | |
| 122 friend class ListStyleInterpolationTest; | |
| 123 | |
| 124 }; | |
| 125 | |
| 126 template<typename InterpolationType> | |
| 127 class ListStyleInterpolation { | |
| 128 public: | |
| 129 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>> maybeCreateFromList(const CSS Value& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) | |
| 130 { | |
| 131 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == 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.
| |
| 132 return ListStyleInterpolationImpl<InterpolationType, typename Interp olationType::NonInterpolableType>::create(start, end, id, range); | |
| 133 return nullptr; | |
| 134 } | |
| 135 }; | |
| 136 | |
| 137 } // namespace blink | |
| 138 | |
| 139 #endif // ListStyleInterpolation_h | |
| OLD | NEW |