2002-01-25 05:07:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2002-01-25 05:07:03 +03:00
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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/
|
2002-01-25 05:07:03 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2002-01-25 05:07:03 +03:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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"),
|
2002-01-25 05:07:03 +03:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2002-01-25 05:07:03 +03:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2002-01-25 05:07:03 +03:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsPageContentFrame.h"
|
2007-07-26 08:03:29 +04:00
|
|
|
#include "nsPageFrame.h"
|
2008-02-24 15:19:17 +03:00
|
|
|
#include "nsPlaceholderFrame.h"
|
2007-07-26 08:03:29 +04:00
|
|
|
#include "nsCSSFrameConstructor.h"
|
|
|
|
#include "nsHTMLContainerFrame.h"
|
2002-01-25 05:07:03 +03:00
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsIContent.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2002-01-25 05:07:03 +03:00
|
|
|
#include "nsIRenderingContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2002-01-25 05:07:03 +03:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIDeviceContext.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2002-09-20 01:45:07 +04:00
|
|
|
#include "nsSimplePageSequence.h"
|
2006-01-26 05:29:17 +03:00
|
|
|
#include "nsDisplayList.h"
|
2002-01-25 05:07:03 +03:00
|
|
|
|
2005-11-04 05:38:33 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewPageContentFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2002-01-31 17:24:06 +03:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) nsPageContentFrame(aContext);
|
2002-01-31 17:24:06 +03:00
|
|
|
}
|
|
|
|
|
2008-02-09 05:54:55 +03: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);
|
|
|
|
}
|
|
|
|
|
2008-02-24 15:19:17 +03:00
|
|
|
/**
|
|
|
|
* Returns true if aFrame is a placeholder for one of our fixed frames.
|
|
|
|
*/
|
|
|
|
inline PRBool
|
|
|
|
nsPageContentFrame::IsFixedPlaceholder(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
if (!aFrame || nsGkAtoms::placeholderFrame != aFrame->GetType())
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
return static_cast<nsPlaceholderFrame*>(aFrame)->GetOutOfFlowFrame()
|
|
|
|
->GetParent() == this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Steals replicated fixed placeholder frames from aDocRoot so they don't
|
|
|
|
* get in the way of reflow.
|
|
|
|
*/
|
|
|
|
inline nsFrameList
|
|
|
|
nsPageContentFrame::StealFixedPlaceholders(nsIFrame* aDocRoot)
|
|
|
|
{
|
|
|
|
nsPresContext* presContext = PresContext();
|
|
|
|
nsFrameList list;
|
|
|
|
if (GetPrevInFlow()) {
|
|
|
|
for (nsIFrame* f = aDocRoot->GetFirstChild(nsnull);
|
|
|
|
IsFixedPlaceholder(f); f = aDocRoot->GetFirstChild(nsnull)) {
|
|
|
|
nsresult rv = static_cast<nsContainerFrame*>(aDocRoot)
|
|
|
|
->StealFrame(presContext, f);
|
|
|
|
NS_ENSURE_SUCCESS(rv, list);
|
|
|
|
list.AppendFrame(nsnull, f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restores stolen replicated fixed placeholder frames to aDocRoot.
|
|
|
|
*/
|
|
|
|
static inline nsresult
|
|
|
|
ReplaceFixedPlaceholders(nsIFrame* aDocRoot,
|
|
|
|
nsFrameList& aPlaceholderList)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (aPlaceholderList.NotEmpty()) {
|
|
|
|
rv = static_cast<nsContainerFrame*>(aDocRoot)
|
|
|
|
->AddFrames(aPlaceholderList.FirstChild(), nsnull);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-07-26 08:03:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageContentFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
2002-01-25 05:07:03 +03:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsPageContentFrame");
|
2002-01-25 05:07:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
|
|
|
|
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
|
2008-02-24 15:19:17 +03:00
|
|
|
nsresult rv = NS_OK;
|
2007-07-26 08:03:31 +04:00
|
|
|
|
2007-08-07 20:06:56 +04:00
|
|
|
// A PageContentFrame must always have one child: the doc root element's frame.
|
|
|
|
// We only need to get overflow frames if we don't already have that child;
|
|
|
|
// Also we need to avoid repeating the call to ReplicateFixedFrames.
|
2007-07-26 08:03:29 +04:00
|
|
|
nsPageContentFrame* prevPageContentFrame = static_cast<nsPageContentFrame*>
|
2007-08-07 20:06:56 +04:00
|
|
|
(GetPrevInFlow());
|
|
|
|
if (mFrames.IsEmpty() && prevPageContentFrame) {
|
|
|
|
// Pull the doc root frame's continuation and copy fixed frames.
|
2007-07-26 08:03:29 +04:00
|
|
|
nsIFrame* overflow = prevPageContentFrame->GetOverflowFrames(aPresContext, PR_TRUE);
|
2007-08-07 20:06:56 +04:00
|
|
|
NS_ASSERTION(overflow && !overflow->GetNextSibling(),
|
|
|
|
"must have doc root as pageContentFrame's only child");
|
|
|
|
nsHTMLContainerFrame::ReparentFrameView(aPresContext, overflow, prevPageContentFrame, this);
|
2007-07-26 08:03:29 +04:00
|
|
|
// Prepend overflow to the page content frame. There may already be
|
|
|
|
// children placeholders which don't get reflowed but must not be
|
|
|
|
// lost until the page content frame is destroyed.
|
|
|
|
mFrames.InsertFrames(this, nsnull, overflow);
|
2007-08-07 20:06:56 +04:00
|
|
|
nsresult rv = aPresContext->PresShell()->FrameConstructor()
|
|
|
|
->ReplicateFixedFrames(this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-26 08:03:29 +04:00
|
|
|
}
|
|
|
|
|
2006-04-01 05:19:28 +04: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);
|
|
|
|
|
|
|
|
mPD->mPageContentSize = aReflowState.availableWidth;
|
|
|
|
|
2008-02-24 15:19:17 +03:00
|
|
|
// Get replicated fixed frames' placeholders out of the way
|
|
|
|
nsFrameList stolenPlaceholders = StealFixedPlaceholders(frame);
|
|
|
|
|
|
|
|
// Reflow the page content area
|
|
|
|
rv = ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, 0, 0, 0, aStatus);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Put removed fixed placeholders back
|
|
|
|
rv = ReplaceFixedPlaceholders(frame, stolenPlaceholders);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-07-26 08:03:31 +04:00
|
|
|
|
2007-07-26 08:03:29 +04:00
|
|
|
if (!NS_FRAME_IS_FULLY_COMPLETE(aStatus)) {
|
|
|
|
nsIFrame* nextFrame = frame->GetNextInFlow();
|
|
|
|
NS_ASSERTION(nextFrame || aStatus & NS_FRAME_REFLOW_NEXTINFLOW,
|
|
|
|
"If it's incomplete and has no nif yet, it must flag a nif reflow.");
|
|
|
|
if (!nextFrame) {
|
|
|
|
nsresult rv = nsHTMLContainerFrame::CreateNextInFlow(aPresContext,
|
|
|
|
this, frame, nextFrame);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
frame->SetNextSibling(nextFrame->GetNextSibling());
|
|
|
|
nextFrame->SetNextSibling(nsnull);
|
|
|
|
SetOverflowFrames(aPresContext, nextFrame);
|
|
|
|
// Root overflow containers will be normal children of
|
|
|
|
// the pageContentFrame, but that's ok because there
|
|
|
|
// aren't any other frames we need to isolate them from
|
|
|
|
// during reflow.
|
|
|
|
}
|
|
|
|
if (NS_FRAME_OVERFLOW_IS_INCOMPLETE(aStatus)) {
|
|
|
|
nextFrame->AddStateBits(NS_FRAME_IS_OVERFLOW_CONTAINER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-01 05:19:28 +04: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
|
|
|
|
if (NS_FRAME_OUTSIDE_CHILDREN & frame->GetStateBits()) {
|
|
|
|
// 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() +
|
|
|
|
kidReflowState.mStyleBorder->GetBorderWidth(NS_SIDE_RIGHT) +
|
|
|
|
padding.right;
|
2002-09-20 01:45:07 +04:00
|
|
|
}
|
2006-04-01 05:19:28 +04:00
|
|
|
}
|
2002-09-20 01:45:07 +04:00
|
|
|
|
2006-04-01 05:19:28 +04:00
|
|
|
// Place and size the child
|
|
|
|
FinishReflowChild(frame, aPresContext, &kidReflowState, aDesiredSize, 0, 0, 0);
|
2002-01-25 05:07:03 +03:00
|
|
|
|
2007-07-26 08:03:29 +04:00
|
|
|
NS_ASSERTION(aPresContext->IsDynamic() || !NS_FRAME_IS_FULLY_COMPLETE(aStatus) ||
|
2006-04-01 05:19:28 +04:00
|
|
|
!frame->GetNextInFlow(), "bad child flow list");
|
|
|
|
}
|
|
|
|
// Reflow our fixed frames
|
2008-04-22 21:24:28 +04:00
|
|
|
nsReflowStatus fixedStatus = NS_FRAME_COMPLETE;
|
|
|
|
mFixedContainer.Reflow(this, aPresContext, aReflowState, fixedStatus,
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
aReflowState.availableWidth,
|
|
|
|
aReflowState.availableHeight,
|
2007-10-02 12:29:23 +04:00
|
|
|
PR_FALSE, PR_TRUE, PR_TRUE); // XXX could be optimized
|
2008-04-22 21:24:28 +04:00
|
|
|
NS_ASSERTION(NS_FRAME_IS_COMPLETE(fixedStatus), "fixed frames can be truncated, but not incomplete");
|
2006-04-01 05:19:28 +04:00
|
|
|
|
|
|
|
// Return our desired size
|
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
if (aReflowState.availableHeight != NS_UNCONSTRAINEDSIZE) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
2002-01-25 05:07:03 +03:00
|
|
|
}
|
|
|
|
|
2002-05-29 02:50:43 +04:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
|
2002-01-25 05:07:03 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
nsPageContentFrame::GetType() const
|
2002-01-25 05:07:03 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::pageContentFrame;
|
2002-01-25 05:07:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageContentFrame::GetFrameName(nsAString& aResult) const
|
|
|
|
{
|
|
|
|
return MakeFrameName(NS_LITERAL_STRING("PageContent"), aResult);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-12 07:40:17 +03:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsPageContentFrame::IsContainingBlock() const
|
2002-01-25 05:07:03 +03:00
|
|
|
{
|
2004-03-12 07:40:17 +03:00
|
|
|
return PR_TRUE;
|
2002-01-25 05:07:03 +03:00
|
|
|
}
|