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