Bug 921174 part 3: Make ReflowButtonContents() use a dedicated nsHTMLReflowMetrics instance, and give it full responsibility for populating parent's metrics. r=bz
This commit is contained in:
@@ -188,18 +188,11 @@ nsHTMLButtonControlFrame::Reflow(nsPresContext* aPresContext,
|
||||
nsMargin focusPadding = mRenderer.GetAddedButtonBorderAndPadding();
|
||||
|
||||
// Reflow the contents of the button.
|
||||
ReflowButtonContents(aPresContext, aDesiredSize, aReflowState, firstKid,
|
||||
// (This populates our aDesiredSize, too.)
|
||||
ReflowButtonContents(aPresContext, aDesiredSize,
|
||||
aReflowState, firstKid,
|
||||
focusPadding);
|
||||
|
||||
aDesiredSize.width = aReflowState.ComputedWidth();
|
||||
|
||||
aDesiredSize.width += aReflowState.mComputedBorderPadding.LeftRight();
|
||||
aDesiredSize.height += aReflowState.mComputedBorderPadding.TopBottom();
|
||||
|
||||
aDesiredSize.ascent +=
|
||||
aReflowState.mComputedBorderPadding.top + focusPadding.top;
|
||||
|
||||
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
||||
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, firstKid);
|
||||
|
||||
aStatus = NS_FRAME_COMPLETE;
|
||||
@@ -212,7 +205,7 @@ nsHTMLButtonControlFrame::Reflow(nsPresContext* aPresContext,
|
||||
|
||||
void
|
||||
nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
|
||||
nsHTMLReflowMetrics& aDesiredSize,
|
||||
nsHTMLReflowMetrics& aButtonDesiredSize,
|
||||
const nsHTMLReflowState& aButtonReflowState,
|
||||
nsIFrame* aFirstKid,
|
||||
nsMargin aFocusPadding)
|
||||
@@ -248,7 +241,9 @@ nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
|
||||
aFirstKid, availSize);
|
||||
|
||||
nsReflowStatus contentsReflowStatus;
|
||||
ReflowChild(aFirstKid, aPresContext, aDesiredSize, contentsReflowState,
|
||||
nsHTMLReflowMetrics contentsDesiredSize;
|
||||
ReflowChild(aFirstKid, aPresContext,
|
||||
contentsDesiredSize, contentsReflowState,
|
||||
xoffset,
|
||||
aFocusPadding.top + aButtonReflowState.mComputedBorderPadding.top,
|
||||
0, contentsReflowStatus);
|
||||
@@ -256,43 +251,64 @@ nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext,
|
||||
"We gave button-contents frame unconstrained available height, "
|
||||
"so it should be complete");
|
||||
|
||||
// Compute our desired height before vertically centering our children
|
||||
nscoord actualDesiredHeight = 0;
|
||||
// Compute the button's content-box height:
|
||||
nscoord buttonContentBoxHeight = 0;
|
||||
if (aButtonReflowState.ComputedHeight() != NS_INTRINSICSIZE) {
|
||||
actualDesiredHeight = aButtonReflowState.ComputedHeight();
|
||||
// Button has a fixed height -- that's its content-box height.
|
||||
buttonContentBoxHeight = aButtonReflowState.ComputedHeight();
|
||||
} else {
|
||||
actualDesiredHeight = aDesiredSize.height + aFocusPadding.TopBottom();
|
||||
// Button is intrinsically sized -- it should shrinkwrap the
|
||||
// button-contents' height, plus any focus-padding space:
|
||||
buttonContentBoxHeight =
|
||||
contentsDesiredSize.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
|
||||
// aButtonReflowState.ComputedHeight()). Note that we do this before
|
||||
// adjusting for borderpadding, since mComputedMaxHeight and
|
||||
// mComputedMinHeight are content heights.
|
||||
actualDesiredHeight = NS_CSS_MINMAX(actualDesiredHeight,
|
||||
aButtonReflowState.mComputedMinHeight,
|
||||
aButtonReflowState.mComputedMaxHeight);
|
||||
buttonContentBoxHeight =
|
||||
NS_CSS_MINMAX(buttonContentBoxHeight,
|
||||
aButtonReflowState.mComputedMinHeight,
|
||||
aButtonReflowState.mComputedMaxHeight);
|
||||
}
|
||||
|
||||
// center child vertically in the content area
|
||||
nscoord yoff = (actualDesiredHeight - aFocusPadding.TopBottom() - aDesiredSize.height) / 2;
|
||||
if (yoff < 0) {
|
||||
yoff = 0;
|
||||
}
|
||||
// Center child vertically in the button
|
||||
// (technically, inside of the button's focus-padding area)
|
||||
nscoord extraSpace =
|
||||
buttonContentBoxHeight - aFocusPadding.TopBottom() -
|
||||
contentsDesiredSize.height;
|
||||
|
||||
nscoord yoffset = std::max(0, extraSpace / 2);
|
||||
|
||||
// Adjust yoffset to be in terms of the button's frame-rect, instead of
|
||||
// its focus-padding rect:
|
||||
yoffset += aFocusPadding.top + aButtonReflowState.mComputedBorderPadding.top;
|
||||
|
||||
// Place the child
|
||||
FinishReflowChild(aFirstKid, aPresContext, &contentsReflowState, aDesiredSize,
|
||||
xoffset,
|
||||
yoff + aFocusPadding.top +
|
||||
aButtonReflowState.mComputedBorderPadding.top,
|
||||
0);
|
||||
FinishReflowChild(aFirstKid, aPresContext,
|
||||
&contentsReflowState, contentsDesiredSize,
|
||||
xoffset, yoffset, 0);
|
||||
|
||||
if (aDesiredSize.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE)
|
||||
aDesiredSize.ascent = aFirstKid->GetBaseline();
|
||||
// Make sure we have a useful 'ascent' value for the child
|
||||
if (contentsDesiredSize.ascent == nsHTMLReflowMetrics::ASK_FOR_BASELINE) {
|
||||
contentsDesiredSize.ascent = aFirstKid->GetBaseline();
|
||||
}
|
||||
|
||||
// Adjust the baseline by our offset (since we moved the child's
|
||||
// baseline by that much), and set our actual desired height.
|
||||
aDesiredSize.ascent += yoff;
|
||||
aDesiredSize.height = actualDesiredHeight;
|
||||
// OK, we're done with the child frame.
|
||||
// Use what we learned to populate the button frame's reflow metrics.
|
||||
// * Button's height & width are content-box size + border-box contribution:
|
||||
aButtonDesiredSize.width = aButtonReflowState.ComputedWidth() +
|
||||
aButtonReflowState.mComputedBorderPadding.LeftRight();
|
||||
|
||||
aButtonDesiredSize.height = buttonContentBoxHeight +
|
||||
aButtonReflowState.mComputedBorderPadding.TopBottom();
|
||||
|
||||
// * Button's ascent is its child's ascent, plus the child's y-offset
|
||||
// within our frame:
|
||||
aButtonDesiredSize.ascent = contentsDesiredSize.ascent + yoffset;
|
||||
|
||||
aButtonDesiredSize.SetOverflowAreasToDesiredBounds();
|
||||
}
|
||||
|
||||
nsresult nsHTMLButtonControlFrame::SetFormProperty(nsIAtom* aName, const nsAString& aValue)
|
||||
|
||||
Reference in New Issue
Block a user