1998-04-13 20:24:54 +00: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"
|
1998-12-18 05:44:26 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIStyleContext.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsIReflowCommand.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
#include "nsIRenderingContext.h"
|
1998-06-25 14:53:45 +00:00
|
|
|
#include "nsHTMLAtoms.h"
|
1998-10-01 04:46:11 +00:00
|
|
|
#include "nsHTMLIIDs.h"
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-10-02 04:10:00 +00:00
|
|
|
NS_METHOD nsPageFrame::Reflow(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-05-12 04:17:56 +00:00
|
|
|
aStatus = NS_FRAME_COMPLETE; // initialize out parameter
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-25 17:31:49 +00:00
|
|
|
if (eReflowReason_Incremental == aReflowState.reason) {
|
|
|
|
// We don't expect the target of the reflow command to be page frame
|
1998-06-09 04:51:44 +00:00
|
|
|
#ifdef NS_DEUG
|
1998-05-25 17:31:49 +00:00
|
|
|
NS_ASSERTION(nsnull != aReflowState.reflowCommand, "null reflow command");
|
1998-06-09 04:51:44 +00:00
|
|
|
|
|
|
|
nsIFrame* target;
|
|
|
|
aReflowState.reflowCommand->GetTarget(target);
|
|
|
|
NS_ASSERTION(target != this, "page frame is reflow command target");
|
|
|
|
#endif
|
1998-05-25 17:31:49 +00:00
|
|
|
|
|
|
|
// Verify the next reflow command frame is our one and only child frame
|
1998-06-09 04:51:44 +00:00
|
|
|
nsIFrame* next;
|
|
|
|
aReflowState.reflowCommand->GetNext(next);
|
1999-01-15 22:53:39 +00:00
|
|
|
NS_ASSERTION(next == mFrames.FirstChild(), "bad reflow frame");
|
1998-05-25 17:31:49 +00:00
|
|
|
|
|
|
|
// Dispatch the reflow command to our content child. Allow it to be as high
|
|
|
|
// as it wants
|
1999-01-05 23:31:18 +00:00
|
|
|
nsSize maxSize(aReflowState.availableWidth, NS_UNCONSTRAINEDSIZE);
|
1999-01-15 22:53:39 +00:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, mFrames.FirstChild(),
|
|
|
|
aReflowState,
|
1998-10-12 14:48:02 +00:00
|
|
|
maxSize);
|
1998-05-25 17:31:49 +00:00
|
|
|
|
1998-12-12 17:58:18 +00:00
|
|
|
kidReflowState.isTopOfPage = PR_TRUE;
|
1999-01-15 22:53:39 +00:00
|
|
|
ReflowChild(mFrames.FirstChild(), aPresContext, aDesiredSize,
|
|
|
|
kidReflowState, aStatus);
|
1998-05-25 17:31:49 +00:00
|
|
|
|
|
|
|
// Place and size the child. Make sure the child is at least as
|
|
|
|
// tall as our max size (the containing window)
|
1999-01-05 23:31:18 +00:00
|
|
|
if (aDesiredSize.height < aReflowState.availableHeight) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
1999-01-15 22:53:39 +00:00
|
|
|
mFrames.FirstChild()->SetRect(rect);
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-05-25 17:31:49 +00:00
|
|
|
} else {
|
|
|
|
// Do we have any children?
|
1998-11-05 06:12:57 +00:00
|
|
|
// XXX We should use the overflow list instead...
|
1999-01-15 22:53:39 +00:00
|
|
|
if (mFrames.IsEmpty() && (nsnull != mPrevInFlow)) {
|
1998-11-05 06:12:57 +00:00
|
|
|
nsPageFrame* prevPage = (nsPageFrame*)mPrevInFlow;
|
|
|
|
|
1999-01-15 22:53:39 +00:00
|
|
|
nsIFrame* prevLastChild = prevPage->mFrames.LastChild();
|
1998-11-05 06:12:57 +00:00
|
|
|
|
|
|
|
// Create a continuing child of the previous page's last child
|
|
|
|
nsIStyleContext* kidSC;
|
|
|
|
prevLastChild->GetStyleContext(kidSC);
|
1999-01-15 22:53:39 +00:00
|
|
|
nsIFrame* newFrame;
|
1998-11-05 06:12:57 +00:00
|
|
|
nsresult rv = prevLastChild->CreateContinuingFrame(aPresContext, this,
|
1999-01-15 22:53:39 +00:00
|
|
|
kidSC,
|
|
|
|
newFrame);
|
|
|
|
mFrames.SetFrames(newFrame);
|
1998-11-05 06:12:57 +00:00
|
|
|
NS_RELEASE(kidSC);
|
1998-05-25 17:31:49 +00:00
|
|
|
}
|
1998-11-05 06:12:57 +00:00
|
|
|
|
1998-05-25 17:31:49 +00:00
|
|
|
// Resize our frame allowing it only to be as big as we are
|
|
|
|
// XXX Pay attention to the page's border and padding...
|
1999-01-15 22:53:39 +00:00
|
|
|
if (mFrames.NotEmpty()) {
|
|
|
|
nsIFrame* frame = mFrames.FirstChild();
|
1999-01-05 23:31:18 +00:00
|
|
|
nsSize maxSize(aReflowState.availableWidth, aReflowState.availableHeight);
|
1999-01-15 22:53:39 +00:00
|
|
|
nsHTMLReflowState kidReflowState(aPresContext, frame, aReflowState,
|
1999-01-05 23:31:18 +00:00
|
|
|
maxSize);
|
1998-12-12 17:58:18 +00:00
|
|
|
kidReflowState.isTopOfPage = PR_TRUE;
|
1998-05-29 20:36:05 +00:00
|
|
|
|
1998-12-12 17:58:18 +00:00
|
|
|
nsIHTMLReflow* htmlReflow;
|
1999-01-15 22:53:39 +00:00
|
|
|
if (NS_OK == frame->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
1998-10-01 04:46:11 +00:00
|
|
|
// Get the child's desired size
|
1999-01-15 22:53:39 +00:00
|
|
|
ReflowChild(frame, aPresContext, aDesiredSize, kidReflowState, aStatus);
|
1998-05-25 17:31:49 +00:00
|
|
|
|
1998-10-01 04:46:11 +00:00
|
|
|
// Make sure the child is at least as tall as our max size (the containing window)
|
1999-01-05 23:31:18 +00:00
|
|
|
if (aDesiredSize.height < aReflowState.availableHeight) {
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
1998-10-01 04:46:11 +00:00
|
|
|
}
|
1998-05-25 17:31:49 +00:00
|
|
|
|
1998-10-01 04:46:11 +00:00
|
|
|
// Place and size the child
|
|
|
|
nsRect rect(0, 0, aDesiredSize.width, aDesiredSize.height);
|
1999-01-15 22:53:39 +00:00
|
|
|
frame->SetRect(rect);
|
1998-10-06 00:27:22 +00:00
|
|
|
// XXX Should we be sending the DidReflow?
|
1998-10-01 04:46:11 +00:00
|
|
|
htmlReflow->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1998-05-25 17:31:49 +00:00
|
|
|
|
1998-10-01 04:46:11 +00:00
|
|
|
// Is the frame complete?
|
|
|
|
if (NS_FRAME_IS_COMPLETE(aStatus)) {
|
|
|
|
nsIFrame* childNextInFlow;
|
1998-05-25 17:31:49 +00:00
|
|
|
|
1999-01-15 22:53:39 +00:00
|
|
|
frame->GetNextInFlow(childNextInFlow);
|
1998-10-01 04:46:11 +00:00
|
|
|
NS_ASSERTION(nsnull == childNextInFlow, "bad child flow list");
|
|
|
|
}
|
1998-05-25 17:31:49 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-25 17:31:49 +00:00
|
|
|
// Return our desired size
|
1999-01-05 23:31:18 +00:00
|
|
|
aDesiredSize.width = aReflowState.availableWidth;
|
|
|
|
aDesiredSize.height = aReflowState.availableHeight;
|
1998-05-25 17:31:49 +00:00
|
|
|
}
|
1998-04-13 20:24:54 +00:00
|
|
|
|
1998-04-17 01:41:24 +00:00
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-05-07 00:08:20 +00:00
|
|
|
NS_METHOD
|
1998-07-15 03:23:23 +00:00
|
|
|
nsPageFrame::CreateContinuingFrame(nsIPresContext& aPresContext,
|
1998-05-28 02:37:37 +00:00
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIStyleContext* aStyleContext,
|
|
|
|
nsIFrame*& aContinuingFrame)
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-12-03 06:31:43 +00:00
|
|
|
nsPageFrame* cf = new nsPageFrame;
|
1998-05-07 00:08:20 +00:00
|
|
|
if (nsnull == cf) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-01-14 05:16:23 +00:00
|
|
|
cf->Init(aPresContext, mContent, aParent, aStyleContext);
|
1998-12-03 06:31:43 +00:00
|
|
|
cf->AppendToFlow(this);
|
1998-04-17 01:41:24 +00:00
|
|
|
aContinuingFrame = cf;
|
|
|
|
return NS_OK;
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-11-19 17:22:29 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPageFrame::GetFrameName(nsString& aResult) const
|
1998-04-13 20:24:54 +00:00
|
|
|
{
|
1998-11-19 17:22:29 +00:00
|
|
|
return MakeFrameName("Page", aResult);
|
1998-04-13 20:24:54 +00:00
|
|
|
}
|
|
|
|
|
1998-12-04 21:04:56 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewPageFrame(nsIFrame*& aResult)
|
|
|
|
{
|
|
|
|
nsPageFrame* it = new nsPageFrame;
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aResult = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|