From 2c8e09cceba4e85631bba0d1c1f2f1bcdceea385 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Thu, 25 Oct 2001 04:08:29 +0000 Subject: [PATCH] Fixing bug 106571. We can live w/o storing a nsINameSpace pointer in our XUL and XML elements (which saves us 4 bytes for every XML (read XBL) element and for the XUL slots), also remove the accessors from the interface nsIXMLContent, and remove some unused code in nsXULContentUtils. r=dbaron@netscape.com, sr=waterson@netscape.com --- content/base/src/nsGenericElement.cpp | 124 +++++++------ content/xbl/src/nsXBLService.cpp | 40 ++-- content/xml/content/public/nsIXMLContent.h | 5 +- content/xml/content/src/nsXMLElement.cpp | 31 +--- content/xml/content/src/nsXMLElement.h | 3 - content/xml/document/src/nsXMLContentSink.cpp | 6 - content/xul/content/src/nsXULElement.cpp | 71 -------- content/xul/content/src/nsXULElement.h | 5 - content/xul/document/src/nsXULContentSink.cpp | 8 - .../xul/templates/src/nsXULContentUtils.cpp | 171 ------------------ content/xul/templates/src/nsXULContentUtils.h | 12 -- 11 files changed, 91 insertions(+), 385 deletions(-) diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index 73559e3536c..8f825cfc0a3 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -456,7 +456,7 @@ NS_IMETHODIMP nsNode3Tearoff::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, nsAWritableString& aPrefix) { - aPrefix.Truncate(); + SetDOMStringToNull(aPrefix); // XXX Waiting for DOM spec to list error codes. @@ -464,6 +464,19 @@ nsNode3Tearoff::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, nsCOMPtr ni; mContent->GetNodeInfo(*getter_AddRefs(ni)); + + if (!ni) { + // If there's no nodeinfo (i.e. mContent is a non-element node), + // check if the parent has nodeinfo + nsCOMPtr parent; + + mContent->GetParent(*getter_AddRefs(parent)); + + if (parent) { + parent->GetNodeInfo(*getter_AddRefs(ni)); + } + } + if (ni) { nsCOMPtr nimgr; @@ -476,12 +489,11 @@ nsNode3Tearoff::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, // If there's no nodeinfo, get the manager from the document if (!manager) { nsCOMPtr doc; - mContent->GetDocument(*getter_AddRefs(doc)); - if (!doc) { - return NS_ERROR_UNEXPECTED; - } + mContent->GetDocument(*getter_AddRefs(doc)); - doc->GetNameSpaceManager(*getter_AddRefs(manager)); + if (doc) { + doc->GetNameSpaceManager(*getter_AddRefs(manager)); + } } if (!manager) { @@ -492,79 +504,77 @@ nsNode3Tearoff::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI, PRInt32 namespaceId; manager->GetNameSpaceID(aNamespaceURI, namespaceId); if (namespaceId == kNameSpaceID_Unknown) { - return NS_ERROR_FAILURE; + return NS_OK; } - // Trace up the content parent chain looking for XML content. - // From there, look for a prefix associated with the namespace. - nsCOMPtr content(mContent); + nsAutoString ns; + + // Trace up the content parent chain looking for the namespace + // declaration that defines the aNamespaceURI namespace. Once found, + // return the prefix (i.e. the attribute localName). + nsCOMPtr content(mContent); while (content) { - nsCOMPtr xmlContent(do_QueryInterface(content)); - - if (xmlContent) { - nsCOMPtr ns; - - xmlContent->GetContainingNameSpace(*getter_AddRefs(ns)); - if (ns) { - nsCOMPtr prefix; - nsresult rv = ns->FindNameSpacePrefix(namespaceId, - *getter_AddRefs(prefix)); - if (NS_FAILED(rv)) { - return NS_ERROR_FAILURE; + PRInt32 attrCount, i; + + nsCOMPtr name, prefix; + PRInt32 namespace_id; + + content->GetAttrCount(attrCount); + + for (i = 0; i < attrCount; i++) { + content->GetAttrNameAt(i, namespace_id, *getter_AddRefs(name), + *getter_AddRefs(prefix)); + + if (namespace_id == kNameSpaceID_XMLNS) { + nsresult rv = content->GetAttr(namespace_id, name, ns); + + if (rv == NS_CONTENT_ATTR_HAS_VALUE && + ns.Equals(aNamespaceURI)) { + name->ToString(aPrefix); + + return NS_OK; } - if (prefix) { - prefix->ToString(aPrefix); - } - return NS_OK; } } - + nsCOMPtr tmp(content); tmp->GetParent(*getter_AddRefs(content)); } - - return NS_ERROR_FAILURE; + + return NS_OK; } NS_IMETHODIMP nsNode3Tearoff::LookupNamespaceURI(const nsAReadableString& aNamespacePrefix, nsAWritableString& aNamespaceURI) { - aNamespaceURI.Truncate(); + nsCOMPtr name; + + if (!aNamespacePrefix.IsEmpty()) { + name = dont_AddRef(NS_NewAtom(aNamespacePrefix)); + NS_ENSURE_TRUE(name, NS_ERROR_OUT_OF_MEMORY); + } else { + name = nsLayoutAtoms::xmlnsNameSpace; + } + + // Trace up the content parent chain looking for the namespace + // declaration that declares aNamespacePrefix. + nsCOMPtr content(mContent); - // Trace up the content parent chain looking for XML content. From - // there, see if anyone up the chain knows about the prefix. - nsCOMPtr content(mContent); while (content) { - nsCOMPtr xmlContent(do_QueryInterface(content)); - - if (xmlContent) { - nsCOMPtr ns; - - xmlContent->GetContainingNameSpace(*getter_AddRefs(ns)); - if (ns) { - nsCOMPtr prefix; - nsCOMPtr foundNS; - - if (!aNamespacePrefix.IsEmpty()) { - prefix = dont_AddRef(NS_NewAtom(aNamespacePrefix)); - } + nsresult rv = content->GetAttr(kNameSpaceID_XMLNS, name, aNamespaceURI); - nsresult rv = ns->FindNameSpace(prefix, *getter_AddRefs(foundNS)); - if (NS_FAILED(rv)) { - return NS_ERROR_FAILURE; - } - - foundNS->GetNameSpaceURI(aNamespaceURI); - return NS_OK; - } + if (rv == NS_CONTENT_ATTR_HAS_VALUE) { + return NS_OK; } - + nsCOMPtr tmp(content); tmp->GetParent(*getter_AddRefs(content)); } - - return NS_ERROR_FAILURE; + + SetDOMStringToNull(aNamespaceURI); + + return NS_OK; } diff --git a/content/xbl/src/nsXBLService.cpp b/content/xbl/src/nsXBLService.cpp index 88ddf48342e..6b253bbfda6 100644 --- a/content/xbl/src/nsXBLService.cpp +++ b/content/xbl/src/nsXBLService.cpp @@ -59,7 +59,6 @@ #include "nsNetUtil.h" #include "plstr.h" #include "nsIContent.h" -#include "nsIXMLContent.h" #include "nsIDOMElement.h" #include "nsIDocument.h" #include "nsIXMLContentSink.h" @@ -1072,30 +1071,35 @@ NS_IMETHODIMP nsXBLService::GetBindingInternal(nsIContent* aBoundElement, } } - nsCOMPtr tagSpace; + nsAutoString nameSpace; + if (prefix.Length() > 0) { nsCOMPtr prefixAtom = getter_AddRefs(NS_NewAtom(prefix)); - nsCOMPtr nameSpace; - nsCOMPtr xmlContent(do_QueryInterface(child)); - if (xmlContent) { - xmlContent->GetContainingNameSpace(*getter_AddRefs(nameSpace)); - if (nameSpace) { - nameSpace->FindNameSpace(prefixAtom, *getter_AddRefs(tagSpace)); - if (tagSpace) { - if (!hasDisplay) { - // We extend some widget/frame. We don't really have a base binding. - protoBinding->SetHasBasePrototype(PR_FALSE); - } - PRInt32 nameSpaceID; - tagSpace->GetNameSpaceID(nameSpaceID); - nsCOMPtr tagName = getter_AddRefs(NS_NewAtom(display)); - protoBinding->SetBaseTag(nameSpaceID, tagName); + + nsCOMPtr node(do_QueryInterface(child)); + + if (node) { + node->LookupNamespaceURI(prefix, nameSpace); + + if (!nameSpace.IsEmpty()) { + if (!hasDisplay) { + // We extend some widget/frame. We don't really have a + // base binding. + + protoBinding->SetHasBasePrototype(PR_FALSE); } + + PRInt32 nameSpaceID; + + gNameSpaceManager->GetNameSpaceID(nameSpace, nameSpaceID); + + nsCOMPtr tagName = getter_AddRefs(NS_NewAtom(display)); + protoBinding->SetBaseTag(nameSpaceID, tagName); } } } - if (hasExtends && (hasDisplay || (!hasDisplay && !tagSpace))) { + if (hasExtends && (hasDisplay || nameSpace.IsEmpty())) { // Look up the prefix. // We have a base class binding. Load it right now. nsCAutoString urlCString; urlCString.AssignWithConversion(value); diff --git a/content/xml/content/public/nsIXMLContent.h b/content/xml/content/public/nsIXMLContent.h index 1ab81b7cab1..db99dad880e 100644 --- a/content/xml/content/public/nsIXMLContent.h +++ b/content/xml/content/public/nsIXMLContent.h @@ -57,10 +57,7 @@ class nsIURI; */ class nsIXMLContent : public nsIStyledContent { public: - static const nsIID& GetIID() { static nsIID iid = NS_IXMLCONTENT_IID; return iid; } - - NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace) = 0; - NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const = 0; + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IXMLCONTENT_IID) /** * Give this element a change to fire its links that should be fired diff --git a/content/xml/content/src/nsXMLElement.cpp b/content/xml/content/src/nsXMLElement.cpp index 11dbf98d87e..4643cf40f76 100644 --- a/content/xml/content/src/nsXMLElement.cpp +++ b/content/xml/content/src/nsXMLElement.cpp @@ -103,10 +103,8 @@ static nsIAtom* kOnLoadAtom; static nsIAtom* kEmbedAtom; static PRUint32 kElementCount; -nsXMLElement::nsXMLElement() : mNameSpace(nsnull) +nsXMLElement::nsXMLElement() : mIsLink(PR_FALSE) { - mIsLink = PR_FALSE; - if (0 == kElementCount++) { kSimpleAtom = NS_NewAtom("simple"); kHrefAtom = NS_NewAtom("href"); @@ -131,8 +129,6 @@ nsXMLElement::~nsXMLElement() NS_RELEASE(kOnLoadAtom); NS_RELEASE(kEmbedAtom); } - - NS_IF_RELEASE(mNameSpace); } @@ -570,9 +566,6 @@ nsXMLElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) CopyInnerTo(this, it, aDeep); - it->mNameSpace = mNameSpace; - NS_IF_ADDREF(it->mNameSpace); - return it->QueryInterface(NS_GET_IID(nsIDOMNode), (void**) aReturn); } @@ -663,28 +656,6 @@ nsXMLElement::GetScriptObject(nsIScriptContext* aContext, void** aScriptObject) } #endif -NS_IMETHODIMP -nsXMLElement::SetContainingNameSpace(nsINameSpace* aNameSpace) -{ - NS_IF_RELEASE(mNameSpace); - - mNameSpace = aNameSpace; - - NS_IF_ADDREF(mNameSpace); - - return NS_OK; -} - -NS_IMETHODIMP -nsXMLElement::GetContainingNameSpace(nsINameSpace*& aNameSpace) const -{ - aNameSpace = mNameSpace; - NS_IF_ADDREF(aNameSpace); - - return NS_OK; -} - - // nsIStyledContent implementation NS_IMETHODIMP diff --git a/content/xml/content/src/nsXMLElement.h b/content/xml/content/src/nsXMLElement.h index 8cb94d2dad3..a6904b12fe7 100644 --- a/content/xml/content/src/nsXMLElement.h +++ b/content/xml/content/src/nsXMLElement.h @@ -69,8 +69,6 @@ public: NS_FORWARD_NSIDOMELEMENT(nsGenericContainerElement::) // nsIXMLContent - NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace); - NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const; NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell); NS_IMETHOD GetXMLBaseURI(nsIURI **aURI); @@ -95,7 +93,6 @@ public: protected: PRBool mIsLink; - nsINameSpace* mNameSpace; }; #endif // nsXMLElement_h___ diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index a60bfc6d815..4ff0892aab0 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -897,12 +897,6 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode) } } nsINameSpace* nameSpace = PopNameSpaces(); - if (content) { - nsCOMPtr xmlContent = do_QueryInterface(content); - if (xmlContent) { - xmlContent->SetContainingNameSpace(nameSpace); - } - } NS_IF_RELEASE(nameSpace); if (mNeedToBlockParser || (mParser && !mParser->IsParserEnabled())) { diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index d3589310183..ca3913980bc 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -1248,15 +1248,6 @@ nsXULElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) // -weren't- generated from RDF. Ugh. Forget it. } - if (mSlots->mNameSpace) { - // Copy namespace stuff. - nsCOMPtr xmlcontent = do_QueryInterface(result); - if (xmlcontent) { - rv = xmlcontent->SetContainingNameSpace(mSlots->mNameSpace); - if (NS_FAILED(rv)) return rv; - } - } - // Note that we're _not_ copying mBroadcastListeners, // mControllers, mInnerXULElement. } @@ -1680,67 +1671,6 @@ nsXULElement::GetElementsByAttribute(const nsAReadableString& aAttribute, //---------------------------------------------------------------------- // nsIXMLContent interface -NS_IMETHODIMP -nsXULElement::SetContainingNameSpace(nsINameSpace* aNameSpace) -{ - nsresult rv; - - rv = EnsureSlots(); - if (NS_FAILED(rv)) return rv; - - mSlots->mNameSpace = dont_QueryInterface(aNameSpace); - return NS_OK; -} - -NS_IMETHODIMP -nsXULElement::GetContainingNameSpace(nsINameSpace*& aNameSpace) const -{ - nsresult rv; - - if (NameSpace()) { - // If we have a namespace, return it. - aNameSpace = NameSpace(); - NS_ADDREF(aNameSpace); - return NS_OK; - } - - // Next, try our parent. - nsCOMPtr parent( dont_QueryInterface(mParent) ); - while (parent) { - nsCOMPtr xml( do_QueryInterface(parent) ); - if (xml) - return xml->GetContainingNameSpace(aNameSpace); - - nsCOMPtr temp = parent; - rv = temp->GetParent(*getter_AddRefs(parent)); - NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get parent"); - if (NS_FAILED(rv)) return rv; - } - - // Allright, we walked all the way to the top of our containment - // hierarchy and couldn't find a parent that supported - // nsIXMLContent. If we're in a document, try to doc's root - // element. - if (mDocument) { - nsCOMPtr docroot; - mDocument->GetRootContent(getter_AddRefs(docroot)); - - // Wow! Nasty cast to get an unambiguous, non-const - // nsISupports pointer. We want to make sure that we're not - // the docroot (this would otherwise spin off into infinity). - nsISupports* me = NS_STATIC_CAST(nsIStyledContent*, NS_CONST_CAST(nsXULElement*, this)); - - if (docroot && !::SameCOMIdentity(docroot, me)) { - nsCOMPtr xml( do_QueryInterface(docroot) ); - if (xml) - return xml->GetContainingNameSpace(aNameSpace); - } - } - - aNameSpace = nsnull; - return NS_OK; -} - NS_IMETHODIMP nsXULElement::MaybeTriggerAutoLink(nsIWebShell *aShell) { @@ -4688,7 +4618,6 @@ nsXULElement::EnsureSlots() if (!mPrototype) return NS_OK; - mSlots->mNameSpace = mPrototype->mNameSpace; NS_ASSERTION(mPrototype->mNodeInfo, "prototype has null nodeinfo!"); mSlots->mNodeInfo = mPrototype->mNodeInfo; diff --git a/content/xul/content/src/nsXULElement.h b/content/xul/content/src/nsXULElement.h index f3fd01968bc..9c6273c3017 100644 --- a/content/xul/content/src/nsXULElement.h +++ b/content/xul/content/src/nsXULElement.h @@ -239,7 +239,6 @@ public: PRInt32 mNumChildren; nsXULPrototypeNode** mChildren; // [OWNER] - nsCOMPtr mNameSpace; // [OWNER] nsCOMPtr mNodeInfo; // [OWNER] PRInt32 mNumAttributes; @@ -425,8 +424,6 @@ public: NS_IMETHOD_(PRBool) IsContentOfType(PRUint32 aFlags); // nsIXMLContent - NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace); - NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const; NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell); NS_IMETHOD GetXMLBaseURI(nsIURI **aURI); @@ -547,7 +544,6 @@ protected: Slots(nsXULElement* mElement); ~Slots(); - nsCOMPtr mNameSpace; // [OWNER] nsCOMPtr mNodeInfo; // [OWNER] nsCOMPtr mControllers; // [OWNER] @@ -621,7 +617,6 @@ protected: // Internal accessors. These shadow the 'Slots', and return // appropriate default values if there are no slots defined in the // delegate. - nsINameSpace* NameSpace() const { return mSlots ? mSlots->mNameSpace.get() : mPrototype->mNameSpace.get(); } nsINodeInfo* NodeInfo() const { return mSlots ? mSlots->mNodeInfo : mPrototype->mNodeInfo; } nsIControllers* Controllers() const { return mSlots ? mSlots->mControllers.get() : nsnull; } nsXULAttributes* Attributes() const { return mSlots ? mSlots->mAttributes : nsnull; } diff --git a/content/xul/document/src/nsXULContentSink.cpp b/content/xul/document/src/nsXULContentSink.cpp index ae0aad33899..61c84051f27 100644 --- a/content/xul/document/src/nsXULContentSink.cpp +++ b/content/xul/document/src/nsXULContentSink.cpp @@ -1393,8 +1393,6 @@ nsresult XULContentSinkImpl::CreateElement(nsINodeInfo *aNodeInfo, nsXULPrototypeElement** aResult) { - nsresult rv; - nsXULPrototypeElement* element = new nsXULPrototypeElement(/* line number */ -1); if (! element) return NS_ERROR_OUT_OF_MEMORY; @@ -1402,12 +1400,6 @@ XULContentSinkImpl::CreateElement(nsINodeInfo *aNodeInfo, element->mNodeInfo = aNodeInfo; element->mDocument = mPrototype; - nsCOMPtr ns; - rv = GetTopNameSpace(address_of(ns)); - if (NS_SUCCEEDED(rv)) { - element->mNameSpace = ns; - } - *aResult = element; return NS_OK; } diff --git a/content/xul/templates/src/nsXULContentUtils.cpp b/content/xul/templates/src/nsXULContentUtils.cpp index 29e7b7ce6fb..edf0f3cbc0b 100644 --- a/content/xul/templates/src/nsXULContentUtils.cpp +++ b/content/xul/templates/src/nsXULContentUtils.cpp @@ -165,35 +165,6 @@ nsXULContentUtils::Finish() //------------------------------------------------------------------------ // nsIXULContentUtils methods -nsresult -nsXULContentUtils::AttachTextNode(nsIContent* parent, nsIRDFNode* value) -{ - nsresult rv; - - nsAutoString s; - rv = GetTextForNode(value, s); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr text; - rv = nsComponentManager::CreateInstance(kTextNodeCID, - nsnull, - NS_GET_IID(nsITextContent), - getter_AddRefs(text)); - if (NS_FAILED(rv)) return rv; - - - rv = text->SetText(s.get(), s.Length(), PR_FALSE); - if (NS_FAILED(rv)) return rv; - - // hook it up to the child - rv = parent->AppendChildTo(nsCOMPtr( do_QueryInterface(text) ), - PR_FALSE, PR_FALSE); - if (NS_FAILED(rv)) return rv; - - return NS_OK; -} - - nsresult nsXULContentUtils::FindChildByTag(nsIContent* aElement, PRInt32 aNameSpaceID, @@ -381,127 +352,6 @@ nsXULContentUtils::GetTextForNode(nsIRDFNode* aNode, nsAWritableString& aResult) return NS_ERROR_UNEXPECTED; } -nsresult -nsXULContentUtils::GetElementLogString(nsIContent* aElement, nsAWritableString& aResult) -{ - nsresult rv; - - aResult.Assign(PRUnichar('<')); - - nsCOMPtr ns; - - PRInt32 elementNameSpaceID; - rv = aElement->GetNameSpaceID(elementNameSpaceID); - if (NS_FAILED(rv)) return rv; - - if (kNameSpaceID_HTML == elementNameSpaceID) { - aResult.Append(NS_LITERAL_STRING("html:")); - } - else { - nsCOMPtr xml( do_QueryInterface(aElement) ); - NS_ASSERTION(xml != nsnull, "not an XML or HTML element"); - if (! xml) return NS_ERROR_UNEXPECTED; - - rv = xml->GetContainingNameSpace(*getter_AddRefs(ns)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr prefix; - rv = ns->FindNameSpacePrefix(elementNameSpaceID, *getter_AddRefs(prefix)); - if (NS_SUCCEEDED(rv) && (prefix != nsnull)) { - nsAutoString prefixStr; - prefix->ToString(prefixStr); - if (prefixStr.Length()) { - const PRUnichar *unicodeString; - prefix->GetUnicode(&unicodeString); - aResult.Append(unicodeString); - aResult.Append(NS_LITERAL_STRING(":")); - } - } - } - - nsCOMPtr tag; - rv = aElement->GetTag(*getter_AddRefs(tag)); - if (NS_FAILED(rv)) return rv; - - const PRUnichar *unicodeString; - tag->GetUnicode(&unicodeString); - aResult.Append(unicodeString); - - PRInt32 count; - rv = aElement->GetAttrCount(count); - if (NS_FAILED(rv)) return rv; - - for (PRInt32 i = 0; i < count; ++i) { - aResult.Append(NS_LITERAL_STRING(" ")); - - PRInt32 nameSpaceID; - nsCOMPtr name, prefix; - rv = aElement->GetAttrNameAt(i, nameSpaceID, *getter_AddRefs(name), *getter_AddRefs(prefix)); - if (NS_FAILED(rv)) return rv; - - nsAutoString attr; - nsXULContentUtils::GetAttributeLogString(aElement, nameSpaceID, name, attr); - - aResult.Append(attr); - aResult.Append(NS_LITERAL_STRING("=\"")); - - nsAutoString value; - rv = aElement->GetAttr(nameSpaceID, name, value); - if (NS_FAILED(rv)) return rv; - - aResult.Append(value); - aResult.Append(NS_LITERAL_STRING("\"")); - } - - aResult.Append(NS_LITERAL_STRING(">")); - return NS_OK; -} - - -nsresult -nsXULContentUtils::GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aTag, nsAWritableString& aResult) -{ - nsresult rv; - - PRInt32 elementNameSpaceID; - rv = aElement->GetNameSpaceID(elementNameSpaceID); - if (NS_FAILED(rv)) return rv; - - if ((kNameSpaceID_HTML == elementNameSpaceID) || - (kNameSpaceID_None == aNameSpaceID)) { - aResult.Truncate(); - } - else { - // we may have a namespace prefix on the attribute - nsCOMPtr xml( do_QueryInterface(aElement) ); - NS_ASSERTION(xml != nsnull, "not an XML or HTML element"); - if (! xml) return NS_ERROR_UNEXPECTED; - - nsCOMPtr ns; - rv = xml->GetContainingNameSpace(*getter_AddRefs(ns)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr prefix; - rv = ns->FindNameSpacePrefix(aNameSpaceID, *getter_AddRefs(prefix)); - if (NS_SUCCEEDED(rv) && (prefix != nsnull)) { - nsAutoString prefixStr; - prefix->ToString(prefixStr); - if (prefixStr.Length()) { - const PRUnichar *unicodeString; - prefix->GetUnicode(&unicodeString); - aResult.Append(unicodeString); - aResult.Append(NS_LITERAL_STRING(":")); - } - } - } - - const PRUnichar *unicodeString; - aTag->GetUnicode(&unicodeString); - aResult.Append(unicodeString); - return NS_OK; -} - - nsresult nsXULContentUtils::MakeElementURI(nsIDocument* aDocument, const nsAReadableString& aElementID, nsCString& aURI) { @@ -606,27 +456,6 @@ nsXULContentUtils::MakeElementID(nsIDocument* aDocument, const nsAReadableString return NS_OK; } -PRBool -nsXULContentUtils::IsContainedBy(nsIContent* aElement, nsIContent* aContainer) -{ - nsCOMPtr element( dont_QueryInterface(aElement) ); - while (element) { - nsresult rv; - - nsCOMPtr parent; - rv = element->GetParent(*getter_AddRefs(parent)); - if (NS_FAILED(rv)) return PR_FALSE; - - if (parent.get() == aContainer) - return PR_TRUE; - - element = parent; - } - - return PR_FALSE; -} - - nsresult nsXULContentUtils::GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult) { diff --git a/content/xul/templates/src/nsXULContentUtils.h b/content/xul/templates/src/nsXULContentUtils.h index 44b2b793034..9c90da8114e 100644 --- a/content/xul/templates/src/nsXULContentUtils.h +++ b/content/xul/templates/src/nsXULContentUtils.h @@ -81,9 +81,6 @@ public: static nsresult Finish(); - static nsresult - AttachTextNode(nsIContent* parent, nsIRDFNode* value); - static nsresult FindChildByTag(nsIContent *aElement, PRInt32 aNameSpaceID, @@ -104,12 +101,6 @@ public: static nsresult GetTextForNode(nsIRDFNode* aNode, nsAWritableString& aResult); - static nsresult - GetElementLogString(nsIContent* aElement, nsAWritableString& aResult); - - static nsresult - GetAttributeLogString(nsIContent* aElement, PRInt32 aNameSpaceID, nsIAtom* aTag, nsAWritableString& aResult); - static nsresult MakeElementURI(nsIDocument* aDocument, const nsAReadableString& aElementID, nsCString& aURI); @@ -119,9 +110,6 @@ public: static nsresult MakeElementID(nsIDocument* aDocument, const nsAReadableString& aURI, nsAWritableString& aElementID); - static PRBool - IsContainedBy(nsIContent* aElement, nsIContent* aContainer); - static nsresult GetResource(PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aResult);