From a9ac8b390ff6e2d0c4daa5b872913db1b77851a7 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Mon, 27 Jul 2026 12:36:24 -0500 Subject: [PATCH] Issue #3153 - Make sure buttons report a definite size for flex containers. Second try, this time ONLY do it for flex container or grids. This should prevent layout problems in non-flex scenarios. --- layout/forms/nsHTMLButtonControlFrame.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/layout/forms/nsHTMLButtonControlFrame.cpp b/layout/forms/nsHTMLButtonControlFrame.cpp index d1fbfbabd7..794834e906 100644 --- a/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/layout/forms/nsHTMLButtonControlFrame.cpp @@ -234,7 +234,18 @@ nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext, { WritingMode wm = GetWritingMode(); LogicalSize availSize = aButtonReflowInput.ComputedSize(wm); - availSize.BSize(wm) = NS_INTRINSICSIZE; + + // Identify if the inner anonymous block is actually functioning as a flex or grid container. + nsIAtom* kidType = aFirstKid->GetType(); + bool isFlexOrGrid = (kidType == nsGkAtoms::flexContainerFrame || + kidType == nsGkAtoms::gridContainerFrame); + + // Preserve the button's definite BSize ONLY for flex/grid children so they + // see a definite containing block main size. For standard buttons, clobber + // to intrinsic so standard vertical centering (extraSpace) calculations work. + if (!isFlexOrGrid || 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 +259,12 @@ nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext, aFirstKid, availSize); + // Apply the definite BSize directly on the inner reflow input ONLY if it's + // a flex or grid container, allowing it to be used as-is. + if (isFlexOrGrid && 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