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

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 else to shadowToInterpolableValue 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 Vector<typename InterpolationType::NonInterpolableType> startNonInte rpolableData;
31
32 OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolabl eValue(start, &startNonInterpolableData);
33 OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableV alue(end);
34
35 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<Interpolati onType, NonInterpolableData>(startValue.release(), endValue.release(), id, start NonInterpolableData, range));
36 }
37 return nullptr;
38 }
39
40 virtual void apply(StyleResolverState& state) const override
41 {
42 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_nonInterpolableData, m_range).get());
43 }
44
45 private:
46 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id,
47 Vector<typename InterpolationType::NonInterpolableType> nonInterpolableD ata, InterpolationRange range = RangeAll)
48 : StyleInterpolation(start, end, id)
49 , m_range(range)
50 {
51 m_nonInterpolableData.swap(nonInterpolableData);
52 }
53
54 InterpolationRange m_range;
55
56 Vector<typename InterpolationType::NonInterpolableType> m_nonInterpolableDat a;
57
58 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename InterpolationType::NonInterpolableType>* non InterpolableData = nullptr)
59 {
60 const CSSValueList& listValue = toCSSValueList(value);
61 if (nonInterpolableData)
62 nonInterpolableData->reserveCapacity(listValue.length());
63 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
64 typename InterpolationType::NonInterpolableType elementData = true;
65 for (size_t i = 0; i < listValue.length(); i++) {
66 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i), elementData));
67 if (nonInterpolableData)
68 nonInterpolableData->append(elementData);
69 }
70 return result.release();
71 }
72
73 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData, InterpolationRange range = RangeAll)
74 {
75 InterpolableList* listValue = toInterpolableList(value);
76 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
77
78 ASSERT(nonInterpolableData.size() == listValue->length());
79
80 for (size_t i = 0; i < listValue->length(); i++)
81 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), nonInterpolableData[i], range));
82 return result.release();
83 }
84
85 friend class ListStyleInterpolationTest;
86 };
87
88 template<typename InterpolationType>
89 class ListStyleInterpolationImpl<InterpolationType, void> : public StyleInterpol ation {
90 public:
91 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, void>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSProper tyID id, InterpolationRange range = RangeAll)
92 {
93 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length())
94 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<Interpolati onType, void>(listToInterpolableValue(start), listToInterpolableValue(end), id, range));
95 return nullptr;
96 }
97
98 private:
99 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll)
100 : StyleInterpolation(start, end, id), m_range(range)
101 {
102 }
103
104 InterpolationRange m_range;
105
106 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value)
107 {
108 const CSSValueList& listValue = toCSSValueList(value);
109 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length());
110 for (size_t i = 0; i < listValue.length(); i++)
111 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i)));
112 return result.release();
113 }
114
115 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll)
116 {
117 InterpolableList* listValue = toInterpolableList(value);
118 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
119
120 for (size_t i = 0; i < listValue->length(); i++)
121 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), range));
122 return result.release();
123 }
124
125 virtual void apply(StyleResolverState& state) const override
126 {
127 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get());
128 }
129
130 friend class ListStyleInterpolationTest;
131
132 };
133
134 template<typename InterpolationType>
135 class ListStyleInterpolation {
136 public:
137 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>> maybeCreateFromList(const CSS Value& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll)
138 {
139 return ListStyleInterpolationImpl<InterpolationType, typename Interpolat ionType::NonInterpolableType>::maybeCreateFromList(start, end, id, range);
140 }
141 };
142
143 } // namespace blink
144
145 #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