From 5b7536c02a0095819d1907f34ed81e7da59878a0 Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Sat, 7 Sep 2013 19:02:10 -0500 Subject: [PATCH] Bug 794693, part 1: Refactor nsHTMLReflowState constructor to allow initialization to be done by caller. [r=dbaron] --- layout/generic/nsFlexContainerFrame.cpp | 2 +- layout/generic/nsGfxScrollFrame.cpp | 2 +- layout/generic/nsHTMLReflowState.cpp | 19 ++++++--- layout/generic/nsHTMLReflowState.h | 49 +++++++++++++++++++----- layout/mathml/nsMathMLContainerFrame.cpp | 2 +- layout/tables/nsTableFrame.cpp | 8 ++-- layout/tables/nsTableOuterFrame.cpp | 4 +- layout/tables/nsTableRowFrame.cpp | 13 ++++--- layout/tables/nsTableRowGroupFrame.cpp | 9 +++-- 9 files changed, 76 insertions(+), 32 deletions(-) diff --git a/layout/generic/nsFlexContainerFrame.cpp b/layout/generic/nsFlexContainerFrame.cpp index c377f9bba6bf..6139f7e094d8 100644 --- a/layout/generic/nsFlexContainerFrame.cpp +++ b/layout/generic/nsFlexContainerFrame.cpp @@ -684,7 +684,7 @@ nsFlexContainerFrame::AppendFlexItemForChild( aChildFrame, nsSize(aParentReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE), - -1, -1, false); + -1, -1, nsHTMLReflowState::CALLER_WILL_INIT); childRSForMeasuringHeight.mFlags.mIsFlexContainerMeasuringHeight = true; childRSForMeasuringHeight.Init(aPresContext); diff --git a/layout/generic/nsGfxScrollFrame.cpp b/layout/generic/nsGfxScrollFrame.cpp index 85ddcd58c815..8f0270d34161 100644 --- a/layout/generic/nsGfxScrollFrame.cpp +++ b/layout/generic/nsGfxScrollFrame.cpp @@ -419,7 +419,7 @@ nsHTMLScrollFrame::ReflowScrolledFrame(ScrollReflowState* aState, nsHTMLReflowState kidReflowState(presContext, aState->mReflowState, mInner.mScrolledFrame, nsSize(availWidth, NS_UNCONSTRAINEDSIZE), - -1, -1, false); + -1, -1, nsHTMLReflowState::CALLER_WILL_INIT); kidReflowState.Init(presContext, -1, -1, nullptr, &aState->mReflowState.mComputedPadding); kidReflowState.mFlags.mAssumingHScrollbar = aAssumeHScroll; diff --git a/layout/generic/nsHTMLReflowState.cpp b/layout/generic/nsHTMLReflowState.cpp index d8bbfa82013b..4a20f5f12ad2 100644 --- a/layout/generic/nsHTMLReflowState.cpp +++ b/layout/generic/nsHTMLReflowState.cpp @@ -49,7 +49,7 @@ static eNormalLineHeightControl sNormalLineHeightControl = eUninitialized; // use for measuring things. nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext, nsIFrame* aFrame, - nsRenderingContext* aRenderingContext, + nsRenderingContext* aRenderingContext, const nsSize& aAvailableSpace, uint32_t aFlags) : nsCSSOffsetState(aFrame, aRenderingContext) @@ -72,7 +72,9 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext, mFlags.mDummyParentReflowState = true; } - Init(aPresContext); + if (!(aFlags & CALLER_WILL_INIT)) { + Init(aPresContext); + } } static bool CheckNextInFlowParenthood(nsIFrame* aFrame, nsIFrame* aParent) @@ -121,6 +123,7 @@ FontSizeInflationListMarginAdjustment(const nsIFrame* aFrame) return 0; } + // Initialize a reflow state for a child frames reflow. Some state // is copied from the parent reflow state; the remaining state is // computed. @@ -130,7 +133,7 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext, const nsSize& aAvailableSpace, nscoord aContainingBlockWidth, nscoord aContainingBlockHeight, - bool aInit) + uint32_t aFlags) : nsCSSOffsetState(aFrame, aParentReflowState.rendContext) , mBlockDelta(0) , mReflowDepth(aParentReflowState.mReflowDepth + 1) @@ -175,11 +178,15 @@ nsHTMLReflowState::nsHTMLReflowState(nsPresContext* aPresContext, mFlags.mDummyParentReflowState = false; mDiscoveredClearance = nullptr; - mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver && - aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this)) + mPercentHeightObserver = (aParentReflowState.mPercentHeightObserver && + aParentReflowState.mPercentHeightObserver->NeedsToObserve(*this)) ? aParentReflowState.mPercentHeightObserver : nullptr; - if (aInit) { + if (aFlags & DUMMY_PARENT_REFLOW_STATE) { + mFlags.mDummyParentReflowState = true; + } + + if (!(aFlags & CALLER_WILL_INIT)) { Init(aPresContext, aContainingBlockWidth, aContainingBlockHeight); } } diff --git a/layout/generic/nsHTMLReflowState.h b/layout/generic/nsHTMLReflowState.h index 95ac50ae5250..ae6fd31dfb35 100644 --- a/layout/generic/nsHTMLReflowState.h +++ b/layout/generic/nsHTMLReflowState.h @@ -380,30 +380,59 @@ public: // can use that and then override specific values if you want, or you can // call Init as desired... - // Initialize a root 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, nsIFrame* aFrame, - nsRenderingContext* aRenderingContext, + nsRenderingContext* aRenderingContext, const nsSize& aAvailableSpace, 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 - // computed. + /** + * Initialize a reflow state for a child frame's reflow. Some parts of the + * 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, const nsHTMLReflowState& aParentReflowState, nsIFrame* aFrame, const nsSize& aAvailableSpace, - // These two are used by absolute positioning code - // to override default containing block w & h: nscoord aContainingBlockWidth = -1, nscoord aContainingBlockHeight = -1, - bool aInit = true); + uint32_t aFlags = 0); // Values for |aFlags| passed to constructor 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 diff --git a/layout/mathml/nsMathMLContainerFrame.cpp b/layout/mathml/nsMathMLContainerFrame.cpp index 877c486452bf..73d2ed79067a 100644 --- a/layout/mathml/nsMathMLContainerFrame.cpp +++ b/layout/mathml/nsMathMLContainerFrame.cpp @@ -911,7 +911,7 @@ nsMathMLContainerFrame::Reflow(nsPresContext* aPresContext, while (childFrame) { nsHTMLReflowMetrics childDesiredSize(aDesiredSize.mFlags); nsHTMLReflowState childReflowState(aPresContext, aReflowState, - childFrame, availSize); + childFrame, availSize, (uint32_t)0); nsresult rv = ReflowChild(childFrame, aPresContext, childDesiredSize, childReflowState, childStatus); //NS_ASSERTION(NS_FRAME_IS_COMPLETE(childStatus), "bad status"); diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp index a09f26f8b4e7..4d238351c85a 100644 --- a/layout/tables/nsTableFrame.cpp +++ b/layout/tables/nsTableFrame.cpp @@ -2681,7 +2681,7 @@ nsTableFrame::SetupHeaderFooterChild(const nsTableReflowState& aReflowState, nsHTMLReflowState kidReflowState(presContext, aReflowState.reflowState, aFrame, nsSize(aReflowState.availSize.width, NS_UNCONSTRAINEDSIZE), - -1, -1, false); + -1, -1, nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(kidReflowState); kidReflowState.mFlags.mIsTopOfPage = true; nsHTMLReflowMetrics desiredSize; @@ -2708,7 +2708,8 @@ nsTableFrame::PlaceRepeatedFooter(nsTableReflowState& aReflowState, nsHTMLReflowState footerReflowState(presContext, aReflowState.reflowState, aTfoot, kidAvailSize, - -1, -1, false); + -1, -1, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(footerReflowState); aReflowState.y += GetCellSpacingY(); @@ -2828,7 +2829,8 @@ nsTableFrame::ReflowChildren(nsTableReflowState& aReflowState, // Reflow the child into the available space nsHTMLReflowState kidReflowState(presContext, aReflowState.reflowState, kidFrame, kidAvailSize, - -1, -1, false); + -1, -1, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(kidReflowState); // If this isn't the first row group, and the previous row group has a diff --git a/layout/tables/nsTableOuterFrame.cpp b/layout/tables/nsTableOuterFrame.cpp index c50c822e4610..a5b452e1e193 100644 --- a/layout/tables/nsTableOuterFrame.cpp +++ b/layout/tables/nsTableOuterFrame.cpp @@ -382,7 +382,7 @@ nsTableOuterFrame::GetChildMargin(nsPresContext* aPresContext, // XXX We really shouldn't construct a reflow state to do this. nsHTMLReflowState childRS(aPresContext, aOuterRS, aChildFrame, nsSize(aAvailWidth, aOuterRS.availableHeight), - -1, -1, false); + -1, -1, nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, childRS); aMargin = childRS.mComputedMargin; @@ -824,7 +824,7 @@ nsTableOuterFrame::OuterBeginReflowChild(nsPresContext* aPresContext, // it nsHTMLReflowState &childRS = * new (aChildRSSpace) nsHTMLReflowState(aPresContext, aOuterRS, aChildFrame, availSize, - -1, -1, false); + -1, -1, nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, childRS); // see if we need to reset top-of-page due to a caption diff --git a/layout/tables/nsTableRowFrame.cpp b/layout/tables/nsTableRowFrame.cpp index f95da67a702a..e3b12c1f28a4 100644 --- a/layout/tables/nsTableRowFrame.cpp +++ b/layout/tables/nsTableRowFrame.cpp @@ -28,9 +28,9 @@ struct nsTableCellReflowState : public nsHTMLReflowState const nsHTMLReflowState& aParentReflowState, nsIFrame* aFrame, const nsSize& aAvailableSpace, - bool aInit = true) + uint32_t aFlags = 0) : 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 nsTableCellReflowState kidReflowState(aPresContext, aReflowState, - kidFrame, nsSize(0,0), false); + kidFrame, nsSize(0,0), + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, nsSize(0,0), false, kidReflowState); nsHTMLReflowMetrics desiredSize; nsReflowStatus status; @@ -889,7 +890,8 @@ nsTableRowFrame::ReflowChildren(nsPresContext* aPresContext, // Reflow the child nsTableCellReflowState kidReflowState(aPresContext, aReflowState, - kidFrame, kidAvailSize, false); + kidFrame, kidAvailSize, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, kidAvailSize, borderCollapse, kidReflowState); @@ -1083,7 +1085,8 @@ nsTableRowFrame::ReflowCellFrame(nsPresContext* aPresContext, nsTableFrame* tableFrame = nsTableFrame::GetTableFrame(this); bool borderCollapse = tableFrame->IsBorderCollapse(); nsTableCellReflowState cellReflowState(aPresContext, aReflowState, - aCellFrame, availSize, false); + aCellFrame, availSize, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, availSize, borderCollapse, cellReflowState); cellReflowState.mFlags.mIsTopOfPage = aIsTopOfPage; diff --git a/layout/tables/nsTableRowGroupFrame.cpp b/layout/tables/nsTableRowGroupFrame.cpp index 111568584895..a02b74919220 100644 --- a/layout/tables/nsTableRowGroupFrame.cpp +++ b/layout/tables/nsTableRowGroupFrame.cpp @@ -371,7 +371,8 @@ nsTableRowGroupFrame::ReflowChildren(nsPresContext* aPresContext, nsSize kidAvailSize(aReflowState.availSize.width, NS_UNCONSTRAINEDSIZE); nsHTMLReflowState kidReflowState(aPresContext, aReflowState.reflowState, kidFrame, kidAvailSize, - -1, -1, false); + -1, -1, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, borderCollapse, kidReflowState); // This can indicate that columns were resized. @@ -933,7 +934,8 @@ nsTableRowGroupFrame::SplitSpanningCells(nsPresContext& aPresContext, rowAvailSize.height = std::min(rowAvailSize.height, rowRect.height); nsHTMLReflowState rowReflowState(&aPresContext, aReflowState, row, rowAvailSize, - -1, -1, false); + -1, -1, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(aPresContext, borderCollapse, rowReflowState); rowReflowState.mFlags.mIsTopOfPage = isTopOfPage; // set top of page @@ -1068,7 +1070,8 @@ nsTableRowGroupFrame::SplitRowGroup(nsPresContext* aPresContext, nsHTMLReflowState rowReflowState(aPresContext, aReflowState, rowFrame, availSize, - -1, -1, false); + -1, -1, + nsHTMLReflowState::CALLER_WILL_INIT); InitChildReflowState(*aPresContext, borderCollapse, rowReflowState); rowReflowState.mFlags.mIsTopOfPage = isTopOfPage; // set top of page