Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 InterpolationPrimitive_h | |
| 6 #define InterpolationPrimitive_h | |
| 7 | |
| 8 #include "core/animation/AnimationValue.h" | |
| 9 #include "platform/heap/Handle.h" | |
| 10 #include "wtf/Vector.h" | |
| 11 #include <cmath> | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 class StyleResolverState; | |
| 16 | |
| 17 // Represents a conversion from a pair of keyframes to something compatible with interpolation. | |
| 18 // This is agnostic to whether the keyframes are compatible with each other or n ot. | |
| 19 class InterpolationPrimitive : public NoBaseWillBeGarbageCollectedFinalized<Inte rpolationPrimitive> { | |
|
shans
2015/06/22 11:43:21
This isn't a primitive used in interpolation, this
alancutter (OOO until 2018)
2015/06/23 05:05:33
Done.
| |
| 20 public: | |
| 21 virtual ~InterpolationPrimitive() { } | |
| 22 | |
| 23 virtual void interpolate(double fraction, AnimationValue& result) const = 0; | |
| 24 | |
| 25 DEFINE_INLINE_VIRTUAL_TRACE() { } | |
| 26 }; | |
| 27 | |
| 28 // Represents a pair of keyframes that are compatible for "smooth" interpolation eg. "0px" and "100px". | |
| 29 class PairwiseInterpolationPrimitive : public InterpolationPrimitive { | |
| 30 public: | |
| 31 virtual ~PairwiseInterpolationPrimitive() { } | |
| 32 | |
| 33 static PassOwnPtrWillBeRawPtr<PairwiseInterpolationPrimitive> create(PassOwn PtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableVal ue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) | |
| 34 { | |
| 35 return adoptPtrWillBeNoop(new PairwiseInterpolationPrimitive(start, end, nonInterpolableValue)); | |
| 36 } | |
| 37 | |
| 38 void initialiseAnimationValue(AnimationValue& value) | |
| 39 { | |
| 40 value.interpolableValue = m_start->clone(); | |
| 41 value.nonInterpolableValue = m_nonInterpolableValue; | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 virtual void interpolate(double fraction, AnimationValue& result) const over ride final | |
| 46 { | |
| 47 ASSERT(result.nonInterpolableValue == m_nonInterpolableValue); | |
| 48 m_start->interpolate(*m_end, fraction, *result.interpolableValue); | |
| 49 } | |
| 50 | |
| 51 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 52 { | |
| 53 InterpolationPrimitive::trace(visitor); | |
| 54 visitor->trace(m_start); | |
| 55 visitor->trace(m_end); | |
| 56 visitor->trace(m_nonInterpolableValue); | |
| 57 } | |
| 58 | |
| 59 PairwiseInterpolationPrimitive(PassOwnPtrWillBeRawPtr<InterpolableValue> sta rt, PassOwnPtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInt erpolableValue> nonInterpolableValue) | |
| 60 : m_start(start) | |
| 61 , m_end(end) | |
| 62 , m_nonInterpolableValue(nonInterpolableValue) | |
| 63 { } | |
| 64 OwnPtrWillBeRawPtr<InterpolableValue> m_start; | |
| 65 OwnPtrWillBeRawPtr<InterpolableValue> m_end; | |
| 66 RefPtrWillBeRawPtr<NonInterpolableValue> m_nonInterpolableValue; | |
| 67 }; | |
| 68 | |
| 69 // Represents a pair of incompatible keyframes that fall back to 50% flip behavi our eg. "auto" and "0px". | |
| 70 class FlipInterpolationPrimitive : public InterpolationPrimitive { | |
| 71 public: | |
| 72 struct Side : public NoBaseWillBeGarbageCollectedFinalized<Side> { | |
| 73 const AnimationType* type; | |
| 74 OwnPtrWillBeMember<InterpolableValue> interpolableValue; | |
| 75 RefPtrWillBeMember<NonInterpolableValue> nonInterpolableValue; | |
| 76 | |
| 77 static PassOwnPtrWillBeRawPtr<Side> create() { return adoptPtrWillBeNoop (new Side()); } | |
| 78 | |
| 79 DEFINE_INLINE_TRACE() | |
| 80 { | |
| 81 visitor->trace(interpolableValue); | |
| 82 visitor->trace(nonInterpolableValue); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 Side() | |
| 87 : type(nullptr) | |
| 88 { } | |
| 89 }; | |
| 90 | |
| 91 virtual ~FlipInterpolationPrimitive() { } | |
| 92 | |
| 93 static PassOwnPtrWillBeRawPtr<FlipInterpolationPrimitive> create(PassOwnPtrW illBeRawPtr<Side> start, PassOwnPtrWillBeRawPtr<Side> end) | |
| 94 { | |
| 95 ASSERT(start->type); | |
| 96 ASSERT(end->type); | |
| 97 return adoptPtrWillBeNoop(new FlipInterpolationPrimitive(start, end)); | |
| 98 } | |
| 99 | |
| 100 private: | |
| 101 virtual void interpolate(double fraction, AnimationValue& result) const over ride final | |
| 102 { | |
| 103 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction < 0.5)) | |
| 104 return; | |
| 105 result.copy((fraction < 0.5) ? m_start : m_end); | |
| 106 m_lastFraction = fraction; | |
| 107 } | |
| 108 | |
| 109 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 110 { | |
| 111 InterpolationPrimitive::trace(visitor); | |
| 112 visitor->trace(m_start); | |
| 113 visitor->trace(m_end); | |
| 114 } | |
| 115 | |
| 116 FlipInterpolationPrimitive(PassOwnPtrWillBeRawPtr<Side> start, PassOwnPtrWil lBeRawPtr<Side> end) | |
| 117 : m_start(start->type, start->interpolableValue.release(), start->nonInt erpolableValue.release()) | |
| 118 , m_end(end->type, end->interpolableValue.release(), end->nonInterpolabl eValue.release()) | |
| 119 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | |
| 120 { } | |
| 121 | |
| 122 AnimationValue m_start; | |
| 123 AnimationValue m_end; | |
| 124 mutable double m_lastFraction; | |
| 125 }; | |
| 126 | |
| 127 } // namespace blink | |
| 128 | |
| 129 #endif // InterpolationPrimitive_h | |
| OLD | NEW |