Chromium Code Reviews| 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 currentColorGetter(CSSPropertyWebkitTextFillColor, *state.style(), |
| 126 currentColorGetter(CSSPropertyWebkitTextFillColor, *state.style()); | 126 currentStyleColor); |
| 127 } | |
| 127 if (currentStyleColor.isCurrentColor()) | 128 if (currentStyleColor.isCurrentColor()) |
| 128 currentStyleColor = currentColorGetter(CSSPropertyColor, *state.style()); | 129 currentColorGetter(CSSPropertyColor, *state.style(), currentStyleColor); |
| 129 addPremultipliedColor(red, green, blue, alpha, currentcolorFraction, | 130 addPremultipliedColor(red, green, blue, alpha, currentcolorFraction, |
| 130 currentStyleColor.getColor()); | 131 currentStyleColor.getColor()); |
| 131 } | 132 } |
| 132 const TextLinkColors& colors = state.document().textLinkColors(); | 133 const TextLinkColors& colors = state.document().textLinkColors(); |
| 133 if (double webkitActivelinkFraction = | 134 if (double webkitActivelinkFraction = |
| 134 toInterpolableNumber(list.get(WebkitActivelink))->value()) | 135 toInterpolableNumber(list.get(WebkitActivelink))->value()) |
| 135 addPremultipliedColor(red, green, blue, alpha, webkitActivelinkFraction, | 136 addPremultipliedColor(red, green, blue, alpha, webkitActivelinkFraction, |
| 136 colors.activeLinkColor()); | 137 colors.activeLinkColor()); |
| 137 if (double webkitLinkFraction = | 138 if (double webkitLinkFraction = |
| 138 toInterpolableNumber(list.get(WebkitLink))->value()) | 139 toInterpolableNumber(list.get(WebkitLink))->value()) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 159 const StyleColor& color) { | 160 const StyleColor& color) { |
| 160 return WTF::wrapUnique(new InheritedColorChecker(property, color)); | 161 return WTF::wrapUnique(new InheritedColorChecker(property, color)); |
| 161 } | 162 } |
| 162 | 163 |
| 163 private: | 164 private: |
| 164 InheritedColorChecker(CSSPropertyID property, const StyleColor& color) | 165 InheritedColorChecker(CSSPropertyID property, const StyleColor& color) |
| 165 : m_property(property), m_color(color) {} | 166 : m_property(property), m_color(color) {} |
| 166 | 167 |
| 167 bool isValid(const InterpolationEnvironment& environment, | 168 bool isValid(const InterpolationEnvironment& environment, |
| 168 const InterpolationValue& underlying) const final { | 169 const InterpolationValue& underlying) const final { |
| 169 return m_color == ColorPropertyFunctions::getUnvisitedColor( | 170 StyleColor unvisitedColor; |
| 170 m_property, *environment.state().parentStyle()); | 171 if (!ColorPropertyFunctions::getUnvisitedColor( |
| 172 m_property, *environment.state().parentStyle(), unvisitedColor)) | |
| 173 return false; | |
| 174 return m_color == unvisitedColor; | |
| 171 } | 175 } |
| 172 | 176 |
| 173 const CSSPropertyID m_property; | 177 const CSSPropertyID m_property; |
| 174 const StyleColor m_color; | 178 const StyleColor 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 const StyleColor initialColor = | 191 StyleColor initialColor; |
| 188 ColorPropertyFunctions::getInitialColor(cssProperty()); | 192 if (ColorPropertyFunctions::getInitialColor(cssProperty(), initialColor)) |
| 189 return convertStyleColorPair(initialColor, initialColor); | 193 return convertStyleColorPair(initialColor, initialColor); |
| 194 return nullptr; | |
| 190 } | 195 } |
| 191 | 196 |
| 192 InterpolationValue CSSColorInterpolationType::maybeConvertInherit( | 197 InterpolationValue CSSColorInterpolationType::maybeConvertInherit( |
| 193 const StyleResolverState& state, | 198 const StyleResolverState& state, |
| 194 ConversionCheckers& conversionCheckers) const { | 199 ConversionCheckers& conversionCheckers) const { |
| 195 if (!state.parentStyle()) | 200 if (!state.parentStyle()) |
| 196 return nullptr; | 201 return nullptr; |
| 197 // Visited color can never explicitly inherit from parent visited color so | 202 // Visited color can never explicitly inherit from parent visited color so |
| 198 // only use the unvisited color. | 203 // only use the unvisited color. |
| 199 const StyleColor inheritedColor = ColorPropertyFunctions::getUnvisitedColor( | 204 StyleColor inheritedColor; |
| 200 cssProperty(), *state.parentStyle()); | 205 if (!ColorPropertyFunctions::getUnvisitedColor( |
| 206 cssProperty(), *state.parentStyle(), inheritedColor)) | |
| 207 return nullptr; | |
| 201 conversionCheckers.push_back( | 208 conversionCheckers.push_back( |
| 202 InheritedColorChecker::create(cssProperty(), inheritedColor)); | 209 InheritedColorChecker::create(cssProperty(), inheritedColor)); |
| 203 return convertStyleColorPair(inheritedColor, inheritedColor); | 210 return convertStyleColorPair(inheritedColor, inheritedColor); |
| 204 } | 211 } |
| 205 | 212 |
| 206 enum InterpolableColorPairIndex : unsigned { | 213 enum InterpolableColorPairIndex : unsigned { |
| 207 Unvisited, | 214 Unvisited, |
| 208 Visited, | 215 Visited, |
| 209 InterpolableColorPairIndexCount, | 216 InterpolableColorPairIndexCount, |
| 210 }; | 217 }; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 233 const StyleColor& visitedColor) const { | 240 const StyleColor& visitedColor) const { |
| 234 std::unique_ptr<InterpolableList> colorPair = | 241 std::unique_ptr<InterpolableList> colorPair = |
| 235 InterpolableList::create(InterpolableColorPairIndexCount); | 242 InterpolableList::create(InterpolableColorPairIndexCount); |
| 236 colorPair->set(Unvisited, createInterpolableColor(unvisitedColor)); | 243 colorPair->set(Unvisited, createInterpolableColor(unvisitedColor)); |
| 237 colorPair->set(Visited, createInterpolableColor(visitedColor)); | 244 colorPair->set(Visited, createInterpolableColor(visitedColor)); |
| 238 return InterpolationValue(std::move(colorPair)); | 245 return InterpolationValue(std::move(colorPair)); |
| 239 } | 246 } |
| 240 | 247 |
| 241 InterpolationValue CSSColorInterpolationType::maybeConvertUnderlyingValue( | 248 InterpolationValue CSSColorInterpolationType::maybeConvertUnderlyingValue( |
| 242 const InterpolationEnvironment& environment) const { | 249 const InterpolationEnvironment& environment) const { |
| 243 return convertStyleColorPair( | 250 StyleColor unvisitedColor; |
| 244 ColorPropertyFunctions::getUnvisitedColor(cssProperty(), | 251 if (!ColorPropertyFunctions::getUnvisitedColor( |
| 245 *environment.state().style()), | 252 cssProperty(), *environment.state().style(), unvisitedColor)) |
| 246 ColorPropertyFunctions::getVisitedColor(cssProperty(), | 253 return nullptr; |
| 247 *environment.state().style())); | 254 StyleColor visitedColor; |
| 255 if (!ColorPropertyFunctions::getVisitedColor( | |
| 256 cssProperty(), *environment.state().style(), visitedColor)) | |
| 257 return nullptr; | |
|
alancutter (OOO until 2018)
2016/12/21 00:49:05
I see a problem here. If either the visited or unv
Manuel Rego
2016/12/21 13:14:38
Wow, it's clear this is getting more complex. :-)
| |
| 258 | |
| 259 return convertStyleColorPair(unvisitedColor, visitedColor); | |
| 248 } | 260 } |
| 249 | 261 |
| 250 void CSSColorInterpolationType::apply( | 262 void CSSColorInterpolationType::apply( |
| 251 const InterpolableValue& interpolableValue, | 263 const InterpolableValue& interpolableValue, |
| 252 const NonInterpolableValue*, | 264 const NonInterpolableValue*, |
| 253 InterpolationEnvironment& environment) const { | 265 InterpolationEnvironment& environment) const { |
| 254 const InterpolableList& colorPair = toInterpolableList(interpolableValue); | 266 const InterpolableList& colorPair = toInterpolableList(interpolableValue); |
| 255 DCHECK_EQ(colorPair.length(), InterpolableColorPairIndexCount); | 267 DCHECK_EQ(colorPair.length(), InterpolableColorPairIndexCount); |
| 256 ColorPropertyFunctions::setUnvisitedColor( | 268 ColorPropertyFunctions::setUnvisitedColor( |
| 257 cssProperty(), *environment.state().style(), | 269 cssProperty(), *environment.state().style(), |
| 258 resolveInterpolableColor( | 270 resolveInterpolableColor( |
| 259 *colorPair.get(Unvisited), environment.state(), false, | 271 *colorPair.get(Unvisited), environment.state(), false, |
| 260 cssProperty() == CSSPropertyTextDecorationColor)); | 272 cssProperty() == CSSPropertyTextDecorationColor)); |
| 261 ColorPropertyFunctions::setVisitedColor( | 273 ColorPropertyFunctions::setVisitedColor( |
| 262 cssProperty(), *environment.state().style(), | 274 cssProperty(), *environment.state().style(), |
| 263 resolveInterpolableColor( | 275 resolveInterpolableColor( |
| 264 *colorPair.get(Visited), environment.state(), true, | 276 *colorPair.get(Visited), environment.state(), true, |
| 265 cssProperty() == CSSPropertyTextDecorationColor)); | 277 cssProperty() == CSSPropertyTextDecorationColor)); |
| 266 } | 278 } |
| 267 | 279 |
| 268 } // namespace blink | 280 } // namespace blink |
| OLD | NEW |