Bug 801116. Take box-sizing into account when computing intrinsic width based on a fixed height and an intrinsic ratio. r=dholbert
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 15 Oct 2012 23:12:03 -0400
changeset 110503 2297babdb84d22a4ae731d3592658350a1c0794d
parent 110502 ef03cd944ba8930ce7bb781016f7371f062a6fa1
child 110504 c317ac04497a6e9ade1d6650f746d72aa6a61035
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersdholbert
bugs801116
milestone19.0a1
Bug 801116. Take box-sizing into account when computing intrinsic width based on a fixed height and an intrinsic ratio. r=dholbert
layout/base/nsLayoutUtils.cpp
layout/reftests/box-sizing/intrinsic-1-ref.html
layout/reftests/box-sizing/intrinsic-1a.html
layout/reftests/box-sizing/intrinsic-1b.html
layout/reftests/box-sizing/intrinsic-1c.html
layout/reftests/box-sizing/intrinsic-1d.html
layout/reftests/box-sizing/intrinsic-1e.html
layout/reftests/box-sizing/intrinsic-1f.html
layout/reftests/box-sizing/lime100x100.png
layout/reftests/box-sizing/reftest.list
layout/reftests/reftest.list
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2550,36 +2550,66 @@ nsLayoutUtils::IntrinsicForContainer(nsR
         !(styleMinHeight.GetUnit() == eStyleUnit_Auto || 
           (styleMinHeight.GetUnit() == eStyleUnit_Coord &&
            styleMinHeight.GetCoordValue() == 0)) ||
         styleMaxHeight.GetUnit() != eStyleUnit_None) {
 
       nsSize ratio = aFrame->GetIntrinsicRatio();
 
       if (ratio.height != 0) {
+        nscoord heightTakenByBoxSizing = 0;
+        switch (boxSizing) {
+        case NS_STYLE_BOX_SIZING_BORDER: {
+          const nsStyleBorder* styleBorder = aFrame->GetStyleBorder();
+          heightTakenByBoxSizing +=
+            styleBorder->GetComputedBorder().TopBottom();
+          // fall through
+        }
+        case NS_STYLE_BOX_SIZING_PADDING: {
+          const nsStylePadding* stylePadding = aFrame->GetStylePadding();
+          nscoord pad;
+          if (GetAbsoluteCoord(stylePadding->mPadding.GetTop(), pad) ||
+              GetPercentHeight(stylePadding->mPadding.GetTop(), aFrame, pad)) {
+            heightTakenByBoxSizing += pad;
+          }
+          if (GetAbsoluteCoord(stylePadding->mPadding.GetBottom(), pad) ||
+              GetPercentHeight(stylePadding->mPadding.GetBottom(), aFrame, pad)) {
+            heightTakenByBoxSizing += pad;
+          }
+          // fall through
+        }
+        case NS_STYLE_BOX_SIZING_CONTENT:
+        default:
+          break;
+        }
 
         nscoord h;
         if (GetAbsoluteCoord(styleHeight, h) ||
             GetPercentHeight(styleHeight, aFrame, h)) {
+          h = NS_MAX(0, h - heightTakenByBoxSizing);
           result =
             NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
         }
 
         if (GetAbsoluteCoord(styleMaxHeight, h) ||
             GetPercentHeight(styleMaxHeight, aFrame, h)) {
-          h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
-          if (h < result)
-            result = h;
+          h = NS_MAX(0, h - heightTakenByBoxSizing);
+          nscoord maxHeight =
+            NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
+          if (maxHeight < result)
+            result = maxHeight;
         }
 
         if (GetAbsoluteCoord(styleMinHeight, h) ||
             GetPercentHeight(styleMinHeight, aFrame, h)) {
-          h = NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
-          if (h > result)
-            result = h;
+          h = NS_MAX(0, h - heightTakenByBoxSizing);
+          nscoord minHeight =
+            NSToCoordRound(h * (float(ratio.width) / float(ratio.height)));
+          if (minHeight > result)
+            result = minHeight;
         }
       }
     }
   }
 
   if (aFrame->GetType() == nsGkAtoms::tableFrame) {
     // Tables can't shrink smaller than their intrinsic minimum width,
     // no matter what.
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue; width: 200px;
+              height: 200px">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1a.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue">
+    <img src="lime100x100.png"
+         style="height: 200px; display: block; visibility: hidden;
+                padding: 30px;
+                -moz-box-sizing: padding-box;
+                box-sizing: padding-box;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1b.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue; height: 200px">
+    <img src="lime100x100.png"
+         style="height: 200px; display: block; visibility: hidden;
+                padding: 15% 30px;
+                -moz-box-sizing: padding-box;
+                box-sizing: padding-box;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1c.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue">
+    <img src="lime100x100.png"
+         style="height: 200px; display: block; visibility: hidden;
+                padding: 30px; border: 20px solid;
+                -moz-box-sizing: border-box;
+                box-sizing: border-box;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1d.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue; height: 200px">
+    <img src="lime100x100.png"
+         style="height: 200px; display: block; visibility: hidden;
+                padding: calc(15%) 30px;
+                -moz-box-sizing: padding-box;
+                box-sizing: padding-box;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1e.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue; height: 200px">
+    <img src="lime100x100.png"
+         style="height: 200px; display: block; visibility: hidden;
+                padding: calc(10% + 10px) 30px;
+                -moz-box-sizing: padding-box;
+                box-sizing: padding-box;">
+  </div>
+</body>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/intrinsic-1f.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<body>
+  <div style="display: inline-block; background: blue">
+    <img src="lime100x100.png"
+         style="height: 200px; display: block; visibility: hidden;
+                padding: calc(30px);
+                -moz-box-sizing: padding-box;
+                box-sizing: padding-box;">
+  </div>
+</body>
new file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..c9bb37594320c6e6a094d52548cdcd4e046c2a4b
GIT binary patch
literal 232
zc%17D@N?(olHy`uVBq!ia0vp^DIm<j1|$m}O$`B3jKx9jP7LeL$-D$|7J0fjhE&{o
zdy$csfq~=jhUWV73C$Dy4n@uMDOt9Sp`(F8P(Xo+$;F|8gPv>-0Y)f$-}cwOOvf^6
SU*!N@%i!ti=d#Wzp$P!tlsJ6=
new file mode 100644
--- /dev/null
+++ b/layout/reftests/box-sizing/reftest.list
@@ -0,0 +1,6 @@
+== intrinsic-1a.html intrinsic-1-ref.html
+== intrinsic-1b.html intrinsic-1-ref.html
+== intrinsic-1c.html intrinsic-1-ref.html
+fails == intrinsic-1d.html intrinsic-1-ref.html # Bug 801994
+fails == intrinsic-1e.html intrinsic-1-ref.html # Bug 801994
+== intrinsic-1f.html intrinsic-1-ref.html
--- a/layout/reftests/reftest.list
+++ b/layout/reftests/reftest.list
@@ -317,8 +317,11 @@ include ../xul/base/src/grid/reftests/re
 include z-index/reftest.list
 
 # reftest(s) to verify content bugfixes
 include ../../content/html/document/reftests/reftests.list
 include ../../content/html/content/reftests/reftest.list
 
 # editor/
 include ../../editor/reftests/reftest.list
+
+# box-sizing
+include box-sizing/reftest.list