Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Attributes
ChildIterator Class Reference

Helper class for iterating children during frame construction. More...

#include <nsChildIterator.h>

Collaboration diagram for ChildIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ChildIterator ()
 ChildIterator (const ChildIterator &aOther)
ChildIteratoroperator= (const ChildIterator &aOther)
ChildIteratoroperator++ ()
ChildIterator operator++ (int)
ChildIteratoroperator-- ()
ChildIterator operator-- (int)
already_AddRefed< nsIContentget () const
already_AddRefed< nsIContentoperator* () const
PRBool operator== (const ChildIterator &aOther) const
PRBool operator!= (const ChildIterator &aOther) const
PRUint32 index ()
void seek (PRUint32 aIndex)

Static Public Member Functions

static nsresult Init (nsIContent *aContent, ChildIterator *aFirst, ChildIterator *aLast)
 Create a pair of ChildIterators for a content node.

Protected Attributes

nsCOMPtr< nsIContentmContent
PRUint32 mIndex
nsCOMPtr< nsIDOMNodeListmNodes

Detailed Description

Helper class for iterating children during frame construction.

This class should always be used in lieu of the straight content node APIs, since it handles XBL-generated anonymous content as well.

Definition at line 50 of file nsChildIterator.h.


Constructor & Destructor Documentation

Definition at line 58 of file nsChildIterator.h.

    : mIndex(0) {}

Definition at line 61 of file nsChildIterator.h.

    : mContent(aOther.mContent),
      mIndex(aOther.mIndex),
      mNodes(aOther.mNodes) {}

Member Function Documentation

Definition at line 95 of file nsChildIterator.h.

                                           {
    nsIContent* result = nsnull;
    if (mNodes) {
      nsCOMPtr<nsIDOMNode> node;
      mNodes->Item(mIndex, getter_AddRefs(node));
      CallQueryInterface(node, &result);
    } else {
      result = mContent->GetChildAt(PRInt32(mIndex));
      NS_IF_ADDREF(result);
    }

    return result;
  }

Here is the call graph for this function:

Definition at line 119 of file nsChildIterator.h.

                   {
    return mIndex;
  }
nsresult ChildIterator::Init ( nsIContent aContent,
ChildIterator aFirst,
ChildIterator aLast 
) [static]

Create a pair of ChildIterators for a content node.

aFirst will point to the first child of aContent; aLast will point one past the last child of aContent.

Definition at line 44 of file nsChildIterator.cpp.

{
  // Initialize out parameters to be equal, in case of failure.
  aFirst->mContent = aLast->mContent = nsnull;
  aFirst->mIndex   = aLast->mIndex   = 0;
  
  NS_PRECONDITION(aContent != nsnull, "no content");
  if (! aContent)
    return NS_ERROR_NULL_POINTER;

  nsCOMPtr<nsIDocument> doc = aContent->GetDocument();
  NS_ASSERTION(doc, "element not in the document");
  if (! doc)
    return NS_ERROR_FAILURE;

  // If this node has XBL children, then use them. Otherwise, just use
  // the vanilla content APIs.
  nsCOMPtr<nsIDOMNodeList> nodes;
  doc->BindingManager()->GetXBLChildNodesFor(aContent, getter_AddRefs(nodes));

  PRUint32 length;
  if (nodes)
    nodes->GetLength(&length);
  else
    length = aContent->GetChildCount();

  aFirst->mContent = aContent;
  aLast->mContent  = aContent;
  aFirst->mIndex   = 0;
  aLast->mIndex    = length;
  aFirst->mNodes   = nodes;
  aLast->mNodes    = nodes;

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool ChildIterator::operator!= ( const ChildIterator aOther) const [inline]

Definition at line 115 of file nsChildIterator.h.

                                                       {
    return !aOther.operator==(*this);
  }
already_AddRefed<nsIContent> ChildIterator::operator* ( ) const [inline]

Definition at line 109 of file nsChildIterator.h.

{ return get(); }
ChildIterator& ChildIterator::operator++ ( ) [inline]

Definition at line 73 of file nsChildIterator.h.

                              {
    ++mIndex;
    return *this;
  }
ChildIterator ChildIterator::operator++ ( int  ) [inline]

Definition at line 78 of file nsChildIterator.h.

                                {
    ChildIterator result(*this);
    ++mIndex;
    return result;
  }
ChildIterator& ChildIterator::operator-- ( ) [inline]

Definition at line 84 of file nsChildIterator.h.

                              {
    --mIndex;
    return *this;
  }
ChildIterator ChildIterator::operator-- ( int  ) [inline]

Definition at line 89 of file nsChildIterator.h.

                                {
    ChildIterator result(*this);
    --mIndex;
    return result;
  }
ChildIterator& ChildIterator::operator= ( const ChildIterator aOther) [inline]

Definition at line 66 of file nsChildIterator.h.

                                                        {
    mContent = aOther.mContent;
    mIndex = aOther.mIndex;
    mNodes = aOther.mNodes;
    return *this;
  }
PRBool ChildIterator::operator== ( const ChildIterator aOther) const [inline]

Definition at line 111 of file nsChildIterator.h.

                                                       {
    return mContent == aOther.mContent && mIndex == aOther.mIndex;
  }
void ChildIterator::seek ( PRUint32  aIndex) [inline]

Definition at line 123 of file nsChildIterator.h.

                             {
    // Make sure that aIndex is reasonable.  This should be |#ifdef
    // DEBUG|, but we need these numbers for the temporary workaround
    // for bug 133219.
    PRUint32 length;
    if (mNodes)
      mNodes->GetLength(&length);
    else
      length = mContent->GetChildCount();

    NS_ASSERTION(PRInt32(aIndex) >= 0 && aIndex <= length, "out of bounds");

    // Temporary workaround for bug 133219.
    if (aIndex > length)
      aIndex = length;

    mIndex = aIndex;
  }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 53 of file nsChildIterator.h.

Definition at line 54 of file nsChildIterator.h.

Definition at line 55 of file nsChildIterator.h.


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