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/ShadowStyleInterpolation.h" | 6 #include "core/animation/ShadowStyleInterpolation.h" |
7 | 7 |
8 #include "core/animation/ColorStyleInterpolation.h" | 8 #include "core/animation/ColorStyleInterpolation.h" |
9 #include "core/animation/LengthStyleInterpolation.h" | 9 #include "core/animation/LengthStyleInterpolation.h" |
10 #include "core/css/CSSPrimitiveValue.h" | 10 #include "core/css/CSSPrimitiveValue.h" |
11 #include "core/css/CSSValuePool.h" | 11 #include "core/css/CSSValuePool.h" |
12 #include "core/css/resolver/StyleBuilder.h" | 12 #include "core/css/resolver/StyleBuilder.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 bool ShadowStyleInterpolation::canCreateFrom(const CSSValue& value) | 16 bool ShadowStyleInterpolation::canCreateFrom(const CSSValue& start, const CSSVal
ue& end) |
17 { | 17 { |
18 return value.isShadowValue(); | 18 return start.isShadowValue() && end.isShadowValue() |
| 19 && toCSSShadowValue(start).style == toCSSShadowValue(end).style; |
19 } | 20 } |
20 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::shadowToInte
rpolableValue(const CSSValue& value) | 21 |
| 22 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::lengthToInte
rpolableValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value) |
21 { | 23 { |
22 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(6); | 24 if (value && LengthStyleInterpolation::canCreateFrom(*value)) |
| 25 return LengthStyleInterpolation::toInterpolableValue(*value); |
| 26 return InterpolableBool::create(false); |
| 27 } |
| 28 |
| 29 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab
leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) |
| 30 { |
| 31 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); |
23 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); | 32 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); |
24 ASSERT(shadowValue); | 33 ASSERT(shadowValue); |
25 | 34 |
26 result->set(0, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->x)); | 35 result->set(0, lengthToInterpolableValue(shadowValue->x)); |
27 result->set(1, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->y)); | 36 result->set(1, lengthToInterpolableValue(shadowValue->y)); |
28 result->set(2, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->blur)); | 37 result->set(2, lengthToInterpolableValue(shadowValue->blur)); |
29 result->set(3, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->spread)); | 38 result->set(3, lengthToInterpolableValue(shadowValue->spread)); |
30 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadowValu
e->color)); | 39 |
| 40 if (shadowValue->color && ColorStyleInterpolation::canCreateFrom(*shadowValu
e->color)) |
| 41 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadow
Value->color)); |
| 42 else |
| 43 result->set(4, InterpolableBool::create(false)); |
| 44 |
| 45 if (shadowValue->style) |
| 46 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset
); |
| 47 else |
| 48 nonInterpolableData = false; |
31 | 49 |
32 return result.release(); | 50 return result.release(); |
33 } | 51 } |
34 | 52 |
35 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::interpolableValueToSh
adow(InterpolableValue* value, bool styleFlag) | 53 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> ShadowStyleInterpolation::interpolable
ValueToLength(const InterpolableValue* value, InterpolationRange range) |
36 { | 54 { |
37 InterpolableList* shadow = toInterpolableList(value); | 55 if (!value->isBool()) |
38 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::interpol
ableValueToLength(shadow->get(0), RangeNonNegative); | 56 return LengthStyleInterpolation::fromInterpolableValue(*value, range); |
39 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::interpol
ableValueToLength(shadow->get(1), RangeNonNegative); | 57 return nullptr; |
40 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::inter
polableValueToLength(shadow->get(2), RangeNonNegative); | 58 } |
41 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::int
erpolableValueToLength(shadow->get(3), RangeNonNegative); | |
42 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter
polableValueToColor(*(shadow->get(4))); | |
43 | 59 |
44 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = styleFlag ? CSSPrimitiveValue:
:createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier(CSSValueN
one); | 60 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue
(const InterpolableValue& value, NonInterpolableType nonInterpolableData, Interp
olationRange range) |
| 61 { |
| 62 const InterpolableList* shadow = toInterpolableList(&value); |
| 63 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = interpolableValueToLength(shadow->
get(0)); |
| 64 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = interpolableValueToLength(shadow->
get(1)); |
| 65 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = interpolableValueToLength(shado
w->get(2), RangeNonNegative); |
| 66 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = interpolableValueToLength(sha
dow->get(3)); |
| 67 |
| 68 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = (!shadow->get(4)->isBool()) ?
ColorStyleInterpolation::interpolableValueToColor(*shadow->get(4)) : nullptr; |
| 69 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi
tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier
(CSSValueNone); |
45 | 70 |
46 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu
r, spread, style, color); | 71 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu
r, spread, style, color); |
47 return result.release(); | 72 return result.release(); |
48 } | 73 } |
49 | 74 |
50 PassRefPtrWillBeRawPtr<ShadowStyleInterpolation> ShadowStyleInterpolation::maybe
CreateFromShadow(const CSSValue& start, const CSSValue& end, CSSPropertyID id) | 75 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) |
51 { | 76 { |
52 if (canCreateFrom(start) && canCreateFrom(end)) { | 77 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { |
53 if (toCSSShadowValue(start).style == toCSSShadowValue(end).style) { | 78 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
54 bool styleFlag = (toCSSShadowValue(start).style->getValueID() == CSS
ValueInset) ? true : false; | 79 if (!canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueList(e
nd).item(i))) |
55 return ShadowStyleInterpolation::create(start, end, id, styleFlag); | 80 return true; |
| 81 } |
56 } | 82 } |
57 } | 83 return false; |
58 return nullptr; | |
59 } | 84 } |
60 | 85 |
61 | 86 } // namespace blink |
62 void ShadowStyleInterpolation::apply(StyleResolverState& state) const | |
63 { | |
64 StyleBuilder::applyProperty(m_id, state, interpolableValueToShadow(m_cachedV
alue.get(), m_styleFlag).get()); | |
65 } | |
66 | |
67 void ShadowStyleInterpolation::trace(Visitor* visitor) | |
68 { | |
69 StyleInterpolation::trace(visitor); | |
70 } | |
71 | |
72 } | |
OLD | NEW |