s/ratio/weight/ per dbaron's www-style message about terminology (especially because we might move to tracking per-flex-item the _actual_ ratio of its weight to the sum of the weights, and we want to be clear about which values are which)
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 13 Aug 2012 16:17:43 -0700
changeset 1701 63f6894d00dfcde990d0ea87b72e795bc72e45cb
parent 1700 d2093033cdd32b2e624fb06eadce3973af6853fe
child 1702 e8a159f61254726c8dd5d1c90bdc46062e942d4d
push id1387
push userdholbert@mozilla.com
push dateMon, 13 Aug 2012 23:17:44 +0000
s/ratio/weight/ per dbaron's www-style message about terminology (especially because we might move to tracking per-flex-item the _actual_ ratio of its weight to the sum of the weights, and we want to be clear about which values are which)
flexbox-mainImpl.patch
--- a/flexbox-mainImpl.patch
+++ b/flexbox-mainImpl.patch
@@ -264,21 +264,21 @@ diff --git a/layout/generic/nsFlexContai
 +
 +  // Indicates whether this item's cross-size has been stretched (from having
 +  // "align-self: stretch" with an auto cross-size and no auto margins in the
 +  // cross axis).
 +  bool IsStretched() const         { return mIsStretched; }
 +
 +  PRUint8 GetAlignSelf() const     { return mAlignSelf; }
 +
-+  // Returns the flex ratio that we should use in the "resolving flexible
++  // Returns the flex weight that we should use in the "resolving flexible
 +  // lengths" algorithm.  If we've got a positive amount of free space, we use
-+  // the flex-grow ratio; otherwise, we use the "scaled flex shrink ratio"
++  // the flex-grow weight; otherwise, we use the "scaled flex shrink weight"
 +  // (scaled by our flex base size)
-+  float GetFlexRatioToUse(bool aHavePositiveFreeSpace)
++  float GetFlexWeightToUse(bool aHavePositiveFreeSpace)
 +  {
 +    if (IsFrozen()) {
 +      return 0.0f;
 +    }
 +
 +    return aHavePositiveFreeSpace ?
 +      mFlexGrow :
 +      mFlexShrink * mFlexBaseSize;
@@ -557,17 +557,17 @@ diff --git a/layout/generic/nsFlexContai
 +      mainMinSize = NS_MAX(mainMinSize, widgetMainMinSize);
 +      mainMaxSize = NS_MAX(mainMaxSize, widgetMainMinSize);
 +
 +      crossMinSize = NS_MAX(crossMinSize, widgetCrossMinSize);
 +      crossMaxSize = NS_MAX(crossMaxSize, widgetCrossMinSize);
 +    }
 +  }
 +
-+  // FLEX GROW & SHRINK RATIOS
++  // FLEX GROW & SHRINK WEIGHTS
 +  const nsStylePosition* stylePos = aChildFrame->GetStylePosition();
 +  float flexGrow   = stylePos->mFlexGrow;
 +  float flexShrink = stylePos->mFlexShrink;
 +
 +  aFlexItems.AppendElement(FlexItem(aChildFrame,
 +                                    flexGrow, flexShrink, flexBaseSize,
 +                                    mainMinSize, mainMaxSize,
 +                                    crossMinSize, crossMaxSize,
@@ -1051,105 +1051,105 @@ diff --git a/layout/generic/nsFlexContai
 +    PR_LOG(nsFlexContainerFrameLM, PR_LOG_DEBUG,
 +           (" available free space = %d\n", availableFreeSpace));
 +
 +    // If sign of free space matches flexType, give each flexible
 +    // item a portion of availableFreeSpace.
 +    if ((availableFreeSpace > 0 && havePositiveFreeSpace) ||
 +        (availableFreeSpace < 0 && !havePositiveFreeSpace)) {
 +
-+      float sumOfFlexRatios = 0.0f;
++      float sumOfFlexWeights = 0.0f;
 +
 +      // To work around floating-point error, we keep track of the last item
 +      // with nonzero flexibility, and when we hit that entry in our main
 +      // distribution loop, we'll just give it all the remaining flexiblity.
-+      PRUint32 idxOfLastNonzeroFlexRatio = 0;
++      PRUint32 idxOfLastNonzeroFlexWeight = 0;
 +
-+      // Keep track of the largest flex ratio we've seen, and the number of
-+      // items with that flex ratio, in case the sum of our flex ratios ends
++      // Keep track of the largest flex weight we've seen, and the number of
++      // items with that flex weight, in case the sum of our flex weights ends
 +      // up being infinite (overflowing the maximum storable float value).
 +      // If that happens, we'll distribute all the available space among the
-+      // item(s) with the largest flex ratio.
-+      float largestFlexRatio = 0.0f;
-+      PRUint32 numItemsWithLargestFlexRatio = 0;
++      // item(s) with the largest flex weight.
++      float largestFlexWeight = 0.0f;
++      PRUint32 numItemsWithLargestFlexWeight = 0;
 +
 +      for (PRUint32 i = 0; i < aItems.Length(); i++) {
-+        float curFlexRatio = aItems[i].GetFlexRatioToUse(havePositiveFreeSpace);
-+        if (curFlexRatio > 0.0f) {
-+          sumOfFlexRatios += curFlexRatio;
++        float curFlexWeight = aItems[i].GetFlexWeightToUse(havePositiveFreeSpace);
++        if (curFlexWeight > 0.0f) {
++          sumOfFlexWeights += curFlexWeight;
 +
-+          // Update the last nonzero flex ratio
-+          idxOfLastNonzeroFlexRatio = i;
++          // Update the last nonzero flex weight
++          idxOfLastNonzeroFlexWeight = i;
 +
-+          // Update our largest-flex-ratio tracking vars
-+          if (curFlexRatio > largestFlexRatio) {
-+            largestFlexRatio = curFlexRatio;
-+            numItemsWithLargestFlexRatio = 1;
-+          } else if (curFlexRatio == largestFlexRatio) {
-+            numItemsWithLargestFlexRatio++;
++          // Update our largest-flex-weight tracking vars
++          if (curFlexWeight > largestFlexWeight) {
++            largestFlexWeight = curFlexWeight;
++            numItemsWithLargestFlexWeight = 1;
++          } else if (curFlexWeight == largestFlexWeight) {
++            numItemsWithLargestFlexWeight++;
 +          }
 +        }
 +      }
 +
-+      if (sumOfFlexRatios != 0.0f) { // (no distribution if nothing is flexible)
++      if (sumOfFlexWeights != 0.0f) { // (no distribution if nothing is flexible)
 +        // Distribute!
-+        // (chipping away at sumOfFlexRatios & availableSpace as we go)
++        // (chipping away at sumOfFlexWeights & availableSpace as we go)
 +
 +        PR_LOG(nsFlexContainerFrameLM, PR_LOG_DEBUG,
 +               (" Distributing available space:"));
 +        for (PRUint32 i = 0; i < aItems.Length(); i++) {
 +          FlexItem& item = aItems[i];
-+          float curFlexRatio = item.GetFlexRatioToUse(havePositiveFreeSpace);
++          float curFlexWeight = item.GetFlexWeightToUse(havePositiveFreeSpace);
 +
-+          if (curFlexRatio > 0.0f &&
-+              sumOfFlexRatios > 0.0f) { // to deal with float rounding error
++          if (curFlexWeight > 0.0f &&
++              sumOfFlexWeights > 0.0f) { // to deal with float rounding error
 +
-+            // To avoid rounding issues, we subtract our current flex ratio &
++            // To avoid rounding issues, we subtract our current flex weight &
 +            // our sizeDelta from the totals (so that at the end, the remaining
 +            // free space gets entirely assigned to the final entry, with no
 +            // rounding issues.)
 +
 +            nscoord sizeDelta = 0;
-+            if (NS_finite(sumOfFlexRatios)) {
++            if (NS_finite(sumOfFlexWeights)) {
 +              // If this is the last flexible element, then assign it all the
 +              // remaining flexibility, so that no flexibility is left over.
 +              // (to account for floating-point rounding error.)
-+              if (i == idxOfLastNonzeroFlexRatio) {
-+                NS_WARN_IF_FALSE(fabs(sumOfFlexRatios - curFlexRatio) < 0.0001,
++              if (i == idxOfLastNonzeroFlexWeight) {
++                NS_WARN_IF_FALSE(fabs(sumOfFlexWeights - curFlexWeight) < 0.0001,
 +                                 "Especially large amount of floating-point "
 +                                 "error in computation of total flexibility");
-+                curFlexRatio = sumOfFlexRatios;
++                curFlexWeight = sumOfFlexWeights;
 +              }
 +
 +              sizeDelta = NSToCoordRound(availableFreeSpace *
-+                                         (curFlexRatio / sumOfFlexRatios));
-+              sumOfFlexRatios -= curFlexRatio;
-+            } else if (curFlexRatio == largestFlexRatio) {
++                                         (curFlexWeight / sumOfFlexWeights));
++              sumOfFlexWeights -= curFlexWeight;
++            } else if (curFlexWeight == largestFlexWeight) {
 +              sizeDelta = NSToCoordRound(availableFreeSpace /
-+                                         float(numItemsWithLargestFlexRatio));
-+              // Don't subtract from sumOfFlexRatios, since it (and potentially
-+              // curFlexRatio) is infinite.  Instead, we just decrement our
-+              // count of elements with the largest flex ratio.
-+              numItemsWithLargestFlexRatio--;
++                                         float(numItemsWithLargestFlexWeight));
++              // Don't subtract from sumOfFlexWeights, since it (and potentially
++              // curFlexWeight) is infinite.  Instead, we just decrement our
++              // count of elements with the largest flex weight.
++              numItemsWithLargestFlexWeight--;
 +            }
 +
 +            availableFreeSpace -= sizeDelta;
 +
 +            item.SetMainSize(item.GetMainSize() + sizeDelta);
 +            PR_LOG(nsFlexContainerFrameLM, PR_LOG_DEBUG,
 +                   ("  child %d receives %d, for a total of %d\n",
 +                    i, sizeDelta, item.GetMainSize()));
 +
 +          }
 +        }
-+        NS_ASSERTION(sumOfFlexRatios >= 0.0f,
++        NS_ASSERTION(sumOfFlexWeights >= 0.0f,
 +                     "total flex shouldn't be allowed to drop below 0");
 +      }
-+      NS_ABORT_IF_FALSE(sumOfFlexRatios == 0.0f ||
-+                        !NS_finite(sumOfFlexRatios),
++      NS_ABORT_IF_FALSE(sumOfFlexWeights == 0.0f ||
++                        !NS_finite(sumOfFlexWeights),
 +                        "Shouldn't have any flexibility left over");
 +    }
 +
 +    // Fix min/max violations:
 +    nscoord totalViolation = 0; // keeps track of adjustments for min/max
 +    PR_LOG(nsFlexContainerFrameLM, PR_LOG_DEBUG,
 +           (" Checking for violations:"));
 +