Bug 594933 - Part 1: Let calc() supports number. r=dbaron
authorMorris Tseng <mtseng@mozilla.com>
Tue, 15 Mar 2016 10:37:37 +0800
changeset 288691 8e35ad3b586f7aabdfce8050893a45a8c47f518c
parent 288690 4167dfdf10457360c9c94ee6e55b03ef1b92c16d
child 288692 2f3cc8818587cc3b25d196cb61a2063f37227ab9
push id18174
push usercbook@mozilla.com
push dateTue, 15 Mar 2016 09:44:58 +0000
treeherderfx-team@dd0baa33759d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs594933
milestone48.0a1
Bug 594933 - Part 1: Let calc() supports number. r=dbaron
layout/style/nsCSSParser.cpp
layout/style/nsCSSValue.cpp
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -7871,18 +7871,20 @@ CSSParserImpl::ParseVariant(nsCSSValue& 
       }
       return CSSParseResult::Ok;
     }
   }
   if ((aVariantMask & VARIANT_CALC) &&
       (eCSSToken_Function == tk->mType) &&
       (tk->mIdent.LowerCaseEqualsLiteral("calc") ||
        tk->mIdent.LowerCaseEqualsLiteral("-moz-calc"))) {
-    // calc() currently allows only lengths and percents inside it.
-    if (!ParseCalc(aValue, aVariantMask & VARIANT_LP)) {
+    // 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;
   }
 
   UngetToken();
   AssertNextTokenAt(lineBefore, colBefore);
   return CSSParseResult::NotFound;
@@ -12955,17 +12957,16 @@ CSSParserImpl::ParseBorderColors(nsCSSPr
 // Parse the top level of a calc() expression.
 bool
 CSSParserImpl::ParseCalc(nsCSSValue &aValue, uint32_t aVariantMask)
 {
   // Parsing calc expressions requires, in a number of cases, looking
   // for a token that is *either* a value of the property or a number.
   // This can be done without lookahead when we assume that the property
   // values cannot themselves be numbers.
-  NS_ASSERTION(!(aVariantMask & VARIANT_NUMBER), "unexpected variant mask");
   MOZ_ASSERT(aVariantMask != 0, "unexpected variant mask");
 
   bool oldUnitlessLengthQuirk = mUnitlessLengthQuirk;
   mUnitlessLengthQuirk = false;
 
   // One-iteration loop so we can break to the error-handling case.
   do {
     // The toplevel of a calc() is always an nsCSSValue::Array of length 1.
--- a/layout/style/nsCSSValue.cpp
+++ b/layout/style/nsCSSValue.cpp
@@ -807,17 +807,19 @@ struct CSSValueSerializeCalcOps {
 
   void Append(const char* aString)
   {
     mResult.AppendASCII(aString);
   }
 
   void AppendLeafValue(const input_type& aValue)
   {
-    MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Percent || aValue.IsLengthUnit(),
+    MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Percent ||
+               aValue.IsLengthUnit() ||
+               aValue.GetUnit() == eCSSUnit_Number,
                "unexpected unit");
     aValue.AppendToString(mProperty, mResult, mValueSerialization);
   }
 
   void AppendNumber(const input_type& aValue)
   {
     MOZ_ASSERT(aValue.GetUnit() == eCSSUnit_Number, "unexpected unit");
     aValue.AppendToString(mProperty, mResult, mValueSerialization);