Bug 986857 - Replace the Attr element getters by something that returns an Element; r=bz

This commit is contained in:
Aryeh Gregor 2014-04-10 19:09:50 +03:00
parent 635d18ab9f
commit 7da371c253
6 changed files with 42 additions and 45 deletions

View File

@ -12,8 +12,8 @@ class nsDOMAttributeMap;
class nsIContent;
#define NS_IATTRIBUTE_IID \
{ 0x8d9d7dbf, 0xc42d, 0x4715, \
{ 0x95, 0xcf, 0x7a, 0x5e, 0xd5, 0xa4, 0x47, 0x70 } }
{ 0x233a9c4d, 0xb27f, 0x4662, \
{ 0xbd, 0x90, 0xba, 0xd6, 0x2e, 0x76, 0xc8, 0xe1 } }
class nsIAttribute : public nsINode
{
@ -32,8 +32,6 @@ public:
return mNodeInfo;
}
virtual nsIContent* GetContent() const = 0;
/**
* Called when our ownerElement is moved into a new document.
* Updates the nodeinfo of this node.

View File

@ -78,7 +78,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Attr)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Attr)
Element* ownerElement = tmp->GetContentInternal();
Element* ownerElement = tmp->GetElement();
if (tmp->IsBlack()) {
if (ownerElement) {
// The attribute owns the element via attribute map so we can
@ -129,10 +129,14 @@ Attr::SetMap(nsDOMAttributeMap *aMap)
mAttrMap = aMap;
}
nsIContent*
Attr::GetContent() const
Element*
Attr::GetElement() const
{
return GetContentInternal();
if (!mAttrMap) {
return nullptr;
}
nsIContent* content = mAttrMap->GetContent();
return content ? content->AsElement() : nullptr;
}
nsresult
@ -182,10 +186,10 @@ Attr::GetNameAtom(nsIContent* aContent)
NS_IMETHODIMP
Attr::GetValue(nsAString& aValue)
{
nsIContent* content = GetContentInternal();
if (content) {
nsCOMPtr<nsIAtom> nameAtom = GetNameAtom(content);
content->GetAttr(mNodeInfo->NamespaceID(), nameAtom, aValue);
Element* element = GetElement();
if (element) {
nsCOMPtr<nsIAtom> nameAtom = GetNameAtom(element);
element->GetAttr(mNodeInfo->NamespaceID(), nameAtom, aValue);
}
else {
aValue = mValue;
@ -197,14 +201,14 @@ Attr::GetValue(nsAString& aValue)
void
Attr::SetValue(const nsAString& aValue, ErrorResult& aRv)
{
nsIContent* content = GetContentInternal();
if (!content) {
Element* element = GetElement();
if (!element) {
mValue = aValue;
return;
}
nsCOMPtr<nsIAtom> nameAtom = GetNameAtom(content);
aRv = content->SetAttr(mNodeInfo->NamespaceID(),
nsCOMPtr<nsIAtom> nameAtom = GetNameAtom(element);
aRv = element->SetAttr(mNodeInfo->NamespaceID(),
nameAtom,
mNodeInfo->GetPrefixAtom(),
aValue,
@ -238,7 +242,7 @@ Element*
Attr::GetOwnerElement(ErrorResult& aRv)
{
OwnerDoc()->WarnOnceAbout(nsIDocument::eOwnerElement);
return GetContentInternal();
return GetElement();
}
NS_IMETHODIMP
@ -247,9 +251,9 @@ Attr::GetOwnerElement(nsIDOMElement** aOwnerElement)
NS_ENSURE_ARG_POINTER(aOwnerElement);
OwnerDoc()->WarnOnceAbout(nsIDocument::eOwnerElement);
nsIContent* content = GetContentInternal();
if (content) {
return CallQueryInterface(content, aOwnerElement);
Element* element = GetElement();
if (element) {
return CallQueryInterface(element, aOwnerElement);
}
*aOwnerElement = nullptr;
@ -293,7 +297,7 @@ Attr::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
already_AddRefed<nsIURI>
Attr::GetBaseURI(bool aTryUseXHRDocBaseURI) const
{
nsINode *parent = GetContentInternal();
Element* parent = GetElement();
return parent ? parent->GetBaseURI(aTryUseXHRDocBaseURI) : nullptr;
}
@ -318,16 +322,14 @@ Attr::SetTextContentInternal(const nsAString& aTextContent,
NS_IMETHODIMP
Attr::GetIsId(bool* aReturn)
{
nsIContent* content = GetContentInternal();
if (!content)
{
Element* element = GetElement();
if (!element) {
*aReturn = false;
return NS_OK;
}
nsIAtom* idAtom = content->GetIDAttributeName();
if (!idAtom)
{
nsIAtom* idAtom = element->GetIDAttributeName();
if (!idAtom) {
*aReturn = false;
return NS_OK;
}
@ -404,11 +406,5 @@ Attr::WrapObject(JSContext* aCx)
return AttrBinding::Wrap(aCx, this);
}
Element*
Attr::GetContentInternal() const
{
return mAttrMap ? mAttrMap->GetContent() : nullptr;
}
} // namespace dom
} // namespace mozilla

View File

@ -56,7 +56,7 @@ public:
// nsIAttribute interface
void SetMap(nsDOMAttributeMap *aMap) MOZ_OVERRIDE;
nsIContent *GetContent() const MOZ_OVERRIDE;
Element* GetElement() const;
nsresult SetOwnerDocument(nsIDocument* aDocument) MOZ_OVERRIDE;
// nsINode interface
@ -98,14 +98,13 @@ public:
protected:
virtual Element* GetNameSpaceElement()
{
return GetContentInternal();
return GetElement();
}
static bool sInitialized;
private:
already_AddRefed<nsIAtom> GetNameAtom(nsIContent* aContent);
Element* GetContentInternal() const;
nsString mValue;
};

View File

@ -809,10 +809,10 @@ nsINode::CompareDocumentPosition(nsINode& aOtherNode) const
const nsINode *node1 = &aOtherNode, *node2 = this;
// Check if either node is an attribute
const nsIAttribute* attr1 = nullptr;
const Attr* attr1 = nullptr;
if (node1->IsNodeOfType(nsINode::eATTRIBUTE)) {
attr1 = static_cast<const nsIAttribute*>(node1);
const nsIContent* elem = attr1->GetContent();
attr1 = static_cast<const Attr*>(node1);
const Element* elem = attr1->GetElement();
// If there is an owner element add the attribute
// to the chain and walk up to the element
if (elem) {
@ -821,8 +821,8 @@ nsINode::CompareDocumentPosition(nsINode& aOtherNode) const
}
}
if (node2->IsNodeOfType(nsINode::eATTRIBUTE)) {
const nsIAttribute* attr2 = static_cast<const nsIAttribute*>(node2);
const nsIContent* elem = attr2->GetContent();
const Attr* attr2 = static_cast<const Attr*>(node2);
const Element* elem = attr2->GetElement();
if (elem == node1 && attr1) {
// Both nodes are attributes on the same element.
// Compare position between the attributes.

View File

@ -7,8 +7,8 @@
#include "txExprResult.h"
#include "txNodeSet.h"
#include "nsError.h"
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/Element.h"
#include "nsIAttribute.h"
#include "nsDOMClassInfoID.h"
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
@ -361,8 +361,8 @@ nsXPathResult::Invalidate(const nsIContent* aChangeRoot)
static_cast<nsIContent*>(contextNode.get())
->GetBindingParent();
} else if (contextNode->IsNodeOfType(nsINode::eATTRIBUTE)) {
nsIContent* parent =
static_cast<nsIAttribute*>(contextNode.get())->GetContent();
Element* parent =
static_cast<Attr*>(contextNode.get())->GetElement();
if (parent) {
ctxBindingParent = parent->GetBindingParent();
}

View File

@ -21,10 +21,13 @@
#include "nsUnicharUtils.h"
#include "nsAttrName.h"
#include "nsTArray.h"
#include "mozilla/dom/Attr.h"
#include "mozilla/dom/Element.h"
#include <stdint.h>
#include <algorithm>
using mozilla::dom::Attr;
const uint32_t kUnknownIndex = uint32_t(-1);
txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther)
@ -691,7 +694,8 @@ txXPathNativeNode::createXPathNode(nsIDOMNode* aNode, bool aKeepRootAlive)
NS_ASSERTION(attr, "doesn't implement nsIAttribute");
nsINodeInfo *nodeInfo = attr->NodeInfo();
nsIContent *parent = attr->GetContent();
mozilla::dom::Element* parent =
static_cast<Attr*>(attr.get())->GetElement();
if (!parent) {
return nullptr;
}