Bug 930218 part 2. Account for the parent's box-sizing whe figuring out the percentage height of a kid with an intrinsic ratio for purposes of determining the parent's shrink-wrap width. r=dbaron
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 08 Dec 2015 14:56:20 -0500
changeset 297591 38fbb8418ffcddc43061ec9b1e347efaede8e72f
parent 297590 6196e9f9d1392798458a1dc060afa5b2be49b002
child 297592 7d5dfdfe0150615d9ad01d2178ca43db0bf3645d
push id8824
push userraliiev@mozilla.com
push dateMon, 14 Dec 2015 20:18:56 +0000
treeherdermozilla-aurora@e2031358e2a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs930218
milestone45.0a1
Bug 930218 part 2. Account for the parent's box-sizing whe figuring out the percentage height of a kid with an intrinsic ratio for purposes of determining the parent's shrink-wrap width. r=dbaron
layout/base/nsLayoutUtils.cpp
layout/reftests/box-sizing/intrinsic-1g.html
layout/reftests/box-sizing/intrinsic-1h.html
layout/reftests/box-sizing/intrinsic-1i.html
layout/reftests/box-sizing/intrinsic-1j.html
layout/reftests/box-sizing/intrinsic-1k.html
layout/reftests/box-sizing/intrinsic-1l.html
layout/reftests/box-sizing/intrinsic-1m.html
layout/reftests/box-sizing/intrinsic-1n.html
layout/reftests/box-sizing/intrinsic-1o.html
layout/reftests/box-sizing/reftest.list
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -4199,18 +4199,19 @@ static nscoord
 GetBSizeTakenByBoxSizing(StyleBoxSizing aBoxSizing,
                          nsIFrame* aFrame,
                          bool aHorizontalAxis,
                          bool aIgnorePadding);
 
 // Only call on style coords for which GetAbsoluteCoord returned false.
 static bool
 GetPercentBSize(const nsStyleCoord& aStyle,
-                 nsIFrame* aFrame,
-                 nscoord& aResult)
+                nsIFrame* aFrame,
+                bool aHorizontalAxis,
+                nscoord& aResult)
 {
   if (eStyleUnit_Percent != aStyle.GetUnit() &&
       !aStyle.IsCalcUnit())
     return false;
 
   MOZ_ASSERT(!aStyle.IsCalcUnit() || aStyle.CalcHasPercent(),
              "GetAbsoluteCoord should have handled this");
 
@@ -4226,17 +4227,17 @@ GetPercentBSize(const nsStyleCoord& aSty
   }
 
   WritingMode wm = f->GetWritingMode();
 
   const nsStylePosition *pos = f->StylePosition();
   const nsStyleCoord& bSizeCoord = pos->BSize(wm);
   nscoord h;
   if (!GetAbsoluteCoord(bSizeCoord, h) &&
-      !GetPercentBSize(bSizeCoord, f, h)) {
+      !GetPercentBSize(bSizeCoord, f, aHorizontalAxis, h)) {
     NS_ASSERTION(bSizeCoord.GetUnit() == eStyleUnit_Auto ||
                  bSizeCoord.HasPercent(),
                  "unknown block-size unit");
     nsIAtom* fType = f->GetType();
     if (fType != nsGkAtoms::viewportFrame && fType != nsGkAtoms::canvasFrame &&
         fType != nsGkAtoms::pageContentFrame) {
       // There's no basis for the percentage height, so it acts like auto.
       // Should we consider a max-height < min-height pair a basis for
@@ -4256,38 +4257,46 @@ GetPercentBSize(const nsStyleCoord& aSty
       return false;
     }
   }
 
   const nsStyleCoord& maxBSizeCoord = pos->MaxBSize(wm);
 
   nscoord maxh;
   if (GetAbsoluteCoord(maxBSizeCoord, maxh) ||
-      GetPercentBSize(maxBSizeCoord, f, maxh)) {
+      GetPercentBSize(maxBSizeCoord, f, aHorizontalAxis, maxh)) {
     if (maxh < h)
       h = maxh;
   } else {
     NS_ASSERTION(maxBSizeCoord.GetUnit() == eStyleUnit_None ||
                  maxBSizeCoord.HasPercent(),
                  "unknown max block-size unit");
   }
 
   const nsStyleCoord& minBSizeCoord = pos->MinBSize(wm);
 
   nscoord minh;
   if (GetAbsoluteCoord(minBSizeCoord, minh) ||
-      GetPercentBSize(minBSizeCoord, f, minh)) {
+      GetPercentBSize(minBSizeCoord, f, aHorizontalAxis, minh)) {
     if (minh > h)
       h = minh;
   } else {
     NS_ASSERTION(minBSizeCoord.HasPercent() ||
                  minBSizeCoord.GetUnit() == eStyleUnit_Auto,
                  "unknown min block-size unit");
   }
 
+  // Now adjust h for box-sizing styles on the parent.  We never ignore padding
+  // here.  That could conceivably cause some problems with fieldsets (which are
+  // the one place that wants to ignore padding), but solving that here without
+  // hardcoding a check for f being a fieldset-content frame is a bit of a pain.
+  nscoord bSizeTakenByBoxSizing =
+    GetBSizeTakenByBoxSizing(pos->mBoxSizing, f, aHorizontalAxis, false);
+  h = std::max(0, h - bSizeTakenByBoxSizing);
+
   if (aStyle.IsCalcUnit()) {
     aResult = std::max(nsRuleNode::ComputeComputedCalc(aStyle, h), 0);
     return true;
   }
 
   aResult = NSToCoordRound(aStyle.GetPercentValue() * h);
   return true;
 }
@@ -4323,21 +4332,21 @@ GetBSizeTakenByBoxSizing(StyleBoxSizing 
         stylePadding.Get(aHorizontalAxis ? NS_SIDE_BOTTOM : NS_SIDE_RIGHT);
       nscoord pad;
       // XXXbz Calling GetPercentBSize on padding values looks bogus, since
       // percent padding is always a percentage of the inline-size of the
       // containing block.  We should perhaps just treat non-absolute paddings
       // here as 0 instead, except that in some cases the width may in fact be
       // known.  See bug 1231059.
       if (GetAbsoluteCoord(paddingStart, pad) ||
-          GetPercentBSize(paddingStart, aFrame, pad)) {
+          GetPercentBSize(paddingStart, aFrame, aHorizontalAxis, pad)) {
         bSizeTakenByBoxSizing += pad;
       }
       if (GetAbsoluteCoord(paddingEnd, pad) ||
-          GetPercentBSize(paddingEnd, aFrame, pad)) {
+          GetPercentBSize(paddingEnd, aFrame, aHorizontalAxis, pad)) {
         bSizeTakenByBoxSizing += pad;
       }
     }
     // fall through
   }
   case StyleBoxSizing::Content:
   default:
     break;
@@ -4706,31 +4715,31 @@ nsLayoutUtils::IntrinsicForAxis(Physical
             NS_FRAME_DESCENDANT_INTRINSIC_ISIZE_DEPENDS_ON_BSIZE);
 
         nscoord bSizeTakenByBoxSizing =
           GetBSizeTakenByBoxSizing(boxSizing, aFrame, horizontalAxis,
                                    aFlags & IGNORE_PADDING);
 
         nscoord h;
         if (GetAbsoluteCoord(styleBSize, h) ||
-            GetPercentBSize(styleBSize, aFrame, h)) {
+            GetPercentBSize(styleBSize, aFrame, horizontalAxis, h)) {
           h = std::max(0, h - bSizeTakenByBoxSizing);
           result = NSCoordMulDiv(h, ratioISize, ratioBSize);
         }
 
         if (GetAbsoluteCoord(styleMaxBSize, h) ||
-            GetPercentBSize(styleMaxBSize, aFrame, h)) {
+            GetPercentBSize(styleMaxBSize, aFrame, horizontalAxis, h)) {
           h = std::max(0, h - bSizeTakenByBoxSizing);
           nscoord maxISize = NSCoordMulDiv(h, ratioISize, ratioBSize);
           if (maxISize < result)
             result = maxISize;
         }
 
         if (GetAbsoluteCoord(styleMinBSize, h) ||
-            GetPercentBSize(styleMinBSize, aFrame, h)) {
+            GetPercentBSize(styleMinBSize, aFrame, horizontalAxis, h)) {
           h = std::max(0, h - bSizeTakenByBoxSizing);
           nscoord minISize = NSCoordMulDiv(h, ratioISize, ratioBSize);
           if (minISize > result)
             result = minISize;
         }
       }
     }
   }
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1g.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: border-box; height: 200px;
+              border: 40px transparent solid">
+    <img src="lime100x100.png"
+         style="height: 100%; display: block; visibility: hidden;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1h.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: padding-box; height: 120px;
+              border: 40px transparent solid">
+    <img src="lime100x100.png"
+         style="height: 100%; display: block; visibility: hidden;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1i.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: border-box; height: 200px;
+              border: 25px transparent solid">
+    <div style="height: 100%; box-sizing: border-box;
+                border: 15px transparent solid;">
+         <img src="lime100x100.png"
+              style="height: 100%; display: block; visibility: hidden;">
+    </div>
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1j.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: border-box; height: 200px;
+              border: 40px transparent solid">
+    <!-- We need to be taller than intrinsic height, so use a min-height -->
+    <img src="lime100x100.png"
+         style="min-height: 100%; display: block; visibility: hidden;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1k.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: padding-box; height: 120px;
+              border: 40px transparent solid">
+    <!-- We need to be taller than intrinsic height, so use a min-height -->
+    <img src="lime100x100.png"
+         style="min-height: 100%; display: block; visibility: hidden;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1l.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: border-box; height: 200px;
+              border: 25px transparent solid">
+    <div style="height: 100%; box-sizing: border-box;
+                border: 15px transparent solid;">
+      <!-- We need to be taller than intrinsic height, so use a min-height -->
+      <img src="lime100x100.png"
+           style="min-height: 100%; display: block; visibility: hidden;">
+    </div>
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1m.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: border-box; height: 200px;
+              border: 80px transparent solid">
+    <!-- We need to be shorter than intrinsic height, so use a max-height -->
+    <img src="lime100x100.png"
+         style="max-height: 100%; display: block; visibility: hidden;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1n.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: padding-box; height: 40px;
+              border: 80px transparent solid">
+    <!-- We need to be shorter than intrinsic height, so use a max-height -->
+    <img src="lime100x100.png"
+         style="max-height: 100%; display: block; visibility: hidden;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1o.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue;
+              box-sizing: border-box; height: 200px;
+              border: 50px transparent solid">
+    <div style="height: 100%; box-sizing: border-box;
+                border: 30px transparent solid;">
+      <!-- We need to be shorter than intrinsic height, so use a max-height -->
+      <img src="lime100x100.png"
+           style="max-height: 100%; display: block; visibility: hidden;">
+    </div>
+  </div>
+</body>
--- a/layout/reftests/box-sizing/reftest.list
+++ b/layout/reftests/box-sizing/reftest.list
@@ -1,7 +1,16 @@
 == intrinsic-1a.html intrinsic-1-ref.html
 == intrinsic-1b.html intrinsic-1-ref.html
 == intrinsic-1c.html intrinsic-1-ref.html
 == intrinsic-1d.html intrinsic-1-ref.html
 == intrinsic-1e.html intrinsic-1-ref.html
 == intrinsic-1f.html intrinsic-1-ref.html
+== intrinsic-1g.html intrinsic-1-ref.html
+== intrinsic-1h.html intrinsic-1-ref.html
+== intrinsic-1i.html intrinsic-1-ref.html
+== intrinsic-1j.html intrinsic-1-ref.html
+== intrinsic-1k.html intrinsic-1-ref.html
+== intrinsic-1l.html intrinsic-1-ref.html
+== intrinsic-1m.html intrinsic-1-ref.html
+== intrinsic-1n.html intrinsic-1-ref.html
+== intrinsic-1o.html intrinsic-1-ref.html
 == computed-size-reporting.html computed-size-reporting-ref.html