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)) |
dstockwell
2015/02/02 06:10:11
When can LengthStyleInterpolation::canCreateFrom r
evemj (not active)
2015/02/03 00:25:55
Done.
(Never oops)
| |
25 return LengthStyleInterpolation::toInterpolableValue(*value); | |
26 return InterpolableBool::create(false); | |
dstockwell
2015/02/02 06:10:12
Using an InterpolableBool seems a bit of a hack. M
shans
2015/02/02 23:49:11
We should use an InterpolableValue that represents
evemj (not active)
2015/02/03 00:25:55
Done.
Additionally we are now not handling the ca
| |
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)); | |
dstockwell
2015/02/02 06:10:11
Is there any reason to set this to a bool over swi
| |
44 | |
45 if (shadowValue->style) | |
46 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset ); | |
31 | 47 |
32 return result.release(); | 48 return result.release(); |
33 } | 49 } |
34 | 50 |
35 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::interpolableValueToSh adow(InterpolableValue* value, bool styleFlag) | 51 PassRefPtrWillBeRawPtr<CSSPrimitiveValue> ShadowStyleInterpolation::interpolable ValueToLength(const InterpolableValue* value, InterpolationRange range) |
36 { | 52 { |
37 InterpolableList* shadow = toInterpolableList(value); | 53 if (!value->isBool()) |
38 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::interpol ableValueToLength(shadow->get(0), RangeNonNegative); | 54 return LengthStyleInterpolation::fromInterpolableValue(*value, range); |
39 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::interpol ableValueToLength(shadow->get(1), RangeNonNegative); | 55 return nullptr; |
40 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::inter polableValueToLength(shadow->get(2), RangeNonNegative); | 56 } |
41 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::int erpolableValueToLength(shadow->get(3), RangeNonNegative); | |
42 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter polableValueToColor(*(shadow->get(4))); | |
43 | 57 |
44 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = styleFlag ? CSSPrimitiveValue: :createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier(CSSValueN one); | 58 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue (const InterpolableValue& value, NonInterpolableType nonInterpolableData, Interp olationRange range) |
59 { | |
60 const InterpolableList* shadow = toInterpolableList(&value); | |
61 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = interpolableValueToLength(shadow-> get(0)); | |
62 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = interpolableValueToLength(shadow-> get(1)); | |
63 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = interpolableValueToLength(shado w->get(2), RangeNonNegative); | |
64 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = interpolableValueToLength(sha dow->get(3)); | |
65 | |
66 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = (!shadow->get(4)->isBool()) ? ColorStyleInterpolation::interpolableValueToColor(*shadow->get(4)) : nullptr; | |
dstockwell
2015/02/02 06:10:12
outer parens not needed
evemj (not active)
2015/02/03 00:25:56
Done.
| |
67 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier (CSSValueNone); | |
45 | 68 |
46 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu r, spread, style, color); | 69 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu r, spread, style, color); |
47 return result.release(); | 70 return result.release(); |
48 } | 71 } |
49 | 72 |
50 PassRefPtrWillBeRawPtr<ShadowStyleInterpolation> ShadowStyleInterpolation::maybe CreateFromShadow(const CSSValue& start, const CSSValue& end, CSSPropertyID id) | 73 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta rt, const CSSValue& end) |
51 { | 74 { |
52 if (canCreateFrom(start) && canCreateFrom(end)) { | 75 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length () == toCSSValueList(end).length()) { |
53 if (toCSSShadowValue(start).style == toCSSShadowValue(end).style) { | 76 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
54 bool styleFlag = (toCSSShadowValue(start).style->getValueID() == CSS ValueInset) ? true : false; | 77 if (!canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueList(e nd).item(i))) |
55 return ShadowStyleInterpolation::create(start, end, id, styleFlag); | 78 return true; |
79 } | |
56 } | 80 } |
dstockwell
2015/02/02 06:10:11
these braces aren't indented correctly
evemj (not active)
2015/02/03 00:25:55
Done.
| |
57 } | 81 return false; |
58 return nullptr; | |
59 } | 82 } |
60 | 83 |
61 | 84 } // 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 |