| 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/CSSValueList.h" | 11 #include "core/css/CSSValueList.h" |
| 12 #include "core/css/CSSValuePool.h" | 12 #include "core/css/CSSValuePool.h" |
| 13 #include "core/css/resolver/StyleBuilder.h" | 13 #include "core/css/resolver/StyleBuilder.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 | 16 |
| 17 bool ShadowStyleInterpolation::canCreateFrom(const CSSValue& start, const CSSVal
ue& end) | 17 bool ShadowStyleInterpolation::canCreateFrom(const CSSValue& start, const CSSVal
ue& end) |
| 18 { | 18 { |
| 19 if (!start.isShadowValue() || end.isShadowValue()) | 19 if (!start.isShadowValue() || end.isShadowValue()) |
| 20 return false; | 20 return false; |
| 21 const CSSShadowValue& startShadow = toCSSShadowValue(start); | 21 const CSSShadowValue& startShadow = toCSSShadowValue(start); |
| 22 const CSSShadowValue& endShadow = toCSSShadowValue(end); | 22 const CSSShadowValue& endShadow = toCSSShadowValue(end); |
| 23 if (startShadow.style != endShadow.style || !startShadow.color || !endShadow
.color) | 23 if (startShadow.style != endShadow.style || !startShadow.color || !endShadow
.color) |
| 24 return false; | 24 return false; |
| 25 return !ColorStyleInterpolation::shouldUseLegacyStyleInterpolation(*startSha
dow.color, *endShadow.color); | 25 return !ColorStyleInterpolation::shouldUseLegacyStyleInterpolation(*startSha
dow.color, *endShadow.color); |
| 26 } | 26 } |
| 27 | 27 |
| 28 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::lengthToInte
rpolableValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value) | 28 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::lengthToInte
rpolableValue(PassRefPtr<CSSPrimitiveValue> value) |
| 29 { | 29 { |
| 30 if (value) | 30 if (value) |
| 31 return LengthStyleInterpolation::toInterpolableValue(*value); | 31 return LengthStyleInterpolation::toInterpolableValue(*value); |
| 32 return LengthStyleInterpolation::toInterpolableValue(*CSSPrimitiveValue::cre
ate(0, CSSPrimitiveValue::UnitType::Pixels)); | 32 return LengthStyleInterpolation::toInterpolableValue(*CSSPrimitiveValue::cre
ate(0, CSSPrimitiveValue::UnitType::Pixels)); |
| 33 } | 33 } |
| 34 | 34 |
| 35 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab
leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) | 35 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab
leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) |
| 36 { | 36 { |
| 37 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); | 37 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); |
| 38 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); | 38 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); |
| 39 ASSERT(shadowValue); | 39 ASSERT(shadowValue); |
| 40 | 40 |
| 41 result->set(0, lengthToInterpolableValue(shadowValue->x)); | 41 result->set(0, lengthToInterpolableValue(shadowValue->x)); |
| 42 result->set(1, lengthToInterpolableValue(shadowValue->y)); | 42 result->set(1, lengthToInterpolableValue(shadowValue->y)); |
| 43 result->set(2, lengthToInterpolableValue(shadowValue->blur)); | 43 result->set(2, lengthToInterpolableValue(shadowValue->blur)); |
| 44 result->set(3, lengthToInterpolableValue(shadowValue->spread)); | 44 result->set(3, lengthToInterpolableValue(shadowValue->spread)); |
| 45 | 45 |
| 46 if (shadowValue->color && ColorStyleInterpolation::canCreateFrom(*shadowValu
e->color)) | 46 if (shadowValue->color && ColorStyleInterpolation::canCreateFrom(*shadowValu
e->color)) |
| 47 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadow
Value->color)); | 47 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadow
Value->color)); |
| 48 | 48 |
| 49 if (shadowValue->style) | 49 if (shadowValue->style) |
| 50 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset
); | 50 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset
); |
| 51 else | 51 else |
| 52 nonInterpolableData = false; | 52 nonInterpolableData = false; |
| 53 | 53 |
| 54 return result.release(); | 54 return result.release(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue
(const InterpolableValue& value, NonInterpolableType nonInterpolableData, Interp
olationRange range) | 57 PassRefPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue(const Inter
polableValue& value, NonInterpolableType nonInterpolableData, InterpolationRange
range) |
| 58 { | 58 { |
| 59 const InterpolableList* shadow = toInterpolableList(&value); | 59 const InterpolableList* shadow = toInterpolableList(&value); |
| 60 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(0), RangeAll); | 60 RefPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::fromInterpolableValu
e(*shadow->get(0), RangeAll); |
| 61 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(1), RangeAll); | 61 RefPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::fromInterpolableValu
e(*shadow->get(1), RangeAll); |
| 62 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::fromI
nterpolableValue(*shadow->get(2), RangeNonNegative); | 62 RefPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::fromInterpolableV
alue(*shadow->get(2), RangeNonNegative); |
| 63 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::fro
mInterpolableValue(*shadow->get(3), RangeAll); | 63 RefPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::fromInterpolabl
eValue(*shadow->get(3), RangeAll); |
| 64 | 64 |
| 65 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter
polableValueToColor(*shadow->get(4)); | 65 RefPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::interpolableValue
ToColor(*shadow->get(4)); |
| 66 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi
tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier
(CSSValueNone); | 66 RefPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimitiveValue::c
reateIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier(CSSValueNon
e); |
| 67 | 67 |
| 68 RefPtrWillBeRawPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blu
r, spread, style, color); | 68 RefPtr<CSSShadowValue> result = CSSShadowValue::create(x, y, blur, spread, s
tyle, color); |
| 69 return result.release(); | 69 return result.release(); |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) | 72 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) |
| 73 { | 73 { |
| 74 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { | 74 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { |
| 75 const CSSValueList* startList = toCSSValueList(&start); | 75 const CSSValueList* startList = toCSSValueList(&start); |
| 76 const CSSValueList* endList = toCSSValueList(&end); | 76 const CSSValueList* endList = toCSSValueList(&end); |
| 77 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { | 77 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| 78 if (startList->item(i)->isShadowValue() && endList->item(i)->isShado
wValue() | 78 if (startList->item(i)->isShadowValue() && endList->item(i)->isShado
wValue() |
| 79 && toCSSShadowValue(startList->item(i))->style != toCSSShadowVal
ue(endList->item(i))->style) | 79 && toCSSShadowValue(startList->item(i))->style != toCSSShadowVal
ue(endList->item(i))->style) |
| 80 return true; | 80 return true; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace blink | 86 } // namespace blink |
| OLD | NEW |