Issue #2477 - Part 1: Implement a separate function for parsing pair box properties

This reuses existing logic from ParseGap.
This commit is contained in:
FranklinDM 2024-03-29 20:30:13 +08:00 committed by roytam1
commit 1e73f1f2d2

View file

@ -1188,6 +1188,7 @@ protected:
// Reused utility parsing routines
void AppendValue(nsCSSPropertyID aPropID, const nsCSSValue& aValue);
bool ParseBoxProperties(const nsCSSPropertyID aPropIDs[]);
bool ParseBoxPairProperties(nsCSSPropertyID aStart, nsCSSPropertyID aEnd);
bool ParseGroupedBoxProperty(int32_t aVariantMask,
nsCSSValue& aValue,
uint32_t aRestrictions);
@ -10107,25 +10108,8 @@ CSSParserImpl::ParseGridArea()
bool
CSSParserImpl::ParseGap()
{
nsCSSValue first;
if (ParseSingleTokenVariant(first, VARIANT_INHERIT, nullptr)) {
AppendValue(eCSSProperty_row_gap, first);
AppendValue(eCSSProperty_column_gap, first);
return true;
}
if (ParseNonNegativeVariant(first, VARIANT_LPCALC, nullptr) !=
CSSParseResult::Ok) {
return false;
}
nsCSSValue second;
auto result = ParseNonNegativeVariant(second, VARIANT_LPCALC, nullptr);
if (result == CSSParseResult::Error) {
return false;
}
AppendValue(eCSSProperty_row_gap, first);
AppendValue(eCSSProperty_column_gap,
result == CSSParseResult::NotFound ? first : second);
return true;
return ParseBoxPairProperties(eCSSProperty_row_gap,
eCSSProperty_column_gap);
}
// normal | [<number> <integer>?]
@ -11448,6 +11432,30 @@ CSSParserImpl::ParseBoxProperties(const nsCSSPropertyID aPropIDs[])
return true;
}
bool
CSSParserImpl::ParseBoxPairProperties(nsCSSPropertyID aStart, nsCSSPropertyID aEnd)
{
nsCSSValue first;
if (ParseSingleTokenVariant(first, VARIANT_INHERIT, nullptr)) {
AppendValue(aStart, first);
AppendValue(aEnd, first);
return true;
}
if (ParseNonNegativeVariant(first, VARIANT_LPCALC, nullptr) !=
CSSParseResult::Ok) {
return false;
}
nsCSSValue second;
auto result = ParseNonNegativeVariant(second, VARIANT_LPCALC, nullptr);
if (result == CSSParseResult::Error) {
return false;
}
AppendValue(aStart, first);
AppendValue(aEnd,
result == CSSParseResult::NotFound ? first : second);
return true;
}
// Similar to ParseBoxProperties, except there is only one property
// with the result as its value, not four.
bool