Bug 804970, patch 1: Don't force calc() units out of the rule tree. r=bzbarsky
authorL. David Baron <dbaron@dbaron.org>
Fri, 26 Oct 2012 19:04:20 +0200
changeset 111665 eac41b17bc5230b56b9a089a3bbfd1e62532d2a0
parent 111664 78cf3c6d8fc51a664b76c4f8caeed3252549899f
child 111666 0776bcfd7e0c3013443172c3b39678964b7285db
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbzbarsky
bugs804970
milestone19.0a1
Bug 804970, patch 1: Don't force calc() units out of the rule tree. r=bzbarsky This moves the calc() handling above the aCanStoreInRuleTree = false, which it had no reason to be below. calc() units are still forced out of the rule tree when there's an em, ex, or rem unit inside the calc() structure, since aCanStoreInRuleTree is passed through to the leaf CalcLengthWith calls.
layout/style/nsRuleNode.cpp
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -252,16 +252,28 @@ static nscoord CalcLengthWith(const nsCS
   NS_ASSERTION(aPresContext, "Must have prescontext");
 
   if (aValue.IsFixedLengthUnit()) {
     return aValue.GetFixedLength(aPresContext);
   }
   if (aValue.IsPixelLengthUnit()) {
     return aValue.GetPixelLength();
   }
+  if (aValue.IsCalcUnit()) {
+    // For properties for which lengths are the *only* units accepted in
+    // calc(), we can handle calc() here and just compute a final
+    // result.  We ensure that we don't get to this code for other
+    // properties by not calling CalcLength in those cases:  SetCoord
+    // only calls CalcLength for a calc when it is appropriate to do so.
+    CalcLengthCalcOps ops(aFontSize, aStyleFont,
+                          aStyleContext, aPresContext,
+                          aUseProvidedRootEmSize, aUseUserFontSet,
+                          aCanStoreInRuleTree);
+    return css::ComputeCalc(aValue, ops);
+  }
   // Common code for all units other than pixel-based units and fixed-length
   // units:
   aCanStoreInRuleTree = false;
   const nsStyleFont *styleFont =
     aStyleFont ? aStyleFont : aStyleContext->GetStyleFont();
   if (aFontSize == -1) {
     // XXX Should this be styleFont->mSize instead to avoid taking minfontsize
     // prefs into account?
@@ -337,33 +349,16 @@ static nscoord CalcLengthWith(const nsCS
         GetMetricsFor(aPresContext, aStyleContext, styleFont,
                       aFontSize, aUseUserFontSet);
       gfxFloat zeroWidth = (fm->GetThebesFontGroup()->GetFontAt(0)
                             ->GetMetrics().zeroOrAveCharWidth);
 
       return ScaleCoord(aValue, ceil(aPresContext->AppUnitsPerDevPixel() *
                                      zeroWidth));
     }
-    // For properties for which lengths are the *only* units accepted in
-    // calc(), we can handle calc() here and just compute a final
-    // result.  We ensure that we don't get to this code for other
-    // properties by not calling CalcLength in those cases:  SetCoord
-    // only calls CalcLength for a calc when it is appropriate to do so.
-    case eCSSUnit_Calc:
-    case eCSSUnit_Calc_Plus:
-    case eCSSUnit_Calc_Minus:
-    case eCSSUnit_Calc_Times_L:
-    case eCSSUnit_Calc_Times_R:
-    case eCSSUnit_Calc_Divided: {
-      CalcLengthCalcOps ops(aFontSize, aStyleFont,
-                            aStyleContext, aPresContext,
-                            aUseProvidedRootEmSize, aUseUserFontSet,
-                            aCanStoreInRuleTree);
-      return css::ComputeCalc(aValue, ops);
-    }
     default:
       NS_NOTREACHED("unexpected unit");
       break;
   }
   return 0;
 }
 
 /* static */ nscoord