Part 5 of fix for bug 560273 (Stop using DOM tearoffs from quickstubs) - add nsIDOM3Node namespace-related methods to nsINode. r=jst.

--HG--
extra : rebase_source : 9f4680ed3d8dec7001503c57f9d4bede74392b2f
This commit is contained in:
Peter Van der Beken 2010-04-19 17:40:16 +02:00
parent 199b861a9e
commit 2d92228c9a
11 changed files with 100 additions and 94 deletions

View File

@ -906,6 +906,11 @@ public:
PRBool aNotify) = 0;
#endif // MOZ_SMIL
nsresult LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI) const;
nsIAtom* LookupPrefix(const nsAString& aNamespaceURI);
private:
/**
* Hook for implementing GetClasses. This is guaranteed to only be

View File

@ -1376,6 +1376,11 @@ protected:
virtual void MutationEventDispatched(nsINode* aTarget) = 0;
friend class mozAutoSubtreeModified;
virtual mozilla::dom::Element* GetNameSpaceElement()
{
return GetRootElement();
}
nsCOMPtr<nsIURI> mDocumentURI;
nsCOMPtr<nsIURI> mDocumentBaseURI;

View File

@ -1005,6 +1005,16 @@ public:
return static_cast<nsIVariant*>(GetProperty(DOM_USER_DATA, key));
}
void LookupPrefix(const nsAString& aNamespaceURI, nsAString& aPrefix);
PRBool IsDefaultNamespace(const nsAString& aNamespaceURI)
{
nsAutoString defaultNamespace;
LookupNamespaceURI(EmptyString(), defaultNamespace);
return aNamespaceURI.Equals(defaultNamespace);
}
void LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI);
protected:
// Override this function to create a custom slots class.
@ -1081,6 +1091,14 @@ protected:
nsINode* aRefChild);
nsresult RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn);
/**
* Returns the Element that should be used for resolving namespaces
* on this node (ie the ownerElement for attributes, the documentElement for
* documents, the node itself for elements and for other nodes the parentNode
* if it is an element).
*/
virtual mozilla::dom::Element* GetNameSpaceElement() = 0;
nsCOMPtr<nsINodeInfo> mNodeInfo;
enum { PARENT_BIT_INDOCUMENT = 1 << 0, PARENT_BIT_PARENT_IS_CONTENT = 1 << 1 };

View File

@ -2091,7 +2091,7 @@ nsContentUtils::SplitQName(nsIContent* aNamespaceResolver,
const PRUnichar* end;
aQName.EndReading(end);
nsAutoString nameSpace;
rv = LookupNamespaceURI(aNamespaceResolver, Substring(aQName.get(), colon),
rv = aNamespaceResolver->LookupNamespaceURI(Substring(aQName.get(), colon),
nameSpace);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -582,11 +582,8 @@ NS_IMETHODIMP
nsDOMAttribute::IsDefaultNamespace(const nsAString& aNamespaceURI,
PRBool* aReturn)
{
*aReturn = PR_FALSE;
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(GetContentInternal()));
if (node) {
return node->IsDefaultNamespace(aNamespaceURI, aReturn);
}
*aReturn = nsINode::IsDefaultNamespace(aNamespaceURI);
return NS_OK;
}
@ -659,11 +656,8 @@ NS_IMETHODIMP
nsDOMAttribute::LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
{
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(GetContentInternal()));
if (node)
return node->LookupPrefix(aNamespaceURI, aPrefix);
nsINode::LookupPrefix(aNamespaceURI, aPrefix);
SetDOMStringToNull(aPrefix);
return NS_OK;
}
@ -671,11 +665,8 @@ NS_IMETHODIMP
nsDOMAttribute::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(GetContentInternal()));
if (node)
return node->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
nsINode::LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
SetDOMStringToNull(aNamespaceURI);
return NS_OK;
}

View File

@ -124,6 +124,11 @@ public:
nsIAttribute)
protected:
virtual mozilla::dom::Element* GetNameSpaceElement()
{
return GetContentInternal()->AsElement();
}
static PRBool sInitialized;
private:

View File

@ -5725,9 +5725,8 @@ NS_IMETHODIMP
nsDocument::IsDefaultNamespace(const nsAString& aNamespaceURI,
PRBool* aReturn)
{
nsAutoString defaultNamespace;
LookupNamespaceURI(EmptyString(), defaultNamespace);
*aReturn = aNamespaceURI.Equals(defaultNamespace);
*aReturn = nsINode::IsDefaultNamespace(aNamespaceURI);
return NS_OK;
}
@ -5762,12 +5761,7 @@ NS_IMETHODIMP
nsDocument::LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
{
nsCOMPtr<nsIDOM3Node> root(do_QueryInterface(GetRootElement()));
if (root) {
return root->LookupPrefix(aNamespaceURI, aPrefix);
}
SetDOMStringToNull(aPrefix);
nsINode::LookupPrefix(aNamespaceURI, aPrefix);
return NS_OK;
}
@ -5775,11 +5769,8 @@ NS_IMETHODIMP
nsDocument::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
if (NS_FAILED(nsContentUtils::LookupNamespaceURI(GetRootElement(),
aNamespacePrefix,
aNamespaceURI))) {
SetDOMStringToNull(aNamespaceURI);
}
nsINode::LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
return NS_OK;
}

View File

@ -202,41 +202,6 @@ nsGenericDOMDataNode::IsSupported(const nsAString& aFeature,
aFeature, aVersion, aReturn);
}
nsresult
nsGenericDOMDataNode::LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
{
aPrefix.Truncate();
nsIContent *parent_weak = GetParent();
// DOM Data Node passes the query on to its parent
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(parent_weak));
if (node) {
return node->LookupPrefix(aNamespaceURI, aPrefix);
}
return NS_OK;
}
nsresult
nsGenericDOMDataNode::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
aNamespaceURI.Truncate();
nsIContent *parent_weak = GetParent();
// DOM Data Node passes the query on to its parent
nsCOMPtr<nsIDOM3Node> node(do_QueryInterface(parent_weak));
if (node) {
return node->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
}
return NS_OK;
}
//----------------------------------------------------------------------
// Implementation of nsIDOMCharacterData

View File

@ -134,11 +134,6 @@ public:
const nsAString& aVersion,
PRBool* aReturn);
nsresult LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix);
nsresult LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI);
// Implementation for nsIDOMCharacterData
nsresult GetData(nsAString& aData) const;
nsresult SetData(const nsAString& aData);
@ -273,6 +268,13 @@ public:
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsGenericDOMDataNode)
protected:
virtual mozilla::dom::Element* GetNameSpaceElement()
{
nsINode *parent = GetNodeParent();
return parent->IsElement() ? parent->AsElement() : nsnull;
}
/**
* There are a set of DOM- and scripting-specific instance variables
* that may only be instantiated when a content object is accessed

View File

@ -602,6 +602,19 @@ nsINode::GetBaseURI(nsAString &aURI) const
CopyUTF8toUTF16(spec, aURI);
}
void
nsINode::LookupPrefix(const nsAString& aNamespaceURI, nsAString& aPrefix)
{
Element *element = GetNameSpaceElement();
nsIAtom *prefix = element ? element->LookupPrefix(aNamespaceURI) : nsnull;
if (prefix) {
prefix->ToString(aPrefix);
}
else {
SetDOMStringToNull(aPrefix);
}
}
static nsresult
SetUserDataProperty(PRUint16 aCategory, nsINode *aNode, nsIAtom *aKey,
nsISupports* aValue, void** aOldValue)
@ -773,6 +786,17 @@ nsContentUtils::ComparePosition(nsINode* aNode1,
nsIDOM3Node::DOCUMENT_POSITION_CONTAINED_BY);
}
void
nsINode::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
Element *element = GetNameSpaceElement();
if (!element || NS_FAILED(element->LookupNamespaceURI(aNamespacePrefix,
aNamespaceURI))) {
SetDOMStringToNull(aNamespaceURI);
}
}
//----------------------------------------------------------------------
PRInt32
@ -863,11 +887,9 @@ nsIContent::GetDesiredIMEState()
return state;
}
// static
nsresult
nsContentUtils::LookupNamespaceURI(nsIContent* aNamespaceResolver,
const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
nsIContent::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI) const
{
if (aNamespacePrefix.EqualsLiteral("xml")) {
// Special-case for xml prefix
@ -891,11 +913,11 @@ nsContentUtils::LookupNamespaceURI(nsIContent* aNamespaceResolver,
}
// Trace up the content parent chain looking for the namespace
// declaration that declares aNamespacePrefix.
for (nsIContent* content = aNamespaceResolver; content;
content = content->GetParent()) {
const nsIContent* content = this;
do {
if (content->GetAttr(kNameSpaceID_XMLNS, name, aNamespaceURI))
return NS_OK;
}
} while ((content = content->GetParent()));
return NS_ERROR_FAILURE;
}
@ -1201,18 +1223,15 @@ nsNode3Tearoff::GetUserData(const nsAString& aKey,
return NS_OK;
}
NS_IMETHODIMP
nsNode3Tearoff::LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
nsIAtom*
nsIContent::LookupPrefix(const nsAString& aNamespaceURI)
{
SetDOMStringToNull(aPrefix);
// XXX Waiting for DOM spec to list error codes.
// 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).
for (nsIContent* content = mContent; content;
for (nsIContent* content = this; content;
content = content->GetParent()) {
PRUint32 attrCount = content->GetAttrCount();
@ -1224,15 +1243,21 @@ nsNode3Tearoff::LookupPrefix(const nsAString& aNamespaceURI,
aNamespaceURI, eCaseMatters)) {
// If the localName is "xmlns", the prefix we output should be
// null.
if (name->LocalName() != nsGkAtoms::xmlns) {
name->LocalName()->ToString(aPrefix);
}
nsIAtom *localName = name->LocalName();
return NS_OK;
return localName == nsGkAtoms::xmlns ? nsnull : localName;
}
}
}
return nsnull;
}
NS_IMETHODIMP
nsNode3Tearoff::LookupPrefix(const nsAString& aNamespaceURI,
nsAString& aPrefix)
{
static_cast<nsINode*>(mContent)->LookupPrefix(aNamespaceURI, aPrefix);
return NS_OK;
}
@ -1240,11 +1265,7 @@ NS_IMETHODIMP
nsNode3Tearoff::LookupNamespaceURI(const nsAString& aNamespacePrefix,
nsAString& aNamespaceURI)
{
if (NS_FAILED(nsContentUtils::LookupNamespaceURI(mContent,
aNamespacePrefix,
aNamespaceURI))) {
SetDOMStringToNull(aNamespaceURI);
}
mContent->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI);
return NS_OK;
}
@ -1252,9 +1273,7 @@ NS_IMETHODIMP
nsNode3Tearoff::IsDefaultNamespace(const nsAString& aNamespaceURI,
PRBool* aReturn)
{
nsAutoString defaultNamespace;
LookupNamespaceURI(EmptyString(), defaultNamespace);
*aReturn = aNamespaceURI.Equals(defaultNamespace);
*aReturn = mContent->IsDefaultNamespace(aNamespaceURI);
return NS_OK;
}

View File

@ -883,6 +883,11 @@ protected:
nsIFrame* GetStyledFrame();
virtual mozilla::dom::Element* GetNameSpaceElement()
{
return this;
}
public:
// Because of a bug in MS C++ compiler nsDOMSlots must be declared public,
// otherwise nsXULElement::nsXULSlots doesn't compile.