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

Side by Side Diff: third_party/WebKit/Source/core/animation/InterpolableValue.h

Issue 2050123002: Remove OwnPtr from Blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First attempt to land. Created 4 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 InterpolableValue_h 5 #ifndef InterpolableValue_h
6 #define InterpolableValue_h 6 #define InterpolableValue_h
7 7
8 #include "core/CoreExport.h" 8 #include "core/CoreExport.h"
9 #include "core/animation/animatable/AnimatableValue.h" 9 #include "core/animation/animatable/AnimatableValue.h"
10 #include "platform/heap/Handle.h" 10 #include "platform/heap/Handle.h"
11 #include "wtf/OwnPtr.h" 11 #include "wtf/PtrUtil.h"
12 #include "wtf/PassOwnPtr.h"
13 #include "wtf/Vector.h" 12 #include "wtf/Vector.h"
13 #include <memory>
14 14
15 namespace blink { 15 namespace blink {
16 16
17 // Represents the components of a PropertySpecificKeyframe's value that change s moothly as it interpolates to an adjacent value. 17 // Represents the components of a PropertySpecificKeyframe's value that change s moothly as it interpolates to an adjacent value.
18 class CORE_EXPORT InterpolableValue { 18 class CORE_EXPORT InterpolableValue {
19 USING_FAST_MALLOC(InterpolableValue); 19 USING_FAST_MALLOC(InterpolableValue);
20 public: 20 public:
21 virtual ~InterpolableValue() { } 21 virtual ~InterpolableValue() { }
22 22
23 virtual bool isNumber() const { return false; } 23 virtual bool isNumber() const { return false; }
24 virtual bool isBool() const { return false; } 24 virtual bool isBool() const { return false; }
25 virtual bool isList() const { return false; } 25 virtual bool isList() const { return false; }
26 virtual bool isAnimatableValue() const { return false; } 26 virtual bool isAnimatableValue() const { return false; }
27 27
28 virtual bool equals(const InterpolableValue&) const = 0; 28 virtual bool equals(const InterpolableValue&) const = 0;
29 virtual PassOwnPtr<InterpolableValue> clone() const = 0; 29 virtual std::unique_ptr<InterpolableValue> clone() const = 0;
30 virtual PassOwnPtr<InterpolableValue> cloneAndZero() const = 0; 30 virtual std::unique_ptr<InterpolableValue> cloneAndZero() const = 0;
31 virtual void scale(double scale) = 0; 31 virtual void scale(double scale) = 0;
32 virtual void scaleAndAdd(double scale, const InterpolableValue& other) = 0; 32 virtual void scaleAndAdd(double scale, const InterpolableValue& other) = 0;
33 33
34 private: 34 private:
35 virtual void interpolate(const InterpolableValue& to, const double progress, InterpolableValue& result) const = 0; 35 virtual void interpolate(const InterpolableValue& to, const double progress, InterpolableValue& result) const = 0;
36 36
37 friend class Interpolation; 37 friend class Interpolation;
38 friend class PairwisePrimitiveInterpolation; 38 friend class PairwisePrimitiveInterpolation;
39 39
40 // Keep interpolate private, but allow calls within the hierarchy without 40 // Keep interpolate private, but allow calls within the hierarchy without
41 // knowledge of type. 41 // knowledge of type.
42 friend class DeferredLegacyStyleInterpolation; 42 friend class DeferredLegacyStyleInterpolation;
43 friend class InterpolableNumber; 43 friend class InterpolableNumber;
44 friend class InterpolableBool; 44 friend class InterpolableBool;
45 friend class InterpolableList; 45 friend class InterpolableList;
46 46
47 friend class AnimationInterpolableValueTest; 47 friend class AnimationInterpolableValueTest;
48 }; 48 };
49 49
50 class CORE_EXPORT InterpolableNumber final : public InterpolableValue { 50 class CORE_EXPORT InterpolableNumber final : public InterpolableValue {
51 public: 51 public:
52 static PassOwnPtr<InterpolableNumber> create(double value) 52 static std::unique_ptr<InterpolableNumber> create(double value)
53 { 53 {
54 return adoptPtr(new InterpolableNumber(value)); 54 return wrapUnique(new InterpolableNumber(value));
55 } 55 }
56 56
57 bool isNumber() const final { return true; } 57 bool isNumber() const final { return true; }
58 double value() const { return m_value; } 58 double value() const { return m_value; }
59 bool equals(const InterpolableValue& other) const final; 59 bool equals(const InterpolableValue& other) const final;
60 PassOwnPtr<InterpolableValue> clone() const final { return create(m_value); } 60 std::unique_ptr<InterpolableValue> clone() const final { return create(m_val ue); }
61 PassOwnPtr<InterpolableValue> cloneAndZero() const final { return create(0); } 61 std::unique_ptr<InterpolableValue> cloneAndZero() const final { return creat e(0); }
62 void scale(double scale) final; 62 void scale(double scale) final;
63 void scaleAndAdd(double scale, const InterpolableValue& other) final; 63 void scaleAndAdd(double scale, const InterpolableValue& other) final;
64 void set(double value) { m_value = value; } 64 void set(double value) { m_value = value; }
65 65
66 private: 66 private:
67 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final; 67 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final;
68 double m_value; 68 double m_value;
69 69
70 explicit InterpolableNumber(double value) 70 explicit InterpolableNumber(double value)
71 : m_value(value) 71 : m_value(value)
72 { 72 {
73 } 73 }
74 74
75 }; 75 };
76 76
77 class CORE_EXPORT InterpolableBool final : public InterpolableValue { 77 class CORE_EXPORT InterpolableBool final : public InterpolableValue {
78 public: 78 public:
79 static PassOwnPtr<InterpolableBool> create(bool value) 79 static std::unique_ptr<InterpolableBool> create(bool value)
80 { 80 {
81 return adoptPtr(new InterpolableBool(value)); 81 return wrapUnique(new InterpolableBool(value));
82 } 82 }
83 83
84 bool isBool() const final { return true; } 84 bool isBool() const final { return true; }
85 bool value() const { return m_value; } 85 bool value() const { return m_value; }
86 bool equals(const InterpolableValue&) const final { ASSERT_NOT_REACHED(); re turn false; } 86 bool equals(const InterpolableValue&) const final { ASSERT_NOT_REACHED(); re turn false; }
87 PassOwnPtr<InterpolableValue> clone() const final { return create(m_value); } 87 std::unique_ptr<InterpolableValue> clone() const final { return create(m_val ue); }
88 PassOwnPtr<InterpolableValue> cloneAndZero() const final { ASSERT_NOT_REACHE D(); return nullptr; } 88 std::unique_ptr<InterpolableValue> cloneAndZero() const final { ASSERT_NOT_R EACHED(); return nullptr; }
89 void scale(double scale) final { ASSERT_NOT_REACHED(); } 89 void scale(double scale) final { ASSERT_NOT_REACHED(); }
90 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER T_NOT_REACHED(); } 90 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER T_NOT_REACHED(); }
91 91
92 private: 92 private:
93 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final; 93 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final;
94 bool m_value; 94 bool m_value;
95 95
96 explicit InterpolableBool(bool value) 96 explicit InterpolableBool(bool value)
97 : m_value(value) 97 : m_value(value)
98 { 98 {
99 } 99 }
100 100
101 }; 101 };
102 102
103 class CORE_EXPORT InterpolableList : public InterpolableValue { 103 class CORE_EXPORT InterpolableList : public InterpolableValue {
104 public: 104 public:
105 // Explicitly delete operator= because MSVC automatically generate 105 // Explicitly delete operator= because MSVC automatically generate
106 // copy constructors and operator= for dll-exported classes. 106 // copy constructors and operator= for dll-exported classes.
107 // Since InterpolableList is not copyable, automatically generated 107 // Since InterpolableList is not copyable, automatically generated
108 // operator= causes MSVC compiler error. 108 // operator= causes MSVC compiler error.
109 // However, we cannot use WTF_MAKE_NONCOPYABLE because InterpolableList 109 // However, we cannot use WTF_MAKE_NONCOPYABLE because InterpolableList
110 // has its own copy constructor. So just delete operator= here. 110 // has its own copy constructor. So just delete operator= here.
111 InterpolableList& operator=(const InterpolableList&) = delete; 111 InterpolableList& operator=(const InterpolableList&) = delete;
112 112
113 static PassOwnPtr<InterpolableList> create(const InterpolableList &other) 113 static std::unique_ptr<InterpolableList> create(const InterpolableList &othe r)
114 { 114 {
115 return adoptPtr(new InterpolableList(other)); 115 return wrapUnique(new InterpolableList(other));
116 } 116 }
117 117
118 static PassOwnPtr<InterpolableList> create(size_t size) 118 static std::unique_ptr<InterpolableList> create(size_t size)
119 { 119 {
120 return adoptPtr(new InterpolableList(size)); 120 return wrapUnique(new InterpolableList(size));
121 } 121 }
122 122
123 bool isList() const final { return true; } 123 bool isList() const final { return true; }
124 void set(size_t position, PassOwnPtr<InterpolableValue> value) 124 void set(size_t position, std::unique_ptr<InterpolableValue> value)
125 { 125 {
126 ASSERT(position < m_size); 126 ASSERT(position < m_size);
127 m_values[position] = std::move(value); 127 m_values[position] = std::move(value);
128 } 128 }
129 const InterpolableValue* get(size_t position) const 129 const InterpolableValue* get(size_t position) const
130 { 130 {
131 ASSERT(position < m_size); 131 ASSERT(position < m_size);
132 return m_values[position].get(); 132 return m_values[position].get();
133 } 133 }
134 OwnPtr<InterpolableValue>& getMutable(size_t position) 134 std::unique_ptr<InterpolableValue>& getMutable(size_t position)
135 { 135 {
136 ASSERT(position < m_size); 136 ASSERT(position < m_size);
137 return m_values[position]; 137 return m_values[position];
138 } 138 }
139 size_t length() const { return m_size; } 139 size_t length() const { return m_size; }
140 bool equals(const InterpolableValue& other) const final; 140 bool equals(const InterpolableValue& other) const final;
141 PassOwnPtr<InterpolableValue> clone() const final { return create(*this); } 141 std::unique_ptr<InterpolableValue> clone() const final { return create(*this ); }
142 PassOwnPtr<InterpolableValue> cloneAndZero() const final; 142 std::unique_ptr<InterpolableValue> cloneAndZero() const final;
143 void scale(double scale) final; 143 void scale(double scale) final;
144 void scaleAndAdd(double scale, const InterpolableValue& other) final; 144 void scaleAndAdd(double scale, const InterpolableValue& other) final;
145 145
146 private: 146 private:
147 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final; 147 void interpolate(const InterpolableValue& to, const double progress, Interpo lableValue& result) const final;
148 explicit InterpolableList(size_t size) 148 explicit InterpolableList(size_t size)
149 : m_size(size) 149 : m_size(size)
150 , m_values(m_size) 150 , m_values(m_size)
151 { 151 {
152 } 152 }
153 153
154 InterpolableList(const InterpolableList& other) 154 InterpolableList(const InterpolableList& other)
155 : m_size(other.m_size) 155 : m_size(other.m_size)
156 , m_values(m_size) 156 , m_values(m_size)
157 { 157 {
158 for (size_t i = 0; i < m_size; i++) 158 for (size_t i = 0; i < m_size; i++)
159 set(i, other.m_values[i]->clone()); 159 set(i, other.m_values[i]->clone());
160 } 160 }
161 161
162 size_t m_size; 162 size_t m_size;
163 Vector<OwnPtr<InterpolableValue>> m_values; 163 Vector<std::unique_ptr<InterpolableValue>> m_values;
164 }; 164 };
165 165
166 // FIXME: Remove this when we can. 166 // FIXME: Remove this when we can.
167 class InterpolableAnimatableValue : public InterpolableValue { 167 class InterpolableAnimatableValue : public InterpolableValue {
168 public: 168 public:
169 static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtr<AnimatableV alue> value) 169 static std::unique_ptr<InterpolableAnimatableValue> create(PassRefPtr<Animat ableValue> value)
170 { 170 {
171 return adoptPtr(new InterpolableAnimatableValue(value)); 171 return wrapUnique(new InterpolableAnimatableValue(value));
172 } 172 }
173 173
174 bool isAnimatableValue() const final { return true; } 174 bool isAnimatableValue() const final { return true; }
175 AnimatableValue* value() const { return m_value.get(); } 175 AnimatableValue* value() const { return m_value.get(); }
176 bool equals(const InterpolableValue&) const final { ASSERT_NOT_REACHED(); re turn false; } 176 bool equals(const InterpolableValue&) const final { ASSERT_NOT_REACHED(); re turn false; }
177 PassOwnPtr<InterpolableValue> clone() const final { return create(m_value); } 177 std::unique_ptr<InterpolableValue> clone() const final { return create(m_val ue); }
178 PassOwnPtr<InterpolableValue> cloneAndZero() const final { ASSERT_NOT_REACHE D(); return nullptr; } 178 std::unique_ptr<InterpolableValue> cloneAndZero() const final { ASSERT_NOT_R EACHED(); return nullptr; }
179 void scale(double scale) final { ASSERT_NOT_REACHED(); } 179 void scale(double scale) final { ASSERT_NOT_REACHED(); }
180 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER T_NOT_REACHED(); } 180 void scaleAndAdd(double scale, const InterpolableValue& other) final { ASSER T_NOT_REACHED(); }
181 181
182 private: 182 private:
183 void interpolate(const InterpolableValue &to, const double progress, Interpo lableValue& result) const final; 183 void interpolate(const InterpolableValue &to, const double progress, Interpo lableValue& result) const final;
184 RefPtr<AnimatableValue> m_value; 184 RefPtr<AnimatableValue> m_value;
185 185
186 InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value) 186 InterpolableAnimatableValue(PassRefPtr<AnimatableValue> value)
187 : m_value(value) 187 : m_value(value)
188 { 188 {
189 } 189 }
190 }; 190 };
191 191
192 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber()); 192 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber());
193 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool()); 193 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool());
194 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList()); 194 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList());
195 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value-> isAnimatableValue(), value.isAnimatableValue()); 195 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value-> isAnimatableValue(), value.isAnimatableValue());
196 196
197 } // namespace blink 197 } // namespace blink
198 198
199 #endif 199 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698