Bug 1130231 - Properly logicalize the implementation of padding on button contents. r=smontagu
authorJonathan Kew <jkew@mozilla.com>
Mon, 09 Feb 2015 14:40:23 +0000
changeset 241780 44078171052141c0998b64d2f83faf34da75cb1a
parent 241779 c13e7799a147a1ebdb8745e1bc58b7581b49fdca
child 241781 8f675794e1b6471913cbe7cc0e7c30360cad7e1c
push id619
push usercliu@mozilla.com
push dateMon, 09 Feb 2015 21:57:21 +0000
reviewerssmontagu
bugs1130231
milestone38.0a1
Bug 1130231 - Properly logicalize the implementation of padding on button contents. r=smontagu
layout/forms/nsHTMLButtonControlFrame.cpp
--- a/layout/forms/nsHTMLButtonControlFrame.cpp
+++ b/layout/forms/nsHTMLButtonControlFrame.cpp
@@ -258,17 +258,16 @@ CloneReflowStateWithReducedContentBox(
 
 void
 nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
                                                nsHTMLReflowMetrics& aButtonDesiredSize,
                                                const nsHTMLReflowState& aButtonReflowState,
                                                nsIFrame* aFirstKid)
 {
   WritingMode wm = GetWritingMode();
-  bool isVertical = wm.IsVertical();
   LogicalSize availSize = aButtonReflowState.ComputedSize(wm);
   availSize.BSize(wm) = NS_INTRINSICSIZE;
 
   // Buttons have some bonus renderer-determined border/padding,
   // which occupies part of the button's content-box area:
   const LogicalMargin focusPadding =
     LogicalMargin(wm, mRenderer.GetAddedButtonBorderAndPadding());
 
@@ -278,51 +277,53 @@ nsHTMLButtonControlFrame::ReflowButtonCo
   // Indent the child inside us by the focus border. We must do this separate
   // from the regular border.
   availSize.ISize(wm) -= focusPadding.IStartEnd(wm);
 
   // See whether out availSize's inline-size is big enough.  If it's smaller than
   // our intrinsic min iSize, that means that the kid wouldn't really fit; for a
   // better look in such cases we adjust the available iSize and our inline-start
   // offset to allow the kid to spill start-wards into our padding.
-  nscoord ioffset = focusPadding.IStart(wm) + clbp.IStart(wm);
+  LogicalPoint childPos(wm);
+  childPos.I(wm) = focusPadding.IStart(wm) + clbp.IStart(wm);
   nscoord extraISize = GetMinISize(aButtonReflowState.rendContext) -
     aButtonReflowState.ComputedISize();
   if (extraISize > 0) {
     nscoord extraIStart = extraISize / 2;
     nscoord extraIEnd = extraISize - extraIStart;
     NS_ASSERTION(extraIEnd >=0, "How'd that happen?");
 
     // Do not allow the extras to be bigger than the relevant padding
     const LogicalMargin& padding = aButtonReflowState.ComputedLogicalPadding();
     extraIStart = std::min(extraIStart, padding.IStart(wm));
     extraIEnd = std::min(extraIEnd, padding.IEnd(wm));
-    ioffset -= extraIStart;
+    childPos.I(wm) -= extraIStart;
     availSize.ISize(wm) = availSize.ISize(wm) + extraIStart + extraIEnd;
   }
   availSize.ISize(wm) = std::max(availSize.ISize(wm), 0);
 
   // Give child a clone of the button's reflow state, with height/width reduced
   // by focusPadding, so that descendants with height:100% don't protrude.
   nsHTMLReflowState adjustedButtonReflowState =
     CloneReflowStateWithReducedContentBox(aButtonReflowState,
                                           focusPadding.GetPhysicalMargin(wm));
 
   nsHTMLReflowState contentsReflowState(aPresContext,
                                         adjustedButtonReflowState,
                                         aFirstKid, availSize);
 
   nsReflowStatus contentsReflowStatus;
   nsHTMLReflowMetrics contentsDesiredSize(aButtonReflowState);
-  nscoord boffset = focusPadding.BStart(wm) + clbp.BStart(wm);
+  childPos.B(wm) = focusPadding.BStart(wm) + clbp.BStart(wm);
+
+  // We just pass 0 for containerWidth here, as the child will be repositioned
+  // later by FinishReflowChild.
   ReflowChild(aFirstKid, aPresContext,
               contentsDesiredSize, contentsReflowState,
-              isVertical ? boffset : ioffset,
-              isVertical ? ioffset : boffset,
-              0, contentsReflowStatus);
+              wm, childPos, 0, 0, contentsReflowStatus);
   MOZ_ASSERT(NS_FRAME_IS_COMPLETE(contentsReflowStatus),
              "We gave button-contents frame unconstrained available height, "
              "so it should be complete");
 
   // Compute the button's content-box height:
   nscoord buttonContentBoxBSize = 0;
   if (aButtonReflowState.ComputedBSize() != NS_INTRINSICSIZE) {
     // Button has a fixed block-size -- that's its content-box bSize.
@@ -345,28 +346,29 @@ nsHTMLButtonControlFrame::ReflowButtonCo
   }
 
   // Center child in the block-direction in the button
   // (technically, inside of the button's focus-padding area)
   nscoord extraSpace =
     buttonContentBoxBSize - focusPadding.BStartEnd(wm) -
     contentsDesiredSize.BSize(wm);
 
-  boffset = std::max(0, extraSpace / 2);
+  childPos.B(wm) = std::max(0, extraSpace / 2);
 
-  // Adjust boffset to be in terms of the button's frame-rect, instead of
+  // Adjust childPos.B() to be in terms of the button's frame-rect, instead of
   // its focus-padding rect:
-  boffset += focusPadding.BStart(wm) + clbp.BStart(wm);
+  childPos.B(wm) += focusPadding.BStart(wm) + clbp.BStart(wm);
+
+  nscoord containerWidth = contentsDesiredSize.Width() +
+    clbp.LeftRight(wm) + focusPadding.LeftRight(wm);
 
   // Place the child
   FinishReflowChild(aFirstKid, aPresContext,
                     contentsDesiredSize, &contentsReflowState,
-                    isVertical ? boffset : ioffset,
-                    isVertical ? ioffset : boffset,
-                    0);
+                    wm, childPos, containerWidth, 0);
 
   // Make sure we have a useful 'ascent' value for the child
   if (contentsDesiredSize.BlockStartAscent() ==
       nsHTMLReflowMetrics::ASK_FOR_BASELINE) {
     WritingMode wm = aButtonReflowState.GetWritingMode();
     contentsDesiredSize.SetBlockStartAscent(aFirstKid->GetLogicalBaseline(wm));
   }
 
@@ -380,17 +382,17 @@ nsHTMLButtonControlFrame::ReflowButtonCo
   //  * Button's ascent is its child's ascent, plus the child's block-offset
   // within our frame... unless it's orthogonal, in which case we'll use the
   // contents inline-size as an approximation for now.
   // XXX is there a better strategy? should we include border-padding?
   if (aButtonDesiredSize.GetWritingMode().IsOrthogonalTo(wm)) {
     aButtonDesiredSize.SetBlockStartAscent(contentsDesiredSize.ISize(wm));
   } else {
     aButtonDesiredSize.SetBlockStartAscent(contentsDesiredSize.BlockStartAscent() +
-                                           boffset);
+                                           childPos.B(wm));
   }
 
   aButtonDesiredSize.SetOverflowAreasToDesiredBounds();
 }
 
 nsresult nsHTMLButtonControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
 {
   if (nsGkAtoms::value == aName) {