From 263a259da7941441ca9c1dd66dc6b793e013a964 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Sat, 16 Nov 2002 19:32:49 +0000 Subject: [PATCH] Fix regression in rendering buttons that people manually size to less than desired size. Bug 180085, r=jkeiser, sr=roc+moz git-svn-id: svn://10.0.0.236/trunk@133980 18797224-902f-48f8-a5cc-f745e15eee43 --- .../layout/forms/nsGfxButtonControlFrame.cpp | 19 +++++ .../layout/forms/nsHTMLButtonControlFrame.cpp | 70 ++++++------------- mozilla/layout/html/document/src/forms.css | 6 +- .../forms/src/nsGfxButtonControlFrame.cpp | 19 +++++ .../forms/src/nsHTMLButtonControlFrame.cpp | 70 ++++++------------- mozilla/layout/style/forms.css | 6 +- 6 files changed, 88 insertions(+), 102 deletions(-) diff --git a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp index 6642962df82..c11e1aa50d4 100644 --- a/mozilla/layout/forms/nsGfxButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsGfxButtonControlFrame.cpp @@ -200,6 +200,25 @@ nsGfxButtonControlFrame::CreateAnonymousContent(nsIPresContext* aPresContext, GetStyleData(eStyleStruct_Text, (const nsStyleStruct *&)textStyle); if (!textStyle->WhiteSpaceIsSignificant()) { value.CompressWhitespace(); + } else if (value.Length() > 2 && value[0] == ' ' && + value[value.Length() - 1] == ' '){ + // This is a bit of a hack. The reason this is here is as follows: we now + // have default padding on our buttons to make them non-ugly. + // Unfortunately, IE-windows does not have such padding, so people will + // stick values like " ok " (with the spaces) in the buttons in an attempt + // to make them look decent. Unfortunately, if they do this the button + // looks way too big in Mozilla. Worse yet, if they do this _and_ set a + // fixed width for the button we run into trouble because our focus-rect + // border/padding and outer border take up 10px of the horizontal button + // space or so; the result is that the text is misaligned, even with the + // recentering we do in nsHTMLButtonFrame::Reflow. So to solve this, even + // if the whitespace is significant, single leading and trailing _spaces_ + // (and not other whitespace) are removed. The proper solution, of + // course, is to not have the focus rect painting taking up 6px of + // horizontal space. We should do that instead (via XBL form controls or + // changing the renderer) and remove this. + value.Cut(0, 1); + value.Truncate(value.Length() - 1); } // Add a child text content node for the label diff --git a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp index 307c7b74589..3c6729816b3 100644 --- a/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp +++ b/mozilla/layout/forms/nsHTMLButtonControlFrame.cpp @@ -405,34 +405,6 @@ nsHTMLButtonControlFrame::Paint(nsIPresContext* aPresContext, return nsFrame::Paint(aPresContext, aRenderingContext, aDirtyRect, aWhichLayer); } -// XXX a hack until the reflow state does this correctly -// XXX when it gets fixed, leave in the printf statements or add an assertion -static -void ButtonHack(nsHTMLReflowState& aReflowState, const char* aMessage) -{ - // XXXbz is this still relevant? - if (aReflowState.mComputedWidth == 0) { - aReflowState.mComputedWidth = aReflowState.availableWidth; - } - if ((aReflowState.mComputedWidth != NS_INTRINSICSIZE) && - (aReflowState.mComputedWidth > aReflowState.availableWidth) && - (aReflowState.availableWidth > 0)) { -// printf("BUG - %s has a computed width = %d, available width = %d \n", -// aMessage, aReflowState.mComputedWidth, aReflowState.availableWidth); - aReflowState.mComputedWidth = aReflowState.availableWidth; - } - if (aReflowState.mComputedHeight == 0) { - aReflowState.mComputedHeight = aReflowState.availableHeight; - } - if ((aReflowState.mComputedHeight != NS_INTRINSICSIZE) && - (aReflowState.mComputedHeight > aReflowState.availableHeight) && - (aReflowState.availableHeight > 0)) { -// printf("BUG - %s has a computed height = %d, available height = %d \n", -// aMessage, aReflowState.mComputedHeight, aReflowState.availableHeight); - aReflowState.mComputedHeight = aReflowState.availableHeight; - } -} - NS_IMETHODIMP nsHTMLButtonControlFrame::AddComputedBorderPaddingToDesiredSize(nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aSuggestedReflowState) @@ -462,8 +434,6 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, return skiprv; } #endif - // XXX remove the following when the reflow state is fixed - ButtonHack((nsHTMLReflowState&)aReflowState, "html4 button"); // commenting this out for now. We need a view to do mouse grabbing but // it doesn't really seem to work correctly. When you press the only event @@ -545,9 +515,6 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, nsHTMLReflowState reflowState(aPresContext, aReflowState, firstKid, availSize, reason); //reflowState.computedWidth = availSize; - // XXX remove the following when the reflow state is fixed - //ButtonHack(reflowState, "html4 button's area"); - ReflowChild(firstKid, aPresContext, aDesiredSize, reflowState, focusPadding.left + aReflowState.mComputedBorderPadding.left, focusPadding.top + aReflowState.mComputedBorderPadding.top, @@ -572,24 +539,32 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, yoff = (minInternalHeight - aDesiredSize.height) / 2; } + // Place the child. If we have a non-intrinsic width, we want to + // reduce the left padding as needed to try and fit the text in the + // button + nscoord xoffset = focusPadding.left + aReflowState.mComputedBorderPadding.left; + if (aReflowState.mComputedWidth != NS_INTRINSICSIZE) { + // First, how much did we "overflow"? This is the width of our + // kid plus our special focus stuff (which did not get accounted + // for in calculating aReflowState.mComputedWidth minus the width + // we're forced to be. + nscoord extrawidth = + aDesiredSize.width + focusPadding.left + focusPadding.right + - aReflowState.mComputedWidth; + if (extrawidth > 0) { + // Split it evenly between right and left + extrawidth /= 2; + // But do not shoot out the left side of the button, please + extrawidth = PR_MIN(extrawidth, aReflowState.mComputedPadding.left); + xoffset -= extrawidth; + } + } + // Place the child FinishReflowChild(firstKid, aPresContext, &reflowState, aDesiredSize, - focusPadding.left + aReflowState.mComputedBorderPadding.left, + xoffset, yoff + focusPadding.top + aReflowState.mComputedBorderPadding.top, 0); -#if 0 // old way - // if computed use the computed values. - if (aReflowState.mComputedWidth != NS_INTRINSICSIZE && (aDesiredSize.width < aReflowState.mComputedWidth)) - aDesiredSize.width = aReflowState.mComputedWidth; - else - aDesiredSize.width += focusPadding.left + focusPadding.right; - - if (aReflowState.mComputedHeight != NS_INTRINSICSIZE && (aDesiredSize.height < aReflowState.mComputedHeight)) - aDesiredSize.height = aReflowState.mComputedHeight; - else - aDesiredSize.height += focusPadding.top + focusPadding.bottom; - -#else // temporary for Bug #17474 // if computed use the computed values. if (aReflowState.mComputedWidth != NS_INTRINSICSIZE) aDesiredSize.width = aReflowState.mComputedWidth; @@ -600,7 +575,6 @@ nsHTMLButtonControlFrame::Reflow(nsIPresContext* aPresContext, aDesiredSize.height = aReflowState.mComputedHeight; else aDesiredSize.height += focusPadding.top + focusPadding.bottom; -#endif AddComputedBorderPaddingToDesiredSize(aDesiredSize, aReflowState); diff --git a/mozilla/layout/html/document/src/forms.css b/mozilla/layout/html/document/src/forms.css index b4d98bbd609..d7f353cc0cd 100644 --- a/mozilla/layout/html/document/src/forms.css +++ b/mozilla/layout/html/document/src/forms.css @@ -388,7 +388,7 @@ input[type="submit"] { /* The sum of border-top, border-bottom, padding-top, padding-bottom must be the same here, for text inputs, and for . For buttons, make sure to include the -moz-focus-inner border/padding. */ - padding: 0px 8px 0px 8px; + padding: 0px 6px 0px 6px; border: 2px outset ButtonFace; background-color: ButtonFace; color: ButtonText; @@ -411,7 +411,7 @@ button:active:hover, input[type="reset"]:active:hover, input[type="button"]:active:hover, input[type="submit"]:active:hover { - padding: 0px 7px 0px 9px; + padding: 0px 5px 0px 7px; border-style: inset; } @@ -443,7 +443,7 @@ input[type="submit"][disabled]:active, input[type="submit"][disabled] { /* The sum of border-top, border-bottom, padding-top, padding-bottom must be the same here and for text inputs */ - padding: 1px 8px 1px 8px; + padding: 1px 6px 1px 6px; border: 1px outset ButtonShadow; color: GrayText; }