From 5a450351dbc366cb9d21b77e99e1e5751e1e838f Mon Sep 17 00:00:00 2001 From: "rods%netscape.com" Date: Wed, 27 Feb 2002 13:03:00 +0000 Subject: [PATCH] Fix up layout for RTL after areaframe jumbles frames. Bug 118509 r=dcone sr=attinasi a=shaver git-svn-id: svn://10.0.0.236/trunk@115421 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/layout/forms/nsFileControlFrame.cpp | 53 ++++++++++++------- .../html/forms/src/nsFileControlFrame.cpp | 53 ++++++++++++------- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/mozilla/layout/forms/nsFileControlFrame.cpp b/mozilla/layout/forms/nsFileControlFrame.cpp index abc81b00765..fa91d9534d5 100644 --- a/mozilla/layout/forms/nsFileControlFrame.cpp +++ b/mozilla/layout/forms/nsFileControlFrame.cpp @@ -374,6 +374,9 @@ NS_IMETHODIMP nsFileControlFrame::Reflow(nsIPresContext* aPresContext, // except for when style is used to change its size. nsresult rv = nsAreaFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); if (NS_SUCCEEDED(rv) && mTextFrame != nsnull) { + const nsStyleVisibility* vis; + GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis); + nsIFrame * child; FirstChild(aPresContext, nsnull, &child); while (child == mTextFrame) { @@ -385,32 +388,46 @@ NS_IMETHODIMP nsFileControlFrame::Reflow(nsIPresContext* aPresContext, mTextFrame->GetRect(txtRect); child->GetRect(buttonRect); - // check to see if we must reflow just the texField - // because style width or height was set. + // check to see if we must reflow just the area frame again + // in order for the text field to be the correct height + // reflowing just the textfield (for some reason) + // messes up the button's rect if (txtRect.width + buttonRect.width != aDesiredSize.width || txtRect.height != aDesiredSize.height) { - - nsSize txtAvailSize(aDesiredSize.width - buttonRect.width, aDesiredSize.height); + nsSize txtAvailSize(aReflowState.availableWidth, aDesiredSize.height); nsHTMLReflowMetrics txtKidSize(&txtAvailSize); - nsHTMLReflowState txtKidReflowState(aPresContext, aReflowState, mTextFrame, txtAvailSize); + nsHTMLReflowState txtKidReflowState(aPresContext, aReflowState, this, txtAvailSize); txtKidReflowState.reason = eReflowReason_Resize; - txtKidReflowState.mComputedWidth = txtAvailSize.width; - txtKidReflowState.mComputedHeight = txtAvailSize.height; - mTextFrame->WillReflow(aPresContext); - nsReflowStatus status; - rv = mTextFrame->Reflow(aPresContext, txtKidSize, txtKidReflowState, status); - if (NS_FAILED(rv)) return rv; - rv = mTextFrame->DidReflow(aPresContext, &txtKidReflowState, aStatus); - if (NS_FAILED(rv)) return rv; + txtKidReflowState.mComputedHeight = aDesiredSize.height; + rv = nsAreaFrame::WillReflow(aPresContext); + NS_ASSERTION(NS_SUCCEEDED(rv), "Should have succeeded"); + rv = nsAreaFrame::Reflow(aPresContext, txtKidSize, txtKidReflowState, aStatus); + NS_ASSERTION(NS_SUCCEEDED(rv), "Should have succeeded"); + rv = nsAreaFrame::DidReflow(aPresContext, &txtKidReflowState, aStatus); + NS_ASSERTION(NS_SUCCEEDED(rv), "Should have succeeded"); - // now adjust the frame positions - buttonRect.x = aDesiredSize.width - buttonRect.width + aReflowState.mComputedBorderPadding.left; + // If LTR then re-calc and set the correct rect + if (NS_STYLE_DIRECTION_RTL != vis->mDirection) { + // now adjust the frame positions + txtRect.y = aReflowState.mComputedBorderPadding.top; + txtRect.height = aDesiredSize.height; + mTextFrame->SetRect(aPresContext, txtRect); + } + } + + // Do RTL positioning + // for some reason the areaframe does set the X coord of the rects correctly + // so we must redo them here + // and we must make sure the text field is the correct height + if (NS_STYLE_DIRECTION_RTL == vis->mDirection) { + buttonRect.x = aReflowState.mComputedBorderPadding.left; child->SetRect(aPresContext, buttonRect); - txtRect.y = aReflowState.mComputedBorderPadding.top; - txtRect.height = aDesiredSize.height; - txtRect.width = aDesiredSize.width - buttonRect.width; + txtRect.x = aDesiredSize.width - txtRect.width + aReflowState.mComputedBorderPadding.left; + txtRect.y = aReflowState.mComputedBorderPadding.top; + txtRect.height = aDesiredSize.height; mTextFrame->SetRect(aPresContext, txtRect); } + } } return rv; diff --git a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp index abc81b00765..fa91d9534d5 100644 --- a/mozilla/layout/html/forms/src/nsFileControlFrame.cpp +++ b/mozilla/layout/html/forms/src/nsFileControlFrame.cpp @@ -374,6 +374,9 @@ NS_IMETHODIMP nsFileControlFrame::Reflow(nsIPresContext* aPresContext, // except for when style is used to change its size. nsresult rv = nsAreaFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); if (NS_SUCCEEDED(rv) && mTextFrame != nsnull) { + const nsStyleVisibility* vis; + GetStyleData(eStyleStruct_Visibility, (const nsStyleStruct*&)vis); + nsIFrame * child; FirstChild(aPresContext, nsnull, &child); while (child == mTextFrame) { @@ -385,32 +388,46 @@ NS_IMETHODIMP nsFileControlFrame::Reflow(nsIPresContext* aPresContext, mTextFrame->GetRect(txtRect); child->GetRect(buttonRect); - // check to see if we must reflow just the texField - // because style width or height was set. + // check to see if we must reflow just the area frame again + // in order for the text field to be the correct height + // reflowing just the textfield (for some reason) + // messes up the button's rect if (txtRect.width + buttonRect.width != aDesiredSize.width || txtRect.height != aDesiredSize.height) { - - nsSize txtAvailSize(aDesiredSize.width - buttonRect.width, aDesiredSize.height); + nsSize txtAvailSize(aReflowState.availableWidth, aDesiredSize.height); nsHTMLReflowMetrics txtKidSize(&txtAvailSize); - nsHTMLReflowState txtKidReflowState(aPresContext, aReflowState, mTextFrame, txtAvailSize); + nsHTMLReflowState txtKidReflowState(aPresContext, aReflowState, this, txtAvailSize); txtKidReflowState.reason = eReflowReason_Resize; - txtKidReflowState.mComputedWidth = txtAvailSize.width; - txtKidReflowState.mComputedHeight = txtAvailSize.height; - mTextFrame->WillReflow(aPresContext); - nsReflowStatus status; - rv = mTextFrame->Reflow(aPresContext, txtKidSize, txtKidReflowState, status); - if (NS_FAILED(rv)) return rv; - rv = mTextFrame->DidReflow(aPresContext, &txtKidReflowState, aStatus); - if (NS_FAILED(rv)) return rv; + txtKidReflowState.mComputedHeight = aDesiredSize.height; + rv = nsAreaFrame::WillReflow(aPresContext); + NS_ASSERTION(NS_SUCCEEDED(rv), "Should have succeeded"); + rv = nsAreaFrame::Reflow(aPresContext, txtKidSize, txtKidReflowState, aStatus); + NS_ASSERTION(NS_SUCCEEDED(rv), "Should have succeeded"); + rv = nsAreaFrame::DidReflow(aPresContext, &txtKidReflowState, aStatus); + NS_ASSERTION(NS_SUCCEEDED(rv), "Should have succeeded"); - // now adjust the frame positions - buttonRect.x = aDesiredSize.width - buttonRect.width + aReflowState.mComputedBorderPadding.left; + // If LTR then re-calc and set the correct rect + if (NS_STYLE_DIRECTION_RTL != vis->mDirection) { + // now adjust the frame positions + txtRect.y = aReflowState.mComputedBorderPadding.top; + txtRect.height = aDesiredSize.height; + mTextFrame->SetRect(aPresContext, txtRect); + } + } + + // Do RTL positioning + // for some reason the areaframe does set the X coord of the rects correctly + // so we must redo them here + // and we must make sure the text field is the correct height + if (NS_STYLE_DIRECTION_RTL == vis->mDirection) { + buttonRect.x = aReflowState.mComputedBorderPadding.left; child->SetRect(aPresContext, buttonRect); - txtRect.y = aReflowState.mComputedBorderPadding.top; - txtRect.height = aDesiredSize.height; - txtRect.width = aDesiredSize.width - buttonRect.width; + txtRect.x = aDesiredSize.width - txtRect.width + aReflowState.mComputedBorderPadding.left; + txtRect.y = aReflowState.mComputedBorderPadding.top; + txtRect.height = aDesiredSize.height; mTextFrame->SetRect(aPresContext, txtRect); } + } } return rv;