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

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: Created 5 years, 10 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>
dstockwell 2015/01/30 04:24:01 expand T and NI into CamelWords I have no idea wh
evemj (not active) 2015/02/02 03:56:02 Done.
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 OwnPtrWillBeRawPtr<WillBeHeapVector<typename T::NonInterpolableType>> st artNonInterpolableData = adoptPtrWillBeNoop(new WillBeHeapVector<typename T::Non InterpolableType>());
21 OwnPtrWillBeRawPtr<WillBeHeapVector<typename T::NonInterpolableType>> en dNonInterpolableData = adoptPtrWillBeNoop(new WillBeHeapVector<typename T::NonIn terpolableType>());
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
32 OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolableVal ue(start, *startNonInterpolableData.get());
33 OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableValue (end, *endNonInterpolableData.get());
34
35 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, NI>(startVal ue.release(), endValue.release(), id, startNonInterpolableData.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<WillBeHeapVector<typename T::NonInterpolableType> > nonInterpolableData, InterpolationRange range = RangeAll)
46 : StyleInterpolation(start, end, id), m_range(range), m_nonInterpolableD ata(nonInterpolableData)
47 {
48 }
49
50 InterpolationRange m_range;
51
52 OwnPtrWillBeRawPtr<WillBeHeapVector<typename T::NonInterpolableType>> m_nonI nterpolableData;
dstockwell 2015/01/30 04:24:01 Why heap vector?
evemj (not active) 2015/02/02 03:56:02 Done. I didn't fully understand how the WillBeHea
53
54 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, WillBeHeapVector<typename T::NonInterpolableType>& nonInterp olableData)
55 {
56 const CSSValueList& listValue = toCSSValueList(value);
57 nonInterpolableData.reserveCapacity(listValue.length());
58 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
59 typename T::NonInterpolableType elementData = false;
dstockwell 2015/01/30 04:24:01 Can't NonInterpolableType be something other than
samli 2015/01/30 07:20:30 Yes. @eve: this shouldn't be here anymore :)
evemj (not active) 2015/02/02 03:56:02 Yep sorry that was a mistake! Done.
60 for (size_t i = 0; i < listValue.length(); i++) {
61 result->set(i, T::toInterpolableValue(*listValue.item(i), elementDat a));
62 nonInterpolableData.append(elementData);
63 }
64 return result.release();
65 }
66
67 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const WillBeHeapVector<typename T::NonInterpolableType>& nonInterp olableData, InterpolationRange range = RangeAll)
68 {
69 InterpolableList* listValue = toInterpolableList(value);
70 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
71
72 ASSERT(nonInterpolableData.size() != 0);
73
74 for (size_t i = 0; i < listValue->length(); i++)
75 result->append(T::fromInterpolableValue(*(listValue->get(i)), nonInt erpolableData[i], range));
76 return result.release();
77 }
78
79 friend class ListStyleInterpolationTest;
80 };
81
82 template<typename T>
83 class ListStyleInterpolationImpl<T, void> : public StyleInterpolation {
84 public:
85 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, void>> create(co nst CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange r ange = RangeAll)
86 {
87 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<T, void>(listTo InterpolableValue(start), listToInterpolableValue(end), id, range));
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, T::toInterpolableValue(*listValue.item(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(T::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 T>
127 class ListStyleInterpolation {
128 public:
129 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<T, typename T::NonI nterpolableType>> maybeCreateFromList(const CSSValue& start, const CSSValue& en d, CSSPropertyID id, InterpolationRange range = RangeAll)
130 {
131 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length())
dstockwell 2015/01/30 04:24:01 Don't we need to support lists of different length
evemj (not active) 2015/02/02 03:56:02 I think this class is just for simple lists (not r
dstockwell 2015/02/02 06:10:11 Will we create a separate template for repeatable
evemj (not active) 2015/02/03 00:25:55 I got the impression that we would extend this tem
132 return ListStyleInterpolationImpl<T, typename T::NonInterpolableType >::create(start, end, id, range);
133 return nullptr;
134 }
135 };
136
137 } // namespace blink
138
139 #endif // ListStyleInterpolation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698