Bug 1130231 - [Aurora] Properly logicalize the implementation of padding on button contents. r=smontagu a=lmandel
authorJonathan Kew <jkew@mozilla.com>
Fri, 06 Feb 2015 10:47:08 +0000
changeset 249747 7a186c7c962d121bbf459f54251d80261ecfa1de
parent 249746 3d8ee277208964bd31fa6bfb21722e3127e376b3
child 249748 826fe1c67dca6e06383b85203db5cfb940367f74
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmontagu, lmandel
bugs1130231
milestone37.0a2
Bug 1130231 - [Aurora] Properly logicalize the implementation of padding on button contents. r=smontagu a=lmandel
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 coordinates here, as the child will be repositioned
+  // later by FinishReflowChild.
   ReflowChild(aFirstKid, aPresContext,
               contentsDesiredSize, contentsReflowState,
-              isVertical ? boffset : ioffset,
-              isVertical ? ioffset : boffset,
-              0, contentsReflowStatus);
+              0, 0, NS_FRAME_NO_MOVE_FRAME, 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,31 @@ 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
+  nsPoint physicalPos =
+    childPos.GetPhysicalPoint(wm, containerWidth - contentsDesiredSize.Width());
   FinishReflowChild(aFirstKid, aPresContext,
                     contentsDesiredSize, &contentsReflowState,
-                    isVertical ? boffset : ioffset,
-                    isVertical ? ioffset : boffset,
-                    0);
+                    physicalPos.x, physicalPos.y, 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 +384,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) {