michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #include "nsPageContentFrame.h" michael@0: #include "nsCSSFrameConstructor.h" michael@0: #include "nsPresContext.h" michael@0: #include "nsGkAtoms.h" michael@0: #include "nsIPresShell.h" michael@0: #include "nsSimplePageSequenceFrame.h" michael@0: michael@0: nsIFrame* michael@0: NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) michael@0: { michael@0: return new (aPresShell) nsPageContentFrame(aContext); michael@0: } michael@0: michael@0: NS_IMPL_FRAMEARENA_HELPERS(nsPageContentFrame) michael@0: michael@0: nsresult michael@0: nsPageContentFrame::Reflow(nsPresContext* aPresContext, michael@0: nsHTMLReflowMetrics& aDesiredSize, michael@0: const nsHTMLReflowState& aReflowState, michael@0: nsReflowStatus& aStatus) michael@0: { michael@0: DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame"); michael@0: DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); michael@0: aStatus = NS_FRAME_COMPLETE; // initialize out parameter michael@0: nsresult rv = NS_OK; michael@0: michael@0: if (GetPrevInFlow() && (GetStateBits() & NS_FRAME_FIRST_REFLOW)) { michael@0: nsresult rv = aPresContext->PresShell()->FrameConstructor() michael@0: ->ReplicateFixedFrames(this); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: } michael@0: michael@0: // Set our size up front, since some parts of reflow depend on it michael@0: // being already set. Note that the computed height may be michael@0: // unconstrained; that's ok. Consumers should watch out for that. michael@0: nsSize maxSize(aReflowState.ComputedWidth(), michael@0: aReflowState.ComputedHeight()); michael@0: SetSize(maxSize); michael@0: michael@0: // A PageContentFrame must always have one child: the canvas frame. michael@0: // Resize our frame allowing it only to be as big as we are michael@0: // XXX Pay attention to the page's border and padding... michael@0: if (mFrames.NotEmpty()) { michael@0: nsIFrame* frame = mFrames.FirstChild(); michael@0: nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize); michael@0: kidReflowState.SetComputedHeight(maxSize.height); michael@0: michael@0: // Reflow the page content area michael@0: rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus); michael@0: NS_ENSURE_SUCCESS(rv, rv); michael@0: michael@0: // The document element's background should cover the entire canvas, so michael@0: // take into account the combined area and any space taken up by michael@0: // absolutely positioned elements michael@0: nsMargin padding(0,0,0,0); michael@0: michael@0: // XXXbz this screws up percentage padding (sets padding to zero michael@0: // in the percentage padding case) michael@0: kidReflowState.mStylePadding->GetPadding(padding); michael@0: michael@0: // This is for shrink-to-fit, and therefore we want to use the michael@0: // scrollable overflow, since the purpose of shrink to fit is to michael@0: // make the content that ought to be reachable (represented by the michael@0: // scrollable overflow) fit in the page. michael@0: if (frame->HasOverflowAreas()) { michael@0: // The background covers the content area and padding area, so check michael@0: // for children sticking outside the child frame's padding edge michael@0: nscoord xmost = aDesiredSize.ScrollableOverflow().XMost(); michael@0: if (xmost > aDesiredSize.Width()) { michael@0: nscoord widthToFit = xmost + padding.right + michael@0: kidReflowState.mStyleBorder->GetComputedBorderWidth(NS_SIDE_RIGHT); michael@0: float ratio = float(maxSize.width) / widthToFit; michael@0: NS_ASSERTION(ratio >= 0.0 && ratio < 1.0, "invalid shrink-to-fit ratio"); michael@0: mPD->mShrinkToFitRatio = std::min(mPD->mShrinkToFitRatio, ratio); michael@0: } michael@0: } michael@0: michael@0: // Place and size the child michael@0: FinishReflowChild(frame, aPresContext, aDesiredSize, &kidReflowState, 0, 0, 0); michael@0: michael@0: NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) || michael@0: !frame->GetNextInFlow(), "bad child flow list"); michael@0: } michael@0: michael@0: // Reflow our fixed frames michael@0: nsReflowStatus fixedStatus = NS_FRAME_COMPLETE; michael@0: ReflowAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, fixedStatus); michael@0: NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete"); michael@0: michael@0: // Return our desired size michael@0: aDesiredSize.Width() = aReflowState.ComputedWidth(); michael@0: if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) { michael@0: aDesiredSize.Height() = aReflowState.ComputedHeight(); michael@0: } michael@0: michael@0: FinishAndStoreOverflow(&aDesiredSize); michael@0: michael@0: NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize); michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsIAtom* michael@0: nsPageContentFrame::GetType() const michael@0: { michael@0: return nsGkAtoms::pageContentFrame; michael@0: } michael@0: michael@0: #ifdef DEBUG_FRAME_DUMP michael@0: nsresult michael@0: nsPageContentFrame::GetFrameName(nsAString& aResult) const michael@0: { michael@0: return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult); michael@0: } michael@0: #endif