Chromium Code Reviews| Index: Source/core/css/CSSCalculationValue.cpp |
| diff --git a/Source/core/css/CSSCalculationValue.cpp b/Source/core/css/CSSCalculationValue.cpp |
| index 79de5eb33bf8ee142bfad3958a9777d28b560c61..f45b3850cd14a32b87636b63ef4107d17bab0c98 100644 |
| --- a/Source/core/css/CSSCalculationValue.cpp |
| +++ b/Source/core/css/CSSCalculationValue.cpp |
| @@ -70,8 +70,17 @@ static CalculationCategory unitCategory(CSSPrimitiveValue::UnitType type) |
| case CSSPrimitiveValue::CSS_VMIN: |
| case CSSPrimitiveValue::CSS_VMAX: |
| return CalcLength; |
| - // FIXME: Support angle, time and frequency units. |
| - // http://www.w3.org/TR/css3-values/#calc-notation |
| + case CSSPrimitiveValue::CSS_DEG: |
| + case CSSPrimitiveValue::CSS_GRAD: |
| + case CSSPrimitiveValue::CSS_RAD: |
| + case CSSPrimitiveValue::CSS_TURN: |
| + return CalcAngle; |
| + case CSSPrimitiveValue::CSS_MS: |
| + case CSSPrimitiveValue::CSS_S: |
| + return CalcTime; |
| + case CSSPrimitiveValue::CSS_HZ: |
| + case CSSPrimitiveValue::CSS_KHZ: |
| + return CalcFrequency; |
| default: |
| return CalcOther; |
| } |
| @@ -232,11 +241,14 @@ public: |
| switch (m_category) { |
| case CalcLength: |
| return m_value->computeLength<double>(conversionData); |
| - case CalcPercent: |
| case CalcNumber: |
| + case CalcPercent: |
| return m_value->getDoubleValue(); |
| + case CalcAngle: |
| + case CalcFrequency: |
| case CalcPercentLength: |
| case CalcPercentNumber: |
| + case CalcTime: |
| case CalcOther: |
| ASSERT_NOT_REACHED(); |
| break; |
| @@ -282,7 +294,7 @@ private: |
| RefPtrWillBeMember<CSSPrimitiveValue> m_value; |
| }; |
| -static const CalculationCategory addSubtractResult[CalcOther][CalcOther] = { |
| +static const CalculationCategory addSubtractResult[CalcAngle][CalcAngle] = { |
|
alancutter (OOO until 2018)
2014/07/02 05:56:10
It's probably better to use CalcPercentLength + 1
|
| // CalcNumber CalcLength CalcPercent CalcPercentNumber CalcPercentLength |
| /* CalcNumber */ { CalcNumber, CalcOther, CalcPercentNumber, CalcPercentNumber, CalcOther }, |
| /* CalcLength */ { CalcOther, CalcLength, CalcPercentLength, CalcOther, CalcPercentLength }, |
| @@ -302,7 +314,11 @@ static CalculationCategory determineCategory(const CSSCalcExpressionNode& leftSi |
| switch (op) { |
| case CalcAdd: |
| case CalcSubtract: |
| - return addSubtractResult[leftCategory][rightCategory]; |
| + if (leftCategory < CalcAngle || rightCategory < CalcAngle) |
|
alancutter (OOO until 2018)
2014/07/02 05:56:10
<= CalcPercentLength
|
| + return addSubtractResult[leftCategory][rightCategory]; |
| + if (leftCategory == rightCategory) |
| + return leftCategory; |
| + return CalcOther; |
| case CalcMultiply: |
| if (leftCategory != CalcNumber && rightCategory != CalcNumber) |
| return CalcOther; |
| @@ -517,6 +533,12 @@ public: |
| return leftType; |
| return CSSPrimitiveValue::CSS_UNKNOWN; |
| } |
| + case CalcAngle: |
| + return CSSPrimitiveValue::CSS_DEG; |
| + case CalcTime: |
| + return CSSPrimitiveValue::CSS_MS; |
| + case CalcFrequency: |
| + return CSSPrimitiveValue::CSS_HZ; |
| case CalcPercentLength: |
| case CalcPercentNumber: |
| case CalcOther: |
| @@ -630,11 +652,7 @@ private: |
| if (!value || !value->isPrimitiveValue()) |
| return false; |
| - CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value.get()); |
| - if (unitCategory(primitiveValue->primitiveType()) == CalcOther) |
| - return false; |
| - |
| - result->value = CSSCalcPrimitiveValue::create(primitiveValue, parserValue->isInt); |
| + result->value = CSSCalcPrimitiveValue::create(toCSSPrimitiveValue(value.get()), parserValue->isInt); |
| ++*index; |
| return true; |