Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: Source/core/animation/ListStyleInterpolation.h

Issue 851633002: Animation: Add template for ListStyleInterpolation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add separate variables for value lists Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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>
shans 2015/01/29 03:13:11 the 'NI' parameter doesn't appear to be used. It l
evemj (not active) 2015/02/02 03:56:01 Need the NI parameter so that template can be spec
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 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 (!T::canCreateFrom(*startList.item(i), *endList.item(i))) {
28 return nullptr;
29 }
30 }
31 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, NI>(listToIn terpolableValue(start, startNonInterpolableData), listToInterpolableValue(end, e ndNonInterpolableData), id, startNonInterpolableData, range));
32 }
33
34 virtual void apply(StyleResolverState& state) const override
35 {
36 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_nonInterpolableData, m_range).get());
37 }
38
39 private:
40 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, Vector<typename T::NonInterpolableType> nonInterpolableData, InterpolationRange range = RangeAl l)
41 : StyleInterpolation(start, end, id), m_range(range), m_nonInterpolableD ata(nonInterpolableData)
42 {
43 }
44
45 InterpolationRange m_range;
46
47 Vector<typename T::NonInterpolableType> m_nonInterpolableData;
48
49 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename T::NonInterpolableType> &nonInterpolableData )
50 {
51 const CSSValueList& listValue = toCSSValueList(value);
52 nonInterpolableData.reserveCapacity(listValue.length());
53 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
54 typename T::NonInterpolableType elementData;
55 for (size_t i = 0; i < listValue.length(); i++) {
56 result->set(i, T::toInterpolableValue(*listValue.item(i), elementDat a));
57 nonInterpolableData.append(elementData);
58 }
59 return result.release();
60 }
61
62 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const Vector<typename T::NonInterpolableType>& nonInterpolableDat a, InterpolationRange range = RangeAll)
63 {
64 InterpolableList* listValue = toInterpolableList(value);
65 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
66
67 for (size_t i = 0; i < listValue->length(); i++)
68 result->append(T::fromInterpolableValue(*(listValue->get(i)), nonInt erpolableData[i], range));
69 return result.release();
70 }
71
72 friend class ListStyleInterpolationTest;
73 };
74
75 template<typename T>
76 class ListStyleInterpolationImpl<T, void> : public StyleInterpolation {
77 public:
78 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, void>> create(co nst CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange r ange = RangeAll)
79 {
80 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, void>(listTo InterpolableValue(start), listToInterpolableValue(end), id, range));
81 }
82
83 private:
84 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll)
85 : StyleInterpolation(start, end, id), m_range(range)
86 {
87 }
88
89 InterpolationRange m_range;
90
91 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value)
92 {
93 const CSSValueList& listValue = toCSSValueList(value);
94 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
95 for (size_t i = 0; i < listValue.length(); i++)
96 result->set(i, T::toInterpolableValue(*listValue.item(i)));
97 return result.release();
98 }
99
100 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll)
101 {
102 InterpolableList* listValue = toInterpolableList(value);
103 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
104
105 for (size_t i = 0; i < listValue->length(); i++)
106 result->append(T::fromInterpolableValue(*(listValue->get(i)), range) );
107 return result.release();
108 }
109
110 virtual void apply(StyleResolverState& state) const override
111 {
112 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get());
113 }
114
115 friend class ListStyleInterpolationTest;
116
117 };
118
119 template<typename T>
120 class ListStyleInterpolation {
121 public:
122 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, typename T::NonI nterpolableType>> maybeCreateFromList(const CSSValue& start, const CSSValue& en d, CSSPropertyID id, InterpolationRange range = RangeAll)
123 {
124 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length())
125 return ListStyleInterpolationImpl<T, typename T::NonInterpolableType >::create(start, end, id, range);
126 return nullptr;
127 }
128 };
129
130 } // namespace blink
131
132 #endif // ListStyleInterpolation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698