Bug 1293743 - Part 1: Move nsCSSParser's ReduceNumberCalcOps to CSSCalc.h as mozilla::css::ReduceNumberCalcOps. r=dholbert

Bug 1273706 (Properties & Values) uses ReduceNumberCalcOps in nsRuleNode to
compute <number>-typed calc() expressions.

MozReview-Commit-ID: CsZkJBFOufm

--HG--
extra : rebase_source : 257bb56aa2c87f00ae809ee8e674d125c6112a73
This commit is contained in:
Jonathan Chan 2016-10-17 20:49:15 -04:00
parent ac3c4c3eac
commit b746c93c2a
2 changed files with 23 additions and 17 deletions

View File

@ -354,6 +354,27 @@ SerializeCalcInternal(const typename CalcOps::input_type& aValue, CalcOps &aOps)
}
}
/**
* ReduceNumberCalcOps is a CalcOps implementation for pure-number calc()
* (sub-)expressions, input as nsCSSValues.
* For example, nsCSSParser::ParseCalcMultiplicativeExpression uses it to
* simplify numeric sub-expressions in order to check for division-by-zero.
*/
struct ReduceNumberCalcOps : public mozilla::css::BasicFloatCalcOps,
public mozilla::css::CSSValueInputCalcOps
{
result_type ComputeLeafValue(const nsCSSValue& aValue)
{
MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
return aValue.GetFloatValue();
}
float ComputeNumber(const nsCSSValue& aValue)
{
return mozilla::css::ComputeCalc(aValue, *this);
}
};
} // namespace css
} // namespace mozilla

View File

@ -13708,21 +13708,6 @@ CSSParserImpl::ParseCalcAdditiveExpression(nsCSSValue& aValue,
}
}
struct ReduceNumberCalcOps : public mozilla::css::BasicFloatCalcOps,
public mozilla::css::CSSValueInputCalcOps
{
result_type ComputeLeafValue(const nsCSSValue& aValue)
{
MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
return aValue.GetFloatValue();
}
float ComputeNumber(const nsCSSValue& aValue)
{
return mozilla::css::ComputeCalc(aValue, *this);
}
};
// * If aVariantMask is VARIANT_NUMBER, this function parses the
// <number-multiplicative-expression> production.
// * If aVariantMask does not contain VARIANT_NUMBER, this function
@ -13764,7 +13749,7 @@ CSSParserImpl::ParseCalcMultiplicativeExpression(nsCSSValue& aValue,
if (variantMask & VARIANT_NUMBER) {
// Simplify the value immediately so we can check for division by
// zero.
ReduceNumberCalcOps ops;
mozilla::css::ReduceNumberCalcOps ops;
float number = mozilla::css::ComputeCalc(*storage, ops);
if (number == 0.0 && afterDivision)
return false;
@ -13778,7 +13763,7 @@ CSSParserImpl::ParseCalcMultiplicativeExpression(nsCSSValue& aValue,
MOZ_ASSERT(storage == &aValue.GetArrayValue()->Item(1),
"unexpected relationship to current storage");
nsCSSValue &leftValue = aValue.GetArrayValue()->Item(0);
ReduceNumberCalcOps ops;
mozilla::css::ReduceNumberCalcOps ops;
float number = mozilla::css::ComputeCalc(leftValue, ops);
leftValue.SetFloatValue(number, eCSSUnit_Number);
}