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