| 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 |
| 20 && toCSSShadowValue(start).color && toCSSShadowValue(start).color; |
| 19 } | 21 } |
| 20 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::shadowToInte
rpolableValue(const CSSValue& value) | 22 |
| 23 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::lengthToInte
rpolableValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value) |
| 21 { | 24 { |
| 22 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(6); | 25 if (value) |
| 26 return LengthStyleInterpolation::toInterpolableValue(*value); |
| 27 return LengthStyleInterpolation::toInterpolableValue(*CSSPrimitiveValue::cre
ate(0, CSSPrimitiveValue::CSS_PX)); |
| 28 } |
| 29 |
| 30 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab
leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) |
| 31 { |
| 32 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); |
| 23 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); | 33 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); |
| 24 ASSERT(shadowValue); | 34 ASSERT(shadowValue); |
| 25 | 35 |
| 26 result->set(0, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->x)); | 36 result->set(0, lengthToInterpolableValue(shadowValue->x)); |
| 27 result->set(1, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->y)); | 37 result->set(1, lengthToInterpolableValue(shadowValue->y)); |
| 28 result->set(2, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->blur)); | 38 result->set(2, lengthToInterpolableValue(shadowValue->blur)); |
| 29 result->set(3, LengthStyleInterpolation::lengthToInterpolableValue(*shadowVa
lue->spread)); | 39 result->set(3, lengthToInterpolableValue(shadowValue->spread)); |
| 30 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadowValu
e->color)); | 40 |
| 41 if (shadowValue->color && ColorStyleInterpolation::canCreateFrom(*shadowValu
e->color)) |
| 42 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadow
Value->color)); |
| 43 |
| 44 if (shadowValue->style) |
| 45 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset
); |
| 46 else |
| 47 nonInterpolableData = false; |
| 31 | 48 |
| 32 return result.release(); | 49 return result.release(); |
| 33 } | 50 } |
| 34 | 51 |
| 35 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::interpolableValueToSh
adow(InterpolableValue* value, bool styleFlag) | 52 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue
(const InterpolableValue& value, NonInterpolableType nonInterpolableData, Interp
olationRange range) |
| 36 { | 53 { |
| 37 InterpolableList* shadow = toInterpolableList(value); | 54 const InterpolableList* shadow = toInterpolableList(&value); |
| 38 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::interpol
ableValueToLength(shadow->get(0), RangeNonNegative); | 55 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(0), RangeAll); |
| 39 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::interpol
ableValueToLength(shadow->get(1), RangeNonNegative); | 56 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(1), RangeAll); |
| 40 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::inter
polableValueToLength(shadow->get(2), RangeNonNegative); | 57 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::fromI
nterpolableValue(*shadow->get(2), RangeNonNegative); |
| 41 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::int
erpolableValueToLength(shadow->get(3), RangeNonNegative); | 58 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::fro
mInterpolableValue(*shadow->get(3), RangeAll); |
| 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 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter
polableValueToColor(*shadow->get(4)); |
| 61 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi
tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier
(CSSValueNone); |
| 45 | 62 |
| 46 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu
r, spread, style, color); | 63 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu
r, spread, style, color); |
| 47 return result.release(); | 64 return result.release(); |
| 48 } | 65 } |
| 49 | 66 |
| 50 PassRefPtrWillBeRawPtr<ShadowStyleInterpolation> ShadowStyleInterpolation::maybe
CreateFromShadow(const CSSValue& start, const CSSValue& end, CSSPropertyID id) | 67 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) |
| 51 { | 68 { |
| 52 if (canCreateFrom(start) && canCreateFrom(end)) { | 69 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { |
| 53 if (toCSSShadowValue(start).style == toCSSShadowValue(end).style) { | 70 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| 54 bool styleFlag = (toCSSShadowValue(start).style->getValueID() == CSS
ValueInset) ? true : false; | 71 if (!canCreateFrom(*toCSSValueList(start).item(i), *toCSSValueList(e
nd).item(i))) |
| 55 return ShadowStyleInterpolation::create(start, end, id, styleFlag); | 72 return true; |
| 56 } | 73 } |
| 57 } | 74 } |
| 58 return nullptr; | 75 return false; |
| 59 } | 76 } |
| 60 | 77 |
| 61 | 78 } // 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 |