1998-04-14 00:24:54 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsPageFrame.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIContentDelegate.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIRenderingContext.h"
|
1998-06-25 18:53:45 +04:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPageFrame::nsPageFrame(nsIContent* aContent, nsIFrame* aParent)
|
1998-05-06 03:56:50 +04:00
|
|
|
: nsContainerFrame(aContent, aParent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
void nsPageFrame::CreateFirstChild(nsIPresContext* aPresContext)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-06-25 18:53:45 +04:00
|
|
|
// XXX this is a copy of the root-content-frame's version
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-06-25 18:53:45 +04:00
|
|
|
// Create a frame for the body child
|
|
|
|
PRInt32 i, n;
|
|
|
|
n = mContent->ChildCount();
|
|
|
|
for (i = 0; i < n; i++) {
|
|
|
|
nsIContent* child = mContent->ChildAt(i);
|
1998-04-14 00:24:54 +04:00
|
|
|
if (nsnull != child) {
|
1998-06-25 18:53:45 +04:00
|
|
|
nsIAtom* tag;
|
|
|
|
tag = child->GetTag();
|
|
|
|
if (nsHTMLAtoms::body == tag) {
|
|
|
|
// Create a frame
|
|
|
|
nsIContentDelegate* cd = child->GetDelegate(aPresContext);
|
|
|
|
if (nsnull != cd) {
|
|
|
|
nsIStyleContext* kidStyleContext =
|
|
|
|
aPresContext->ResolveStyleContextFor(child, this);
|
|
|
|
nsresult rv = cd->CreateFrame(aPresContext, child, this,
|
|
|
|
kidStyleContext, mFirstChild);
|
|
|
|
NS_RELEASE(kidStyleContext);
|
|
|
|
if (NS_OK == rv) {
|
|
|
|
mChildCount = 1;
|
|
|
|
mFirstContentOffset = i;
|
|
|
|
mLastContentOffset = i;
|
|
|
|
}
|
|
|
|
NS_RELEASE(cd);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
1998-06-25 18:53:45 +04:00
|
|
|
NS_IF_RELEASE(tag);
|
1998-04-14 00:24:54 +04:00
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
NS_METHOD nsPageFrame::Reflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
PreReflowCheck();
|
|
|
|
#endif
|
1998-05-12 08:17:56 +04:00
|
|
|
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// XXX Do something sensible in page mode...
|
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
// We don't expect the target of the reflow command to be page frame
|
1998-06-09 08:51:44 +04:00
|
|
|
#ifdef NS_DEUG
|
1998-05-25 21:31:49 +04:00
|
|
|
NS_ASSERTION(nsnull != aReflowState.reflowCommand, "null reflow command");
|
1998-06-09 08:51:44 +04:00
|
|
|
|
|
|
|
nsIFrame* target;
|
|
|
|
aReflowState.reflowCommand->GetTarget(target);
|
|
|
|
NS_ASSERTION(target != this, "page frame is reflow command target");
|
|
|
|
#endif
|
1998-05-25 21:31:49 +04:00
|
|
|
|
|
|
|
// Verify the next reflow command frame is our one and only child frame
|
1998-06-09 08:51:44 +04:00
|
|
|
nsIFrame* next;
|
|
|
|
aReflowState.reflowCommand->GetNext(next);
|
1998-05-25 21:31:49 +04:00
|
|
|
NS_ASSERTION(next == mFirstChild, "bad reflow frame");
|
|
|
|
|
|
|
|
// Dispatch the reflow command to our content child. Allow it to be as high
|
|
|
|
// as it wants
|
|
|
|
nsSize maxSize(aReflowState.maxSize.width, NS_UNCONSTRAINEDSIZE);
|
1998-05-30 00:36:05 +04:00
|
|
|
nsReflowState kidReflowState(mFirstChild, aReflowState, maxSize);
|
1998-05-25 21:31:49 +04:00
|
|
|
|
1998-05-30 00:36:05 +04:00
|
|
|
aStatus = ReflowChild(mFirstChild, aPresContext, aDesiredSize, kidReflowState);
|
1998-05-25 21:31:49 +04:00
|
|
|
|
|
|
|
// Place and size the child. Make sure the child is at least as
|
|
|
|
// tall as our max size (the containing window)
|
|
|
|
if (aDesiredSize.height < aReflowState.maxSize.height) {
|
|
|
|
aDesiredSize.height = aReflowState.maxSize.height;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
mFirstChild->SetRect(rect);
|
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
} else {
|
|
|
|
// Do we have any children?
|
|
|
|
if (nsnull == mFirstChild) {
|
|
|
|
if (nsnull == mPrevInFlow) {
|
|
|
|
// Create the first child frame
|
|
|
|
CreateFirstChild(aPresContext);
|
|
|
|
} else {
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPageFrame* prevPage = (nsPageFrame*)mPrevInFlow;
|
1998-05-25 21:31:49 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(!prevPage->mLastContentIsComplete, "bad continuing page");
|
|
|
|
nsIFrame* prevLastChild;
|
|
|
|
prevPage->LastChild(prevLastChild);
|
|
|
|
|
|
|
|
// Create a continuing child of the previous page's last child
|
|
|
|
nsIStyleContext* kidSC;
|
|
|
|
prevLastChild->GetStyleContext(aPresContext, kidSC);
|
|
|
|
nsresult rv = prevLastChild->CreateContinuingFrame(aPresContext, this,
|
|
|
|
kidSC, mFirstChild);
|
|
|
|
NS_RELEASE(kidSC);
|
|
|
|
|
|
|
|
mChildCount = 1;
|
|
|
|
mLastContentOffset = mFirstContentOffset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resize our frame allowing it only to be as big as we are
|
|
|
|
// XXX Pay attention to the page's border and padding...
|
|
|
|
if (nsnull != mFirstChild) {
|
1998-05-30 00:36:05 +04:00
|
|
|
nsReflowState kidReflowState(mFirstChild, aReflowState, aReflowState.maxSize);
|
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// Get the child's desired size
|
|
|
|
mFirstChild->WillReflow(*aPresContext);
|
1998-05-30 00:36:05 +04:00
|
|
|
aStatus = ReflowChild(mFirstChild, aPresContext, aDesiredSize, kidReflowState);
|
1998-05-25 21:31:49 +04:00
|
|
|
mLastContentIsComplete = NS_FRAME_IS_COMPLETE(aStatus);
|
|
|
|
|
|
|
|
// Make sure the child is at least as tall as our max size (the containing window)
|
|
|
|
if (aDesiredSize.height < aReflowState.maxSize.height) {
|
|
|
|
aDesiredSize.height = aReflowState.maxSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place and size the child
|
|
|
|
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
mFirstChild->SetRect(rect);
|
|
|
|
mFirstChild->DidReflow(*aPresContext, NS_FRAME_REFLOW_FINISHED);
|
|
|
|
|
|
|
|
// Is the frame complete?
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aStatus)) {
|
|
|
|
nsIFrame* childNextInFlow;
|
|
|
|
|
|
|
|
mFirstChild->GetNextInFlow(childNextInFlow);
|
|
|
|
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list");
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-25 21:31:49 +04:00
|
|
|
// Return our desired size
|
|
|
|
aDesiredSize.width = aReflowState.maxSize.width;
|
|
|
|
aDesiredSize.height = aReflowState.maxSize.height;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1998-07-01 00:22:44 +04:00
|
|
|
// We are always a pseudo-frame; make sure our content offset is
|
|
|
|
// properly pushed upwards
|
|
|
|
nsContainerFrame* parent = (nsContainerFrame*) mGeometricParent;
|
|
|
|
parent->PropagateContentOffsets(this, mFirstContentOffset,
|
|
|
|
mLastContentOffset, mLastContentIsComplete);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#ifdef NS_DEBUG
|
1998-04-17 05:41:24 +04:00
|
|
|
PostReflowCheck(aStatus);
|
1998-04-14 00:24:54 +04:00
|
|
|
#endif
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-07 04:08:20 +04:00
|
|
|
NS_METHOD
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPageFrame::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-28 06:37:37 +04:00
|
|
|
nsPageFrame* cf = new nsPageFrame(mContent, aParent);
|
1998-05-07 04:08:20 +04:00
|
|
|
if (nsnull == cf) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
PrepareContinuingFrame(aPresContext, aParent, aStyleContext, cf);
|
1998-04-17 05:41:24 +04:00
|
|
|
aContinuingFrame = cf;
|
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
NS_METHOD nsPageFrame::Paint(nsIPresContext& aPresContext,
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIRenderingContext& aRenderingContext,
|
|
|
|
const nsRect& aDirtyRect)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
nsContainerFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
|
|
|
|
|
|
|
|
// For the time being paint a border around the page so we know
|
|
|
|
// where each page begins and ends
|
|
|
|
aRenderingContext.SetColor(NS_RGB(0, 0, 0));
|
|
|
|
aRenderingContext.DrawRect(0, 0, mRect.width, mRect.height);
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-28 06:37:37 +04:00
|
|
|
NS_METHOD nsPageFrame::ListTag(FILE* out) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
fprintf(out, "*PAGE@%p", this);
|
1998-04-17 05:41:24 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|