From 43155b03e44e62f4d2c5cb343a846db986cf9103 Mon Sep 17 00:00:00 2001 From: "L. David Baron" Date: Wed, 4 Nov 2009 18:36:18 -0800 Subject: [PATCH] Bug 526402: Stop accepting unitless 0 for angles, times, and frequencies. r=zwol --- layout/style/nsCSSParser.cpp | 32 ++++++++++--------- layout/style/nsCSSScanner.h | 5 --- layout/style/test/property_database.js | 20 ++++++------ .../test/test_shorthand_property_getters.html | 12 +++---- ...ansitions_computed_value_combinations.html | 4 +-- 5 files changed, 35 insertions(+), 38 deletions(-) diff --git a/layout/style/nsCSSParser.cpp b/layout/style/nsCSSParser.cpp index 6772784d1819..0ceac231f0ae 100644 --- a/layout/style/nsCSSParser.cpp +++ b/layout/style/nsCSSParser.cpp @@ -112,6 +112,8 @@ #define VARIANT_CUBIC_BEZIER 0x400000 // CSS transition timing function #define VARIANT_ALL 0x800000 // #define VARIANT_IMAGE_RECT 0x01000000 // eCSSUnit_Function +// This is an extra bit that says that a VARIANT_ANGLE allows unitless zero: +#define VARIANT_ZERO_ANGLE 0x02000000 // unitless zero for angles // Common combinations of variants #define VARIANT_AL (VARIANT_AUTO | VARIANT_LENGTH) @@ -147,6 +149,7 @@ #define VARIANT_HOS (VARIANT_INHERIT | VARIANT_NONE | VARIANT_STRING) #define VARIANT_TIMING_FUNCTION (VARIANT_KEYWORD | VARIANT_CUBIC_BEZIER) #define VARIANT_UK (VARIANT_URL | VARIANT_KEYWORD) +#define VARIANT_ANGLE_OR_ZERO (VARIANT_ANGLE | VARIANT_ZERO_ANGLE) //---------------------------------------------------------------------- @@ -1806,12 +1809,12 @@ CSSParserImpl::ParseMediaQueryExpression(nsMediaQuery* aQuery) } break; case nsMediaFeature::eResolution: - rv = GetToken(PR_TRUE) && mToken.IsDimension() && + rv = GetToken(PR_TRUE) && mToken.mType == eCSSToken_Dimension && mToken.mIntegerValid && mToken.mNumber > 0.0f; if (rv) { // No worries about whether unitless zero is allowed, since the // value must be positive (and we checked that above). - NS_ASSERTION(!mToken.mIdent.IsEmpty(), "IsDimension lied"); + NS_ASSERTION(!mToken.mIdent.IsEmpty(), "unit lied"); if (mToken.mIdent.LowerCaseEqualsLiteral("dpi")) { expr->mValue.SetFloatValue(mToken.mNumber, eCSSUnit_Inch); } else if (mToken.mIdent.LowerCaseEqualsLiteral("dpcm")) { @@ -4294,17 +4297,11 @@ CSSParserImpl::TranslateDimension(nsCSSValue& aValue, type = VARIANT_LENGTH; } else if ((VARIANT_ANGLE & aVariantMask) != 0) { + NS_ASSERTION(aVariantMask & VARIANT_ZERO_ANGLE, + "must have allowed zero angle"); units = eCSSUnit_Degree; type = VARIANT_ANGLE; } - else if ((VARIANT_FREQUENCY & aVariantMask) != 0) { - units = eCSSUnit_Hertz; - type = VARIANT_FREQUENCY; - } - else if ((VARIANT_TIME & aVariantMask) != 0) { - units = eCSSUnit_Seconds; - type = VARIANT_TIME; - } else { NS_ERROR("Variant mask does not include dimension; why were we called?"); return PR_FALSE; @@ -4466,8 +4463,12 @@ CSSParserImpl::ParseVariant(nsCSSValue& aValue, } } } - if (((aVariantMask & (VARIANT_LENGTH | VARIANT_ANGLE | VARIANT_FREQUENCY | VARIANT_TIME)) != 0) && - tk->IsDimension()) { + if (((aVariantMask & (VARIANT_LENGTH | VARIANT_ANGLE | + VARIANT_FREQUENCY | VARIANT_TIME)) != 0 && + eCSSToken_Dimension == tk->mType) || + ((aVariantMask & (VARIANT_LENGTH | VARIANT_ZERO_ANGLE)) != 0 && + eCSSToken_Number == tk->mType && + tk->mNumber == 0.0f)) { if (TranslateDimension(aValue, aVariantMask, tk->mNumber, tk->mIdent)) { return PR_TRUE; } @@ -6475,7 +6476,8 @@ CSSParserImpl::ParseBackgroundItem(CSSParserImpl::BackgroundItem& aItem, eCSSProperty_background_image)) { return PR_FALSE; } - } else if (mToken.IsDimension() || tt == eCSSToken_Percentage) { + } else if (tt == eCSSToken_Dimension || tt == eCSSToken_Number || + tt == eCSSToken_Percentage) { if (havePosition) return PR_FALSE; havePosition = PR_TRUE; @@ -7631,8 +7633,8 @@ static PRBool GetFunctionParseInformation(nsCSSKeyword aToken, static const PRInt32 kVariantMasks[eNumVariantMasks][kMaxElemsPerFunction] = { {VARIANT_LENGTH | VARIANT_PERCENT}, {VARIANT_LENGTH | VARIANT_PERCENT, VARIANT_LENGTH | VARIANT_PERCENT}, - {VARIANT_ANGLE}, - {VARIANT_ANGLE, VARIANT_ANGLE}, + {VARIANT_ANGLE_OR_ZERO}, + {VARIANT_ANGLE_OR_ZERO, VARIANT_ANGLE_OR_ZERO}, {VARIANT_NUMBER}, {VARIANT_NUMBER, VARIANT_NUMBER}, {VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, VARIANT_NUMBER, diff --git a/layout/style/nsCSSScanner.h b/layout/style/nsCSSScanner.h index 983207c0aa29..0afacaa2f240 100644 --- a/layout/style/nsCSSScanner.h +++ b/layout/style/nsCSSScanner.h @@ -120,11 +120,6 @@ struct nsCSSToken { nsCSSToken(); - PRBool IsDimension() { - return PRBool((eCSSToken_Dimension == mType) || - ((eCSSToken_Number == mType) && (mNumber == 0.0f))); - } - PRBool IsSymbol(PRUnichar aSymbol) { return PRBool((eCSSToken_Symbol == mType) && (mSymbol == aSymbol)); } diff --git a/layout/style/test/property_database.js b/layout/style/test/property_database.js index 07d851f8433b..265c6e70b58c 100644 --- a/layout/style/test/property_database.js +++ b/layout/style/test/property_database.js @@ -1745,27 +1745,27 @@ var gCSSProperties = { backend_only: true, type: CSS_TYPE_TRUE_SHORTHAND, subproperties: [ "pause-before", "pause-after" ], - initial_values: [ "0", "0s", "0ms", "0 0", "0s 0ms", "0ms 0" ], + initial_values: [ "0s", "0ms", "0s 0ms" ], other_values: [ "1s", "200ms", "-2s", "50%", "-10%", "10% 200ms", "-3s -5%" ], - invalid_values: [ "0px" ] + invalid_values: [ "0", "0px", "0 0", "0ms 0" ] }, "pause-after": { domProp: "pauseAfter", inherited: false, backend_only: true, type: CSS_TYPE_LONGHAND, - initial_values: [ "0", "0s", "0ms" ], + initial_values: [ "0s", "0ms" ], other_values: [ "1s", "200ms", "-2s", "50%", "-10%" ], - invalid_values: [ "0px" ] + invalid_values: [ "0", "0px" ] }, "pause-before": { domProp: "pauseBefore", inherited: false, backend_only: true, type: CSS_TYPE_LONGHAND, - initial_values: [ "0", "0s", "0ms" ], + initial_values: [ "0s", "0ms" ], other_values: [ "1s", "200ms", "-2s", "50%", "-10%" ], - invalid_values: [ "0px" ] + invalid_values: [ "0", "0px" ] }, "pitch": { domProp: "pitch", @@ -1972,17 +1972,17 @@ var gCSSProperties = { domProp: "MozTransitionDelay", inherited: false, type: CSS_TYPE_LONGHAND, - initial_values: [ "0", "0s", "0ms" ], + initial_values: [ "0s", "0ms" ], other_values: [ "1s", "250ms", "-100ms", "-1s", "1s, 250ms, 2.3s"], - invalid_values: [] + invalid_values: [ "0", "0px" ] }, "-moz-transition-duration": { domProp: "MozTransitionDuration", inherited: false, type: CSS_TYPE_LONGHAND, - initial_values: [ "0", "0s", "0ms" ], + initial_values: [ "0s", "0ms" ], other_values: [ "1s", "250ms", "-1ms", "-2s", "1s, 250ms, 2.3s"], - invalid_values: [] + invalid_values: [ "0", "0px" ] }, "-moz-transition-property": { domProp: "MozTransitionProperty", diff --git a/layout/style/test/test_shorthand_property_getters.html b/layout/style/test/test_shorthand_property_getters.html index 2163b1f17c22..e0f3b2c88555 100644 --- a/layout/style/test/test_shorthand_property_getters.html +++ b/layout/style/test/test_shorthand_property_getters.html @@ -148,17 +148,17 @@ e.setAttribute("style", "-moz-background-clip: border, border, border; -moz-back is(e.style.background, "", "should not have background shorthand (-moz-background-size too long)"); // Check that we only serialize transition when the lists are the same length. -e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0, 1s"); +e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0s, 1s"); isnot(e.style.MozTransition, "", "should have -moz-transition shorthand (lists same length)"); -e.setAttribute("style", "-moz-transition-property: color, width, left; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0, 1s"); +e.setAttribute("style", "-moz-transition-property: color, width, left; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0s, 1s"); is(e.style.MozTransition, "", "should not have -moz-transition shorthand (lists different lengths)"); -e.setAttribute("style", "-moz-transition-property: all; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0, 1s"); +e.setAttribute("style", "-moz-transition-property: all; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0s, 1s"); is(e.style.MozTransition, "", "should not have -moz-transition shorthand (lists different lengths)"); -e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms, 300ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0, 1s"); +e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms, 300ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0s, 1s"); is(e.style.MozTransition, "", "should not have -moz-transition shorthand (lists different lengths)"); -e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear, ease-out; -moz-transition-delay: 0, 1s"); +e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear, ease-out; -moz-transition-delay: 0s, 1s"); is(e.style.MozTransition, "", "should not have -moz-transition shorthand (lists different lengths)"); -e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0, 1s, 0"); +e.setAttribute("style", "-moz-transition-property: color, width; -moz-transition-duration: 1s, 200ms; -moz-transition-timing-function: ease-in, linear; -moz-transition-delay: 0s, 1s, 0s"); is(e.style.MozTransition, "", "should not have -moz-transition shorthand (lists different lengths)"); diff --git a/layout/style/test/test_transitions_computed_value_combinations.html b/layout/style/test/test_transitions_computed_value_combinations.html index bca966a06a17..baf88186193c 100644 --- a/layout/style/test/test_transitions_computed_value_combinations.html +++ b/layout/style/test/test_transitions_computed_value_combinations.html @@ -43,7 +43,7 @@ var values = { [ { lone: true, specified: "-moz-initial" }, { lone: false, specified: "2s" }, - { lone: false, specified: "0" }, + { lone: false, specified: "0s" }, { lone: false, specified: "430ms" }, { lone: false, specified: "-1s" }, ], @@ -70,7 +70,7 @@ var values = { [ { lone: true, specified: "-moz-initial" }, { lone: false, specified: "2s" }, - { lone: false, specified: "0" }, + { lone: false, specified: "0s" }, { lone: false, specified: "430ms" }, { lone: false, specified: "-1s" }, ],