Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
nsGeneratedContentIterator Class Reference
Inheritance diagram for nsGeneratedContentIterator:
Inheritance graph
[legend]
Collaboration diagram for nsGeneratedContentIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsGeneratedContentIterator ()
virtual ~nsGeneratedContentIterator ()
virtual nsresult Init (nsIContent *aRoot)
virtual nsresult Init (nsIDOMRange *aRange)
virtual void First ()
 First will reset the list.
virtual void Last ()
 Last will reset the list to the end.
virtual void Next ()
 Next will advance the list.
virtual void Prev ()
 Prev will decrement the list.
virtual nsIContentGetCurrentNode ()
 CurrentItem will return the current item, or null if the list is empty.
virtual PRBool IsDone ()
 return if the collection is at the end.
virtual nsresult PositionAt (nsIContent *aCurNode)
 PositionAt will position the iterator to the supplied node.
virtual nsresult Init (nsIPresShell *aShell, nsIDOMRange *aRange)
virtual nsresult Init (nsIPresShell *aShell, nsIContent *aContent)

Protected Member Functions

nsCOMPtr< nsIContentGetDeepFirstChild (nsCOMPtr< nsIContent > aRoot)
nsCOMPtr< nsIContentGetDeepLastChild (nsCOMPtr< nsIContent > aRoot)
nsIContentGetNextSibling (nsIContent *aNode)
nsIContentGetPrevSibling (nsIContent *aNode)
nsIContentNextNode (nsIContent *aNode)
nsIContentPrevNode (nsIContent *aNode)
void MakeEmpty ()

Protected Attributes

nsCOMPtr< nsIContentmCurNode
nsCOMPtr< nsIContentmFirst
nsCOMPtr< nsIContentmLast
nsCOMPtr< nsIContentmCommonParent
nsCOMPtr< nsIContentIteratormFirstIter
nsCOMPtr< nsIContentIteratormLastIter
nsCOMPtr< nsIContentIteratormGenIter
nsIPresShell::GeneratedContentType mIterType
nsIPresShell::GeneratedContentType mFirstIterType
nsIPresShell::GeneratedContentType mLastIterType
nsCOMPtr< nsIPresShellmPresShell
PRBool mIsDone

Private Member Functions

 nsGeneratedContentIterator (const nsGeneratedContentIterator &)
nsGeneratedContentIteratoroperator= (const nsGeneratedContentIterator &)

Detailed Description

Definition at line 109 of file nsGeneratedIterator.cpp.


Constructor & Destructor Documentation

Definition at line 219 of file nsGeneratedIterator.cpp.

{
}

Member Function Documentation

First will reset the list.

Implements nsIContentIterator.

Definition at line 687 of file nsGeneratedIterator.cpp.

{
  if (!mFirst) {
    mIsDone = PR_TRUE;

    return;
  }

  mIsDone = PR_FALSE;

  mCurNode = mFirst;
  mGenIter = mFirstIter;
  if (mGenIter)//set directionback to before...
    mGenIter->First();
}

CurrentItem will return the current item, or null if the list is empty.

Returns:
the current node

Implements nsIContentIterator.

Definition at line 773 of file nsGeneratedIterator.cpp.

{
  if (!mCurNode || mIsDone) {
    return nsnull;
  }

  if (mGenIter) {
    return mGenIter->GetCurrentNode();
  }

  NS_ASSERTION(mCurNode, "Null current node in an iterator that's not done!");

  return mCurNode;
}

Here is the caller graph for this function:

Definition at line 410 of file nsGeneratedIterator.cpp.

{
  nsCOMPtr<nsIContent> deepFirstChild;

  if (aRoot)
  {
    nsCOMPtr<nsIContent> cN = aRoot;

#if DO_BEFORE
    //CHECK FOR BEFORESTUFF
    nsresult result = NS_ERROR_FAILURE;
    if (mPresShell)
      result = mPresShell->GetGeneratedContentIterator(cN,nsIPresShell::Before,getter_AddRefs(mGenIter));
    if (NS_SUCCEEDED(result) && mGenIter)
    { //ok we have a generated iter all bets are off
      mIterType = nsIPresShell::Before;
      mGenIter->First();
      return cN;
    }
#endif

    nsIContent *cChild;
    while ((cChild = cN->GetChildAt(0)))
    {
      cN = cChild;

#if DO_BEFORE
      //CHECK FOR BEFORESTUFF
      if (mPresShell)
        result = mPresShell->GetGeneratedContentIterator(cN,nsIPresShell::Before,getter_AddRefs(mGenIter));
      if (NS_SUCCEEDED(result) && mGenIter)
      { //ok we have a generated iter all bets are off
        mIterType = nsIPresShell::Before;
        mGenIter->First();
        return cN;
      }
#endif
    }

    deepFirstChild = cN;
  }

  return deepFirstChild;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 455 of file nsGeneratedIterator.cpp.

{
  nsCOMPtr<nsIContent> deepFirstChild;

  if (aRoot)
  {
    nsCOMPtr<nsIContent> cN = aRoot;
    nsCOMPtr<nsIContent> cChild;

#if DO_AFTER
    //CHECK FOR AFTER STUFF
    nsresult result = NS_ERROR_FAILURE;
    if (mPresShell)
      result = mPresShell->GetGeneratedContentIterator(cN,nsIPresShell::After,getter_AddRefs(mGenIter));
    if (NS_SUCCEEDED(result) && mGenIter)
    { //ok we have a generated iter all bets are off
      mIterType = nsIPresShell::After;
      mGenIter->First();
      return cN;
    }
#endif

    PRUint32 numChildren = cN->GetChildCount();

    while ( numChildren )
    {
      cChild = cN->GetChildAt(--numChildren);
      if (cChild)
      {
#if DO_AFTER
        //CHECK FOR AFTER STUFF
        if (mPresShell)
          result = mPresShell->GetGeneratedContentIterator(cChild,nsIPresShell::After,getter_AddRefs(mGenIter));
        if (NS_SUCCEEDED(result) && mGenIter)
        { //ok we have a generated iter all bets are off
          mGenIter->Last();
          mIterType = nsIPresShell::After;
          return cChild;
        }
#endif
        numChildren = cChild->GetChildCount();
        cN = cChild;
      }
      else
      {
        break;
      }
    }
    deepFirstChild = cN;
  }

  return deepFirstChild;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 511 of file nsGeneratedIterator.cpp.

{
  if (!aNode)
    return nsnull;

  nsIContent *parent = aNode->GetParent();
  if (!parent)
    return nsnull;

  PRInt32 indx = parent->IndexOf(aNode);

  nsIContent *sib = parent->GetChildAt(++indx);

  if (!sib)
  {
#if DO_AFTER
    //CHECK FOR AFTERESTUFF
    if (mPresShell)
      mPresShell->GetGeneratedContentIterator(parent, nsIPresShell::After,
                                              getter_AddRefs(mGenIter));
    if (mGenIter)
    { //ok we have a generated iter all bets are off
      mGenIter->First();
      mIterType = nsIPresShell::After;

      return parent;
    }
#endif
    if (parent != mCommonParent)
    {
      return GetNextSibling(parent);
    }
    else
    {
      sib = nsnull;
    }
  }

  return sib;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 554 of file nsGeneratedIterator.cpp.

{
  if (!aNode)
    return nsnull;

  nsIContent *parent = aNode->GetParent();
  if (!parent)
    return nsnull;

  PRInt32 indx = parent->IndexOf(aNode);
  nsIContent *sib = nsnull;

  if (indx < 1 || !(sib = parent->GetChildAt(--indx)))
  {
#if DO_BEFORE
    //CHECK FOR BEFORESTUFF
    if (mPresShell)
      mPresShell->GetGeneratedContentIterator(parent, nsIPresShell::Before,
                                              getter_AddRefs(mGenIter));
    if (mGenIter)
    { //ok we have a generated iter all bets are off
      mGenIter->Last();
      mIterType = nsIPresShell::Before;
      return parent;
    }
    else
#endif
    if (parent != mCommonParent)
    {
      return GetPrevSibling(parent);
    }
    else
    {
      sib = nsnull;
    }
  }

  return sib;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 230 of file nsGeneratedIterator.cpp.

{
  if (!aRoot)
    return NS_ERROR_NULL_POINTER;
  mIsDone = PR_FALSE;
  nsCOMPtr<nsIContent> root(aRoot);
  mFirst = GetDeepFirstChild(root);
  if (mGenIter)//we have generated
  {
    mFirstIter = mGenIter;
    mFirstIterType = mIterType;
  }
  mLast = root;
  mCommonParent = root;
  mCurNode = mFirst;
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Implements nsIContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 264 of file nsGeneratedIterator.cpp.

{
  if (!aRange)
    return NS_ERROR_NULL_POINTER;

  nsCOMPtr<nsIDOMNode> dN;

  nsCOMPtr<nsIContent> startCon;
  nsCOMPtr<nsIDOMNode> startDOM;
  nsCOMPtr<nsIContent> endCon;
  nsCOMPtr<nsIDOMNode> endDOM;
  PRInt32 startIndx;
  PRInt32 endIndx;

  mIsDone = PR_FALSE;

  // get common content parent
  if (NS_FAILED(aRange->GetCommonAncestorContainer(getter_AddRefs(dN))) || !dN)
    return NS_ERROR_FAILURE;
  mCommonParent = do_QueryInterface(dN);

  // get the start node and offset, convert to nsIContent
  aRange->GetStartContainer(getter_AddRefs(startDOM));
  if (!startDOM)
    return NS_ERROR_ILLEGAL_VALUE;
  startCon = do_QueryInterface(startDOM);
  if (!startCon)
    return NS_ERROR_FAILURE;

  aRange->GetStartOffset(&startIndx);

  // get the end node and offset, convert to nsIContent
  aRange->GetEndContainer(getter_AddRefs(endDOM));
  if (!endDOM)
    return NS_ERROR_ILLEGAL_VALUE;
  endCon = do_QueryInterface(endDOM);
  if (!endCon)
    return NS_ERROR_FAILURE;

  aRange->GetEndOffset(&endIndx);

  // find first node in range
  nsIContent *cChild = startCon->GetChildAt(0);

  // short circuit when start node == end node
  if (startDOM == endDOM)
  {
    if (!cChild) // no children, must be a text node or empty container
    {
      mFirst = startCon;
      mLast = startCon;
      mCurNode = startCon;
      return NS_OK;
    }
    else
    {
      if (startIndx == endIndx)  // collapsed range
      {
        MakeEmpty();
        return NS_OK;
      }
    }
  }

  if (!cChild) // no children, must be a text node
  {
    mFirst = startCon;
  }
  else
  {
    cChild = startCon->GetChildAt(startIndx);
    if (!cChild)  // offset after last child, parent is first node
    {
      mFirst = startCon;
    }
    else
    {
      mFirst = GetDeepFirstChild(cChild);
      if (mGenIter)
      {
        mFirstIter = mGenIter;
        mFirstIterType = mIterType;
      }
    }
    // Does that first node really intersect the range?
    // the range could be collapsed, or the range could be
    // 'degenerate', ie not collapsed but still containing
    // no content.  In this case, we want the iterator to
    // be empty

    if (!nsRange::IsNodeIntersectsRange(mFirst, aRange))
    {
      MakeEmpty();
      return NS_OK;
    }
  }

  // find last node in range
  cChild = endCon->GetChildAt(0);

  if (!cChild) // no children, must be a text node
  {
    mLast = endCon;
  }
  else if (endIndx == 0) // before first child, parent is last node
  {
    mLast = endCon;
  }
  else
  {
    cChild = endCon->GetChildAt(--endIndx);
    if (!cChild)  // offset after last child, last child is last node
    {
      endIndx = (PRInt32)endCon->GetChildCount();
      cChild = endCon->GetChildAt(--endIndx);
      if (!cChild)
      {
        NS_NOTREACHED("nsGeneratedContentIterator::nsGeneratedContentIterator");
        return NS_ERROR_FAILURE;
      }
    }
    mLast = cChild;
  }

  mCurNode = mFirst;
  return NS_OK;
}

Here is the call graph for this function:

nsresult nsGeneratedContentIterator::Init ( nsIPresShell aShell,
nsIDOMRange aRange 
) [virtual]

Implements nsIGeneratedContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 249 of file nsGeneratedIterator.cpp.

{
  mPresShell = aShell;
  return Init(aRange);
}

Here is the call graph for this function:

nsresult nsGeneratedContentIterator::Init ( nsIPresShell aShell,
nsIContent aContent 
) [virtual]

Implements nsIGeneratedContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 256 of file nsGeneratedIterator.cpp.

{
  mPresShell = aShell;
  return Init(aContent);
}

Here is the call graph for this function:

return if the collection is at the end.

that is the beginning following a call to Prev and it is the end of the list following a call to next

Returns:
if the iterator is done.

Implements nsIContentIterator.

Definition at line 754 of file nsGeneratedIterator.cpp.

{
  return mIsDone;
}

Last will reset the list to the end.

Implements nsIContentIterator.

Definition at line 705 of file nsGeneratedIterator.cpp.

{
  if (!mLast) {
    mIsDone = PR_TRUE;

    return;
  }

  mIsDone = PR_FALSE;

  mGenIter = mLastIter;
  mCurNode = mLast;
}

Definition at line 397 of file nsGeneratedIterator.cpp.

{
  nsCOMPtr<nsIContent> noNode;
  mCurNode = noNode;
  mFirst = noNode;
  mLast = noNode;
  mCommonParent = noNode;
  mIsDone = PR_TRUE;
  mGenIter = 0;
  mFirstIter = 0;
  mIterType = nsIPresShell::Before;
}

Here is the caller graph for this function:

Next will advance the list.

Implements nsIContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 721 of file nsGeneratedIterator.cpp.

{
  if (mIsDone || !mCurNode)
    return;

  if (GetCurrentNode() == mLast)
  {
    mIsDone = PR_TRUE;
    return;
  }

  mCurNode = NextNode(mCurNode);
}

Here is the call graph for this function:

Definition at line 595 of file nsGeneratedIterator.cpp.

{
  if (!aNode)
    return nsnull;

  if (mGenIter)
  {
    if (mGenIter->IsDone())
      mGenIter = 0;
    else {
      mGenIter->Next();

      return nsnull;
    }

    if (nsIPresShell::After == mIterType)//answer is parent
    {
      //*ioNextNode = parent; leave it the same
      return nsnull;
    }
    nsIContent *cN = aNode->GetChildAt(0);
    if (cN)
    {
      return GetDeepFirstChild(cN);
    }
  }

  nsIContent *cN = aNode;

    // get next sibling if there is one
  nsIContent *parent = cN->GetParent();
  if (!parent)
  {
    // a little noise to catch some iterator usage bugs.
    NS_NOTREACHED("nsGeneratedContentIterator::NextNode() : no parent found");
    return nsnull;
  }

  PRInt32 indx = parent->IndexOf(cN);

  nsIContent *cSibling = parent->GetChildAt(++indx);
  if (cSibling)
  {
    // next node is siblings "deep left" child
    return GetDeepFirstChild(cSibling);
  }

  //CHECK FOR AFTERSTUFF
  if (mGenIter)//we allready had an afteriter. it must be done!
  {
    mGenIter = 0;
  }
  else//check for after node.
  {
    if (mPresShell)
      mPresShell->GetGeneratedContentIterator(parent, nsIPresShell::After,
                                              getter_AddRefs(mGenIter));
    if (mGenIter)
    { //ok we have a generated iter all bets are off
      mGenIter->First();
      mIterType = nsIPresShell::After;
    }
    else
      mGenIter = 0;
  }

  // else it's the parent
  return parent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsGeneratedContentIterator& nsGeneratedContentIterator::operator= ( const nsGeneratedContentIterator ) [private]

PositionAt will position the iterator to the supplied node.

Implements nsIContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 761 of file nsGeneratedIterator.cpp.

{
  // XXX need to confirm that aCurNode is within range
  if (!aCurNode)
    return NS_ERROR_NULL_POINTER;
  mCurNode = aCurNode;
  mIsDone = PR_FALSE;
  return NS_OK;
}

Prev will decrement the list.

Implements nsIContentIterator.

Reimplemented in nsGeneratedSubtreeIterator.

Definition at line 737 of file nsGeneratedIterator.cpp.

{
  if (mIsDone)
    return;
  if (!mCurNode)
    return;
  if (mCurNode == mFirst)
  {
    mIsDone = PR_TRUE;
    return;
  }

  mCurNode = PrevNode(mCurNode);
}

Here is the call graph for this function:

Definition at line 668 of file nsGeneratedIterator.cpp.

{
  PRUint32 numChildren = aNode->GetChildCount();

  // if it has children then prev node is last child
  if (numChildren > 0)
  {
    return aNode->GetChildAt(--numChildren);
  }

  // else prev sibling is previous
  return GetPrevSibling(aNode);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 163 of file nsGeneratedIterator.cpp.

Definition at line 160 of file nsGeneratedIterator.cpp.

Definition at line 161 of file nsGeneratedIterator.cpp.

Definition at line 165 of file nsGeneratedIterator.cpp.

Definition at line 169 of file nsGeneratedIterator.cpp.

Definition at line 167 of file nsGeneratedIterator.cpp.

Definition at line 172 of file nsGeneratedIterator.cpp.

Definition at line 168 of file nsGeneratedIterator.cpp.

Definition at line 162 of file nsGeneratedIterator.cpp.

Definition at line 166 of file nsGeneratedIterator.cpp.

Definition at line 170 of file nsGeneratedIterator.cpp.

Definition at line 171 of file nsGeneratedIterator.cpp.


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