Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes

nsContentList Class Reference

Class that implements a live NodeList that matches Elements in the tree based on some criterion. More...

#include <nsContentList.h>

Inheritance diagram for nsContentList:
Collaboration diagram for nsContentList:

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS_INHERITED nsContentList (nsINode *aRootNode, nsIAtom *aMatchAtom, PRInt32 aMatchNameSpaceId, PRBool aDeep=1)
 nsContentList (nsINode *aRootNode, nsContentListMatchFunc aFunc, nsContentListDestroyFunc aDestroyFunc, void *aData, PRBool aDeep=1, nsIAtom *aMatchAtom=0, PRInt32 aMatchNameSpaceId=kNameSpaceID_None, PRBool aFuncMayDependOnAttr=1)
virtual ~nsContentList ()
virtual
NS_DECL_NSIDOMHTMLCOLLECTION
PRInt32 
IndexOf (nsIContent *aContent, PRBool aDoFlush)
virtual nsIContent * GetNodeAt (PRUint32 aIndex)
virtual PRInt32 IndexOf (nsIContent *aContent)
virtual nsISupportsGetNodeAt (PRUint32 aIndex, nsresult *aResult)
virtual nsISupportsGetNamedItem (const nsAString &aName, nsresult *aResult)
nsINode * GetParentObject ()
PRUint32 Length (PRBool aDoFlush)
nsIContent * Item (PRUint32 aIndex, PRBool aDoFlush)
nsIContent * NamedItem (const nsAString &aName, PRBool aDoFlush)
nsContentListKeyGetKey ()

Static Public Member Functions

NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
static
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
void 
OnDocumentDestroy (nsIDocument *aDocument)
static nsContentListFromSupports (nsISupports *aSupports)

Protected Member Functions

PRBool Match (nsIContent *aContent)
 Returns whether the content element matches our criterion.
PRBool MatchSelf (nsIContent *aContent)
 Match recursively.
void PopulateWith (nsIContent *aContent, PRUint32 &aElementsToAppend)
 Add elements in the subtree rooted in aContent that match our criterion to our list until we've picked up aElementsToAppend elements.
void PopulateWithStartingAfter (nsINode *aStartRoot, nsINode *aStartChild, PRUint32 &aElementsToAppend)
 Populate our list starting at the child of aStartRoot that comes after aStartChild (if such exists) and continuing in document order.
void PopulateSelf (PRUint32 aNeededLength)
 Populate our list.
PRBool MayContainRelevantNodes (nsINode *aContainer)
void RemoveFromHashtable ()
 Remove ourselves from the hashtable that caches commonly accessed content lists.
void BringSelfUpToDate (PRBool aDoFlush)
 If state is not LIST_UP_TO_DATE, fully populate ourselves with all the nodes we can find.
void SetDirty ()
 Sets the state to LIST_DIRTY and clears mElements array.

Protected Attributes

nsContentListMatchFunc mFunc
 Function to use to determine whether a piece of content matches our criterion.
nsContentListDestroyFunc mDestroyFunc
 Cleanup closure data with this.
void * mData
 Closure data to pass to mFunc when we call it.
PRPackedBool mMatchAll
 True if we are looking for elements named "*".
PRUint8 mState
 The current state of the list (possible values are: LIST_UP_TO_DATE, LIST_LAZY, LIST_DIRTY.
PRPackedBool mDeep
 Whether to actually descend the tree.
PRPackedBool mFuncMayDependOnAttr
 Whether the return value of mFunc could depend on the values of attributes.

Detailed Description

Class that implements a live NodeList that matches Elements in the tree based on some criterion.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS_INHERITED nsContentList::nsContentList ( nsINode *  aRootNode,
nsIAtom aMatchAtom,
PRInt32  aMatchNameSpaceId,
PRBool  aDeep = 1 
)
Parameters:
aRootNode The node under which to limit our search.
aMatchAtom An atom whose meaning depends on aMatchNameSpaceId. The special value "*" always matches whatever aMatchAtom is matched against.
aMatchNameSpaceId If kNameSpaceID_Unknown, then aMatchAtom is the tagName to match. If kNameSpaceID_Wildcard, then aMatchAtom is the localName to match. Otherwise we match nodes whose namespace is aMatchNameSpaceId and localName matches aMatchAtom.
aDeep If false, then look only at children of the root, nothing deeper. If true, then look at the whole subtree rooted at our root.
nsContentList::nsContentList ( nsINode *  aRootNode,
nsContentListMatchFunc  aFunc,
nsContentListDestroyFunc  aDestroyFunc,
void *  aData,
PRBool  aDeep = 1,
nsIAtom aMatchAtom = 0,
PRInt32  aMatchNameSpaceId = kNameSpaceID_None,
PRBool  aFuncMayDependOnAttr = 1 
)
Parameters:
aRootNode The node under which to limit our search.
aFunc the function to be called to determine whether we match. This function MUST NOT ever cause mutation of the DOM. The nsContentList implementation guarantees that everything passed to the function will be IsNodeOfType(nsINode::eELEMENT).
aDestroyFunc the function that will be called to destroy aData
aData closure data that will need to be passed back to aFunc
aDeep If false, then look only at children of the root, nothing deeper. If true, then look at the whole subtree rooted at our root.
aMatchAtom an atom to be passed back to aFunc
aMatchNameSpaceId a namespace id to be passed back to aFunc
aFuncMayDependOnAttr a boolean that indicates whether this list is sensitive to attribute changes.
virtual nsContentList::~nsContentList (  )  [virtual]

Member Function Documentation

void nsContentList::BringSelfUpToDate ( PRBool  aDoFlush  )  [inline, protected]

If state is not LIST_UP_TO_DATE, fully populate ourselves with all the nodes we can find.

static nsContentList* nsContentList::FromSupports ( nsISupports aSupports  )  [inline, static]
nsContentListKey* nsContentList::GetKey (  )  [inline]
virtual nsISupports* nsContentList::GetNamedItem ( const nsAString aName,
nsresult aResult 
) [virtual]
virtual nsIContent* nsContentList::GetNodeAt ( PRUint32  aIndex  )  [virtual]

Reimplemented from nsBaseContentList.

virtual nsISupports* nsContentList::GetNodeAt ( PRUint32  aIndex,
nsresult aResult 
) [virtual]
nsINode* nsContentList::GetParentObject (  )  [inline]
virtual NS_DECL_NSIDOMHTMLCOLLECTION PRInt32 nsContentList::IndexOf ( nsIContent *  aContent,
PRBool  aDoFlush 
) [virtual]

Reimplemented from nsBaseContentList.

virtual PRInt32 nsContentList::IndexOf ( nsIContent *  aContent  )  [virtual]

Reimplemented from nsBaseContentList.

nsIContent* nsContentList::Item ( PRUint32  aIndex,
PRBool  aDoFlush 
)
PRUint32 nsContentList::Length ( PRBool  aDoFlush  ) 
PRBool nsContentList::Match ( nsIContent *  aContent  )  [protected]

Returns whether the content element matches our criterion.

Parameters:
aContent the content to attempt to match
Returns:
whether we match
PRBool nsContentList::MatchSelf ( nsIContent *  aContent  )  [protected]

Match recursively.

See if anything in the subtree rooted at aContent matches our criterion.

Parameters:
aContent the root of the subtree to match against
Returns:
whether we match something in the tree rooted at aContent
PRBool nsContentList::MayContainRelevantNodes ( nsINode *  aContainer  )  [inline, protected]
Parameters:
aContainer a content node which must be a descendant of mRootNode
Returns:
PR_TRUE if children or descendants of aContainer could match our criterion. PR_FALSE otherwise.
nsIContent* nsContentList::NamedItem ( const nsAString aName,
PRBool  aDoFlush 
)
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED static NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED void nsContentList::OnDocumentDestroy ( nsIDocument *  aDocument  )  [static]
void nsContentList::PopulateSelf ( PRUint32  aNeededLength  )  [protected]

Populate our list.

Stop once we have at least aNeededLength elements. At the end of PopulateSelf running, either the last node we examined is the last node in our array or we have traversed the whole document (or both).

Parameters:
aNeededLength the length the list should have when we are done (unless it exhausts the document)
void nsContentList::PopulateWith ( nsIContent *  aContent,
PRUint32 &  aElementsToAppend 
) [protected]

Add elements in the subtree rooted in aContent that match our criterion to our list until we've picked up aElementsToAppend elements.

This function enforces the invariant that |aElementsToAppend + mElements.Count()| is a constant.

Parameters:
aContent the root of the subtree we want to traverse. This node is always included in the traversal and is thus the first node tested. This must be IsNodeOfType(nsINode::eELEMENT).
aElementsToAppend how many elements to append to the list before stopping
void nsContentList::PopulateWithStartingAfter ( nsINode *  aStartRoot,
nsINode *  aStartChild,
PRUint32 &  aElementsToAppend 
) [protected]

Populate our list starting at the child of aStartRoot that comes after aStartChild (if such exists) and continuing in document order.

Stop once we've picked up aElementsToAppend elements. This function enforces the invariant that |aElementsToAppend + mElements.Count()| is a constant.

Parameters:
aStartRoot the node with whose children we want to start traversal
aStartChild the child after which we want to start
aElementsToAppend how many elements to append to the list before stopping
void nsContentList::RemoveFromHashtable (  )  [protected]

Remove ourselves from the hashtable that caches commonly accessed content lists.

Generally done on destruction.

void nsContentList::SetDirty (  )  [inline, protected]

Sets the state to LIST_DIRTY and clears mElements array.

Note:
This is the only acceptable way to set state to LIST_DIRTY.

Member Data Documentation

void* nsContentList::mData [protected]

Closure data to pass to mFunc when we call it.

Whether to actually descend the tree.

If this is false, we won't consider grandkids of mRootNode.

Cleanup closure data with this.

Function to use to determine whether a piece of content matches our criterion.

Whether the return value of mFunc could depend on the values of attributes.

True if we are looking for elements named "*".

PRUint8 nsContentList::mState [protected]

The current state of the list (possible values are: LIST_UP_TO_DATE, LIST_LAZY, LIST_DIRTY.


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