зеркало из https://github.com/mozilla/pjs.git
Fixes to the broadcasters and observers. I made HTML elements work with
observes nodes, and I changed some SetAttribute calls to use the DOM instead of the nsIContent APIs.
This commit is contained in:
Родитель
2700b0b443
Коммит
09561af850
|
@ -2184,26 +2184,22 @@ RDFElementImpl::AddBroadcastListener(const nsString& attr, nsIDOMElement* anElem
|
|||
// We need to sync up the initial attribute value.
|
||||
nsCOMPtr<nsIContent> listener( do_QueryInterface(anElement) );
|
||||
|
||||
// Retrieve our namespace
|
||||
PRInt32 namespaceID;
|
||||
GetNameSpaceID(namespaceID);
|
||||
|
||||
// Find out if the attribute is even present at all.
|
||||
nsString attrValue;
|
||||
nsIAtom* kAtom = NS_NewAtom(attr);
|
||||
nsresult result = GetAttribute(namespaceID, kAtom, attrValue);
|
||||
nsresult result = GetAttribute(kNameSpaceID_None, kAtom, attrValue);
|
||||
PRBool attrPresent = (result == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
result == NS_CONTENT_ATTR_HAS_VALUE);
|
||||
|
||||
if (attrPresent)
|
||||
{
|
||||
// Set the attribute
|
||||
listener->SetAttribute(namespaceID, kAtom, attrValue, PR_TRUE);
|
||||
anElement->SetAttribute(attr, attrValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unset the attribute
|
||||
listener->UnsetAttribute(namespaceID, kAtom, PR_FALSE);
|
||||
anElement->RemoveAttribute(attr);
|
||||
}
|
||||
|
||||
NS_RELEASE(kAtom);
|
||||
|
|
|
@ -563,8 +563,6 @@ public:
|
|||
protected:
|
||||
// pseudo constants
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIAtom* kAttributeAtom;
|
||||
static nsIAtom* kElementAtom;
|
||||
static nsIAtom* kIdAtom;
|
||||
static nsIAtom* kObservesAtom;
|
||||
|
||||
|
@ -608,8 +606,6 @@ protected:
|
|||
};
|
||||
|
||||
PRInt32 XULDocumentImpl::gRefCnt;
|
||||
nsIAtom* XULDocumentImpl::kAttributeAtom;
|
||||
nsIAtom* XULDocumentImpl::kElementAtom;
|
||||
nsIAtom* XULDocumentImpl::kIdAtom;
|
||||
nsIAtom* XULDocumentImpl::kObservesAtom;
|
||||
|
||||
|
@ -649,8 +645,6 @@ XULDocumentImpl::XULDocumentImpl(void)
|
|||
}
|
||||
|
||||
if (gRefCnt++ == 0) {
|
||||
kAttributeAtom = NS_NewAtom("attribute");
|
||||
kElementAtom = NS_NewAtom("element");
|
||||
kIdAtom = NS_NewAtom("id");
|
||||
kObservesAtom = NS_NewAtom("observes");
|
||||
}
|
||||
|
@ -681,8 +675,6 @@ XULDocumentImpl::~XULDocumentImpl()
|
|||
NS_IF_RELEASE(mLineBreaker);
|
||||
|
||||
if (--gRefCnt == 0) {
|
||||
NS_IF_RELEASE(kAttributeAtom);
|
||||
NS_IF_RELEASE(kElementAtom);
|
||||
NS_IF_RELEASE(kIdAtom);
|
||||
NS_IF_RELEASE(kObservesAtom);
|
||||
}
|
||||
|
@ -1974,23 +1966,21 @@ XULDocumentImpl::CreateContents(nsIContent* aElement)
|
|||
if (!tag)
|
||||
break;
|
||||
|
||||
nsString tagName;
|
||||
tag->ToString(tagName);
|
||||
|
||||
if (tagName.EqualsIgnoreCase("observes"))
|
||||
if (tag == kObservesAtom)
|
||||
{
|
||||
// Find the node that we're supposed to be
|
||||
// observing and perform the hookup.
|
||||
nsString elementValue;
|
||||
nsString attributeValue;
|
||||
|
||||
childContent->GetAttribute(kNameSpaceID_None,
|
||||
kElementAtom,
|
||||
elementValue);
|
||||
|
||||
childContent->GetAttribute(kNameSpaceID_None,
|
||||
kAttributeAtom,
|
||||
attributeValue);
|
||||
nsCOMPtr<nsIDOMElement> domContent;
|
||||
domContent = do_QueryInterface(childContent);
|
||||
|
||||
domContent->GetAttribute("element",
|
||||
elementValue);
|
||||
|
||||
domContent->GetAttribute("attribute",
|
||||
attributeValue);
|
||||
|
||||
nsIDOMElement* domElement = nsnull;
|
||||
GetElementById(elementValue, &domElement);
|
||||
|
|
|
@ -2184,26 +2184,22 @@ RDFElementImpl::AddBroadcastListener(const nsString& attr, nsIDOMElement* anElem
|
|||
// We need to sync up the initial attribute value.
|
||||
nsCOMPtr<nsIContent> listener( do_QueryInterface(anElement) );
|
||||
|
||||
// Retrieve our namespace
|
||||
PRInt32 namespaceID;
|
||||
GetNameSpaceID(namespaceID);
|
||||
|
||||
// Find out if the attribute is even present at all.
|
||||
nsString attrValue;
|
||||
nsIAtom* kAtom = NS_NewAtom(attr);
|
||||
nsresult result = GetAttribute(namespaceID, kAtom, attrValue);
|
||||
nsresult result = GetAttribute(kNameSpaceID_None, kAtom, attrValue);
|
||||
PRBool attrPresent = (result == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
result == NS_CONTENT_ATTR_HAS_VALUE);
|
||||
|
||||
if (attrPresent)
|
||||
{
|
||||
// Set the attribute
|
||||
listener->SetAttribute(namespaceID, kAtom, attrValue, PR_TRUE);
|
||||
anElement->SetAttribute(attr, attrValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unset the attribute
|
||||
listener->UnsetAttribute(namespaceID, kAtom, PR_FALSE);
|
||||
anElement->RemoveAttribute(attr);
|
||||
}
|
||||
|
||||
NS_RELEASE(kAtom);
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
#include "nsString.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
#include "nsIDOMXULElement.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
|
||||
// XXX These are needed as scaffolding until we get to a more
|
||||
// DOM-based solution.
|
||||
|
@ -1414,6 +1416,75 @@ RDFXULBuilderImpl::CreateHTMLElement(nsIRDFResource* aResource,
|
|||
return rv;
|
||||
}
|
||||
|
||||
// The observes relationship has to be hooked up here, since the children
|
||||
// were already built. We'll miss out on it if we don't plug in here.
|
||||
// Now that the contents have been created, perform broadcaster
|
||||
// hookups if any of the children are observes nodes.
|
||||
// XXX: Initial sync-up doesn't work, since no document observer exists
|
||||
// yet.
|
||||
PRInt32 childCount;
|
||||
element->ChildCount(childCount);
|
||||
for (PRInt32 j = 0; j < childCount; j++)
|
||||
{
|
||||
nsIContent* childContent = nsnull;
|
||||
element->ChildAt(j, childContent);
|
||||
|
||||
if (!childContent)
|
||||
break;
|
||||
|
||||
nsIAtom* tag = nsnull;
|
||||
childContent->GetTag(tag);
|
||||
|
||||
if (!tag)
|
||||
break;
|
||||
|
||||
nsString tagName;
|
||||
tag->ToString(tagName);
|
||||
|
||||
if (tagName == "observes")
|
||||
{
|
||||
// Find the node that we're supposed to be
|
||||
// observing and perform the hookup.
|
||||
nsString elementValue;
|
||||
nsString attributeValue;
|
||||
nsCOMPtr<nsIDOMElement> domContent;
|
||||
domContent = do_QueryInterface(childContent);
|
||||
|
||||
domContent->GetAttribute("element",
|
||||
elementValue);
|
||||
|
||||
domContent->GetAttribute("attribute",
|
||||
attributeValue);
|
||||
|
||||
nsIDOMElement* domElement = nsnull;
|
||||
nsCOMPtr<nsIDOMXULDocument> xulDoc;
|
||||
xulDoc = do_QueryInterface(doc);
|
||||
|
||||
if (xulDoc)
|
||||
xulDoc->GetElementById(elementValue, &domElement);
|
||||
|
||||
if (!domElement)
|
||||
break;
|
||||
|
||||
// We have a DOM element to bind to. Add a broadcast
|
||||
// listener to that element, but only if it's a XUL element.
|
||||
// XXX: Handle context nodes.
|
||||
nsCOMPtr<nsIDOMElement> listener( do_QueryInterface(element) );
|
||||
nsCOMPtr<nsIDOMXULElement> broadcaster( do_QueryInterface(domElement) );
|
||||
if (listener)
|
||||
{
|
||||
broadcaster->AddBroadcastListener(attributeValue,
|
||||
listener);
|
||||
}
|
||||
|
||||
NS_RELEASE(domElement);
|
||||
}
|
||||
|
||||
NS_RELEASE(childContent);
|
||||
NS_RELEASE(tag);
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -563,8 +563,6 @@ public:
|
|||
protected:
|
||||
// pseudo constants
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIAtom* kAttributeAtom;
|
||||
static nsIAtom* kElementAtom;
|
||||
static nsIAtom* kIdAtom;
|
||||
static nsIAtom* kObservesAtom;
|
||||
|
||||
|
@ -608,8 +606,6 @@ protected:
|
|||
};
|
||||
|
||||
PRInt32 XULDocumentImpl::gRefCnt;
|
||||
nsIAtom* XULDocumentImpl::kAttributeAtom;
|
||||
nsIAtom* XULDocumentImpl::kElementAtom;
|
||||
nsIAtom* XULDocumentImpl::kIdAtom;
|
||||
nsIAtom* XULDocumentImpl::kObservesAtom;
|
||||
|
||||
|
@ -649,8 +645,6 @@ XULDocumentImpl::XULDocumentImpl(void)
|
|||
}
|
||||
|
||||
if (gRefCnt++ == 0) {
|
||||
kAttributeAtom = NS_NewAtom("attribute");
|
||||
kElementAtom = NS_NewAtom("element");
|
||||
kIdAtom = NS_NewAtom("id");
|
||||
kObservesAtom = NS_NewAtom("observes");
|
||||
}
|
||||
|
@ -681,8 +675,6 @@ XULDocumentImpl::~XULDocumentImpl()
|
|||
NS_IF_RELEASE(mLineBreaker);
|
||||
|
||||
if (--gRefCnt == 0) {
|
||||
NS_IF_RELEASE(kAttributeAtom);
|
||||
NS_IF_RELEASE(kElementAtom);
|
||||
NS_IF_RELEASE(kIdAtom);
|
||||
NS_IF_RELEASE(kObservesAtom);
|
||||
}
|
||||
|
@ -1974,23 +1966,21 @@ XULDocumentImpl::CreateContents(nsIContent* aElement)
|
|||
if (!tag)
|
||||
break;
|
||||
|
||||
nsString tagName;
|
||||
tag->ToString(tagName);
|
||||
|
||||
if (tagName.EqualsIgnoreCase("observes"))
|
||||
if (tag == kObservesAtom)
|
||||
{
|
||||
// Find the node that we're supposed to be
|
||||
// observing and perform the hookup.
|
||||
nsString elementValue;
|
||||
nsString attributeValue;
|
||||
|
||||
childContent->GetAttribute(kNameSpaceID_None,
|
||||
kElementAtom,
|
||||
elementValue);
|
||||
|
||||
childContent->GetAttribute(kNameSpaceID_None,
|
||||
kAttributeAtom,
|
||||
attributeValue);
|
||||
nsCOMPtr<nsIDOMElement> domContent;
|
||||
domContent = do_QueryInterface(childContent);
|
||||
|
||||
domContent->GetAttribute("element",
|
||||
elementValue);
|
||||
|
||||
domContent->GetAttribute("attribute",
|
||||
attributeValue);
|
||||
|
||||
nsIDOMElement* domElement = nsnull;
|
||||
GetElementById(elementValue, &domElement);
|
||||
|
|
|
@ -2184,26 +2184,22 @@ RDFElementImpl::AddBroadcastListener(const nsString& attr, nsIDOMElement* anElem
|
|||
// We need to sync up the initial attribute value.
|
||||
nsCOMPtr<nsIContent> listener( do_QueryInterface(anElement) );
|
||||
|
||||
// Retrieve our namespace
|
||||
PRInt32 namespaceID;
|
||||
GetNameSpaceID(namespaceID);
|
||||
|
||||
// Find out if the attribute is even present at all.
|
||||
nsString attrValue;
|
||||
nsIAtom* kAtom = NS_NewAtom(attr);
|
||||
nsresult result = GetAttribute(namespaceID, kAtom, attrValue);
|
||||
nsresult result = GetAttribute(kNameSpaceID_None, kAtom, attrValue);
|
||||
PRBool attrPresent = (result == NS_CONTENT_ATTR_NO_VALUE ||
|
||||
result == NS_CONTENT_ATTR_HAS_VALUE);
|
||||
|
||||
if (attrPresent)
|
||||
{
|
||||
// Set the attribute
|
||||
listener->SetAttribute(namespaceID, kAtom, attrValue, PR_TRUE);
|
||||
anElement->SetAttribute(attr, attrValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unset the attribute
|
||||
listener->UnsetAttribute(namespaceID, kAtom, PR_FALSE);
|
||||
anElement->RemoveAttribute(attr);
|
||||
}
|
||||
|
||||
NS_RELEASE(kAtom);
|
||||
|
|
Загрузка…
Ссылка в новой задаче