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 T, typename NI> | |
16 class ListStyleInterpolationImpl : public StyleInterpolation { | |
17 public: | |
18 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, NI>> create(cons t CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange ran ge = RangeAll) | |
19 { | |
20 Vector<typename T::NonInterpolableType> startNonInterpolableData; | |
21 Vector<typename T::NonInterpolableType> endNonInterpolableData; | |
22 | |
23 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { | |
Eric Willigers
2015/01/28 02:21:23
Consider defining
const CSSValueList& startList
evemj (not active)
2015/01/28 23:01:53
Done.
| |
24 if (!T::canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueLis t(end).item(i))) { | |
25 return nullptr; | |
26 } | |
27 } | |
28 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, NI>(listToIn terpolableValue(start, startNonInterpolableData), listToInterpolableValue(end, e ndNonInterpolableData), id, startNonInterpolableData, range)); | |
29 } | |
30 | |
31 virtual void apply(StyleResolverState& state) const override | |
32 { | |
33 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_nonInterpolableData, m_range).get()); | |
34 } | |
35 | |
36 private: | |
37 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, Vector<typename T::NonInterpolableType> nonInterpolableData, InterpolationRange range = RangeAl l) | |
38 : StyleInterpolation(start, end, id), m_range(range), m_nonInterpolableD ata(nonInterpolableData) | |
39 { | |
40 } | |
41 | |
42 InterpolationRange m_range; | |
43 | |
44 Vector<typename T::NonInterpolableType> m_nonInterpolableData; | |
45 | |
46 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename T::NonInterpolableType> &nonInterpolableData ) | |
47 { | |
48 const CSSValueList& listValue = toCSSValueList(value); | |
49 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); | |
50 typename T::NonInterpolableType elementData; | |
51 for (size_t i = 0; i < listValue.length(); i++) { | |
52 result->set(i, T::toInterpolableValue(*listValue.item(i), elementDat a)); | |
53 nonInterpolableData.append(elementData); | |
54 } | |
55 return result.release(); | |
56 } | |
57 | |
58 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, Vector<typename T::NonInterpolableType> nonInterpolableData, Inte rpolationRange range = RangeAll) | |
Eric Willigers
2015/01/28 02:21:23
Perhaps
const Vector<typename T::NonInterpolableTy
evemj (not active)
2015/01/28 23:01:53
Done.
| |
59 { | |
60 InterpolableList* listValue = toInterpolableList(value); | |
61 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); | |
62 | |
63 for (size_t i = 0; i < listValue->length(); i++) | |
64 result->append(T::fromInterpolableValue(*(listValue->get(i)), nonInt erpolableData[i], range)); | |
65 return result.release(); | |
66 } | |
67 | |
68 friend class ListStyleInterpolationTest; | |
69 }; | |
70 | |
71 template<typename T> | |
72 class ListStyleInterpolationImpl<T, void> : public StyleInterpolation { | |
73 public: | |
74 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, void>> create(co nst CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange r ange = RangeAll) | |
75 { | |
76 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, void>(listTo InterpolableValue(start), listToInterpolableValue(end), id, range)); | |
77 } | |
78 | |
79 private: | |
80 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll) | |
81 : StyleInterpolation(start, end, id), m_range(range) | |
82 { | |
83 } | |
84 | |
85 InterpolationRange m_range; | |
86 | |
87 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value) | |
88 { | |
89 const CSSValueList& listValue = toCSSValueList(value); | |
90 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); | |
91 for (size_t i = 0; i < listValue.length(); i++) | |
92 result->set(i, T::toInterpolableValue(*listValue.item(i))); | |
93 return result.release(); | |
94 } | |
95 | |
96 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll) | |
97 { | |
98 InterpolableList* listValue = toInterpolableList(value); | |
99 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); | |
100 | |
101 for (size_t i = 0; i < listValue->length(); i++) | |
102 result->append(T::fromInterpolableValue(*(listValue->get(i)), range) ); | |
103 return result.release(); | |
104 } | |
105 | |
106 virtual void apply(StyleResolverState& state) const override | |
107 { | |
108 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get()); | |
109 } | |
110 | |
111 friend class ListStyleInterpolationTest; | |
112 | |
113 }; | |
114 | |
115 template<typename T> | |
116 class ListStyleInterpolation { | |
117 public: | |
118 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, typename T::NonI nterpolableType>> maybeCreateFromList(const CSSValue& start, const CSSValue& en d, CSSPropertyID id, InterpolationRange range = RangeAll) | |
119 { | |
120 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length()) | |
121 return ListStyleInterpolationImpl<T, typename T::NonInterpolableType >::create(start, end, id, range); | |
122 return nullptr; | |
123 } | |
124 }; | |
125 | |
126 } // namespace blink | |
127 | |
128 #endif // ListStyleInterpolation_h | |
OLD | NEW |