Bug 893298 - Correctly calculate button and button child's desired height to vertically center the child. r=bz
☠☠ backed out by dab0ba7fb3f4 ☠ ☠
authorBear Travis <betravis@adobe.com>
Thu, 18 Jul 2013 14:21:47 -0700
changeset 151525 319da88f992ec3cb00b09be257f0d926dd2ecede
parent 151524 657c02a2ff0f9f1cc2a18c30b530959110b5e59f
child 151526 5fae2f62da6697700b08972148e6ec8fa512875f
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs893298
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 893298 - Correctly calculate button and button child's desired height to vertically center the child. r=bz
layout/forms/nsHTMLButtonControlFrame.cpp
layout/reftests/forms/button/reftest.list
layout/reftests/forms/button/vertical-centering-ref.html
layout/reftests/forms/button/vertical-centering.html
--- a/layout/forms/nsHTMLButtonControlFrame.cpp
+++ b/layout/forms/nsHTMLButtonControlFrame.cpp
@@ -261,61 +261,52 @@ nsHTMLButtonControlFrame::ReflowButtonCo
   
   nsHTMLReflowState reflowState(aPresContext, aReflowState, aFirstKid,
                                 availSize);
 
   ReflowChild(aFirstKid, aPresContext, aDesiredSize, reflowState,
               xoffset,
               aFocusPadding.top + aReflowState.mComputedBorderPadding.top,
               0, aStatus);
-  
-  // calculate the min internal height so the contents gets centered correctly.
-  // XXXbz this assumes border-box sizing.
-  nscoord minInternalHeight = aReflowState.mComputedMinHeight -
-    aReflowState.mComputedBorderPadding.TopBottom();
-  minInternalHeight = std::max(minInternalHeight, 0);
 
   // Compute our desired height before vertically centering our children
+  nscoord actualDesiredHeight = 0;
   if (aReflowState.ComputedHeight() != NS_INTRINSICSIZE) {
-    aDesiredSize.height = aReflowState.ComputedHeight();
+    actualDesiredHeight = aReflowState.ComputedHeight();
   } else {
-    aDesiredSize.height += aFocusPadding.TopBottom();
+    actualDesiredHeight = aDesiredSize.height + aFocusPadding.TopBottom();
 
     // Make sure we obey min/max-height in the case when we're doing intrinsic
     // sizing (we get it for free when we have a non-intrinsic
     // aReflowState.ComputedHeight()).  Note that we do this before adjusting
     // for borderpadding, since mComputedMaxHeight and mComputedMinHeight are
     // content heights.
-    aDesiredSize.height = NS_CSS_MINMAX(aDesiredSize.height,
+    actualDesiredHeight = NS_CSS_MINMAX(actualDesiredHeight,
                                         aReflowState.mComputedMinHeight,
                                         aReflowState.mComputedMaxHeight);
   }
 
-  // center child vertically
-  nscoord yoff = 0;
-  if (aReflowState.ComputedHeight() != NS_INTRINSICSIZE) {
-    yoff = (aReflowState.ComputedHeight() - aDesiredSize.height)/2;
-    if (yoff < 0) {
-      yoff = 0;
-    }
-  } else if (aDesiredSize.height < minInternalHeight) {
-    yoff = (minInternalHeight - aDesiredSize.height) / 2;
+  // center child vertically in the content area
+  nscoord yoff = (actualDesiredHeight - aFocusPadding.TopBottom() - aDesiredSize.height) / 2;
+  if (yoff < 0) {
+    yoff = 0;
   }
 
   // Place the child
   FinishReflowChild(aFirstKid, aPresContext, &reflowState, aDesiredSize,
                     xoffset,
                     yoff + aFocusPadding.top + aReflowState.mComputedBorderPadding.top, 0);
 
   if (aDesiredSize.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE)
     aDesiredSize.ascent = aFirstKid->GetBaseline();
 
   // Adjust the baseline by our offset (since we moved the child's
-  // baseline by that much).
+  // baseline by that much), and set our actual desired height.
   aDesiredSize.ascent += yoff;
+  aDesiredSize.height = actualDesiredHeight;
 }
 
 nsresult nsHTMLButtonControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
 {
   if (nsGkAtoms::value == aName) {
     return mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::value,
                              aValue, true);
   }
--- a/layout/reftests/forms/button/reftest.list
+++ b/layout/reftests/forms/button/reftest.list
@@ -1,4 +1,5 @@
 asserts(2) == first-letter-1.html first-letter-1-ref.html
 asserts(1) != first-letter-1.html first-letter-1-noref.html
 == max-height.html max-height-ref.html
 == min-height.html min-height-ref.html
+== vertical-centering.html vertical-centering-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/button/vertical-centering-ref.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+div {
+    height: 100px;
+    width: 100px;
+    display: inline-block;
+    border: 0;
+    padding: 0;
+
+    font: 2em/100px sans-serif;
+    color: white;
+    text-align: center;
+
+    background: blue;
+    color: white;
+}
+</style>
+</head>
+<body>
+<div>button</div>
+<div>button</div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/forms/button/vertical-centering.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+input, div {
+    height: 100px;
+    width: 100px;
+    display: inline-block;
+    border: 0;
+    padding: 0;
+
+    font: 2em sans-serif;
+    color: white;
+
+    background-color: blue;
+    color: white;
+}
+input::-moz-focus-inner {
+    padding: 0;
+    border: 0;
+}
+div {
+    line-height: 100px;
+    text-align: center;
+}
+</style>
+</head>
+<body>
+<input type='button' value='button' />
+<div>button</div>
+</body>
+</html>