зеркало из https://github.com/mozilla/pjs.git
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
This commit is contained in:
Родитель
eae0ba690f
Коммит
2c8e09cceb
|
@ -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<nsINodeInfo> 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<nsIContent> parent;
|
||||
|
||||
mContent->GetParent(*getter_AddRefs(parent));
|
||||
|
||||
if (parent) {
|
||||
parent->GetNodeInfo(*getter_AddRefs(ni));
|
||||
}
|
||||
}
|
||||
|
||||
if (ni) {
|
||||
nsCOMPtr<nsINodeInfoManager> nimgr;
|
||||
|
||||
|
@ -476,12 +489,11 @@ nsNode3Tearoff::LookupNamespacePrefix(const nsAReadableString& aNamespaceURI,
|
|||
// If there's no nodeinfo, get the manager from the document
|
||||
if (!manager) {
|
||||
nsCOMPtr<nsIDocument> 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<nsIContent> 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<nsIContent> content(mContent);
|
||||
while (content) {
|
||||
nsCOMPtr<nsIXMLContent> xmlContent(do_QueryInterface(content));
|
||||
|
||||
if (xmlContent) {
|
||||
nsCOMPtr<nsINameSpace> ns;
|
||||
|
||||
xmlContent->GetContainingNameSpace(*getter_AddRefs(ns));
|
||||
if (ns) {
|
||||
nsCOMPtr<nsIAtom> prefix;
|
||||
nsresult rv = ns->FindNameSpacePrefix(namespaceId,
|
||||
*getter_AddRefs(prefix));
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
PRInt32 attrCount, i;
|
||||
|
||||
nsCOMPtr<nsIAtom> 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<nsIContent> 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<nsIAtom> 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<nsIContent> 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<nsIContent> content(mContent);
|
||||
while (content) {
|
||||
nsCOMPtr<nsIXMLContent> xmlContent(do_QueryInterface(content));
|
||||
|
||||
if (xmlContent) {
|
||||
nsCOMPtr<nsINameSpace> ns;
|
||||
|
||||
xmlContent->GetContainingNameSpace(*getter_AddRefs(ns));
|
||||
if (ns) {
|
||||
nsCOMPtr<nsIAtom> prefix;
|
||||
nsCOMPtr<nsINameSpace> 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<nsIContent> tmp(content);
|
||||
tmp->GetParent(*getter_AddRefs(content));
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
SetDOMStringToNull(aNamespaceURI);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<nsINameSpace> tagSpace;
|
||||
nsAutoString nameSpace;
|
||||
|
||||
if (prefix.Length() > 0) {
|
||||
nsCOMPtr<nsIAtom> prefixAtom = getter_AddRefs(NS_NewAtom(prefix));
|
||||
nsCOMPtr<nsINameSpace> nameSpace;
|
||||
nsCOMPtr<nsIXMLContent> 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<nsIAtom> tagName = getter_AddRefs(NS_NewAtom(display));
|
||||
protoBinding->SetBaseTag(nameSpaceID, tagName);
|
||||
|
||||
nsCOMPtr<nsIDOM3Node> 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<nsIAtom> 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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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___
|
||||
|
|
|
@ -897,12 +897,6 @@ nsXMLContentSink::CloseContainer(const nsIParserNode& aNode)
|
|||
}
|
||||
}
|
||||
nsINameSpace* nameSpace = PopNameSpaces();
|
||||
if (content) {
|
||||
nsCOMPtr<nsIXMLContent> xmlContent = do_QueryInterface(content);
|
||||
if (xmlContent) {
|
||||
xmlContent->SetContainingNameSpace(nameSpace);
|
||||
}
|
||||
}
|
||||
NS_IF_RELEASE(nameSpace);
|
||||
|
||||
if (mNeedToBlockParser || (mParser && !mParser->IsParserEnabled())) {
|
||||
|
|
|
@ -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<nsIXMLContent> 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<nsIContent> parent( dont_QueryInterface(mParent) );
|
||||
while (parent) {
|
||||
nsCOMPtr<nsIXMLContent> xml( do_QueryInterface(parent) );
|
||||
if (xml)
|
||||
return xml->GetContainingNameSpace(aNameSpace);
|
||||
|
||||
nsCOMPtr<nsIContent> 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<nsIContent> 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<nsIXMLContent> 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;
|
||||
|
||||
|
|
|
@ -239,7 +239,6 @@ public:
|
|||
PRInt32 mNumChildren;
|
||||
nsXULPrototypeNode** mChildren; // [OWNER]
|
||||
|
||||
nsCOMPtr<nsINameSpace> mNameSpace; // [OWNER]
|
||||
nsCOMPtr<nsINodeInfo> 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<nsINameSpace> mNameSpace; // [OWNER]
|
||||
nsCOMPtr<nsINodeInfo> mNodeInfo; // [OWNER]
|
||||
nsCOMPtr<nsIControllers> 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; }
|
||||
|
|
|
@ -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<nsINameSpace> ns;
|
||||
rv = GetTopNameSpace(address_of(ns));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
element->mNameSpace = ns;
|
||||
}
|
||||
|
||||
*aResult = element;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -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<nsITextContent> 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<nsIContent>( 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<nsINameSpace> 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<nsIXMLContent> 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<nsIAtom> 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<nsIAtom> 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<nsIAtom> 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<nsIXMLContent> xml( do_QueryInterface(aElement) );
|
||||
NS_ASSERTION(xml != nsnull, "not an XML or HTML element");
|
||||
if (! xml) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsINameSpace> ns;
|
||||
rv = xml->GetContainingNameSpace(*getter_AddRefs(ns));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIAtom> 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<nsIContent> element( dont_QueryInterface(aElement) );
|
||||
while (element) {
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIContent> 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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче