2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1998-06-09 04:51:44 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +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
|
|
|
*
|
2001-09-28 20:14:13 +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.
|
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
1999-09-15 00:24:54 +00:00
|
|
|
#include "nsFrame.h"
|
1999-11-19 15:33:29 +00:00
|
|
|
#include "nsContainerFrame.h"
|
2002-04-11 01:13:41 +00:00
|
|
|
#include "nsLayoutAtoms.h"
|
1998-06-09 04:51:44 +00:00
|
|
|
|
|
|
|
nsresult
|
2001-12-17 22:39:59 +00:00
|
|
|
NS_NewHTMLReflowCommand(nsHTMLReflowCommand** aInstancePtrResult,
|
|
|
|
nsIFrame* aTargetFrame,
|
|
|
|
nsReflowType aReflowType,
|
|
|
|
nsIFrame* aChildFrame,
|
|
|
|
nsIAtom* aAttribute)
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
2001-11-29 08:48:53 +00:00
|
|
|
NS_ASSERTION(aInstancePtrResult,
|
|
|
|
"null result passed to NS_NewHTMLReflowCommand");
|
|
|
|
|
|
|
|
*aInstancePtrResult = new nsHTMLReflowCommand(aTargetFrame, aReflowType,
|
|
|
|
aChildFrame, aAttribute);
|
|
|
|
if (!*aInstancePtrResult) {
|
1998-06-09 04:51:44 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2001-11-29 08:48:53 +00:00
|
|
|
return NS_OK;
|
1998-06-09 04:51:44 +00:00
|
|
|
}
|
|
|
|
|
2001-09-06 21:11:44 +00:00
|
|
|
#ifdef DEBUG_jesup
|
|
|
|
PRInt32 gReflows;
|
|
|
|
PRInt32 gReflowsInUse;
|
|
|
|
PRInt32 gReflowsInUseMax;
|
|
|
|
PRInt32 gReflowsZero;
|
|
|
|
PRInt32 gReflowsAuto;
|
|
|
|
PRInt32 gReflowsLarger;
|
|
|
|
PRInt32 gReflowsMaxZero;
|
|
|
|
PRInt32 gReflowsMaxAuto;
|
|
|
|
PRInt32 gReflowsMaxLarger;
|
|
|
|
class mPathStats {
|
|
|
|
public:
|
|
|
|
mPathStats();
|
|
|
|
~mPathStats();
|
|
|
|
};
|
|
|
|
mPathStats::mPathStats()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
mPathStats::~mPathStats()
|
|
|
|
{
|
|
|
|
printf("nsHTMLReflowCommand->mPath stats:\n");
|
|
|
|
printf("\tNumber created: %d\n",gReflows);
|
|
|
|
printf("\tNumber in-use: %d\n",gReflowsInUseMax);
|
|
|
|
|
|
|
|
printf("\tNumber size == 0: %d\n",gReflowsZero);
|
|
|
|
printf("\tNumber size <= 8: %d\n",gReflowsAuto);
|
|
|
|
printf("\tNumber size > 8: %d\n",gReflowsLarger);
|
|
|
|
printf("\tNum max size == 0: %d\n",gReflowsMaxZero);
|
|
|
|
printf("\tNum max size <= 8: %d\n",gReflowsMaxAuto);
|
|
|
|
printf("\tNum max size > 8: %d\n",gReflowsMaxLarger);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just so constructor/destructor's get called
|
|
|
|
mPathStats gmPathStats;
|
|
|
|
#endif
|
|
|
|
|
1998-06-09 04:51:44 +00:00
|
|
|
// Construct a reflow command given a target frame, reflow command type,
|
|
|
|
// and optional child frame
|
2001-12-17 22:39:59 +00:00
|
|
|
nsHTMLReflowCommand::nsHTMLReflowCommand(nsIFrame* aTargetFrame,
|
|
|
|
nsReflowType aReflowType,
|
|
|
|
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
|
|
|
mAttribute(aAttribute),
|
2000-09-12 00:35:11 +00:00
|
|
|
mListName(nsnull),
|
|
|
|
mFlags(0)
|
1998-09-18 17:18:37 +00:00
|
|
|
{
|
2001-12-17 22:39:59 +00:00
|
|
|
MOZ_COUNT_CTOR(nsHTMLReflowCommand);
|
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);
|
2001-09-06 21:11:44 +00:00
|
|
|
#ifdef DEBUG_jesup
|
|
|
|
gReflows++;
|
|
|
|
gReflowsInUse++;
|
|
|
|
if (gReflowsInUse > gReflowsInUseMax)
|
|
|
|
gReflowsInUseMax = gReflowsInUse;
|
|
|
|
#endif
|
1998-09-18 17:18:37 +00:00
|
|
|
}
|
|
|
|
|
1998-06-09 04:51:44 +00:00
|
|
|
nsHTMLReflowCommand::~nsHTMLReflowCommand()
|
|
|
|
{
|
2001-12-17 22:39:59 +00:00
|
|
|
MOZ_COUNT_DTOR(nsHTMLReflowCommand);
|
2001-09-06 21:11:44 +00:00
|
|
|
#ifdef DEBUG_jesup
|
|
|
|
if (mPath.GetArraySize() == 0)
|
|
|
|
gReflowsMaxZero++;
|
|
|
|
else if (mPath.GetArraySize() <= 8)
|
|
|
|
gReflowsMaxAuto++;
|
|
|
|
else
|
|
|
|
gReflowsMaxLarger++;
|
|
|
|
gReflowsInUse--;
|
|
|
|
#endif
|
|
|
|
|
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-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::GetTarget(nsIFrame*& aTargetFrame) const
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
aTargetFrame = mTargetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::SetTarget(nsIFrame* aTargetFrame)
|
1998-09-10 19:32:14 +00:00
|
|
|
{
|
|
|
|
mTargetFrame = aTargetFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::GetType(nsReflowType& aReflowType) const
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
aReflowType = mType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::GetAttribute(nsIAtom *& aAttribute) const
|
1998-11-04 19:26:25 +00:00
|
|
|
{
|
|
|
|
aAttribute = mAttribute;
|
|
|
|
if (nsnull!=aAttribute)
|
|
|
|
NS_ADDREF(aAttribute);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::GetChildFrame(nsIFrame*& aChildFrame) const
|
1998-06-09 04:51:44 +00:00
|
|
|
{
|
|
|
|
aChildFrame = mChildFrame;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::GetChildListName(nsIAtom*& aListName) const
|
1998-11-10 04:31:02 +00:00
|
|
|
{
|
1998-12-29 03:38:16 +00:00
|
|
|
aListName = mListName;
|
|
|
|
NS_IF_ADDREF(aListName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::SetChildListName(nsIAtom* aListName)
|
1998-12-29 03:38:16 +00:00
|
|
|
{
|
|
|
|
mListName = aListName;
|
|
|
|
NS_IF_ADDREF(mListName);
|
1998-11-10 04:31:02 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
|
|
|
nsHTMLReflowCommand::List(FILE* out) const
|
1999-09-15 00:24:54 +00:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
static const char* kReflowCommandType[] = {
|
|
|
|
"ContentChanged",
|
|
|
|
"StyleChanged",
|
|
|
|
"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 (mAttribute) {
|
|
|
|
fprintf(out, " attr=");
|
|
|
|
nsAutoString attr;
|
|
|
|
mAttribute->ToString(attr);
|
2001-10-16 03:53:44 +00:00
|
|
|
fputs(NS_LossyConvertUCS2toASCII(attr).get(), out);
|
1999-09-15 00:24:54 +00:00
|
|
|
}
|
|
|
|
if (mListName) {
|
|
|
|
fprintf(out, " list=");
|
|
|
|
nsAutoString attr;
|
|
|
|
mListName->ToString(attr);
|
2001-10-16 03:53:44 +00:00
|
|
|
fputs(NS_LossyConvertUCS2toASCII(attr).get(), out);
|
1999-09-15 00:24:54 +00:00
|
|
|
}
|
|
|
|
fprintf(out, "\n");
|
|
|
|
|
|
|
|
// Show the path, but without using mPath which is in an undefined
|
|
|
|
// state at this point.
|
|
|
|
if (mTargetFrame) {
|
|
|
|
PRBool didOne = PR_FALSE;
|
2002-04-11 01:13:41 +00:00
|
|
|
for (nsIFrame* f = mTargetFrame; nsnull != f; f->GetParent(&f)) {
|
1999-09-15 00:24:54 +00:00
|
|
|
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
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
2000-09-12 00:35:11 +00:00
|
|
|
nsHTMLReflowCommand::GetFlags(PRInt32* aFlags)
|
|
|
|
{
|
|
|
|
*aFlags = mFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-17 23:57:59 +00:00
|
|
|
nsresult
|
2000-09-12 00:35:11 +00:00
|
|
|
nsHTMLReflowCommand::SetFlags(PRInt32 aFlags)
|
|
|
|
{
|
|
|
|
mFlags = aFlags;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-12-17 22:39:59 +00:00
|
|
|
|