Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
txXPathTreeWalker Class Reference

#include <txXPathTreeWalker.h>

Collaboration diagram for txXPathTreeWalker:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 txXPathTreeWalker (const txXPathTreeWalker &aOther)
 txXPathTreeWalker (const txXPathNode &aNode)
 ~txXPathTreeWalker ()
PRBool getAttr (nsIAtom *aLocalName, PRInt32 aNSID, nsAString &aValue) const
PRInt32 getNamespaceID () const
PRUint16 getNodeType () const
void appendNodeValue (nsAString &aResult) const
void getNodeName (nsAString &aName) const
void moveTo (const txXPathTreeWalker &aWalker)
PRBool moveToParent ()
PRBool moveToElementById (const nsAString &aID)
PRBool moveToFirstAttribute ()
PRBool moveToNextAttribute ()
PRBool moveToFirstChild ()
PRBool moveToLastChild ()
PRBool moveToNextSibling ()
PRBool moveToPreviousSibling ()
PRBool isOnNode (const txXPathNode &aNode) const
const txXPathNodegetCurrentPosition () const

Private Member Functions

PRBool moveToValidAttribute (PRUint32 aStartIndex)
PRBool moveToSibling (PRInt32 aDir)

Private Attributes

txXPathNode mPosition
PRUint32 mCurrentIndex
txUint32Array mDescendants

Detailed Description

Definition at line 71 of file txXPathTreeWalker.h.


Constructor & Destructor Documentation

Definition at line 60 of file txMozillaXPathTreeWalker.cpp.

Definition at line 66 of file txMozillaXPathTreeWalker.cpp.

Definition at line 72 of file txMozillaXPathTreeWalker.cpp.

{
}

Member Function Documentation

void txXPathTreeWalker::appendNodeValue ( nsAString &  aResult) const [inline]

Definition at line 200 of file txXPathTreeWalker.h.

Here is the caller graph for this function:

PRBool txXPathTreeWalker::getAttr ( nsIAtom aLocalName,
PRInt32  aNSID,
nsAString &  aValue 
) const [inline]

Definition at line 187 of file txXPathTreeWalker.h.

{
    return txXPathNodeUtils::getAttr(mPosition, aLocalName, aNSID, aValue);
}

Here is the caller graph for this function:

Definition at line 181 of file txXPathTreeWalker.h.

{
    return mPosition;
}

Here is the caller graph for this function:

Definition at line 194 of file txXPathTreeWalker.h.

Here is the caller graph for this function:

void txXPathTreeWalker::getNodeName ( nsAString &  aName) const [inline]

Definition at line 206 of file txXPathTreeWalker.h.

Here is the caller graph for this function:

PRBool txXPathTreeWalker::isOnNode ( const txXPathNode aNode) const [inline]

Definition at line 226 of file txXPathTreeWalker.h.

{
    return (mPosition == aNode);
}

Here is the caller graph for this function:

Definition at line 212 of file txXPathTreeWalker.h.

{
#ifdef TX_EXE
    mPosition.mInner = aWalker.mPosition.mInner;
#else
    mPosition.mIndex = aWalker.mPosition.mIndex;
    // Hopefully it's ok to access mContent through mDocument.
    mPosition.mDocument = aWalker.mPosition.mDocument;
    mCurrentIndex = aWalker.mCurrentIndex;
    mDescendants.Clear();
#endif
}

Definition at line 77 of file txMozillaXPathTreeWalker.cpp.

{
    nsCOMPtr<nsIDOMDocument> document;
    if (mPosition.isDocument()) {
        document = do_QueryInterface(mPosition.mDocument);
    }
    else {
        document = do_QueryInterface(mPosition.mContent->GetDocument());
    }

    if (!document) {
        return PR_FALSE;
    }

    nsCOMPtr<nsIDOMElement> element;
    document->GetElementById(aID, getter_AddRefs(element));
    if (!element) {
        return PR_FALSE;
    }

    nsCOMPtr<nsIContent> content = do_QueryInterface(element);
    NS_ENSURE_TRUE(content, PR_FALSE);

    mPosition.mIndex = txXPathNode::eContent;
    mPosition.mContent = content;
    mCurrentIndex = kUnknownIndex;
    mDescendants.Clear();

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 109 of file txMozillaXPathTreeWalker.cpp.

{
    if (!mPosition.isContent()) {
        return PR_FALSE;
    }

    return moveToValidAttribute(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 159 of file txMozillaXPathTreeWalker.cpp.

{
    if (mPosition.isAttribute()) {
        return PR_FALSE;
    }

    if (mPosition.isDocument()) {
        nsIContent* child = mPosition.mDocument->GetChildAt(0);
        if (!child) {
            return PR_FALSE;
        }
        mPosition.mIndex = txXPathNode::eContent;
        mPosition.mContent = child;

        NS_ASSERTION(mCurrentIndex == kUnknownIndex && !mDescendants.Count(),
                     "we shouldn't have any position info at the document");
        mCurrentIndex = 0;

        return PR_TRUE;
    }

    nsIContent* child = mPosition.mContent->GetChildAt(0);
    if (!child) {
        return PR_FALSE;
    }
    mPosition.mContent = child;

    NS_ASSERTION(mCurrentIndex != kUnknownIndex || !mDescendants.Count(),
                 "Index should be known if parents index are");
    if (mCurrentIndex != kUnknownIndex &&
        !mDescendants.AppendValue(mCurrentIndex)) {
        mDescendants.Clear();
    }
    mCurrentIndex = 0;

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 198 of file txMozillaXPathTreeWalker.cpp.

{
    if (mPosition.isAttribute()) {
        return PR_FALSE;
    }

    if (mPosition.isDocument()) {
        PRUint32 total = mPosition.mDocument->GetChildCount();
        if (!total) {
            return PR_FALSE;
        }

        mPosition.mIndex = txXPathNode::eContent;
        mPosition.mContent = mPosition.mDocument->GetChildAt(total - 1);
        NS_ASSERTION(mCurrentIndex == kUnknownIndex && !mDescendants.Count(),
                     "we shouldn't have any position info at the document");
        mCurrentIndex = total - 1;

        return PR_TRUE;
    }

    PRUint32 total = mPosition.mContent->GetChildCount();
    if (!total) {
        return PR_FALSE;
    }
    mPosition.mContent = mPosition.mContent->GetChildAt(total - 1);

    NS_ASSERTION(mCurrentIndex != kUnknownIndex || !mDescendants.Count(),
                 "Index should be known if parents index are");
    if (mCurrentIndex != kUnknownIndex &&
        !mDescendants.AppendValue(mCurrentIndex)) {
        mDescendants.Clear();
    }
    mCurrentIndex = total - 1;

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 119 of file txMozillaXPathTreeWalker.cpp.

{
    // XXX an assertion should be enough here with the current code
    if (!mPosition.isAttribute()) {
        return PR_FALSE;
    }

    return moveToValidAttribute(mPosition.mIndex + 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 237 of file txMozillaXPathTreeWalker.cpp.

{
    if (!mPosition.isContent()) {
        return PR_FALSE;
    }

    return moveToSibling(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 257 of file txMozillaXPathTreeWalker.cpp.

{
    if (mPosition.isDocument()) {
        return PR_FALSE;
    }

    if (mPosition.isAttribute()) {
        mPosition.mIndex = txXPathNode::eContent;

        return PR_TRUE;
    }

    nsIContent *parent = mPosition.mContent->GetParent();
    if (parent) {
        mPosition.mContent = parent;
        PRInt32 count = mDescendants.Count();
        if (count) {
            mCurrentIndex = mDescendants.ValueAt(--count);
            mDescendants.RemoveValueAt(count);
        }
        else {
            mCurrentIndex = kUnknownIndex;
        }

        return PR_TRUE;
    }

    nsIDocument* document = mPosition.mContent->GetDocument();
    if (!document) {
        return PR_FALSE;
    }

    mPosition.mIndex = txXPathNode::eDocument;
    mPosition.mDocument = document;

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 247 of file txMozillaXPathTreeWalker.cpp.

{
    if (!mPosition.isContent()) {
        return PR_FALSE;
    }

    return moveToSibling(-1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 296 of file txMozillaXPathTreeWalker.cpp.

{
    NS_ASSERTION(mPosition.isContent(),
                 "moveToSibling should only be called for content");

    nsIDocument* document;
    nsIContent* parent = mPosition.mContent->GetParent();
    if (!parent) {
        document = mPosition.mContent->GetDocument();
        if (!document) {
            return PR_FALSE;
        }
    }
    if (mCurrentIndex == kUnknownIndex) {
        mCurrentIndex = parent ? parent->IndexOf(mPosition.mContent)
                               : document->IndexOf(mPosition.mContent);
    }

    // if mCurrentIndex is 0 we rely on GetChildAt returning null for an
    // index of PRUint32(-1).
    PRUint32 newIndex = mCurrentIndex + aDir;
    nsIContent* newChild = parent ? parent->GetChildAt(newIndex) :
                                    document->GetChildAt(newIndex);
    if (!newChild) {
        return PR_FALSE;
    }

    mPosition.mContent = newChild;
    mCurrentIndex = newIndex;

    return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 130 of file txMozillaXPathTreeWalker.cpp.

{
    NS_ASSERTION(!mPosition.isDocument(), "documents doesn't have attrs");

    PRUint32 total = mPosition.mContent->GetAttrCount();
    if (aStartIndex >= total) {
        return PR_FALSE;
    }

    PRInt32 namespaceID;
    nsCOMPtr<nsIAtom> name, prefix;

    PRUint32 index;
    for (index = aStartIndex; index < total; ++index) {
        mPosition.mContent->GetAttrNameAt(index, &namespaceID,
                                          getter_AddRefs(name),
                                          getter_AddRefs(prefix));

        // We need to ignore XMLNS attributes.
        if (namespaceID != kNameSpaceID_XMLNS) {
            mPosition.mIndex = index;

            return PR_TRUE;
        }
    }
    return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 106 of file txXPathTreeWalker.h.

Definition at line 107 of file txXPathTreeWalker.h.

Definition at line 100 of file txXPathTreeWalker.h.


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