1999-01-15 01:28:07 +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 "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/
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
#include "nsFrameList.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::DeleteFrames(nsIPresContext& aPresContext)
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&next);
|
1999-01-15 01:28:07 +00:00
|
|
|
frame->DeleteFrame(aPresContext);
|
1999-01-15 22:53:39 +00:00
|
|
|
mFirstChild = frame = next;
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::AppendFrames(nsIFrame* aParent, nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrameList, "null ptr");
|
|
|
|
if (nsnull != aFrameList) {
|
|
|
|
nsIFrame* lastChild = LastChild();
|
|
|
|
if (nsnull == lastChild) {
|
|
|
|
mFirstChild = aFrameList;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastChild->SetNextSibling(aFrameList);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
nsIFrame* frame = aFrameList;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frame->SetParent(aParent);
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::AppendFrame(nsIFrame* aParent, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (nsnull != aFrame) {
|
|
|
|
nsIFrame* lastChild = LastChild();
|
|
|
|
if (nsnull == lastChild) {
|
|
|
|
mFirstChild = aFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lastChild->SetNextSibling(aFrame);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
aFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::RemoveFrame(nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (nsnull != aFrame) {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
aFrame->GetNextSibling(&nextFrame);
|
1999-02-01 17:32:05 +00:00
|
|
|
aFrame->SetNextSibling(nsnull);
|
1999-01-15 01:28:07 +00:00
|
|
|
if (aFrame == mFirstChild) {
|
|
|
|
mFirstChild = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* prevSibling = GetPrevSiblingFor(aFrame);
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
prevSibling->SetNextSibling(nextFrame);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-15 22:53:39 +00:00
|
|
|
PRBool
|
|
|
|
nsFrameList::RemoveFirstChild()
|
|
|
|
{
|
|
|
|
if (nsnull != mFirstChild) {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
mFirstChild->GetNextSibling(&nextFrame);
|
1999-02-01 17:32:05 +00:00
|
|
|
mFirstChild->SetNextSibling(nsnull);
|
1999-01-15 22:53:39 +00:00
|
|
|
mFirstChild = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-01-15 01:28:07 +00:00
|
|
|
PRBool
|
|
|
|
nsFrameList::DeleteFrame(nsIPresContext& aPresContext, nsIFrame* aFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (RemoveFrame(aFrame)) {
|
|
|
|
aFrame->DeleteFrame(aPresContext);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::InsertFrame(nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevSibling,
|
|
|
|
nsIFrame* aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aNewFrame, "null ptr");
|
|
|
|
if (nsnull != aNewFrame) {
|
|
|
|
if (nsnull == aPrevSibling) {
|
|
|
|
aNewFrame->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aNewFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
aPrevSibling->GetNextSibling(&nextFrame);
|
1999-01-15 01:28:07 +00:00
|
|
|
aPrevSibling->SetNextSibling(aNewFrame);
|
|
|
|
aNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
aNewFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::InsertFrames(nsIFrame* aParent,
|
|
|
|
nsIFrame* aPrevSibling,
|
|
|
|
nsIFrame* aFrameList)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrameList, "null ptr");
|
|
|
|
if (nsnull != aFrameList) {
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
nsIFrame* frame = aFrameList;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frame->SetParent(aParent);
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameList tmp(aFrameList);
|
|
|
|
nsIFrame* lastNewFrame = tmp.LastChild();
|
|
|
|
if (nsnull == aPrevSibling) {
|
|
|
|
lastNewFrame->SetNextSibling(mFirstChild);
|
|
|
|
mFirstChild = aFrameList;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
aPrevSibling->GetNextSibling(&nextFrame);
|
1999-01-15 01:28:07 +00:00
|
|
|
aPrevSibling->SetNextSibling(aFrameList);
|
|
|
|
lastNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::ReplaceFrame(nsIFrame* aParent,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aOldFrame, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aNewFrame, "null ptr");
|
|
|
|
if ((nsnull != aOldFrame) && (nsnull != aNewFrame)) {
|
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
aOldFrame->GetNextSibling(&nextFrame);
|
1999-01-15 01:28:07 +00:00
|
|
|
if (aOldFrame == mFirstChild) {
|
|
|
|
mFirstChild = aNewFrame;
|
|
|
|
aNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
nsIFrame* prevSibling = GetPrevSiblingFor(aOldFrame);
|
|
|
|
if (nsnull != prevSibling) {
|
|
|
|
prevSibling->SetNextSibling(aNewFrame);
|
|
|
|
aNewFrame->SetNextSibling(nextFrame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
aNewFrame->SetParent(aParent);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::ReplaceAndDeleteFrame(nsIPresContext& aPresContext,
|
|
|
|
nsIFrame* aParent,
|
|
|
|
nsIFrame* aOldFrame,
|
|
|
|
nsIFrame* aNewFrame)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aOldFrame, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aNewFrame, "null ptr");
|
|
|
|
if (ReplaceFrame(aParent, aOldFrame, aNewFrame)) {
|
|
|
|
aNewFrame->DeleteFrame(aPresContext);
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsFrameList::Split(nsIFrame* aAfterFrame, nsIFrame** aNextFrameResult)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aAfterFrame, "null ptr");
|
|
|
|
NS_PRECONDITION(nsnull != aNextFrameResult, "null ptr");
|
|
|
|
NS_ASSERTION(ContainsFrame(aAfterFrame), "split after unknown frame");
|
|
|
|
|
1999-02-01 17:32:05 +00:00
|
|
|
if ((nsnull != aNextFrameResult) && (nsnull != aAfterFrame)) {
|
1999-01-15 01:28:07 +00:00
|
|
|
nsIFrame* nextFrame;
|
1999-02-10 06:13:38 +00:00
|
|
|
aAfterFrame->GetNextSibling(&nextFrame);
|
1999-01-15 01:28:07 +00:00
|
|
|
aAfterFrame->SetNextSibling(nsnull);
|
|
|
|
*aNextFrameResult = nextFrame;
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-02-01 17:32:05 +00:00
|
|
|
nsIFrame*
|
1999-01-15 01:28:07 +00:00
|
|
|
nsFrameList::PullFrame(nsIFrame* aParent,
|
1999-02-01 17:32:05 +00:00
|
|
|
nsIFrame* aLastChild,
|
|
|
|
nsFrameList& aFromList)
|
1999-01-15 01:28:07 +00:00
|
|
|
{
|
1999-02-01 17:32:05 +00:00
|
|
|
NS_PRECONDITION(nsnull != aParent, "null ptr");
|
|
|
|
|
|
|
|
nsIFrame* pulledFrame = nsnull;
|
|
|
|
if (nsnull != aParent) {
|
|
|
|
pulledFrame = aFromList.FirstChild();
|
1999-01-15 01:28:07 +00:00
|
|
|
if (nsnull != pulledFrame) {
|
1999-02-01 17:32:05 +00:00
|
|
|
// Take frame off old list
|
|
|
|
aFromList.RemoveFirstChild();
|
|
|
|
|
|
|
|
// Put it on the end of this list
|
|
|
|
if (nsnull == aLastChild) {
|
|
|
|
NS_ASSERTION(nsnull == mFirstChild, "bad aLastChild");
|
|
|
|
mFirstChild = pulledFrame;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
aLastChild->SetNextSibling(pulledFrame);
|
|
|
|
}
|
|
|
|
pulledFrame->SetParent(aParent);
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
}
|
1999-02-01 17:32:05 +00:00
|
|
|
return pulledFrame;
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::LastChild() const
|
|
|
|
{
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&next);
|
1999-01-15 01:28:07 +00:00
|
|
|
if (nsnull == next) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = next;
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
1999-01-15 22:53:39 +00:00
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::FrameAt(PRInt32 aIndex) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aIndex >= 0, "invalid arg");
|
|
|
|
if (aIndex < 0) return nsnull;
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while ((aIndex-- > 0) && (nsnull != frame)) {
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 22:53:39 +00:00
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
1999-01-15 01:28:07 +00:00
|
|
|
PRBool
|
1999-01-15 22:53:39 +00:00
|
|
|
nsFrameList::ContainsFrame(const nsIFrame* aFrame) const
|
1999-01-15 01:28:07 +00:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
if (frame == aFrame) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsFrameList::GetLength() const
|
|
|
|
{
|
|
|
|
PRInt32 count = 0;
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
count++;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-01-15 01:28:07 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
nsFrameList::GetPrevSiblingFor(nsIFrame* aFrame) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aFrame, "null ptr");
|
|
|
|
if (aFrame == mFirstChild) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* next;
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&next);
|
1999-01-15 01:28:07 +00:00
|
|
|
if (next == aFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
frame = next;
|
|
|
|
}
|
|
|
|
return frame;
|
|
|
|
}
|
1999-02-01 17:32:05 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::VerifyParent(nsIFrame* aParent) const
|
|
|
|
{
|
|
|
|
#ifdef NS_DEBUG
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
nsIFrame* parent;
|
1999-02-10 01:36:30 +00:00
|
|
|
frame->GetParent(&parent);
|
1999-02-01 17:32:05 +00:00
|
|
|
NS_ASSERTION(parent == aParent, "bad parent");
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-02-01 17:32:05 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
1999-02-03 19:10:26 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameList::List(FILE* out) const
|
|
|
|
{
|
|
|
|
fputs("<\n", out);
|
|
|
|
nsIFrame* frame = mFirstChild;
|
|
|
|
while (nsnull != frame) {
|
|
|
|
frame->List(out, 1);
|
1999-02-10 06:13:38 +00:00
|
|
|
frame->GetNextSibling(&frame);
|
1999-02-03 19:10:26 +00:00
|
|
|
}
|
1999-03-24 15:40:44 +00:00
|
|
|
fputs(">\n", out);
|
1999-02-03 19:10:26 +00:00
|
|
|
}
|