diff --git a/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp b/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp index 75f037cb48f..aebcd18e475 100644 --- a/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp +++ b/mozilla/accessible/src/msaa/nsAccessibleWrap.cpp @@ -446,26 +446,24 @@ STDMETHODIMP nsAccessibleWrap::get_accRole( accessNode->GetDOMNode(getter_AddRefs(domNode)); nsIContent *content = GetRoleContent(domNode); NS_ASSERTION(content, "No content for accessible"); - if (content) { + if (content && content->IsContentOfType(nsIContent::eELEMENT)) { nsAutoString roleString; if (role != ROLE_CLIENT) { content->GetAttr(kNameSpaceID_XHTML2_Unofficial, nsAccessibilityAtoms::role, roleString); } if (roleString.IsEmpty()) { - nsINodeInfo *nodeInfo = content->GetNodeInfo(); - if (nodeInfo) { - nodeInfo->GetName(roleString); - nsAutoString nameSpaceURI; - nodeInfo->GetNamespaceURI(nameSpaceURI); - if (!nameSpaceURI.IsEmpty()) { - // Only append name space if different from that of current document - roleString += NS_LITERAL_STRING(", ") + nameSpaceURI; - } - if (!roleString.IsEmpty()) { - pvarRole->vt = VT_BSTR; - pvarRole->bstrVal = ::SysAllocString(roleString.get()); - return S_OK; - } + nsINodeInfo *nodeInfo = content->NodeInfo(); + nodeInfo->GetName(roleString); + nsAutoString nameSpaceURI; + nodeInfo->GetNamespaceURI(nameSpaceURI); + if (!nameSpaceURI.IsEmpty()) { + // Only append name space if different from that of current document + roleString += NS_LITERAL_STRING(", ") + nameSpaceURI; + } + if (!roleString.IsEmpty()) { + pvarRole->vt = VT_BSTR; + pvarRole->bstrVal = ::SysAllocString(roleString.get()); + return S_OK; } } } diff --git a/mozilla/content/base/public/nsContentCreatorFunctions.h b/mozilla/content/base/public/nsContentCreatorFunctions.h index 65e6a9133a8..42e09bdfdc6 100644 --- a/mozilla/content/base/public/nsContentCreatorFunctions.h +++ b/mozilla/content/base/public/nsContentCreatorFunctions.h @@ -52,6 +52,7 @@ class nsIContent; class nsIDocument; class nsINodeInfo; class imgIRequest; +class nsNodeInfoManager; nsresult NS_NewElement(nsIContent** aResult, PRInt32 aElementType, @@ -61,31 +62,28 @@ nsresult NS_NewXMLElement(nsIContent** aResult, nsINodeInfo* aNodeInfo); /** - * There's no need to pass in aOwnerDocument if the node is going to be - * inserted *immediately* after creation. + * aNodeInfoManager must not be null. */ nsresult NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult, + nsNodeInfoManager *aNodeInfoManager, const nsAString& aTarget, - const nsAString& aData, - nsIDocument *aOwnerDocument = nsnull); + const nsAString& aData); /** - * There's no need to pass in aOwnerDocument if the node is going to be - * inserted *immediately* after creation. + * aNodeInfoManager must not be null. */ nsresult NS_NewXMLStylesheetProcessingInstruction(nsIContent** aInstancePtrResult, - const nsAString& aData, - nsIDocument *aOwnerDocument = nsnull); + nsNodeInfoManager *aNodeInfoManager, + const nsAString& aData); /** - * There's no need to pass in aOwnerDocument if the node is going to be - * inserted *immediately* after creation. + * aNodeInfoManager must not be null. */ nsresult NS_NewXMLCDATASection(nsIContent** aInstancePtrResult, - nsIDocument *aOwnerDocument = nsnull); + nsNodeInfoManager *aNodeInfoManager); nsresult NS_NewHTMLElement(nsIContent** aResult, nsINodeInfo *aNodeInfo); diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index e8e095acf31..cc979841704 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -468,14 +468,6 @@ public: aNodeInfo->NamespaceID(), aResult); } - /** - * Retrieve a pointer to the document that owns aNodeInfo. - */ - static nsIDocument *GetDocument(nsINodeInfo *aNodeInfo) - { - return aNodeInfo->NodeInfoManager()->GetDocument(); - } - /** * Returns the appropriate event argument name for the specified * namespace. Added because we need to switch between SVG's "evt" diff --git a/mozilla/content/base/public/nsIContent.h b/mozilla/content/base/public/nsIContent.h index 6cfec054a94..6a1b12ad141 100644 --- a/mozilla/content/base/public/nsIContent.h +++ b/mozilla/content/base/public/nsIContent.h @@ -45,6 +45,7 @@ #include "nsContentErrors.h" #include "nsPropertyTable.h" #include "nsCaseTreatment.h" +#include "nsINodeInfo.h" // Forward declarations class nsIAtom; @@ -55,14 +56,13 @@ class nsIDOMEvent; class nsIContent; class nsISupportsArray; class nsIDOMRange; -class nsINodeInfo; class nsIEventListenerManager; class nsIURI; // IID for the nsIContent interface #define NS_ICONTENT_IID \ -{ 0x89f20ce8, 0x08cd, 0x4066, \ - { 0x8a, 0xd5, 0x9e, 0x11, 0x1e, 0x43, 0x52, 0x29 } } +{ 0x0b762446, 0x041f, 0x46cf, \ + { 0xb4, 0x6e, 0x98, 0x65, 0x4a, 0x5a, 0x7c, 0x37 } } /** * A node of content in a document's content model. This interface @@ -72,15 +72,23 @@ class nsIContent : public nsISupports { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID) - nsIContent() - : mParentPtrBits(0) { } + nsIContent(nsINodeInfo *aNodeInfo) + : mParentPtrBits(0), + mNodeInfo(aNodeInfo) + { + NS_ASSERTION(aNodeInfo, + "No nsINodeInfo passed to nsIContent, PREPARE TO CRASH!!!"); + } /** * DEPRECATED - Use GetCurrentDoc or GetOwnerDoc. * Get the document for this content. * @return the document */ - virtual nsIDocument* GetDocument() const = 0; + nsIDocument *GetDocument() const + { + return GetCurrentDoc(); + } /** * Bind this content node to a tree. If this method throws, the caller must @@ -133,7 +141,10 @@ public: * * @return whether this content is in a document tree */ - virtual PRBool IsInDoc() const = 0; + PRBool IsInDoc() const + { + return mParentPtrBits & PARENT_BIT_INDOCUMENT; + } /** * Get the document that this content is currently in, if any. This will be @@ -143,9 +154,7 @@ public: */ nsIDocument *GetCurrentDoc() const { - // XXX This should become: - // return IsInDoc() ? GetOwnerDoc() : nsnull; - return GetDocument(); + return IsInDoc() ? GetOwnerDoc() : nsnull; } /** @@ -153,7 +162,10 @@ public: * * @return the ownerDocument */ - virtual nsIDocument *GetOwnerDoc() const = 0; + nsIDocument *GetOwnerDoc() const + { + return mNodeInfo->GetDocument(); + } /** * Get the parent content for this content. @@ -182,19 +194,28 @@ public: * Get the namespace that this element's tag is defined in * @return the namespace */ - virtual PRInt32 GetNameSpaceID() const = 0; + PRInt32 GetNameSpaceID() const + { + return mNodeInfo->NamespaceID(); + } /** * Get the tag for this element. This will always return a non-null * atom pointer (as implied by the naming of the method). */ - virtual nsIAtom *Tag() const = 0; + nsIAtom *Tag() const + { + return mNodeInfo->NameAtom(); + } /** * Get the NodeInfo for this element * @return the nodes node info */ - virtual nsINodeInfo * GetNodeInfo() const = 0; + nsINodeInfo *NodeInfo() const + { + return mNodeInfo; + } /** * Get the number of children @@ -728,20 +749,18 @@ public: /** - * Clones this node, setting aOwnerDocument as the ownerDocument of the + * Clones this node, using aNodeInfoManager to get the nodeinfo for the * clone. When cloning an element, all attributes of the element will be * cloned. If aDeep is set, all descendants will also be cloned (by calling - * the DOM method cloneNode on them if aOwnerDocument is the same as the - * ownerDocument of this content node or by calling the DOM method importNode - * if they differ). + * the DOM method cloneNode on them if aNodeInfoManager is the same as + * the nodeinfo manager of the mNodeInfo of this content node or by calling + * the DOM method importNode if they differ). * - * @param aOwnerDocument the document to use as the ownerDocument of the - * clone, it should not be null unless this element's - * ownerDocument is null and you don't want to set a - * different ownerDocument. + * @param aNodeInfoManager the nodeinfo manager to get the nodeinfo for the + * clone, it should not be null * @param aDeep whether to clone the descendants of this node */ - virtual nsresult CloneContent(nsIDocument *aOwnerDocument, + virtual nsresult CloneContent(nsNodeInfoManager *aNodeInfoManager, PRBool aDeep, nsIContent **aResult) const = 0; #ifdef DEBUG @@ -778,10 +797,13 @@ public: protected: typedef PRWord PtrBits; - // Subclasses may use the low two bits of mParentPtrBits to store other data + // Subclasses may use the 0x2 bit of mParentPtrBits to store other data + enum { PARENT_BIT_INDOCUMENT = 0x1 }; enum { kParentBitMask = 0x3 }; PtrBits mParentPtrBits; + + nsCOMPtr mNodeInfo; }; #endif /* nsIContent_h___ */ diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 21903076856..72d48d55055 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -883,7 +883,7 @@ NS_NewImageDocument(nsIDocument** aInstancePtrResult); nsresult NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, - nsIDocument* aOwnerDocument); + nsNodeInfoManager *aNodeInfoManager); nsresult NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult, const nsAString& aNamespaceURI, diff --git a/mozilla/content/base/public/nsINodeInfo.h b/mozilla/content/base/public/nsINodeInfo.h index b930fdb52f0..b9d12813dec 100644 --- a/mozilla/content/base/public/nsINodeInfo.h +++ b/mozilla/content/base/public/nsINodeInfo.h @@ -57,21 +57,21 @@ #include "nsISupports.h" #include "nsIAtom.h" -#include "nsAString.h" #include "nsDOMString.h" #include "nsINameSpaceManager.h" #include "nsCOMPtr.h" +#include "nsNodeInfoManager.h" // Forward declarations class nsIDocument; class nsIURI; class nsIPrincipal; -class nsNodeInfoManager; // IID for the nsINodeInfo interface +// b24fd4ad-7d94-40ea-b09b-9262f58bc28a #define NS_INODEINFO_IID \ -{ 0x290ecd20, 0xb3cb, 0x11d8, \ - { 0xb2, 0x67, 0x00, 0x0a, 0x95, 0xdc, 0x23, 0x4c } } +{ 0xb24fd4ad, 0x7d94, 0x40ea, \ + { 0xb0, 0x9b, 0x92, 0x62, 0xf5, 0x8b, 0xc2, 0x8a } } class nsINodeInfo : public nsISupports { @@ -264,7 +264,10 @@ public: /* * Retrieve a pointer to the document that owns this node info. */ - virtual nsIDocument* GetDocument() const = 0; + nsIDocument* GetDocument() const + { + return mOwnerManager->GetDocument(); + } /* * Retrieve a pointer to the principal for the document of this node info. diff --git a/mozilla/content/base/public/nsIStyledContent.h b/mozilla/content/base/public/nsIStyledContent.h index 1efd70d8249..fcc983380b5 100644 --- a/mozilla/content/base/public/nsIStyledContent.h +++ b/mozilla/content/base/public/nsIStyledContent.h @@ -47,8 +47,10 @@ class nsRuleWalker; class nsAttrValue; // IID for the nsIStyledContent class +// c59f05f5-6e39-4e98-a1ea-6c555cb7813c #define NS_ISTYLEDCONTENT_IID \ -{ 0xa7b53093, 0x3516, 0x4392, { 0xb3, 0x3e, 0x12, 0xc0, 0x0d, 0xe7, 0x85, 0xaa } }; +{ 0xc59f05f5, 0x6e39, 0x4e98, \ + { 0xa1, 0xea, 0x6c, 0x55, 0x5c, 0xb7, 0x81, 0x3c } } // Abstract interface for all styled content (that supports ID, CLASS, STYLE, and // the ability to specify style hints on an attribute change). @@ -56,6 +58,11 @@ class nsIStyledContent : public nsIContent { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTYLEDCONTENT_IID) + nsIStyledContent(nsINodeInfo *aNodeInfo) + : nsIContent(aNodeInfo) + { + } + // XXX Currently callers (e.g., CSSStyleSheetImpl) assume that the ID // corresponds to the attribute nsHTMLAtoms::id and that the Class // corresponds to the attribute nsHTMLAtoms::kClass. If this becomes diff --git a/mozilla/content/base/public/nsITextContent.h b/mozilla/content/base/public/nsITextContent.h index 5f777e1601b..d62efb8b5c1 100644 --- a/mozilla/content/base/public/nsITextContent.h +++ b/mozilla/content/base/public/nsITextContent.h @@ -38,12 +38,15 @@ #define nsITextContent_h___ #include "nsIContent.h" +#include "nsIDocument.h" class nsString; class nsTextFragment; // IID for the nsITextContent interface +// e5334e75-ac53-4447-b7fa-830e55cf5ac6 #define NS_ITEXT_CONTENT_IID \ - {0x3c4cfec2, 0x4438, 0x48df, {0xa2, 0x12, 0x30, 0x5e, 0x5a, 0xd8, 0xbb, 0xa0}} +{ 0xe5334e75, 0xac53, 0x4447, \ + { 0xb7, 0xfa, 0x83, 0x0e, 0x55, 0xcf, 0x5a, 0xc6 } } /** * Interface for textual content. This interface is used to provide @@ -53,6 +56,11 @@ class nsITextContent : public nsIContent { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITEXT_CONTENT_IID) + nsITextContent(nsINodeInfo *aNodeInfo) + : nsIContent(aNodeInfo) + { + } + /** * Get direct access (but read only) to the text in the text content. */ @@ -96,18 +104,16 @@ public: // XXX These belong elsewhere /** - * There's no need to pass in aOwnerDocument if the node is going to be - * inserted *immediately* after creation. + * aNodeInfoManager must not be null. */ nsresult -NS_NewTextNode(nsITextContent **aResult, nsIDocument *aOwnerDocument = nsnull); +NS_NewTextNode(nsITextContent **aResult, nsNodeInfoManager *aNodeInfoManager); /** - * There's no need to pass in aOwnerDocument if the node is going to be - * inserted *immediately* after creation. + * aNodeInfoManager must not be null. */ nsresult -NS_NewCommentNode(nsIContent **aResult, nsIDocument *aOwnerDocument = nsnull); +NS_NewCommentNode(nsIContent **aResult, nsNodeInfoManager *aNodeInfoManager); #endif /* nsITextContent_h___ */ diff --git a/mozilla/content/base/src/nsCommentNode.cpp b/mozilla/content/base/src/nsCommentNode.cpp index b7d4ab7edf8..9491a9d61bb 100644 --- a/mozilla/content/base/src/nsCommentNode.cpp +++ b/mozilla/content/base/src/nsCommentNode.cpp @@ -46,7 +46,7 @@ class nsCommentNode : public nsGenericDOMDataNode, public nsIDOMComment { public: - nsCommentNode(nsIDocument *aDocument); + nsCommentNode(nsINodeInfo *aNodeInfo); virtual ~nsCommentNode(); // nsISupports @@ -62,7 +62,6 @@ public: // Empty interface // nsIContent - virtual nsIAtom *Tag() const; virtual PRBool MayHaveFrame() const; virtual PRBool IsContentOfType(PRUint32 aFlags) const; @@ -77,22 +76,28 @@ public: }; nsresult -NS_NewCommentNode(nsIContent** aInstancePtrResult, nsIDocument *aOwnerDocument) +NS_NewCommentNode(nsIContent** aInstancePtrResult, + nsNodeInfoManager *aNodeInfoManager) { + NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager"); + *aInstancePtrResult = nsnull; - // XXX We really want to pass the document to the constructor, but can't - // yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=27382 - nsCOMPtr instance = new nsCommentNode(nsnull); - NS_ENSURE_TRUE(instance, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr ni = aNodeInfoManager->GetCommentNodeInfo(); + NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); - instance.swap(*aInstancePtrResult); + nsCommentNode *instance = new nsCommentNode(ni); + if (!instance) { + return NS_ERROR_OUT_OF_MEMORY; + } + + NS_ADDREF(*aInstancePtrResult = instance); return NS_OK; } -nsCommentNode::nsCommentNode(nsIDocument *aDocument) - : nsGenericDOMDataNode(aDocument) +nsCommentNode::nsCommentNode(nsINodeInfo *aNodeInfo) + : nsGenericDOMDataNode(aNodeInfo) { } @@ -115,12 +120,6 @@ NS_IMPL_ADDREF_INHERITED(nsCommentNode, nsGenericDOMDataNode) NS_IMPL_RELEASE_INHERITED(nsCommentNode, nsGenericDOMDataNode) -nsIAtom * -nsCommentNode::Tag() const -{ - return nsLayoutAtoms::commentTagName; -} - // virtual PRBool nsCommentNode::MayHaveFrame() const @@ -161,9 +160,9 @@ nsCommentNode::GetNodeType(PRUint16* aNodeType) } nsGenericDOMDataNode* -nsCommentNode::Clone(nsIDocument *aOwnerDocument, PRBool aCloneText) const +nsCommentNode::Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { - nsCommentNode *it = new nsCommentNode(aOwnerDocument); + nsCommentNode *it = new nsCommentNode(aNodeInfo); if (it && aCloneText) { it->mText = mText; } diff --git a/mozilla/content/base/src/nsContentList.cpp b/mozilla/content/base/src/nsContentList.cpp index c9c44089424..85ffef55085 100644 --- a/mozilla/content/base/src/nsContentList.cpp +++ b/mozilla/content/base/src/nsContentList.cpp @@ -710,8 +710,7 @@ nsContentList::Match(nsIContent *aContent) return PR_FALSE; } - nsINodeInfo *ni = aContent->GetNodeInfo(); - NS_ASSERTION(ni, "Element without nodeinfo!"); + nsINodeInfo *ni = aContent->NodeInfo(); if (mMatchNameSpaceId == kNameSpaceID_Unknown) { return (mMatchAll || ni->Equals(mMatchAtom)); diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 6782a597602..8b28bb7a735 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -514,19 +514,7 @@ nsContentUtils::GetDocumentAndPrincipal(nsIDOMNode* aNode, if (!domDoc) { // if we can't get a doc then lets try to get principal through nodeinfo // manager - nsINodeInfo *ni; - if (content) { - ni = content->GetNodeInfo(); - } - else { - ni = attr->NodeInfo(); - } - - if (!ni) { - // we can't get to the principal so we'll give up - - return NS_OK; - } + nsINodeInfo *ni = content ? content->NodeInfo() : attr->NodeInfo(); *aPrincipal = ni->NodeInfoManager()->GetDocumentPrincipal(); if (!*aPrincipal) { @@ -601,10 +589,8 @@ nsContentUtils::CheckSameOrigin(nsIDOMNode *aTrustedNode, nsCOMPtr cont = do_QueryInterface(aTrustedNode); NS_ENSURE_TRUE(cont, NS_ERROR_UNEXPECTED); - nsINodeInfo *ni = cont->GetNodeInfo(); - NS_ENSURE_TRUE(ni, NS_ERROR_UNEXPECTED); - - trustedPrincipal = ni->NodeInfoManager()->GetDocumentPrincipal(); + trustedPrincipal = cont->NodeInfo()->NodeInfoManager()-> + GetDocumentPrincipal(); if (!trustedPrincipal) { // Can't get principal of aTrustedNode so we can't check security @@ -832,11 +818,7 @@ nsContentUtils::ReparentContentWrapper(nsIContent *aContent, nsIDocument* old_doc = aOldDocument; if (!old_doc) { - nsINodeInfo *ni = aContent->GetNodeInfo(); - - if (ni) { - old_doc = nsContentUtils::GetDocument(ni); - } + old_doc = aContent->GetOwnerDoc(); if (!old_doc) { // If we can't find our old document we don't know what our old diff --git a/mozilla/content/base/src/nsDOMAttribute.cpp b/mozilla/content/base/src/nsDOMAttribute.cpp index 8333e303822..a6c1bd9e0fc 100644 --- a/mozilla/content/base/src/nsDOMAttribute.cpp +++ b/mozilla/content/base/src/nsDOMAttribute.cpp @@ -270,8 +270,8 @@ nsDOMAttribute::GetFirstChild(nsIDOMNode** aFirstChild) if (!value.IsEmpty()) { if (!mChild) { nsCOMPtr content; - - result = NS_NewTextNode(getter_AddRefs(content)); + result = NS_NewTextNode(getter_AddRefs(content), + mNodeInfo->NodeInfoManager()); if (NS_FAILED(result)) { return result; } diff --git a/mozilla/content/base/src/nsDOMAttributeMap.cpp b/mozilla/content/base/src/nsDOMAttributeMap.cpp index 0a7f24896ad..a6b2e21b0a3 100644 --- a/mozilla/content/base/src/nsDOMAttributeMap.cpp +++ b/mozilla/content/base/src/nsDOMAttributeMap.cpp @@ -231,12 +231,9 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode, nsAutoString nsURI; attribute->GetNamespaceURI(nsURI); - nsINodeInfo *contentNi = mContent->GetNodeInfo(); - NS_ENSURE_TRUE(contentNi, NS_ERROR_FAILURE); - - contentNi->NodeInfoManager()->GetNodeInfo(name, nsURI, - getter_AddRefs(ni)); - NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); + rv = mContent->NodeInfo()->NodeInfoManager()-> + GetNodeInfo(name, nsURI, getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); if (mContent->HasAttr(ni->NamespaceID(), ni->NameAtom())) { rv = GetAttribute(ni, getter_AddRefs(tmpReturn), PR_TRUE); @@ -252,12 +249,8 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode, NS_ENSURE_SUCCESS(rv, rv); } else { - nsINodeInfo *contentNi = mContent->GetNodeInfo(); - NS_ENSURE_TRUE(contentNi, NS_ERROR_FAILURE); - - rv = contentNi->NodeInfoManager()->GetNodeInfo(name, nsnull, - kNameSpaceID_None, - getter_AddRefs(ni)); + rv = mContent->NodeInfo()->NodeInfoManager()-> + GetNodeInfo(name, nsnull, kNameSpaceID_None, getter_AddRefs(ni)); NS_ENSURE_SUCCESS(rv, rv); // value is already empty } @@ -332,12 +325,9 @@ nsDOMAttributeMap::Item(PRUint32 aIndex, nsIDOMNode** aReturn) &nameSpaceID, getter_AddRefs(nameAtom), getter_AddRefs(prefix)))) { - nsINodeInfo *contentNi = mContent->GetNodeInfo(); - NS_ENSURE_TRUE(contentNi, NS_ERROR_FAILURE); - nsCOMPtr ni; - contentNi->NodeInfoManager()->GetNodeInfo(nameAtom, prefix, nameSpaceID, - getter_AddRefs(ni)); + mContent->NodeInfo()->NodeInfoManager()-> + GetNodeInfo(nameAtom, prefix, nameSpaceID, getter_AddRefs(ni)); NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); rv = GetAttribute(ni, aReturn); @@ -406,7 +396,7 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI, if (nameSpaceID == attrNS && nameAtom->EqualsUTF8(utf8Name)) { nsCOMPtr ni; - mContent->GetNodeInfo()->NodeInfoManager()-> + mContent->NodeInfo()->NodeInfoManager()-> GetNodeInfo(nameAtom, prefix, nameSpaceID, getter_AddRefs(ni)); NS_ENSURE_TRUE(ni, NS_ERROR_FAILURE); diff --git a/mozilla/content/base/src/nsDOMDocumentType.cpp b/mozilla/content/base/src/nsDOMDocumentType.cpp index 474e2259ca1..de676d0730c 100644 --- a/mozilla/content/base/src/nsDOMDocumentType.cpp +++ b/mozilla/content/base/src/nsDOMDocumentType.cpp @@ -43,9 +43,14 @@ #include "nsContentUtils.h" #include "nsDOMString.h" #include "nsIDOM3Node.h" +#include "nsNodeInfoManager.h" +#include "nsLayoutAtoms.h" +#include "nsIDocument.h" nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, + nsNodeInfoManager *aNodeInfoManager, + nsIPrincipal *aPrincipal, nsIAtom *aName, nsIDOMNamedNodeMap *aEntities, nsIDOMNamedNodeMap *aNotations, @@ -53,11 +58,34 @@ NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, const nsAString& aSystemId, const nsAString& aInternalSubset) { + NS_PRECONDITION(aNodeInfoManager || aPrincipal, + "Must have a principal if no nodeinfo manager."); NS_ENSURE_ARG_POINTER(aDocType); NS_ENSURE_ARG_POINTER(aName); - *aDocType = new nsDOMDocumentType(aName, aEntities, aNotations, aPublicId, - aSystemId, aInternalSubset); + nsresult rv; + + nsRefPtr nimgr; + if (aNodeInfoManager) { + nimgr = aNodeInfoManager; + } + else { + nimgr = new nsNodeInfoManager(); + NS_ENSURE_TRUE(nimgr, NS_ERROR_OUT_OF_MEMORY); + + rv = nimgr->Init(nsnull); + NS_ENSURE_SUCCESS(rv, rv); + + nimgr->SetDocumentPrincipal(aPrincipal); + } + + nsCOMPtr ni; + rv = nimgr->GetNodeInfo(nsLayoutAtoms::documentTypeNodeName, nsnull, + kNameSpaceID_None, getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); + + *aDocType = new nsDOMDocumentType(ni, aName, aEntities, aNotations, + aPublicId, aSystemId, aInternalSubset); if (!*aDocType) { return NS_ERROR_OUT_OF_MEMORY; } @@ -67,13 +95,14 @@ NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, return NS_OK; } -nsDOMDocumentType::nsDOMDocumentType(nsIAtom *aName, +nsDOMDocumentType::nsDOMDocumentType(nsINodeInfo *aNodeInfo, + nsIAtom *aName, nsIDOMNamedNodeMap *aEntities, nsIDOMNamedNodeMap *aNotations, const nsAString& aPublicId, const nsAString& aSystemId, const nsAString& aInternalSubset) : - nsGenericDOMDataNode(nsnull), + nsGenericDOMDataNode(aNodeInfo), mName(aName), mEntities(aEntities), mNotations(aNotations), @@ -158,12 +187,6 @@ nsDOMDocumentType::GetInternalSubset(nsAString& aInternalSubset) return NS_OK; } -nsIAtom * -nsDOMDocumentType::Tag() const -{ - return mName; -} - NS_IMETHODIMP nsDOMDocumentType::GetNodeName(nsAString& aNodeName) { @@ -193,9 +216,8 @@ nsDOMDocumentType::GetNodeType(PRUint16* aNodeType) } nsGenericDOMDataNode* -nsDOMDocumentType::Clone(nsIDocument *aOwnerDocument, PRBool aCloneText) const +nsDOMDocumentType::Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { - // XXX ownerDocument - return new nsDOMDocumentType(mName, mEntities, mNotations, mPublicId, - mSystemId, mInternalSubset); + return new nsDOMDocumentType(aNodeInfo, mName, mEntities, mNotations, + mPublicId, mSystemId, mInternalSubset); } diff --git a/mozilla/content/base/src/nsDOMDocumentType.h b/mozilla/content/base/src/nsDOMDocumentType.h index 88194f4d94d..d6f51e9b0d9 100644 --- a/mozilla/content/base/src/nsDOMDocumentType.h +++ b/mozilla/content/base/src/nsDOMDocumentType.h @@ -53,7 +53,8 @@ class nsDOMDocumentType : public nsGenericDOMDataNode, public nsIDOMDocumentType { public: - nsDOMDocumentType(nsIAtom *aName, + nsDOMDocumentType(nsINodeInfo* aNodeInfo, + nsIAtom *aName, nsIDOMNamedNodeMap *aEntities, nsIDOMNamedNodeMap *aNotations, const nsAString& aPublicId, @@ -71,9 +72,6 @@ public: // nsIDOMDocumentType NS_DECL_NSIDOMDOCUMENTTYPE - // nsIContent - virtual nsIAtom *Tag() const; - protected: nsCOMPtr mName; nsCOMPtr mEntities; @@ -85,6 +83,8 @@ protected: nsresult NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, + nsNodeInfoManager *aOwnerDoc, + nsIPrincipal *aPrincipal, nsIAtom *aName, nsIDOMNamedNodeMap *aEntities, nsIDOMNamedNodeMap *aNotations, diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 727e8757584..118bcf45fb7 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -541,8 +541,13 @@ nsDOMImplementation::CreateDocumentType(const nsAString& aQualifiedName, nsCOMPtr name = do_GetAtom(aQualifiedName); NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY); - return NS_NewDOMDocumentType(aReturn, name, nsnull, nsnull, - aPublicId, aSystemId, EmptyString()); + nsCOMPtr principal; + rv = nsContentUtils::SecurityManager()-> + GetCodebasePrincipal(mBaseURI, getter_AddRefs(principal)); + NS_ENSURE_SUCCESS(rv, rv); + + return NS_NewDOMDocumentType(aReturn, nsnull, principal, name, nsnull, + nsnull, aPublicId, aSystemId, EmptyString()); } NS_IMETHODIMP @@ -2567,7 +2572,7 @@ nsDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn) *aReturn = nsnull; nsCOMPtr text; - nsresult rv = NS_NewTextNode(getter_AddRefs(text), this); + nsresult rv = NS_NewTextNode(getter_AddRefs(text), mNodeInfoManager); if (NS_SUCCEEDED(rv)) { rv = CallQueryInterface(text, aReturn); @@ -2580,7 +2585,7 @@ nsDocument::CreateTextNode(const nsAString& aData, nsIDOMText** aReturn) NS_IMETHODIMP nsDocument::CreateDocumentFragment(nsIDOMDocumentFragment** aReturn) { - return NS_NewDocumentFragment(aReturn, this); + return NS_NewDocumentFragment(aReturn, mNodeInfoManager); } NS_IMETHODIMP @@ -2589,7 +2594,7 @@ nsDocument::CreateComment(const nsAString& aData, nsIDOMComment** aReturn) *aReturn = nsnull; nsCOMPtr comment; - nsresult rv = NS_NewCommentNode(getter_AddRefs(comment), this); + nsresult rv = NS_NewCommentNode(getter_AddRefs(comment), mNodeInfoManager); if (NS_SUCCEEDED(rv)) { rv = CallQueryInterface(comment, aReturn); @@ -2614,7 +2619,8 @@ nsDocument::CreateCDATASection(const nsAString& aData, return NS_ERROR_DOM_INVALID_CHARACTER_ERR; nsCOMPtr content; - nsresult rv = NS_NewXMLCDATASection(getter_AddRefs(content), this); + nsresult rv = NS_NewXMLCDATASection(getter_AddRefs(content), + mNodeInfoManager); if (NS_SUCCEEDED(rv)) { rv = CallQueryInterface(content, aReturn); @@ -2635,8 +2641,8 @@ nsDocument::CreateProcessingInstruction(const nsAString& aTarget, NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr content; - rv = NS_NewXMLProcessingInstruction(getter_AddRefs(content), aTarget, aData, - this); + rv = NS_NewXMLProcessingInstruction(getter_AddRefs(content), + mNodeInfoManager, aTarget, aData); if (NS_FAILED(rv)) { return rv; } @@ -2890,7 +2896,8 @@ nsDocument::ImportNode(nsIDOMNode* aImportedNode, NS_ENSURE_TRUE(imported, NS_ERROR_FAILURE); nsCOMPtr clone; - rv = imported->CloneContent(this, aDeep, getter_AddRefs(clone)); + rv = imported->CloneContent(mNodeInfoManager, aDeep, + getter_AddRefs(clone)); NS_ENSURE_SUCCESS(rv, rv); return CallQueryInterface(clone, aResult); diff --git a/mozilla/content/base/src/nsDocumentFragment.cpp b/mozilla/content/base/src/nsDocumentFragment.cpp index 4fcf1d4162e..c3276218eb7 100644 --- a/mozilla/content/base/src/nsDocumentFragment.cpp +++ b/mozilla/content/base/src/nsDocumentFragment.cpp @@ -172,19 +172,18 @@ protected: nsresult NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, - nsIDocument* aOwnerDocument) + nsNodeInfoManager *aNodeInfoManager) { - NS_ENSURE_ARG(aOwnerDocument); - - nsNodeInfoManager *nimgr = aOwnerDocument->NodeInfoManager(); + NS_ENSURE_ARG(aNodeInfoManager); nsCOMPtr nodeInfo; - nsresult rv = nimgr->GetNodeInfo(nsLayoutAtoms::documentFragmentNodeName, - nsnull, kNameSpaceID_None, - getter_AddRefs(nodeInfo)); + nsresult rv = + aNodeInfoManager->GetNodeInfo(nsLayoutAtoms::documentFragmentNodeName, + nsnull, kNameSpaceID_None, + getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - nsDocumentFragment* it = new nsDocumentFragment(nodeInfo); + nsDocumentFragment *it = new nsDocumentFragment(nodeInfo); if (!it) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/content/base/src/nsFrameLoader.cpp b/mozilla/content/base/src/nsFrameLoader.cpp index 0ce2252d392..58ef4f22093 100644 --- a/mozilla/content/base/src/nsFrameLoader.cpp +++ b/mozilla/content/base/src/nsFrameLoader.cpp @@ -268,16 +268,14 @@ nsFrameLoader::EnsureDocShell() NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE); nsAutoString frameName; - // Don't use mOwnerContent->GetNameSpaceID() here since it returns - // kNameSpaceID_XHTML for both HTML and XHTML, see bug 183683. - nsINodeInfo* ni = mOwnerContent->GetNodeInfo(); - if (ni && ni->NamespaceID() == kNameSpaceID_XHTML) { + PRInt32 namespaceID = mOwnerContent->GetNameSpaceID(); + if (namespaceID == kNameSpaceID_XHTML) { mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, frameName); } else { mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::name, frameName); // XXX if no NAME then use ID, after a transition period this will be // changed so that XUL only uses ID too (bug 254284). - if (frameName.IsEmpty() && ni && ni->NamespaceID() == kNameSpaceID_XUL) { + if (frameName.IsEmpty() && namespaceID == kNameSpaceID_XUL) { mOwnerContent->GetAttr(kNameSpaceID_None, nsHTMLAtoms::id, frameName); } } diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.cpp b/mozilla/content/base/src/nsGenericDOMDataNode.cpp index d3fbee56019..024d0c5ae28 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.cpp +++ b/mozilla/content/base/src/nsGenericDOMDataNode.cpp @@ -53,12 +53,13 @@ #include "nsIDOMText.h" #include "nsCOMPtr.h" #include "nsDOMString.h" +#include "nsLayoutAtoms.h" #include "pldhash.h" #include "prprf.h" -nsGenericDOMDataNode::nsGenericDOMDataNode(nsIDocument *aDocument) - : mDocument(aDocument) +nsGenericDOMDataNode::nsGenericDOMDataNode(nsINodeInfo *aNodeInfo) + : nsITextContent(aNodeInfo) { } @@ -116,8 +117,8 @@ nsGenericDOMDataNode::GetParentNode(nsIDOMNode** aParentNode) if (parent) { rv = CallQueryInterface(parent, aParentNode); } - else if (mDocument) { - rv = CallQueryInterface(mDocument, aParentNode); + else if (IsInDoc()) { + rv = CallQueryInterface(GetCurrentDoc(), aParentNode); } else { *aParentNode = nsnull; @@ -141,10 +142,13 @@ nsGenericDOMDataNode::GetPreviousSibling(nsIDOMNode** aPrevSibling) sibling = parent->GetChildAt(pos - 1); } } - else if (mDocument) { - PRInt32 pos = mDocument->IndexOf(this); - if (pos > 0) { - sibling = mDocument->GetChildAt(pos - 1); + else { + nsIDocument *doc = GetCurrentDoc(); + if (doc) { + PRInt32 pos = doc->IndexOf(this); + if (pos > 0) { + sibling = doc->GetChildAt(pos - 1); + } } } @@ -171,10 +175,13 @@ nsGenericDOMDataNode::GetNextSibling(nsIDOMNode** aNextSibling) sibling = parent->GetChildAt(pos + 1); } } - else if (mDocument) { - PRInt32 pos = mDocument->IndexOf(this); - if (pos > -1) { - sibling = mDocument->GetChildAt(pos + 1); + else { + nsIDocument *doc = GetCurrentDoc(); + if (doc) { + PRInt32 pos = doc->IndexOf(this); + if (pos > -1) { + sibling = doc->GetChildAt(pos + 1); + } } } @@ -280,10 +287,9 @@ nsGenericDOMDataNode::CloneNode(PRBool aDeep, nsIDOMNode **aResult) const { *aResult = nsnull; - nsIDocument *document = GetOwnerDoc(); - nsCOMPtr newContent; - nsresult rv = CloneContent(document, aDeep, getter_AddRefs(newContent)); + nsresult rv = CloneContent(mNodeInfo->NodeInfoManager(), aDeep, + getter_AddRefs(newContent)); NS_ENSURE_SUCCESS(rv, rv); return CallQueryInterface(newContent, aResult); @@ -604,12 +610,6 @@ nsGenericDOMDataNode::ToCString(nsAString& aBuf, PRInt32 aOffset, } #endif -nsIDocument* -nsGenericDOMDataNode::GetDocument() const -{ - return GetCurrentDoc(); -} - nsresult nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, @@ -640,15 +640,44 @@ nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // XXXbz we don't keep track of the binding parent yet. We should. + nsresult rv; + // Set parent PtrBits new_bits = NS_REINTERPRET_CAST(PtrBits, aParent); new_bits |= mParentPtrBits & nsIContent::kParentBitMask; mParentPtrBits = new_bits; // Set document - mDocument = aDocument; - if (mDocument && mText.IsBidi()) { - mDocument->SetBidiEnabled(PR_TRUE); + if (aDocument) { + mParentPtrBits |= PARENT_BIT_INDOCUMENT; + if (mText.IsBidi()) { + aDocument->SetBidiEnabled(PR_TRUE); + } + + nsIDocument *ownerDocument = GetOwnerDoc(); + if (aDocument != ownerDocument) { + // get a new nodeinfo + nsNodeInfoManager *nodeInfoManager = aDocument->NodeInfoManager(); + nsCOMPtr newNodeInfo; + // optimize common cases + nsIAtom* name = mNodeInfo->NameAtom(); + if (name == nsLayoutAtoms::textTagName) { + newNodeInfo = nodeInfoManager->GetTextNodeInfo(); + NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); + } + else if (name == nsLayoutAtoms::commentTagName) { + newNodeInfo = nodeInfoManager->GetCommentNodeInfo(); + NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); + } + else { + rv = nodeInfoManager->GetNodeInfo(name, + mNodeInfo->GetPrefixAtom(), + mNodeInfo->NamespaceID(), + getter_AddRefs(newNodeInfo)); + NS_ENSURE_SUCCESS(rv, rv); + } + mNodeInfo.swap(newNodeInfo); + } } NS_POSTCONDITION(aDocument == GetCurrentDoc(), "Bound to wrong document"); @@ -664,7 +693,7 @@ nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent, void nsGenericDOMDataNode::UnbindFromTree(PRBool aDeep, PRBool aNullParent) { - mDocument = nsnull; + mParentPtrBits &= ~PARENT_BIT_INDOCUMENT; if (aNullParent) { mParentPtrBits &= nsIContent::kParentBitMask; } @@ -683,12 +712,6 @@ nsGenericDOMDataNode::SetNativeAnonymous(PRBool aAnonymous) // XXX Need to fix this to do something - bug 165110 } -PRInt32 -nsGenericDOMDataNode::GetNameSpaceID() const -{ - return kNameSpaceID_None; -} - nsIAtom * nsGenericDOMDataNode::GetIDAttributeName() const { @@ -851,12 +874,6 @@ nsGenericDOMDataNode::ContentID() const return 0; } -nsINodeInfo * -nsGenericDOMDataNode::GetNodeInfo() const -{ - return nsnull; -} - PRUint32 nsGenericDOMDataNode::GetChildCount() const { @@ -1016,8 +1033,9 @@ nsGenericDOMDataNode::GetBaseURI() const } nsIURI *uri; - if (mDocument) { - NS_IF_ADDREF(uri = mDocument->GetBaseURI()); + nsIDocument *doc = GetOwnerDoc(); + if (doc) { + NS_IF_ADDREF(uri = doc->GetBaseURI()); } else { uri = nsnull; @@ -1056,7 +1074,7 @@ nsGenericDOMDataNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn) * as this node! */ - nsCOMPtr newContent = Clone(nsnull, PR_FALSE); + nsCOMPtr newContent = Clone(mNodeInfo, PR_FALSE); if (!newContent) { return NS_ERROR_OUT_OF_MEMORY; } @@ -1073,7 +1091,8 @@ nsGenericDOMDataNode::SplitText(PRUint32 aOffset, nsIDOMText** aReturn) parent->InsertChildAt(content, index+1, PR_TRUE); } - // XXX Shouldn't we handle the case where this is a child of the document? + // No need to handle the case of document being the parent since text + // isn't allowed as direct child of documents return CallQueryInterface(newContent, aReturn); } @@ -1328,12 +1347,22 @@ nsGenericDOMDataNode::GetCurrentValueAtom() } nsresult -nsGenericDOMDataNode::CloneContent(nsIDocument *aOwnerDocument, PRBool aDeep, - nsIContent **aResult) const +nsGenericDOMDataNode::CloneContent(nsNodeInfoManager *aNodeInfoManager, + PRBool aDeep, nsIContent **aResult) const { - // XXX We really want to pass the document to the constructor, but can't - // yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=27382 - *aResult = Clone(nsnull, PR_TRUE); + nsINodeInfo *nodeInfo = NodeInfo(); + nsCOMPtr newNodeInfo; + if (aNodeInfoManager != nodeInfo->NodeInfoManager()) { + nsresult rv = aNodeInfoManager->GetNodeInfo(nodeInfo->NameAtom(), + nodeInfo->GetPrefixAtom(), + nodeInfo->NamespaceID(), + getter_AddRefs(newNodeInfo)); + NS_ENSURE_SUCCESS(rv, rv); + + nodeInfo = newNodeInfo; + } + + *aResult = Clone(nodeInfo, PR_TRUE); if (!*aResult) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/content/base/src/nsGenericDOMDataNode.h b/mozilla/content/base/src/nsGenericDOMDataNode.h index 2765c67743f..a07db3fd881 100644 --- a/mozilla/content/base/src/nsGenericDOMDataNode.h +++ b/mozilla/content/base/src/nsGenericDOMDataNode.h @@ -55,14 +55,12 @@ class nsIDOMText; class nsINodeInfo; class nsURI; -#define PARENT_BIT_IS_IN_A_HASH ((PtrBits)0x1 << 0) - class nsGenericDOMDataNode : public nsITextContent { public: NS_DECL_ISUPPORTS - nsGenericDOMDataNode(nsIDocument *aDocument); + nsGenericDOMDataNode(nsINodeInfo *aNodeInfo); virtual ~nsGenericDOMDataNode(); // Implementation for nsIDOMNode @@ -175,37 +173,14 @@ public: const nsAString& aArg); // Implementation for nsIContent - nsIDocument* GetDocument() const; virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, PRBool aCompileEventHandlers); virtual void UnbindFromTree(PRBool aDeep = PR_TRUE, PRBool aNullParent = PR_TRUE); - PRBool IsInDoc() const - { - return !!mDocument; - } - - nsIDocument *GetCurrentDoc() const - { - return mDocument; - } - - nsIDocument *GetOwnerDoc() const - { - // XXXbz sXBL/XBL2 issue! - if (mDocument) { - return mDocument; - } - - nsIContent *parent = GetParent(); - - return parent ? parent->GetOwnerDoc() : nsnull; - } virtual PRBool IsNativeAnonymous() const; virtual void SetNativeAnonymous(PRBool aAnonymous); - virtual PRInt32 GetNameSpaceID() const; virtual nsIAtom *GetIDAttributeName() const; virtual already_AddRefed GetExistingAttrNameFromQName(const nsAString& aStr) const; nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, @@ -243,7 +218,6 @@ public: virtual nsresult GetListenerManager(nsIEventListenerManager **aResult); virtual already_AddRefed GetBaseURI() const; - virtual nsINodeInfo *GetNodeInfo() const; virtual PRUint32 GetChildCount() const; virtual nsIContent *GetChildAt(PRUint32 aIndex) const; virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const; @@ -257,7 +231,7 @@ public: * This calls Clone to do the actual cloning so that we end up with the * right class for the clone. */ - nsresult CloneContent(nsIDocument *aOwnerDocument, PRBool aDeep, + nsresult CloneContent(nsNodeInfoManager *aNodeInfoManager, PRBool aDeep, nsIContent **aResult) const; // nsITextContent @@ -288,12 +262,14 @@ protected: * @param aCloneText if true the text content will be cloned too * @return the clone */ - virtual nsGenericDOMDataNode *Clone(nsIDocument *aOwnerDocument, + virtual nsGenericDOMDataNode *Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const = 0; nsTextFragment mText; private: + enum { PARENT_BIT_IS_IN_A_HASH = 0x2 }; + void LookupListenerManager(nsIEventListenerManager **aListenerManager) const; nsVoidArray *LookupRangeList() const; @@ -329,8 +305,6 @@ private: { return GetIsInAHash() && nsGenericElement::sEventListenerManagersHash.ops; } - - nsIDocument *mDocument; }; //---------------------------------------------------------------------- @@ -341,7 +315,7 @@ private: * * Note that classes using this macro will need to implement: * NS_IMETHOD GetNodeType(PRUint16* aNodeType); - * nsGenericDOMDataNode *Clone(nsIDocument *aOwnerDocument, + * nsGenericDOMDataNode *Clone(nsINodeInfo *aNodeInfo, * PRBool aCloneText) const; */ #define NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA \ @@ -418,7 +392,7 @@ private: NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { \ return nsGenericDOMDataNode::CloneNode(aDeep, aReturn); \ } \ - virtual nsGenericDOMDataNode *Clone(nsIDocument *aOwnerDocument, \ + virtual nsGenericDOMDataNode *Clone(nsINodeInfo *aNodeInfo, \ PRBool aCloneText) const; #endif /* nsGenericDOMDataNode_h___ */ diff --git a/mozilla/content/base/src/nsGenericElement.cpp b/mozilla/content/base/src/nsGenericElement.cpp index d68b6ea136d..11b58f6d95d 100644 --- a/mozilla/content/base/src/nsGenericElement.cpp +++ b/mozilla/content/base/src/nsGenericElement.cpp @@ -284,7 +284,8 @@ nsNode3Tearoff::SetTextContent(nsIContent* aContent, if (!aTextContent.IsEmpty()) { nsCOMPtr textContent; - nsresult rv = NS_NewTextNode(getter_AddRefs(textContent)); + nsresult rv = NS_NewTextNode(getter_AddRefs(textContent), + aContent->NodeInfo()->NodeInfoManager()); NS_ENSURE_SUCCESS(rv, rv); textContent->SetText(aTextContent, PR_TRUE); @@ -807,11 +808,9 @@ nsGenericElement::Shutdown() } nsGenericElement::nsGenericElement(nsINodeInfo *aNodeInfo) - : mNodeInfo(aNodeInfo), + : nsIXMLContent(aNodeInfo), mFlagsOrSlots(GENERIC_ELEMENT_DOESNT_HAVE_DOMSLOTS) { - NS_ASSERTION(mNodeInfo, "No nsINodeInfo passed to nsGenericElement, " - "PREPARE TO CRASH!!!"); } nsGenericElement::~nsGenericElement() @@ -1947,24 +1946,6 @@ nsGenericElement::SetNativeAnonymous(PRBool aAnonymous) } } -PRInt32 -nsGenericElement::GetNameSpaceID() const -{ - return mNodeInfo->NamespaceID(); -} - -nsIAtom * -nsGenericElement::Tag() const -{ - return mNodeInfo->NameAtom(); -} - -nsINodeInfo * -nsGenericElement::GetNodeInfo() const -{ - return mNodeInfo; -} - nsresult nsGenericElement::HandleDOMEvent(nsPresContext* aPresContext, nsEvent* aEvent, @@ -4037,31 +4018,29 @@ nsGenericElement::CloneNode(PRBool aDeep, nsIDOMNode **aResult) const { *aResult = nsnull; - nsIDocument *document = GetOwnerDoc(); - nsCOMPtr newContent; - nsresult rv = CloneContent(document, aDeep, getter_AddRefs(newContent)); + nsresult rv = CloneContent(mNodeInfo->NodeInfoManager(), aDeep, + getter_AddRefs(newContent)); NS_ENSURE_SUCCESS(rv, rv); return CallQueryInterface(newContent, aResult); } nsresult -nsGenericElement::CloneContent(nsIDocument *aOwnerDocument, PRBool aDeep, - nsIContent **aResult) const +nsGenericElement::CloneContent(nsNodeInfoManager *aNodeInfoManager, + PRBool aDeep, nsIContent **aResult) const { - if (GetOwnerDoc() == aOwnerDocument) { - return Clone(mNodeInfo, aDeep, aResult); + nsINodeInfo *nodeInfo = NodeInfo(); + nsCOMPtr newNodeInfo; + if (aNodeInfoManager != nodeInfo->NodeInfoManager()) { + nsresult rv = aNodeInfoManager->GetNodeInfo(nodeInfo->NameAtom(), + nodeInfo->GetPrefixAtom(), + nodeInfo->NamespaceID(), + getter_AddRefs(newNodeInfo)); + NS_ENSURE_SUCCESS(rv, rv); + + nodeInfo = newNodeInfo; } - nsNodeInfoManager* nodeInfoManager = aOwnerDocument->NodeInfoManager(); - - nsCOMPtr newNodeInfo; - nsresult rv = nodeInfoManager->GetNodeInfo(mNodeInfo->NameAtom(), - mNodeInfo->GetPrefixAtom(), - mNodeInfo->NamespaceID(), - getter_AddRefs(newNodeInfo)); - NS_ENSURE_SUCCESS(rv, rv); - - return Clone(newNodeInfo, aDeep, aResult); + return Clone(nodeInfo, aDeep, aResult); } diff --git a/mozilla/content/base/src/nsGenericElement.h b/mozilla/content/base/src/nsGenericElement.h index 0798e215947..26eba3f778d 100644 --- a/mozilla/content/base/src/nsGenericElement.h +++ b/mozilla/content/base/src/nsGenericElement.h @@ -112,8 +112,6 @@ typedef unsigned long PtrBits; ((PRUint32)((~PtrBits(0)) >> GENERIC_ELEMENT_CONTENT_ID_BITS_OFFSET)) -#define PARENT_BIT_INDOCUMENT ((PtrBits)0x1 << 0) - /** * Class that implements the nsIDOMNodeList interface (a list of children of * the content), by holding a reference to the content and delegating GetLength @@ -372,28 +370,13 @@ public: static void Shutdown(); // nsIContent interface methods - nsIDocument* GetDocument() const - { - return IsInDoc() ? GetOwnerDoc() : nsnull; - } virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, nsIContent* aBindingParent, PRBool aCompileEventHandlers); virtual void UnbindFromTree(PRBool aDeep = PR_TRUE, PRBool aNullParent = PR_TRUE); - PRBool IsInDoc() const - { - return mParentPtrBits & PARENT_BIT_INDOCUMENT; - } - nsIDocument *GetOwnerDoc() const - { - return nsContentUtils::GetDocument(mNodeInfo); - } virtual PRBool IsNativeAnonymous() const; virtual void SetNativeAnonymous(PRBool aAnonymous); - virtual PRInt32 GetNameSpaceID() const; - virtual nsIAtom *Tag() const; - virtual nsINodeInfo *GetNodeInfo() const; virtual PRUint32 GetChildCount() const; virtual nsIContent *GetChildAt(PRUint32 aIndex) const; virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const; @@ -455,7 +438,7 @@ public: * This calls Clone to do the actual cloning so that we end up with the * right class for the clone. */ - nsresult CloneContent(nsIDocument *aOwnerDocument, PRBool aDeep, + nsresult CloneContent(nsNodeInfoManager *aNodeInfoManager, PRBool aDeep, nsIContent **aResult) const; #ifdef DEBUG @@ -843,11 +826,6 @@ protected: */ nsresult CloneNode(PRBool aDeep, nsIDOMNode **aResult) const; - /** - * Information about this type of node - */ - nsCOMPtr mNodeInfo; // OWNER - /** * Used for either storing flags for this element or a pointer to * this elements nsDOMSlots. See the definition of the diff --git a/mozilla/content/base/src/nsNodeInfo.h b/mozilla/content/base/src/nsNodeInfo.h index e8d6c9c815d..8c2a1be94e9 100644 --- a/mozilla/content/base/src/nsNodeInfo.h +++ b/mozilla/content/base/src/nsNodeInfo.h @@ -62,11 +62,6 @@ public: virtual PRBool NamespaceEquals(const nsAString& aNamespaceURI) const; virtual PRBool QualifiedNameEquals(const nsACString& aQualifiedName) const; - nsIDocument* GetDocument() const - { - return mOwnerManager->GetDocument(); - } - nsIPrincipal *GetDocumentPrincipal() const { return mOwnerManager->GetDocumentPrincipal(); diff --git a/mozilla/content/base/src/nsNodeInfoManager.cpp b/mozilla/content/base/src/nsNodeInfoManager.cpp index b7dd65acfcb..5ff2d4c6980 100644 --- a/mozilla/content/base/src/nsNodeInfoManager.cpp +++ b/mozilla/content/base/src/nsNodeInfoManager.cpp @@ -46,6 +46,7 @@ #include "nsArray.h" #include "nsContentUtils.h" #include "nsReadableUtils.h" +#include "nsLayoutAtoms.h" PRUint32 nsNodeInfoManager::gNodeManagerCount; @@ -78,7 +79,10 @@ nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2) } -nsNodeInfoManager::nsNodeInfoManager() : mDocument(nsnull) +nsNodeInfoManager::nsNodeInfoManager() + : mDocument(nsnull), + mTextNodeInfo(nsnull), + mCommentNodeInfo(nsnull) { ++gNodeManagerCount; @@ -257,6 +261,35 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aQualifiedName, return GetNodeInfo(nameAtom, prefixAtom, nsid, aNodeInfo); } +already_AddRefed +nsNodeInfoManager::GetTextNodeInfo() +{ + if (!mTextNodeInfo) { + GetNodeInfo(nsLayoutAtoms::textTagName, nsnull, kNameSpaceID_None, + &mTextNodeInfo); + } + else { + NS_ADDREF(mTextNodeInfo); + } + + return mTextNodeInfo; +} + +already_AddRefed +nsNodeInfoManager::GetCommentNodeInfo() +{ + if (!mCommentNodeInfo) { + GetNodeInfo(nsLayoutAtoms::commentTagName, nsnull, kNameSpaceID_None, + &mCommentNodeInfo); + } + else { + NS_ADDREF(mCommentNodeInfo); + } + + return mCommentNodeInfo; +} + + nsIPrincipal* nsNodeInfoManager::GetDocumentPrincipal() { @@ -289,14 +322,20 @@ nsNodeInfoManager::SetDocumentPrincipal(nsIPrincipal *aPrincipal) void nsNodeInfoManager::RemoveNodeInfo(nsNodeInfo *aNodeInfo) { - NS_WARN_IF_FALSE(aNodeInfo, "Trying to remove null nodeinfo from manager!"); + NS_PRECONDITION(aNodeInfo, "Trying to remove null nodeinfo from manager!"); - if (aNodeInfo) { -#ifdef DEBUG - PRBool ret = -#endif - PL_HashTableRemove(mNodeInfoHash, &aNodeInfo->mInner); - - NS_WARN_IF_FALSE(ret, "Can't find nsINodeInfo to remove!!!"); + // Drop weak reference if needed + if (aNodeInfo == mTextNodeInfo) { + mTextNodeInfo = nsnull; } + else if (aNodeInfo == mCommentNodeInfo) { + mCommentNodeInfo = nsnull; + } + +#ifdef DEBUG + PRBool ret = +#endif + PL_HashTableRemove(mNodeInfoHash, &aNodeInfo->mInner); + + NS_POSTCONDITION(ret, "Can't find nsINodeInfo to remove!!!"); } diff --git a/mozilla/content/base/src/nsNodeInfoManager.h b/mozilla/content/base/src/nsNodeInfoManager.h index 79c005a4fb8..1ec25a72c40 100644 --- a/mozilla/content/base/src/nsNodeInfoManager.h +++ b/mozilla/content/base/src/nsNodeInfoManager.h @@ -80,6 +80,12 @@ public: const nsAString& aNamespaceURI, nsINodeInfo** aNodeInfo); + /** + * Returns the nodeinfo for text nodes. Can return null if OOM. + */ + already_AddRefed GetTextNodeInfo(); + already_AddRefed GetCommentNodeInfo(); + /** * Retrieve a pointer to the document that owns this node info * manager. @@ -100,12 +106,6 @@ public: */ void SetDocumentPrincipal(nsIPrincipal *aPrincipal); - /** - * Populate the given nsCOMArray with all of the nsINodeInfos - * managed by this manager. - */ - nsresult GetNodeInfos(nsCOMArray *aArray); - void RemoveNodeInfo(nsNodeInfo *aNodeInfo); private: @@ -119,6 +119,8 @@ private: PLHashTable *mNodeInfoHash; nsIDocument *mDocument; // WEAK nsCOMPtr mPrincipal; + nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership + nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership static PRUint32 gNodeManagerCount; }; diff --git a/mozilla/content/base/src/nsRange.cpp b/mozilla/content/base/src/nsRange.cpp index 80eb4a88711..23b8b04b5d7 100644 --- a/mozilla/content/base/src/nsRange.cpp +++ b/mozilla/content/base/src/nsRange.cpp @@ -1732,7 +1732,8 @@ nsresult nsRange::CloneContents(nsIDOMDocumentFragment** aReturn) nsCOMPtr doc(do_QueryInterface(document)); - res = NS_NewDocumentFragment(getter_AddRefs(clonedFrag), doc); + res = NS_NewDocumentFragment(getter_AddRefs(clonedFrag), + doc->NodeInfoManager()); if (NS_FAILED(res)) return res; nsCOMPtr commonCloneAncestor(do_QueryInterface(clonedFrag)); @@ -2367,8 +2368,8 @@ nsRange::CreateContextualFragment(const nsAString& aFragment, } } if (!setDefaultNamespace) { - nsINodeInfo* info = content->GetNodeInfo(); - if (info && !info->GetPrefixAtom() && + nsINodeInfo* info = content->NodeInfo(); + if (!info->GetPrefixAtom() && info->NamespaceID() != kNameSpaceID_None) { // We have no namespace prefix, but have a namespace ID. Push // default namespace attr in, so that our kids will be in our diff --git a/mozilla/content/base/src/nsScriptLoader.cpp b/mozilla/content/base/src/nsScriptLoader.cpp index 7ef302e7aed..331e5d8f888 100644 --- a/mozilla/content/base/src/nsScriptLoader.cpp +++ b/mozilla/content/base/src/nsScriptLoader.cpp @@ -48,7 +48,6 @@ #include "nsNetUtil.h" #include "nsIScriptGlobalObject.h" #include "nsIScriptContext.h" -#include "nsINodeInfo.h" #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" #include "nsContentPolicyUtils.h" @@ -257,22 +256,17 @@ nsScriptLoader::InNonScriptingContainer(nsIScriptElement* aScriptElement) break; } - nsINodeInfo *nodeInfo = content->GetNodeInfo(); - NS_ASSERTION(nodeInfo, "element without node info"); + nsIAtom *localName = content->Tag(); - if (nodeInfo) { - nsIAtom *localName = nodeInfo->NameAtom(); - - // XXX noframes and noembed are currently unconditionally not - // displayed and processed. This might change if we support either - // prefs or per-document container settings for not allowing - // frames or plugins. - if (content->IsContentOfType(nsIContent::eHTML) && - ((localName == nsHTMLAtoms::iframe) || - (localName == nsHTMLAtoms::noframes) || - (localName == nsHTMLAtoms::noembed))) { - return PR_TRUE; - } + // XXX noframes and noembed are currently unconditionally not + // displayed and processed. This might change if we support either + // prefs or per-document container settings for not allowing + // frames or plugins. + if (content->IsContentOfType(nsIContent::eHTML) && + (localName == nsHTMLAtoms::iframe || + localName == nsHTMLAtoms::noframes || + localName == nsHTMLAtoms::noembed)) { + return PR_TRUE; } node = parent; diff --git a/mozilla/content/base/src/nsTextNode.cpp b/mozilla/content/base/src/nsTextNode.cpp index 36b7743db10..35046b41b3e 100644 --- a/mozilla/content/base/src/nsTextNode.cpp +++ b/mozilla/content/base/src/nsTextNode.cpp @@ -52,7 +52,7 @@ class nsTextNode : public nsGenericDOMDataNode, public nsIDOMText { public: - nsTextNode(nsIDocument *aDocument); + nsTextNode(nsINodeInfo *aNodeInfo); virtual ~nsTextNode(); // nsISupports @@ -68,7 +68,6 @@ public: NS_FORWARD_NSIDOMTEXT(nsGenericDOMDataNode::) // nsIContent - virtual nsIAtom *Tag() const; virtual PRBool IsContentOfType(PRUint32 aFlags) const; #ifdef DEBUG virtual void List(FILE* out, PRInt32 aIndent) const; @@ -109,7 +108,8 @@ public: nsITextContent* mContent; // Weak ref; it owns us }; - nsAttributeTextNode(nsIDocument *aDocument) : nsTextNode(aDocument) { + nsAttributeTextNode(nsINodeInfo *aNodeInfo) : nsTextNode(aNodeInfo) + { } virtual ~nsAttributeTextNode() { DetachListener(); @@ -121,10 +121,10 @@ public: virtual void UnbindFromTree(PRBool aDeep = PR_TRUE, PRBool aNullParent = PR_TRUE); - virtual nsGenericDOMDataNode *Clone(nsIDocument *aOwnerDocument, + virtual nsGenericDOMDataNode *Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { - nsAttributeTextNode *it = new nsAttributeTextNode(aOwnerDocument); + nsAttributeTextNode *it = new nsAttributeTextNode(aNodeInfo); if (it && aCloneText) { it->mText = mText; } @@ -139,22 +139,29 @@ private: nsresult NS_NewTextNode(nsITextContent** aInstancePtrResult, - nsIDocument *aOwnerDocument) + nsNodeInfoManager *aNodeInfoManager) { + NS_PRECONDITION(aNodeInfoManager, "Missing nodeInfoManager"); + *aInstancePtrResult = nsnull; - // XXX We really want to pass the document to the constructor, but can't - // yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=27382 - nsCOMPtr instance = new nsTextNode(nsnull); - NS_ENSURE_TRUE(instance, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr ni = aNodeInfoManager->GetTextNodeInfo(); + if (!ni) { + return NS_ERROR_OUT_OF_MEMORY; + } - instance.swap(*aInstancePtrResult); + nsITextContent *instance = new nsTextNode(ni); + if (!instance) { + return NS_ERROR_OUT_OF_MEMORY; + } + + NS_ADDREF(*aInstancePtrResult = instance); return NS_OK; } -nsTextNode::nsTextNode(nsIDocument *aDocument) - : nsGenericDOMDataNode(aDocument) +nsTextNode::nsTextNode(nsINodeInfo *aNodeInfo) + : nsGenericDOMDataNode(aNodeInfo) { } @@ -175,12 +182,6 @@ NS_INTERFACE_MAP_BEGIN(nsTextNode) NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(Text) NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode) -nsIAtom * -nsTextNode::Tag() const -{ - return nsLayoutAtoms::textTagName; -} - NS_IMETHODIMP nsTextNode::GetNodeName(nsAString& aNodeName) { @@ -214,9 +215,9 @@ nsTextNode::IsContentOfType(PRUint32 aFlags) const } nsGenericDOMDataNode* -nsTextNode::Clone(nsIDocument *aOwnerDocument, PRBool aCloneText) const +nsTextNode::Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { - nsTextNode *it = new nsTextNode(aOwnerDocument); + nsTextNode *it = new nsTextNode(aNodeInfo); if (it && aCloneText) { it->mText = mText; } @@ -300,18 +301,25 @@ nsAttributeTextNode::nsAttrChangeListener::HandleEvent(nsIDOMEvent* aEvent) } nsresult -NS_NewAttributeContent(nsIDocument *aOwnerDoc, PRInt32 aNameSpaceID, - nsIAtom* aAttrName, nsIContent** aResult) +NS_NewAttributeContent(nsNodeInfoManager *aNodeInfoManager, + PRInt32 aNameSpaceID, nsIAtom* aAttrName, + nsIContent** aResult) { + NS_PRECONDITION(aNodeInfoManager, "Missing nodeInfoManager"); NS_PRECONDITION(aAttrName, "Must have an attr name"); NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "Must know namespace"); *aResult = nsnull; - // XXX We really want to pass the document to the constructor, but can't - // yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=27382 - nsRefPtr textNode = new nsAttributeTextNode(nsnull); - NS_ENSURE_TRUE(textNode, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr ni = aNodeInfoManager->GetTextNodeInfo(); + if (!ni) { + return NS_ERROR_OUT_OF_MEMORY; + } + + nsRefPtr textNode = new nsAttributeTextNode(ni); + if (!textNode) { + return NS_ERROR_OUT_OF_MEMORY; + } textNode->mListener = new nsAttributeTextNode::nsAttrChangeListener(aNameSpaceID, @@ -320,6 +328,7 @@ NS_NewAttributeContent(nsIDocument *aOwnerDoc, PRInt32 aNameSpaceID, NS_ENSURE_TRUE(textNode->mListener, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(*aResult = textNode); + return NS_OK; } diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index 1e5646d826a..8ea62133fec 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -5193,7 +5193,7 @@ nsEventStateManager::IsFrameSetDoc(nsIDocShell* aDocShell) for (PRUint32 i = 0; i < childCount; ++i) { nsIContent *childContent = rootContent->GetChildAt(i); - nsINodeInfo *ni = childContent->GetNodeInfo(); + nsINodeInfo *ni = childContent->NodeInfo(); if (childContent->IsContentOfType(nsIContent::eHTML) && ni->Equals(nsHTMLAtoms::frameset)) { diff --git a/mozilla/content/events/src/nsXMLEventsManager.cpp b/mozilla/content/events/src/nsXMLEventsManager.cpp index dda55a6621c..6d9ced7e50a 100644 --- a/mozilla/content/events/src/nsXMLEventsManager.cpp +++ b/mozilla/content/events/src/nsXMLEventsManager.cpp @@ -56,7 +56,8 @@ PRBool nsXMLEventsListener::InitXMLEventsListener(nsIDocument * aDocument, PRInt32 nameSpaceID; if (aContent->GetDocument() != aDocument) return PR_FALSE; - if (aContent->GetNodeInfo()->Equals(nsHTMLAtoms::listener, kNameSpaceID_XMLEvents)) + if (aContent->NodeInfo()->Equals(nsHTMLAtoms::listener, + kNameSpaceID_XMLEvents)) nameSpaceID = kNameSpaceID_None; else nameSpaceID = kNameSpaceID_XMLEvents; @@ -375,7 +376,8 @@ nsXMLEventsManager::AttributeChanged(nsIDocument* aDocument, nsXMLEventsListener::InitXMLEventsListener(aDocument, this, aContent); } else { - if (aContent->GetNodeInfo()->Equals(nsHTMLAtoms::listener, kNameSpaceID_XMLEvents)) { + if (aContent->NodeInfo()->Equals(nsHTMLAtoms::listener, + kNameSpaceID_XMLEvents)) { RemoveListener(aContent); AddXMLEventsContent(aContent); nsXMLEventsListener::InitXMLEventsListener(aDocument, this, aContent); diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index fe640470731..c9eca02f960 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -560,20 +560,18 @@ nsGenericHTMLElement::RecreateFrames() static PRBool IsBody(nsIContent *aContent) { - nsINodeInfo *ni = aContent->GetNodeInfo(); - - return (ni && ni->Equals(nsHTMLAtoms::body) && + return (aContent->NodeInfo()->Equals(nsHTMLAtoms::body) && aContent->IsContentOfType(nsIContent::eHTML)); } static PRBool IsOffsetParent(nsIContent *aContent) { - nsINodeInfo *ni = aContent->GetNodeInfo(); + nsINodeInfo *ni = aContent->NodeInfo(); - return (ni && (ni->Equals(nsHTMLAtoms::td) || - ni->Equals(nsHTMLAtoms::table) || - ni->Equals(nsHTMLAtoms::th)) && + return ((ni->Equals(nsHTMLAtoms::td) || + ni->Equals(nsHTMLAtoms::table) || + ni->Equals(nsHTMLAtoms::th)) && aContent->IsContentOfType(nsIContent::eHTML)); } @@ -1337,8 +1335,8 @@ nsGenericHTMLElement::FindForm(nsIForm* aCurrentForm) nsIContent* content = this; while (content) { // If the current ancestor is a form, return it as our form - if (content->IsContentOfType(nsIContent::eHTML) && - content->GetNodeInfo()->Equals(nsHTMLAtoms::form)) { + if (content->Tag() == nsHTMLAtoms::form && + content->IsContentOfType(nsIContent::eHTML)) { nsIDOMHTMLFormElement* form; CallQueryInterface(content, &form); @@ -1390,9 +1388,7 @@ nsGenericHTMLElement::FindForm(nsIForm* aCurrentForm) static PRBool IsArea(nsIContent *aContent) { - nsINodeInfo *ni = aContent->GetNodeInfo(); - - return (ni && ni->Equals(nsHTMLAtoms::area) && + return (aContent->Tag() == nsHTMLAtoms::area && aContent->IsContentOfType(nsIContent::eHTML)); } @@ -2596,8 +2592,6 @@ nsGenericHTMLElement::ParseStyleAttribute(nsIContent* aContent, nsAttrValue& aResult) { nsresult result = NS_OK; - NS_ASSERTION(aContent->GetNodeInfo(), "If we don't have a nodeinfo, we are very screwed"); - nsIDocument* doc = aContent->GetOwnerDoc(); if (doc) { @@ -2990,7 +2984,7 @@ nsGenericHTMLElement::ReplaceContentsWithText(const nsAString& aText, rv = textChild->SetData(aText); } else { nsCOMPtr text; - rv = NS_NewTextNode(getter_AddRefs(text)); + rv = NS_NewTextNode(getter_AddRefs(text), mNodeInfo->NodeInfoManager()); NS_ENSURE_SUCCESS(rv, rv); text->SetText(aText, PR_TRUE); diff --git a/mozilla/content/html/content/src/nsHTMLOptionElement.cpp b/mozilla/content/html/content/src/nsHTMLOptionElement.cpp index 795ba6934f2..a2836cbd445 100644 --- a/mozilla/content/html/content/src/nsHTMLOptionElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLOptionElement.cpp @@ -400,7 +400,7 @@ nsHTMLOptionElement::SetText(const nsAString& aText) if (!usedExistingTextNode) { nsCOMPtr text; - rv = NS_NewTextNode(getter_AddRefs(text)); + rv = NS_NewTextNode(getter_AddRefs(text), mNodeInfo->NodeInfoManager()); NS_ENSURE_SUCCESS(rv, rv); text->SetText(aText, PR_TRUE); @@ -482,8 +482,8 @@ nsHTMLOptionElement::Initialize(JSContext* aContext, if (jsstr) { // Create a new text node and append it to the option nsCOMPtr textContent; - - result = NS_NewTextNode(getter_AddRefs(textContent)); + result = NS_NewTextNode(getter_AddRefs(textContent), + mNodeInfo->NodeInfoManager()); if (NS_FAILED(result)) { return result; } diff --git a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp index bc7e2e050aa..58f5caa7361 100644 --- a/mozilla/content/html/content/src/nsHTMLSelectElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLSelectElement.cpp @@ -648,9 +648,7 @@ nsHTMLSelectElement::RemoveOptionsFromList(nsIContent* aOptions, static PRBool IsOptGroup(nsIContent *aContent) { - nsINodeInfo *ni = aContent->GetNodeInfo(); - - return (ni && ni->Equals(nsHTMLAtoms::optgroup) && + return (aContent->NodeInfo()->Equals(nsHTMLAtoms::optgroup) && aContent->IsContentOfType(nsIContent::eHTML)); } @@ -1059,7 +1057,7 @@ nsHTMLSelectElement::SetLength(PRUint32 aLength) } nsCOMPtr text; - rv = NS_NewTextNode(getter_AddRefs(text)); + rv = NS_NewTextNode(getter_AddRefs(text), mNodeInfo->NodeInfoManager()); NS_ENSURE_SUCCESS(rv, rv); rv = element->AppendChildTo(text, PR_FALSE); diff --git a/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp b/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp index 00fcb86c23a..1fb0687d3b2 100644 --- a/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableCellElement.cpp @@ -135,7 +135,7 @@ nsHTMLTableCellElement::GetTable() nsIContent* section = parent->GetParent(); if (section) { if (section->IsContentOfType(eHTML) && - section->GetNodeInfo()->Equals(nsHTMLAtoms::table)) { + section->NodeInfo()->Equals(nsHTMLAtoms::table)) { // XHTML, without a row group result = section; } else { diff --git a/mozilla/content/html/content/src/nsHTMLTableElement.cpp b/mozilla/content/html/content/src/nsHTMLTableElement.cpp index 32c3f410fac..459a42cfc39 100644 --- a/mozilla/content/html/content/src/nsHTMLTableElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLTableElement.cpp @@ -400,7 +400,7 @@ nsHTMLTableElement::GetSection(nsIAtom *aTag) section = do_QueryInterface(child); - if (section && child->GetNodeInfo()->Equals(aTag)) { + if (section && child->NodeInfo()->Equals(aTag)) { nsIDOMHTMLTableSectionElement *result = section; NS_ADDREF(result); @@ -729,11 +729,12 @@ nsHTMLTableElement::InsertRow(PRInt32 aIndex, nsIDOMHTMLElement** aValue) PRUint32 childCount = GetChildCount(); for (PRUint32 i = 0; i < childCount; ++i) { nsIContent* child = GetChildAt(i); - nsINodeInfo* childInfo = child->GetNodeInfo(); - if (childInfo && - (childInfo->Equals(nsHTMLAtoms::thead, namespaceID) || - childInfo->Equals(nsHTMLAtoms::tbody, namespaceID) || - childInfo->Equals(nsHTMLAtoms::tfoot, namespaceID))) { + nsINodeInfo *childInfo = child->NodeInfo(); + nsIAtom *localName = childInfo->NameAtom(); + if (childInfo->NamespaceID() == namespaceID && + (localName == nsHTMLAtoms::thead || + localName == nsHTMLAtoms::tbody || + localName == nsHTMLAtoms::tfoot)) { rowGroup = do_QueryInterface(child); NS_ASSERTION(rowGroup, "HTML node did not QI to nsIDOMNode"); break; diff --git a/mozilla/content/html/document/src/nsHTMLContentSink.cpp b/mozilla/content/html/document/src/nsHTMLContentSink.cpp index cc461cfd154..73e03958aff 100644 --- a/mozilla/content/html/document/src/nsHTMLContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLContentSink.cpp @@ -1566,7 +1566,8 @@ SinkContext::AddComment(const nsIParserNode& aNode) } nsCOMPtr comment; - nsresult rv = NS_NewCommentNode(getter_AddRefs(comment)); + nsresult rv = NS_NewCommentNode(getter_AddRefs(comment), + mSink->mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr domComment(do_QueryInterface(comment)); @@ -1811,7 +1812,8 @@ SinkContext::FlushText(PRBool* aDidFlush, PRBool aReleaseLast) } } else { nsCOMPtr textContent; - rv = NS_NewTextNode(getter_AddRefs(textContent)); + rv = NS_NewTextNode(getter_AddRefs(textContent), + mSink->mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); mLastTextNode = textContent; diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 293205c694d..5e0370e4a50 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1680,28 +1680,26 @@ PRBool nsHTMLDocument::MatchLinks(nsIContent *aContent, PRInt32 aNamespaceID, nsIAtom* aAtom, const nsAString& aData) { - nsINodeInfo *ni = aContent->GetNodeInfo(); - - if (ni) { - NS_ASSERTION(aContent->IsInDoc(), - "This method should never be called on content nodes that " - "are not in a document!"); + NS_ASSERTION(aContent->IsInDoc(), + "This method should never be called on content nodes that " + "are not in a document!"); #ifdef DEBUG - { - nsCOMPtr htmldoc = - do_QueryInterface(aContent->GetCurrentDoc()); - NS_ASSERTION(htmldoc, - "Huh, how did this happen? This should only be used with " - "HTML documents!"); - } + { + nsCOMPtr htmldoc = + do_QueryInterface(aContent->GetCurrentDoc()); + NS_ASSERTION(htmldoc, + "Huh, how did this happen? This should only be used with " + "HTML documents!"); + } #endif - PRInt32 namespaceID = aContent->GetCurrentDoc()->GetDefaultNamespaceID(); + nsINodeInfo *ni = aContent->NodeInfo(); + PRInt32 namespaceID = aContent->GetCurrentDoc()->GetDefaultNamespaceID(); - if (ni->Equals(nsHTMLAtoms::a, namespaceID) || - ni->Equals(nsHTMLAtoms::area, namespaceID)) { - return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::href); - } + nsIAtom *localName = ni->NameAtom(); + if (ni->NamespaceID() == namespaceID && + (localName == nsHTMLAtoms::a || localName == nsHTMLAtoms::area)) { + return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::href); } return PR_FALSE; @@ -1727,26 +1725,22 @@ PRBool nsHTMLDocument::MatchAnchors(nsIContent *aContent, PRInt32 aNamespaceID, nsIAtom* aAtom, const nsAString& aData) { - nsINodeInfo *ni = aContent->GetNodeInfo(); - - if (ni) { - NS_ASSERTION(aContent->IsInDoc(), - "This method should never be called on content nodes that " - "are not in a document!"); + NS_ASSERTION(aContent->IsInDoc(), + "This method should never be called on content nodes that " + "are not in a document!"); #ifdef DEBUG - { - nsCOMPtr htmldoc = - do_QueryInterface(aContent->GetCurrentDoc()); - NS_ASSERTION(htmldoc, - "Huh, how did this happen? This should only be used with " - "HTML documents!"); - } + { + nsCOMPtr htmldoc = + do_QueryInterface(aContent->GetCurrentDoc()); + NS_ASSERTION(htmldoc, + "Huh, how did this happen? This should only be used with " + "HTML documents!"); + } #endif - if (ni->Equals(nsHTMLAtoms::a, - aContent->GetCurrentDoc()->GetDefaultNamespaceID())) { - return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::name); - } + PRInt32 namespaceID = aContent->GetCurrentDoc()->GetDefaultNamespaceID(); + if (aContent->NodeInfo()->Equals(nsHTMLAtoms::a, namespaceID)) { + return aContent->HasAttr(kNameSpaceID_None, nsHTMLAtoms::name); } return PR_FALSE; @@ -3380,9 +3374,8 @@ nsHTMLDocument::GetBodyContent() nsIContent *child = mRootContent->GetChildAt(i); NS_ENSURE_TRUE(child, NS_ERROR_UNEXPECTED); - if (child->IsContentOfType(nsIContent::eHTML) && - child->GetNodeInfo()->Equals(nsHTMLAtoms::body, - mDefaultNamespaceID)) { + if (child->NodeInfo()->Equals(nsHTMLAtoms::body, mDefaultNamespaceID) && + child->IsContentOfType(nsIContent::eHTML)) { mBodyContent = do_QueryInterface(child); return PR_TRUE; diff --git a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp index d598f0b23ee..4168cef8782 100644 --- a/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/mozilla/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -244,10 +244,10 @@ nsHTMLFragmentContentSink::WillBuildModel(void) return NS_OK; } - NS_ASSERTION(mTargetDocument, "Need a document!"); + NS_ASSERTION(mNodeInfoManager, "Need a nodeinfo manager!"); nsCOMPtr frag; - nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mTargetDocument); + nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); mRoot = do_QueryInterface(frag, &rv); @@ -588,7 +588,7 @@ nsHTMLFragmentContentSink::AddComment(const nsIParserNode& aNode) FlushText(); - result = NS_NewCommentNode(&comment); + result = NS_NewCommentNode(&comment, mNodeInfoManager); if (NS_SUCCEEDED(result)) { result = CallQueryInterface(comment, &domComment); if (NS_SUCCEEDED(result)) { @@ -767,7 +767,7 @@ nsHTMLFragmentContentSink::AddTextToContent(nsIContent* aContent, const nsAStrin if(aContent) { if (!aText.IsEmpty()) { nsCOMPtr text; - result = NS_NewTextNode(getter_AddRefs(text)); + result = NS_NewTextNode(getter_AddRefs(text), mNodeInfoManager); if (NS_SUCCEEDED(result)) { text->SetText(aText, PR_TRUE); @@ -786,7 +786,7 @@ nsHTMLFragmentContentSink::FlushText() } nsCOMPtr content; - nsresult rv = NS_NewTextNode(getter_AddRefs(content)); + nsresult rv = NS_NewTextNode(getter_AddRefs(content), mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); // Set the text in the text node diff --git a/mozilla/content/svg/content/src/nsSVGElementFactory.cpp b/mozilla/content/svg/content/src/nsSVGElementFactory.cpp index 7d6ed2504ac..d5281e2bbc9 100644 --- a/mozilla/content/svg/content/src/nsSVGElementFactory.cpp +++ b/mozilla/content/svg/content/src/nsSVGElementFactory.cpp @@ -136,7 +136,7 @@ NS_NewSVGElement(nsIContent** aResult, nsINodeInfo *aNodeInfo) static const char kSVGStyleSheetURI[] = "resource://gre/res/svg.css"; // this bit of code is to load svg.css on demand - nsIDocument* doc = nsContentUtils::GetDocument(aNodeInfo); + nsIDocument *doc = aNodeInfo->GetDocument(); if (doc) doc->EnsureCatalogStyleSheet(kSVGStyleSheetURI); diff --git a/mozilla/content/xbl/src/nsXBLBinding.cpp b/mozilla/content/xbl/src/nsXBLBinding.cpp index b17e0ac73ee..bae3d3dab75 100644 --- a/mozilla/content/xbl/src/nsXBLBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLBinding.cpp @@ -493,10 +493,11 @@ nsXBLBinding::GenerateAnonymousContent() children->Item(i, getter_AddRefs(node)); childContent = do_QueryInterface(node); - nsINodeInfo *ni = childContent->GetNodeInfo(); - - if (!ni || (!ni->Equals(nsXULAtoms::observes, kNameSpaceID_XUL) && - !ni->Equals(nsXULAtoms::templateAtom, kNameSpaceID_XUL))) { + nsINodeInfo *ni = childContent->NodeInfo(); + nsIAtom *localName = ni->NameAtom(); + if (ni->NamespaceID() != kNameSpaceID_XUL || + (localName != nsXULAtoms::observes && + localName != nsXULAtoms::templateAtom)) { hasContent = PR_FALSE; break; } @@ -568,11 +569,11 @@ nsXBLBinding::GenerateAnonymousContent() // We were unable to place this child. All anonymous content // should be thrown out. Special-case template and observes. - nsINodeInfo *ni = childContent->GetNodeInfo(); - - if (!ni || - (!ni->Equals(nsXULAtoms::observes, kNameSpaceID_XUL) && - !ni->Equals(nsXULAtoms::templateAtom, kNameSpaceID_XUL))) { + nsINodeInfo *ni = childContent->NodeInfo(); + nsIAtom *localName = ni->NameAtom(); + if (ni->NamespaceID() != kNameSpaceID_XUL || + (localName != nsXULAtoms::observes && + localName != nsXULAtoms::templateAtom)) { // Kill all anonymous content. mContent = nsnull; bindingManager->SetContentListFor(mBoundElement, nsnull); diff --git a/mozilla/content/xbl/src/nsXBLContentSink.cpp b/mozilla/content/xbl/src/nsXBLContentSink.cpp index 8c3af6f5cdf..21f824c0f4d 100644 --- a/mozilla/content/xbl/src/nsXBLContentSink.cpp +++ b/mozilla/content/xbl/src/nsXBLContentSink.cpp @@ -171,10 +171,11 @@ nsXBLContentSink::FlushText(PRBool aCreateTextNode, } nsIContent* content = GetCurrentContent(); - if (content && (content->GetNodeInfo()->NamespaceEquals(kNameSpaceID_XBL) || ( - content->GetNodeInfo()->NamespaceEquals(kNameSpaceID_XUL) && - content->Tag() != nsXULAtoms::label && - content->Tag() != nsXULAtoms::description))) { + if (content && + (content->NodeInfo()->NamespaceEquals(kNameSpaceID_XBL) || + (content->NodeInfo()->NamespaceEquals(kNameSpaceID_XUL) && + content->Tag() != nsXULAtoms::label && + content->Tag() != nsXULAtoms::description))) { PRBool isWS = PR_TRUE; if (mTextLength > 0) { @@ -307,8 +308,8 @@ nsXBLContentSink::HandleEndElement(const PRUnichar *aName) if (mState == eXBL_Error) { // Check whether we've opened this tag before; we may not have if // it was a real XBL tag before the error occured. - if (!GetCurrentContent()->GetNodeInfo()->Equals(localName, - nameSpaceID)) { + if (!GetCurrentContent()->NodeInfo()->Equals(localName, + nameSpaceID)) { // OK, this tag was never opened as far as the XML sink is // concerned. Just drop the HandleEndElement return NS_OK; diff --git a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp index 01ce0fdfb1f..022f67de66a 100644 --- a/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/mozilla/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -508,8 +508,8 @@ nsXBLPrototypeBinding::AttributeChanged(nsIAtom* aAttribute, // xbl:text set on us. if ((dstAttr == nsHTMLAtoms::text && dstNs == kNameSpaceID_XBL) || - realElement->GetNodeInfo()->Equals(nsHTMLAtoms::html, - kNameSpaceID_XUL) && + realElement->NodeInfo()->Equals(nsHTMLAtoms::html, + kNameSpaceID_XUL) && dstAttr == nsHTMLAtoms::value) { // Flush out all our kids. PRUint32 childCount = realElement->GetChildCount(); @@ -522,7 +522,8 @@ nsXBLPrototypeBinding::AttributeChanged(nsIAtom* aAttribute, aChangedElement->GetAttr(aNameSpaceID, aAttribute, value); if (!value.IsEmpty()) { nsCOMPtr textContent; - NS_NewTextNode(getter_AddRefs(textContent)); + NS_NewTextNode(getter_AddRefs(textContent), + realElement->NodeInfo()->NodeInfoManager()); if (!textContent) { continue; } @@ -721,10 +722,8 @@ nsXBLPrototypeBinding::GetImmediateChild(nsIAtom* aTag) PRUint32 childCount = mBinding->GetChildCount(); for (PRUint32 i = 0; i < childCount; i++) { - nsIContent *child = mBinding->GetChildAt(i); - nsINodeInfo *childNodeInfo = child->GetNodeInfo(); - - if (childNodeInfo && childNodeInfo->Equals(aTag, kNameSpaceID_XBL)) { + nsIContent* child = mBinding->GetChildAt(i); + if (child->NodeInfo()->Equals(aTag, kNameSpaceID_XBL)) { return child; } } @@ -761,9 +760,8 @@ nsXBLPrototypeBinding::LocateInstance(nsIContent* aBoundElement, nsCOMPtr childPoint; if (aBoundElement) { - nsINodeInfo *ni = templParent->GetNodeInfo(); - - if (ni->Equals(nsXBLAtoms::children, kNameSpaceID_XBL)) { + if (templParent->NodeInfo()->Equals(nsXBLAtoms::children, + kNameSpaceID_XBL)) { childPoint = templParent; templParent = childPoint->GetParent(); } @@ -888,11 +886,13 @@ PRBool PR_CALLBACK SetAttrs(nsHashKey* aKey, void* aData, void* aClosure) realElement->SetAttr(dstNs, dst, value, PR_FALSE); if ((dst == nsHTMLAtoms::text && dstNs == kNameSpaceID_XBL) || - (realElement->GetNodeInfo()->Equals(nsHTMLAtoms::html, - kNameSpaceID_XUL) && + (realElement->NodeInfo()->Equals(nsHTMLAtoms::html, + kNameSpaceID_XUL) && dst == nsHTMLAtoms::value && !value.IsEmpty())) { + nsCOMPtr textContent; - NS_NewTextNode(getter_AddRefs(textContent)); + NS_NewTextNode(getter_AddRefs(textContent), + realElement->NodeInfo()->NodeInfoManager()); if (!textContent) { continue; } @@ -988,9 +988,7 @@ nsXBLPrototypeBinding::ConstructAttributeTable(nsIContent* aElement) { // Don't add entries for elements, since those will get // removed from the DOM when we construct the insertion point table. - nsINodeInfo* nodeInfo = aElement->GetNodeInfo(); - if (nodeInfo && !nodeInfo->Equals(nsXBLAtoms::children, - kNameSpaceID_XBL)) { + if (!aElement->NodeInfo()->Equals(nsXBLAtoms::children, kNameSpaceID_XBL)) { nsAutoString inherits; aElement->GetAttr(kNameSpaceID_XBL, nsXBLAtoms::inherits, inherits); @@ -1288,8 +1286,7 @@ nsXBLPrototypeBinding::GetNestedChildren(nsIAtom* aTag, PRInt32 aNamespace, for (PRUint32 i = 0; i < childCount; i++) { nsIContent *child = aContent->GetChildAt(i); - nsINodeInfo *nodeInfo = child->GetNodeInfo(); - if (nodeInfo && nodeInfo->Equals(aTag, aNamespace)) { + if (child->NodeInfo()->Equals(aTag, aNamespace)) { aList.AppendObject(child); } else diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index 3e9147c7636..9d019df7ce3 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -1061,7 +1061,7 @@ nsXBLService::LoadBindingDocumentInfo(nsIContent* aBoundElement, nsINodeInfo *ni = nsnull; if (aBoundElement) - ni = aBoundElement->GetNodeInfo(); + ni = aBoundElement->NodeInfo(); if (!info && bindingManager && (!ni || !(ni->Equals(nsXULAtoms::scrollbar, kNameSpaceID_XUL) || @@ -1153,7 +1153,7 @@ nsXBLService::FetchBindingDocument(nsIContent* aBoundElement, nsIDocument* aBoun nsINodeInfo *ni = nsnull; if (aBoundElement) - ni = aBoundElement->GetNodeInfo(); + ni = aBoundElement->NodeInfo(); if (ni && (ni->Equals(nsXULAtoms::scrollbar, kNameSpaceID_XUL) || ni->Equals(nsXULAtoms::thumb, kNameSpaceID_XUL) || diff --git a/mozilla/content/xml/content/public/nsIXMLContent.h b/mozilla/content/xml/content/public/nsIXMLContent.h index cc1d3b11745..c11c35f23b5 100644 --- a/mozilla/content/xml/content/public/nsIXMLContent.h +++ b/mozilla/content/xml/content/public/nsIXMLContent.h @@ -44,9 +44,10 @@ class nsIDocShell; +// ded21e95-2484-4735-a29a-af778335ecfe #define NS_IXMLCONTENT_IID \ - { 0xb9df7adc, 0x3262, 0x4692, \ - { 0xbb, 0x97, 0xb7, 0xd5, 0xab, 0xdf, 0x85, 0x9c } } + { 0xded21e95, 0x2484, 0x4735, \ + { 0xa2, 0x9a, 0xaf, 0x77, 0x83, 0x35, 0xec, 0xfe } } /** * XML content extensions to nsIContent @@ -55,6 +56,11 @@ class nsIXMLContent : public nsIStyledContent { public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXMLCONTENT_IID) + nsIXMLContent(nsINodeInfo *aNodeInfo) + : nsIStyledContent(aNodeInfo) + { + } + /** * Give this element a chance to fire links that should be fired * automatically when loaded. If the element was an autoloading link diff --git a/mozilla/content/xml/content/src/nsXMLCDATASection.cpp b/mozilla/content/xml/content/src/nsXMLCDATASection.cpp index c4186083790..0c4af858dc8 100644 --- a/mozilla/content/xml/content/src/nsXMLCDATASection.cpp +++ b/mozilla/content/xml/content/src/nsXMLCDATASection.cpp @@ -46,7 +46,7 @@ class nsXMLCDATASection : public nsGenericDOMDataNode, public nsIDOMCDATASection { public: - nsXMLCDATASection(nsIDocument *aDocument); + nsXMLCDATASection(nsINodeInfo *aNodeInfo); virtual ~nsXMLCDATASection(); // nsISupports @@ -65,7 +65,6 @@ public: // Empty interface // nsIContent - virtual nsIAtom *Tag() const; virtual PRBool IsContentOfType(PRUint32 aFlags) const; #ifdef DEBUG virtual void List(FILE* out, PRInt32 aIndent) const; @@ -75,20 +74,30 @@ public: nsresult NS_NewXMLCDATASection(nsIContent** aInstancePtrResult, - nsIDocument *aOwnerDocument) + nsNodeInfoManager *aNodeInfoManager) { + NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager"); + *aInstancePtrResult = nsnull; - nsCOMPtr instance = new nsXMLCDATASection(nsnull); - NS_ENSURE_TRUE(instance, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr ni; + nsresult rv = aNodeInfoManager->GetNodeInfo(nsLayoutAtoms::cdataTagName, + nsnull, kNameSpaceID_None, + getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); - instance.swap(*aInstancePtrResult); + nsXMLCDATASection *instance = new nsXMLCDATASection(ni); + if (!instance) { + return NS_ERROR_OUT_OF_MEMORY; + } + + NS_ADDREF(*aInstancePtrResult = instance); return NS_OK; } -nsXMLCDATASection::nsXMLCDATASection(nsIDocument *aDocument) - : nsGenericDOMDataNode(aDocument) +nsXMLCDATASection::nsXMLCDATASection(nsINodeInfo *aNodeInfo) + : nsGenericDOMDataNode(aNodeInfo) { } @@ -111,12 +120,6 @@ NS_IMPL_ADDREF_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode) NS_IMPL_RELEASE_INHERITED(nsXMLCDATASection, nsGenericDOMDataNode) -nsIAtom * -nsXMLCDATASection::Tag() const -{ - return nsLayoutAtoms::cdataTagName; -} - PRBool nsXMLCDATASection::IsContentOfType(PRUint32 aFlags) const { @@ -150,9 +153,9 @@ nsXMLCDATASection::GetNodeType(PRUint16* aNodeType) } nsGenericDOMDataNode* -nsXMLCDATASection::Clone(nsIDocument *aOwnerDocument, PRBool aCloneText) const +nsXMLCDATASection::Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { - nsXMLCDATASection* it = new nsXMLCDATASection(aOwnerDocument); + nsXMLCDATASection *it = new nsXMLCDATASection(aNodeInfo); if (it && aCloneText) { it->mText = mText; } diff --git a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp index b8d3ae6ba7a..b0cfeb40c72 100644 --- a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -44,31 +44,41 @@ nsresult NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult, + nsNodeInfoManager *aNodeInfoManager, const nsAString& aTarget, - const nsAString& aData, - nsIDocument *aOwnerDocument) + const nsAString& aData) { + NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager"); + if (aTarget.EqualsLiteral("xml-stylesheet")) { - return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult, aData, - aOwnerDocument); + return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult, + aNodeInfoManager, aData); } *aInstancePtrResult = nsnull; - nsCOMPtr instance; - instance = new nsXMLProcessingInstruction(aTarget, aData, - nsnull); - NS_ENSURE_TRUE(instance, NS_ERROR_OUT_OF_MEMORY); + nsCOMPtr ni; + nsresult rv = + aNodeInfoManager->GetNodeInfo(nsLayoutAtoms::processingInstructionTagName, + nsnull, kNameSpaceID_None, + getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); - instance.swap(*aInstancePtrResult); + nsXMLProcessingInstruction *instance = + new nsXMLProcessingInstruction(ni, aTarget, aData); + if (!instance) { + return NS_ERROR_OUT_OF_MEMORY; + } + + NS_ADDREF(*aInstancePtrResult = instance); return NS_OK; } -nsXMLProcessingInstruction::nsXMLProcessingInstruction(const nsAString& aTarget, - const nsAString& aData, - nsIDocument *aDocument) - : nsGenericDOMDataNode(aDocument), +nsXMLProcessingInstruction::nsXMLProcessingInstruction(nsINodeInfo *aNodeInfo, + const nsAString& aTarget, + const nsAString& aData) + : nsGenericDOMDataNode(aNodeInfo), mTarget(aTarget) { nsGenericDOMDataNode::SetData(aData); @@ -121,12 +131,6 @@ nsXMLProcessingInstruction::GetAttrValue(const nsAString& aAttr, return nsParserUtils::GetQuotedAttributeValue(data, aAttr, aValue); } -nsIAtom * -nsXMLProcessingInstruction::Tag() const -{ - return nsLayoutAtoms::processingInstructionTagName; -} - PRBool nsXMLProcessingInstruction::IsContentOfType(PRUint32 aFlags) const { @@ -167,13 +171,13 @@ nsXMLProcessingInstruction::GetNodeType(PRUint16* aNodeType) } nsGenericDOMDataNode* -nsXMLProcessingInstruction::Clone(nsIDocument *aOwnerDocument, +nsXMLProcessingInstruction::Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { nsAutoString data; nsGenericDOMDataNode::GetData(data); - return new nsXMLProcessingInstruction(mTarget, data, aOwnerDocument); + return new nsXMLProcessingInstruction(aNodeInfo, mTarget, data); } #ifdef DEBUG diff --git a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.h b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.h index e32b20b2dad..22c95ed4298 100644 --- a/mozilla/content/xml/content/src/nsXMLProcessingInstruction.h +++ b/mozilla/content/xml/content/src/nsXMLProcessingInstruction.h @@ -49,9 +49,9 @@ class nsXMLProcessingInstruction : public nsGenericDOMDataNode, public nsIDOMProcessingInstruction { public: - nsXMLProcessingInstruction(const nsAString& aTarget, - const nsAString& aData, - nsIDocument *aDocument); + nsXMLProcessingInstruction(nsINodeInfo *aNodeInfo, + const nsAString& aTarget, + const nsAString& aData); virtual ~nsXMLProcessingInstruction(); // nsISupports @@ -64,7 +64,6 @@ public: NS_DECL_NSIDOMPROCESSINGINSTRUCTION // nsIContent - virtual nsIAtom *Tag() const; virtual PRBool IsContentOfType(PRUint32 aFlags) const; virtual PRBool MayHaveFrame() const; diff --git a/mozilla/content/xml/content/src/nsXMLStylesheetPI.cpp b/mozilla/content/xml/content/src/nsXMLStylesheetPI.cpp index 0e58dbe6a97..c83017e596a 100644 --- a/mozilla/content/xml/content/src/nsXMLStylesheetPI.cpp +++ b/mozilla/content/xml/content/src/nsXMLStylesheetPI.cpp @@ -46,12 +46,13 @@ #include "nsXMLProcessingInstruction.h" #include "nsUnicharUtils.h" #include "nsParserUtils.h" +#include "nsLayoutAtoms.h" class nsXMLStylesheetPI : public nsXMLProcessingInstruction, public nsStyleLinkElement { public: - nsXMLStylesheetPI(const nsAString& aData, nsIDocument *aDocument); + nsXMLStylesheetPI(nsINodeInfo *aNodeInfo, const nsAString& aData); virtual ~nsXMLStylesheetPI(); // nsISupports @@ -77,7 +78,7 @@ protected: nsAString& aType, nsAString& aMedia, PRBool* aIsAlternate); - virtual nsGenericDOMDataNode* Clone(nsIDocument *aOwnerDocument, + virtual nsGenericDOMDataNode* Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const; }; @@ -93,10 +94,10 @@ NS_IMPL_ADDREF_INHERITED(nsXMLStylesheetPI, nsXMLProcessingInstruction) NS_IMPL_RELEASE_INHERITED(nsXMLStylesheetPI, nsXMLProcessingInstruction) -nsXMLStylesheetPI::nsXMLStylesheetPI(const nsAString& aData, - nsIDocument *aDocument) : - nsXMLProcessingInstruction(NS_LITERAL_STRING("xml-stylesheet"), aData, - aDocument) +nsXMLStylesheetPI::nsXMLStylesheetPI(nsINodeInfo *aNodeInfo, + const nsAString& aData) + : nsXMLProcessingInstruction(aNodeInfo, NS_LITERAL_STRING("xml-stylesheet"), + aData) { } @@ -235,27 +236,36 @@ nsXMLStylesheetPI::GetStyleSheetInfo(nsAString& aTitle, } nsGenericDOMDataNode* -nsXMLStylesheetPI::Clone(nsIDocument *aOwnerDocument, PRBool aCloneText) const +nsXMLStylesheetPI::Clone(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { nsAutoString data; nsGenericDOMDataNode::GetData(data); - return new nsXMLStylesheetPI(data, aOwnerDocument); + return new nsXMLStylesheetPI(aNodeInfo, data); } nsresult NS_NewXMLStylesheetProcessingInstruction(nsIContent** aInstancePtrResult, - const nsAString& aData, - nsIDocument *aOwnerDocument) + nsNodeInfoManager *aNodeInfoManager, + const nsAString& aData) { + NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager"); + *aInstancePtrResult = nsnull; - nsCOMPtr instance = new nsXMLStylesheetPI(aData, nsnull); + nsCOMPtr ni; + nsresult rv = + aNodeInfoManager->GetNodeInfo(nsLayoutAtoms::processingInstructionTagName, + nsnull, kNameSpaceID_None, + getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); + + nsXMLStylesheetPI *instance = new nsXMLStylesheetPI(ni, aData); if (!instance) { return NS_ERROR_OUT_OF_MEMORY; } - instance.swap(*aInstancePtrResult); + NS_ADDREF(*aInstancePtrResult = instance); return NS_OK; } diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index eebd7228abc..a2fd12f970a 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -453,7 +453,7 @@ nsXMLContentSink::CreateElement(const PRUnichar** aAtts, PRUint32 aAttsCount, nsIContent* parent = GetCurrentContent(); if (mDocument && mDocument->GetDocumentTitle().IsVoid() && parent && parent == mDocElement && - parent->GetNodeInfo()->Equals(nsSVGAtoms::svg, kNameSpaceID_SVG)) { + parent->NodeInfo()->Equals(nsSVGAtoms::svg, kNameSpaceID_SVG)) { mInTitle = PR_TRUE; // The first title wins } } @@ -485,7 +485,7 @@ nsXMLContentSink::CloseElement(nsIContent* aContent, nsIContent* aParent, *aAppendContent = PR_FALSE; - nsINodeInfo* nodeInfo = aContent->GetNodeInfo(); + nsINodeInfo *nodeInfo = aContent->NodeInfo(); // Some HTML nodes need DoneAddingChildren() called to initialize // properly (eg form state restoration). @@ -738,7 +738,7 @@ nsXMLContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush) if (0 != mTextLength) { if (aCreateTextNode) { nsCOMPtr textContent; - rv = NS_NewTextNode(getter_AddRefs(textContent)); + rv = NS_NewTextNode(getter_AddRefs(textContent), mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); // Set the text in the text node @@ -828,7 +828,7 @@ NS_NewMathMLElement(nsIContent** aResult, nsINodeInfo* aNodeInfo) aNodeInfo->SetIDAttributeAtom(nsHTMLAtoms::id); // this bit of code is to load mathml.css on demand - nsIDocument* doc = nsContentUtils::GetDocument(aNodeInfo); + nsIDocument *doc = aNodeInfo->GetDocument(); if (doc) doc->EnsureCatalogStyleSheet(kMathMLStyleSheetURI); @@ -992,7 +992,7 @@ nsXMLContentSink::HandleEndElement(const PRUnichar *aName) nsContentUtils::SplitExpatName(aName, getter_AddRefs(debugNameSpacePrefix), getter_AddRefs(debugTagAtom), &debugNameSpaceID); - NS_ASSERTION(content->GetNodeInfo()->Equals(debugTagAtom, debugNameSpaceID), + NS_ASSERTION(content->NodeInfo()->Equals(debugTagAtom, debugNameSpaceID), "Wrong element being closed"); #endif @@ -1038,16 +1038,16 @@ nsXMLContentSink::HandleComment(const PRUnichar *aName) FlushText(); nsCOMPtr comment; - nsresult result = NS_NewCommentNode(getter_AddRefs(comment)); + nsresult rv = NS_NewCommentNode(getter_AddRefs(comment), mNodeInfoManager); if (comment) { - nsCOMPtr domComment = do_QueryInterface(comment, &result); + nsCOMPtr domComment = do_QueryInterface(comment, &rv); if (domComment) { domComment->AppendData(nsDependentString(aName)); - result = AddContentAsLeaf(comment); + rv = AddContentAsLeaf(comment); } } - return result; + return rv; } NS_IMETHODIMP @@ -1061,16 +1061,16 @@ nsXMLContentSink::HandleCDataSection(const PRUnichar *aData, } nsCOMPtr cdata; - nsresult result = NS_NewXMLCDATASection(getter_AddRefs(cdata)); + nsresult rv = NS_NewXMLCDATASection(getter_AddRefs(cdata), mNodeInfoManager); if (cdata) { nsCOMPtr domCDATA = do_QueryInterface(cdata); if (domCDATA) { domCDATA->SetData(nsDependentString(aData, aLength)); - result = AddContentAsLeaf(cdata); + rv = AddContentAsLeaf(cdata); } } - return result; + return rv; } NS_IMETHODIMP @@ -1093,8 +1093,9 @@ nsXMLContentSink::HandleDoctypeDecl(const nsAString & aSubset, // Create a new doctype node nsCOMPtr docType; - rv = NS_NewDOMDocumentType(getter_AddRefs(docType), name, nsnull, nsnull, - aPublicId, aSystemId, aSubset); + rv = NS_NewDOMDocumentType(getter_AddRefs(docType), mNodeInfoManager, nsnull, + name, nsnull, nsnull, aPublicId, aSystemId, + aSubset); if (NS_FAILED(rv) || !docType) { return rv; } @@ -1148,7 +1149,8 @@ nsXMLContentSink::HandleProcessingInstruction(const PRUnichar *aTarget, nsCOMPtr node; - result = NS_NewXMLProcessingInstruction(getter_AddRefs(node), target, data); + result = NS_NewXMLProcessingInstruction(getter_AddRefs(node), + mNodeInfoManager, target, data); if (NS_OK == result) { nsCOMPtr ssle(do_QueryInterface(node)); diff --git a/mozilla/content/xml/document/src/nsXMLFragmentContentSink.cpp b/mozilla/content/xml/document/src/nsXMLFragmentContentSink.cpp index 940824129f3..3474747effb 100644 --- a/mozilla/content/xml/document/src/nsXMLFragmentContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLFragmentContentSink.cpp @@ -171,7 +171,7 @@ nsXMLFragmentContentSink::WillBuildModel(void) NS_ASSERTION(mTargetDocument, "Need a document!"); nsCOMPtr frag; - nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mTargetDocument); + nsresult rv = NS_NewDocumentFragment(getter_AddRefs(frag), mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); mRoot = do_QueryInterface(frag); @@ -283,7 +283,8 @@ nsXMLFragmentContentSink::HandleProcessingInstruction(const PRUnichar *aTarget, nsCOMPtr node; - result = NS_NewXMLProcessingInstruction(getter_AddRefs(node), target, data); + result = NS_NewXMLProcessingInstruction(getter_AddRefs(node), + mNodeInfoManager, target, data); if (NS_SUCCEEDED(result)) { // no special processing here. that should happen when the fragment moves into the document result = AddContentAsLeaf(node); diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index ba8035a3e4d..9cfa7075f54 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -395,7 +395,7 @@ NS_NewXULElement(nsIContent** aResult, nsINodeInfo *aNodeInfo) { gFaults.Create++; gFaults.Total++; nsAutoString tagstr; - element->GetNodeInfo()->GetQualifiedName(tagstr); + element->NodeInfo()->GetQualifiedName(tagstr); char *tagcstr = ToNewCString(tagstr); fprintf(stderr, "XUL: Heavyweight create of <%s>: %d/%d\n", tagcstr, gFaults.Create, gFaults.Total); @@ -1076,8 +1076,7 @@ nsXULElement::RemoveChildAt(PRUint32 aIndex, PRBool aNotify) // anything else = index to re-set as current PRInt32 newCurrentIndex = -1; - nsINodeInfo *ni = oldKid->GetNodeInfo(); - if (ni && ni->Equals(nsXULAtoms::listitem, kNameSpaceID_XUL)) { + if (oldKid->NodeInfo()->Equals(nsXULAtoms::listitem, kNameSpaceID_XUL)) { // This is the nasty case. We have (potentially) a slew of selected items // and cells going away. // First, retrieve the tree. @@ -2535,8 +2534,8 @@ nsXULElement::GetParentTree(nsIDOMXULMultiSelectControlElement** aTreeElement) { for (nsIContent* current = GetParent(); current; current = current->GetParent()) { - if (current->GetNodeInfo()->Equals(nsXULAtoms::listbox, - kNameSpaceID_XUL)) { + if (current->NodeInfo()->Equals(nsXULAtoms::listbox, + kNameSpaceID_XUL)) { CallQueryInterface(current, aTreeElement); // XXX returning NS_OK because that's what the code used to do; // is that the right thing, though? diff --git a/mozilla/content/xul/content/src/nsXULPopupListener.cpp b/mozilla/content/xul/content/src/nsXULPopupListener.cpp index a660340210e..115716079dd 100644 --- a/mozilla/content/xul/content/src/nsXULPopupListener.cpp +++ b/mozilla/content/xul/content/src/nsXULPopupListener.cpp @@ -556,9 +556,8 @@ XULPopupListenerImpl::LaunchPopup(PRInt32 aClientX, PRInt32 aClientY) list->Item(ctr, getter_AddRefs(node)); nsCOMPtr childContent(do_QueryInterface(node)); - nsINodeInfo *ni = childContent->GetNodeInfo(); - - if (ni && ni->Equals(nsXULAtoms::menupopup, kNameSpaceID_XUL)) { + if (childContent->NodeInfo()->Equals(nsXULAtoms::menupopup, + kNameSpaceID_XUL)) { popupContent = do_QueryInterface(childContent); break; } diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 7bea0f1c3cf..75c2d280526 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -1027,8 +1027,7 @@ nsXULDocument::ExecuteOnBroadcastHandlerFor(nsIContent* aBroadcaster, // attriubtes we're listening for. nsIContent *child = listener->GetChildAt(i); - nsINodeInfo *ni = child->GetNodeInfo(); - if (!ni || !ni->Equals(nsXULAtoms::observes, kNameSpaceID_XUL)) + if (!child->NodeInfo()->Equals(nsXULAtoms::observes, kNameSpaceID_XUL)) continue; // Is this the element that was listening to us? @@ -1721,10 +1720,8 @@ nsXULDocument::AddElementToDocumentPre(nsIContent* aElement) nsresult nsXULDocument::AddElementToDocumentPost(nsIContent* aElement) { - nsINodeInfo *ni = aElement->GetNodeInfo(); - // We need to pay special attention to the keyset tag to set up a listener - if (ni && ni->Equals(nsXULAtoms::keyset, kNameSpaceID_XUL)) { + if (aElement->NodeInfo()->Equals(nsXULAtoms::keyset, kNameSpaceID_XUL)) { // Create our XUL key listener and hook it up. nsCOMPtr xblService(do_GetService("@mozilla.org/xbl;1")); if (xblService) { @@ -1762,10 +1759,13 @@ nsXULDocument::AddElementToDocumentPost(nsIContent* aElement) NS_IMETHODIMP nsXULDocument::AddSubtreeToDocument(nsIContent* aElement) { - nsresult rv; + // From here on we only care about elements. + if (!aElement->IsContentOfType(nsIContent::eELEMENT)) { + return NS_OK; + } // Do pre-order addition magic - rv = AddElementToDocumentPre(aElement); + nsresult rv = AddElementToDocumentPre(aElement); if (NS_FAILED(rv)) return rv; // Recurse to children @@ -1787,6 +1787,11 @@ nsXULDocument::AddSubtreeToDocument(nsIContent* aElement) NS_IMETHODIMP nsXULDocument::RemoveSubtreeFromDocument(nsIContent* aElement) { + // From here on we only care about elements. + if (!aElement->IsContentOfType(nsIContent::eELEMENT)) { + return NS_OK; + } + // Do a bunch of cleanup to remove an element from the XUL // document. nsresult rv; @@ -2396,9 +2401,8 @@ nsXULDocument::ContextStack::IsInsideXULTemplate() for (nsIContent* element = mTop->mElement; element; element = element->GetParent()) { - nsINodeInfo *ni = element->GetNodeInfo(); - - if (ni && ni->Equals(nsXULAtoms::Template, kNameSpaceID_XUL)) { + if (element->NodeInfo()->Equals(nsXULAtoms::Template, + kNameSpaceID_XUL)) { return PR_TRUE; } } @@ -2894,7 +2898,8 @@ nsXULDocument::ResumeWalk() NS_ASSERTION(element, "no element on context stack"); nsCOMPtr text; - rv = NS_NewTextNode(getter_AddRefs(text)); + rv = NS_NewTextNode(getter_AddRefs(text), + mNodeInfoManager); NS_ENSURE_SUCCESS(rv, rv); nsXULPrototypeText* textproto = @@ -3587,7 +3592,7 @@ nsXULDocument::CreateTemplateBuilder(nsIContent* aElement) xblService->ResolveTag(aElement, &nameSpaceID, getter_AddRefs(baseTag)); } else { - nsINodeInfo *ni = aElement->GetNodeInfo(); + nsINodeInfo *ni = aElement->NodeInfo(); nameSpaceID = ni->NamespaceID(); baseTag = ni->NameAtom(); } @@ -4033,12 +4038,15 @@ nsXULDocument::FindBroadcaster(nsIContent* aElement, nsString& aAttribute, nsIDOMElement** aBroadcaster) { + NS_ASSERTION(aElement->IsContentOfType(nsIContent::eELEMENT), + "Only pass elements into FindBroadcaster!"); + nsresult rv; - nsINodeInfo *ni = aElement->GetNodeInfo(); + nsINodeInfo *ni = aElement->NodeInfo(); *aListener = nsnull; *aBroadcaster = nsnull; - if (ni && ni->Equals(nsXULAtoms::observes, kNameSpaceID_XUL)) { + if (ni->Equals(nsXULAtoms::observes, kNameSpaceID_XUL)) { // It's an element, which means that the actual // listener is the _parent_ node. This element should have an // 'element' attribute that specifies the ID of the @@ -4048,7 +4056,8 @@ nsXULDocument::FindBroadcaster(nsIContent* aElement, // If we're still parented by an 'overlay' tag, then we haven't // made it into the real document yet. Defer hookup. - if (parent->GetNodeInfo()->Equals(nsXULAtoms::overlay, kNameSpaceID_XUL)) { + if (parent->NodeInfo()->Equals(nsXULAtoms::overlay, + kNameSpaceID_XUL)) { return NS_FINDBROADCASTER_AWAIT_OVERLAYS; } diff --git a/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp b/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp index 89697d62c00..19198484aa4 100644 --- a/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp +++ b/mozilla/content/xul/templates/src/nsXULContentBuilder.cpp @@ -653,7 +653,8 @@ nsXULContentBuilder::BuildContentFromTemplate(nsIContent *aTemplateNode, if (NS_FAILED(rv)) return rv; nsCOMPtr content; - rv = NS_NewTextNode(getter_AddRefs(content)); + rv = NS_NewTextNode(getter_AddRefs(content), + mRoot->NodeInfo()->NodeInfoManager()); if (NS_FAILED(rv)) return rv; content->SetText(value, PR_FALSE); @@ -1019,7 +1020,7 @@ nsXULContentBuilder::IsDirectlyContainedBy(nsIContent* aChild, nsIContent* aPare // The content within a template ends when we hit the //