| 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(NullableCSSValue value) |
| 25 { | 25 { |
| 26 if (value) | 26 if (value) |
| 27 return LengthStyleInterpolation::toInterpolableValue(value); | 27 return LengthStyleInterpolation::toInterpolableValue(*value); |
| 28 return LengthStyleInterpolation::toInterpolableValue(CSSPrimitiveValue::crea
te(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 | 35 |
| 36 result->set(0, lengthToInterpolableValue(shadowValue.x)); | 36 result->set(0, lengthToInterpolableValue(shadowValue.x)); |
| 37 result->set(1, lengthToInterpolableValue(shadowValue.y)); | 37 result->set(1, lengthToInterpolableValue(shadowValue.y)); |
| 38 result->set(2, lengthToInterpolableValue(shadowValue.blur)); | 38 result->set(2, lengthToInterpolableValue(shadowValue.blur)); |
| 39 result->set(3, lengthToInterpolableValue(shadowValue.spread)); | 39 result->set(3, lengthToInterpolableValue(shadowValue.spread)); |
| 40 | 40 |
| 41 if (shadowValue.color && ColorStyleInterpolation::canCreateFrom(CSSValue(*sh
adowValue.color.get()))) | 41 if (shadowValue.color && ColorStyleInterpolation::canCreateFrom(CSSValue(*sh
adowValue.color.get()))) |
| 42 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(CSSValu
e(*shadowValue.color.get()))); | 42 result->set(4, ColorStyleInterpolation::colorToInterpolableValue(CSSValu
e(*shadowValue.color.get()))); |
| 43 | 43 |
| 44 if (shadowValue.style) | 44 if (shadowValue.style) |
| 45 nonInterpolableData = (shadowValue.style->getValueID() == CSSValueInset)
; | 45 nonInterpolableData = (toCSSPrimitiveValue(*shadowValue.style).getValueI
D() == CSSValueInset); |
| 46 else | 46 else |
| 47 nonInterpolableData = false; | 47 nonInterpolableData = false; |
| 48 | 48 |
| 49 return result.release(); | 49 return result.release(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 CSSValue ShadowStyleInterpolation::fromInterpolableValue(const InterpolableValue
& value, NonInterpolableType nonInterpolableData, InterpolationRange range) | 52 CSSValue ShadowStyleInterpolation::fromInterpolableValue(const InterpolableValue
& value, NonInterpolableType nonInterpolableData, InterpolationRange range) |
| 53 { | 53 { |
| 54 const InterpolableList* shadow = toInterpolableList(&value); | 54 const InterpolableList* shadow = toInterpolableList(&value); |
| 55 RefPtrWillBeRawPtr<CSSPrimitiveValue> x = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(0), RangeAll); | 55 CSSPrimitiveValue x = LengthStyleInterpolation::fromInterpolableValue(*shado
w->get(0), RangeAll); |
| 56 RefPtrWillBeRawPtr<CSSPrimitiveValue> y = LengthStyleInterpolation::fromInte
rpolableValue(*shadow->get(1), RangeAll); | 56 CSSPrimitiveValue y = LengthStyleInterpolation::fromInterpolableValue(*shado
w->get(1), RangeAll); |
| 57 RefPtrWillBeRawPtr<CSSPrimitiveValue> blur = LengthStyleInterpolation::fromI
nterpolableValue(*shadow->get(2), RangeNonNegative); | 57 CSSPrimitiveValue blur = LengthStyleInterpolation::fromInterpolableValue(*sh
adow->get(2), RangeNonNegative); |
| 58 RefPtrWillBeRawPtr<CSSPrimitiveValue> spread = LengthStyleInterpolation::fro
mInterpolableValue(*shadow->get(3), RangeAll); | 58 CSSPrimitiveValue spread = LengthStyleInterpolation::fromInterpolableValue(*
shadow->get(3), RangeAll); |
| 59 | 59 |
| 60 RefPtrWillBeRawPtr<CSSPrimitiveValue> color = ColorStyleInterpolation::inter
polableValueToColor(*shadow->get(4)); | 60 CSSPrimitiveValue color = ColorStyleInterpolation::interpolableValueToColor(
*shadow->get(4)); |
| 61 RefPtrWillBeRawPtr<CSSPrimitiveValue> style = nonInterpolableData ? CSSPrimi
tiveValue::createIdentifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier
(CSSValueNone); | 61 CSSPrimitiveValue style = nonInterpolableData ? CSSPrimitiveValue::createIde
ntifier(CSSValueInset) : CSSPrimitiveValue::createIdentifier(CSSValueNone); |
| 62 | 62 |
| 63 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); |
| 64 return result.release(); | 64 return result.release(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) | 67 bool ShadowStyleInterpolation::usesDefaultStyleInterpolation(const CSSValue& sta
rt, const CSSValue& end) |
| 68 { | 68 { |
| 69 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { | 69 if (start.isValueList() && end.isValueList() && toCSSValueList(start).length
() == toCSSValueList(end).length()) { |
| 70 const CSSValueList& startList = toCSSValueList(start); | 70 const CSSValueList& startList = toCSSValueList(start); |
| 71 const CSSValueList& endList = toCSSValueList(end); | 71 const CSSValueList& endList = toCSSValueList(end); |
| 72 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { | 72 for (size_t i = 0; i < toCSSValueList(start).length(); i++) { |
| 73 if (startList.item(i).isShadowValue() && endList.item(i).isShadowVal
ue() | 73 if (startList.item(i).isShadowValue() && endList.item(i).isShadowVal
ue() |
| 74 && toCSSShadowValue(startList.item(i)).style != toCSSShadowValue
(endList.item(i)).style) | 74 && toCSSShadowValue(startList.item(i)).style != toCSSShadowValue
(endList.item(i)).style) |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 | 80 |
| 81 } // namespace blink | 81 } // namespace blink |
| OLD | NEW |