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

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: Remove InterpolableBool from ShadowStyleInterpolation 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 InterpolationType, typename NonInterpolableData>
16 class ListStyleInterpolationImpl : public StyleInterpolation {
17 public:
18 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, NonInterpolableData>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll)
19 {
20 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length()) {
21 const CSSValueList& startList = toCSSValueList(start);
22 const CSSValueList& endList = toCSSValueList(end);
23
24 for (size_t i = 0; i < toCSSValueList(start).length(); i++) {
25 if (!InterpolationType::canCreateFrom(*startList.item(i), *endLi st.item(i))) {
26 return nullptr;
27 }
28 }
29
30 OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolabl eType>> endNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename Interpol ationType::NonInterpolableType>());
dstockwell 2015/02/03 02:22:18 I think end/startNonInterpolableData can be just O
evemj (not active) 2015/02/03 03:45:50 Done. Changed to own ptr and was getting compile
dstockwell 2015/02/03 05:20:40 Ahh, I see! I don't think that's a change we shoul
evemj (not active) 2015/02/03 05:58:45 Hopefully done!
31 OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolabl eType>> startNonInterpolableData = adoptPtrWillBeNoop(new Vector<typename Interp olationType::NonInterpolableType>());
32
33 OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolabl eValue(start, *startNonInterpolableData.get());
34 OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableV alue(end, *endNonInterpolableData.get());
dstockwell 2015/02/03 02:22:18 It seems like we just throw away the endNonInterpo
evemj (not active) 2015/02/03 03:45:50 Done. Sam and I added a default parameter to list
35
36 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<Interpolati onType, NonInterpolableData>(startValue.release(), endValue.release(), id, start NonInterpolableData.release(), range));
37 }
38 return nullptr;
39 }
40
41 virtual void apply(StyleResolverState& state) const override
42 {
43 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), *m_nonInterpolableData.get(), m_range).get());
44 }
45
46 private:
47 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id,
48 PassOwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolabl eType>> nonInterpolableData, InterpolationRange range = RangeAll)
49 : StyleInterpolation(start, end, id)
50 , m_range(range)
51 , m_nonInterpolableData(nonInterpolableData)
52 {
53 }
54
55 InterpolationRange m_range;
56
57 OwnPtrWillBeRawPtr<Vector<typename InterpolationType::NonInterpolableType>> m_nonInterpolableData;
58
59 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData)
60 {
61 const CSSValueList& listValue = toCSSValueList(value);
62 nonInterpolableData.reserveCapacity(listValue.length());
63 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
64 typename InterpolationType::NonInterpolableType elementData;
65 for (size_t i = 0; i < listValue.length(); i++) {
66 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i), elementData));
67 nonInterpolableData.append(elementData);
68 }
69 return result.release();
70 }
71
72 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData, InterpolationRange range = RangeAll)
73 {
74 InterpolableList* listValue = toInterpolableList(value);
75 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
76
77 ASSERT(nonInterpolableData.size() == listValue->length());
78
79 for (size_t i = 0; i < listValue->length(); i++)
80 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), nonInterpolableData[i], range));
81 return result.release();
82 }
83
84 friend class ListStyleInterpolationTest;
85 };
86
87 template<typename InterpolationType>
88 class ListStyleInterpolationImpl<InterpolationType, void> : public StyleInterpol ation {
89 public:
90 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, void>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSProper tyID id, InterpolationRange range = RangeAll)
91 {
92 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length())
93 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<Interpolati onType, void>(listToInterpolableValue(start), listToInterpolableValue(end), id, range));
94 return nullptr;
95 }
96
97 private:
98 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll)
99 : StyleInterpolation(start, end, id), m_range(range)
100 {
101 }
102
103 InterpolationRange m_range;
104
105 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value)
106 {
107 const CSSValueList& listValue = toCSSValueList(value);
108 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
109 for (size_t i = 0; i < listValue.length(); i++)
110 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i)));
111 return result.release();
112 }
113
114 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll)
115 {
116 InterpolableList* listValue = toInterpolableList(value);
117 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
118
119 for (size_t i = 0; i < listValue->length(); i++)
120 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), range));
121 return result.release();
122 }
123
124 virtual void apply(StyleResolverState& state) const override
125 {
126 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get());
127 }
128
129 friend class ListStyleInterpolationTest;
130
131 };
132
133 template<typename InterpolationType>
134 class ListStyleInterpolation {
135 public:
136 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>> maybeCreateFromList(const CSS Value& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll)
137 {
138 return ListStyleInterpolationImpl<InterpolationType, typename Interpolat ionType::NonInterpolableType>::maybeCreateFromList(start, end, id, range);
139 }
140 };
141
142 } // namespace blink
143
144 #endif // ListStyleInterpolation_h
OLDNEW
« no previous file with comments | « Source/core/animation/LengthStyleInterpolationTest.cpp ('k') | Source/core/animation/ListStyleInterpolationTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698