Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsContentIterator.cpp File Reference
#include "nsISupports.h"
#include "nsIDOMNodeList.h"
#include "nsIContentIterator.h"
#include "nsRange.h"
#include "nsIContent.h"
#include "nsIDOMText.h"
#include "nsISupportsArray.h"
#include "nsCOMPtr.h"
#include "nsPresContext.h"
#include "nsIComponentManager.h"
#include "nsContentCID.h"
#include "nsLayoutCID.h"
#include "nsVoidArray.h"
#include "nsContentUtils.h"

Go to the source code of this file.

Classes

class  nsContentIterator
class  nsPreContentIterator
class  nsContentSubtreeIterator

Functions

static NS_DEFINE_IID (kISupportsIID, NS_ISUPPORTS_IID)
static PRUint32 GetNumChildren (nsIDOMNode *aNode)
static nsCOMPtr< nsIDOMNodeGetChildAt (nsIDOMNode *aParent, PRInt32 aOffset)
static PRBool ContentHasChildren (nsIContent *aContent)
static void ContentToParentOffset (nsIContent *aContent, nsIDOMNode **aParent, PRInt32 *aOffset)
static PRBool ContentIsInTraversalRange (nsIContent *aContent, PRBool aIsPreMode, nsIDOMNode *aStartNode, PRInt32 aStartOffset, nsIDOMNode *aEndNode, PRInt32 aEndOffset)
nsresult NS_NewContentIterator (nsIContentIterator **aInstancePtrResult)
nsresult NS_NewPreContentIterator (nsIContentIterator **aInstancePtrResult)
nsresult NS_NewContentSubtreeIterator (nsIContentIterator **aInstancePtrResult)

Function Documentation

static PRBool ContentHasChildren ( nsIContent aContent) [inline, static]

Definition at line 125 of file nsContentIterator.cpp.

{
  return aContent->GetChildCount() > 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool ContentIsInTraversalRange ( nsIContent aContent,
PRBool  aIsPreMode,
nsIDOMNode aStartNode,
PRInt32  aStartOffset,
nsIDOMNode aEndNode,
PRInt32  aEndOffset 
) [static]

Definition at line 156 of file nsContentIterator.cpp.

{
  if (!aStartNode || !aEndNode || !aContent)
    return PR_FALSE;

  nsCOMPtr<nsIDOMCharacterData> cData(do_QueryInterface(aContent));

  if (cData)
  {
    // If a chardata node contains an end point of the traversal range,
    // it is always in the traversal range.

    nsCOMPtr<nsIContent> startContent(do_QueryInterface(aStartNode));
    nsCOMPtr<nsIContent> endContent(do_QueryInterface(aEndNode));

    if (aContent == startContent || aContent == endContent)
      return PR_TRUE;
  }

  nsCOMPtr<nsIDOMNode> parentNode;
  PRInt32 indx = 0;

  ContentToParentOffset(aContent, getter_AddRefs(parentNode), &indx);

  if (!parentNode)
    return PR_FALSE;

  if (!aIsPreMode)
    ++indx;

  return (nsRange::ComparePoints(aStartNode, aStartOffset,
                                 parentNode, indx) <= 0) &&
         (nsRange::ComparePoints(aEndNode, aEndOffset, parentNode, indx) >= 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void ContentToParentOffset ( nsIContent aContent,
nsIDOMNode **  aParent,
PRInt32 aOffset 
) [static]

Definition at line 135 of file nsContentIterator.cpp.

{
  *aParent = nsnull;
  *aOffset  = 0;

  nsIContent* parent = aContent->GetParent();

  if (!parent)
    return;

  *aOffset = parent->IndexOf(aContent);

  CallQueryInterface(parent, aParent);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsCOMPtr<nsIDOMNode> GetChildAt ( nsIDOMNode aParent,
PRInt32  aOffset 
) [static]

Definition at line 95 of file nsContentIterator.cpp.

{
  nsCOMPtr<nsIDOMNode> resultNode;

  if (!aParent) 
    return resultNode;

  nsCOMPtr<nsIContent> content(do_QueryInterface(aParent));

  if (content) {
    resultNode = do_QueryInterface(content->GetChildAt(aOffset));
  } else if (aParent) {
    PRBool hasChildNodes;
    aParent->HasChildNodes(&hasChildNodes);
    if (hasChildNodes)
    {
      nsCOMPtr<nsIDOMNodeList>nodeList;
      aParent->GetChildNodes(getter_AddRefs(nodeList));
      if (nodeList) 
        nodeList->Item(aOffset, getter_AddRefs(resultNode));
    }
  }
  
  return resultNode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRUint32 GetNumChildren ( nsIDOMNode aNode) [static]

Definition at line 67 of file nsContentIterator.cpp.

{
  if (!aNode)
    return 0;

  PRUint32 numChildren = 0;
  PRBool hasChildNodes;
  aNode->HasChildNodes(&hasChildNodes);
  if (hasChildNodes)
  {
    nsCOMPtr<nsIContent> content(do_QueryInterface(aNode));

    if (content)
      return content->GetChildCount();

    nsCOMPtr<nsIDOMNodeList>nodeList;
    aNode->GetChildNodes(getter_AddRefs(nodeList));
    if (nodeList) 
      nodeList->GetLength(&numChildren);
  }

  return numChildren;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static NS_DEFINE_IID ( kISupportsIID  ,
NS_ISUPPORTS_IID   
) [static]

Definition at line 299 of file nsContentIterator.cpp.

{
  nsContentIterator * iter = new nsContentIterator();
  if (!iter) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  NS_ADDREF(*aInstancePtrResult = iter);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1269 of file nsContentIterator.cpp.

{
  nsContentIterator * iter = new nsContentSubtreeIterator();
  if (!iter) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  NS_ADDREF(*aInstancePtrResult = iter);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 312 of file nsContentIterator.cpp.

{
  nsContentIterator * iter = new nsPreContentIterator();
  if (!iter) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  NS_ADDREF(*aInstancePtrResult = iter);

  return NS_OK;
}

Here is the call graph for this function: