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/CSSColorInterpolationType.h" | 5 #include "core/animation/CSSColorInterpolationType.h" |
6 | 6 |
7 #include "core/animation/ColorPropertyFunctions.h" | 7 #include "core/animation/ColorPropertyFunctions.h" |
8 #include "core/css/CSSColorValue.h" | 8 #include "core/css/CSSColorValue.h" |
9 #include "core/css/CSSIdentifierValue.h" | 9 #include "core/css/CSSIdentifierValue.h" |
10 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 double green = toInterpolableNumber(list.get(Green))->value(); | 114 double green = toInterpolableNumber(list.get(Green))->value(); |
115 double blue = toInterpolableNumber(list.get(Blue))->value(); | 115 double blue = toInterpolableNumber(list.get(Blue))->value(); |
116 double alpha = toInterpolableNumber(list.get(Alpha))->value(); | 116 double alpha = toInterpolableNumber(list.get(Alpha))->value(); |
117 | 117 |
118 if (double currentcolorFraction = | 118 if (double currentcolorFraction = |
119 toInterpolableNumber(list.get(Currentcolor))->value()) { | 119 toInterpolableNumber(list.get(Currentcolor))->value()) { |
120 auto currentColorGetter = isVisited | 120 auto currentColorGetter = isVisited |
121 ? ColorPropertyFunctions::getVisitedColor | 121 ? ColorPropertyFunctions::getVisitedColor |
122 : ColorPropertyFunctions::getUnvisitedColor; | 122 : ColorPropertyFunctions::getUnvisitedColor; |
123 StyleColor currentStyleColor = StyleColor::currentColor(); | 123 StyleColor currentStyleColor = StyleColor::currentColor(); |
124 if (isTextDecoration) | 124 if (isTextDecoration) { |
125 currentStyleColor = | 125 currentStyleColor = |
126 currentColorGetter(CSSPropertyWebkitTextFillColor, *state.style()); | 126 currentColorGetter(CSSPropertyWebkitTextFillColor, *state.style()) |
127 if (currentStyleColor.isCurrentColor()) | 127 .access(); |
128 currentStyleColor = currentColorGetter(CSSPropertyColor, *state.style()); | 128 } |
| 129 if (currentStyleColor.isCurrentColor()) { |
| 130 currentStyleColor = |
| 131 currentColorGetter(CSSPropertyColor, *state.style()).access(); |
| 132 } |
129 addPremultipliedColor(red, green, blue, alpha, currentcolorFraction, | 133 addPremultipliedColor(red, green, blue, alpha, currentcolorFraction, |
130 currentStyleColor.getColor()); | 134 currentStyleColor.getColor()); |
131 } | 135 } |
132 const TextLinkColors& colors = state.document().textLinkColors(); | 136 const TextLinkColors& colors = state.document().textLinkColors(); |
133 if (double webkitActivelinkFraction = | 137 if (double webkitActivelinkFraction = |
134 toInterpolableNumber(list.get(WebkitActivelink))->value()) | 138 toInterpolableNumber(list.get(WebkitActivelink))->value()) |
135 addPremultipliedColor(red, green, blue, alpha, webkitActivelinkFraction, | 139 addPremultipliedColor(red, green, blue, alpha, webkitActivelinkFraction, |
136 colors.activeLinkColor()); | 140 colors.activeLinkColor()); |
137 if (double webkitLinkFraction = | 141 if (double webkitLinkFraction = |
138 toInterpolableNumber(list.get(WebkitLink))->value()) | 142 toInterpolableNumber(list.get(WebkitLink))->value()) |
(...skipping 10 matching lines...) Expand all Loading... |
149 return Color::transparent; | 153 return Color::transparent; |
150 | 154 |
151 return makeRGBA(round(red / alpha), round(green / alpha), round(blue / alpha), | 155 return makeRGBA(round(red / alpha), round(green / alpha), round(blue / alpha), |
152 round(alpha)); | 156 round(alpha)); |
153 } | 157 } |
154 | 158 |
155 class InheritedColorChecker : public InterpolationType::ConversionChecker { | 159 class InheritedColorChecker : public InterpolationType::ConversionChecker { |
156 public: | 160 public: |
157 static std::unique_ptr<InheritedColorChecker> create( | 161 static std::unique_ptr<InheritedColorChecker> create( |
158 CSSPropertyID property, | 162 CSSPropertyID property, |
159 const StyleColor& color) { | 163 const OptionalStyleColor& color) { |
160 return WTF::wrapUnique(new InheritedColorChecker(property, color)); | 164 return WTF::wrapUnique(new InheritedColorChecker(property, color)); |
161 } | 165 } |
162 | 166 |
163 private: | 167 private: |
164 InheritedColorChecker(CSSPropertyID property, const StyleColor& color) | 168 InheritedColorChecker(CSSPropertyID property, const OptionalStyleColor& color) |
165 : m_property(property), m_color(color) {} | 169 : m_property(property), m_color(color) {} |
166 | 170 |
167 bool isValid(const InterpolationEnvironment& environment, | 171 bool isValid(const InterpolationEnvironment& environment, |
168 const InterpolationValue& underlying) const final { | 172 const InterpolationValue& underlying) const final { |
169 return m_color == ColorPropertyFunctions::getUnvisitedColor( | 173 return m_color == ColorPropertyFunctions::getUnvisitedColor( |
170 m_property, *environment.state().parentStyle()); | 174 m_property, *environment.state().parentStyle()); |
171 } | 175 } |
172 | 176 |
173 const CSSPropertyID m_property; | 177 const CSSPropertyID m_property; |
174 const StyleColor m_color; | 178 const OptionalStyleColor m_color; |
175 }; | 179 }; |
176 | 180 |
177 InterpolationValue CSSColorInterpolationType::maybeConvertNeutral( | 181 InterpolationValue CSSColorInterpolationType::maybeConvertNeutral( |
178 const InterpolationValue&, | 182 const InterpolationValue&, |
179 ConversionCheckers&) const { | 183 ConversionCheckers&) const { |
180 return convertStyleColorPair(StyleColor(Color::transparent), | 184 return convertStyleColorPair(StyleColor(Color::transparent), |
181 StyleColor(Color::transparent)); | 185 StyleColor(Color::transparent)); |
182 } | 186 } |
183 | 187 |
184 InterpolationValue CSSColorInterpolationType::maybeConvertInitial( | 188 InterpolationValue CSSColorInterpolationType::maybeConvertInitial( |
185 const StyleResolverState&, | 189 const StyleResolverState&, |
186 ConversionCheckers& conversionCheckers) const { | 190 ConversionCheckers& conversionCheckers) const { |
187 StyleColor initialColor; | 191 OptionalStyleColor initialColor = |
188 if (ColorPropertyFunctions::getInitialColor(cssProperty(), initialColor)) | 192 ColorPropertyFunctions::getInitialColor(cssProperty()); |
189 return convertStyleColorPair(initialColor, initialColor); | 193 if (initialColor.isNull()) |
190 return nullptr; | 194 return nullptr; |
| 195 return convertStyleColorPair(initialColor.access(), initialColor.access()); |
191 } | 196 } |
192 | 197 |
193 InterpolationValue CSSColorInterpolationType::maybeConvertInherit( | 198 InterpolationValue CSSColorInterpolationType::maybeConvertInherit( |
194 const StyleResolverState& state, | 199 const StyleResolverState& state, |
195 ConversionCheckers& conversionCheckers) const { | 200 ConversionCheckers& conversionCheckers) const { |
196 if (!state.parentStyle()) | 201 if (!state.parentStyle()) |
197 return nullptr; | 202 return nullptr; |
198 // Visited color can never explicitly inherit from parent visited color so | 203 // Visited color can never explicitly inherit from parent visited color so |
199 // only use the unvisited color. | 204 // only use the unvisited color. |
200 const StyleColor inheritedColor = ColorPropertyFunctions::getUnvisitedColor( | 205 OptionalStyleColor inheritedColor = ColorPropertyFunctions::getUnvisitedColor( |
201 cssProperty(), *state.parentStyle()); | 206 cssProperty(), *state.parentStyle()); |
202 conversionCheckers.push_back( | 207 conversionCheckers.push_back( |
203 InheritedColorChecker::create(cssProperty(), inheritedColor)); | 208 InheritedColorChecker::create(cssProperty(), inheritedColor)); |
204 return convertStyleColorPair(inheritedColor, inheritedColor); | 209 return convertStyleColorPair(inheritedColor, inheritedColor); |
205 } | 210 } |
206 | 211 |
207 enum InterpolableColorPairIndex : unsigned { | 212 enum InterpolableColorPairIndex : unsigned { |
208 Unvisited, | 213 Unvisited, |
209 Visited, | 214 Visited, |
210 InterpolableColorPairIndexCount, | 215 InterpolableColorPairIndexCount, |
(...skipping 14 matching lines...) Expand all Loading... |
225 if (!interpolableColor) | 230 if (!interpolableColor) |
226 return nullptr; | 231 return nullptr; |
227 std::unique_ptr<InterpolableList> colorPair = | 232 std::unique_ptr<InterpolableList> colorPair = |
228 InterpolableList::create(InterpolableColorPairIndexCount); | 233 InterpolableList::create(InterpolableColorPairIndexCount); |
229 colorPair->set(Unvisited, interpolableColor->clone()); | 234 colorPair->set(Unvisited, interpolableColor->clone()); |
230 colorPair->set(Visited, std::move(interpolableColor)); | 235 colorPair->set(Visited, std::move(interpolableColor)); |
231 return InterpolationValue(std::move(colorPair)); | 236 return InterpolationValue(std::move(colorPair)); |
232 } | 237 } |
233 | 238 |
234 InterpolationValue CSSColorInterpolationType::convertStyleColorPair( | 239 InterpolationValue CSSColorInterpolationType::convertStyleColorPair( |
235 const StyleColor& unvisitedColor, | 240 const OptionalStyleColor& unvisitedColor, |
236 const StyleColor& visitedColor) const { | 241 const OptionalStyleColor& visitedColor) const { |
| 242 if (unvisitedColor.isNull() || visitedColor.isNull()) { |
| 243 return nullptr; |
| 244 } |
237 std::unique_ptr<InterpolableList> colorPair = | 245 std::unique_ptr<InterpolableList> colorPair = |
238 InterpolableList::create(InterpolableColorPairIndexCount); | 246 InterpolableList::create(InterpolableColorPairIndexCount); |
239 colorPair->set(Unvisited, createInterpolableColor(unvisitedColor)); | 247 colorPair->set(Unvisited, createInterpolableColor(unvisitedColor.access())); |
240 colorPair->set(Visited, createInterpolableColor(visitedColor)); | 248 colorPair->set(Visited, createInterpolableColor(visitedColor.access())); |
241 return InterpolationValue(std::move(colorPair)); | 249 return InterpolationValue(std::move(colorPair)); |
242 } | 250 } |
243 | 251 |
244 InterpolationValue | 252 InterpolationValue |
245 CSSColorInterpolationType::maybeConvertStandardPropertyUnderlyingValue( | 253 CSSColorInterpolationType::maybeConvertStandardPropertyUnderlyingValue( |
246 const ComputedStyle& style) const { | 254 const ComputedStyle& style) const { |
247 return convertStyleColorPair( | 255 return convertStyleColorPair( |
248 ColorPropertyFunctions::getUnvisitedColor(cssProperty(), style), | 256 ColorPropertyFunctions::getUnvisitedColor(cssProperty(), style), |
249 ColorPropertyFunctions::getVisitedColor(cssProperty(), style)); | 257 ColorPropertyFunctions::getVisitedColor(cssProperty(), style)); |
250 } | 258 } |
(...skipping 19 matching lines...) Expand all Loading... |
270 const CSSValue* CSSColorInterpolationType::createCSSValue( | 278 const CSSValue* CSSColorInterpolationType::createCSSValue( |
271 const InterpolableValue& interpolableValue, | 279 const InterpolableValue& interpolableValue, |
272 const NonInterpolableValue*, | 280 const NonInterpolableValue*, |
273 const StyleResolverState& state) const { | 281 const StyleResolverState& state) const { |
274 const InterpolableList& colorPair = toInterpolableList(interpolableValue); | 282 const InterpolableList& colorPair = toInterpolableList(interpolableValue); |
275 Color color = resolveInterpolableColor(*colorPair.get(Unvisited), state); | 283 Color color = resolveInterpolableColor(*colorPair.get(Unvisited), state); |
276 return CSSColorValue::create(color.rgb()); | 284 return CSSColorValue::create(color.rgb()); |
277 } | 285 } |
278 | 286 |
279 } // namespace blink | 287 } // namespace blink |
OLD | NEW |