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/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
| 10 #include "core/layout/LayoutTheme.h" | 11 #include "core/layout/LayoutTheme.h" |
| 11 #include "wtf/PtrUtil.h" | 12 #include "wtf/PtrUtil.h" |
| 12 #include <memory> | 13 #include <memory> |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 enum InterpolableColorIndex : unsigned { | 17 enum InterpolableColorIndex : unsigned { |
| 17 Red, | 18 Red, |
| 18 Green, | 19 Green, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 71 { | 72 { |
| 72 if (color.isCurrentColor()) | 73 if (color.isCurrentColor()) |
| 73 return createInterpolableColorForIndex(Currentcolor); | 74 return createInterpolableColorForIndex(Currentcolor); |
| 74 return createInterpolableColor(color.getColor()); | 75 return createInterpolableColor(color.getColor()); |
| 75 } | 76 } |
| 76 | 77 |
| 77 std::unique_ptr<InterpolableValue> CSSColorInterpolationType::maybeCreateInterpo lableColor(const CSSValue& value) | 78 std::unique_ptr<InterpolableValue> CSSColorInterpolationType::maybeCreateInterpo lableColor(const CSSValue& value) |
| 78 { | 79 { |
| 79 if (value.isColorValue()) | 80 if (value.isColorValue()) |
| 80 return createInterpolableColor(toCSSColorValue(value).value()); | 81 return createInterpolableColor(toCSSColorValue(value).value()); |
| 81 if (!value.isPrimitiveValue()) | 82 if (!value.isIdentifierValue()) |
| 82 return nullptr; | 83 return nullptr; |
| 83 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); | 84 const CSSIdentifierValue& ident = toCSSIdentifierValue(value); |
|
rjwright
2016/09/22 01:29:55
Avoid abbreviated variable names. You've used "ide
| |
| 84 if (!primitive.isValueID()) | 85 if (!StyleColor::isColorKeyword(ident.getValueID())) |
| 85 return nullptr; | 86 return nullptr; |
| 86 if (!StyleColor::isColorKeyword(primitive.getValueID())) | 87 return createInterpolableColor(ident.getValueID()); |
| 87 return nullptr; | |
| 88 return createInterpolableColor(primitive.getValueID()); | |
| 89 } | 88 } |
| 90 | 89 |
| 91 static void addPremultipliedColor(double& red, double& green, double& blue, doub le& alpha, double fraction, const Color& color) | 90 static void addPremultipliedColor(double& red, double& green, double& blue, doub le& alpha, double fraction, const Color& color) |
| 92 { | 91 { |
| 93 double colorAlpha = color.alpha(); | 92 double colorAlpha = color.alpha(); |
| 94 red += fraction * color.red() * colorAlpha; | 93 red += fraction * color.red() * colorAlpha; |
| 95 green += fraction * color.green() * colorAlpha; | 94 green += fraction * color.green() * colorAlpha; |
| 96 blue += fraction * color.blue() * colorAlpha; | 95 blue += fraction * color.blue() * colorAlpha; |
| 97 alpha += fraction * colorAlpha; | 96 alpha += fraction * colorAlpha; |
| 98 } | 97 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 } | 178 } |
| 180 | 179 |
| 181 enum InterpolableColorPairIndex : unsigned { | 180 enum InterpolableColorPairIndex : unsigned { |
| 182 Unvisited, | 181 Unvisited, |
| 183 Visited, | 182 Visited, |
| 184 InterpolableColorPairIndexCount, | 183 InterpolableColorPairIndexCount, |
| 185 }; | 184 }; |
| 186 | 185 |
| 187 InterpolationValue CSSColorInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState& state, ConversionCheckers& conversionCheckers) const | 186 InterpolationValue CSSColorInterpolationType::maybeConvertValue(const CSSValue& value, const StyleResolverState& state, ConversionCheckers& conversionCheckers) const |
| 188 { | 187 { |
| 189 if (cssProperty() == CSSPropertyColor && value.isPrimitiveValue() && toCSSPr imitiveValue(value).getValueID() == CSSValueCurrentcolor) | 188 if (cssProperty() == CSSPropertyColor && value.isIdentifierValue() && toCSSI dentifierValue(value).getValueID() == CSSValueCurrentcolor) |
| 190 return maybeConvertInherit(state, conversionCheckers); | 189 return maybeConvertInherit(state, conversionCheckers); |
| 191 | 190 |
| 192 std::unique_ptr<InterpolableValue> interpolableColor = maybeCreateInterpolab leColor(value); | 191 std::unique_ptr<InterpolableValue> interpolableColor = maybeCreateInterpolab leColor(value); |
| 193 if (!interpolableColor) | 192 if (!interpolableColor) |
| 194 return nullptr; | 193 return nullptr; |
| 195 std::unique_ptr<InterpolableList> colorPair = InterpolableList::create(Inter polableColorPairIndexCount); | 194 std::unique_ptr<InterpolableList> colorPair = InterpolableList::create(Inter polableColorPairIndexCount); |
| 196 colorPair->set(Unvisited, interpolableColor->clone()); | 195 colorPair->set(Unvisited, interpolableColor->clone()); |
| 197 colorPair->set(Visited, std::move(interpolableColor)); | 196 colorPair->set(Visited, std::move(interpolableColor)); |
| 198 return InterpolationValue(std::move(colorPair)); | 197 return InterpolationValue(std::move(colorPair)); |
| 199 } | 198 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 217 { | 216 { |
| 218 const InterpolableList& colorPair = toInterpolableList(interpolableValue); | 217 const InterpolableList& colorPair = toInterpolableList(interpolableValue); |
| 219 DCHECK_EQ(colorPair.length(), InterpolableColorPairIndexCount); | 218 DCHECK_EQ(colorPair.length(), InterpolableColorPairIndexCount); |
| 220 ColorPropertyFunctions::setUnvisitedColor(cssProperty(), *environment.state( ).style(), | 219 ColorPropertyFunctions::setUnvisitedColor(cssProperty(), *environment.state( ).style(), |
| 221 resolveInterpolableColor(*colorPair.get(Unvisited), environment.state(), false, cssProperty() == CSSPropertyTextDecorationColor)); | 220 resolveInterpolableColor(*colorPair.get(Unvisited), environment.state(), false, cssProperty() == CSSPropertyTextDecorationColor)); |
| 222 ColorPropertyFunctions::setVisitedColor(cssProperty(), *environment.state(). style(), | 221 ColorPropertyFunctions::setVisitedColor(cssProperty(), *environment.state(). style(), |
| 223 resolveInterpolableColor(*colorPair.get(Visited), environment.state(), t rue, cssProperty() == CSSPropertyTextDecorationColor)); | 222 resolveInterpolableColor(*colorPair.get(Visited), environment.state(), t rue, cssProperty() == CSSPropertyTextDecorationColor)); |
| 224 } | 223 } |
| 225 | 224 |
| 226 } // namespace blink | 225 } // namespace blink |
| OLD | NEW |