| 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 "core/animation/ShadowInterpolationFunctions.h" | 5 #include "core/animation/ShadowInterpolationFunctions.h" |
| 6 | 6 |
| 7 #include "core/animation/CSSColorInterpolationType.h" | 7 #include "core/animation/CSSColorInterpolationType.h" |
| 8 #include "core/animation/CSSLengthInterpolationType.h" | 8 #include "core/animation/CSSLengthInterpolationType.h" |
| 9 #include "core/animation/InterpolationValue.h" | 9 #include "core/animation/InterpolationValue.h" |
| 10 #include "core/animation/NonInterpolableValue.h" | 10 #include "core/animation/NonInterpolableValue.h" |
| 11 #include "core/css/CSSShadowValue.h" | 11 #include "core/css/CSSShadowValue.h" |
| 12 #include "core/css/resolver/StyleResolverState.h" | 12 #include "core/css/resolver/StyleResolverState.h" |
| 13 #include "core/style/ShadowData.h" | 13 #include "core/style/ShadowData.h" |
| 14 #include "platform/geometry/FloatPoint.h" | 14 #include "platform/geometry/FloatPoint.h" |
| 15 #include <memory> | |
| 16 | 15 |
| 17 namespace blink { | 16 namespace blink { |
| 18 | 17 |
| 19 enum ShadowComponentIndex { | 18 enum ShadowComponentIndex { |
| 20 ShadowX, | 19 ShadowX, |
| 21 ShadowY, | 20 ShadowY, |
| 22 ShadowBlur, | 21 ShadowBlur, |
| 23 ShadowSpread, | 22 ShadowSpread, |
| 24 ShadowColor, | 23 ShadowColor, |
| 25 ShadowComponentIndexCount, | 24 ShadowComponentIndexCount, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 56 | 55 |
| 57 PairwiseInterpolationValue ShadowInterpolationFunctions::maybeMergeSingles(Inter
polationValue&& start, InterpolationValue&& end) | 56 PairwiseInterpolationValue ShadowInterpolationFunctions::maybeMergeSingles(Inter
polationValue&& start, InterpolationValue&& end) |
| 58 { | 57 { |
| 59 if (!nonInterpolableValuesAreCompatible(start.nonInterpolableValue.get(), en
d.nonInterpolableValue.get())) | 58 if (!nonInterpolableValuesAreCompatible(start.nonInterpolableValue.get(), en
d.nonInterpolableValue.get())) |
| 60 return nullptr; | 59 return nullptr; |
| 61 return PairwiseInterpolationValue(std::move(start.interpolableValue), std::m
ove(end.interpolableValue), start.nonInterpolableValue.release()); | 60 return PairwiseInterpolationValue(std::move(start.interpolableValue), std::m
ove(end.interpolableValue), start.nonInterpolableValue.release()); |
| 62 } | 61 } |
| 63 | 62 |
| 64 InterpolationValue ShadowInterpolationFunctions::convertShadowData(const ShadowD
ata& shadowData, double zoom) | 63 InterpolationValue ShadowInterpolationFunctions::convertShadowData(const ShadowD
ata& shadowData, double zoom) |
| 65 { | 64 { |
| 66 std::unique_ptr<InterpolableList> interpolableList = InterpolableList::creat
e(ShadowComponentIndexCount); | 65 OwnPtr<InterpolableList> interpolableList = InterpolableList::create(ShadowC
omponentIndexCount); |
| 67 interpolableList->set(ShadowX, CSSLengthInterpolationType::createInterpolabl
ePixels(shadowData.x() / zoom)); | 66 interpolableList->set(ShadowX, CSSLengthInterpolationType::createInterpolabl
ePixels(shadowData.x() / zoom)); |
| 68 interpolableList->set(ShadowY, CSSLengthInterpolationType::createInterpolabl
ePixels(shadowData.y() / zoom)); | 67 interpolableList->set(ShadowY, CSSLengthInterpolationType::createInterpolabl
ePixels(shadowData.y() / zoom)); |
| 69 interpolableList->set(ShadowBlur, CSSLengthInterpolationType::createInterpol
ablePixels(shadowData.blur() / zoom)); | 68 interpolableList->set(ShadowBlur, CSSLengthInterpolationType::createInterpol
ablePixels(shadowData.blur() / zoom)); |
| 70 interpolableList->set(ShadowSpread, CSSLengthInterpolationType::createInterp
olablePixels(shadowData.spread() / zoom)); | 69 interpolableList->set(ShadowSpread, CSSLengthInterpolationType::createInterp
olablePixels(shadowData.spread() / zoom)); |
| 71 interpolableList->set(ShadowColor, CSSColorInterpolationType::createInterpol
ableColor(shadowData.color())); | 70 interpolableList->set(ShadowColor, CSSColorInterpolationType::createInterpol
ableColor(shadowData.color())); |
| 72 return InterpolationValue(std::move(interpolableList), ShadowNonInterpolable
Value::create(shadowData.style())); | 71 return InterpolationValue(std::move(interpolableList), ShadowNonInterpolable
Value::create(shadowData.style())); |
| 73 } | 72 } |
| 74 | 73 |
| 75 InterpolationValue ShadowInterpolationFunctions::maybeConvertCSSValue(const CSSV
alue& value) | 74 InterpolationValue ShadowInterpolationFunctions::maybeConvertCSSValue(const CSSV
alue& value) |
| 76 { | 75 { |
| 77 if (!value.isShadowValue()) | 76 if (!value.isShadowValue()) |
| 78 return nullptr; | 77 return nullptr; |
| 79 const CSSShadowValue& shadow = toCSSShadowValue(value); | 78 const CSSShadowValue& shadow = toCSSShadowValue(value); |
| 80 | 79 |
| 81 ShadowStyle style = Normal; | 80 ShadowStyle style = Normal; |
| 82 if (shadow.style) { | 81 if (shadow.style) { |
| 83 if (shadow.style->getValueID() == CSSValueInset) | 82 if (shadow.style->getValueID() == CSSValueInset) |
| 84 style = Inset; | 83 style = Inset; |
| 85 else | 84 else |
| 86 return nullptr; | 85 return nullptr; |
| 87 } | 86 } |
| 88 | 87 |
| 89 std::unique_ptr<InterpolableList> interpolableList = InterpolableList::creat
e(ShadowComponentIndexCount); | 88 OwnPtr<InterpolableList> interpolableList = InterpolableList::create(ShadowC
omponentIndexCount); |
| 90 static_assert(ShadowX == 0, "Enum ordering check."); | 89 static_assert(ShadowX == 0, "Enum ordering check."); |
| 91 static_assert(ShadowY == 1, "Enum ordering check."); | 90 static_assert(ShadowY == 1, "Enum ordering check."); |
| 92 static_assert(ShadowBlur == 2, "Enum ordering check."); | 91 static_assert(ShadowBlur == 2, "Enum ordering check."); |
| 93 static_assert(ShadowSpread == 3, "Enum ordering check."); | 92 static_assert(ShadowSpread == 3, "Enum ordering check."); |
| 94 const CSSPrimitiveValue* lengths[] = { | 93 const CSSPrimitiveValue* lengths[] = { |
| 95 shadow.x.get(), | 94 shadow.x.get(), |
| 96 shadow.y.get(), | 95 shadow.y.get(), |
| 97 shadow.blur.get(), | 96 shadow.blur.get(), |
| 98 shadow.spread.get(), | 97 shadow.spread.get(), |
| 99 }; | 98 }; |
| 100 for (size_t i = 0; i < WTF_ARRAY_LENGTH(lengths); i++) { | 99 for (size_t i = 0; i < WTF_ARRAY_LENGTH(lengths); i++) { |
| 101 if (lengths[i]) { | 100 if (lengths[i]) { |
| 102 InterpolationValue lengthField = CSSLengthInterpolationType::maybeCo
nvertCSSValue(*lengths[i]); | 101 InterpolationValue lengthField = CSSLengthInterpolationType::maybeCo
nvertCSSValue(*lengths[i]); |
| 103 if (!lengthField) | 102 if (!lengthField) |
| 104 return nullptr; | 103 return nullptr; |
| 105 ASSERT(!lengthField.nonInterpolableValue); | 104 ASSERT(!lengthField.nonInterpolableValue); |
| 106 interpolableList->set(i, std::move(lengthField.interpolableValue)); | 105 interpolableList->set(i, std::move(lengthField.interpolableValue)); |
| 107 } else { | 106 } else { |
| 108 interpolableList->set(i, CSSLengthInterpolationType::createInterpola
blePixels(0)); | 107 interpolableList->set(i, CSSLengthInterpolationType::createInterpola
blePixels(0)); |
| 109 } | 108 } |
| 110 } | 109 } |
| 111 | 110 |
| 112 if (shadow.color) { | 111 if (shadow.color) { |
| 113 std::unique_ptr<InterpolableValue> interpolableColor = CSSColorInterpola
tionType::maybeCreateInterpolableColor(*shadow.color); | 112 OwnPtr<InterpolableValue> interpolableColor = CSSColorInterpolationType:
:maybeCreateInterpolableColor(*shadow.color); |
| 114 if (!interpolableColor) | 113 if (!interpolableColor) |
| 115 return nullptr; | 114 return nullptr; |
| 116 interpolableList->set(ShadowColor, std::move(interpolableColor)); | 115 interpolableList->set(ShadowColor, std::move(interpolableColor)); |
| 117 } else { | 116 } else { |
| 118 interpolableList->set(ShadowColor, CSSColorInterpolationType::createInte
rpolableColor(StyleColor::currentColor())); | 117 interpolableList->set(ShadowColor, CSSColorInterpolationType::createInte
rpolableColor(StyleColor::currentColor())); |
| 119 } | 118 } |
| 120 | 119 |
| 121 return InterpolationValue(std::move(interpolableList), ShadowNonInterpolable
Value::create(style)); | 120 return InterpolationValue(std::move(interpolableList), ShadowNonInterpolable
Value::create(style)); |
| 122 } | 121 } |
| 123 | 122 |
| 124 std::unique_ptr<InterpolableValue> ShadowInterpolationFunctions::createNeutralIn
terpolableValue() | 123 PassOwnPtr<InterpolableValue> ShadowInterpolationFunctions::createNeutralInterpo
lableValue() |
| 125 { | 124 { |
| 126 return convertShadowData(ShadowData(FloatPoint(0, 0), 0, 0, Normal, StyleCol
or(Color::transparent)), 1).interpolableValue; | 125 return convertShadowData(ShadowData(FloatPoint(0, 0), 0, 0, Normal, StyleCol
or(Color::transparent)), 1).interpolableValue; |
| 127 } | 126 } |
| 128 | 127 |
| 129 void ShadowInterpolationFunctions::composite(std::unique_ptr<InterpolableValue>&
underlyingInterpolableValue, RefPtr<NonInterpolableValue>& underlyingNonInterpo
lableValue, double underlyingFraction, const InterpolableValue& interpolableValu
e, const NonInterpolableValue* nonInterpolableValue) | 128 void ShadowInterpolationFunctions::composite(OwnPtr<InterpolableValue>& underlyi
ngInterpolableValue, RefPtr<NonInterpolableValue>& underlyingNonInterpolableValu
e, double underlyingFraction, const InterpolableValue& interpolableValue, const
NonInterpolableValue* nonInterpolableValue) |
| 130 { | 129 { |
| 131 ASSERT(nonInterpolableValuesAreCompatible(underlyingNonInterpolableValue.get
(), nonInterpolableValue)); | 130 ASSERT(nonInterpolableValuesAreCompatible(underlyingNonInterpolableValue.get
(), nonInterpolableValue)); |
| 132 InterpolableList& underlyingInterpolableList = toInterpolableList(*underlyin
gInterpolableValue); | 131 InterpolableList& underlyingInterpolableList = toInterpolableList(*underlyin
gInterpolableValue); |
| 133 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); | 132 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); |
| 134 underlyingInterpolableList.scaleAndAdd(underlyingFraction, interpolableList)
; | 133 underlyingInterpolableList.scaleAndAdd(underlyingFraction, interpolableList)
; |
| 135 } | 134 } |
| 136 | 135 |
| 137 ShadowData ShadowInterpolationFunctions::createShadowData(const InterpolableValu
e& interpolableValue, const NonInterpolableValue* nonInterpolableValue, const St
yleResolverState& state) | 136 ShadowData ShadowInterpolationFunctions::createShadowData(const InterpolableValu
e& interpolableValue, const NonInterpolableValue* nonInterpolableValue, const St
yleResolverState& state) |
| 138 { | 137 { |
| 139 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); | 138 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); |
| 140 const ShadowNonInterpolableValue& shadowNonInterpolableValue = toShadowNonIn
terpolableValue(*nonInterpolableValue); | 139 const ShadowNonInterpolableValue& shadowNonInterpolableValue = toShadowNonIn
terpolableValue(*nonInterpolableValue); |
| 141 const CSSToLengthConversionData& conversionData = state.cssToLengthConversio
nData(); | 140 const CSSToLengthConversionData& conversionData = state.cssToLengthConversio
nData(); |
| 142 Length shadowX = CSSLengthInterpolationType::resolveInterpolableLength(*inte
rpolableList.get(ShadowX), nullptr, conversionData); | 141 Length shadowX = CSSLengthInterpolationType::resolveInterpolableLength(*inte
rpolableList.get(ShadowX), nullptr, conversionData); |
| 143 Length shadowY = CSSLengthInterpolationType::resolveInterpolableLength(*inte
rpolableList.get(ShadowY), nullptr, conversionData); | 142 Length shadowY = CSSLengthInterpolationType::resolveInterpolableLength(*inte
rpolableList.get(ShadowY), nullptr, conversionData); |
| 144 Length shadowBlur = CSSLengthInterpolationType::resolveInterpolableLength(*i
nterpolableList.get(ShadowBlur), nullptr, conversionData, ValueRangeNonNegative)
; | 143 Length shadowBlur = CSSLengthInterpolationType::resolveInterpolableLength(*i
nterpolableList.get(ShadowBlur), nullptr, conversionData, ValueRangeNonNegative)
; |
| 145 Length shadowSpread = CSSLengthInterpolationType::resolveInterpolableLength(
*interpolableList.get(ShadowSpread), nullptr, conversionData); | 144 Length shadowSpread = CSSLengthInterpolationType::resolveInterpolableLength(
*interpolableList.get(ShadowSpread), nullptr, conversionData); |
| 146 ASSERT(shadowX.isFixed() && shadowY.isFixed() && shadowBlur.isFixed() && sha
dowSpread.isFixed()); | 145 ASSERT(shadowX.isFixed() && shadowY.isFixed() && shadowBlur.isFixed() && sha
dowSpread.isFixed()); |
| 147 return ShadowData( | 146 return ShadowData( |
| 148 FloatPoint(shadowX.value(), shadowY.value()), shadowBlur.value(), shadow
Spread.value(), shadowNonInterpolableValue.style(), | 147 FloatPoint(shadowX.value(), shadowY.value()), shadowBlur.value(), shadow
Spread.value(), shadowNonInterpolableValue.style(), |
| 149 CSSColorInterpolationType::resolveInterpolableColor(*interpolableList.ge
t(ShadowColor), state)); | 148 CSSColorInterpolationType::resolveInterpolableColor(*interpolableList.ge
t(ShadowColor), state)); |
| 150 } | 149 } |
| 151 | 150 |
| 152 } // namespace blink | 151 } // namespace blink |
| OLD | NEW |