Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/animation/AnimatableValue.h" | 8 #include "core/animation/AnimatableValue.h" |
| 9 #include "wtf/OwnPtr.h" | 9 #include "wtf/OwnPtr.h" |
| 10 #include "wtf/PassOwnPtr.h" | 10 #include "wtf/PassOwnPtr.h" |
| 11 #include "wtf/Vector.h" | |
| 11 | 12 |
| 12 namespace WebCore { | 13 namespace WebCore { |
| 13 | 14 |
| 14 class InterpolableValue { | 15 class InterpolableValue : public NoBaseWillBeGarbageCollected<InterpolableValue> { |
| 16 DECLARE_EMPTY_VIRTUAL_DESTRUCTOR_WILL_BE_REMOVED(InterpolableValue); | |
| 15 public: | 17 public: |
| 16 virtual bool isNumber() const { return false; } | 18 virtual bool isNumber() const { return false; } |
| 17 virtual bool isBool() const { return false; } | 19 virtual bool isBool() const { return false; } |
| 18 virtual bool isList() const { return false; } | 20 virtual bool isList() const { return false; } |
| 19 virtual bool isAnimatableValue() const { return false; } | 21 virtual bool isAnimatableValue() const { return false; } |
| 20 | 22 |
| 21 virtual ~InterpolableValue() { } | 23 virtual ~InterpolableValue() { } |
|
Mads Ager (chromium)
2014/03/26 13:28:31
This should be removed and should lead to a compil
haraken
2014/03/26 13:42:30
Nice catch. Done.
| |
| 22 virtual PassOwnPtr<InterpolableValue> clone() const = 0; | 24 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const = 0; |
| 25 | |
| 26 virtual void trace(Visitor*) = 0; | |
| 23 | 27 |
| 24 private: | 28 private: |
| 25 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t o, const double progress) const = 0; | 29 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol ableValue &to, const double progress) const = 0; |
| 26 | 30 |
| 27 friend class Interpolation; | 31 friend class Interpolation; |
| 28 | 32 |
| 29 // Keep interpolate private, but allow calls within the hierarchy without | 33 // Keep interpolate private, but allow calls within the hierarchy without |
| 30 // knowledge of type. | 34 // knowledge of type. |
| 31 friend class InterpolableNumber; | 35 friend class InterpolableNumber; |
| 32 friend class InterpolableBool; | 36 friend class InterpolableBool; |
| 33 friend class InterpolableList; | 37 friend class InterpolableList; |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 class InterpolableNumber : public InterpolableValue { | 40 class InterpolableNumber : public InterpolableValue { |
| 37 public: | 41 public: |
| 38 static PassOwnPtr<InterpolableNumber> create(double value) | 42 static PassOwnPtrWillBeRawPtr<InterpolableNumber> create(double value) |
| 39 { | 43 { |
| 40 return adoptPtr(new InterpolableNumber(value)); | 44 return adoptPtrWillBeNoop(new InterpolableNumber(value)); |
| 41 } | 45 } |
| 42 | 46 |
| 43 virtual bool isNumber() const OVERRIDE FINAL { return true; } | 47 virtual bool isNumber() const OVERRIDE FINAL { return true; } |
| 44 double value() const { return m_value; } | 48 double value() const { return m_value; } |
| 45 virtual PassOwnPtr<InterpolableValue> clone() const OVERRIDE FINAL { return create(m_value); } | 49 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const OVERRIDE FIN AL { return create(m_value); } |
| 50 | |
| 51 virtual void trace(Visitor*) OVERRIDE { } | |
| 46 | 52 |
| 47 private: | 53 private: |
| 48 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t o, const double progress) const OVERRIDE FINAL; | 54 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol ableValue &to, const double progress) const OVERRIDE FINAL; |
| 49 double m_value; | 55 double m_value; |
| 50 | 56 |
| 51 InterpolableNumber(double value) | 57 explicit InterpolableNumber(double value) |
| 52 : m_value(value) | 58 : m_value(value) |
| 53 { } | 59 { |
| 60 } | |
| 54 | 61 |
| 55 }; | 62 }; |
| 56 | 63 |
| 57 class InterpolableBool : public InterpolableValue { | 64 class InterpolableBool : public InterpolableValue { |
| 58 public: | 65 public: |
| 59 static PassOwnPtr<InterpolableBool> create(bool value) | 66 static PassOwnPtrWillBeRawPtr<InterpolableBool> create(bool value) |
| 60 { | 67 { |
| 61 return adoptPtr(new InterpolableBool(value)); | 68 return adoptPtrWillBeNoop(new InterpolableBool(value)); |
| 62 } | 69 } |
| 63 | 70 |
| 64 virtual bool isBool() const OVERRIDE FINAL { return true; } | 71 virtual bool isBool() const OVERRIDE FINAL { return true; } |
| 65 bool value() const { return m_value; } | 72 bool value() const { return m_value; } |
| 66 virtual PassOwnPtr<InterpolableValue> clone() const OVERRIDE FINAL { return create(m_value); } | 73 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const OVERRIDE FIN AL { return create(m_value); } |
| 74 | |
| 75 virtual void trace(Visitor*) OVERRIDE { } | |
| 67 | 76 |
| 68 private: | 77 private: |
| 69 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &t o, const double progress) const OVERRIDE FINAL; | 78 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol ableValue &to, const double progress) const OVERRIDE FINAL; |
| 70 bool m_value; | 79 bool m_value; |
| 71 | 80 |
| 72 InterpolableBool(bool value) | 81 explicit InterpolableBool(bool value) |
| 73 : m_value(value) | 82 : m_value(value) |
| 74 { } | 83 { |
| 84 } | |
| 75 | 85 |
| 76 }; | 86 }; |
| 77 | 87 |
| 78 class InterpolableList : public InterpolableValue { | 88 class InterpolableList : public InterpolableValue { |
| 79 public: | 89 public: |
| 80 static PassOwnPtr<InterpolableList> create(const InterpolableList &other) | 90 static PassOwnPtrWillBeRawPtr<InterpolableList> create(const InterpolableLis t &other) |
| 81 { | 91 { |
| 82 return adoptPtr(new InterpolableList(other)); | 92 return adoptPtrWillBeNoop(new InterpolableList(other)); |
| 83 } | 93 } |
| 84 | 94 |
| 85 static PassOwnPtr<InterpolableList> create(size_t size) | 95 static PassOwnPtrWillBeRawPtr<InterpolableList> create(size_t size) |
| 86 { | 96 { |
| 87 return adoptPtr(new InterpolableList(size)); | 97 return adoptPtrWillBeNoop(new InterpolableList(size)); |
| 88 } | 98 } |
| 89 | 99 |
| 90 virtual bool isList() const OVERRIDE FINAL { return true; } | 100 virtual bool isList() const OVERRIDE FINAL { return true; } |
| 91 void set(size_t position, PassOwnPtr<InterpolableValue> value) | 101 void set(size_t position, PassOwnPtrWillBeRawPtr<InterpolableValue> value) |
| 92 { | 102 { |
| 93 ASSERT(position < m_size); | 103 ASSERT(position < m_size); |
| 94 m_values.get()[position] = value; | 104 m_values[position] = value; |
| 95 } | 105 } |
| 96 const InterpolableValue* get(size_t position) const | 106 const InterpolableValue* get(size_t position) const |
| 97 { | 107 { |
| 98 ASSERT(position < m_size); | 108 ASSERT(position < m_size); |
| 99 return m_values.get()[position].get(); | 109 return m_values[position].get(); |
| 100 } | 110 } |
| 101 size_t length() const { return m_size; } | 111 size_t length() const { return m_size; } |
| 102 virtual PassOwnPtr<InterpolableValue> clone() const OVERRIDE FINAL { return create(*this); } | 112 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const OVERRIDE FIN AL { return create(*this); } |
| 113 | |
| 114 virtual void trace(Visitor*) OVERRIDE; | |
| 103 | 115 |
| 104 private: | 116 private: |
| 105 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o ther, const double progress) const OVERRIDE FINAL; | 117 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol ableValue &other, const double progress) const OVERRIDE FINAL; |
| 106 InterpolableList(size_t size) | 118 explicit InterpolableList(size_t size) |
| 107 : m_size(size) | 119 : m_size(size) |
| 108 { | 120 { |
| 109 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[size]); | 121 m_values.reserveCapacity(m_size); |
| 122 m_values.resize(m_size); | |
| 110 } | 123 } |
| 111 | 124 |
| 112 InterpolableList(const InterpolableList& other) | 125 InterpolableList(const InterpolableList& other) |
| 113 : m_size(other.m_size) | 126 : m_size(other.m_size) |
| 114 { | 127 { |
| 115 m_values = adoptArrayPtr(new OwnPtr<InterpolableValue>[m_size]); | 128 m_values.reserveCapacity(m_size); |
| 129 m_values.resize(m_size); | |
| 116 for (size_t i = 0; i < m_size; i++) | 130 for (size_t i = 0; i < m_size; i++) |
| 117 set(i, other.m_values.get()[i]->clone()); | 131 set(i, other.m_values[i]->clone()); |
| 118 } | 132 } |
| 119 | 133 |
| 120 size_t m_size; | 134 size_t m_size; |
| 121 OwnPtr<OwnPtr<InterpolableValue>[]> m_values; | 135 WillBeHeapVector<OwnPtrWillBeMember<InterpolableValue> > m_values; |
|
haraken
2014/03/26 13:11:06
dstockwell@, shanes@: Would you just check that th
| |
| 122 }; | 136 }; |
| 123 | 137 |
| 124 // FIXME: Remove this when we can. | 138 // FIXME: Remove this when we can. |
| 125 class InterpolableAnimatableValue : public InterpolableValue { | 139 class InterpolableAnimatableValue : public InterpolableValue { |
| 126 public: | 140 public: |
| 127 static PassOwnPtr<InterpolableAnimatableValue> create(PassRefPtrWillBeRawPtr <AnimatableValue> value) | 141 static PassOwnPtrWillBeRawPtr<InterpolableAnimatableValue> create(PassRefPtr WillBeRawPtr<AnimatableValue> value) |
| 128 { | 142 { |
| 129 return adoptPtr(new InterpolableAnimatableValue(value)); | 143 return adoptPtrWillBeNoop(new InterpolableAnimatableValue(value)); |
| 130 } | 144 } |
| 131 | 145 |
| 132 virtual bool isAnimatableValue() const OVERRIDE FINAL { return true; } | 146 virtual bool isAnimatableValue() const OVERRIDE FINAL { return true; } |
| 133 AnimatableValue* value() const { return m_value.get(); } | 147 AnimatableValue* value() const { return m_value.get(); } |
| 134 virtual PassOwnPtr<InterpolableValue> clone() const OVERRIDE FINAL { return create(m_value); } | 148 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> clone() const OVERRIDE FIN AL { return create(m_value); } |
| 149 | |
| 150 virtual void trace(Visitor*) OVERRIDE; | |
| 135 | 151 |
| 136 private: | 152 private: |
| 137 virtual PassOwnPtr<InterpolableValue> interpolate(const InterpolableValue &o ther, const double progress) const OVERRIDE FINAL; | 153 virtual PassOwnPtrWillBeRawPtr<InterpolableValue> interpolate(const Interpol ableValue &other, const double progress) const OVERRIDE FINAL; |
| 138 RefPtrWillBePersistent<AnimatableValue> m_value; | 154 RefPtrWillBeMember<AnimatableValue> m_value; |
| 139 | 155 |
| 140 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) | 156 InterpolableAnimatableValue(PassRefPtrWillBeRawPtr<AnimatableValue> value) |
| 141 : m_value(value) | 157 : m_value(value) |
| 142 { } | 158 { |
| 159 } | |
| 143 }; | 160 }; |
| 144 | 161 |
| 145 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber()); | 162 DEFINE_TYPE_CASTS(InterpolableNumber, InterpolableValue, value, value->isNumber( ), value.isNumber()); |
| 146 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool()); | 163 DEFINE_TYPE_CASTS(InterpolableBool, InterpolableValue, value, value->isBool(), v alue.isBool()); |
| 147 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList()); | 164 DEFINE_TYPE_CASTS(InterpolableList, InterpolableValue, value, value->isList(), v alue.isList()); |
| 148 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value-> isAnimatableValue(), value.isAnimatableValue()); | 165 DEFINE_TYPE_CASTS(InterpolableAnimatableValue, InterpolableValue, value, value-> isAnimatableValue(), value.isAnimatableValue()); |
| 149 | 166 |
| 150 } | 167 } |
| 151 | 168 |
| 152 #endif | 169 #endif |
| OLD | NEW |