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 PrimitiveInterpolation_h | |
| 6 #define PrimitiveInterpolation_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 PrimitiveInterpolation : public NoBaseWillBeGarbageCollectedFinalized<Prim itiveInterpolation> { | |
| 20 public: | |
| 21 virtual ~PrimitiveInterpolation() { } | |
| 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 PairwisePrimitiveInterpolation : public PrimitiveInterpolation { | |
| 30 public: | |
| 31 virtual ~PairwisePrimitiveInterpolation() { } | |
| 32 | |
| 33 static PassOwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> create(PassOwn PtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableVal ue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) | |
| 34 { | |
| 35 return adoptPtrWillBeNoop(new PairwisePrimitiveInterpolation(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 PrimitiveInterpolation::trace(visitor); | |
| 54 visitor->trace(m_start); | |
| 55 visitor->trace(m_end); | |
| 56 visitor->trace(m_nonInterpolableValue); | |
| 57 } | |
| 58 | |
| 59 PairwisePrimitiveInterpolation(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 FlipPrimitiveInterpolation : public PrimitiveInterpolation { | |
| 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(const AnimationType& type) { return adoptPtrWillBeNoop(new Side(type)); } | |
| 78 | |
| 79 DEFINE_INLINE_TRACE() | |
| 80 { | |
| 81 visitor->trace(interpolableValue); | |
| 82 visitor->trace(nonInterpolableValue); | |
| 83 } | |
| 84 | |
| 85 private: | |
| 86 Side(const AnimationType& type) | |
| 87 : type(type) | |
| 88 { } | |
| 89 }; | |
| 90 | |
| 91 virtual ~FlipPrimitiveInterpolation() { } | |
| 92 | |
| 93 static PassOwnPtrWillBeRawPtr<FlipPrimitiveInterpolation> create(PassOwnPtrW illBeRawPtr<Side> start, PassOwnPtrWillBeRawPtr<Side> end) | |
| 94 { | |
| 95 return adoptPtrWillBeNoop(new FlipPrimitiveInterpolation(start, end)); | |
| 96 } | |
| 97 | |
| 98 private: | |
| 99 virtual void interpolate(double fraction, AnimationValue& result) const over ride final | |
| 100 { | |
| 101 if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction < 0.5)) | |
|
dstockwell
2015/06/23 06:49:46
comment about the post-oilpan cleanup
alancutter (OOO until 2018)
2015/06/23 08:11:04
Done.
| |
| 102 return; | |
| 103 result.copy((fraction < 0.5) ? m_start : m_end); | |
| 104 m_lastFraction = fraction; | |
| 105 } | |
| 106 | |
| 107 DEFINE_INLINE_VIRTUAL_TRACE() | |
| 108 { | |
| 109 PrimitiveInterpolation::trace(visitor); | |
| 110 visitor->trace(m_start); | |
| 111 visitor->trace(m_end); | |
| 112 } | |
| 113 | |
| 114 FlipPrimitiveInterpolation(PassOwnPtrWillBeRawPtr<Side> start, PassOwnPtrWil lBeRawPtr<Side> end) | |
| 115 : m_start(&start->type, start->interpolableValue.release(), start->nonIn terpolableValue.release()) | |
| 116 , m_end(&end->type, end->interpolableValue.release(), end->nonInterpolab leValue.release()) | |
| 117 , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) | |
| 118 { } | |
| 119 | |
| 120 AnimationValue m_start; | |
| 121 AnimationValue m_end; | |
| 122 mutable double m_lastFraction; | |
| 123 }; | |
| 124 | |
| 125 } // namespace blink | |
| 126 | |
| 127 #endif // PrimitiveInterpolation_h | |
| OLD | NEW |