From 1cbad10decf4b9fae868013e9d969e535dfe3800 Mon Sep 17 00:00:00 2001 From: "bernd.mielke%snafu.de" Date: Thu, 31 Jan 2002 05:09:13 +0000 Subject: [PATCH] fieldset reflow cleanup: bug 120958 report correct maxElementSize under table reflow conditions bug 48318 implement correct default alignement under bidi conditions, make legend alignment indepedent of fieldset content if fieldset size is not content driven. bug 80422 route trough events for floats inside a fieldset bug 42302 honour padding-top bug 60375 large maxElementsize overwrite computedWidth r=karnaze sr=waterson git-svn-id: svn://10.0.0.236/trunk@113292 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFieldSetFrame.cpp | 56 +++++++++++-------- mozilla/layout/forms/nsLegendFrame.cpp | 7 +++ .../layout/html/forms/src/nsFieldSetFrame.cpp | 56 +++++++++++-------- .../layout/html/forms/src/nsLegendFrame.cpp | 7 +++ 4 files changed, 82 insertions(+), 44 deletions(-) diff --git a/mozilla/layout/forms/nsFieldSetFrame.cpp b/mozilla/layout/forms/nsFieldSetFrame.cpp index d0b62e62a33..ad1efe0d0f4 100644 --- a/mozilla/layout/forms/nsFieldSetFrame.cpp +++ b/mozilla/layout/forms/nsFieldSetFrame.cpp @@ -100,6 +100,11 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame, nsIFrame* aNewFrame); + NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, + const nsPoint& aPoint, + nsFramePaintLayer aWhichLayer, + nsIFrame** aFrame); + #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const { return MakeFrameName(NS_LITERAL_STRING("FieldSet"), aResult); @@ -278,10 +283,15 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, { DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); - + // Initialize OUT parameter aStatus = NS_FRAME_COMPLETE; + if (nsnull != aDesiredSize.maxElementSize) { + aDesiredSize.maxElementSize->width = 0; + aDesiredSize.maxElementSize->height = 0; + } + //------------ Handle Incremental Reflow ----------------- nsIFrame* incrementalChild = nsnull; PRBool reflowContent = PR_TRUE; @@ -350,7 +360,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, // availSize could have unconstrained values, don't perform any addition on them nsSize availSize(aReflowState.mComputedWidth, aReflowState.availableHeight); - + // get our border and padding const nsMargin &borderPadding = aReflowState.mComputedBorderPadding; const nsMargin &padding = aReflowState.mComputedPadding; @@ -395,7 +405,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, mLegendSpace = 0; if (mLegendRect.height > border.top) { // center the border on the legend - mLegendSpace = mLegendRect.height - borderPadding.top; + mLegendSpace = mLegendRect.height - border.top; } else { mLegendRect.y = (border.top - mLegendRect.height)/2; } @@ -446,8 +456,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, kidReflowState.reason = reason; - nsHTMLReflowMetrics kidDesiredSize(0,0); - + nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.maxElementSize, aDesiredSize.mFlags); // Reflow the frame ReflowChild(mContentFrame, aPresContext, kidDesiredSize, kidReflowState, kidReflowState.mComputedMargin.left, kidReflowState.mComputedMargin.top, @@ -509,20 +518,26 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, } if (mLegendFrame) { + // use the computed width if the inner content does not fill it + if (aReflowState.mComputedWidth != NS_INTRINSICSIZE && aReflowState.mComputedWidth > contentRect.width ) + contentRect.width = aReflowState.mComputedWidth; + // if the content rect is larger then the legend we can align the legend if (contentRect.width > mLegendRect.width) { PRInt32 align = ((nsLegendFrame*)mLegendFrame)->GetAlign(); - + switch(align) { case NS_STYLE_TEXT_ALIGN_RIGHT: mLegendRect.x = contentRect.width - mLegendRect.width + borderPadding.left; break; case NS_STYLE_TEXT_ALIGN_CENTER: - mLegendRect.x = contentRect.width/2 - mLegendRect.width/2 + borderPadding.left; + float p2t; + aPresContext->GetPixelsToTwips(&p2t); + mLegendRect.x = NSIntPixelsToTwips((nscoord) NSToIntRound((float)(contentRect.width/2 - mLegendRect.width/2 + borderPadding.left) / p2t),p2t); } } else { - contentRect.width = mLegendRect.width + borderPadding.left + borderPadding.right; - aDesiredSize.width = contentRect.width; + //otherwise make place for the legend + contentRect.width = mLegendRect.width; } // place the legend nsRect actualLegendRect(mLegendRect); @@ -554,18 +569,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, if (aDesiredSize.height < min) aDesiredSize.height = min; } - - if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) { - aDesiredSize.width = borderPadding.left + - contentRect.width + - borderPadding.right; - } else { - nscoord min = borderPadding.left + borderPadding.right + mLegendRect.width; - aDesiredSize.width = aReflowState.mComputedWidth + borderPadding.left + borderPadding.right; - if (aDesiredSize.width < min) - aDesiredSize.width = min; - } - + aDesiredSize.width = contentRect.width + borderPadding.left + borderPadding.right; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; aDesiredSize.mMaximumWidth = aDesiredSize.width; @@ -671,4 +675,12 @@ nsFieldSetFrame::ReplaceFrame(nsIPresContext* aPresContext, aNewFrame); } - +NS_IMETHODIMP +nsFieldSetFrame::GetFrameForPoint(nsIPresContext* aPresContext, + const nsPoint& aPoint, + nsFramePaintLayer aWhichLayer, + nsIFrame** aFrame) +{ + // this should act like a block, so we need to override + return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame); +} diff --git a/mozilla/layout/forms/nsLegendFrame.cpp b/mozilla/layout/forms/nsLegendFrame.cpp index ef64e384eb3..51f8aa1fbd0 100644 --- a/mozilla/layout/forms/nsLegendFrame.cpp +++ b/mozilla/layout/forms/nsLegendFrame.cpp @@ -137,6 +137,13 @@ nsLegendFrame::Paint(nsIPresContext* aPresContext, PRInt32 nsLegendFrame::GetAlign() { PRInt32 intValue = NS_STYLE_TEXT_ALIGN_LEFT; +#ifdef IBMBIDI + const nsStyleVisibility* vis; + GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis); + if (NS_STYLE_DIRECTION_RTL == vis->mDirection) { + intValue = NS_STYLE_TEXT_ALIGN_RIGHT; + } +#endif // IBMBIDI nsIHTMLContent* content = nsnull; mContent->QueryInterface(kIHTMLContentIID, (void**) &content); if (nsnull != content) { diff --git a/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp b/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp index d0b62e62a33..ad1efe0d0f4 100644 --- a/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFieldSetFrame.cpp @@ -100,6 +100,11 @@ public: nsIAtom* aListName, nsIFrame* aOldFrame, nsIFrame* aNewFrame); + NS_IMETHOD GetFrameForPoint(nsIPresContext* aPresContext, + const nsPoint& aPoint, + nsFramePaintLayer aWhichLayer, + nsIFrame** aFrame); + #ifdef DEBUG NS_IMETHOD GetFrameName(nsAString& aResult) const { return MakeFrameName(NS_LITERAL_STRING("FieldSet"), aResult); @@ -278,10 +283,15 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, { DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); - + // Initialize OUT parameter aStatus = NS_FRAME_COMPLETE; + if (nsnull != aDesiredSize.maxElementSize) { + aDesiredSize.maxElementSize->width = 0; + aDesiredSize.maxElementSize->height = 0; + } + //------------ Handle Incremental Reflow ----------------- nsIFrame* incrementalChild = nsnull; PRBool reflowContent = PR_TRUE; @@ -350,7 +360,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, // availSize could have unconstrained values, don't perform any addition on them nsSize availSize(aReflowState.mComputedWidth, aReflowState.availableHeight); - + // get our border and padding const nsMargin &borderPadding = aReflowState.mComputedBorderPadding; const nsMargin &padding = aReflowState.mComputedPadding; @@ -395,7 +405,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, mLegendSpace = 0; if (mLegendRect.height > border.top) { // center the border on the legend - mLegendSpace = mLegendRect.height - borderPadding.top; + mLegendSpace = mLegendRect.height - border.top; } else { mLegendRect.y = (border.top - mLegendRect.height)/2; } @@ -446,8 +456,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, kidReflowState.reason = reason; - nsHTMLReflowMetrics kidDesiredSize(0,0); - + nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.maxElementSize, aDesiredSize.mFlags); // Reflow the frame ReflowChild(mContentFrame, aPresContext, kidDesiredSize, kidReflowState, kidReflowState.mComputedMargin.left, kidReflowState.mComputedMargin.top, @@ -509,20 +518,26 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, } if (mLegendFrame) { + // use the computed width if the inner content does not fill it + if (aReflowState.mComputedWidth != NS_INTRINSICSIZE && aReflowState.mComputedWidth > contentRect.width ) + contentRect.width = aReflowState.mComputedWidth; + // if the content rect is larger then the legend we can align the legend if (contentRect.width > mLegendRect.width) { PRInt32 align = ((nsLegendFrame*)mLegendFrame)->GetAlign(); - + switch(align) { case NS_STYLE_TEXT_ALIGN_RIGHT: mLegendRect.x = contentRect.width - mLegendRect.width + borderPadding.left; break; case NS_STYLE_TEXT_ALIGN_CENTER: - mLegendRect.x = contentRect.width/2 - mLegendRect.width/2 + borderPadding.left; + float p2t; + aPresContext->GetPixelsToTwips(&p2t); + mLegendRect.x = NSIntPixelsToTwips((nscoord) NSToIntRound((float)(contentRect.width/2 - mLegendRect.width/2 + borderPadding.left) / p2t),p2t); } } else { - contentRect.width = mLegendRect.width + borderPadding.left + borderPadding.right; - aDesiredSize.width = contentRect.width; + //otherwise make place for the legend + contentRect.width = mLegendRect.width; } // place the legend nsRect actualLegendRect(mLegendRect); @@ -554,18 +569,7 @@ nsFieldSetFrame::Reflow(nsIPresContext* aPresContext, if (aDesiredSize.height < min) aDesiredSize.height = min; } - - if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) { - aDesiredSize.width = borderPadding.left + - contentRect.width + - borderPadding.right; - } else { - nscoord min = borderPadding.left + borderPadding.right + mLegendRect.width; - aDesiredSize.width = aReflowState.mComputedWidth + borderPadding.left + borderPadding.right; - if (aDesiredSize.width < min) - aDesiredSize.width = min; - } - + aDesiredSize.width = contentRect.width + borderPadding.left + borderPadding.right; aDesiredSize.ascent = aDesiredSize.height; aDesiredSize.descent = 0; aDesiredSize.mMaximumWidth = aDesiredSize.width; @@ -671,4 +675,12 @@ nsFieldSetFrame::ReplaceFrame(nsIPresContext* aPresContext, aNewFrame); } - +NS_IMETHODIMP +nsFieldSetFrame::GetFrameForPoint(nsIPresContext* aPresContext, + const nsPoint& aPoint, + nsFramePaintLayer aWhichLayer, + nsIFrame** aFrame) +{ + // this should act like a block, so we need to override + return GetFrameForPointUsing(aPresContext, aPoint, nsnull, aWhichLayer, (aWhichLayer == NS_FRAME_PAINT_LAYER_BACKGROUND), aFrame); +} diff --git a/mozilla/layout/html/forms/src/nsLegendFrame.cpp b/mozilla/layout/html/forms/src/nsLegendFrame.cpp index ef64e384eb3..51f8aa1fbd0 100644 --- a/mozilla/layout/html/forms/src/nsLegendFrame.cpp +++ b/mozilla/layout/html/forms/src/nsLegendFrame.cpp @@ -137,6 +137,13 @@ nsLegendFrame::Paint(nsIPresContext* aPresContext, PRInt32 nsLegendFrame::GetAlign() { PRInt32 intValue = NS_STYLE_TEXT_ALIGN_LEFT; +#ifdef IBMBIDI + const nsStyleVisibility* vis; + GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis); + if (NS_STYLE_DIRECTION_RTL == vis->mDirection) { + intValue = NS_STYLE_TEXT_ALIGN_RIGHT; + } +#endif // IBMBIDI nsIHTMLContent* content = nsnull; mContent->QueryInterface(kIHTMLContentIID, (void**) &content); if (nsnull != content) {