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

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

Issue 182383011: Web Animations: Add Interpolation class. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@interpolableValue
Patch Set: Created 6 years, 9 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
« no previous file with comments | « no previous file | Source/core/animation/InterpolableValueTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "wtf/OwnPtr.h" 8 #include "wtf/OwnPtr.h"
9 #include "wtf/PassOwnPtr.h" 9 #include "wtf/PassOwnPtr.h"
10 10
11 namespace WebCore { 11 namespace WebCore {
12 12
13 class InterpolableValue { 13 class InterpolableValue {
14 public: 14 public:
15 virtual bool isNumber() const { return false; } 15 virtual bool isNumber() const { return false; }
16 virtual bool isBool() const { return false; } 16 virtual bool isBool() const { return false; }
17 virtual bool isList() const { return false; } 17 virtual bool isList() const { return false; }
18 18
19 virtual ~InterpolableValue() { } 19 virtual ~InterpolableValue() { }
20 virtual PassOwnPtr<InterpolableValue> clone() const = 0; 20 virtual PassOwnPtr<InterpolableValue> clone() const = 0;
21 21
22 private: 22 private:
23 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t o, const double progress) const = 0; 23 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t o, const double progress) const = 0;
24 24
25 // TODO: Replace this with Interpolation when committing Interpolation 25 friend class Interpolation;
26 // patch. Refactor InterpolableValueTest to test via Interpolation
27 // interface.
28 friend class AnimationInterpolableValueTest;
29 26
30 // Keep interpolate private, but allow calls within the hierarchy without 27 // Keep interpolate private, but allow calls within the hierarchy without
31 // knowledge of type. 28 // knowledge of type.
32 friend class InterpolableNumber; 29 friend class InterpolableNumber;
33 friend class InterpolableBool; 30 friend class InterpolableBool;
34 friend class InterpolableList; 31 friend class InterpolableList;
35 }; 32 };
36 33
37 class InterpolableNumber : public InterpolableValue { 34 class InterpolableNumber : public InterpolableValue {
38 public: 35 public:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 void set(size_t position, PassOwnPtr<InterpolableValue> value) 89 void set(size_t position, PassOwnPtr<InterpolableValue> value)
93 { 90 {
94 ASSERT(position < m_size); 91 ASSERT(position < m_size);
95 m_values.get()[position] = value; 92 m_values.get()[position] = value;
96 } 93 }
97 const InterpolableValue* get(size_t position) const 94 const InterpolableValue* get(size_t position) const
98 { 95 {
99 ASSERT(position < m_size); 96 ASSERT(position < m_size);
100 return m_values.get()[position].get(); 97 return m_values.get()[position].get();
101 } 98 }
99 size_t length() const { return m_size; }
102 virtual PassOwnPtr<InterpolableValue> clone() const OVERRIDE FINAL { return create(*this); } 100 virtual PassOwnPtr<InterpolableValue> clone() const OVERRIDE FINAL { return create(*this); }
103 101
104 private: 102 private:
105 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o ther, const double progress) const OVERRIDE FINAL; 103 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o ther, const double progress) const OVERRIDE FINAL;
106 InterpolableList(size_t size) 104 InterpolableList(size_t size)
107 : m_size(size) 105 : m_size(size)
108 { 106 {
109 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[size]); 107 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[size]);
110 } 108 }
111 109
112 InterpolableList(const InterpolableList& other) 110 InterpolableList(const InterpolableList& other)
113 : m_size(other.m_size) 111 : m_size(other.m_size)
114 { 112 {
115 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[m_size]); 113 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[m_size]);
116 for (size_t i = 0; i < m_size; i++) 114 for (size_t i = 0; i < m_size; i++)
117 set(i, other.m_values.get()[i]->clone()); 115 set(i, other.m_values.get()[i]->clone());
118 } 116 }
119 117
120 size_t m_size; 118 size_t m_size;
121 OwnPtr<OwnPtr<InterpolableValue>[]> m_values; 119 OwnPtr<OwnPtr<InterpolableValue>[]> m_values;
122 }; 120 };
123 121
124 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber()); 122 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber());
125 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool()); 123 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool());
126 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList()); 124 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList());
127 125
128 } 126 }
129 127
130 #endif 128 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/animation/InterpolableValueTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698