Chromium Code Reviews| 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/SVGLengthStyleInterpolation.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, const Vector<CSSPrimitiveValue::UnitType>& types) | 28 PassRefPtrWillBeRawPtr<CSSValueList> SVGStrokeDasharrayStyleInterpolation::inter polableValueToStrokeDasharray(const InterpolableValue& interpolableValue) |
| 29 { | 29 { |
| 30 const InterpolableList& interpolableList = toInterpolableList(interpolableVa lue); | 30 const InterpolableList& interpolableList = toInterpolableList(interpolableVa lue); |
| 31 ASSERT(types.size() == interpolableList.length()); | |
| 32 | 31 |
| 33 RefPtrWillBeRawPtr<CSSValueList> ret = CSSValueList::createCommaSeparated(); | 32 RefPtrWillBeRawPtr<CSSValueList> ret = CSSValueList::createCommaSeparated(); |
| 34 for (size_t index = 0; index < interpolableList.length(); ++index) { | 33 for (size_t index = 0; index < interpolableList.length(); ++index) |
| 35 ret->append(SVGLengthStyleInterpolation::interpolableValueToLength(*inte rpolableList.get(index), types.at(index), RangeNonNegative)); | 34 ret->append(LengthStyleInterpolation::fromInterpolableValue(*interpolabl eList.get(index), RangeNonNegative)); |
| 36 } | |
| 37 return ret.release(); | 35 return ret.release(); |
| 38 } | 36 } |
| 39 | 37 |
| 40 bool SVGStrokeDasharrayStyleInterpolation::canCreateFrom(const CSSValue& value) | 38 bool SVGStrokeDasharrayStyleInterpolation::canCreateFrom(const CSSValue& value) |
| 41 { | 39 { |
| 42 if (!value.isValueList()) | 40 if (!value.isValueList()) |
| 43 return isNone(value); | 41 return isNone(value); |
| 44 const CSSValueList& valueList = toCSSValueList(value); | 42 const CSSValueList& valueList = toCSSValueList(value); |
| 45 | 43 |
| 46 for (size_t index = 0; index < valueList.length(); ++index) { | 44 for (size_t index = 0; index < valueList.length(); ++index) { |
| 47 if (!SVGLengthStyleInterpolation::canCreateFrom(*valueList.item(index))) | 45 if (!LengthStyleInterpolation::canCreateFrom(*valueList.item(index))) |
| 48 return false; | 46 return false; |
| 49 } | 47 } |
| 50 return true; | 48 return true; |
| 51 } | 49 } |
| 52 | 50 |
| 53 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) |
| 54 { | 52 { |
| 55 if (!canCreateFrom(start) || !canCreateFrom(end)) | 53 if (!canCreateFrom(start) || !canCreateFrom(end)) |
| 56 return nullptr; | 54 return nullptr; |
| 57 | 55 |
| 58 RefPtrWillBeRawPtr<CSSValueList> singleZero = CSSValueList::createCommaSepar ated(); | 56 RefPtrWillBeRawPtr<CSSValueList> singleZero = CSSValueList::createCommaSepar ated(); |
| 59 singleZero->append(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); | 57 singleZero->append(CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX)); |
| 60 | 58 |
| 61 const CSSValueList& valueListStart = start.isValueList() ? toCSSValueList(st art) : *singleZero; | 59 const CSSValueList& valueListStart = start.isValueList() ? toCSSValueList(st art) : *singleZero; |
| 62 const CSSValueList& valueListEnd = end.isValueList() ? toCSSValueList(end) : *singleZero; | 60 const CSSValueList& valueListEnd = end.isValueList() ? toCSSValueList(end) : *singleZero; |
| 63 size_t size = lowestCommonMultiple(valueListStart.length(), valueListEnd.len gth()); | 61 size_t size = lowestCommonMultiple(valueListStart.length(), valueListEnd.len gth()); |
| 64 ASSERT(size > 0); | 62 ASSERT(size > 0); |
| 65 | 63 |
| 66 Vector<CSSPrimitiveValue::UnitType> types(size); | |
| 67 OwnPtrWillBeRawPtr<InterpolableList> interpolableStart = InterpolableList::c reate(size); | 64 OwnPtrWillBeRawPtr<InterpolableList> interpolableStart = InterpolableList::c reate(size); |
| 68 OwnPtrWillBeRawPtr<InterpolableList> interpolableEnd = InterpolableList::cre ate(size); | 65 OwnPtrWillBeRawPtr<InterpolableList> interpolableEnd = InterpolableList::cre ate(size); |
| 69 | 66 |
| 70 for (size_t i = 0; i < size; ++i) { | 67 for (size_t i = 0; i < size; ++i) { |
| 71 const CSSPrimitiveValue& from = *toCSSPrimitiveValue(valueListStart.item (i % valueListStart.length())); | 68 const CSSPrimitiveValue& from = *toCSSPrimitiveValue(valueListStart.item (i % valueListStart.length())); |
| 72 const CSSPrimitiveValue& to = *toCSSPrimitiveValue(valueListEnd.item(i % valueListEnd.length())); | 69 const CSSPrimitiveValue& to = *toCSSPrimitiveValue(valueListEnd.item(i % valueListEnd.length())); |
| 73 | 70 |
| 74 // Spec: If a pair of values cannot be interpolated, then the lists are not interpolable. | 71 interpolableStart->set(i, LengthStyleInterpolation::toInterpolableValue( from)); |
| 75 types[i] = SVGLengthStyleInterpolation::commonUnitType(from, to); | 72 interpolableEnd->set(i, LengthStyleInterpolation::toInterpolableValue(to )); |
| 76 if (types[i] == CSSPrimitiveValue::CSS_UNKNOWN) | |
|
pdr.
2015/03/03 21:08:22
Where did this check go?
Eric Willigers
2015/03/04 02:21:13
canCreateFrom calls have already ensured we have t
| |
| 77 return nullptr; | |
| 78 interpolableStart->set(i, SVGLengthStyleInterpolation::lengthToInterpola bleValue(from)); | |
| 79 interpolableEnd->set(i, SVGLengthStyleInterpolation::lengthToInterpolabl eValue(to)); | |
| 80 } | 73 } |
| 81 return adoptRefWillBeNoop(new SVGStrokeDasharrayStyleInterpolation(interpola bleStart.release(), interpolableEnd.release(), id, types)); | 74 return adoptRefWillBeNoop(new SVGStrokeDasharrayStyleInterpolation(interpola bleStart.release(), interpolableEnd.release(), id)); |
| 82 } | 75 } |
| 83 | 76 |
| 84 void SVGStrokeDasharrayStyleInterpolation::apply(StyleResolverState& state) cons t | 77 void SVGStrokeDasharrayStyleInterpolation::apply(StyleResolverState& state) cons t |
| 85 { | 78 { |
| 86 StyleBuilder::applyProperty(m_id, state, interpolableValueToStrokeDasharray( *m_cachedValue, m_types).get()); | 79 StyleBuilder::applyProperty(m_id, state, interpolableValueToStrokeDasharray( *m_cachedValue).get()); |
| 87 } | 80 } |
| 88 | 81 |
| 89 } | 82 } |
| OLD | NEW |