1998-06-09 04:51:44 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The contents of this file are subject to the Netscape 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/NPL/
|
1998-06-09 04:51:44 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00: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.
|
1998-06-09 04:51:44 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-06-09 04:51:44 +00:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 03:40:37 +00:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-06-09 04:51:44 +00:00
|
|
|
*/
|
1999-02-12 17:45:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsHTMLReflowCommand.h"
|
1998-12-18 05:50:19 +00:00
|
|
|
#include "nsHTMLParts.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIContent.h"
|
1998-06-30 23:19:10 +00:00
|
|
|
#include "nsIStyleContext.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsHTMLIIDs.h"
|
1999-09-15 00:24:54 +00:00
|
|
|
#include "nsFrame.h"
|
1999-11-19 15:33:29 +00:00
|
|
|
#include "nsContainerFrame.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewHTMLReflowCommand(nsIReflowCommand** aInstancePtrResult,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsIReflowCommand::ReflowType aReflowType,
|
1998-11-04 19:26:25 +00:00
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIAtom* aAttribute)
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
|
|
|
if (nsnull == aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
1998-11-04 19:26:25 +00:00
|
|
|
nsHTMLReflowCommand* cmd = new nsHTMLReflowCommand(aTargetFrame, aReflowType, aChildFrame, aAttribute);
|
1998-06-09 04:51:44 +00:00
|
|
|
if (nsnull == cmd) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2001-01-04 20:44:42 +00:00
|
|
|
return cmd->QueryInterface(NS_GET_IID(nsIReflowCommand), (void**)aInstancePtrResult);
|
1998-06-09 04:51:44 +00: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 19:26:25 +00:00
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIAtom* aAttribute)
|
1998-09-18 17:18:37 +00:00
|
|
|
: mType(aReflowType), mTargetFrame(aTargetFrame), mChildFrame(aChildFrame),
|
1999-02-12 17:45:58 +00:00
|
|
|
mPrevSiblingFrame(nsnull),
|
|
|
|
mAttribute(aAttribute),
|
2000-09-12 00:35:11 +00:00
|
|
|
mListName(nsnull),
|
|
|
|
mFlags(0)
|
1998-09-18 17:18:37 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(mTargetFrame != nsnull, "null target frame");
|
1998-11-04 19:26:25 +00:00
|
|
|
if (nsnull!=mAttribute)
|
|
|
|
NS_ADDREF(mAttribute);
|
1998-09-18 17:18:37 +00:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
1998-06-09 04:51:44 +00:00
|
|
|
nsHTMLReflowCommand::~nsHTMLReflowCommand()
|
|
|
|
{
|
1998-11-04 19:26:25 +00:00
|
|
|
NS_IF_RELEASE(mAttribute);
|
1998-12-29 03:38:16 +00:00
|
|
|
NS_IF_RELEASE(mListName);
|
1998-06-09 04:51:44 +00:00
|
|
|
}
|
|
|
|
|
2001-01-04 20:44:42 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsHTMLReflowCommand, NS_GET_IID(nsIReflowCommand));
|
1998-06-09 04:51:44 +00:00
|
|
|
|
1999-09-15 00:24:54 +00:00
|
|
|
nsIFrame* nsHTMLReflowCommand::GetContainingBlock(nsIFrame* aFloater) const
|
1998-06-30 23:19:10 +00:00
|
|
|
{
|
1998-11-10 18:04:10 +00:00
|
|
|
nsIFrame* containingBlock;
|
1999-02-10 01:36:30 +00:00
|
|
|
aFloater->GetParent(&containingBlock);
|
1998-06-30 23:19:10 +00:00
|
|
|
return containingBlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsHTMLReflowCommand::BuildPath()
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
mPath.Clear();
|
1998-06-30 23:19:10 +00: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 16:45:20 +00:00
|
|
|
const nsStyleDisplay* display;
|
|
|
|
mTargetFrame->GetStyleData(eStyleStruct_Display, (const nsStyleStruct*&)display);
|
1998-06-30 23:19:10 +00:00
|
|
|
if (NS_STYLE_FLOAT_NONE != display->mFloats) {
|
|
|
|
mPath.AppendElement((void*)mTargetFrame);
|
|
|
|
|
1999-02-10 01:36:30 +00:00
|
|
|
for (nsIFrame* f = GetContainingBlock(mTargetFrame); nsnull != f; f->GetParent(&f)) {
|
1998-06-30 23:19:10 +00:00
|
|
|
mPath.AppendElement((void*)f);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
1999-02-10 01:36:30 +00:00
|
|
|
for (nsIFrame* f = mTargetFrame; nsnull != f; f->GetParent(&f)) {
|
1998-06-30 23:19:10 +00:00
|
|
|
mPath.AppendElement((void*)f);
|
|
|
|
}
|
1998-06-09 04:51:44 +00:00
|
|
|
}
|
1998-06-30 23:19:10 +00:00
|
|
|
}
|
|
|
|
|
1999-11-24 06:03:41 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::Dispatch(nsIPresContext* aPresContext,
|
1998-10-01 04:46:11 +00:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
1998-10-02 01:12:39 +00:00
|
|
|
const nsSize& aMaxSize,
|
|
|
|
nsIRenderingContext& aRendContext)
|
1998-06-30 23:19:10 +00:00
|
|
|
{
|
|
|
|
// Build the path from the target frame (index 0) to the root frame
|
|
|
|
BuildPath();
|
1998-06-09 04:51:44 +00:00
|
|
|
|
|
|
|
// Send an incremental reflow notification to the root frame
|
|
|
|
nsIFrame* root = (nsIFrame*)mPath[mPath.Count() - 1];
|
|
|
|
|
|
|
|
#ifdef NS_DEBUG
|
1999-02-12 17:45:58 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
1999-11-24 06:03:41 +00:00
|
|
|
aPresContext->GetShell(getter_AddRefs(shell));
|
1999-02-12 18:41:26 +00:00
|
|
|
if (shell) {
|
1998-12-29 04:45:18 +00:00
|
|
|
nsIFrame* rootFrame;
|
1999-02-12 17:45:58 +00:00
|
|
|
shell->GetRootFrame(&rootFrame);
|
1998-12-29 04:45:18 +00:00
|
|
|
NS_ASSERTION(rootFrame == root, "bad root frame");
|
1998-06-09 04:51:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-01-12 08:28:24 +00:00
|
|
|
if (nsnull != root) {
|
1998-06-09 04:51:44 +00:00
|
|
|
mPath.RemoveElementAt(mPath.Count() - 1);
|
|
|
|
|
1999-03-05 04:29:11 +00:00
|
|
|
nsHTMLReflowState reflowState(aPresContext, root, *this,
|
|
|
|
&aRendContext, aMaxSize);
|
1998-10-02 04:10:00 +00:00
|
|
|
nsReflowStatus status;
|
1999-11-19 15:33:29 +00:00
|
|
|
nsIView* view;
|
1998-10-01 04:46:11 +00:00
|
|
|
|
1999-11-19 15:33:29 +00:00
|
|
|
root->WillReflow(aPresContext);
|
1999-11-24 06:03:41 +00:00
|
|
|
root->GetView(aPresContext, &view);
|
1999-11-19 15:33:29 +00:00
|
|
|
if (view) {
|
1999-11-24 06:03:41 +00:00
|
|
|
nsContainerFrame::PositionFrameView(aPresContext, root, view);
|
1999-11-19 15:33:29 +00:00
|
|
|
}
|
1999-10-30 02:52:11 +00:00
|
|
|
root->Reflow(aPresContext, aDesiredSize, reflowState, status);
|
1999-11-24 06:03:41 +00:00
|
|
|
root->SizeTo(aPresContext, aDesiredSize.width, aDesiredSize.height);
|
1999-11-19 15:33:29 +00:00
|
|
|
if (view) {
|
1999-11-24 06:03:41 +00:00
|
|
|
nsContainerFrame::SyncFrameViewAfterReflow(aPresContext, root, view,
|
1999-11-19 15:33:29 +00:00
|
|
|
nsnull);
|
|
|
|
}
|
|
|
|
root->DidReflow(aPresContext, NS_FRAME_REFLOW_FINISHED);
|
1998-06-09 04:51:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-20 05:11:17 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetNext(nsIFrame*& aNextFrame, PRBool aRemove)
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
PRInt32 count = mPath.Count();
|
|
|
|
|
|
|
|
aNextFrame = nsnull;
|
|
|
|
if (count > 0) {
|
|
|
|
aNextFrame = (nsIFrame*)mPath[count - 1];
|
1999-01-20 05:11:17 +00:00
|
|
|
if (aRemove) {
|
|
|
|
mPath.RemoveElementAt(count - 1);
|
|
|
|
}
|
1998-06-09 04:51:44 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-30 23:19:10 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetTarget(nsIFrame*& aTargetFrame) const
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
aTargetFrame = mTargetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-10 19:32:14 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::SetTarget(nsIFrame* aTargetFrame)
|
|
|
|
{
|
|
|
|
mTargetFrame = aTargetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-30 23:19:10 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetType(ReflowType& aReflowType) const
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
aReflowType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-04 19:26:25 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetAttribute(nsIAtom *& aAttribute) const
|
|
|
|
{
|
|
|
|
aAttribute = mAttribute;
|
|
|
|
if (nsnull!=aAttribute)
|
|
|
|
NS_ADDREF(aAttribute);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-06-30 23:19:10 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetChildFrame(nsIFrame*& aChildFrame) const
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
aChildFrame = mChildFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-10 04:31:02 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetChildListName(nsIAtom*& aListName) const
|
|
|
|
{
|
1998-12-29 03:38:16 +00: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 04:31:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-09-18 17:18:37 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::GetPrevSiblingFrame(nsIFrame*& aSiblingFrame) const
|
|
|
|
{
|
|
|
|
aSiblingFrame = mPrevSiblingFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-15 00:24:54 +00:00
|
|
|
NS_IMETHODIMP nsHTMLReflowCommand::List(FILE* out) const
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const char* kReflowCommandType[] = {
|
|
|
|
"ContentChanged",
|
|
|
|
"StyleChanged",
|
|
|
|
"PullupReflow",
|
|
|
|
"PushReflow",
|
|
|
|
"CheckPullupReflow",
|
|
|
|
"ReflowDirty",
|
|
|
|
"UserDefined",
|
|
|
|
};
|
|
|
|
|
|
|
|
fprintf(out, "ReflowCommand@%p[%s]:",
|
|
|
|
this, kReflowCommandType[mType]);
|
|
|
|
if (mTargetFrame) {
|
|
|
|
fprintf(out, " target=");
|
|
|
|
nsFrame::ListTag(out, mTargetFrame);
|
|
|
|
}
|
|
|
|
if (mChildFrame) {
|
|
|
|
fprintf(out, " child=");
|
|
|
|
nsFrame::ListTag(out, mChildFrame);
|
|
|
|
}
|
|
|
|
if (mPrevSiblingFrame) {
|
|
|
|
fprintf(out, " prevSibling=");
|
|
|
|
nsFrame::ListTag(out, mPrevSiblingFrame);
|
|
|
|
}
|
|
|
|
if (mAttribute) {
|
|
|
|
fprintf(out, " attr=");
|
|
|
|
nsAutoString attr;
|
|
|
|
mAttribute->ToString(attr);
|
|
|
|
fputs(attr, out);
|
|
|
|
}
|
|
|
|
if (mListName) {
|
|
|
|
fprintf(out, " list=");
|
|
|
|
nsAutoString attr;
|
|
|
|
mListName->ToString(attr);
|
|
|
|
fputs(attr, out);
|
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
// Show the path, but without using mPath which is in an undefined
|
|
|
|
// state at this point.
|
|
|
|
if (mTargetFrame) {
|
|
|
|
// Floating frames are handled differently. The path goes from the target
|
|
|
|
// frame to the containing block, and then up the hierarchy
|
|
|
|
PRBool didOne = PR_FALSE;
|
|
|
|
nsIFrame* start = mTargetFrame;
|
|
|
|
const nsStyleDisplay* display;
|
|
|
|
mTargetFrame->GetStyleData(eStyleStruct_Display,
|
|
|
|
(const nsStyleStruct*&) display);
|
|
|
|
if (NS_STYLE_FLOAT_NONE != display->mFloats) {
|
|
|
|
start = GetContainingBlock(mTargetFrame);
|
|
|
|
}
|
|
|
|
for (nsIFrame* f = start; nsnull != f; f->GetParent(&f)) {
|
|
|
|
if (f != mTargetFrame) {
|
|
|
|
fprintf(out, " ");
|
|
|
|
nsFrame::ListTag(out, f);
|
|
|
|
didOne = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (didOne) {
|
|
|
|
fprintf(out, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-12 00:35:11 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLReflowCommand::GetFlags(PRInt32* aFlags)
|
|
|
|
{
|
|
|
|
*aFlags = mFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsHTMLReflowCommand::SetFlags(PRInt32 aFlags)
|
|
|
|
{
|
|
|
|
mFlags = aFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|