Chromium Code Reviews| Index: Source/core/animation/LengthStyleInterpolation.cpp |
| diff --git a/Source/core/animation/LengthStyleInterpolation.cpp b/Source/core/animation/LengthStyleInterpolation.cpp |
| index 8d4996ed1979ebe80e13873e416c5ce50defcf8e..cfeee51a9be723c933a5c1cf775332201edacbda 100644 |
| --- a/Source/core/animation/LengthStyleInterpolation.cpp |
| +++ b/Source/core/animation/LengthStyleInterpolation.cpp |
| @@ -26,18 +26,29 @@ bool LengthStyleInterpolation::canCreateFrom(const CSSValue& value) |
| PassOwnPtrWillBeRawPtr<InterpolableValue> LengthStyleInterpolation::lengthToInterpolableValue(const CSSValue& value) |
| { |
| - OwnPtrWillBeRawPtr<InterpolableList> result = InterpolableList::create(CSSPrimitiveValue::LengthUnitTypeCount); |
| + OwnPtrWillBeRawPtr<InterpolableList> listOfValuesAndTypes = InterpolableList::create(2); |
| + OwnPtrWillBeRawPtr<InterpolableList> listOfValues = InterpolableList::create(CSSPrimitiveValue::LengthUnitTypeCount); |
| + OwnPtrWillBeRawPtr<InterpolableList> listOfTypes = InterpolableList::create(CSSPrimitiveValue::LengthUnitTypeCount); |
| + |
| const CSSPrimitiveValue& primitive = toCSSPrimitiveValue(value); |
| - CSSLengthArray array; |
| - for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) |
| - array.append(0); |
| - primitive.accumulateLengthArray(array); |
| + CSSLengthArray arrayOfValues; |
| + CSSLengthTypeArray arrayOfTypes; |
| + for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
| + arrayOfValues.append(0); |
| + } |
|
samli
2014/12/22 03:38:04
Remove braces for single line loop
evemj (not active)
2014/12/22 06:09:05
Done.
|
| + arrayOfTypes.ensureSize(CSSPrimitiveValue::LengthUnitTypeCount); |
| + primitive.accumulateLengthArray(arrayOfValues, arrayOfTypes); |
| - for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) |
| - result->set(i, InterpolableNumber::create(array.at(i))); |
| + for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
| + listOfValues->set(i, InterpolableNumber::create(arrayOfValues.at(i))); |
| + listOfTypes->set(i, InterpolableNumber::create(arrayOfTypes.get(i))); |
| + } |
| + |
| + listOfValuesAndTypes->set(0, listOfValues.release()); |
| + listOfValuesAndTypes->set(1, listOfTypes.release()); |
| - return result.release(); |
| + return listOfValuesAndTypes.release(); |
| } |
| namespace { |
| @@ -49,14 +60,17 @@ static CSSPrimitiveValue::UnitType toUnitType(int lengthUnitType) |
| static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> constructCalcExpression(PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> previous, const InterpolableList* list, size_t position) |
| { |
| + const InterpolableList* listOfValues = toInterpolableList(list->get(0)); |
| + const InterpolableList* listOfTypes = toInterpolableList(list->get(1)); |
| while (position != CSSPrimitiveValue::LengthUnitTypeCount) { |
| - const InterpolableNumber *subValue = toInterpolableNumber(list->get(position)); |
| - if (subValue->value()) { |
| + const InterpolableNumber *subValueType = toInterpolableNumber(listOfTypes->get(position)); |
| + if (subValueType->value()) { |
| RefPtrWillBeRawPtr<CSSCalcExpressionNode> next; |
| + double value = toInterpolableNumber(listOfValues->get(position))->value(); |
| if (previous) |
| - next = CSSCalcValue::createExpressionNode(previous, CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(subValue->value(), toUnitType(position))), CalcAdd); |
| + next = CSSCalcValue::createExpressionNode(previous, CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, toUnitType(position))), CalcAdd); |
| else |
| - next = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(subValue->value(), toUnitType(position))); |
| + next = CSSCalcValue::createExpressionNode(CSSPrimitiveValue::create(value, toUnitType(position))); |
| return constructCalcExpression(next, list, position + 1); |
| } |
| position++; |
| @@ -68,23 +82,25 @@ static PassRefPtrWillBeRawPtr<CSSCalcExpressionNode> constructCalcExpression(Pas |
| PassRefPtrWillBeRawPtr<CSSValue> LengthStyleInterpolation::interpolableValueToLength(const InterpolableValue* value, ValueRange range) |
| { |
| - const InterpolableList* listValue = toInterpolableList(value); |
| - unsigned unitCount = 0; |
| + const InterpolableList* listOfValuesAndTypes = toInterpolableList(value); |
| + const InterpolableList* listOfValues = toInterpolableList(listOfValuesAndTypes->get(0)); |
| + const InterpolableList* listOfTypes = toInterpolableList(listOfValuesAndTypes->get(1)); |
| + unsigned unitTypeCount = 0; |
| for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
| - const InterpolableNumber* subValue = toInterpolableNumber(listValue->get(i)); |
| - if (subValue->value()) { |
| - unitCount++; |
| + const InterpolableNumber* subType = toInterpolableNumber(listOfTypes->get(i)); |
| + if (subType->value()) { |
| + unitTypeCount++; |
| } |
| } |
| - switch (unitCount) { |
| + switch (unitTypeCount) { |
| case 0: |
| - return CSSPrimitiveValue::create(0, CSSPrimitiveValue::CSS_PX); |
| + ASSERT_NOT_REACHED(); |
| case 1: |
| for (size_t i = 0; i < CSSPrimitiveValue::LengthUnitTypeCount; i++) { |
| - const InterpolableNumber* subValue = toInterpolableNumber(listValue->get(i)); |
| - double value = subValue->value(); |
| - if (value) { |
| + const InterpolableNumber *subValueType = toInterpolableNumber(listOfTypes->get(i)); |
| + if (subValueType->value()) { |
| + double value = toInterpolableNumber(listOfValues->get(i))->value(); |
| if (range == ValueRangeNonNegative && value < 0) |
| value = 0; |
| return CSSPrimitiveValue::create(value, toUnitType(i)); |
| @@ -92,7 +108,7 @@ PassRefPtrWillBeRawPtr<CSSValue> LengthStyleInterpolation::interpolableValueToLe |
| } |
| ASSERT_NOT_REACHED(); |
| default: |
| - return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpression(nullptr, listValue, 0), range)); |
| + return CSSPrimitiveValue::create(CSSCalcValue::create(constructCalcExpression(nullptr, listOfValuesAndTypes, 0), range)); |
| } |
| } |