Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes
nsFilteredContentIterator Class Reference

#include <nsFilteredContentIterator.h>

Inheritance diagram for nsFilteredContentIterator:
Inheritance graph
[legend]
Collaboration diagram for nsFilteredContentIterator:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsFilteredContentIterator (nsITextServicesFilter *aFilter)
virtual ~nsFilteredContentIterator ()
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.
PRPackedBool DidSkip ()
void ClearDidSkip ()

Protected Types

enum  eDirectionType { eDirNotSet, eForward, eBackward }

Protected Member Functions

 nsFilteredContentIterator ()
nsresult AdvanceNode (nsIDOMNode *aNode, nsIDOMNode *&aNewNode, eDirectionType aDir)
void CheckAdvNode (nsIDOMNode *aNode, PRPackedBool &aDidSkip, eDirectionType aDir)
nsresult SwitchDirections (PRPackedBool aChangeToForward)

Protected Attributes

nsCOMPtr< nsIContentIteratormCurrentIterator
nsCOMPtr< nsIContentIteratormIterator
nsCOMPtr< nsIContentIteratormPreIterator
nsCOMPtr< nsIAtommBlockQuoteAtom
nsCOMPtr< nsIAtommScriptAtom
nsCOMPtr< nsIAtommTextAreaAtom
nsCOMPtr< nsIAtommSelectAreaAtom
nsCOMPtr< nsIAtommMapAtom
nsCOMPtr< nsITextServicesFiltermFilter
nsCOMPtr< nsIDOMNSRangemRange
PRPackedBool mDidSkip
PRPackedBool mIsOutOfRange
eDirectionType mDirection

Detailed Description

Definition at line 51 of file nsFilteredContentIterator.h.


Member Enumeration Documentation

Enumerator:
eDirNotSet 
eForward 
eBackward 

Definition at line 81 of file nsFilteredContentIterator.h.


Constructor & Destructor Documentation

Definition at line 51 of file nsFilteredContentIterator.cpp.

                                                                                   :
  mFilter(aFilter),
  mDidSkip(PR_FALSE),
  mIsOutOfRange(PR_FALSE),
  mDirection(eDirNotSet)
{
  mIterator = do_CreateInstance("@mozilla.org/content/post-content-iterator;1");
  mPreIterator = do_CreateInstance("@mozilla.org/content/pre-content-iterator;1");
}

Here is the call graph for this function:

Definition at line 62 of file nsFilteredContentIterator.cpp.

{
}

Definition at line 78 of file nsFilteredContentIterator.h.

{ }

Member Function Documentation

nsresult nsFilteredContentIterator::AdvanceNode ( nsIDOMNode aNode,
nsIDOMNode *&  aNewNode,
eDirectionType  aDir 
) [protected]

Definition at line 284 of file nsFilteredContentIterator.cpp.

{
  nsCOMPtr<nsIDOMNode> nextNode;
  if (aDir == eForward) {
    aNode->GetNextSibling(getter_AddRefs(nextNode));
  } else {
    aNode->GetPreviousSibling(getter_AddRefs(nextNode));
  }

  if (nextNode) {
    // If we got here, that means we found the nxt/prv node
    // make sure it is in our DOMRange
    PRBool intersects = ContentIsInTraversalRange(mRange, nextNode, aDir == eForward);
    if (intersects) {
      aNewNode = nextNode;
      NS_ADDREF(aNewNode);
      return NS_OK;
    }
  } else {
    // The next node was null so we need to walk up the parent(s)
    nsCOMPtr<nsIDOMNode> parent;
    aNode->GetParentNode(getter_AddRefs(parent));
    NS_ASSERTION(parent, "parent can't be NULL");

    // Make sure the parent is in the DOMRange before going further
    PRBool intersects = ContentIsInTraversalRange(mRange, nextNode, aDir == eForward);
    if (intersects) {
      // Now find the nxt/prv node after/before this node
      nsresult rv = AdvanceNode(parent, aNewNode, aDir);
      if (NS_SUCCEEDED(rv) && aNewNode) {
        return NS_OK;
      }
    }
  }

  // if we get here it pretty much means 
  // we went out of the DOM Range
  mIsOutOfRange = PR_TRUE;

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsFilteredContentIterator::CheckAdvNode ( nsIDOMNode aNode,
PRPackedBool aDidSkip,
eDirectionType  aDir 
) [protected]

Definition at line 329 of file nsFilteredContentIterator.cpp.

{
  aDidSkip      = PR_FALSE;
  mIsOutOfRange = PR_FALSE;

  if (aNode && mFilter) {
    nsCOMPtr<nsIDOMNode> currentNode = aNode;
    PRBool skipIt;
    while (1) {
      nsresult rv = mFilter->Skip(aNode, &skipIt);
      if (NS_SUCCEEDED(rv) && skipIt) {
        aDidSkip = PR_TRUE;
        // Get the next/prev node and then 
        // see if we should skip that
        nsCOMPtr<nsIDOMNode> advNode;
        rv = AdvanceNode(aNode, *getter_AddRefs(advNode), aDir);
        if (NS_SUCCEEDED(rv) && advNode) {
          aNode = advNode;
        } else {
          return; // fell out of range
        }
      } else {
        if (aNode != currentNode) {
          nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));
          mCurrentIterator->PositionAt(content);
        }
        return; // found something
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 75 of file nsFilteredContentIterator.h.

Here is the caller graph for this function:

Definition at line 74 of file nsFilteredContentIterator.h.

{ return mDidSkip; }

Here is the caller graph for this function:

First will reset the list.

Implements nsIContentIterator.

Definition at line 140 of file nsFilteredContentIterator.cpp.

{
  if (!mCurrentIterator) {
    NS_ERROR("Missing iterator!");

    return;
  }

  // If we are switching directions then
  // we need to switch how we process the nodes
  if (mDirection != eForward) {
    mCurrentIterator = mPreIterator;
    mDirection       = eForward;
    mIsOutOfRange    = PR_FALSE;
  }

  mCurrentIterator->First();

  if (mCurrentIterator->IsDone()) {
    return;
  }

  nsIContent *currentContent = mCurrentIterator->GetCurrentNode();
  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(currentContent));

  PRPackedBool didCross;
  CheckAdvNode(node, didCross, eForward);
}

Here is the call graph for this function:

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

Returns:
the current node

Implements nsIContentIterator.

Definition at line 426 of file nsFilteredContentIterator.cpp.

{
  if (mIsOutOfRange || !mCurrentIterator) {
    return nsnull;
  }

  return mCurrentIterator->GetCurrentNode();
}

Implements nsIContentIterator.

Definition at line 71 of file nsFilteredContentIterator.cpp.

{
  NS_ENSURE_TRUE(mPreIterator, NS_ERROR_FAILURE);
  NS_ENSURE_TRUE(mIterator, NS_ERROR_FAILURE);
  mIsOutOfRange    = PR_FALSE;
  mDirection       = eForward;
  mCurrentIterator = mPreIterator;

  nsresult rv;
  mRange = do_CreateInstance("@mozilla.org/content/range;1", &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  nsCOMPtr<nsIDOMRange> domRange(do_QueryInterface(mRange));
  nsCOMPtr<nsIDOMNode> domNode(do_QueryInterface(aRoot));
  if (domRange && domNode) {
    domRange->SelectNode(domNode);
  }

  rv = mPreIterator->Init(domRange);
  NS_ENSURE_SUCCESS(rv, rv);
  return mIterator->Init(domRange);
}

Here is the call graph for this function:

Implements nsIContentIterator.

Definition at line 95 of file nsFilteredContentIterator.cpp.

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 436 of file nsFilteredContentIterator.cpp.

{
  if (mIsOutOfRange || !mCurrentIterator) {
    return PR_TRUE;
  }

  return mCurrentIterator->IsDone();
}

Last will reset the list to the end.

Implements nsIContentIterator.

Definition at line 171 of file nsFilteredContentIterator.cpp.

{
  if (!mCurrentIterator) {
    NS_ERROR("Missing iterator!");

    return;
  }

  // If we are switching directions then
  // we need to switch how we process the nodes
  if (mDirection != eBackward) {
    mCurrentIterator = mIterator;
    mDirection       = eBackward;
    mIsOutOfRange    = PR_FALSE;
  }

  mCurrentIterator->Last();

  if (mCurrentIterator->IsDone()) {
    return;
  }

  nsIContent *currentContent = mCurrentIterator->GetCurrentNode();
  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(currentContent));

  PRPackedBool didCross;
  CheckAdvNode(node, didCross, eBackward);
}

Here is the call graph for this function:

Next will advance the list.

Implements nsIContentIterator.

Definition at line 362 of file nsFilteredContentIterator.cpp.

{
  if (mIsOutOfRange || !mCurrentIterator) {
    NS_ASSERTION(mCurrentIterator, "Missing iterator!");

    return;
  }

  // If we are switching directions then
  // we need to switch how we process the nodes
  if (mDirection != eForward) {
    nsresult rv = SwitchDirections(PR_TRUE);
    if (NS_FAILED(rv)) {
      return;
    }
  }

  mCurrentIterator->Next();

  if (mCurrentIterator->IsDone()) {
    return;
  }

  // If we can't get the current node then 
  // don't check to see if we can skip it
  nsIContent *currentContent = mCurrentIterator->GetCurrentNode();

  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(currentContent));
  CheckAdvNode(node, mDidSkip, eForward);
}

Here is the call graph for this function:

PositionAt will position the iterator to the supplied node.

Implements nsIContentIterator.

Definition at line 446 of file nsFilteredContentIterator.cpp.

Prev will decrement the list.

Implements nsIContentIterator.

Definition at line 394 of file nsFilteredContentIterator.cpp.

{
  if (mIsOutOfRange || !mCurrentIterator) {
    NS_ASSERTION(mCurrentIterator, "Missing iterator!");

    return;
  }

  // If we are switching directions then
  // we need to switch how we process the nodes
  if (mDirection != eBackward) {
    nsresult rv = SwitchDirections(PR_FALSE);
    if (NS_FAILED(rv)) {
      return;
    }
  }

  mCurrentIterator->Prev();

  if (mCurrentIterator->IsDone()) {
    return;
  }

  // If we can't get the current node then 
  // don't check to see if we can skip it
  nsIContent *currentContent = mCurrentIterator->GetCurrentNode();

  nsCOMPtr<nsIDOMNode> node(do_QueryInterface(currentContent));
  CheckAdvNode(node, mDidSkip, eBackward);
}

Here is the call graph for this function:

Definition at line 116 of file nsFilteredContentIterator.cpp.

{
  nsIContent *node = mCurrentIterator->GetCurrentNode();

  if (aChangeToForward) {
    mCurrentIterator = mPreIterator;
    mDirection       = eForward;
  } else {
    mCurrentIterator = mIterator;
    mDirection       = eBackward;
  }

  if (node) {
    nsresult rv = mCurrentIterator->PositionAt(node);
    if (NS_FAILED(rv)) {
      mIsOutOfRange = PR_TRUE;
      return rv;
    }
  }
  return NS_OK;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 90 of file nsFilteredContentIterator.h.

Definition at line 86 of file nsFilteredContentIterator.h.

Definition at line 98 of file nsFilteredContentIterator.h.

Definition at line 100 of file nsFilteredContentIterator.h.

Definition at line 96 of file nsFilteredContentIterator.h.

Definition at line 99 of file nsFilteredContentIterator.h.

Definition at line 87 of file nsFilteredContentIterator.h.

Definition at line 94 of file nsFilteredContentIterator.h.

Definition at line 88 of file nsFilteredContentIterator.h.

Definition at line 97 of file nsFilteredContentIterator.h.

Definition at line 91 of file nsFilteredContentIterator.h.

Definition at line 93 of file nsFilteredContentIterator.h.

Definition at line 92 of file nsFilteredContentIterator.h.


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