Set inflation container and width correctly during reflow. (Bug 706609, patch 3) r=roc

This is the second of three patches to rework the way we handle getting
the font inflation container and width data during reflow, which are
needed so that we can sometimes honor inflation during intrinsic width
calculation (which we need to do to make some form controls inflate
correctly).
This commit is contained in:
L. David Baron 2012-01-24 17:21:28 -08:00
parent 82aef174b7
commit 77cffa9ed9
4 changed files with 44 additions and 0 deletions

View File

@ -7509,6 +7509,20 @@ PresShell::DoReflow(nsIFrame* target, bool aInterruptible)
return false;
}
NS_ASSERTION(!mPresContext->mCurrentInflationContainer,
"current inflation container should be null");
AutoRestore<nsIFrame*> restoreInflationContainer(mPresContext->
mCurrentInflationContainer);
for (nsIFrame *f = target->GetParent(); f; f = f->GetParent()) {
if (nsLayoutUtils::IsContainerForFontSizeInflation(f)) {
NS_ASSERTION(!(f->GetStateBits() & NS_FRAME_IN_REFLOW),
"a frame outside should not be in reflow");
mPresContext->mCurrentInflationContainer = f;
mPresContext->mCurrentInflationContainerWidth = f->GetContentRect().width;
break;
}
}
#ifdef DEBUG
mCurrentReflowRoot = target;
#endif

View File

@ -90,6 +90,9 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
: nsCSSOffsetState(aFrame, aRenderingContext)
, mBlockDelta(0)
, mReflowDepth(0)
, mRestoreCurrentInflationContainer(aPresContext->mCurrentInflationContainer)
, mRestoreCurrentInflationContainerWidth(aPresContext->
mCurrentInflationContainerWidth)
{
NS_PRECONDITION(aPresContext, "no pres context");
NS_PRECONDITION(aRenderingContext, "no rendering context");
@ -132,6 +135,9 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
, mBlockDelta(0)
, mReflowDepth(aParentReflowState.mReflowDepth + 1)
, mFlags(aParentReflowState.mFlags)
, mRestoreCurrentInflationContainer(aPresContext->mCurrentInflationContainer)
, mRestoreCurrentInflationContainerWidth(aPresContext->
mCurrentInflationContainerWidth)
{
NS_PRECONDITION(aPresContext, "no pres context");
NS_PRECONDITION(aFrame, "no frame");
@ -1894,6 +1900,11 @@ nsHTMLReflowState::InitConstraints(nsPresContext* aPresContext,
const nsStyleTextReset* st = frame->GetStyleTextReset();
mFlags.mBlinks = (st->mTextBlink != NS_STYLE_TEXT_BLINK_NONE);
}
if (nsLayoutUtils::IsContainerForFontSizeInflation(frame)) {
aPresContext->mCurrentInflationContainer = frame;
aPresContext->mCurrentInflationContainerWidth = mComputedWidth;
}
}
static void

View File

@ -43,6 +43,7 @@
#include "nsMargin.h"
#include "nsStyleCoord.h"
#include "nsIFrame.h"
#include "mozilla/AutoRestore.h"
class nsPresContext;
class nsRenderingContext;
@ -369,6 +370,12 @@ public:
} mFlags;
private:
mozilla::AutoRestore<nsIFrame*> mRestoreCurrentInflationContainer;
mozilla::AutoRestore<nscoord> mRestoreCurrentInflationContainerWidth;
public:
// Note: The copy constructor is written by the compiler automatically. You
// can use that and then override specific values if you want, or you can
// call Init as desired...

View File

@ -537,6 +537,18 @@ nsIFrame::Layout(nsBoxLayoutState& aState)
{
NS_ASSERTION(aState.GetRenderingContext(), "must have rendering context");
nsPresContext *presContext = aState.PresContext();
AutoRestore<nsIFrame*> restoreCurrentInflationContainer(presContext->
mCurrentInflationContainer);
AutoRestore<nscoord> restoreCurrentInflationContainerWidth(presContext->
mCurrentInflationContainerWidth);
if (nsLayoutUtils::IsContainerForFontSizeInflation(mParent) &&
mParent->IsBoxFrame()) {
presContext->mCurrentInflationContainer = mParent;
presContext->mCurrentInflationContainerWidth =
mParent->GetContentRect().width;
}
nsBox *box = static_cast<nsBox*>(this);
DISPLAY_LAYOUT(box);