From afa637e3ce7778ce7e4c7eddbbc1b36a0cc7a12e Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 14 Mar 2008 20:48:24 +0000 Subject: [PATCH] Don't use fieldset pref widths as min widths, since pref widths can be unconstrained. Incidentally makes it possible for text to legends to wrap if the page wants it to. Bug 404123 and bug 354502, r+sr=dbaron, a=beltzner. git-svn-id: svn://10.0.0.236/trunk@247866 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/crashtests/404123-1.html | 12 ++ .../layout/forms/crashtests/crashtests.list | 1 + mozilla/layout/forms/nsFieldSetFrame.cpp | 109 +++++------------- .../layout/reftests/bugs/404123-1-ref.html | 10 ++ mozilla/layout/reftests/bugs/404123-1.html | 9 ++ .../layout/reftests/bugs/404123-2-ref.html | 10 ++ mozilla/layout/reftests/bugs/404123-2.html | 9 ++ .../layout/reftests/bugs/404123-3-ref.html | 10 ++ mozilla/layout/reftests/bugs/404123-3.html | 12 ++ mozilla/layout/reftests/bugs/reftest.list | 3 + mozilla/layout/style/forms.css | 7 ++ 11 files changed, 114 insertions(+), 78 deletions(-) create mode 100644 mozilla/layout/forms/crashtests/404123-1.html create mode 100644 mozilla/layout/reftests/bugs/404123-1-ref.html create mode 100644 mozilla/layout/reftests/bugs/404123-1.html create mode 100644 mozilla/layout/reftests/bugs/404123-2-ref.html create mode 100644 mozilla/layout/reftests/bugs/404123-2.html create mode 100644 mozilla/layout/reftests/bugs/404123-3-ref.html create mode 100644 mozilla/layout/reftests/bugs/404123-3.html diff --git a/mozilla/layout/forms/crashtests/404123-1.html b/mozilla/layout/forms/crashtests/404123-1.html new file mode 100644 index 00000000000..73fbaa363c4 --- /dev/null +++ b/mozilla/layout/forms/crashtests/404123-1.html @@ -0,0 +1,12 @@ + + + + + + +
+ +
+ + + diff --git a/mozilla/layout/forms/crashtests/crashtests.list b/mozilla/layout/forms/crashtests/crashtests.list index 849698f6e77..00fd6fc20ca 100644 --- a/mozilla/layout/forms/crashtests/crashtests.list +++ b/mozilla/layout/forms/crashtests/crashtests.list @@ -20,3 +20,4 @@ load 388374-1.xhtml load 388374-2.html load 393656-1.xhtml load 393656-2.xhtml +load 404123-1.html diff --git a/mozilla/layout/forms/nsFieldSetFrame.cpp b/mozilla/layout/forms/nsFieldSetFrame.cpp index 23854e9776f..4b4dc160f09 100644 --- a/mozilla/layout/forms/nsFieldSetFrame.cpp +++ b/mozilla/layout/forms/nsFieldSetFrame.cpp @@ -73,9 +73,8 @@ public: nsIFrame* aChildList); NS_HIDDEN_(nscoord) - GetLegendPrefWidth(nsIRenderingContext* aRenderingContext); - NS_HIDDEN_(nscoord) - GetContentMinWidth(nsIRenderingContext* aRenderingContext); + GetIntrinsicWidth(nsIRenderingContext* aRenderingContext, + nsLayoutUtils::IntrinsicWidthType); virtual nscoord GetMinWidth(nsIRenderingContext* aRenderingContext); virtual nscoord GetPrefWidth(nsIRenderingContext* aRenderingContext); virtual nsSize ComputeSize(nsIRenderingContext *aRenderingContext, @@ -334,47 +333,27 @@ nsFieldSetFrame::PaintBorderBackground(nsIRenderingContext& aRenderingContext, } } -// XXXbz This duplicates code in nsGkAtoms (near IntrinsicForContainer) - -static nscoord GetCoord(const nsStyleCoord& aCoord, nscoord aIfNotCoord) -{ - return aCoord.GetUnit() == eStyleUnit_Coord - ? aCoord.GetCoordValue() - : aIfNotCoord; -} - nscoord -nsFieldSetFrame::GetLegendPrefWidth(nsIRenderingContext* aRenderingContext) +nsFieldSetFrame::GetIntrinsicWidth(nsIRenderingContext* aRenderingContext, + nsLayoutUtils::IntrinsicWidthType aType) { - NS_ASSERTION(mLegendFrame, "Don't call me if there is no legend frame!"); + nscoord legendWidth = 0; + nscoord contentWidth = 0; + if (mLegendFrame) { + legendWidth = + nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mLegendFrame, + aType); + } - // We don't want to use nsLayoutUtils::IntrinsicForContainer, - // because legends ignore their CSS-specified width. - nscoord result = mLegendFrame->GetPrefWidth(aRenderingContext); - - const nsStylePadding *stylePadding = mLegendFrame->GetStylePadding(); - result += GetCoord(stylePadding->mPadding.GetLeft(), 0); - result += GetCoord(stylePadding->mPadding.GetRight(), 0); - - const nsStyleBorder *styleBorder = mLegendFrame->GetStyleBorder(); - result += styleBorder->GetBorderWidth(NS_SIDE_LEFT); - result += styleBorder->GetBorderWidth(NS_SIDE_RIGHT); - - const nsStyleMargin *styleMargin = mLegendFrame->GetStyleMargin(); - result += GetCoord(styleMargin->mMargin.GetLeft(), 0); - result += GetCoord(styleMargin->mMargin.GetRight(), 0); - - return result; + if (mContentFrame) { + contentWidth = + nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mContentFrame, + aType); + } + + return PR_MAX(legendWidth, contentWidth); } -nscoord -nsFieldSetFrame::GetContentMinWidth(nsIRenderingContext* aRenderingContext) -{ - NS_ASSERTION(mContentFrame, "Don't call me if there is no legend frame!"); - - return nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mContentFrame, - nsLayoutUtils::MIN_WIDTH); -} nscoord nsFieldSetFrame::GetMinWidth(nsIRenderingContext* aRenderingContext) @@ -382,17 +361,7 @@ nsFieldSetFrame::GetMinWidth(nsIRenderingContext* aRenderingContext) nscoord result = 0; DISPLAY_MIN_WIDTH(this, result); - nscoord legendPrefWidth = 0; - nscoord contentMinWidth = 0; - if (mLegendFrame) { - legendPrefWidth = GetLegendPrefWidth(aRenderingContext); - } - - if (mContentFrame) { - contentMinWidth = GetContentMinWidth(aRenderingContext); - } - - result = PR_MAX(legendPrefWidth, contentMinWidth); + result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::MIN_WIDTH); return result; } @@ -402,19 +371,7 @@ nsFieldSetFrame::GetPrefWidth(nsIRenderingContext* aRenderingContext) nscoord result = 0; DISPLAY_PREF_WIDTH(this, result); - nscoord legendPrefWidth = 0; - nscoord contentPrefWidth = 0; - if (mLegendFrame) { - legendPrefWidth = GetLegendPrefWidth(aRenderingContext); - } - - if (mContentFrame) { - contentPrefWidth = - nsLayoutUtils::IntrinsicForContainer(aRenderingContext, mContentFrame, - nsLayoutUtils::PREF_WIDTH); - } - - result = PR_MAX(legendPrefWidth, contentPrefWidth); + result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::PREF_WIDTH); return result; } @@ -467,7 +424,16 @@ nsFieldSetFrame::Reflow(nsPresContext* aPresContext, nsSize availSize(aReflowState.ComputedWidth(), aReflowState.availableHeight); NS_ASSERTION(!mContentFrame || - GetContentMinWidth(aReflowState.rendContext) <= availSize.width, + nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext, + mContentFrame, + nsLayoutUtils::MIN_WIDTH) <= + availSize.width, + "Bogus availSize.width; should be bigger"); + NS_ASSERTION(!mLegendFrame || + nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext, + mLegendFrame, + nsLayoutUtils::MIN_WIDTH) <= + availSize.width, "Bogus availSize.width; should be bigger"); // get our border and padding @@ -483,18 +449,8 @@ nsFieldSetFrame::Reflow(nsPresContext* aPresContext, const nsStyleMargin* marginStyle = mLegendFrame->GetStyleMargin(); marginStyle->GetMargin(legendMargin); - // Give the legend all the space it wants. - nsSize legendAvailSize(GetLegendPrefWidth(aReflowState.rendContext), - NS_INTRINSICSIZE); - nsHTMLReflowState legendReflowState(aPresContext, aReflowState, - mLegendFrame, - legendAvailSize); - - // always give the legend as much size as it wants - legendReflowState. - SetComputedWidth(mLegendFrame->GetPrefWidth(aReflowState.rendContext)); - legendReflowState.SetComputedHeight(NS_INTRINSICSIZE); + mLegendFrame, availSize); nsHTMLReflowMetrics legendDesiredSize; @@ -529,9 +485,6 @@ nsFieldSetFrame::Reflow(nsPresContext* aPresContext, availSize.height -= mLegendSpace; availSize.height = PR_MAX(availSize.height, 0); } - - NS_ASSERTION(availSize.width >= mLegendRect.width, - "Bogus availSize.width. Should be bigger"); FinishReflowChild(mLegendFrame, aPresContext, &legendReflowState, legendDesiredSize, 0, 0, NS_FRAME_NO_MOVE_FRAME); diff --git a/mozilla/layout/reftests/bugs/404123-1-ref.html b/mozilla/layout/reftests/bugs/404123-1-ref.html new file mode 100644 index 00000000000..0b0758a09b7 --- /dev/null +++ b/mozilla/layout/reftests/bugs/404123-1-ref.html @@ -0,0 +1,10 @@ + + + +
+ This is legend text + This is other text +
+ + + diff --git a/mozilla/layout/reftests/bugs/404123-1.html b/mozilla/layout/reftests/bugs/404123-1.html new file mode 100644 index 00000000000..54678c6ad15 --- /dev/null +++ b/mozilla/layout/reftests/bugs/404123-1.html @@ -0,0 +1,9 @@ + + + +
+ This is legend text + This is other text +
+ + diff --git a/mozilla/layout/reftests/bugs/404123-2-ref.html b/mozilla/layout/reftests/bugs/404123-2-ref.html new file mode 100644 index 00000000000..f862706a216 --- /dev/null +++ b/mozilla/layout/reftests/bugs/404123-2-ref.html @@ -0,0 +1,10 @@ + + + +
+ Legend
textstuffandall
+ Text +
+ + + diff --git a/mozilla/layout/reftests/bugs/404123-2.html b/mozilla/layout/reftests/bugs/404123-2.html new file mode 100644 index 00000000000..87580138ace --- /dev/null +++ b/mozilla/layout/reftests/bugs/404123-2.html @@ -0,0 +1,9 @@ + + + +
+ Legend textstuffandall + Text +
+ + diff --git a/mozilla/layout/reftests/bugs/404123-3-ref.html b/mozilla/layout/reftests/bugs/404123-3-ref.html new file mode 100644 index 00000000000..2a99d26d2fb --- /dev/null +++ b/mozilla/layout/reftests/bugs/404123-3-ref.html @@ -0,0 +1,10 @@ + + + +
+ + + +
+ + diff --git a/mozilla/layout/reftests/bugs/404123-3.html b/mozilla/layout/reftests/bugs/404123-3.html new file mode 100644 index 00000000000..bf9638786f2 --- /dev/null +++ b/mozilla/layout/reftests/bugs/404123-3.html @@ -0,0 +1,12 @@ + + + +
+ + + +
+ + diff --git a/mozilla/layout/reftests/bugs/reftest.list b/mozilla/layout/reftests/bugs/reftest.list index 9f7a97c05ed..55d92ecc07d 100644 --- a/mozilla/layout/reftests/bugs/reftest.list +++ b/mozilla/layout/reftests/bugs/reftest.list @@ -679,6 +679,9 @@ random == 403134-1.html 403134-1-ref.html # bug 405377 == 404030-1.html 404030-1-ref.html != 404030-1-notref.html 404030-1.html != 404030-1-notref2.html 404030-1.html +== 404123-1.html 404123-1-ref.html +== 404123-2.html 404123-2-ref.html +== 404123-3.html 404123-3-ref.html == 404180-1.html 404180-1-ref.html == 404301-1.html 404301-1-ref.html == 404309-1a.html 404309-1-ref.html diff --git a/mozilla/layout/style/forms.css b/mozilla/layout/style/forms.css index 095ac833e98..223ffe59b6e 100644 --- a/mozilla/layout/style/forms.css +++ b/mozilla/layout/style/forms.css @@ -55,6 +55,13 @@ legend { border: none; position: static ! important; float: none ! important; + width: auto ! important; + min-width: 0 ! important; + max-width: none ! important; + height: auto ! important; + min-height: 0 ! important; + max-height: none ! important; + white-space: nowrap; } fieldset {