nsColumnSetFrame::ReflowConfig nsColumnSetFrame::ChooseColumnStrategy(const nsHTMLReflowState& aReflowState, bool aForceAuto = false, nscoord aFeasibleHeight = NS_INTRINSICSIZE, nscoord aInfeasibleHeight = 0) { nscoord knownFeasibleHeight = aFeasibleHeight; nscoord knownInfeasibleHeight = aInfeasibleHeight; const nsStyleColumn* colStyle = StyleColumn(); nscoord availContentWidth = GetAvailableContentWidth(aReflowState); if (aReflowState.ComputedWidth() != NS_INTRINSICSIZE) { availContentWidth = aReflowState.ComputedWidth(); } nscoord consumedBSize = GetConsumedBSize(); // The effective computed height is the height of the current continuation // of the column set frame. This should be the same as the computed height // if we have an unconstrained available height. nscoord computedBSize = GetEffectiveComputedBSize(aReflowState, consumedBSize); nscoord colHeight = GetAvailableContentHeight(aReflowState); if (aReflowState.ComputedHeight() != NS_INTRINSICSIZE) { colHeight = aReflowState.ComputedHeight(); } else if (aReflowState.ComputedMaxHeight() != NS_INTRINSICSIZE) { colHeight = std::min(colHeight, aReflowState.ComputedMaxHeight()); } nscoord colGap = GetColumnGap(this, colStyle); int32_t numColumns = colStyle->mColumnCount; // If column-fill is set to 'balance', then we want to balance the columns. const bool isBalancing = colStyle->mColumnFill == NS_STYLE_COLUMN_FILL_BALANCE && !aForceAuto; if (isBalancing) { const uint32_t MAX_NESTED_COLUMN_BALANCING = 2; uint32_t cnt = 0; for (const nsHTMLReflowState* rs = aReflowState.parentReflowState; rs && cnt < MAX_NESTED_COLUMN_BALANCING; rs = rs->parentReflowState) { if (rs->mFlags.mIsColumnBalancing) { ++cnt; } } if (cnt == MAX_NESTED_COLUMN_BALANCING) { numColumns = 1; } } nscoord colWidth; if (colStyle->mColumnWidth.GetUnit() == eStyleUnit_Coord) { colWidth = colStyle->mColumnWidth.GetCoordValue(); NS_ASSERTION(colWidth >= 0, "negative column width"); // Reduce column count if necessary to make columns fit in the // available width. Compute max number of columns that fit in // availContentWidth, satisfying colGap*(maxColumns - 1) + // colWidth*maxColumns <= availContentWidth if (availContentWidth != NS_INTRINSICSIZE && colGap + colWidth > 0 && numColumns > 0) { // This expression uses truncated rounding, which is what we // want int32_t maxColumns = std::min(nscoord(nsStyleColumn::kMaxColumnCount), (availContentWidth + colGap)/(colGap + colWidth)); numColumns = std::max(1, std::min(numColumns, maxColumns)); } } else if (numColumns > 0 && availContentWidth != NS_INTRINSICSIZE) { nscoord widthMinusGaps = availContentWidth - colGap*(numColumns - 1); colWidth = widthMinusGaps/numColumns; } else { colWidth = NS_INTRINSICSIZE; } // Take care of the situation where there's only one column but it's // still too wide colWidth = std::max(1, std::min(colWidth, availContentWidth)); nscoord expectedWidthLeftOver = 0; if (colWidth != NS_INTRINSICSIZE && availContentWidth != NS_INTRINSICSIZE) { // distribute leftover space // First, determine how many columns will be showing if the column // count is auto if (numColumns <= 0) { // choose so that colGap*(nominalColumnCount - 1) + // colWidth*nominalColumnCount is nearly availContentWidth // make sure to round down if (colGap + colWidth > 0) { numColumns = (availContentWidth + colGap)/(colGap + colWidth); // The number of columns should never exceed kMaxColumnCount. numColumns = std::min(nscoord(nsStyleColumn::kMaxColumnCount), numColumns); } if (numColumns <= 0) { numColumns = 1; } } // Compute extra space and divide it among the columns nscoord extraSpace = std::max(0, availContentWidth - (colWidth*numColumns + colGap*(numColumns - 1))); nscoord extraToColumns = extraSpace/numColumns; colWidth += extraToColumns; expectedWidthLeftOver = extraSpace - (extraToColumns*numColumns); } if (isBalancing) { if (numColumns <= 0) { // Hmm, auto column count, column width or available width is unknown, // and balancing is required. Let's just use one column then. numColumns = 1; } colHeight = std::min(mLastBalanceHeight, colHeight); } else { // This is the case when the column-fill property is set to 'auto'. // No balancing, so don't limit the column count numColumns = INT32_MAX; // XXX_jwir3: If a page's height is set to 0, we could continually // create continuations, resulting in an infinite loop, since // no progress is ever made. This is an issue with the spec // (css3-multicol, css3-page, and css3-break) that is // unresolved as of 27 Feb 2013. For the time being, we set this // to have a minimum of 1 css px. Once a resolution is made // on what minimum to have for a page height, we may need to // change this value to match the appropriate spec(s). colHeight = std::max(colHeight, nsPresContext::CSSPixelsToAppUnits(1)); } #ifdef DEBUG_roc printf("*** nsColumnSetFrame::ChooseColumnStrategy: numColumns=%d, colWidth=%d, expectedWidthLeftOver=%d, colHeight=%d, colGap=%d\n", numColumns, colWidth, expectedWidthLeftOver, colHeight, colGap); #endif ReflowConfig config = { numColumns, colWidth, expectedWidthLeftOver, colGap, colHeight, isBalancing, knownFeasibleHeight, knownInfeasibleHeight, computedBSize, consumedBSize }; return config; }
void nsLeafBoxFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { // This is mostly a copy of nsBoxFrame::Reflow(). // We aren't able to share an implementation because of the frame // class hierarchy. If you make changes here, please keep // nsBoxFrame::Reflow in sync. DO_GLOBAL_REFLOW_COUNT("nsLeafBoxFrame"); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_ASSERTION(aReflowState.ComputedWidth() >=0 && aReflowState.ComputedHeight() >= 0, "Computed Size < 0"); #ifdef DO_NOISY_REFLOW printf("\n-------------Starting LeafBoxFrame Reflow ----------------------------\n"); printf("%p ** nsLBF::Reflow %d R: ", this, myCounter++); switch (aReflowState.reason) { case eReflowReason_Initial: printf("Ini");break; case eReflowReason_Incremental: printf("Inc");break; case eReflowReason_Resize: printf("Rsz");break; case eReflowReason_StyleChange: printf("Sty");break; case eReflowReason_Dirty: printf("Drt "); break; default:printf("<unknown>%d", aReflowState.reason);break; } printSize("AW", aReflowState.AvailableWidth()); printSize("AH", aReflowState.AvailableHeight()); printSize("CW", aReflowState.ComputedWidth()); printSize("CH", aReflowState.ComputedHeight()); printf(" *\n"); #endif aStatus = NS_FRAME_COMPLETE; // create the layout state nsBoxLayoutState state(aPresContext, aReflowState.rendContext); nsSize computedSize(aReflowState.ComputedWidth(),aReflowState.ComputedHeight()); nsMargin m; m = aReflowState.ComputedPhysicalBorderPadding(); //GetBorderAndPadding(m); // this happens sometimes. So lets handle it gracefully. if (aReflowState.ComputedHeight() == 0) { nsSize minSize = GetMinSize(state); computedSize.height = minSize.height - m.top - m.bottom; } nsSize prefSize(0,0); // if we are told to layout intrinic then get our preferred size. if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) { prefSize = GetPrefSize(state); nsSize minSize = GetMinSize(state); nsSize maxSize = GetMaxSize(state); prefSize = BoundsCheck(minSize, prefSize, maxSize); } // get our desiredSize if (aReflowState.ComputedWidth() == NS_INTRINSICSIZE) { computedSize.width = prefSize.width; } else { computedSize.width += m.left + m.right; } if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) { computedSize.height = prefSize.height; } else { computedSize.height += m.top + m.bottom; } // handle reflow state min and max sizes // XXXbz the width handling here seems to be wrong, since // mComputedMin/MaxWidth is a content-box size, whole // computedSize.width is a border-box size... if (computedSize.width > aReflowState.ComputedMaxWidth()) computedSize.width = aReflowState.ComputedMaxWidth(); if (computedSize.width < aReflowState.ComputedMinWidth()) computedSize.width = aReflowState.ComputedMinWidth(); // Now adjust computedSize.height for our min and max computed // height. The only problem is that those are content-box sizes, // while computedSize.height is a border-box size. So subtract off // m.TopBottom() before adjusting, then readd it. computedSize.height = std::max(0, computedSize.height - m.TopBottom()); computedSize.height = NS_CSS_MINMAX(computedSize.height, aReflowState.ComputedMinHeight(), aReflowState.ComputedMaxHeight()); computedSize.height += m.TopBottom(); nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height); SetBounds(state, r); // layout our children Layout(state); // ok our child could have gotten bigger. So lets get its bounds aDesiredSize.Width() = mRect.width; aDesiredSize.Height() = mRect.height; aDesiredSize.SetTopAscent(GetBoxAscent(state)); // the overflow rect is set in SetBounds() above aDesiredSize.mOverflowAreas = GetOverflowAreas(); #ifdef DO_NOISY_REFLOW { printf("%p ** nsLBF(done) W:%d H:%d ", this, aDesiredSize.Width(), aDesiredSize.Height()); if (maxElementWidth) { printf("MW:%d\n", *maxElementWidth); } else { printf("MW:?\n"); } } #endif }
void nsFieldSetFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame"); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_PRECONDITION(aReflowState.ComputedWidth() != NS_INTRINSICSIZE, "Should have a precomputed width!"); // Initialize OUT parameter aStatus = NS_FRAME_COMPLETE; nsOverflowAreas ocBounds; nsReflowStatus ocStatus = NS_FRAME_COMPLETE; if (GetPrevInFlow()) { ReflowOverflowContainerChildren(aPresContext, aReflowState, ocBounds, 0, ocStatus); } //------------ Handle Incremental Reflow ----------------- bool reflowInner; bool reflowLegend; nsIFrame* legend = GetLegend(); nsIFrame* inner = GetInner(); if (aReflowState.ShouldReflowAllKids()) { reflowInner = inner != nullptr; reflowLegend = legend != nullptr; } else { reflowInner = inner && NS_SUBTREE_DIRTY(inner); reflowLegend = legend && NS_SUBTREE_DIRTY(legend); } // We don't allow fieldsets to break vertically. If we did, we'd // need logic here to push and pull overflow frames. // Since we're not applying our padding in this frame, we need to add it here // to compute the available width for our children. WritingMode innerWM = inner ? inner->GetWritingMode() : GetWritingMode(); WritingMode legendWM = legend ? legend->GetWritingMode() : GetWritingMode(); LogicalSize innerAvailSize = aReflowState.ComputedSizeWithPadding(innerWM); LogicalSize legendAvailSize = aReflowState.ComputedSizeWithPadding(legendWM); innerAvailSize.BSize(innerWM) = legendAvailSize.BSize(legendWM) = NS_UNCONSTRAINEDSIZE; NS_ASSERTION(!inner || nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext, inner, nsLayoutUtils::MIN_ISIZE) <= innerAvailSize.ISize(innerWM), "Bogus availSize.ISize; should be bigger"); NS_ASSERTION(!legend || nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext, legend, nsLayoutUtils::MIN_ISIZE) <= legendAvailSize.ISize(legendWM), "Bogus availSize.ISize; should be bigger"); // get our border and padding nsMargin border = aReflowState.ComputedPhysicalBorderPadding() - aReflowState.ComputedPhysicalPadding(); // Figure out how big the legend is if there is one. // get the legend's margin nsMargin legendMargin(0,0,0,0); // reflow the legend only if needed Maybe<nsHTMLReflowState> legendReflowState; if (legend) { legendReflowState.emplace(aPresContext, aReflowState, legend, legendAvailSize); } if (reflowLegend) { nsHTMLReflowMetrics legendDesiredSize(aReflowState); ReflowChild(legend, aPresContext, legendDesiredSize, *legendReflowState, 0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus); #ifdef NOISY_REFLOW printf(" returned (%d, %d)\n", legendDesiredSize.Width(), legendDesiredSize.Height()); #endif // figure out the legend's rectangle legendMargin = legend->GetUsedMargin(); mLegendRect.width = legendDesiredSize.Width() + legendMargin.left + legendMargin.right; mLegendRect.height = legendDesiredSize.Height() + legendMargin.top + legendMargin.bottom; mLegendRect.x = 0; mLegendRect.y = 0; nscoord oldSpace = mLegendSpace; mLegendSpace = 0; if (mLegendRect.height > border.top) { // center the border on the legend mLegendSpace = mLegendRect.height - border.top; } else { mLegendRect.y = (border.top - mLegendRect.height)/2; } // if the legend space changes then we need to reflow the // content area as well. if (mLegendSpace != oldSpace && inner) { reflowInner = true; } FinishReflowChild(legend, aPresContext, legendDesiredSize, legendReflowState.ptr(), 0, 0, NS_FRAME_NO_MOVE_FRAME); } else if (!legend) { mLegendRect.SetEmpty(); mLegendSpace = 0; } else { // mLegendSpace and mLegendRect haven't changed, but we need // the used margin when placing the legend. legendMargin = legend->GetUsedMargin(); } // reflow the content frame only if needed if (reflowInner) { nsHTMLReflowState kidReflowState(aPresContext, aReflowState, inner, innerAvailSize, -1, -1, nsHTMLReflowState::CALLER_WILL_INIT); // Override computed padding, in case it's percentage padding kidReflowState.Init(aPresContext, -1, -1, nullptr, &aReflowState.ComputedPhysicalPadding()); // Our child is "height:100%" but we actually want its height to be reduced // by the amount of content-height the legend is eating up, unless our // height is unconstrained (in which case the child's will be too). if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) { kidReflowState.SetComputedHeight( std::max(0, aReflowState.ComputedHeight() - mLegendSpace)); } if (aReflowState.ComputedMinHeight() > 0) { kidReflowState.ComputedMinHeight() = std::max(0, aReflowState.ComputedMinHeight() - mLegendSpace); } if (aReflowState.ComputedMaxHeight() != NS_UNCONSTRAINEDSIZE) { kidReflowState.ComputedMaxHeight() = std::max(0, aReflowState.ComputedMaxHeight() - mLegendSpace); } nsHTMLReflowMetrics kidDesiredSize(kidReflowState, aDesiredSize.mFlags); // Reflow the frame NS_ASSERTION(kidReflowState.ComputedPhysicalMargin() == nsMargin(0,0,0,0), "Margins on anonymous fieldset child not supported!"); nsPoint pt(border.left, border.top + mLegendSpace); ReflowChild(inner, aPresContext, kidDesiredSize, kidReflowState, pt.x, pt.y, 0, aStatus); FinishReflowChild(inner, aPresContext, kidDesiredSize, &kidReflowState, pt.x, pt.y, 0); NS_FRAME_TRACE_REFLOW_OUT("FieldSet::Reflow", aStatus); } LogicalRect contentRect(innerWM); if (inner) { // We don't support margins on inner, so our content rect is just the // inner's border-box. contentRect = inner->GetLogicalRect(aReflowState.ComputedWidth()); } // Our content rect must fill up the available width if (innerAvailSize.ISize(innerWM) > contentRect.ISize(innerWM)) { contentRect.ISize(innerWM) = innerAvailSize.ISize(innerWM); } //XXX temporary! nsRect physicalContentRect = contentRect.GetPhysicalRect(innerWM, aReflowState.ComputedWidth()); if (legend) { // the legend is postioned horizontally within the inner's content rect // (so that padding on the fieldset affects the legend position). nsRect innerContentRect = physicalContentRect; innerContentRect.Deflate(aReflowState.ComputedPhysicalPadding()); // if the inner content rect is larger than the legend, we can align the legend if (innerContentRect.width > mLegendRect.width) { int32_t align = static_cast<nsLegendFrame*> (legend->GetContentInsertionFrame())->GetAlign(); switch (align) { case NS_STYLE_TEXT_ALIGN_RIGHT: mLegendRect.x = innerContentRect.XMost() - mLegendRect.width; break; case NS_STYLE_TEXT_ALIGN_CENTER: // Note: rounding removed; there doesn't seem to be any need mLegendRect.x = innerContentRect.width / 2 - mLegendRect.width / 2 + innerContentRect.x; break; default: mLegendRect.x = innerContentRect.x; break; } } else { // otherwise make place for the legend mLegendRect.x = innerContentRect.x; innerContentRect.width = mLegendRect.width; physicalContentRect.width = mLegendRect.width + aReflowState.ComputedPhysicalPadding().LeftRight(); } // place the legend nsRect actualLegendRect(mLegendRect); actualLegendRect.Deflate(legendMargin); nsPoint actualLegendPos(actualLegendRect.TopLeft()); legendReflowState->ApplyRelativePositioning(&actualLegendPos); legend->SetPosition(actualLegendPos); nsContainerFrame::PositionFrameView(legend); nsContainerFrame::PositionChildViews(legend); } // Return our size and our result. WritingMode wm = aReflowState.GetWritingMode(); nsSize finalSize(physicalContentRect.width + border.LeftRight(), mLegendSpace + border.TopBottom() + (inner ? inner->GetRect().height : 0)); aDesiredSize.SetSize(wm, LogicalSize(wm, finalSize)); aDesiredSize.SetOverflowAreasToDesiredBounds(); if (legend) ConsiderChildOverflow(aDesiredSize.mOverflowAreas, legend); if (inner) ConsiderChildOverflow(aDesiredSize.mOverflowAreas, inner); // Merge overflow container bounds and status. aDesiredSize.mOverflowAreas.UnionWith(ocBounds); NS_MergeReflowStatusInto(&aStatus, ocStatus); FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, aStatus); InvalidateFrame(); NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); }
void nsHTMLButtonControlFrame::ReflowButtonContents(nsPresContext* aPresContext, nsHTMLReflowMetrics& aButtonDesiredSize, const nsHTMLReflowState& aButtonReflowState, nsIFrame* aFirstKid) { // Buttons have some bonus renderer-determined border/padding, // which occupies part of the button's content-box area: const nsMargin focusPadding = mRenderer.GetAddedButtonBorderAndPadding(); WritingMode wm = aFirstKid->GetWritingMode(); LogicalSize availSize = aButtonReflowState.ComputedSize(GetWritingMode()); availSize.BSize(wm) = NS_INTRINSICSIZE; // Indent the child inside us by the focus border. We must do this separate // from the regular border. availSize.ISize(wm) -= LogicalMargin(wm, focusPadding).IStartEnd(wm); // See whether out availSize's width is big enough. If it's smaller than our // intrinsic min width, that means that the kid wouldn't really fit; for a // better look in such cases we adjust the available width and our left // offset to allow the kid to spill left into our padding. nscoord xoffset = focusPadding.left + aButtonReflowState.ComputedPhysicalBorderPadding().left; nscoord extrawidth = GetMinISize(aButtonReflowState.rendContext) - aButtonReflowState.ComputedWidth(); if (extrawidth > 0) { nscoord extraleft = extrawidth / 2; nscoord extraright = extrawidth - extraleft; NS_ASSERTION(extraright >=0, "How'd that happen?"); // Do not allow the extras to be bigger than the relevant padding extraleft = std::min(extraleft, aButtonReflowState.ComputedPhysicalPadding().left); extraright = std::min(extraright, aButtonReflowState.ComputedPhysicalPadding().right); xoffset -= extraleft; availSize.Width(wm) = availSize.Width(wm) + extraleft + extraright; } availSize.Width(wm) = std::max(availSize.Width(wm), 0); // Give child a clone of the button's reflow state, with height/width reduced // by focusPadding, so that descendants with height:100% don't protrude. nsHTMLReflowState adjustedButtonReflowState = CloneReflowStateWithReducedContentBox(aButtonReflowState, focusPadding); nsHTMLReflowState contentsReflowState(aPresContext, adjustedButtonReflowState, aFirstKid, availSize); nsReflowStatus contentsReflowStatus; nsHTMLReflowMetrics contentsDesiredSize(aButtonReflowState); ReflowChild(aFirstKid, aPresContext, contentsDesiredSize, contentsReflowState, xoffset, focusPadding.top + aButtonReflowState.ComputedPhysicalBorderPadding().top, 0, contentsReflowStatus); MOZ_ASSERT(NS_FRAME_IS_COMPLETE(contentsReflowStatus), "We gave button-contents frame unconstrained available height, " "so it should be complete"); // Compute the button's content-box height: nscoord buttonContentBoxHeight = 0; if (aButtonReflowState.ComputedHeight() != NS_INTRINSICSIZE) { // Button has a fixed height -- that's its content-box height. buttonContentBoxHeight = aButtonReflowState.ComputedHeight(); } else { // Button is intrinsically sized -- it should shrinkwrap the // button-contents' height, plus any focus-padding space: buttonContentBoxHeight = contentsDesiredSize.Height() + focusPadding.TopBottom(); // Make sure we obey min/max-height in the case when we're doing intrinsic // sizing (we get it for free when we have a non-intrinsic // aButtonReflowState.ComputedHeight()). Note that we do this before // adjusting for borderpadding, since mComputedMaxHeight and // mComputedMinHeight are content heights. buttonContentBoxHeight = NS_CSS_MINMAX(buttonContentBoxHeight, aButtonReflowState.ComputedMinHeight(), aButtonReflowState.ComputedMaxHeight()); } // Center child vertically in the button // (technically, inside of the button's focus-padding area) nscoord extraSpace = buttonContentBoxHeight - focusPadding.TopBottom() - contentsDesiredSize.Height(); nscoord yoffset = std::max(0, extraSpace / 2); // Adjust yoffset to be in terms of the button's frame-rect, instead of // its focus-padding rect: yoffset += focusPadding.top + aButtonReflowState.ComputedPhysicalBorderPadding().top; // Place the child FinishReflowChild(aFirstKid, aPresContext, contentsDesiredSize, &contentsReflowState, xoffset, yoffset, 0); // Make sure we have a useful 'ascent' value for the child if (contentsDesiredSize.BlockStartAscent() == nsHTMLReflowMetrics::ASK_FOR_BASELINE) { WritingMode wm = aButtonReflowState.GetWritingMode(); contentsDesiredSize.SetBlockStartAscent(aFirstKid->GetLogicalBaseline(wm)); } // OK, we're done with the child frame. // Use what we learned to populate the button frame's reflow metrics. // * Button's height & width are content-box size + border-box contribution: aButtonDesiredSize.Width() = aButtonReflowState.ComputedWidth() + aButtonReflowState.ComputedPhysicalBorderPadding().LeftRight(); aButtonDesiredSize.Height() = buttonContentBoxHeight + aButtonReflowState.ComputedPhysicalBorderPadding().TopBottom(); // * Button's ascent is its child's ascent, plus the child's y-offset // within our frame: aButtonDesiredSize.SetBlockStartAscent(contentsDesiredSize.BlockStartAscent() + yoffset); aButtonDesiredSize.SetOverflowAreasToDesiredBounds(); }
void nsNumberControlFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { DO_GLOBAL_REFLOW_COUNT("nsNumberControlFrame"); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_ASSERTION(mOuterWrapper, "Outer wrapper div must exist!"); NS_ASSERTION(!GetPrevContinuation() && !GetNextContinuation(), "nsNumberControlFrame should not have continuations; if it does we " "need to call RegUnregAccessKey only for the first"); NS_ASSERTION(!mFrames.FirstChild() || !mFrames.FirstChild()->GetNextSibling(), "We expect at most one direct child frame"); if (mState & NS_FRAME_FIRST_REFLOW) { nsFormControlFrame::RegUnRegAccessKey(this, true); } // The width of our content box, which is the available width // for our anonymous content: const nscoord contentBoxWidth = aReflowState.ComputedWidth(); nscoord contentBoxHeight = aReflowState.ComputedHeight(); nsIFrame* outerWrapperFrame = mOuterWrapper->GetPrimaryFrame(); if (!outerWrapperFrame) { // display:none? if (contentBoxHeight == NS_INTRINSICSIZE) { contentBoxHeight = 0; } } else { NS_ASSERTION(outerWrapperFrame == mFrames.FirstChild(), "huh?"); nsHTMLReflowMetrics wrappersDesiredSize(aReflowState); WritingMode wm = outerWrapperFrame->GetWritingMode(); LogicalSize availSize = aReflowState.ComputedSize(wm); availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE; nsHTMLReflowState wrapperReflowState(aPresContext, aReflowState, outerWrapperFrame, availSize); // offsets of wrapper frame nscoord xoffset = aReflowState.ComputedPhysicalBorderPadding().left + wrapperReflowState.ComputedPhysicalMargin().left; nscoord yoffset = aReflowState.ComputedPhysicalBorderPadding().top + wrapperReflowState.ComputedPhysicalMargin().top; nsReflowStatus childStatus; ReflowChild(outerWrapperFrame, aPresContext, wrappersDesiredSize, wrapperReflowState, xoffset, yoffset, 0, childStatus); MOZ_ASSERT(NS_FRAME_IS_FULLY_COMPLETE(childStatus), "We gave our child unconstrained height, so it should be complete"); nscoord wrappersMarginBoxHeight = wrappersDesiredSize.Height() + wrapperReflowState.ComputedPhysicalMargin().TopBottom(); if (contentBoxHeight == NS_INTRINSICSIZE) { // We are intrinsically sized -- we should shrinkwrap the outer wrapper's // height: contentBoxHeight = wrappersMarginBoxHeight; // Make sure we obey min/max-height in the case when we're doing intrinsic // sizing (we get it for free when we have a non-intrinsic // aReflowState.ComputedHeight()). Note that we do this before // adjusting for borderpadding, since mComputedMaxHeight and // mComputedMinHeight are content heights. contentBoxHeight = NS_CSS_MINMAX(contentBoxHeight, aReflowState.ComputedMinHeight(), aReflowState.ComputedMaxHeight()); } // Center child vertically nscoord extraSpace = contentBoxHeight - wrappersMarginBoxHeight; yoffset += std::max(0, extraSpace / 2); // Place the child FinishReflowChild(outerWrapperFrame, aPresContext, wrappersDesiredSize, &wrapperReflowState, xoffset, yoffset, 0); aDesiredSize.SetBlockStartAscent( wrappersDesiredSize.BlockStartAscent() + outerWrapperFrame->BStart(aReflowState.GetWritingMode(), contentBoxWidth)); } aDesiredSize.Width() = contentBoxWidth + aReflowState.ComputedPhysicalBorderPadding().LeftRight(); aDesiredSize.Height() = contentBoxHeight + aReflowState.ComputedPhysicalBorderPadding().TopBottom(); aDesiredSize.SetOverflowAreasToDesiredBounds(); if (outerWrapperFrame) { ConsiderChildOverflow(aDesiredSize.mOverflowAreas, outerWrapperFrame); } FinishAndStoreOverflow(&aDesiredSize); aStatus = NS_FRAME_COMPLETE; NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); }