Bug 801994. Fix intrinsic width determination in cases when we have an intrinsic ratio and our height is styled as calc() with percentages. r=dholbert
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 17 Oct 2012 17:01:56 -0400
changeset 110725 91e2659887c63a431ce0d07ec326a8df0664d644
parent 110724 4f40efa904b00ea9250e97c1ad781b96f2e21477
child 110726 e711e4cdb4d5cec821d29f17c2f552cb35297303
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersdholbert
bugs801994
milestone19.0a1
Bug 801994. Fix intrinsic width determination in cases when we have an intrinsic ratio and our height is styled as calc() with percentages. r=dholbert
layout/base/nsLayoutUtils.cpp
layout/reftests/box-sizing/reftest.list
layout/reftests/bugs/801994-1-ref.html
layout/reftests/bugs/801994-1.html
layout/reftests/bugs/reftest.list
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -2321,24 +2321,29 @@ static bool GetAbsoluteCoord(const nsSty
   if (eStyleUnit_Coord != aStyle.GetUnit())
     return false;
 
   aResult = aStyle.GetCoordValue();
   NS_ASSERTION(aResult >= 0, "negative widths not allowed");
   return true;
 }
 
+// Only call on style coords for which GetAbsoluteCoord returned false.
 static bool
 GetPercentHeight(const nsStyleCoord& aStyle,
                  nsIFrame* aFrame,
                  nscoord& aResult)
 {
-  if (eStyleUnit_Percent != aStyle.GetUnit())
+  if (eStyleUnit_Percent != aStyle.GetUnit() &&
+      !aStyle.IsCalcUnit())
     return false;
 
+  MOZ_ASSERT(!aStyle.IsCalcUnit() || aStyle.CalcHasPercent(),
+             "GetAbsoluteCoord should have handled this");
+
   nsIFrame *f = aFrame->GetContainingBlock();
   if (!f) {
     NS_NOTREACHED("top of frame tree not a containing block");
     return false;
   }
 
   const nsStylePosition *pos = f->GetStylePosition();
   nscoord h;
@@ -2386,16 +2391,21 @@ GetPercentHeight(const nsStyleCoord& aSt
     if (minh > h)
       h = minh;
   } else {
     NS_ASSERTION(pos->mMinHeight.HasPercent() ||
                  pos->mMinHeight.GetUnit() == eStyleUnit_Auto,
                  "unknown min-height unit");
   }
 
+  if (aStyle.IsCalcUnit()) {
+    aResult = NS_MAX(nsRuleNode::ComputeComputedCalc(aStyle, h), 0);
+    return true;
+  }
+
   aResult = NSToCoordRound(aStyle.GetPercentValue() * h);
   return true;
 }
 
 // Handles only -moz-max-content and -moz-min-content, and
 // -moz-fit-content for min-width and max-width, since the others
 // (-moz-fit-content for width, and -moz-available) have no effect on
 // intrinsic widths.
--- a/layout/reftests/box-sizing/reftest.list
+++ b/layout/reftests/box-sizing/reftest.list
@@ -1,6 +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-1d.html intrinsic-1-ref.html
+== intrinsic-1e.html intrinsic-1-ref.html
 == intrinsic-1f.html intrinsic-1-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/801994-1-ref.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<div style="height: 200px; float: left; background: green">
+  <img style="height: 120px; opacity: 0.5;" src="solidblue.png">
+</div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/bugs/801994-1.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html>
+<div style="height: 200px; float: left; background: green">
+  <img style="height: calc(50% + 20px); opacity: 0.5;" src="solidblue.png">
+</div>
--- a/layout/reftests/bugs/reftest.list
+++ b/layout/reftests/bugs/reftest.list
@@ -1720,8 +1720,9 @@ fuzzy-if(true,17,5859) == 759036-2.html 
 == 776265-1d.html 776265-1-ref.html
 == 776265-2a.html 776265-2-ref.html
 == 776265-2b.html 776265-2-ref.html
 == 776265-2c.html 776265-2-ref.html
 == 776265-2d.html 776265-2-ref.html
 == 787947-1.html 787947-1-ref.html
 fuzzy(40,800) == 797797-1.html 797797-1-ref.html # 'opacity:N' and rgba(,,,N) text don't match precisely
 fuzzy(40,800) == 797797-2.html 797797-2-ref.html # 'opacity:N' and rgba(,,,N) text don't match precisely
+== 801994-1.html 801994-1-ref.html