Bug 968761 - Treat nested calc() as plain parenthesis. r=dbaron
authorXidorn Quan <quanxunzhen@gmail.com>
Thu, 03 Mar 2016 10:05:37 +0800
changeset 342030 9cd676104bc42cf7e3153ec144d70c3171f08454
parent 342029 4cde1aabe95e6c8d98a88055797737481e04352f
child 342031 ceb8532131fb64a9029f4ffeb146af8ea7f7537e
push id13342
push userbmo:james@hoppipolla.co.uk
push dateFri, 18 Mar 2016 09:55:58 +0000
reviewersdbaron
bugs968761
milestone48.0a1
Bug 968761 - Treat nested calc() as plain parenthesis. r=dbaron MozReview-Commit-ID: Lwd56FaaDWx
layout/reftests/w3c-css/failures.list
layout/reftests/w3c-css/received/reftest.list
layout/style/nsCSSParser.cpp
--- a/layout/reftests/w3c-css/failures.list
+++ b/layout/reftests/w3c-css/failures.list
@@ -10,15 +10,13 @@
 css-values-3/attr-color-invalid-cast.html
 css-values-3/attr-color-valid.html
 css-values-3/attr-length-invalid-cast.html
 css-values-3/attr-length-valid-zero-nofallback.html
 css-values-3/attr-length-valid-zero.html
 css-values-3/attr-length-valid.html
 css-values-3/attr-px-invalid-cast.html
 css-values-3/attr-px-valid.html
-# Bug 968761
-css-values-3/calc-in-calc.html
 # Bug 1256575
 css-values-3/calc-in-media-queries-001.html
 css-values-3/calc-in-media-queries-002.html
 # Bug 1256579
 css-values-3/vh-interpolate-pct.html
--- a/layout/reftests/w3c-css/received/reftest.list
+++ b/layout/reftests/w3c-css/received/reftest.list
@@ -73,17 +73,17 @@ fails == css-values-3/attr-color-valid.h
 fails == css-values-3/attr-length-invalid-cast.html css-values-3/200-200-green.html
 == css-values-3/attr-length-invalid-fallback.html css-values-3/200-200-green.html
 fails == css-values-3/attr-length-valid-zero-nofallback.html css-values-3/200-200-green.html
 fails == css-values-3/attr-length-valid-zero.html css-values-3/200-200-green.html
 fails == css-values-3/attr-length-valid.html css-values-3/200-200-green.html
 fails == css-values-3/attr-px-invalid-cast.html css-values-3/200-200-green.html
 == css-values-3/attr-px-invalid-fallback.html css-values-3/200-200-green.html
 fails == css-values-3/attr-px-valid.html css-values-3/200-200-green.html
-fails == css-values-3/calc-in-calc.html css-values-3/all-green.html
+== css-values-3/calc-in-calc.html css-values-3/all-green.html
 fails == css-values-3/calc-in-media-queries-001.html css-values-3/all-green.html
 fails == css-values-3/calc-in-media-queries-002.html css-values-3/all-green.html
 == css-values-3/calc-invalid-range-clamping.html css-values-3/200-200-green.html
 == css-values-3/calc-parenthesis-stack.html css-values-3/all-green.html
 skip == css-values-3/ch-unit-001.html css-values-3/ch-unit-001-ref.html
 == css-values-3/initial-background-color.html css-values-3/all-green.html
 == css-values-3/vh-calc-support-pct.html css-values-3/all-green.html
 == css-values-3/vh-calc-support.html css-values-3/all-green.html
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -7565,16 +7565,24 @@ CSSParserImpl::ParseOneOrLargerVariant(n
         UngetToken();
         return CSSParseResult::NotFound;
       }
     }
   }
   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,
                             uint32_t aVariantMask,
                             const KTableEntry aKeywordTable[])
 {
   NS_ASSERTION(!(mHashlessColorQuirk && (aVariantMask & VARIANT_COLOR)) ||
                !(aVariantMask & VARIANT_NUMBER),
@@ -7868,19 +7876,17 @@ CSSParserImpl::ParseVariant(nsCSSValue& 
       if (!ParseTransitionStepTimingFunctionValues(aValue)) {
         SkipUntil(')');
         return CSSParseResult::Error;
       }
       return CSSParseResult::Ok;
     }
   }
   if ((aVariantMask & VARIANT_CALC) &&
-      (eCSSToken_Function == tk->mType) &&
-      (tk->mIdent.LowerCaseEqualsLiteral("calc") ||
-       tk->mIdent.LowerCaseEqualsLiteral("-moz-calc"))) {
+      IsCSSTokenCalcFunction(*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.
     if (!ParseCalc(aValue, aVariantMask & VARIANT_LPN)) {
       return CSSParseResult::Error;
     }
     return CSSParseResult::Ok;
   }
@@ -13182,17 +13188,19 @@ CSSParserImpl::ParseCalcMultiplicativeEx
 //    removing VARIANT_NUMBER or removing all other bits.
 bool
 CSSParserImpl::ParseCalcTerm(nsCSSValue& aValue, uint32_t& aVariantMask)
 {
   MOZ_ASSERT(aVariantMask != 0, "unexpected variant mask");
   if (!GetToken(true))
     return false;
   // Either an additive expression in parentheses...
-  if (mToken.IsSymbol('(')) {
+  if (mToken.IsSymbol('(') ||
+      // Treat nested calc() as plain parenthesis.
+      IsCSSTokenCalcFunction(mToken)) {
     if (!ParseCalcAdditiveExpression(aValue, aVariantMask) ||
         !ExpectSymbol(')', true)) {
       SkipUntil(')');
       return false;
     }
     return true;
   }
   // ... or just a value