Issue #1765 - Part 1: Move ReduceNumberCalcOps struct up higher, rename IsCSSTokenCalcFunction to CSSParserImpl::IsCalcFunctionToken

This commit is contained in:
FranklinDM 2023-05-13 14:50:12 +08:00 committed by roytam1
commit 73a6dc3122

View file

@ -137,6 +137,22 @@ struct CSSParserInputState {
bool mHavePushBack;
};
struct ReduceNumberCalcOps : public mozilla::css::BasicFloatCalcOps,
public mozilla::css::CSSValueInputCalcOps
{
result_type ComputeLeafValue(const nsCSSValue& aValue)
{
// FIXME: Restore this assertion once ParseColor no longer uses this class.
//MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
return aValue.GetFloatValue();
}
float ComputeNumber(const nsCSSValue& aValue)
{
return mozilla::css::ComputeCalc(aValue, *this);
}
};
static_assert(css::eAuthorSheetFeatures == 0 &&
css::eUserSheetFeatures == 1 &&
css::eAgentSheetFeatures == 2,
@ -896,6 +912,7 @@ protected:
};
bool IsFunctionTokenValidForImageLayerImage(const nsCSSToken& aToken) const;
bool IsCalcFunctionToken(const nsCSSToken& aToken) const;
bool ParseImageLayersItem(ImageLayersShorthandParseState& aState,
const nsCSSPropertyID aTable[]);
@ -7874,14 +7891,6 @@ CSSParserImpl::ParseOneOrLargerVariant(nsCSSValue& aValue,
return result;
}
static bool
IsCSSTokenCalcFunction(const nsCSSToken& aToken)
{
return aToken.mType == eCSSToken_Function &&
(aToken.mIdent.LowerCaseEqualsLiteral("calc") ||
aToken.mIdent.LowerCaseEqualsLiteral("-moz-calc"));
}
// Assigns to aValue iff it returns CSSParseResult::Ok.
CSSParseResult
CSSParserImpl::ParseVariant(nsCSSValue& aValue,
@ -8181,7 +8190,7 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue,
}
}
if ((aVariantMask & VARIANT_CALC) &&
IsCSSTokenCalcFunction(*tk)) {
IsCalcFunctionToken(*tk)) {
// calc() currently allows only lengths and percents and number inside it.
// And note that in current implementation, number cannot be mixed with
// length and percent.
@ -12430,6 +12439,14 @@ CSSParserImpl::IsFunctionTokenValidForImageLayerImage(
funcName.LowerCaseEqualsLiteral("-webkit-repeating-radial-gradient")));
}
bool
CSSParserImpl::IsCalcFunctionToken(const nsCSSToken& aToken) const
{
return aToken.mType == eCSSToken_Function &&
(aToken.mIdent.LowerCaseEqualsLiteral("calc") ||
aToken.mIdent.LowerCaseEqualsLiteral("-moz-calc"));
}
// Parse one item of the background shorthand property.
bool
CSSParserImpl::ParseImageLayersItem(
@ -13822,21 +13839,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
@ -13957,7 +13959,7 @@ CSSParserImpl::ParseCalcTerm(nsCSSValue& aValue, uint32_t& aVariantMask)
// Either an additive expression in parentheses...
if (mToken.IsSymbol('(') ||
// Treat nested calc() as plain parenthesis.
IsCSSTokenCalcFunction(mToken)) {
IsCalcFunctionToken(mToken)) {
if (!ParseCalcAdditiveExpression(aValue, aVariantMask) ||
!ExpectSymbol(')', true)) {
SkipUntil(')');