| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/animation/InvalidatableStyleInterpolation.h" | 6 #include "core/animation/InvalidatableStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/animation/StringKeyframe.h" | 8 #include "core/animation/StringKeyframe.h" |
| 9 #include "core/css/resolver/StyleResolverState.h" | 9 #include "core/css/resolver/StyleResolverState.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 { | 21 { |
| 22 maybeCachePairwiseConversion(nullptr, nullptr); | 22 maybeCachePairwiseConversion(nullptr, nullptr); |
| 23 interpolate(0, 0); | 23 interpolate(0, 0); |
| 24 } | 24 } |
| 25 | 25 |
| 26 bool InvalidatableStyleInterpolation::maybeCachePairwiseConversion(const StyleRe
solverState* state, const InterpolationValue* underlyingValue) const | 26 bool InvalidatableStyleInterpolation::maybeCachePairwiseConversion(const StyleRe
solverState* state, const InterpolationValue* underlyingValue) const |
| 27 { | 27 { |
| 28 for (const auto& interpolationType : m_interpolationTypes) { | 28 for (const auto& interpolationType : m_interpolationTypes) { |
| 29 if ((m_startKeyframe->isNeutral() || m_endKeyframe->isNeutral()) && (!un
derlyingValue || underlyingValue->type() != *interpolationType)) | 29 if ((m_startKeyframe->isNeutral() || m_endKeyframe->isNeutral()) && (!un
derlyingValue || underlyingValue->type() != *interpolationType)) |
| 30 continue; | 30 continue; |
| 31 OwnPtrWillBeRawPtr<PairwisePrimitiveInterpolation> pairwiseConversion =
interpolationType->maybeConvertPairwise(*m_startKeyframe, *m_endKeyframe, state,
m_conversionCheckers); | 31 OwnPtr<PairwisePrimitiveInterpolation> pairwiseConversion = interpolatio
nType->maybeConvertPairwise(*m_startKeyframe, *m_endKeyframe, state, m_conversio
nCheckers); |
| 32 if (pairwiseConversion) { | 32 if (pairwiseConversion) { |
| 33 m_cachedValue = pairwiseConversion->initialValue(); | 33 m_cachedValue = pairwiseConversion->initialValue(); |
| 34 m_cachedConversion = pairwiseConversion.release(); | 34 m_cachedConversion = pairwiseConversion.release(); |
| 35 return true; | 35 return true; |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void InvalidatableStyleInterpolation::interpolate(int, double fraction) | 41 void InvalidatableStyleInterpolation::interpolate(int, double fraction) |
| 42 { | 42 { |
| 43 m_currentFraction = fraction; | 43 m_currentFraction = fraction; |
| 44 if (m_cachedConversion) | 44 if (m_cachedConversion) |
| 45 m_cachedConversion->interpolateValue(fraction, m_cachedValue); | 45 m_cachedConversion->interpolateValue(fraction, m_cachedValue); |
| 46 // We defer the interpolation to ensureValidInterpolation() if m_cachedConve
rsion is null. | 46 // We defer the interpolation to ensureValidInterpolation() if m_cachedConve
rsion is null. |
| 47 } | 47 } |
| 48 | 48 |
| 49 PassOwnPtrWillBeRawPtr<InterpolationValue> InvalidatableStyleInterpolation::conv
ertSingleKeyframe(const CSSPropertySpecificKeyframe& keyframe, const StyleResolv
erState& state, const InterpolationValue* underlyingValue) const | 49 PassOwnPtr<InterpolationValue> InvalidatableStyleInterpolation::convertSingleKey
frame(const CSSPropertySpecificKeyframe& keyframe, const StyleResolverState& sta
te, const InterpolationValue* underlyingValue) const |
| 50 { | 50 { |
| 51 if (keyframe.isNeutral() && !underlyingValue) | 51 if (keyframe.isNeutral() && !underlyingValue) |
| 52 return nullptr; | 52 return nullptr; |
| 53 for (const auto& interpolationType : m_interpolationTypes) { | 53 for (const auto& interpolationType : m_interpolationTypes) { |
| 54 if (keyframe.isNeutral() && underlyingValue->type() != *interpolationTyp
e) | 54 if (keyframe.isNeutral() && underlyingValue->type() != *interpolationTyp
e) |
| 55 continue; | 55 continue; |
| 56 OwnPtrWillBeRawPtr<InterpolationValue> result = interpolationType->maybe
ConvertSingle(keyframe, &state, m_conversionCheckers); | 56 OwnPtr<InterpolationValue> result = interpolationType->maybeConvertSingl
e(keyframe, &state, m_conversionCheckers); |
| 57 if (result) | 57 if (result) |
| 58 return result.release(); | 58 return result.release(); |
| 59 } | 59 } |
| 60 ASSERT(keyframe.isNeutral()); | 60 ASSERT(keyframe.isNeutral()); |
| 61 return nullptr; | 61 return nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 PassOwnPtrWillBeRawPtr<InterpolationValue> InvalidatableStyleInterpolation::mayb
eConvertUnderlyingValue(const StyleResolverState& state) const | 64 PassOwnPtr<InterpolationValue> InvalidatableStyleInterpolation::maybeConvertUnde
rlyingValue(const StyleResolverState& state) const |
| 65 { | 65 { |
| 66 for (const auto& interpolationType : m_interpolationTypes) { | 66 for (const auto& interpolationType : m_interpolationTypes) { |
| 67 OwnPtrWillBeRawPtr<InterpolationValue> result = interpolationType->maybe
ConvertUnderlyingValue(state); | 67 OwnPtr<InterpolationValue> result = interpolationType->maybeConvertUnder
lyingValue(state); |
| 68 if (result) | 68 if (result) |
| 69 return result.release(); | 69 return result.release(); |
| 70 } | 70 } |
| 71 return nullptr; | 71 return nullptr; |
| 72 } | 72 } |
| 73 | 73 |
| 74 bool InvalidatableStyleInterpolation::dependsOnUnderlyingValue() const | 74 bool InvalidatableStyleInterpolation::dependsOnUnderlyingValue() const |
| 75 { | 75 { |
| 76 return (m_startKeyframe->underlyingFraction() != 0 && m_currentFraction != 1
) || (m_endKeyframe->underlyingFraction() != 0 && m_currentFraction != 0); | 76 return (m_startKeyframe->underlyingFraction() != 0 && m_currentFraction != 1
) || (m_endKeyframe->underlyingFraction() != 0 && m_currentFraction != 0); |
| 77 } | 77 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 if (!state.parentStyle()) | 115 if (!state.parentStyle()) |
| 116 return; | 116 return; |
| 117 if ((m_startKeyframe->value() && m_startKeyframe->value()->isInheritedValue(
)) | 117 if ((m_startKeyframe->value() && m_startKeyframe->value()->isInheritedValue(
)) |
| 118 || (m_endKeyframe->value() && m_endKeyframe->value()->isInheritedValue()
)) { | 118 || (m_endKeyframe->value() && m_endKeyframe->value()->isInheritedValue()
)) { |
| 119 state.parentStyle()->setHasExplicitlyInheritedProperties(); | 119 state.parentStyle()->setHasExplicitlyInheritedProperties(); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void InvalidatableStyleInterpolation::apply(StyleResolverState& state) const | 123 void InvalidatableStyleInterpolation::apply(StyleResolverState& state) const |
| 124 { | 124 { |
| 125 OwnPtrWillBeRawPtr<InterpolationValue> underlyingValue = dependsOnUnderlying
Value() ? maybeConvertUnderlyingValue(state) : nullptr; | 125 OwnPtr<InterpolationValue> underlyingValue = dependsOnUnderlyingValue() ? ma
ybeConvertUnderlyingValue(state) : nullptr; |
| 126 ensureValidInterpolation(state, underlyingValue.get()); | 126 ensureValidInterpolation(state, underlyingValue.get()); |
| 127 if (!m_cachedValue) | 127 if (!m_cachedValue) |
| 128 return; | 128 return; |
| 129 const InterpolableValue* appliedInterpolableValue = &m_cachedValue->interpol
ableValue(); | 129 const InterpolableValue* appliedInterpolableValue = &m_cachedValue->interpol
ableValue(); |
| 130 if (underlyingValue && m_cachedValue->type() == underlyingValue->type()) { | 130 if (underlyingValue && m_cachedValue->type() == underlyingValue->type()) { |
| 131 double underlyingFraction = m_cachedConversion->interpolateUnderlyingFra
ction(m_startKeyframe->underlyingFraction(), m_endKeyframe->underlyingFraction()
, m_currentFraction); | 131 double underlyingFraction = m_cachedConversion->interpolateUnderlyingFra
ction(m_startKeyframe->underlyingFraction(), m_endKeyframe->underlyingFraction()
, m_currentFraction); |
| 132 underlyingValue->interpolableValue().scaleAndAdd(underlyingFraction, m_c
achedValue->interpolableValue()); | 132 underlyingValue->interpolableValue().scaleAndAdd(underlyingFraction, m_c
achedValue->interpolableValue()); |
| 133 appliedInterpolableValue = &underlyingValue->interpolableValue(); | 133 appliedInterpolableValue = &underlyingValue->interpolableValue(); |
| 134 } | 134 } |
| 135 m_cachedValue->type().apply(*appliedInterpolableValue, m_cachedValue->nonInt
erpolableValue(), state); | 135 m_cachedValue->type().apply(*appliedInterpolableValue, m_cachedValue->nonInt
erpolableValue(), state); |
| 136 setFlagIfInheritUsed(state); | 136 setFlagIfInheritUsed(state); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace blink | 139 } // namespace blink |
| OLD | NEW |