Bug 921522 - Use already-established flex container content-box main size to determine packing space, instead of checking reflow state. r=mats, a=lsblakk
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 07 Oct 2013 08:37:26 -0400
changeset 155652 5532bfeb1a1755252a3b2aebd8c14be9bb509698
parent 155651 1767b159729a35624a535ba2e209e6143f1ef69e
child 155653 373bbcc04658cd26dcc4bdafe33f6cf9ea5838ff
push id4357
push userryanvm@gmail.com
push dateMon, 07 Oct 2013 12:39:17 +0000
treeherdermozilla-aurora@5933872ba6ba [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmats, lsblakk
bugs921522
milestone26.0a2
Bug 921522 - Use already-established flex container content-box main size to determine packing space, instead of checking reflow state. r=mats, a=lsblakk
layout/generic/nsFlexContainerFrame.cpp
layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1.xhtml
layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1a.xhtml
layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1b.xhtml
layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1.xhtml
layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1a.xhtml
layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1b.xhtml
layout/reftests/w3c-css/submitted/flexbox/reftest.list
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -963,17 +963,18 @@ protected:
 };
 
 // Tracks our position in the main axis, when we're laying out flex items.
 class MOZ_STACK_CLASS MainAxisPositionTracker : public PositionTracker {
 public:
   MainAxisPositionTracker(nsFlexContainerFrame* aFlexContainerFrame,
                           const FlexboxAxisTracker& aAxisTracker,
                           const nsHTMLReflowState& aReflowState,
-                          const nsTArray<FlexItem>& aItems);
+                          const nsTArray<FlexItem>& aItems,
+                          nscoord aContentBoxMainSize);
 
   ~MainAxisPositionTracker() {
     MOZ_ASSERT(mNumPackingSpacesRemaining == 0,
                "miscounted the number of packing spaces");
     MOZ_ASSERT(mNumAutoMarginsInMainAxis == 0,
                "miscounted the number of auto margins");
   }
 
@@ -1449,45 +1450,38 @@ nsFlexContainerFrame::ResolveFlexibleLen
   }
 #endif // DEBUG
 }
 
 MainAxisPositionTracker::
   MainAxisPositionTracker(nsFlexContainerFrame* aFlexContainerFrame,
                           const FlexboxAxisTracker& aAxisTracker,
                           const nsHTMLReflowState& aReflowState,
-                          const nsTArray<FlexItem>& aItems)
+                          const nsTArray<FlexItem>& aItems,
+                          nscoord aContentBoxMainSize)
   : PositionTracker(aAxisTracker.GetMainAxis()),
+    mPackingSpaceRemaining(aContentBoxMainSize), // we chip away at this below
     mNumAutoMarginsInMainAxis(0),
     mNumPackingSpacesRemaining(0)
 {
   MOZ_ASSERT(aReflowState.frame == aFlexContainerFrame,
              "Expecting the reflow state for the flex container frame");
 
   // Step over flex container's own main-start border/padding.
   // XXXdholbert Check GetSkipSides() here when we support pagination.
   EnterMargin(aReflowState.mComputedBorderPadding);
 
-  // Set up our state for managing packing space & auto margins.
-  //   * If our main-size is unconstrained, then we just shrinkwrap our
-  // contents, and we don't have any packing space.
-  //   * Otherwise, we subtract our items' margin-box main-sizes from our
-  // computed main-size to get our available packing space.
-  mPackingSpaceRemaining =
-    aAxisTracker.GetMainComponent(nsSize(aReflowState.ComputedWidth(),
-                                         aReflowState.ComputedHeight()));
-  if (mPackingSpaceRemaining == NS_UNCONSTRAINEDSIZE) {
-    mPackingSpaceRemaining = 0;
-  } else {
-    for (uint32_t i = 0; i < aItems.Length(); i++) {
-      nscoord itemMarginBoxMainSize =
-        aItems[i].GetMainSize() +
-        aItems[i].GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
-      mPackingSpaceRemaining -= itemMarginBoxMainSize;
-    }
+  // mPackingSpaceRemaining is initialized to the container's main size.  Now
+  // we'll subtract out the main sizes of our flex items, so that it ends up
+  // with the *actual* amount of packing space.
+  for (uint32_t i = 0; i < aItems.Length(); i++) {
+    nscoord itemMarginBoxMainSize =
+      aItems[i].GetMainSize() +
+      aItems[i].GetMarginBorderPaddingSizeInAxis(aAxisTracker.GetMainAxis());
+    mPackingSpaceRemaining -= itemMarginBoxMainSize;
   }
 
   if (mPackingSpaceRemaining > 0) {
     for (uint32_t i = 0; i < aItems.Length(); i++) {
       mNumAutoMarginsInMainAxis += aItems[i].GetNumAutoMarginsInAxis(mAxis);
     }
   }
 
@@ -2272,17 +2266,18 @@ nsFlexContainerFrame::Reflow(nsPresConte
   if (flexContainerAscent != nscoord_MIN) {
     // Add top borderpadding, so our ascent is w.r.t. border-box
     flexContainerAscent += aReflowState.mComputedBorderPadding.top;
   }
 
   // Main-Axis Alignment - Flexbox spec section 9.5
   // ==============================================
   MainAxisPositionTracker mainAxisPosnTracker(this, axisTracker,
-                                              aReflowState, items);
+                                              aReflowState, items,
+                                              contentBoxMainSize);
   for (uint32_t i = 0; i < items.Length(); ++i) {
     PositionItemInMainAxis(mainAxisPosnTracker, items[i]);
   }
 
   // Cross-Axis Alignment - Flexbox spec section 9.6
   // ===============================================
   for (uint32_t i = 0; i < items.Length(); ++i) {
     PositionItemInCrossAxis(crossAxisPosnTracker.GetPosition(),
rename from layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1.xhtml
rename to layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1a.xhtml
--- a/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1.xhtml
+++ b/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1a.xhtml
@@ -1,15 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
      Any copyright is dedicated to the Public Domain.
      http://creativecommons.org/publicdomain/zero/1.0/
 -->
-<!-- Testcase with a variety of 'display: flex' examples
-     testing each possible value of the 'justify-content' property. -->
+<!-- Testcase with a series of horizontal flex containers, testing each
+     possible value of the 'justify-content' property. -->
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <title>CSS Test: Testing 'justify-content' in a horizontal flex container</title>
     <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com"/>
     <link rel="help" href="http://www.w3.org/TR/css3-flexbox/#justify-content-property"/>
     <link rel="match" href="flexbox-justify-content-horiz-1-ref.xhtml"/>
     <style>
       div.flexbox {
copy from layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1.xhtml
copy to layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1b.xhtml
--- a/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1.xhtml
+++ b/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-horiz-1b.xhtml
@@ -1,26 +1,32 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
      Any copyright is dedicated to the Public Domain.
      http://creativecommons.org/publicdomain/zero/1.0/
 -->
-<!-- Testcase with a variety of 'display: flex' examples
-     testing each possible value of the 'justify-content' property. -->
+<!-- Testcase with a series of horizontal flex containers, testing each
+     possible value of the 'justify-content' property. The flex containers'
+     widths are determined by their "min-width" property. -->
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
-    <title>CSS Test: Testing 'justify-content' in a horizontal flex container</title>
+    <title>CSS Test: Testing 'justify-content' in a horizontal flex container with "min-width"</title>
     <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com"/>
     <link rel="help" href="http://www.w3.org/TR/css3-flexbox/#justify-content-property"/>
     <link rel="match" href="flexbox-justify-content-horiz-1-ref.xhtml"/>
     <style>
       div.flexbox {
-        width: 200px;
+        min-width: 200px;
         display: flex;
         margin-bottom: 2px;
+
+        /* Use "float" to trigger intrinsic sizing, which in this case will
+            make us clamp to "min-width": */
+        float: left;
+        clear: both;
       }
       div.a {
         height: 20px;
         flex: 0 10px;
         background: lightgreen;
       }
       div.b {
         height: 20px;
rename from layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1.xhtml
rename to layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1a.xhtml
--- a/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1.xhtml
+++ b/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1a.xhtml
@@ -1,15 +1,15 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
      Any copyright is dedicated to the Public Domain.
      http://creativecommons.org/publicdomain/zero/1.0/
 -->
-<!-- Testcase with a series of flex containers, testing each possible value of
-     the 'justify-content' property. -->
+<!-- Testcase with a series of vertical flex containers, testing each
+     possible value of the 'justify-content' property. -->
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <title>CSS Test: Testing 'justify-content' in a vertical flex container</title>
     <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com"/>
     <link rel="help" href="http://www.w3.org/TR/css3-flexbox/#justify-content-property"/>
     <link rel="match" href="flexbox-justify-content-vert-1-ref.xhtml"/>
     <style>
       div.flexbox {
copy from layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1.xhtml
copy to layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1b.xhtml
--- a/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1.xhtml
+++ b/layout/reftests/w3c-css/submitted/flexbox/flexbox-justify-content-vert-1b.xhtml
@@ -1,24 +1,25 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
      Any copyright is dedicated to the Public Domain.
      http://creativecommons.org/publicdomain/zero/1.0/
 -->
-<!-- Testcase with a series of flex containers, testing each possible value of
-     the 'justify-content' property. -->
+<!-- Testcase with a series of vertical flex containers, testing each
+     possible value of the 'justify-content' property. The flex containers'
+     heights are determined by their "min-height" property. -->
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
-    <title>CSS Test: Testing 'justify-content' in a vertical flex container</title>
+    <title>CSS Test: Testing 'justify-content' in a vertical flex container with "min-height"</title>
     <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com"/>
     <link rel="help" href="http://www.w3.org/TR/css3-flexbox/#justify-content-property"/>
     <link rel="match" href="flexbox-justify-content-vert-1-ref.xhtml"/>
     <style>
       div.flexbox {
-        height: 200px;
+        min-height: 200px;
         display: flex;
         flex-direction: column;
         margin-right: 2px;
         float: left;
       }
       div.a {
         width: 20px;
         flex: 0 10px;
--- a/layout/reftests/w3c-css/submitted/flexbox/reftest.list
+++ b/layout/reftests/w3c-css/submitted/flexbox/reftest.list
@@ -45,22 +45,24 @@ fuzzy-if(Android,158,32) == flexbox-alig
 == flexbox-basic-video-vert-1.xhtml     flexbox-basic-video-vert-1-ref.xhtml
 
 # Tests for flex items as (pseudo) stacking contexts
 == flexbox-items-as-stacking-contexts-1.xhtml flexbox-items-as-stacking-contexts-1-ref.xhtml
 == flexbox-items-as-stacking-contexts-2.html flexbox-items-as-stacking-contexts-2-ref.html
 == flexbox-items-as-stacking-contexts-3.html flexbox-items-as-stacking-contexts-3-ref.html
 
 # Tests for main-axis alignment (jusify-content property)
-== flexbox-justify-content-horiz-1.xhtml flexbox-justify-content-horiz-1-ref.xhtml
+== flexbox-justify-content-horiz-1a.xhtml flexbox-justify-content-horiz-1-ref.xhtml
+== flexbox-justify-content-horiz-1b.xhtml flexbox-justify-content-horiz-1-ref.xhtml
 == flexbox-justify-content-horiz-2.xhtml flexbox-justify-content-horiz-2-ref.xhtml
 == flexbox-justify-content-horiz-3.xhtml flexbox-justify-content-horiz-3-ref.xhtml
 == flexbox-justify-content-horiz-4.xhtml flexbox-justify-content-horiz-4-ref.xhtml
 == flexbox-justify-content-horiz-5.xhtml flexbox-justify-content-horiz-5-ref.xhtml
-== flexbox-justify-content-vert-1.xhtml flexbox-justify-content-vert-1-ref.xhtml
+== flexbox-justify-content-vert-1a.xhtml flexbox-justify-content-vert-1-ref.xhtml
+== flexbox-justify-content-vert-1b.xhtml flexbox-justify-content-vert-1-ref.xhtml
 == flexbox-justify-content-vert-2.xhtml flexbox-justify-content-vert-2-ref.xhtml
 == flexbox-justify-content-vert-3.xhtml flexbox-justify-content-vert-3-ref.xhtml
 == flexbox-justify-content-vert-4.xhtml flexbox-justify-content-vert-4-ref.xhtml
 == flexbox-justify-content-vert-5.xhtml flexbox-justify-content-vert-5-ref.xhtml
 
 # Tests for flexbox with margin, border, and/or padding on flex items
 == flexbox-margin-auto-horiz-1.xhtml     flexbox-margin-auto-horiz-1-ref.xhtml
 == flexbox-margin-auto-horiz-2.xhtml     flexbox-margin-auto-horiz-2-ref.xhtml