Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes | Private Member Functions
nsFrameList Class Reference

A class for managing a singly linked list of frames. More...

#include <nsFrameList.h>

Collaboration diagram for nsFrameList:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsFrameList ()
 nsFrameList (nsIFrame *aHead)
 ~nsFrameList ()
void DestroyFrames (nsPresContext *aPresContext)
void SetFrames (nsIFrame *aFrameList)
void AppendFrames (nsIFrame *aParent, nsIFrame *aFrameList)
void AppendFrames (nsIFrame *aParent, nsFrameList &aFrameList)
void AppendFrame (nsIFrame *aParent, nsIFrame *aFrame)
PRBool RemoveFrame (nsIFrame *aFrame, nsIFrame *aPrevSiblingHint=nsnull)
PRBool RemoveFirstChild ()
PRBool DestroyFrame (nsPresContext *aPresContext, nsIFrame *aFrame)
void InsertFrame (nsIFrame *aParent, nsIFrame *aPrevSibling, nsIFrame *aNewFrame)
void InsertFrames (nsIFrame *aParent, nsIFrame *aPrevSibling, nsIFrame *aFrameList)
void InsertFrames (nsIFrame *aParent, nsIFrame *aPrevSibling, nsFrameList &aFrameList)
PRBool ReplaceFrame (nsIFrame *aParent, nsIFrame *aOldFrame, nsIFrame *aNewFrame, PRBool aDestroy)
PRBool Split (nsIFrame *aAfterFrame, nsIFrame **aNextFrameResult)
void SortByContentOrder ()
 Sort the frames according to content order so that the first frame in the list is the first in content order.
nsIFrameFirstChild () const
nsIFrameLastChild () const
nsIFrameFrameAt (PRInt32 aIndex) const
PRBool IsEmpty () const
PRBool NotEmpty () const
PRBool ContainsFrame (const nsIFrame *aFrame) const
PRInt32 GetLength () const
nsIFrameGetPrevSiblingFor (nsIFrame *aFrame) const
void VerifyParent (nsIFrame *aParent) const

Protected Attributes

nsIFramemFirstChild

Private Member Functions

PRBool DoReplaceFrame (nsIFrame *aParent, nsIFrame *aOldFrame, nsIFrame *aNewFrame)

Detailed Description

A class for managing a singly linked list of frames.

Frames are linked together through their next-sibling pointer.

Definition at line 46 of file nsFrameList.h.


Constructor & Destructor Documentation

Definition at line 48 of file nsFrameList.h.

nsFrameList::nsFrameList ( nsIFrame aHead) [inline]

Definition at line 52 of file nsFrameList.h.

                               {
    mFirstChild = aHead;
#ifdef DEBUG
    CheckForLoops();
#endif
  }

Definition at line 59 of file nsFrameList.h.

                 {
  }

Member Function Documentation

void nsFrameList::AppendFrame ( nsIFrame aParent,
nsIFrame aFrame 
)

Definition at line 168 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrame, "null ptr");
  if (nsnull != aFrame) {
    NS_PRECONDITION(!aFrame->GetNextSibling(), "Can only append one frame here");
    nsIFrame* lastChild = LastChild();
    if (nsnull == lastChild) {
      mFirstChild = aFrame;
    }
    else {
      lastChild->SetNextSibling(aFrame);
    }
    if (nsnull != aParent) {
      aFrame->SetParent(aParent);
    }
  }
#ifdef DEBUG
  CheckForLoops();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFrameList::AppendFrames ( nsIFrame aParent,
nsIFrame aFrameList 
)

Definition at line 144 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrameList, "null ptr");
  if (nsnull != aFrameList) {
    nsIFrame* lastChild = LastChild();
    if (nsnull == lastChild) {
      mFirstChild = aFrameList;
    }
    else {
      lastChild->SetNextSibling(aFrameList);
    }
    if (aParent) {
      for (nsIFrame* frame = aFrameList; frame;
           frame = frame->GetNextSibling()) {
        frame->SetParent(aParent);
      }
    }
  }
#ifdef DEBUG
  CheckForLoops();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFrameList::AppendFrames ( nsIFrame aParent,
nsFrameList aFrameList 
) [inline]

Definition at line 73 of file nsFrameList.h.

                                                                {
    AppendFrames(aParent, aFrameList.mFirstChild);
    aFrameList.mFirstChild = nsnull;
  }

Here is the call graph for this function:

Definition at line 399 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrame, "null ptr");
  nsIFrame* frame = mFirstChild;
  while (frame) {
    if (frame == aFrame) {
      return PR_TRUE;
    }
    frame = frame->GetNextSibling();
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsFrameList::DestroyFrame ( nsPresContext aPresContext,
nsIFrame aFrame 
)

Definition at line 229 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrame, "null ptr");
  if (RemoveFrame(aFrame)) {
    aFrame->Destroy(aPresContext);
    return PR_TRUE;
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 133 of file nsFrameList.cpp.

{
  nsIFrame* next;
  for (nsIFrame* frame = mFirstChild; frame; frame = next) {
    next = frame->GetNextSibling();
    frame->Destroy(aPresContext);
    mFirstChild = next;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsFrameList::DoReplaceFrame ( nsIFrame aParent,
nsIFrame aOldFrame,
nsIFrame aNewFrame 
) [private]

Definition at line 303 of file nsFrameList.cpp.

{
  NS_PRECONDITION(aOldFrame, "null ptr");
  NS_PRECONDITION(aNewFrame, "null ptr");
  if (!aOldFrame || !aNewFrame) {
    return PR_FALSE;
  }
  
  nsIFrame* nextFrame = aOldFrame->GetNextSibling();
  if (aOldFrame == mFirstChild) {
    mFirstChild = aNewFrame;
  }
  else {
    nsIFrame* prevSibling = GetPrevSiblingFor(aOldFrame);
    if (!prevSibling) {
      NS_WARNING("nsFrameList::ReplaceFrame: aOldFrame not found in list");
      return PR_FALSE;
    }
    prevSibling->SetNextSibling(aNewFrame);
  }

  aNewFrame->SetNextSibling(nextFrame);
  
  if (aParent) {
    aNewFrame->SetParent(aParent);
  }
#ifdef DEBUG
  CheckForLoops();
#endif
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsIFrame* nsFrameList::FirstChild ( ) const [inline]

Definition at line 126 of file nsFrameList.h.

                               {
    return mFirstChild;
  }
nsIFrame * nsFrameList::FrameAt ( PRInt32  aIndex) const

Definition at line 387 of file nsFrameList.cpp.

{
  NS_PRECONDITION(aIndex >= 0, "invalid arg");
  if (aIndex < 0) return nsnull;
  nsIFrame* frame = mFirstChild;
  while ((aIndex-- > 0) && frame) {
    frame = frame->GetNextSibling();
  }
  return frame;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 413 of file nsFrameList.cpp.

{
  PRInt32 count = 0;
  nsIFrame* frame = mFirstChild;
  while (frame) {
    count++;
    frame = frame->GetNextSibling();
  }
  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 477 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrame, "null ptr");
  if (aFrame == mFirstChild) {
    return nsnull;
  }
  nsIFrame* frame = mFirstChild;
  while (frame) {
    nsIFrame* next = frame->GetNextSibling();
    if (next == aFrame) {
      break;
    }
    frame = next;
  }
  return frame;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFrameList::InsertFrame ( nsIFrame aParent,
nsIFrame aPrevSibling,
nsIFrame aNewFrame 
)

Definition at line 240 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aNewFrame, "null ptr");
  if (nsnull != aNewFrame) {
    if (nsnull == aPrevSibling) {
      aNewFrame->SetNextSibling(mFirstChild);
      mFirstChild = aNewFrame;
    }
    else {
      nsIFrame* nextFrame = aPrevSibling->GetNextSibling();
      aPrevSibling->SetNextSibling(aNewFrame);
      aNewFrame->SetNextSibling(nextFrame);
    }
    if (aParent) {
      aNewFrame->SetParent(aParent);
    }
  }
#ifdef DEBUG
  CheckForLoops();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFrameList::InsertFrames ( nsIFrame aParent,
nsIFrame aPrevSibling,
nsIFrame aFrameList 
)

Definition at line 265 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrameList, "null ptr");
  if (nsnull != aFrameList) {
    nsIFrame* lastNewFrame = nsnull;
    if (aParent) {
      for (nsIFrame* frame = aFrameList; frame;
           frame = frame->GetNextSibling()) {
        frame->SetParent(aParent);
        lastNewFrame = frame;
      }
    }

    // Get the last new frame if necessary
    if (!lastNewFrame) {
      nsFrameList tmp(aFrameList);
      lastNewFrame = tmp.LastChild();
    }

    // Link the new frames into the child list
    if (nsnull == aPrevSibling) {
      lastNewFrame->SetNextSibling(mFirstChild);
      mFirstChild = aFrameList;
    }
    else {
      nsIFrame* nextFrame = aPrevSibling->GetNextSibling();
      aPrevSibling->SetNextSibling(aFrameList);
      lastNewFrame->SetNextSibling(nextFrame);
    }
  }
#ifdef DEBUG
  CheckForLoops();
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFrameList::InsertFrames ( nsIFrame aParent,
nsIFrame aPrevSibling,
nsFrameList aFrameList 
) [inline]

Definition at line 105 of file nsFrameList.h.

                                             {
    InsertFrames(aParent, aPrevSibling, aFrameList.FirstChild());
    aFrameList.mFirstChild = nsnull;
  }

Here is the call graph for this function:

PRBool nsFrameList::IsEmpty ( void  ) const [inline]

Definition at line 134 of file nsFrameList.h.

                         {
    return nsnull == mFirstChild;
  }

Here is the caller graph for this function:

Definition at line 371 of file nsFrameList.cpp.

{
  nsIFrame* frame = mFirstChild;
  if (!frame) {
    return nsnull;
  }

  nsIFrame* next = frame->GetNextSibling();
  while (next) {
    frame = next;
    next = frame->GetNextSibling();
  }
  return frame;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsFrameList::NotEmpty ( ) const [inline]

Definition at line 138 of file nsFrameList.h.

                          {
    return nsnull != mFirstChild;
  }

Here is the caller graph for this function:

Definition at line 217 of file nsFrameList.cpp.

{
  if (mFirstChild) {
    nsIFrame* nextFrame = mFirstChild->GetNextSibling();
    mFirstChild->SetNextSibling(nsnull);
    mFirstChild = nextFrame;
    return PR_TRUE;
  }
  return PR_FALSE;
}

Here is the call graph for this function:

PRBool nsFrameList::RemoveFrame ( nsIFrame aFrame,
nsIFrame aPrevSiblingHint = nsnull 
)

Definition at line 190 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aFrame, "null ptr");
  if (aFrame) {
    nsIFrame* nextFrame = aFrame->GetNextSibling();
    if (aFrame == mFirstChild) {
      mFirstChild = nextFrame;
      aFrame->SetNextSibling(nsnull);
      return PR_TRUE;
    }
    else {
      nsIFrame* prevSibling = aPrevSiblingHint;
      if (!prevSibling || prevSibling->GetNextSibling() != aFrame) {
        prevSibling = GetPrevSiblingFor(aFrame);
      }
      if (prevSibling) {
        prevSibling->SetNextSibling(nextFrame);
        aFrame->SetNextSibling(nsnull);
        return PR_TRUE;
      }
    }
  }
  // aFrame was not in the list. 
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsFrameList::ReplaceFrame ( nsIFrame aParent,
nsIFrame aOldFrame,
nsIFrame aNewFrame,
PRBool  aDestroy 
)

Definition at line 338 of file nsFrameList.cpp.

{
  NS_PRECONDITION(aOldFrame, "null ptr");
  NS_PRECONDITION(aNewFrame, "null ptr");
  if (DoReplaceFrame(aParent, aOldFrame, aNewFrame)) {
    if (aDestroy) {
      aOldFrame->Destroy(aOldFrame->GetPresContext());
    }
    return PR_TRUE;
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFrameList::SetFrames ( nsIFrame aFrameList) [inline]

Definition at line 64 of file nsFrameList.h.

                                       {
    mFirstChild = aFrameList;
#ifdef DEBUG
    CheckForLoops();
#endif
  }

Here is the caller graph for this function:

Sort the frames according to content order so that the first frame in the list is the first in content order.

Frames for the same content will be ordered so that a prev in flow comes before its next in flow.

Definition at line 456 of file nsFrameList.cpp.

{
  if (!mFirstChild)
    return;

  nsAutoVoidArray array;
  nsIFrame* f;
  for (f = mFirstChild; f; f = f->GetNextSibling()) {
    array.AppendElement(f);
  }
  array.Sort(CompareByContentOrder, nsnull);
  f = mFirstChild = NS_STATIC_CAST(nsIFrame*, array.FastElementAt(0));
  for (PRInt32 i = 1; i < array.Count(); ++i) {
    nsIFrame* ff = NS_STATIC_CAST(nsIFrame*, array.FastElementAt(i));
    f->SetNextSibling(ff);
    f = ff;
  }
  f->SetNextSibling(nsnull);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsFrameList::Split ( nsIFrame aAfterFrame,
nsIFrame **  aNextFrameResult 
)

Definition at line 355 of file nsFrameList.cpp.

{
  NS_PRECONDITION(nsnull != aAfterFrame, "null ptr");
  NS_PRECONDITION(nsnull != aNextFrameResult, "null ptr");
  NS_ASSERTION(ContainsFrame(aAfterFrame), "split after unknown frame");

  if (aNextFrameResult && aAfterFrame) {
    nsIFrame* nextFrame = aAfterFrame->GetNextSibling();
    aAfterFrame->SetNextSibling(nsnull);
    *aNextFrameResult = nextFrame;
    return PR_TRUE;
  }
  return PR_FALSE;
}

Here is the call graph for this function:

void nsFrameList::VerifyParent ( nsIFrame aParent) const

Definition at line 495 of file nsFrameList.cpp.

{
#ifdef NS_DEBUG
  for (nsIFrame* frame = mFirstChild; frame;
       frame = frame->GetNextSibling()) {
    NS_ASSERTION(frame->GetParent() == aParent, "bad parent");
  }
#endif
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 176 of file nsFrameList.h.


The documentation for this class was generated from the following files: