Back to index

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

List of all members.

Public Member Functions

 nsGeneratedSubtreeIterator ()
virtual ~nsGeneratedSubtreeIterator ()
virtual nsresult Init (nsIContent *aRoot)
virtual nsresult Init (nsIDOMRange *aRange)
virtual void Next ()
 Next will advance the list.
virtual void Prev ()
 Prev will decrement the list.
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)
virtual void First ()
 First will reset the list.
virtual void Last ()
 Last will reset the list to the end.
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.

Protected Member Functions

nsresult GetTopAncestorInRange (nsCOMPtr< nsIContent > aNode, nsCOMPtr< nsIContent > *outAnestor)
 nsGeneratedSubtreeIterator (const nsGeneratedSubtreeIterator &)
nsGeneratedSubtreeIteratoroperator= (const nsGeneratedSubtreeIterator &)
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< nsIDOMRangemRange
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

Detailed Description

Definition at line 803 of file nsGeneratedIterator.cpp.


Constructor & Destructor Documentation

Definition at line 806 of file nsGeneratedIterator.cpp.

{};

Definition at line 807 of file nsGeneratedIterator.cpp.

{};

Member Function Documentation

void nsGeneratedContentIterator::First ( ) [virtual, inherited]

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:

nsIContent * nsGeneratedContentIterator::GetNextSibling ( nsIContent aNode) [protected, inherited]

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:

nsIContent * nsGeneratedContentIterator::GetPrevSibling ( nsIContent aNode) [protected, inherited]

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:

Definition at line 1203 of file nsGeneratedIterator.cpp.

{
  if (!aNode)
    return NS_ERROR_NULL_POINTER;
  if (!outAnestor)
    return NS_ERROR_NULL_POINTER;


  // sanity check: aNode is itself in the range
  PRBool nodeBefore, nodeAfter;
  if (NS_FAILED(nsRange::CompareNodeToRange(aNode, mRange, &nodeBefore,
                                            &nodeAfter)))
    return NS_ERROR_FAILURE;

  if (nodeBefore || nodeAfter)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsIContent> parent;
  while (aNode)
  {
    parent = aNode->GetParent();
    if (!parent)
      return NS_ERROR_FAILURE;
    if (NS_FAILED(nsRange::CompareNodeToRange(parent, mRange, &nodeBefore,
                                              &nodeAfter)))
      return NS_ERROR_FAILURE;

    if (nodeBefore || nodeAfter)
    {
      *outAnestor = aNode;
      return NS_OK;
    }
    aNode = parent;
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from nsGeneratedContentIterator.

Definition at line 864 of file nsGeneratedIterator.cpp.

Here is the caller graph for this function:

Reimplemented from nsGeneratedContentIterator.

Definition at line 884 of file nsGeneratedIterator.cpp.

{
  if (!aRange)
    return NS_ERROR_NULL_POINTER;

  mIsDone = PR_FALSE;

  mRange = aRange;

  // get the start node and offset, convert to nsIContent
  nsCOMPtr<nsIDOMNode> commonParent;
  nsCOMPtr<nsIDOMNode> startParent;
  nsCOMPtr<nsIDOMNode> endParent;
  nsCOMPtr<nsIContent> cStartP;
  nsCOMPtr<nsIContent> cEndP;
  nsCOMPtr<nsIContent> cN;
  nsCOMPtr<nsIContent> firstCandidate;
  nsCOMPtr<nsIContent> lastCandidate;
  nsCOMPtr<nsIDOMNode> dChild;
  nsCOMPtr<nsIContent> cChild;
  PRInt32 indx, startIndx, endIndx;
  PRInt32 numChildren;

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

  // get start content parent
  if (NS_FAILED(aRange->GetStartContainer(getter_AddRefs(startParent))) || !startParent)
    return NS_ERROR_FAILURE;
  cStartP = do_QueryInterface(startParent);
  aRange->GetStartOffset(&startIndx);

  // get end content parent
  if (NS_FAILED(aRange->GetEndContainer(getter_AddRefs(endParent))) || !endParent)
    return NS_ERROR_FAILURE;
  cEndP = do_QueryInterface(endParent);
  aRange->GetEndOffset(&endIndx);

  // short circuit when start node == end node
  if (startParent == endParent)
  {
    cChild = cStartP->GetChildAt(0);

    if (!cChild) // no children, must be a text node or empty container
    {
      // all inside one text node - empty subtree iterator
      MakeEmpty();
      return NS_OK;
    }
    else
    {
      if (startIndx == endIndx)  // collapsed range
      {
        MakeEmpty();
        return NS_OK;
      }
    }
  }

  // find first node in range
  aRange->GetStartOffset(&indx);
  numChildren = GetNumChildren(startParent);

  if (!numChildren) // no children, must be a text node
  {
    cN = cStartP;
  }
  else
  {
    dChild = GetChildAt(startParent, indx);
    cChild = do_QueryInterface(dChild);
    if (!cChild)  // offset after last child
    {
      cN = cStartP;
    }
    else
    {
      firstCandidate = cChild;
    }
  }

  if (!firstCandidate)
  {
    // then firstCandidate is next node after cN
    firstCandidate = GetNextSibling(cN);

    if (!firstCandidate)
    {
      MakeEmpty();
      return NS_OK;
    }
  }
  if (mGenIter)
  {
    mFirstIter = mGenIter;
    mFirstIterType = mIterType;
  }
  if (!mFirstIter)
  {
    firstCandidate = GetDeepFirstChild(firstCandidate);
    if (mGenIter)
    {
      mFirstIter = mGenIter;
      mFirstIterType = mIterType;
    }
  }
  // confirm that this first possible contained node
  // is indeed contained.  Else we have a range that
  // does not fully contain any node.

  PRBool nodeBefore(PR_FALSE), nodeAfter(PR_FALSE);
  if (!mFirstIter &&
      NS_FAILED(nsRange::CompareNodeToRange(firstCandidate, aRange,
                                            &nodeBefore, &nodeAfter)))
    return NS_ERROR_FAILURE;

  if (nodeBefore || nodeAfter)
  {
    MakeEmpty();
    return NS_OK;
  }

  // cool, we have the first node in the range.  Now we walk
  // up it's ancestors to find the most senior that is still
  // in the range.  That's the real first node.
  if (NS_SUCCEEDED(GetTopAncestorInRange(firstCandidate, address_of(mFirst))))
  {
    mFirstIter = 0;//ancestor has one no
    mGenIter = 0;
  }
  else if (!mFirstIter) //something bad happened and its not generated content iterators fault
    return NS_ERROR_FAILURE;
  else
    mFirst = firstCandidate;//setting last candidate to parent of generated content this is ok



  // now to find the last node
  aRange->GetEndOffset(&indx);
  numChildren = GetNumChildren(endParent);

  if (indx > numChildren) indx = numChildren;
  if (!indx)
  {
    cN = cEndP;
  }
  else
  {
    if (!numChildren) // no children, must be a text node
    {
      cN = cEndP;
    }
    else
    {
      dChild = GetChildAt(endParent, --indx);
      cChild = do_QueryInterface(dChild);
      if (!cChild)  // shouldn't happen
      {
        NS_ASSERTION(0,"tree traversal trouble in nsGeneratedSubtreeIterator::Init");
        return NS_ERROR_FAILURE;
      }
      else
      {
        lastCandidate = cChild;
      }
    }
  }

  if (!lastCandidate)
  {
    // then lastCandidate is prev node before cN
    lastCandidate = GetPrevSibling(cN);

    if (!lastCandidate)
    {
      MakeEmpty();
      return NS_OK;
    }
  }
  if (mGenIter)
  {
    mLastIter = mGenIter;
    mLastIterType = mIterType;
  }
  if (!mLastIter)//dont ever set last candidate to a generated node!
  {
    lastCandidate = GetDeepLastChild(lastCandidate);
    if (mGenIter)
    {
      mLastIter = mGenIter;
      mLastIterType = mIterType;
    }
  }

  // confirm that this first possible contained node
  // is indeed contained.  Else we have a range that
  // does not fully contain any node.

  if (!mLastIter &&
      NS_FAILED(nsRange::CompareNodeToRange(lastCandidate, aRange, &nodeBefore,
                                            &nodeAfter)))
    return NS_ERROR_FAILURE;

  if (nodeBefore || nodeAfter)
  {
    MakeEmpty();
    return NS_OK;
  }

  // cool, we have the last node in the range.  Now we walk
  // up it's ancestors to find the most senior that is still
  // in the range.  That's the real first node.
  if (NS_SUCCEEDED(GetTopAncestorInRange(lastCandidate, address_of(mLast))))
  {
    mLastIter = 0;//ancestor has one no
    mGenIter = 0;
  }
  else if (!mLastIter) //something bad happened and its not generated content iterators fault
    return NS_ERROR_FAILURE;
  else
    mLast = lastCandidate;//setting last candidate to parent of generated content this is ok

  mCurNode = mFirst;
  mGenIter = mFirstIter;
  mIterType = mFirstIterType ;
  return NS_OK;
}

Here is the call graph for this function:

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

Reimplemented from nsGeneratedContentIterator.

Definition at line 870 of file nsGeneratedIterator.cpp.

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

Here is the call graph for this function:

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

Reimplemented from nsGeneratedContentIterator.

Definition at line 877 of file nsGeneratedIterator.cpp.

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

Here is the call graph for this function:

PRBool nsGeneratedContentIterator::IsDone ( ) [virtual, inherited]

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;
}
void nsGeneratedContentIterator::Last ( ) [virtual, inherited]

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;
}
void nsGeneratedContentIterator::MakeEmpty ( ) [protected, inherited]

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.

Reimplemented from nsGeneratedContentIterator.

Definition at line 1120 of file nsGeneratedIterator.cpp.

{
  if (mIsDone)
    return;
  nsCOMPtr<nsIContent> curnode;
  nsCOMPtr<nsIContent> nextNode;
  if (mGenIter)
  {
    if (mGenIter->IsDone())
    {
      mGenIter = 0;

      if (mIterType == nsIPresShell::After)
      {
        nextNode = GetNextSibling(mCurNode);

        if (!nextNode)
        {
          mIsDone = PR_TRUE;

          return;
        }
      }
      else
      {
        nextNode = mCurNode->GetChildAt(0);
      }
    }
    else {
       mGenIter->Next();

       return;
    }
  }
  else
  {
    if (mCurNode == mLast)
    {
      mIsDone = PR_TRUE;
      return;
    }
    nextNode = GetNextSibling(mCurNode);

    if (!nextNode)
    {
      mIsDone = PR_TRUE;

      return;
    }
  }

  if (!mGenIter)
    nextNode = GetDeepFirstChild(nextNode);
  if (NS_SUCCEEDED(GetTopAncestorInRange(nextNode, address_of(mCurNode))))
  {
    mGenIter = 0;
  }
  else if (!mGenIter) //something bad happened and its not generated content iterators fault
    return;
  else
    mCurNode = nextNode;//setting last candidate to parent of generated content this is ok
}

Here is the call graph for this function:

nsIContent * nsGeneratedContentIterator::NextNode ( nsIContent aNode) [protected, inherited]

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:

nsGeneratedSubtreeIterator& nsGeneratedSubtreeIterator::operator= ( const nsGeneratedSubtreeIterator ) [protected]

PositionAt will position the iterator to the supplied node.

Reimplemented from nsGeneratedContentIterator.

Definition at line 1192 of file nsGeneratedIterator.cpp.

{
  NS_ERROR("Not implemented!");

  return NS_ERROR_NOT_IMPLEMENTED;
}

Prev will decrement the list.

Reimplemented from nsGeneratedContentIterator.

Definition at line 1185 of file nsGeneratedIterator.cpp.

{
//notimplemented
  NS_ERROR("Not implemented!");
}
nsIContent * nsGeneratedContentIterator::PrevNode ( nsIContent aNode) [protected, inherited]

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.

Definition at line 832 of file nsGeneratedIterator.cpp.


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