| 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 return start.isShadowValue() && end.isShadowValue() | 19 return start.isShadowValue() && end.isShadowValue() |
| 20 && toCSSShadowValue(start).style == toCSSShadowValue(end).style | 20 && toCSSShadowValue(start).style == toCSSShadowValue(end).style |
| 21 && toCSSShadowValue(start).color && toCSSShadowValue(end).color; | 21 && toCSSShadowValue(start).color && toCSSShadowValue(end).color; |
| 22 } | 22 } |
| 23 | 23 |
| 24 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::lengthToInte
rpolableValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value) | 24 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::lengthToInte
rpolableValue(PassRefPtrWillBeRawPtr<CSSPrimitiveValue> value) |
| 25 { | 25 { |
| 26 if (value) | 26 if (value) |
| 27 return LengthStyleInterpolation::toInterpolableValue(*value); | 27 return LengthStyleInterpolation::toInterpolableValue(value); |
| 28 return LengthStyleInterpolation::toInterpolableValue(*CSSPrimitiveValue::cre
ate(0, CSSPrimitiveValue::CSS_PX)); | 28 return LengthStyleInterpolation::toInterpolableValue(CSSPrimitiveValue::crea
te(0, CSSPrimitiveValue::CSS_PX)); |
| 29 } | 29 } |
| 30 | 30 |
| 31 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab
leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) | 31 PassOwnPtrWillBeRawPtr<InterpolableValue> ShadowStyleInterpolation::toInterpolab
leValue(const CSSValue& value, NonInterpolableType& nonInterpolableData) |
| 32 { | 32 { |
| 33 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); | 33 OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(5); |
| 34 const CSSShadowValue* shadowValue = toCSSShadowValue(&value); | 34 const CSSShadowValue& shadowValue = toCSSShadowValue(value); |
| 35 ASSERT(shadowValue); | |
| 36 | 35 |
| 37 result->set(0, lengthToInterpolableValue(shadowValue->x)); | 36 result->set(0, lengthToInterpolableValue(shadowValue.x)); |
| 38 result->set(1, lengthToInterpolableValue(shadowValue->y)); | 37 result->set(1, lengthToInterpolableValue(shadowValue.y)); |
| 39 result->set(2, lengthToInterpolableValue(shadowValue->blur)); | 38 result->set(2, lengthToInterpolableValue(shadowValue.blur)); |
| 40 result->set(3, lengthToInterpolableValue(shadowValue->spread)); | 39 result->set(3, lengthToInterpolableValue(shadowValue.spread)); |
| 41 | 40 |
| 42 if (shadowValue->color && ColorStyleInterpolation::canCreateFrom(*shadowValu
e->color)) | 41 if (shadowValue.color && ColorStyleInterpolation::canCreateFrom(CSSValue(*sh
adowValue.color.get()))) |
| 43 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(*shadow
Value->color)); | 42 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(CSSValu
e(*shadowValue.color.get()))); |
| 44 | 43 |
| 45 if (shadowValue->style) | 44 if (shadowValue.style) |
| 46 nonInterpolableData = (shadowValue->style->getValueID() == CSSValueInset
); | 45 nonInterpolableData = (shadowValue.style->getValueID() == CSSValueInset)
; |
| 47 else | 46 else |
| 48 nonInterpolableData = false; | 47 nonInterpolableData = false; |
| 49 | 48 |
| 50 return result.release(); | 49 return result.release(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 PassRefPtrWillBeRawPtr<CSSValue> ShadowStyleInterpolation::fromInterpolableValue
(const InterpolableValue& value, NonInterpolableType nonInterpolableData, Interp
olationRange range) | 52 CSSValue ShadowStyleInterpolation::fromInterpolableValue(const InterpolableValue
& value, NonInterpolableType nonInterpolableData, InterpolationRange range) |
| 54 { | 53 { |
| 55 const InterpolableList* shadow = toInterpolableList(&value); | 54 const InterpolableList* shadow = toInterpolableList(&value); |
| 56 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(0), RangeAll); | 55 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(0), RangeAll); |
| 57 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(1), RangeAll); | 56 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(1), RangeAll); |
| 58 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::fromI
nterpolableValue(*shadow->get(2), RangeNonNegative); | 57 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::fromI
nterpolableValue(*shadow->get(2), RangeNonNegative); |
| 59 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::fro
mInterpolableValue(*shadow->get(3), RangeAll); | 58 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::fro
mInterpolableValue(*shadow->get(3), RangeAll); |
| 60 | 59 |
| 61 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter
polableValueToColor(*shadow->get(4)); | 60 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter
polableValueToColor(*shadow->get(4)); |
| 62 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi
tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier
(CSSValueNone); | 61 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi
tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier
(CSSValueNone); |
| 63 | 62 |
| 64 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); |
| 65 return result.release(); | 64 return result.release(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) | 67 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) |
| 69 { | 68 { |
| 70 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { | 69 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { |
| 71 const CSSValueList* startList = toCSSValueList(&start); | 70 const CSSValueList& startList = toCSSValueList(start); |
| 72 const CSSValueList* endList = toCSSValueList(&end); | 71 const CSSValueList& endList = toCSSValueList(end); |
| 73 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { | 72 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| 74 if (startList->item(i)->isShadowValue() && endList->item(i)->isShado
wValue() | 73 if (startList.item(i).isShadowValue() && endList.item(i).isShadowVal
ue() |
| 75 && toCSSShadowValue(startList->item(i))->style != toCSSShadowVal
ue(endList->item(i))->style) | 74 && toCSSShadowValue(startList.item(i)).style != toCSSShadowValue
(endList.item(i)).style) |
| 76 return true; | 75 return true; |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 return false; | 78 return false; |
| 80 } | 79 } |
| 81 | 80 |
| 82 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |