OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "config.h" | 5 #include "config.h" |
6 #include "core/animation/ColorStyleInterpolation.h" | 6 #include "core/animation/ColorStyleInterpolation.h" |
7 | 7 |
8 #include "core/CSSValueKeywords.h" | 8 #include "core/CSSValueKeywords.h" |
9 #include "core/css/CSSPrimitiveValue.h" | 9 #include "core/css/CSSPrimitiveValue.h" |
10 #include "core/css/parser/CSSPropertyParser.h" | 10 #include "core/css/parser/CSSPropertyParser.h" |
11 #include "core/css/resolver/StyleBuilder.h" | 11 #include "core/css/resolver/StyleBuilder.h" |
12 #include "core/layout/LayoutTheme.h" | 12 #include "core/layout/LayoutTheme.h" |
13 #include "platform/graphics/Color.h" | 13 #include "platform/graphics/Color.h" |
14 #include "wtf/MathExtras.h" | 14 #include "wtf/MathExtras.h" |
15 | 15 |
16 #include <algorithm> | 16 #include <algorithm> |
17 | 17 |
18 namespace blink { | 18 namespace blink { |
19 | 19 |
20 bool ColorStyleInterpolation::canCreateFrom(const CSSValue& value) | 20 bool ColorStyleInterpolation::canCreateFrom(const CSSValue& value) |
21 { | 21 { |
22 return value.isPrimitiveValue() && (toCSSPrimitiveValue(value).isValueID() |
| toCSSPrimitiveValue(value).isRGBColor()); | 22 return value.isPrimitiveValue() && (toCSSPrimitiveValue(value).isValueID() |
| toCSSPrimitiveValue(value).isRGBColor()); |
23 } | 23 } |
24 | 24 |
25 PassOwnPtrWillBeRawPtr<InterpolableValue> ColorStyleInterpolation::colorToInterp
olableValue(const CSSValue& value) | 25 InterpolableValue* ColorStyleInterpolation::colorToInterpolableValue(const CSSVa
lue& value) |
26 { | 26 { |
27 ASSERT(value.isPrimitiveValue()); | 27 ASSERT(value.isPrimitiveValue()); |
28 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); | 28 const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); |
29 RGBA32 color; | 29 RGBA32 color; |
30 if (primitive.isValueID()) { | 30 if (primitive.isValueID()) { |
31 if (CSSPropertyParser::isSystemColor(primitive.getValueID())) { | 31 if (CSSPropertyParser::isSystemColor(primitive.getValueID())) { |
32 color = LayoutTheme::theme().systemColor(primitive.getValueID()).rgb
(); | 32 color = LayoutTheme::theme().systemColor(primitive.getValueID()).rgb
(); |
33 } else { | 33 } else { |
34 Color colorFromID; | 34 Color colorFromID; |
35 colorFromID.setNamedColor(getValueName(primitive.getValueID())); | 35 colorFromID.setNamedColor(getValueName(primitive.getValueID())); |
36 color = colorFromID.rgb(); | 36 color = colorFromID.rgb(); |
37 } | 37 } |
38 } else { | 38 } else { |
39 color = primitive.getRGBA32Value(); | 39 color = primitive.getRGBA32Value(); |
40 } | 40 } |
41 | 41 |
42 int alpha = alphaChannel(color); | 42 int alpha = alphaChannel(color); |
43 | 43 |
44 OwnPtrWillBeRawPtr<InterpolableList> list = InterpolableList::create(4); | 44 InterpolableList* list = InterpolableList::create(4); |
45 list->set(0, InterpolableNumber::create(redChannel(color) * alpha)); | 45 list->set(0, InterpolableNumber::create(redChannel(color) * alpha)); |
46 list->set(1, InterpolableNumber::create(greenChannel(color) * alpha)); | 46 list->set(1, InterpolableNumber::create(greenChannel(color) * alpha)); |
47 list->set(2, InterpolableNumber::create(blueChannel(color) * alpha)); | 47 list->set(2, InterpolableNumber::create(blueChannel(color) * alpha)); |
48 list->set(3, InterpolableNumber::create(alpha)); | 48 list->set(3, InterpolableNumber::create(alpha)); |
49 | 49 |
50 return list->clone(); | 50 return list->clone(); |
51 } | 51 } |
52 | 52 |
53 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> ColorStyleInterpolation::interpolableV
alueToColor(const InterpolableValue& value) | 53 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> ColorStyleInterpolation::interpolableV
alueToColor(const InterpolableValue& value) |
54 { | 54 { |
(...skipping 17 matching lines...) Expand all Loading... |
72 void ColorStyleInterpolation::apply(StyleResolverState& state) const | 72 void ColorStyleInterpolation::apply(StyleResolverState& state) const |
73 { | 73 { |
74 StyleBuilder::applyProperty(m_id, state, interpolableValueToColor(*m_cachedV
alue).get()); | 74 StyleBuilder::applyProperty(m_id, state, interpolableValueToColor(*m_cachedV
alue).get()); |
75 } | 75 } |
76 | 76 |
77 DEFINE_TRACE(ColorStyleInterpolation) | 77 DEFINE_TRACE(ColorStyleInterpolation) |
78 { | 78 { |
79 StyleInterpolation::trace(visitor); | 79 StyleInterpolation::trace(visitor); |
80 } | 80 } |
81 | 81 |
82 PassRefPtrWillBeRawPtr<ColorStyleInterpolation> ColorStyleInterpolation::maybeCr
eateFromColor(const CSSValue& start, const CSSValue& end, CSSPropertyID id) | 82 ColorStyleInterpolation* ColorStyleInterpolation::maybeCreateFromColor(const CSS
Value& start, const CSSValue& end, CSSPropertyID id) |
83 { | 83 { |
84 if (canCreateFrom(start) && !toCSSPrimitiveValue(start).colorIsDerivedFromEl
ement() && canCreateFrom(end) && !toCSSPrimitiveValue(end).colorIsDerivedFromEle
ment()) | 84 if (canCreateFrom(start) && !toCSSPrimitiveValue(start).colorIsDerivedFromEl
ement() && canCreateFrom(end) && !toCSSPrimitiveValue(end).colorIsDerivedFromEle
ment()) |
85 return adoptRefWillBeNoop(new ColorStyleInterpolation(colorToInterpolabl
eValue(start), colorToInterpolableValue(end), id)); | 85 return new ColorStyleInterpolation(colorToInterpolableValue(start), colo
rToInterpolableValue(end), id); |
86 return nullptr; | 86 return nullptr; |
87 } | 87 } |
88 | 88 |
89 bool ColorStyleInterpolation::shouldUseLegacyStyleInterpolation(const CSSValue&
start, const CSSValue& end) | 89 bool ColorStyleInterpolation::shouldUseLegacyStyleInterpolation(const CSSValue&
start, const CSSValue& end) |
90 { | 90 { |
91 if (ColorStyleInterpolation::canCreateFrom(start) && ColorStyleInterpolation
::canCreateFrom(end)) { | 91 if (ColorStyleInterpolation::canCreateFrom(start) && ColorStyleInterpolation
::canCreateFrom(end)) { |
92 if (toCSSPrimitiveValue(start).colorIsDerivedFromElement() || toCSSPrimi
tiveValue(end).colorIsDerivedFromElement()) | 92 if (toCSSPrimitiveValue(start).colorIsDerivedFromElement() || toCSSPrimi
tiveValue(end).colorIsDerivedFromElement()) |
93 return true; | 93 return true; |
94 } | 94 } |
95 return false; | 95 return false; |
96 } | 96 } |
97 | 97 |
98 } | 98 } |
OLD | NEW |