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"
|
|
|
|
#include "nsReflowCommand.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
|
|
|
|
1998-05-06 03:56:50 +04:00
|
|
|
PageFrame::PageFrame(nsIContent* aContent, nsIFrame* aParent)
|
|
|
|
: nsContainerFrame(aContent, aParent)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageFrame::CreateFirstChild(nsIPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
// Create a frame for our one and only content child
|
|
|
|
if (mContent->ChildCount() > 0) {
|
|
|
|
nsIContent* child = mContent->ChildAt(0);
|
|
|
|
|
|
|
|
if (nsnull != child) {
|
|
|
|
// Create a frame
|
|
|
|
nsIContentDelegate* cd = child->GetDelegate(aPresContext);
|
|
|
|
if (nsnull != cd) {
|
1998-05-07 04:08:20 +04:00
|
|
|
nsIStyleContext* kidStyleContext =
|
|
|
|
aPresContext->ResolveStyleContextFor(child, this);
|
|
|
|
nsresult rv = cd->CreateFrame(aPresContext, child, this,
|
|
|
|
kidStyleContext, mFirstChild);
|
|
|
|
NS_RELEASE(kidStyleContext);
|
|
|
|
if (NS_OK == mFirstChild) {
|
1998-04-14 00:24:54 +04:00
|
|
|
mChildCount = 1;
|
|
|
|
mLastContentOffset = mFirstContentOffset;
|
|
|
|
}
|
|
|
|
NS_RELEASE(cd);
|
|
|
|
}
|
|
|
|
NS_RELEASE(child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD PageFrame::ResizeReflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsSize* aMaxElementSize,
|
1998-05-12 08:17:56 +04:00
|
|
|
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
|
|
|
|
|
|
|
// Do we have any children?
|
|
|
|
if (nsnull == mFirstChild) {
|
|
|
|
if (nsnull == mPrevInFlow) {
|
|
|
|
// Create the first child frame
|
|
|
|
CreateFirstChild(aPresContext);
|
|
|
|
} else {
|
|
|
|
PageFrame* prevPage = (PageFrame*)mPrevInFlow;
|
|
|
|
|
|
|
|
NS_ASSERTION(!prevPage->mLastContentIsComplete, "bad continuing page");
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIFrame* prevLastChild;
|
|
|
|
prevPage->LastChild(prevLastChild);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Create a continuing child of the previous page's last child
|
1998-05-07 04:08:20 +04:00
|
|
|
nsIStyleContext* kidSC;
|
|
|
|
prevLastChild->GetStyleContext(aPresContext, kidSC);
|
|
|
|
nsresult rv = prevLastChild->CreateContinuingFrame(aPresContext, this,
|
|
|
|
kidSC, mFirstChild);
|
|
|
|
NS_RELEASE(kidSC);
|
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
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) {
|
|
|
|
// Get the child's desired size
|
1998-05-20 20:28:05 +04:00
|
|
|
mFirstChild->WillReflow(*aPresContext);
|
1998-04-17 05:41:24 +04:00
|
|
|
aStatus = ReflowChild(mFirstChild, aPresContext, aDesiredSize, aMaxSize,
|
|
|
|
aMaxElementSize);
|
1998-05-12 08:17:56 +04:00
|
|
|
mLastContentIsComplete = NS_FRAME_IS_COMPLETE(aStatus);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Make sure the child is at least as tall as our max size (the containing window)
|
|
|
|
if (aDesiredSize.height < aMaxSize.height) {
|
|
|
|
aDesiredSize.height = aMaxSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place and size the child
|
|
|
|
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
mFirstChild->SetRect(rect);
|
1998-05-20 20:28:05 +04:00
|
|
|
mFirstChild->DidReflow(*aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Is the frame complete?
|
1998-05-12 08:17:56 +04:00
|
|
|
if (NS_FRAME_IS_COMPLETE(aStatus)) {
|
1998-04-17 05:41:24 +04:00
|
|
|
nsIFrame* childNextInFlow;
|
|
|
|
|
|
|
|
mFirstChild->GetNextInFlow(childNextInFlow);
|
|
|
|
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list");
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return our desired size
|
|
|
|
aDesiredSize.width = aMaxSize.width;
|
|
|
|
aDesiredSize.height = aMaxSize.height;
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
// XXX Do something sensible in page mode...
|
1998-04-17 05:41:24 +04:00
|
|
|
NS_METHOD PageFrame::IncrementalReflow(nsIPresContext* aPresContext,
|
|
|
|
nsReflowMetrics& aDesiredSize,
|
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsReflowCommand& aReflowCommand,
|
1998-05-12 08:17:56 +04:00
|
|
|
nsReflowStatus& aStatus)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
|
|
|
// We don't expect the target of the reflow command to be page frame
|
|
|
|
NS_ASSERTION(aReflowCommand.GetTarget() != this, "page frame is reflow command target");
|
|
|
|
|
|
|
|
nsSize maxSize(aMaxSize.width, NS_UNCONSTRAINEDSIZE);
|
|
|
|
nsIFrame* child;
|
|
|
|
|
|
|
|
// Dispatch the reflow command to our pseudo frame. Allow it to be as high
|
|
|
|
// as it wants
|
1998-04-17 05:41:24 +04:00
|
|
|
aStatus = aReflowCommand.Next(aDesiredSize, maxSize, child);
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
// Place and size the child. Make sure the child is at least as
|
|
|
|
// tall as our max size (the containing window)
|
|
|
|
if (nsnull != child) {
|
|
|
|
NS_ASSERTION(child == mFirstChild, "unexpected reflow command frame");
|
|
|
|
if (aDesiredSize.height < aMaxSize.height) {
|
|
|
|
aDesiredSize.height = aMaxSize.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
|
|
|
child->SetRect(rect);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
PageFrame::CreateContinuingFrame(nsIPresContext* aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-05-06 03:56:50 +04:00
|
|
|
PageFrame* cf = new PageFrame(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-04-17 05:41:24 +04:00
|
|
|
NS_METHOD PageFrame::Paint(nsIPresContext& aPresContext,
|
|
|
|
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-04-17 05:41:24 +04:00
|
|
|
NS_METHOD PageFrame::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
|
|
|
}
|
|
|
|
|