summaryrefslogtreecommitdiffstats
path: root/layout/style/nsCSSParser.cpp
diff options
context:
space:
mode:
authorathenian200 <athenian200@outlook.com>2020-09-17 16:01:38 -0500
committerMoonchild <moonchild@palemoon.org>2020-09-21 11:05:30 +0000
commitf2866a5420b4645d888fc50b22f7cbdd8a178042 (patch)
tree0fcf939a8a8bb1da4c57ba154cbe543b5b4dfb63 /layout/style/nsCSSParser.cpp
parentb862145e9c7f0802ea5fa7e02c003744dbca9ec2 (diff)
downloadUXP-f2866a5420b4645d888fc50b22f7cbdd8a178042.tar
UXP-f2866a5420b4645d888fc50b22f7cbdd8a178042.tar.gz
UXP-f2866a5420b4645d888fc50b22f7cbdd8a178042.tar.lz
UXP-f2866a5420b4645d888fc50b22f7cbdd8a178042.tar.xz
UXP-f2866a5420b4645d888fc50b22f7cbdd8a178042.zip
Issue #1647 - Part 2: Implement VARIANT_OPACITY to correctly serialize.
Even though percentages are already treated as floats internally by the style system for computation purposes, you have to go out of your way to stop them from being read back out as percentages. What I do here amounts to storing the percentage token in the "wrong" container, the one normally used for floats. This allows a value that was read in as a percentage to be read back out as something else, which is normally prevented by the design of the style system.
Diffstat (limited to 'layout/style/nsCSSParser.cpp')
-rw-r--r--layout/style/nsCSSParser.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp
index f6b84bfac..1525c5f9a 100644
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -1300,7 +1300,7 @@ protected:
}
bool ParseNonNegativeNumber(nsCSSValue& aValue)
{
- return ParseSingleTokenNonNegativeVariant(aValue, VARIANT_NUMBER, nullptr);
+ return ParseSingleTokenNonNegativeVariant(aValue, VARIANT_NUMBER | VARIANT_OPACITY, nullptr);
}
// Helpers for some common ParseSingleTokenOneOrLargerVariant calls.
@@ -1310,7 +1310,7 @@ protected:
}
bool ParseOneOrLargerNumber(nsCSSValue& aValue)
{
- return ParseSingleTokenOneOrLargerVariant(aValue, VARIANT_NUMBER, nullptr);
+ return ParseSingleTokenOneOrLargerVariant(aValue, VARIANT_NUMBER | VARIANT_OPACITY, nullptr);
}
// http://dev.w3.org/csswg/css-values/#custom-idents
@@ -7789,6 +7789,7 @@ CSSParserImpl::ParseNonNegativeVariant(nsCSSValue& aValue,
VARIANT_NUMBER |
VARIANT_LENGTH |
VARIANT_PERCENT |
+ VARIANT_OPACITY |
VARIANT_INTEGER)) == 0,
"need to update code below to handle additional variants");
@@ -7829,6 +7830,7 @@ CSSParserImpl::ParseOneOrLargerVariant(nsCSSValue& aValue,
// that we specifically handle.
MOZ_ASSERT((aVariantMask & ~(VARIANT_ALL_NONNUMERIC |
VARIANT_NUMBER |
+ VARIANT_OPACITY |
VARIANT_INTEGER)) == 0,
"need to update code below to handle additional variants");
@@ -7957,9 +7959,9 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue,
}
}
}
- // Check VARIANT_NUMBER and VARIANT_INTEGER before VARIANT_LENGTH or
- // VARIANT_ZERO_ANGLE.
- if (((aVariantMask & VARIANT_NUMBER) != 0) &&
+ // Check VARIANT_NUMBER, number tokens for VARIANT_OPACITY, and
+ // VARIANT_INTEGER before VARIANT_LENGTH or VARIANT_ZERO_ANGLE.
+ if (((aVariantMask & (VARIANT_NUMBER | VARIANT_OPACITY)) != 0) &&
(eCSSToken_Number == tk->mType)) {
aValue.SetFloatValue(tk->mNumber, eCSSUnit_Number);
return CSSParseResult::Ok;
@@ -7969,6 +7971,7 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue,
aValue.SetIntValue(tk->mInteger, eCSSUnit_Integer);
return CSSParseResult::Ok;
}
+
if (((aVariantMask & (VARIANT_LENGTH | VARIANT_ANGLE |
VARIANT_FREQUENCY | VARIANT_TIME)) != 0 &&
eCSSToken_Dimension == tk->mType) ||
@@ -7994,6 +7997,15 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue,
aValue.SetPercentValue(tk->mNumber);
return CSSParseResult::Ok;
}
+ // We need to store eCSSToken_Percentage in eCSSUnit_Number in order to
+ // serialize opacity according to spec. All percentage tokens are stored
+ // as floats, so no type conversion is needed to make this possible.
+ // Percentage tokens have to be evaluated later than number tokens.
+ if (((aVariantMask & VARIANT_OPACITY) != 0) &&
+ (eCSSToken_Percentage == tk->mType)) {
+ aValue.SetFloatValue(tk->mNumber, eCSSUnit_Number);
+ return CSSParseResult::Ok;
+ }
if (mUnitlessLengthQuirk) { // NONSTANDARD: Nav interprets unitless numbers as px
if (((aVariantMask & VARIANT_LENGTH) != 0) &&
(eCSSToken_Number == tk->mType)) {
@@ -8472,7 +8484,7 @@ CSSParserImpl::ParseImageRect(nsCSSValue& aImage)
break;
}
- static const int32_t VARIANT_SIDE = VARIANT_NUMBER | VARIANT_PERCENT;
+ static const int32_t VARIANT_SIDE = VARIANT_NUMBER | VARIANT_PERCENT | VARIANT_OPACITY;
if (!ParseSingleTokenNonNegativeVariant(top, VARIANT_SIDE, nullptr) ||
!ExpectSymbol(',', true) ||
!ParseSingleTokenNonNegativeVariant(right, VARIANT_SIDE, nullptr) ||
@@ -10881,7 +10893,7 @@ CSSParserImpl::ParseWebkitGradientColorStop(nsCSSValueGradient* aGradient)
if (mToken.mIdent.LowerCaseEqualsLiteral("color-stop")) {
// Parse stop location, followed by comma.
if (!ParseSingleTokenVariant(stop->mLocation,
- VARIANT_NUMBER | VARIANT_PERCENT,
+ VARIANT_NUMBER | VARIANT_PERCENT | VARIANT_OPACITY,
nullptr) ||
!ExpectSymbol(',', true)) {
SkipUntil(')'); // Skip to end of color-stop(...) expression.
@@ -16044,7 +16056,7 @@ static bool GetFunctionParseInformation(nsCSSKeyword aToken,
{VARIANT_LBCALC, VARIANT_LBCALC, VARIANT_LBCALC},
{VARIANT_ANGLE_OR_ZERO},
{VARIANT_ANGLE_OR_ZERO, VARIANT_ANGLE_OR_ZERO},
- {VARIANT_NUMBER},
+ {VARIANT_NUMBER|VARIANT_OPACITY},
{VARIANT_LENGTH|VARIANT_NONNEGATIVE_DIMENSION},
{VARIANT_LB|VARIANT_NONNEGATIVE_DIMENSION},
{VARIANT_NUMBER, VARIANT_NUMBER},
@@ -17626,7 +17638,7 @@ CSSParserImpl::ParseScrollSnapPoints(nsCSSValue& aValue, nsCSSPropertyID aPropID
nsCSSKeywords::LookupKeyword(mToken.mIdent) == eCSSKeyword_repeat) {
nsCSSValue lengthValue;
if (ParseNonNegativeVariant(lengthValue,
- VARIANT_LENGTH | VARIANT_PERCENT | VARIANT_CALC,
+ VARIANT_LENGTH | VARIANT_PERCENT | VARIANT_OPACITY | VARIANT_CALC,
nullptr) != CSSParseResult::Ok) {
REPORT_UNEXPECTED(PEExpectedNonnegativeNP);
SkipUntil(')');