Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
nsContentList.h File Reference
#include "nsISupports.h"
#include "nsCOMArray.h"
#include "nsString.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMNodeList.h"
#include "nsStubDocumentObserver.h"
#include "nsIAtom.h"
#include "nsINameSpaceManager.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  nsBaseContentList
class  nsFormContentList
class  nsContentListKey
 Class that's used as the key to hash nsContentList implementations for fast retrieval. More...
class  nsContentList
 Class that implements a live NodeList that matches nodes in the tree based on some criterion. More...

Defines

#define LIST_UP_TO_DATE   0
 LIST_UP_TO_DATE means that the list is up to date and need not do any walking to be able to answer any questions anyone may have.
#define LIST_DIRTY   1
 LIST_DIRTY means that the list contains no useful information and if anyone asks it anything it will have to populate itself before answering.
#define LIST_LAZY   2
 LIST_LAZY means that the list has populated itself to a certain extent and that that part of the list is still valid.

Typedefs

typedef PRBool(* nsContentListMatchFunc )(nsIContent *aContent, PRInt32 aNamespaceID, nsIAtom *aAtom, const nsAString &aData)

Functions

already_AddRefed< nsContentListNS_GetContentList (nsIDocument *aDocument, nsIAtom *aMatchAtom, PRInt32 aMatchNameSpaceId, nsIContent *aRootContent)

Define Documentation

#define LIST_DIRTY   1

LIST_DIRTY means that the list contains no useful information and if anyone asks it anything it will have to populate itself before answering.

Definition at line 159 of file nsContentList.h.

#define LIST_LAZY   2

LIST_LAZY means that the list has populated itself to a certain extent and that that part of the list is still valid.

Requests for things outside that part of the list will require walking the tree some more. When a list is in this state, the last thing in mElements is the last node in the tree that the list looked at.

Definition at line 167 of file nsContentList.h.

LIST_UP_TO_DATE means that the list is up to date and need not do any walking to be able to answer any questions anyone may have.

Definition at line 153 of file nsContentList.h.


Typedef Documentation

typedef PRBool(* nsContentListMatchFunc)(nsIContent *aContent, PRInt32 aNamespaceID, nsIAtom *aAtom, const nsAString &aData)

Definition at line 53 of file nsContentList.h.


Function Documentation

already_AddRefed<nsContentList> NS_GetContentList ( nsIDocument aDocument,
nsIAtom aMatchAtom,
PRInt32  aMatchNameSpaceId,
nsIContent aRootContent 
)

Definition at line 194 of file nsContentList.cpp.

{
  nsContentList* list = nsnull;

  static PLDHashTableOps hash_table_ops =
  {
    PL_DHashAllocTable,
    PL_DHashFreeTable,
    ContentListHashtableGetKey,
    ContentListHashtableHashKey,
    ContentListHashtableMatchEntry,
    PL_DHashMoveEntryStub,
    PL_DHashClearEntryStub,
    PL_DHashFinalizeStub
  };

  // Initialize the hashtable if needed.
  if (!gContentListHashTable.ops) {
    PRBool success = PL_DHashTableInit(&gContentListHashTable,
                                       &hash_table_ops, nsnull,
                                       sizeof(ContentListHashEntry),
                                       16);

    if (!success) {
      gContentListHashTable.ops = nsnull;
    }
  }
  
  ContentListHashEntry *entry = nsnull;
  // First we look in our hashtable.  Then we create a content list if needed
  if (gContentListHashTable.ops) {
    nsContentListKey hashKey(aDocument, aMatchAtom,
                             aMatchNameSpaceId, aRootContent);
    
    // A PL_DHASH_ADD is equivalent to a PL_DHASH_LOOKUP for cases
    // when the entry is already in the hashtable.
    entry = NS_STATIC_CAST(ContentListHashEntry *,
                           PL_DHashTableOperate(&gContentListHashTable,
                                                &hashKey,
                                                PL_DHASH_ADD));
    if (entry)
      list = entry->mContentList;
  }

  if (!list) {
    // We need to create a ContentList and add it to our new entry, if
    // we have an entry
    list = new nsContentList(aDocument, aMatchAtom,
                             aMatchNameSpaceId, aRootContent);
    if (entry) {
      if (list)
        entry->mContentList = list;
      else
        PL_DHashTableRawRemove(&gContentListHashTable, entry);
    }

    NS_ENSURE_TRUE(list, nsnull);
  }

  NS_ADDREF(list);

  // Hold on to the last requested content list to avoid having it be
  // removed from the cache immediately when it's released. Avoid
  // bumping the refcount on the list if the requested list is the one
  // that's already cached.

  if (!aRootContent && gCachedContentList != list) {
    NS_IF_RELEASE(gCachedContentList);

    gCachedContentList = list;
    NS_ADDREF(gCachedContentList);
  }

  return list;
}

Here is the call graph for this function:

Here is the caller graph for this function: