1998-06-09 08:51:44 +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 "nsHTMLReflowCommand.h"
|
1998-12-18 08:50:19 +03:00
|
|
|
#include "nsHTMLParts.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIFrame.h"
|
1998-10-01 08:46:11 +04:00
|
|
|
#include "nsIHTMLReflow.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIContent.h"
|
1998-07-01 03:19:10 +04:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
1998-06-09 08:51:44 +04:00
|
|
|
|
|
|
|
static NS_DEFINE_IID(kIReflowCommandIID, NS_IREFLOWCOMMAND_IID);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLReflowCommand(nsIReflowCommand** aInstancePtrResult,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsIReflowCommand::ReflowType aReflowType,
|
1998-11-04 22:26:25 +03:00
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIAtom* aAttribute)
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-11-04 22:26:25 +03:00
|
|
|
nsHTMLReflowCommand* cmd = new nsHTMLReflowCommand(aTargetFrame, aReflowType, aChildFrame, aAttribute);
|
1998-06-09 08:51:44 +04:00
|
|
|
if (nsnull == cmd) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd->QueryInterface(kIReflowCommandIID, (void**)aInstancePtrResult);
|
|
|
|
}
|
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
nsresult
|
|
|
|
NS_NewHTMLReflowCommand(nsIReflowCommand** aInstancePtrResult,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIFrame* aPrevSiblingFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
nsHTMLReflowCommand* cmd = new nsHTMLReflowCommand(aTargetFrame, aChildFrame,
|
|
|
|
aPrevSiblingFrame);
|
|
|
|
if (nsnull == cmd) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd->QueryInterface(kIReflowCommandIID, (void**)aInstancePtrResult);
|
|
|
|
}
|
1998-06-09 08:51:44 +04:00
|
|
|
|
|
|
|
// Construct a reflow command given a target frame, reflow command type,
|
|
|
|
// and optional child frame
|
|
|
|
nsHTMLReflowCommand::nsHTMLReflowCommand(nsIFrame* aTargetFrame,
|
|
|
|
ReflowType aReflowType,
|
1998-11-04 22:26:25 +03:00
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIAtom* aAttribute)
|
1998-09-18 21:18:37 +04:00
|
|
|
: mType(aReflowType), mTargetFrame(aTargetFrame), mChildFrame(aChildFrame),
|
1998-12-29 06:38:16 +03:00
|
|
|
mAttribute(aAttribute), mPrevSiblingFrame(nsnull), mListName(nsnull)
|
1998-09-18 21:18:37 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mTargetFrame != nsnull, "null target frame");
|
1998-11-04 22:26:25 +03:00
|
|
|
if (nsnull!=mAttribute)
|
|
|
|
NS_ADDREF(mAttribute);
|
1998-09-18 21:18:37 +04:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLReflowCommand::nsHTMLReflowCommand(nsIFrame* aTargetFrame,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIFrame* aPrevSiblingFrame)
|
|
|
|
: mType(FrameInserted), mTargetFrame(aTargetFrame), mChildFrame(aChildFrame),
|
1998-12-29 06:38:16 +03:00
|
|
|
mPrevSiblingFrame(aPrevSiblingFrame), mAttribute(nsnull), mListName(nsnull)
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mTargetFrame != nsnull, "null target frame");
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLReflowCommand::~nsHTMLReflowCommand()
|
|
|
|
{
|
1998-11-04 22:26:25 +03:00
|
|
|
NS_IF_RELEASE(mAttribute);
|
1998-12-29 06:38:16 +03:00
|
|
|
NS_IF_RELEASE(mListName);
|
1998-06-09 08:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsHTMLReflowCommand, kIReflowCommandIID);
|
|
|
|
|
1998-07-01 03:19:10 +04:00
|
|
|
nsIFrame* nsHTMLReflowCommand::GetContainingBlock(nsIFrame* aFloater)
|
|
|
|
{
|
1998-11-10 21:04:10 +03:00
|
|
|
nsIFrame* containingBlock;
|
1999-02-10 04:36:30 +03:00
|
|
|
aFloater->GetParent(&containingBlock);
|
1998-07-01 03:19:10 +04:00
|
|
|
return containingBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLReflowCommand::BuildPath()
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
mPath.Clear();
|
1998-07-01 03:19:10 +04:00
|
|
|
|
|
|
|
// Floating frames are handled differently. The path goes from the target
|
|
|
|
// frame to the containing block, and then up the hierarchy
|
1998-12-02 19:45:20 +03:00
|
|
|
const nsStyleDisplay* display;
|
|
|
|
mTargetFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
|
1998-07-01 03:19:10 +04:00
|
|
|
if (NS_STYLE_FLOAT_NONE != display->mFloats) {
|
|
|
|
mPath.AppendElement((void*)mTargetFrame);
|
|
|
|
|
1999-02-10 04:36:30 +03:00
|
|
|
for (nsIFrame* f = GetContainingBlock(mTargetFrame); nsnull != f; f->GetParent(&f)) {
|
1998-07-01 03:19:10 +04:00
|
|
|
mPath.AppendElement((void*)f);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
1999-02-10 04:36:30 +03:00
|
|
|
for (nsIFrame* f = mTargetFrame; nsnull != f; f->GetParent(&f)) {
|
1998-07-01 03:19:10 +04:00
|
|
|
mPath.AppendElement((void*)f);
|
|
|
|
}
|
1998-06-09 08:51:44 +04:00
|
|
|
}
|
1998-07-01 03:19:10 +04:00
|
|
|
}
|
|
|
|
|
1998-10-01 08:46:11 +04:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::Dispatch(nsIPresContext& aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
1998-10-02 05:12:39 +04:00
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsIRenderingContext& aRendContext)
|
1998-07-01 03:19:10 +04:00
|
|
|
{
|
|
|
|
// Build the path from the target frame (index 0) to the root frame
|
|
|
|
BuildPath();
|
1998-06-09 08:51:44 +04:00
|
|
|
|
|
|
|
// Send an incremental reflow notification to the root frame
|
|
|
|
nsIFrame* root = (nsIFrame*)mPath[mPath.Count() - 1];
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsIPresShell* shell = aPresContext.GetShell();
|
|
|
|
if (nsnull != shell) {
|
1998-12-29 07:45:18 +03:00
|
|
|
nsIFrame* rootFrame;
|
|
|
|
shell->GetRootFrame(rootFrame);
|
|
|
|
NS_ASSERTION(rootFrame == root, "bad root frame");
|
1998-06-09 08:51:44 +04:00
|
|
|
NS_RELEASE(shell);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (nsnull != root) {
|
|
|
|
mPath.RemoveElementAt(mPath.Count() - 1);
|
|
|
|
|
1998-10-12 18:48:02 +04:00
|
|
|
nsHTMLReflowState reflowState(aPresContext, root, *this, aMaxSize,
|
|
|
|
&aRendContext);
|
1998-10-02 08:10:00 +04:00
|
|
|
nsIHTMLReflow* htmlReflow;
|
|
|
|
nsReflowStatus status;
|
1998-10-01 08:46:11 +04:00
|
|
|
|
|
|
|
if (NS_OK == root->QueryInterface(kIHTMLReflowIID, (void**)&htmlReflow)) {
|
|
|
|
htmlReflow->Reflow(aPresContext, aDesiredSize, reflowState, status);
|
|
|
|
}
|
1998-06-09 08:51:44 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-20 08:11:17 +03:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetNext(nsIFrame*& aNextFrame, PRBool aRemove)
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
PRInt32 count = mPath.Count();
|
|
|
|
|
|
|
|
aNextFrame = nsnull;
|
|
|
|
if (count > 0) {
|
|
|
|
aNextFrame = (nsIFrame*)mPath[count - 1];
|
1999-01-20 08:11:17 +03:00
|
|
|
if (aRemove) {
|
|
|
|
mPath.RemoveElementAt(count - 1);
|
|
|
|
}
|
1998-06-09 08:51:44 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-01 03:19:10 +04:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetTarget(nsIFrame*& aTargetFrame) const
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
aTargetFrame = mTargetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-10 23:32:14 +04:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::SetTarget(nsIFrame* aTargetFrame)
|
|
|
|
{
|
|
|
|
mTargetFrame = aTargetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-01 03:19:10 +04:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetType(ReflowType& aReflowType) const
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
aReflowType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-04 22:26:25 +03:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetAttribute(nsIAtom *& aAttribute) const
|
|
|
|
{
|
|
|
|
aAttribute = mAttribute;
|
|
|
|
if (nsnull!=aAttribute)
|
|
|
|
NS_ADDREF(aAttribute);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-07-01 03:19:10 +04:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetChildFrame(nsIFrame*& aChildFrame) const
|
1998-06-09 08:51:44 +04:00
|
|
|
{
|
|
|
|
aChildFrame = mChildFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-10 07:31:02 +03:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetChildListName(nsIAtom*& aListName) const
|
|
|
|
{
|
1998-12-29 06:38:16 +03:00
|
|
|
aListName = mListName;
|
|
|
|
NS_IF_ADDREF(aListName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::SetChildListName(nsIAtom* aListName)
|
|
|
|
{
|
|
|
|
mListName = aListName;
|
|
|
|
NS_IF_ADDREF(mListName);
|
1998-11-10 07:31:02 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-18 21:18:37 +04:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetPrevSiblingFrame(nsIFrame*& aSiblingFrame) const
|
|
|
|
{
|
|
|
|
aSiblingFrame = mPrevSiblingFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|