Chromium Code Reviews| Index: Source/core/animation/InterpolationPrimitive.h |
| diff --git a/Source/core/animation/InterpolationPrimitive.h b/Source/core/animation/InterpolationPrimitive.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7e80327adc01e55b63b055b3b50e496a05198939 |
| --- /dev/null |
| +++ b/Source/core/animation/InterpolationPrimitive.h |
| @@ -0,0 +1,129 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef InterpolationPrimitive_h |
| +#define InterpolationPrimitive_h |
| + |
| +#include "core/animation/AnimationValue.h" |
| +#include "platform/heap/Handle.h" |
| +#include "wtf/Vector.h" |
| +#include <cmath> |
| + |
| +namespace blink { |
| + |
| +class StyleResolverState; |
| + |
| +// Represents a conversion from a pair of keyframes to something compatible with interpolation. |
| +// This is agnostic to whether the keyframes are compatible with each other or not. |
| +class InterpolationPrimitive : public NoBaseWillBeGarbageCollectedFinalized<InterpolationPrimitive> { |
|
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.
|
| +public: |
| + virtual ~InterpolationPrimitive() { } |
| + |
| + virtual void interpolate(double fraction, AnimationValue& result) const = 0; |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() { } |
| +}; |
| + |
| +// Represents a pair of keyframes that are compatible for "smooth" interpolation eg. "0px" and "100px". |
| +class PairwiseInterpolationPrimitive : public InterpolationPrimitive { |
| +public: |
| + virtual ~PairwiseInterpolationPrimitive() { } |
| + |
| + static PassOwnPtrWillBeRawPtr<PairwiseInterpolationPrimitive> create(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) |
| + { |
| + return adoptPtrWillBeNoop(new PairwiseInterpolationPrimitive(start, end, nonInterpolableValue)); |
| + } |
| + |
| + void initialiseAnimationValue(AnimationValue& value) |
| + { |
| + value.interpolableValue = m_start->clone(); |
| + value.nonInterpolableValue = m_nonInterpolableValue; |
| + } |
| + |
| +private: |
| + virtual void interpolate(double fraction, AnimationValue& result) const override final |
| + { |
| + ASSERT(result.nonInterpolableValue == m_nonInterpolableValue); |
| + m_start->interpolate(*m_end, fraction, *result.interpolableValue); |
| + } |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() |
| + { |
| + InterpolationPrimitive::trace(visitor); |
| + visitor->trace(m_start); |
| + visitor->trace(m_end); |
| + visitor->trace(m_nonInterpolableValue); |
| + } |
| + |
| + PairwiseInterpolationPrimitive(PassOwnPtrWillBeRawPtr<InterpolableValue> start, PassOwnPtrWillBeRawPtr<InterpolableValue> end, PassRefPtrWillBeRawPtr<NonInterpolableValue> nonInterpolableValue) |
| + : m_start(start) |
| + , m_end(end) |
| + , m_nonInterpolableValue(nonInterpolableValue) |
| + { } |
| + OwnPtrWillBeRawPtr<InterpolableValue> m_start; |
| + OwnPtrWillBeRawPtr<InterpolableValue> m_end; |
| + RefPtrWillBeRawPtr<NonInterpolableValue> m_nonInterpolableValue; |
| +}; |
| + |
| +// Represents a pair of incompatible keyframes that fall back to 50% flip behaviour eg. "auto" and "0px". |
| +class FlipInterpolationPrimitive : public InterpolationPrimitive { |
| +public: |
| + struct Side : public NoBaseWillBeGarbageCollectedFinalized<Side> { |
| + const AnimationType* type; |
| + OwnPtrWillBeMember<InterpolableValue> interpolableValue; |
| + RefPtrWillBeMember<NonInterpolableValue> nonInterpolableValue; |
| + |
| + static PassOwnPtrWillBeRawPtr<Side> create() { return adoptPtrWillBeNoop(new Side()); } |
| + |
| + DEFINE_INLINE_TRACE() |
| + { |
| + visitor->trace(interpolableValue); |
| + visitor->trace(nonInterpolableValue); |
| + } |
| + |
| + private: |
| + Side() |
| + : type(nullptr) |
| + { } |
| + }; |
| + |
| + virtual ~FlipInterpolationPrimitive() { } |
| + |
| + static PassOwnPtrWillBeRawPtr<FlipInterpolationPrimitive> create(PassOwnPtrWillBeRawPtr<Side> start, PassOwnPtrWillBeRawPtr<Side> end) |
| + { |
| + ASSERT(start->type); |
| + ASSERT(end->type); |
| + return adoptPtrWillBeNoop(new FlipInterpolationPrimitive(start, end)); |
| + } |
| + |
| +private: |
| + virtual void interpolate(double fraction, AnimationValue& result) const override final |
| + { |
| + if (!std::isnan(m_lastFraction) && (fraction < 0.5) == (m_lastFraction < 0.5)) |
| + return; |
| + result.copy((fraction < 0.5) ? m_start : m_end); |
| + m_lastFraction = fraction; |
| + } |
| + |
| + DEFINE_INLINE_VIRTUAL_TRACE() |
| + { |
| + InterpolationPrimitive::trace(visitor); |
| + visitor->trace(m_start); |
| + visitor->trace(m_end); |
| + } |
| + |
| + FlipInterpolationPrimitive(PassOwnPtrWillBeRawPtr<Side> start, PassOwnPtrWillBeRawPtr<Side> end) |
| + : m_start(start->type, start->interpolableValue.release(), start->nonInterpolableValue.release()) |
| + , m_end(end->type, end->interpolableValue.release(), end->nonInterpolableValue.release()) |
| + , m_lastFraction(std::numeric_limits<double>::quiet_NaN()) |
| + { } |
| + |
| + AnimationValue m_start; |
| + AnimationValue m_end; |
| + mutable double m_lastFraction; |
| +}; |
| + |
| +} // namespace blink |
| + |
| +#endif // InterpolationPrimitive_h |