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

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

Issue 1276183004: Oilpan: Unship oilpan from temporary animation objects (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef ListStyleInterpolation_h 5 #ifndef ListStyleInterpolation_h
6 #define ListStyleInterpolation_h 6 #define ListStyleInterpolation_h
7 7
8 #include "core/animation/StyleInterpolation.h" 8 #include "core/animation/StyleInterpolation.h"
9 #include "core/css/CSSPrimitiveValue.h" 9 #include "core/css/CSSPrimitiveValue.h"
10 #include "core/css/CSSValueList.h" 10 #include "core/css/CSSValueList.h"
11 #include "core/css/resolver/StyleBuilder.h" 11 #include "core/css/resolver/StyleBuilder.h"
12 12
13 namespace blink { 13 namespace blink {
14 14
15 template<typename InterpolationType, typename NonInterpolableData> 15 template<typename InterpolationType, typename NonInterpolableData>
16 class ListStyleInterpolationImpl : public StyleInterpolation { 16 class ListStyleInterpolationImpl : public StyleInterpolation {
17 public: 17 public:
18 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, NonInterpolableData>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) 18 static PassRefPtr<ListStyleInterpolationImpl<InterpolationType, NonInterpola bleData>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSPro pertyID id, InterpolationRange range = RangeAll)
19 { 19 {
20 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length()) { 20 if (start.isValueList() && end.isValueList() && toCSSValueList(start).le ngth() == toCSSValueList(end).length()) {
21 const CSSValueList& startList = toCSSValueList(start); 21 const CSSValueList& startList = toCSSValueList(start);
22 const CSSValueList& endList = toCSSValueList(end); 22 const CSSValueList& endList = toCSSValueList(end);
23 23
24 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { 24 for (size_t i = 0; i < toCSSValueList(start).length(); i++) {
25 if (!InterpolationType::canCreateFrom(*startList.item(i), *endLi st.item(i))) { 25 if (!InterpolationType::canCreateFrom(*startList.item(i), *endLi st.item(i))) {
26 return nullptr; 26 return nullptr;
27 } 27 }
28 } 28 }
29 29
30 Vector<typename InterpolationType::NonInterpolableType> startNonInte rpolableData; 30 Vector<typename InterpolationType::NonInterpolableType> startNonInte rpolableData;
31 31
32 OwnPtrWillBeRawPtr<InterpolableValue> startValue = listToInterpolabl eValue(start, &startNonInterpolableData); 32 OwnPtr<InterpolableValue> startValue = listToInterpolableValue(start , &startNonInterpolableData);
33 OwnPtrWillBeRawPtr<InterpolableValue> endValue = listToInterpolableV alue(end); 33 OwnPtr<InterpolableValue> endValue = listToInterpolableValue(end);
34 34
35 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<Interpolati onType, NonInterpolableData>(startValue.release(), endValue.release(), id, start NonInterpolableData, range)); 35 return adoptRef(new ListStyleInterpolationImpl<InterpolationType, No nInterpolableData>(startValue.release(), endValue.release(), id, startNonInterpo lableData, range));
36 } 36 }
37 return nullptr; 37 return nullptr;
38 } 38 }
39 39
40 void apply(StyleResolverState& state) const override 40 void apply(StyleResolverState& state) const override
41 { 41 {
42 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_nonInterpolableData, m_range).get()); 42 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_nonInterpolableData, m_range).get());
43 } 43 }
44 44
45 private: 45 private:
46 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, 46 ListStyleInterpolationImpl(PassOwnPtr<InterpolableValue> start, PassOwnPtr<I nterpolableValue> end, CSSPropertyID id,
47 Vector<typename InterpolationType::NonInterpolableType> nonInterpolableD ata, InterpolationRange range = RangeAll) 47 Vector<typename InterpolationType::NonInterpolableType> nonInterpolableD ata, InterpolationRange range = RangeAll)
48 : StyleInterpolation(start, end, id) 48 : StyleInterpolation(start, end, id)
49 , m_range(range) 49 , m_range(range)
50 { 50 {
51 m_nonInterpolableData.swap(nonInterpolableData); 51 m_nonInterpolableData.swap(nonInterpolableData);
52 } 52 }
53 53
54 InterpolationRange m_range; 54 InterpolationRange m_range;
55 55
56 Vector<typename InterpolationType::NonInterpolableType> m_nonInterpolableDat a; 56 Vector<typename InterpolationType::NonInterpolableType> m_nonInterpolableDat a;
57 57
58 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value, Vector<typename InterpolationType::NonInterpolableType>* non InterpolableData = nullptr) 58 static PassOwnPtr<InterpolableValue> listToInterpolableValue(const CSSValue& value, Vector<typename InterpolationType::NonInterpolableType>* nonInterpolable Data = nullptr)
59 { 59 {
60 const CSSValueList& listValue = toCSSValueList(value); 60 const CSSValueList& listValue = toCSSValueList(value);
61 if (nonInterpolableData) 61 if (nonInterpolableData)
62 nonInterpolableData->reserveCapacity(listValue.length()); 62 nonInterpolableData->reserveCapacity(listValue.length());
63 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); 63 OwnPtr<InterpolableList> result = InterpolableList::create(listValue.len gth());
64 typename InterpolationType::NonInterpolableType elementData = typename I nterpolationType::NonInterpolableType(); 64 typename InterpolationType::NonInterpolableType elementData = typename I nterpolationType::NonInterpolableType();
65 for (size_t i = 0; i < listValue.length(); i++) { 65 for (size_t i = 0; i < listValue.length(); i++) {
66 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i), elementData)); 66 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i), elementData));
67 if (nonInterpolableData) 67 if (nonInterpolableData)
68 nonInterpolableData->append(elementData); 68 nonInterpolableData->append(elementData);
69 } 69 }
70 return result.release(); 70 return result.release();
71 } 71 }
72 72
73 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData, InterpolationRange range = RangeAll) 73 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, const Vector<typename InterpolationType::NonInterpolableType>& non InterpolableData, InterpolationRange range = RangeAll)
74 { 74 {
75 InterpolableList* listValue = toInterpolableList(value); 75 InterpolableList* listValue = toInterpolableList(value);
76 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); 76 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
77 77
78 ASSERT(nonInterpolableData.size() == listValue->length()); 78 ASSERT(nonInterpolableData.size() == listValue->length());
79 79
80 for (size_t i = 0; i < listValue->length(); i++) 80 for (size_t i = 0; i < listValue->length(); i++)
81 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), nonInterpolableData[i], range)); 81 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), nonInterpolableData[i], range));
82 return result.release(); 82 return result.release();
83 } 83 }
84 84
85 friend class ListStyleInterpolationTest; 85 friend class ListStyleInterpolationTest;
86 }; 86 };
87 87
88 template<typename InterpolationType> 88 template<typename InterpolationType>
89 class ListStyleInterpolationImpl<InterpolationType, void> : public StyleInterpol ation { 89 class ListStyleInterpolationImpl<InterpolationType, void> : public StyleInterpol ation {
90 public: 90 public:
91 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, void>> maybeCreateFromList(const CSSValue& start, const CSSValue& end, CSSProper tyID id, InterpolationRange range = RangeAll) 91 static PassRefPtr<ListStyleInterpolationImpl<InterpolationType, void>> maybe CreateFromList(const CSSValue& start, const CSSValue& end, CSSPropertyID id, Int erpolationRange range = RangeAll)
92 { 92 {
93 if (!start.isValueList() || !end.isValueList()) 93 if (!start.isValueList() || !end.isValueList())
94 return nullptr; 94 return nullptr;
95 const CSSValueList& startList = toCSSValueList(start); 95 const CSSValueList& startList = toCSSValueList(start);
96 const CSSValueList& endList = toCSSValueList(end); 96 const CSSValueList& endList = toCSSValueList(end);
97 if (startList.length() != endList.length()) 97 if (startList.length() != endList.length())
98 return nullptr; 98 return nullptr;
99 for (const auto& value : startList) { 99 for (const auto& value : startList) {
100 if (!InterpolationType::canCreateFrom(*value)) 100 if (!InterpolationType::canCreateFrom(*value))
101 return nullptr; 101 return nullptr;
102 } 102 }
103 for (const auto& value : endList) { 103 for (const auto& value : endList) {
104 if (!InterpolationType::canCreateFrom(*value)) 104 if (!InterpolationType::canCreateFrom(*value))
105 return nullptr; 105 return nullptr;
106 } 106 }
107 return adoptRefWillBeNoop(new ListStyleInterpolationImpl<InterpolationTy pe, void>(listToInterpolableValue(start), listToInterpolableValue(end), id, rang e)); 107 return adoptRef(new ListStyleInterpolationImpl<InterpolationType, void>( listToInterpolableValue(start), listToInterpolableValue(end), id, range));
108 } 108 }
109 109
110 private: 110 private:
111 ListStyleInterpolationImpl(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, CSSPropertyID id, InterpolationRa nge range = RangeAll) 111 ListStyleInterpolationImpl(PassOwnPtr<InterpolableValue> start, PassOwnPtr<I nterpolableValue> end, CSSPropertyID id, InterpolationRange range = RangeAll)
112 : StyleInterpolation(start, end, id), m_range(range) 112 : StyleInterpolation(start, end, id), m_range(range)
113 { 113 {
114 } 114 }
115 115
116 InterpolationRange m_range; 116 InterpolationRange m_range;
117 117
118 static PassOwnPtrWillBeRawPtr<InterpolableValue> listToInterpolableValue(con st CSSValue& value) 118 static PassOwnPtr<InterpolableValue> listToInterpolableValue(const CSSValue& value)
119 { 119 {
120 const CSSValueList& listValue = toCSSValueList(value); 120 const CSSValueList& listValue = toCSSValueList(value);
121 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(l istValue.length()); 121 OwnPtr<InterpolableList> result = InterpolableList::create(listValue.len gth());
122 for (size_t i = 0; i < listValue.length(); i++) 122 for (size_t i = 0; i < listValue.length(); i++)
123 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i))); 123 result->set(i, InterpolationType::toInterpolableValue(*listValue.ite m(i)));
124 return result.release(); 124 return result.release();
125 } 125 }
126 126
127 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll) 127 static PassRefPtrWillBeRawPtr<CSSValue> interpolableValueToList(Interpolable Value* value, InterpolationRange range = RangeAll)
128 { 128 {
129 InterpolableList* listValue = toInterpolableList(value); 129 InterpolableList* listValue = toInterpolableList(value);
130 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated(); 130 RefPtrWillBeRawPtr<CSSValueList> result = CSSValueList::createCommaSepar ated();
131 131
132 for (size_t i = 0; i < listValue->length(); i++) 132 for (size_t i = 0; i < listValue->length(); i++)
133 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), range)); 133 result->append(InterpolationType::fromInterpolableValue(*(listValue- >get(i)), range));
134 return result.release(); 134 return result.release();
135 } 135 }
136 136
137 void apply(StyleResolverState& state) const override 137 void apply(StyleResolverState& state) const override
138 { 138 {
139 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get()); 139 StyleBuilder::applyProperty(m_id, state, interpolableValueToList(m_cache dValue.get(), m_range).get());
140 } 140 }
141 141
142 friend class ListStyleInterpolationTest; 142 friend class ListStyleInterpolationTest;
143 143
144 }; 144 };
145 145
146 template<typename InterpolationType> 146 template<typename InterpolationType>
147 class ListStyleInterpolation { 147 class ListStyleInterpolation {
148 public: 148 public:
149 static PassRefPtrWillBeRawPtr<ListStyleInterpolationImpl<InterpolationType, typename InterpolationType::NonInterpolableType>> maybeCreateFromList(const CSS Value& start, const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll) 149 static PassRefPtr<ListStyleInterpolationImpl<InterpolationType, typename Int erpolationType::NonInterpolableType>> maybeCreateFromList(const CSSValue& start , const CSSValue& end, CSSPropertyID id, InterpolationRange range = RangeAll)
150 { 150 {
151 return ListStyleInterpolationImpl<InterpolationType, typename Interpolat ionType::NonInterpolableType>::maybeCreateFromList(start, end, id, range); 151 return ListStyleInterpolationImpl<InterpolationType, typename Interpolat ionType::NonInterpolableType>::maybeCreateFromList(start, end, id, range);
152 } 152 }
153 }; 153 };
154 154
155 } // namespace blink 155 } // namespace blink
156 156
157 #endif // ListStyleInterpolation_h 157 #endif // ListStyleInterpolation_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698