2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsPageContentFrame.h"
|
2007-07-25 21:03:29 -07:00
|
|
|
#include "nsPageFrame.h"
|
2008-02-24 04:19:17 -08:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2007-07-25 21:03:29 -07:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsSimplePageSequence.h"
|
|
|
|
#include "nsDisplayList.h"
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2008-02-08 18:54:55 -08:00
|
|
|
/* virtual */ nsSize
|
|
|
|
nsPageContentFrame::ComputeSize(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsSize aCBSize, nscoord aAvailableWidth,
|
|
|
|
nsSize aMargin, nsSize aBorder, nsSize aPadding,
|
|
|
|
PRBool aShrinkWrap)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mPD, "Pages are supposed to have page data");
|
|
|
|
nscoord height = (!mPD || mPD->mReflowSize.height == NS_UNCONSTRAINEDSIZE)
|
|
|
|
? NS_UNCONSTRAINEDSIZE
|
|
|
|
: (mPD->mReflowSize.height - mPD->mReflowMargin.TopBottom());
|
|
|
|
return nsSize(aAvailableWidth, height);
|
|
|
|
}
|
|
|
|
|
2007-07-25 21:03:29 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
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-02-24 04:19:17 -08:00
|
|
|
nsresult rv = NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
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);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
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.
|
|
|
|
SetSize(nsSize(aReflowState.availableWidth, aReflowState.availableHeight));
|
|
|
|
|
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();
|
|
|
|
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, frame, maxSize);
|
2008-09-08 01:13:17 -07:00
|
|
|
kidReflowState.SetComputedHeight(aReflowState.availableHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mPD->mPageContentSize = aReflowState.availableWidth;
|
|
|
|
|
2008-02-24 04:19:17 -08:00
|
|
|
// Reflow the page content area
|
|
|
|
rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
// First check the combined area
|
2009-04-05 17:31:50 -07:00
|
|
|
if (frame->HasOverflowRect()) {
|
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
|
|
|
|
if (aDesiredSize.mOverflowArea.XMost() > aDesiredSize.width) {
|
|
|
|
mPD->mPageContentXMost =
|
|
|
|
aDesiredSize.mOverflowArea.XMost() +
|
2008-07-16 23:30:25 -07:00
|
|
|
kidReflowState.mStyleBorder->GetActualBorderWidth(NS_SIDE_RIGHT) +
|
2007-03-22 10:30:00 -07:00
|
|
|
padding.right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place and size the child
|
|
|
|
FinishReflowChild(frame, aPresContext, &kidReflowState, aDesiredSize, 0, 0, 0);
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
// Reflow our fixed frames
|
2008-04-22 10:24:28 -07:00
|
|
|
nsReflowStatus fixedStatus = NS_FRAME_COMPLETE;
|
|
|
|
mFixedContainer.Reflow(this, aPresContext, aReflowState, fixedStatus,
|
2007-03-22 10:30:00 -07:00
|
|
|
aReflowState.availableWidth,
|
|
|
|
aReflowState.availableHeight,
|
2007-10-02 01:29:23 -07:00
|
|
|
PR_FALSE, PR_TRUE, PR_TRUE); // XXX could be optimized
|
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
|
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsPageContentFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::pageContentFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageContentFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* virtual */ PRBool
|
|
|
|
nsPageContentFrame::IsContainingBlock() const
|
|
|
|
{
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|