Back to index

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

#include <nsXULElement.h>

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

List of all members.

Public Types

enum  Type { eType_Element, eType_Script, eType_Text }

Public Member Functions

 nsXULPrototypeElement ()
virtual ~nsXULPrototypeElement ()
virtual void ReleaseSubtree ()
virtual nsresult Serialize (nsIObjectOutputStream *aStream, nsIScriptContext *aContext, const nsCOMArray< nsINodeInfo > *aNodeInfos)
virtual nsresult Deserialize (nsIObjectInputStream *aStream, nsIScriptContext *aContext, nsIURI *aDocumentURI, const nsCOMArray< nsINodeInfo > *aNodeInfos)
nsresult SetAttrAt (PRUint32 aPos, const nsAString &aValue, nsIURI *aDocumentURI)
void AddRef ()
void Release ()

Static Public Member Functions

static void ReleaseGlobals ()

Public Attributes

PRUint32 mNumChildren
nsXULPrototypeNode ** mChildren
nsCOMPtr< nsINodeInfomNodeInfo
PRUint32 mNumAttributes
nsXULPrototypeAttributemAttributes
Type mType
PRInt32 mRefCnt

Static Protected Member Functions

static nsICSSParserGetCSSParser ()

Static Protected Attributes

static nsICSSParsersCSSParser = nsnull

Detailed Description

Definition at line 233 of file nsXULElement.h.


Member Enumeration Documentation

enum nsXULPrototypeNode::Type [inherited]
Enumerator:
eType_Element 
eType_Script 
eType_Text 

Definition at line 195 of file nsXULElement.h.


Constructor & Destructor Documentation

Definition at line 236 of file nsXULElement.h.

Here is the caller graph for this function:

virtual nsXULPrototypeElement::~nsXULPrototypeElement ( ) [inline, virtual]

Definition at line 246 of file nsXULElement.h.

    {
        delete[] mAttributes;
        delete[] mChildren;
    }

Member Function Documentation

void nsXULPrototypeNode::AddRef ( void  ) [inline, inherited]

Definition at line 215 of file nsXULElement.h.

                  {
        ++mRefCnt;
        NS_LOG_ADDREF(this, mRefCnt, ClassName(), ClassSize());
    }

Here is the caller graph for this function:

nsresult nsXULPrototypeElement::Deserialize ( nsIObjectInputStream aStream,
nsIScriptContext aContext,
nsIURI aDocumentURI,
const nsCOMArray< nsINodeInfo > *  aNodeInfos 
) [virtual]

Implements nsXULPrototypeNode.

Definition at line 3132 of file nsXULElement.cpp.

{
    NS_PRECONDITION(aNodeInfos, "missing nodeinfo array");
    nsresult rv;

    // Read Node Info
    PRUint32 number;
    rv = aStream->Read32(&number);
    mNodeInfo = aNodeInfos->SafeObjectAt(number);
    if (!mNodeInfo)
        return NS_ERROR_UNEXPECTED;

    // Read Attributes
    rv |= aStream->Read32(&number);
    mNumAttributes = PRInt32(number);

    PRUint32 i;
    if (mNumAttributes > 0) {
        mAttributes = new nsXULPrototypeAttribute[mNumAttributes];
        if (! mAttributes)
            return NS_ERROR_OUT_OF_MEMORY;

        nsAutoString attributeValue;
        for (i = 0; i < mNumAttributes; ++i) {
            rv |= aStream->Read32(&number);
            nsINodeInfo* ni = aNodeInfos->SafeObjectAt(number);
            if (!ni)
                return NS_ERROR_UNEXPECTED;

            mAttributes[i].mName.SetTo(ni);

            rv |= aStream->ReadString(attributeValue);
            rv |= SetAttrAt(i, attributeValue, aDocumentURI);
        }
    }

    rv |= aStream->Read32(&number);
    mNumChildren = PRInt32(number);

    if (mNumChildren > 0) {
        mChildren = new nsXULPrototypeNode*[mNumChildren];
        if (! mChildren)
            return NS_ERROR_OUT_OF_MEMORY;

        memset(mChildren, 0, sizeof(nsXULPrototypeNode*) * mNumChildren);

        for (i = 0; i < mNumChildren; i++) {
            rv |= aStream->Read32(&number);
            Type childType = (Type)number;

            nsXULPrototypeNode* child = nsnull;

            switch (childType) {
            case eType_Element:
                child = new nsXULPrototypeElement();
                if (! child)
                    return NS_ERROR_OUT_OF_MEMORY;
                child->mType = childType;

                rv |= child->Deserialize(aStream, aContext, aDocumentURI,
                                         aNodeInfos);
                break;
            case eType_Text:
                child = new nsXULPrototypeText();
                if (! child)
                    return NS_ERROR_OUT_OF_MEMORY;
                child->mType = childType;

                rv |= child->Deserialize(aStream, aContext, aDocumentURI,
                                         aNodeInfos);
                break;
            case eType_Script: {
                // language version/options obtained during deserialization.
                // Don't clobber rv here, since it might already be a failure!
                nsresult result;
                nsXULPrototypeScript* script =
                    new nsXULPrototypeScript(0, nsnull, PR_FALSE, &result);
                if (! script)
                    return NS_ERROR_OUT_OF_MEMORY;
                if (NS_FAILED(result)) {
                    delete script;
                    return result;
                }
                child = script;
                child->mType = childType;

                rv |= aStream->Read8(&script->mOutOfLine);
                if (! script->mOutOfLine) {
                    rv |= script->Deserialize(aStream, aContext, aDocumentURI,
                                              aNodeInfos);
                } else {
                    rv |= aStream->ReadObject(PR_TRUE, getter_AddRefs(script->mSrcURI));

                    rv |= script->DeserializeOutOfLine(aStream, aContext);
                }
                break;
            }
            }

            mChildren[i] = child;

            // Oh dear. Something failed during the deserialization.
            // We don't know what.  But likely consequences of failed
            // deserializations included calls to |AbortFastLoads| which
            // shuts down the FastLoadService and closes our streams.
            // If that happens, next time through this loop, we die a messy
            // death. So, let's just fail now, and propagate that failure
            // upward so that the ChromeProtocolHandler knows it can't use
            // a cached chrome channel for this.
            if (NS_FAILED(rv))
                return rv;
        }
    }

    return rv;
}

Here is the call graph for this function:

static nsICSSParser* nsXULPrototypeElement::GetCSSParser ( ) [inline, static, protected]

Definition at line 293 of file nsXULElement.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void nsXULPrototypeNode::Release ( void  ) [inline, inherited]

Definition at line 219 of file nsXULElement.h.

    {
        --mRefCnt;
        NS_LOG_RELEASE(this, mRefCnt, ClassName());
        if (mRefCnt == 0)
            delete this;
    }

Here is the caller graph for this function:

static void nsXULPrototypeElement::ReleaseGlobals ( ) [inline, static]

Definition at line 287 of file nsXULElement.h.

Here is the caller graph for this function:

virtual void nsXULPrototypeElement::ReleaseSubtree ( ) [inline, virtual]

Reimplemented from nsXULPrototypeNode.

Definition at line 257 of file nsXULElement.h.

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsXULPrototypeElement::Serialize ( nsIObjectOutputStream aStream,
nsIScriptContext aContext,
const nsCOMArray< nsINodeInfo > *  aNodeInfos 
) [virtual]

Implements nsXULPrototypeNode.

Definition at line 3055 of file nsXULElement.cpp.

{
    nsresult rv;

    // Write basic prototype data
    rv = aStream->Write32(mType);

    // Write Node Info
    PRInt32 index = aNodeInfos->IndexOf(mNodeInfo);
    NS_ASSERTION(index >= 0, "unknown nsINodeInfo index");
    rv |= aStream->Write32(index);

    // Write Attributes
    rv |= aStream->Write32(mNumAttributes);

    nsAutoString attributeValue;
    PRUint32 i;
    for (i = 0; i < mNumAttributes; ++i) {
        nsCOMPtr<nsINodeInfo> ni;
        if (mAttributes[i].mName.IsAtom()) {
            mNodeInfo->NodeInfoManager()->
                GetNodeInfo(mAttributes[i].mName.Atom(), nsnull,
                            kNameSpaceID_None, getter_AddRefs(ni));
            NS_ASSERTION(ni, "the nodeinfo should already exist");
        }
        else {
            ni = mAttributes[i].mName.NodeInfo();
        }

        index = aNodeInfos->IndexOf(ni);
        NS_ASSERTION(index >= 0, "unknown nsINodeInfo index");
        rv |= aStream->Write32(index);

        mAttributes[i].mValue.ToString(attributeValue);
        rv |= aStream->WriteWStringZ(attributeValue.get());
    }

    // Now write children
    rv |= aStream->Write32(PRUint32(mNumChildren));
    for (i = 0; i < mNumChildren; i++) {
        nsXULPrototypeNode* child = mChildren[i];
        switch (child->mType) {
        case eType_Element:
        case eType_Text:
            rv |= child->Serialize(aStream, aContext, aNodeInfos);
            break;
        case eType_Script:
            rv |= aStream->Write32(child->mType);
            nsXULPrototypeScript* script = NS_STATIC_CAST(nsXULPrototypeScript*, child);

            rv |= aStream->Write8(script->mOutOfLine);
            if (! script->mOutOfLine) {
                rv |= script->Serialize(aStream, aContext, aNodeInfos);
            } else {
                rv |= aStream->WriteCompoundObject(script->mSrcURI,
                                                   NS_GET_IID(nsIURI),
                                                   PR_TRUE);

                if (script->mJSObject) {
                    // This may return NS_OK without muxing script->mSrcURI's
                    // data into the FastLoad file, in the case where that
                    // muxed document is already there (written by a prior
                    // session, or by an earlier FastLoad episode during this
                    // session).
                    rv |= script->SerializeOutOfLine(aStream, aContext);
                }
            }
            break;
        }
    }

    return rv;
}

Here is the call graph for this function:

nsresult nsXULPrototypeElement::SetAttrAt ( PRUint32  aPos,
const nsAString &  aValue,
nsIURI aDocumentURI 
)

Definition at line 3253 of file nsXULElement.cpp.

{
    NS_PRECONDITION(aPos < mNumAttributes, "out-of-bounds");

    // WARNING!!
    // This code is largely duplicated in nsXULElement::SetAttr.
    // Any changes should be made to both functions.

    if (!mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
        mAttributes[aPos].mValue.ParseStringOrAtom(aValue);

        return NS_OK;
    }

    if (mAttributes[aPos].mName.Equals(nsXULAtoms::id) &&
        !aValue.IsEmpty()) {
        // Store id as atom.
        // id="" means that the element has no id. Not that it has
        // emptystring as id.
        mAttributes[aPos].mValue.ParseAtom(aValue);

        return NS_OK;
    }
    else if (mAttributes[aPos].mName.Equals(nsXULAtoms::clazz)) {
        // Compute the element's class list
        mAttributes[aPos].mValue.ParseAtomArray(aValue);
        
        return NS_OK;
    }
    else if (mAttributes[aPos].mName.Equals(nsXULAtoms::style)) {
        // Parse the element's 'style' attribute
        nsCOMPtr<nsICSSStyleRule> rule;
        nsICSSParser* parser = GetCSSParser();
        NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);

        // XXX Get correct Base URI (need GetBaseURI on *prototype* element)
        parser->ParseStyleAttribute(aValue, aDocumentURI, aDocumentURI,
                                    getter_AddRefs(rule));
        if (rule) {
            mAttributes[aPos].mValue.SetTo(rule);

            return NS_OK;
        }
        // Don't abort if parsing failed, it could just be malformed css.
    }

    mAttributes[aPos].mValue.ParseStringOrAtom(aValue);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 285 of file nsXULElement.h.

Definition at line 280 of file nsXULElement.h.

Definition at line 282 of file nsXULElement.h.

Definition at line 284 of file nsXULElement.h.

Definition at line 279 of file nsXULElement.h.

Definition at line 199 of file nsXULElement.h.

Definition at line 197 of file nsXULElement.h.

Definition at line 304 of file nsXULElement.h.


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