| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/SVGStrokeDasharrayStyleInterpolation.h" | 6 #include "core/animation/SVGStrokeDasharrayStyleInterpolation.h" |
| 7 | 7 |
| 8 #include "core/animation/LengthStyleInterpolation.h" | 8 #include "core/animation/LengthStyleInterpolation.h" |
| 9 #include "core/css/CSSValueList.h" | 9 #include "core/css/CSSValueList.h" |
| 10 #include "core/css/resolver/StyleBuilder.h" | 10 #include "core/css/resolver/StyleBuilder.h" |
| 11 | 11 |
| 12 #include "wtf/MathExtras.h" | 12 #include "wtf/MathExtras.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 bool isNone(const CSSValue& value) | 18 bool isNone(const CSSValue& value) |
| 19 { | 19 { |
| 20 if (!value.isPrimitiveValue()) | 20 if (!value.isPrimitiveValue()) |
| 21 return false; | 21 return false; |
| 22 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); | 22 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 23 return primitiveValue.isValueID() && primitiveValue.getValueID() == CSSValue
None; | 23 return primitiveValue.isValueID() && primitiveValue.getValueID() == CSSValue
None; |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace | 26 } // namespace |
| 27 | 27 |
| 28 PassRefPtrWillBeRawPtr<CSSValueList> SVGStrokeDasharrayStyleInterpolation::inter
polableValueToStrokeDasharray(const InterpolableValue& interpolableValue) | 28 PassRefPtr<CSSValueList> SVGStrokeDasharrayStyleInterpolation::interpolableValue
ToStrokeDasharray(const InterpolableValue& interpolableValue) |
| 29 { | 29 { |
| 30 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); | 30 const InterpolableList& interpolableList = toInterpolableList(interpolableVa
lue); |
| 31 | 31 |
| 32 RefPtrWillBeRawPtr<CSSValueList> ret = CSSValueList::createCommaSeparated(); | 32 RefPtr<CSSValueList> ret = CSSValueList::createCommaSeparated(); |
| 33 for (size_t index = 0; index < interpolableList.length(); ++index) | 33 for (size_t index = 0; index < interpolableList.length(); ++index) |
| 34 ret->append(LengthStyleInterpolation::fromInterpolableValue(*interpolabl
eList.get(index), RangeNonNegative)); | 34 ret->append(LengthStyleInterpolation::fromInterpolableValue(*interpolabl
eList.get(index), RangeNonNegative)); |
| 35 return ret.release(); | 35 return ret.release(); |
| 36 } | 36 } |
| 37 | 37 |
| 38 bool SVGStrokeDasharrayStyleInterpolation::canCreateFrom(const CSSValue& value) | 38 bool SVGStrokeDasharrayStyleInterpolation::canCreateFrom(const CSSValue& value) |
| 39 { | 39 { |
| 40 if (!value.isValueList()) | 40 if (!value.isValueList()) |
| 41 return isNone(value); | 41 return isNone(value); |
| 42 const CSSValueList& valueList = toCSSValueList(value); | 42 const CSSValueList& valueList = toCSSValueList(value); |
| 43 | 43 |
| 44 for (size_t index = 0; index < valueList.length(); ++index) { | 44 for (size_t index = 0; index < valueList.length(); ++index) { |
| 45 if (!LengthStyleInterpolation::canCreateFrom(*valueList.item(index))) | 45 if (!LengthStyleInterpolation::canCreateFrom(*valueList.item(index))) |
| 46 return false; | 46 return false; |
| 47 } | 47 } |
| 48 return true; | 48 return true; |
| 49 } | 49 } |
| 50 | 50 |
| 51 PassRefPtrWillBeRawPtr<SVGStrokeDasharrayStyleInterpolation> SVGStrokeDasharrayS
tyleInterpolation::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPr
opertyID id) | 51 PassRefPtrWillBeRawPtr<SVGStrokeDasharrayStyleInterpolation> SVGStrokeDasharrayS
tyleInterpolation::maybeCreate(const CSSValue& start, const CSSValue& end, CSSPr
opertyID id) |
| 52 { | 52 { |
| 53 if (!canCreateFrom(start) || !canCreateFrom(end)) | 53 if (!canCreateFrom(start) || !canCreateFrom(end)) |
| 54 return nullptr; | 54 return nullptr; |
| 55 | 55 |
| 56 RefPtrWillBeRawPtr<CSSValueList> singleZero = CSSValueList::createCommaSepar
ated(); | 56 RefPtr<CSSValueList> singleZero = CSSValueList::createCommaSeparated(); |
| 57 singleZero->append(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType:
:Pixels)); | 57 singleZero->append(CSSPrimitiveValue::create(0, CSSPrimitiveValue::UnitType:
:Pixels)); |
| 58 | 58 |
| 59 const CSSValueList& valueListStart = start.isValueList() ? toCSSValueList(st
art) : *singleZero; | 59 const CSSValueList& valueListStart = start.isValueList() ? toCSSValueList(st
art) : *singleZero; |
| 60 const CSSValueList& valueListEnd = end.isValueList() ? toCSSValueList(end) :
*singleZero; | 60 const CSSValueList& valueListEnd = end.isValueList() ? toCSSValueList(end) :
*singleZero; |
| 61 size_t size = lowestCommonMultiple(valueListStart.length(), valueListEnd.len
gth()); | 61 size_t size = lowestCommonMultiple(valueListStart.length(), valueListEnd.len
gth()); |
| 62 ASSERT(size > 0); | 62 ASSERT(size > 0); |
| 63 | 63 |
| 64 OwnPtrWillBeRawPtr<InterpolableList> interpolableStart = InterpolableList::c
reate(size); | 64 OwnPtrWillBeRawPtr<InterpolableList> interpolableStart = InterpolableList::c
reate(size); |
| 65 OwnPtrWillBeRawPtr<InterpolableList> interpolableEnd = InterpolableList::cre
ate(size); | 65 OwnPtrWillBeRawPtr<InterpolableList> interpolableEnd = InterpolableList::cre
ate(size); |
| 66 | 66 |
| 67 for (size_t i = 0; i < size; ++i) { | 67 for (size_t i = 0; i < size; ++i) { |
| 68 const CSSPrimitiveValue& from = *toCSSPrimitiveValue(valueListStart.item
(i % valueListStart.length())); | 68 const CSSPrimitiveValue& from = *toCSSPrimitiveValue(valueListStart.item
(i % valueListStart.length())); |
| 69 const CSSPrimitiveValue& to = *toCSSPrimitiveValue(valueListEnd.item(i %
valueListEnd.length())); | 69 const CSSPrimitiveValue& to = *toCSSPrimitiveValue(valueListEnd.item(i %
valueListEnd.length())); |
| 70 | 70 |
| 71 interpolableStart->set(i, LengthStyleInterpolation::toInterpolableValue(
from)); | 71 interpolableStart->set(i, LengthStyleInterpolation::toInterpolableValue(
from)); |
| 72 interpolableEnd->set(i, LengthStyleInterpolation::toInterpolableValue(to
)); | 72 interpolableEnd->set(i, LengthStyleInterpolation::toInterpolableValue(to
)); |
| 73 } | 73 } |
| 74 return adoptRefWillBeNoop(new SVGStrokeDasharrayStyleInterpolation(interpola
bleStart.release(), interpolableEnd.release(), id)); | 74 return adoptRefWillBeNoop(new SVGStrokeDasharrayStyleInterpolation(interpola
bleStart.release(), interpolableEnd.release(), id)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void SVGStrokeDasharrayStyleInterpolation::apply(StyleResolverState& state) cons
t | 77 void SVGStrokeDasharrayStyleInterpolation::apply(StyleResolverState& state) cons
t |
| 78 { | 78 { |
| 79 StyleBuilder::applyProperty(m_id, state, interpolableValueToStrokeDasharray(
*m_cachedValue).get()); | 79 StyleBuilder::applyProperty(m_id, state, interpolableValueToStrokeDasharray(
*m_cachedValue).get()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 } | 82 } |
| OLD | NEW |