diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp index d1fbfbabd7..068f9d06dd 100644 --- a/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/layout/forms/nsHTMLButtonControlFrame.cpp @@ -234,7 +234,13 @@ nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext, { WritingMode wm = GetWritingMode(); LogicalSize availSize = aButtonReflowInput.ComputedSize(wm); - availSize.BSize(wm) = NS_INTRINSICSIZE; + + // Preserve the button's definite BSize so that flex/grid children inside + // see a definite containing block main size. Only clobber to intrinsic + // when the button itself has an indefinite BSize. + if (aButtonReflowInput.ComputedBSize() == NS_INTRINSICSIZE) { + availSize.BSize(wm) = NS_INTRINSICSIZE; + } // shorthand for a value we need to use in a bunch of places const LogicalMargin& clbp = aButtonReflowInput.ComputedLogicalBorderPadding(); @@ -248,6 +254,12 @@ nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext, aFirstKid, availSize); + // Also set the computed BSize directly on the inner reflow input so it + // gets used as-is by the anonymous flex container: + if (aButtonReflowInput.ComputedBSize() != NS_INTRINSICSIZE) { + contentsReflowInput.SetComputedBSize(aButtonReflowInput.ComputedBSize()); + } + nsReflowStatus contentsReflowStatus; ReflowOutput contentsDesiredSize(aButtonReflowInput); childPos.B(wm) = 0; // This will be set properly later, after reflowing the