Bug 1501109 Part 1: Change Flex API growth state to match layout algorithm, and use enums from webidl. r=dholbert
authorBrad Werth <bwerth@mozilla.com>
Tue, 23 Oct 2018 16:23:37 +0000
changeset 490949 19472cba78cc8439d0b1007ce1d4a8b3f2fcd592
parent 490948 e9bf22cdf91a5de5cf8ebafe7f43bac7646d6878
child 490950 ec3c914d6136944e6803e1596d383d9cd64fba64
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersdholbert
bugs1501109
milestone65.0a1
Bug 1501109 Part 1: Change Flex API growth state to match layout algorithm, and use enums from webidl. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D9454
dom/chrome-webidl/Flex.webidl
dom/flex/FlexLineValues.cpp
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsFlexContainerFrame.h
--- a/dom/chrome-webidl/Flex.webidl
+++ b/dom/chrome-webidl/Flex.webidl
@@ -34,20 +34,27 @@ interface Flex
   /**
    * The physical direction in which successive flex lines are placed
    * in this flex container (if it is or were multi-line).
    */
   readonly attribute FlexPhysicalDirection crossAxisDirection;
 };
 
 /**
- * Lines with items that have been shrunk are shrinking; with items
- * that have grown are growing, and all others are unchanged.
+ * This indicates which flex factor (flex-grow vs. flex-shrink) the
+ * flex layout algorithm uses internally when resolving flexible sizes
+ * in a given flex line, per flexbox spec section 9.7 step 1. Note that
+ * this value doesn't necessarily mean that any items on this line
+ * are *actually* growing (or shrinking).  This simply indicates what
+ * the layout algorithm "wants" to do, based on the free space -- 
+ * and items will stretch from their flex base size in the corresponding
+ * direction, if permitted by their min/max constraints and their
+ * corresponding flex factor.
  */
-enum FlexLineGrowthState { "unchanged", "shrinking", "growing" };
+enum FlexLineGrowthState { "shrinking", "growing" };
 
 [ChromeOnly]
 interface FlexLineValues
 {
   readonly attribute FlexLineGrowthState growthState;
   readonly attribute double crossStart;
   readonly attribute double crossSize;
 
--- a/dom/flex/FlexLineValues.cpp
+++ b/dom/flex/FlexLineValues.cpp
@@ -25,28 +25,17 @@ FlexLineValues::FlexLineValues(Flex* aPa
                                const ComputedFlexLineInfo* aLine)
   : mParent(aParent)
 {
   MOZ_ASSERT(aLine,
     "Should never be instantiated with a null ComputedFlexLineInfo.");
 
   // Eagerly copy values from aLine, because we're not
   // going to keep it around.
-  switch (aLine->mGrowthState) {
-    case ComputedFlexLineInfo::GrowthState::SHRINKING:
-      mGrowthState = FlexLineGrowthState::Shrinking;
-      break;
-
-    case ComputedFlexLineInfo::GrowthState::GROWING:
-      mGrowthState = FlexLineGrowthState::Growing;
-      break;
-
-    default:
-      mGrowthState = FlexLineGrowthState::Unchanged;
-  };
+  mGrowthState = aLine->mGrowthState;
 
   // Convert all the app unit values into css pixels.
   mCrossStart = nsPresContext::AppUnitsToDoubleCSSPixels(
     aLine->mCrossStart);
   mCrossSize = nsPresContext::AppUnitsToDoubleCSSPixels(
     aLine->mCrossSize);
   mFirstBaselineOffset = nsPresContext::AppUnitsToDoubleCSSPixels(
     aLine->mFirstBaselineOffset);
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -2638,16 +2638,22 @@ FlexLine::ResolveFlexibleLengths(nscoord
       aLineInfo->mItems[itemIndex].mMainDeltaSize = 0;
     }
   }
 
   // Determine whether we're going to be growing or shrinking items.
   const bool isUsingFlexGrow =
     (mTotalOuterHypotheticalMainSize < aFlexContainerMainSize);
 
+  if (aLineInfo) {
+    aLineInfo->mGrowthState = isUsingFlexGrow ?
+                              mozilla::dom::FlexLineGrowthState::Growing :
+                              mozilla::dom::FlexLineGrowthState::Shrinking;
+  }
+
   // Do an "early freeze" for flex items that obviously can't flex in the
   // direction we've chosen:
   FreezeItemsEarly(isUsingFlexGrow, aLineInfo);
 
   if ((mNumFrozenItems == mNumItems) && !aLineInfo) {
     // All our items are frozen, so we have no flexible lengths to resolve,
     // and we aren't being asked to generate computed line info.
     return;
@@ -2867,40 +2873,16 @@ FlexLine::ResolveFlexibleLengths(nscoord
               // actually changed, since the size of the item will be clamped
               // to min and max values later in this pass. That's intentional,
               // since we want to report the value that the sizing algorithm
               // tried to stretch or shrink the item.
               nscoord deltaSize = item->GetMainSize() -
                 aLineInfo->mItems[itemIndex].mMainBaseSize;
 
               aLineInfo->mItems[itemIndex].mMainDeltaSize = deltaSize;
-              // If any (unfrozen) item on the line is growing, we mark the
-              // aLineInfo structure; likewise if any item is shrinking.
-              // (Note: a line can't contain a mix of items that are growing
-              // and shrinking. Also, the sign of any delta should match the
-              // type of flex factor we're using [grow vs shrink].)
-              if (deltaSize > 0) {
-                MOZ_ASSERT(isUsingFlexGrow,
-                           "Unfrozen items can only grow if we're "
-                           "distributing (positive) space with flex-grow");
-                MOZ_ASSERT(aLineInfo->mGrowthState !=
-                           ComputedFlexLineInfo::GrowthState::SHRINKING,
-                           "shouldn't flip flop from shrinking to growing");
-                aLineInfo->mGrowthState =
-                  ComputedFlexLineInfo::GrowthState::GROWING;
-              } else if (deltaSize < 0) {
-                MOZ_ASSERT(!isUsingFlexGrow,
-                           "Unfrozen items can only shrink if we're "
-                           "distributing (negative) space with flex-shrink");
-                MOZ_ASSERT(aLineInfo->mGrowthState !=
-                           ComputedFlexLineInfo::GrowthState::GROWING,
-                           "shouldn't flip flop from growing to shrinking");
-                aLineInfo->mGrowthState =
-                  ComputedFlexLineInfo::GrowthState::SHRINKING;
-              }
             }
           }
         }
       }
     }
 
     // Fix min/max violations:
     nscoord totalViolation = 0; // keeps track of adjustments for min/max
@@ -4765,26 +4747,20 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
       ConvertAxisOrientationTypeToAPIEnum(mainAxis);
     containerInfo->mCrossAxisDirection =
       ConvertAxisOrientationTypeToAPIEnum(crossAxis);
 
     for (const FlexLine* line = lines.getFirst(); line;
          line = line->getNext()) {
       ComputedFlexLineInfo* lineInfo =
         containerInfo->mLines.AppendElement();
-      // Most lineInfo properties will be set later, but we set
-      // mGrowthState to UNCHANGED here because it may be later
-      // modified by ResolveFlexibleLengths().
-      lineInfo->mGrowthState =
-        ComputedFlexLineInfo::GrowthState::UNCHANGED;
-
-      // The remaining lineInfo properties will be filled out at the
-      // end of this function, when we have real values. But we still
-      // add all the items here, so we can capture computed data for
-      // each item.
+      // Most of the remaining lineInfo properties will be filled out at the
+      // end of this function (some will be provided by other functions),
+      // when we have real values. But we still add all the items here, so
+      // we can capture computed data for each item as we proceed.
       for (const FlexItem* item = line->GetFirstItem(); item;
            item = item->getNext()) {
         nsIFrame* frame = item->Frame();
 
         // The frame may be for an element, or it may be for an
         // anonymous flex item, e.g. wrapping one or more text nodes.
         // DevTools wants the content node for the actual child in
         // the DOM tree, so we descend through anonymous boxes.
--- a/layout/generic/nsFlexContainerFrame.h
+++ b/layout/generic/nsFlexContainerFrame.h
@@ -58,21 +58,17 @@ struct ComputedFlexItemInfo
 
 struct ComputedFlexLineInfo
 {
   nsTArray<ComputedFlexItemInfo> mItems;
   nscoord mCrossStart;
   nscoord mCrossSize;
   nscoord mFirstBaselineOffset;
   nscoord mLastBaselineOffset;
-  enum GrowthState {
-    UNCHANGED,
-    SHRINKING,
-    GROWING,
-  } mGrowthState;
+  mozilla::dom::FlexLineGrowthState mGrowthState;
 };
 
 struct ComputedFlexContainerInfo
 {
   nsTArray<ComputedFlexLineInfo> mLines;
   mozilla::dom::FlexPhysicalDirection mMainAxisDirection;
   mozilla::dom::FlexPhysicalDirection mCrossAxisDirection;
 };