Bug 794693, part 1: Refactor nsHTMLReflowState constructor to allow initialization to be done by caller. [r=dbaron]

This commit is contained in:
Scott Johnson
2013-09-07 19:02:10 -05:00
parent fd9715bd30
commit 0811cc3636
9 changed files with 76 additions and 32 deletions

View File

@@ -684,7 +684,7 @@ nsFlexContainerFrame::AppendFlexItemForChild(
aChildFrame, aChildFrame,
nsSize(aParentReflowState.ComputedWidth(), nsSize(aParentReflowState.ComputedWidth(),
NS_UNCONSTRAINEDSIZE), NS_UNCONSTRAINEDSIZE),
-1, -1, false); -1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
childRSForMeasuringHeight.mFlags.mIsFlexContainerMeasuringHeight = true; childRSForMeasuringHeight.mFlags.mIsFlexContainerMeasuringHeight = true;
childRSForMeasuringHeight.Init(aPresContext); childRSForMeasuringHeight.Init(aPresContext);

View File

@@ -419,7 +419,7 @@ nsHTMLScrollFrame::ReflowScrolledFrame(ScrollReflowState* aState,
nsHTMLReflowState kidReflowState(presContext, aState->mReflowState, nsHTMLReflowState kidReflowState(presContext, aState->mReflowState,
mInner.mScrolledFrame, mInner.mScrolledFrame,
nsSize(availWidth, NS_UNCONSTRAINEDSIZE), nsSize(availWidth, NS_UNCONSTRAINEDSIZE),
-1, -1, false); -1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
kidReflowState.Init(presContext, -1, -1, nullptr, kidReflowState.Init(presContext, -1, -1, nullptr,
&aState->mReflowState.mComputedPadding); &aState->mReflowState.mComputedPadding);
kidReflowState.mFlags.mAssumingHScrollbar = aAssumeHScroll; kidReflowState.mFlags.mAssumingHScrollbar = aAssumeHScroll;

View File

@@ -49,7 +49,7 @@ static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized;
// use for measuring things. // use for measuring things.
nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext, nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
nsIFrame* aFrame, nsIFrame* aFrame,
nsRenderingContext* aRenderingContext, nsRenderingContext* aRenderingContext,
const nsSize& aAvailableSpace, const nsSize& aAvailableSpace,
uint32_t aFlags) uint32_t aFlags)
: nsCSSOffsetState(aFrame, aRenderingContext) : nsCSSOffsetState(aFrame, aRenderingContext)
@@ -72,7 +72,9 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
mFlags.mDummyParentReflowState = true; mFlags.mDummyParentReflowState = true;
} }
Init(aPresContext); if (!(aFlags & CALLER_WILL_INIT)) {
Init(aPresContext);
}
} }
static bool CheckNextInFlowParenthood(nsIFrame* aFrame, nsIFrame* aParent) static bool CheckNextInFlowParenthood(nsIFrame* aFrame, nsIFrame* aParent)
@@ -121,6 +123,7 @@ FontSizeInflationListMarginAdjustment(const nsIFrame* aFrame)
return 0; return 0;
} }
// Initialize a reflow state for a child frames reflow. Some state // Initialize a reflow state for a child frames reflow. Some state
// is copied from the parent reflow state; the remaining state is // is copied from the parent reflow state; the remaining state is
// computed. // computed.
@@ -130,7 +133,7 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
const nsSize& aAvailableSpace, const nsSize& aAvailableSpace,
nscoord aContainingBlockWidth, nscoord aContainingBlockWidth,
nscoord aContainingBlockHeight, nscoord aContainingBlockHeight,
bool aInit) uint32_t aFlags)
: nsCSSOffsetState(aFrame, aParentReflowState.rendContext) : nsCSSOffsetState(aFrame, aParentReflowState.rendContext)
, mBlockDelta(0) , mBlockDelta(0)
, mReflowDepth(aParentReflowState.mReflowDepth + 1) , mReflowDepth(aParentReflowState.mReflowDepth + 1)
@@ -175,11 +178,15 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext,
mFlags.mDummyParentReflowState = false; mFlags.mDummyParentReflowState = false;
mDiscoveredClearance = nullptr; mDiscoveredClearance = nullptr;
mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver && mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver &&
aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this)) aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this))
? aParentReflowState.mPercentHeightObserver : nullptr; ? aParentReflowState.mPercentHeightObserver : nullptr;
if (aInit) { if (aFlags & DUMMY_PARENT_REFLOW_STATE) {
mFlags.mDummyParentReflowState = true;
}
if (!(aFlags & CALLER_WILL_INIT)) {
Init(aPresContext, aContainingBlockWidth, aContainingBlockHeight); Init(aPresContext, aContainingBlockWidth, aContainingBlockHeight);
} }
} }

View File

@@ -380,30 +380,59 @@ public:
// can use that and then override specific values if you want, or you can // can use that and then override specific values if you want, or you can
// call Init as desired... // call Init as desired...
// Initialize a <b>root</b> reflow state with a rendering context to /**
// use for measuring things. * Initialize a ROOT reflow state.
*
* @param aPresContext Must be equal to aFrame->PresContext().
* @param aFrame The frame for whose reflow state is being constructed.
* @param aRenderingContext The rendering context to be used for measurements.
* @param aAvailableSpace See comments for availableHeight and availableWidth
* members.
* @param aFlags A set of flags used for additional boolean parameters (see
* below).
*/
nsHTMLReflowState(nsPresContext* aPresContext, nsHTMLReflowState(nsPresContext* aPresContext,
nsIFrame* aFrame, nsIFrame* aFrame,
nsRenderingContext* aRenderingContext, nsRenderingContext* aRenderingContext,
const nsSize& aAvailableSpace, const nsSize& aAvailableSpace,
uint32_t aFlags = 0); uint32_t aFlags = 0);
// Initialize a reflow state for a child frame's reflow. Some state /**
// is copied from the parent reflow state; the remaining state is * Initialize a reflow state for a child frame's reflow. Some parts of the
// computed. * state are copied from the parent's reflow state. The remainder is computed.
*
* @param aPresContext Must be equal to aFrame->PresContext().
* @param aParentReflowState A reference to an nsHTMLReflowState object that
* is to be the parent of this object.
* @param aFrame The frame for whose reflow state is being constructed.
* @param aAvailableSpace See comments for availableHeight and availableWidth
* members.
* @param aContainingBlockWidth An optional width, in app units, that is used
* by absolute positioning code to override default containing block
* width.
* @param aContainingBlockHeight An optional height, in app units, that is
* used by absolute positioning code to override default containing
* block height.
* @param aFlags A set of flags used for additional boolean parameters (see
* below).
*/
nsHTMLReflowState(nsPresContext* aPresContext, nsHTMLReflowState(nsPresContext* aPresContext,
const nsHTMLReflowState& aParentReflowState, const nsHTMLReflowState& aParentReflowState,
nsIFrame* aFrame, nsIFrame* aFrame,
const nsSize& aAvailableSpace, const nsSize& aAvailableSpace,
// These two are used by absolute positioning code
// to override default containing block w & h:
nscoord aContainingBlockWidth = -1, nscoord aContainingBlockWidth = -1,
nscoord aContainingBlockHeight = -1, nscoord aContainingBlockHeight = -1,
bool aInit = true); uint32_t aFlags = 0);
// Values for |aFlags| passed to constructor // Values for |aFlags| passed to constructor
enum { enum {
DUMMY_PARENT_REFLOW_STATE = (1<<0) // Indicates that the parent of this reflow state is "fake" (see
// mDummyParentReflowState in mFlags).
DUMMY_PARENT_REFLOW_STATE = (1<<0),
// Indicates that the calling function will initialize the reflow state, and
// that the constructor should not call Init().
CALLER_WILL_INIT = (1<<1)
}; };
// This method initializes various data members. It is automatically // This method initializes various data members. It is automatically

View File

@@ -911,7 +911,7 @@ nsMathMLContainerFrame::Reflow(nsPresContext* aPresContext,
while (childFrame) { while (childFrame) {
nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags); nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags);
nsHTMLReflowState childReflowState(aPresContext, aReflowState, nsHTMLReflowState childReflowState(aPresContext, aReflowState,
childFrame, availSize); childFrame, availSize, (uint32_t)0);
nsresult rv = ReflowChild(childFrame, aPresContext, childDesiredSize, nsresult rv = ReflowChild(childFrame, aPresContext, childDesiredSize,
childReflowState, childStatus); childReflowState, childStatus);
//NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status"); //NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status");

View File

@@ -2681,7 +2681,7 @@ nsTableFrame::SetupHeaderFooterChild(const nsTableReflowState& aReflowState,
nsHTMLReflowState kidReflowState(presContext, aReflowState.reflowState, nsHTMLReflowState kidReflowState(presContext, aReflowState.reflowState,
aFrame, aFrame,
nsSize(aReflowState.availSize.width, NS_UNCONSTRAINEDSIZE), nsSize(aReflowState.availSize.width, NS_UNCONSTRAINEDSIZE),
-1, -1, false); -1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(kidReflowState); InitChildReflowState(kidReflowState);
kidReflowState.mFlags.mIsTopOfPage = true; kidReflowState.mFlags.mIsTopOfPage = true;
nsHTMLReflowMetrics desiredSize; nsHTMLReflowMetrics desiredSize;
@@ -2708,7 +2708,8 @@ nsTableFrame::PlaceRepeatedFooter(nsTableReflowState& aReflowState,
nsHTMLReflowState footerReflowState(presContext, nsHTMLReflowState footerReflowState(presContext,
aReflowState.reflowState, aReflowState.reflowState,
aTfoot, kidAvailSize, aTfoot, kidAvailSize,
-1, -1, false); -1, -1,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(footerReflowState); InitChildReflowState(footerReflowState);
aReflowState.y += GetCellSpacingY(); aReflowState.y += GetCellSpacingY();
@@ -2828,7 +2829,8 @@ nsTableFrame::ReflowChildren(nsTableReflowState& aReflowState,
// Reflow the child into the available space // Reflow the child into the available space
nsHTMLReflowState kidReflowState(presContext, aReflowState.reflowState, nsHTMLReflowState kidReflowState(presContext, aReflowState.reflowState,
kidFrame, kidAvailSize, kidFrame, kidAvailSize,
-1, -1, false); -1, -1,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(kidReflowState); InitChildReflowState(kidReflowState);
// If this isn't the first row group, and the previous row group has a // If this isn't the first row group, and the previous row group has a

View File

@@ -382,7 +382,7 @@ nsTableOuterFrame::GetChildMargin(nsPresContext* aPresContext,
// XXX We really shouldn't construct a reflow state to do this. // XXX We really shouldn't construct a reflow state to do this.
nsHTMLReflowState childRS(aPresContext, aOuterRS, aChildFrame, nsHTMLReflowState childRS(aPresContext, aOuterRS, aChildFrame,
nsSize(aAvailWidth, aOuterRS.availableHeight), nsSize(aAvailWidth, aOuterRS.availableHeight),
-1, -1, false); -1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, childRS); InitChildReflowState(*aPresContext, childRS);
aMargin = childRS.mComputedMargin; aMargin = childRS.mComputedMargin;
@@ -824,7 +824,7 @@ nsTableOuterFrame::OuterBeginReflowChild(nsPresContext* aPresContext,
// it // it
nsHTMLReflowState &childRS = * new (aChildRSSpace) nsHTMLReflowState &childRS = * new (aChildRSSpace)
nsHTMLReflowState(aPresContext, aOuterRS, aChildFrame, availSize, nsHTMLReflowState(aPresContext, aOuterRS, aChildFrame, availSize,
-1, -1, false); -1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, childRS); InitChildReflowState(*aPresContext, childRS);
// see if we need to reset top-of-page due to a caption // see if we need to reset top-of-page due to a caption

View File

@@ -28,9 +28,9 @@ struct nsTableCellReflowState : public nsHTMLReflowState
const nsHTMLReflowState& aParentReflowState, const nsHTMLReflowState& aParentReflowState,
nsIFrame* aFrame, nsIFrame* aFrame,
const nsSize& aAvailableSpace, const nsSize& aAvailableSpace,
bool aInit = true) uint32_t aFlags = 0)
: nsHTMLReflowState(aPresContext, aParentReflowState, aFrame, : nsHTMLReflowState(aPresContext, aParentReflowState, aFrame,
aAvailableSpace, -1, -1, aInit) aAvailableSpace, -1, -1, aFlags)
{ {
} }
@@ -810,7 +810,8 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext,
// it's an unknown frame type, give it a generic reflow and ignore the results // it's an unknown frame type, give it a generic reflow and ignore the results
nsTableCellReflowState kidReflowState(aPresContext, aReflowState, nsTableCellReflowState kidReflowState(aPresContext, aReflowState,
kidFrame, nsSize(0,0), false); kidFrame, nsSize(0,0),
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, nsSize(0,0), false, kidReflowState); InitChildReflowState(*aPresContext, nsSize(0,0), false, kidReflowState);
nsHTMLReflowMetrics desiredSize; nsHTMLReflowMetrics desiredSize;
nsReflowStatus status; nsReflowStatus status;
@@ -889,7 +890,8 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext,
// Reflow the child // Reflow the child
nsTableCellReflowState kidReflowState(aPresContext, aReflowState, nsTableCellReflowState kidReflowState(aPresContext, aReflowState,
kidFrame, kidAvailSize, false); kidFrame, kidAvailSize,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, kidAvailSize, borderCollapse, InitChildReflowState(*aPresContext, kidAvailSize, borderCollapse,
kidReflowState); kidReflowState);
@@ -1083,7 +1085,8 @@ nsTableRowFrame::ReflowCellFrame(nsPresContext* aPresContext,
nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this);
bool borderCollapse = tableFrame->IsBorderCollapse(); bool borderCollapse = tableFrame->IsBorderCollapse();
nsTableCellReflowState cellReflowState(aPresContext, aReflowState, nsTableCellReflowState cellReflowState(aPresContext, aReflowState,
aCellFrame, availSize, false); aCellFrame, availSize,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, availSize, borderCollapse, cellReflowState); InitChildReflowState(*aPresContext, availSize, borderCollapse, cellReflowState);
cellReflowState.mFlags.mIsTopOfPage = aIsTopOfPage; cellReflowState.mFlags.mIsTopOfPage = aIsTopOfPage;

View File

@@ -371,7 +371,8 @@ nsTableRowGroupFrame::ReflowChildren(nsPresContext* aPresContext,
nsSize kidAvailSize(aReflowState.availSize.width, NS_UNCONSTRAINEDSIZE); nsSize kidAvailSize(aReflowState.availSize.width, NS_UNCONSTRAINEDSIZE);
nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState,
kidFrame, kidAvailSize, kidFrame, kidAvailSize,
-1, -1, false); -1, -1,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, borderCollapse, kidReflowState); InitChildReflowState(*aPresContext, borderCollapse, kidReflowState);
// This can indicate that columns were resized. // This can indicate that columns were resized.
@@ -933,7 +934,8 @@ nsTableRowGroupFrame::SplitSpanningCells(nsPresContext& aPresContext,
rowAvailSize.height = std::min(rowAvailSize.height, rowRect.height); rowAvailSize.height = std::min(rowAvailSize.height, rowRect.height);
nsHTMLReflowState rowReflowState(&aPresContext, aReflowState, nsHTMLReflowState rowReflowState(&aPresContext, aReflowState,
row, rowAvailSize, row, rowAvailSize,
-1, -1, false); -1, -1,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(aPresContext, borderCollapse, rowReflowState); InitChildReflowState(aPresContext, borderCollapse, rowReflowState);
rowReflowState.mFlags.mIsTopOfPage = isTopOfPage; // set top of page rowReflowState.mFlags.mIsTopOfPage = isTopOfPage; // set top of page
@@ -1068,7 +1070,8 @@ nsTableRowGroupFrame::SplitRowGroup(nsPresContext* aPresContext,
nsHTMLReflowState rowReflowState(aPresContext, aReflowState, nsHTMLReflowState rowReflowState(aPresContext, aReflowState,
rowFrame, availSize, rowFrame, availSize,
-1, -1, false); -1, -1,
nsHTMLReflowState::CALLER_WILL_INIT);
InitChildReflowState(*aPresContext, borderCollapse, rowReflowState); InitChildReflowState(*aPresContext, borderCollapse, rowReflowState);
rowReflowState.mFlags.mIsTopOfPage = isTopOfPage; // set top of page rowReflowState.mFlags.mIsTopOfPage = isTopOfPage; // set top of page