Relanding 189384 since it seems Not Guilty. Still r=sicking/sr=jst/a=asa

This commit is contained in:
bzbarsky%mit.edu 2003-01-31 23:21:22 +00:00
Родитель 0561607dac
Коммит e74f70b957
7 изменённых файлов: 68 добавлений и 237 удалений

Просмотреть файл

@ -2451,7 +2451,6 @@ nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
nsIDOMNodeList** aReturn)
{
PRInt32 nameSpaceId = kNameSpaceID_Unknown;
nsCOMPtr<nsIContentList> list;
@ -2461,7 +2460,7 @@ nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
nameSpaceId);
if (nameSpaceId == kNameSpaceID_Unknown) {
// Unkonwn namespace means no matches, we create an empty list...
// Unknown namespace means no matches, we create an empty list...
NS_GetContentList(this, nsnull, kNameSpaceID_None, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
@ -2470,6 +2469,8 @@ nsDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
if (!list) {
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLocalName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
NS_GetContentList(this, nameAtom, nameSpaceId, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);

Просмотреть файл

@ -1323,18 +1323,13 @@ nsresult
nsGenericElement::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
{
nsCOMPtr<nsIAtom> nameAtom;
nameAtom = do_GetAtom(aTagname);
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aTagname);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIContentList> list;
NS_GetContentList(mDocument, nameAtom, kNameSpaceID_Unknown, this,
getter_AddRefs(list));
if (!list) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
return CallQueryInterface(list, aReturn);
}
@ -1452,9 +1447,6 @@ nsGenericElement::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
nsIDOMNodeList** aReturn)
{
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLocalName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
PRInt32 nameSpaceId = kNameSpaceID_Unknown;
nsCOMPtr<nsIContentList> list;
@ -1472,6 +1464,9 @@ nsGenericElement::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
}
if (!list) {
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLocalName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
NS_GetContentList(mDocument, nameAtom, nameSpaceId, this,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);

Просмотреть файл

@ -129,7 +129,7 @@
#include "nsIListBoxObject.h"
#include "nsContentUtils.h"
#include "nsGenericElement.h"
#include "nsContentList.h"
#include "nsMutationEvent.h"
#include "nsIDOMMutationEvent.h"
#include "nsPIDOMWindow.h"
@ -1392,25 +1392,18 @@ nsXULElement::RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn)
NS_IMETHODIMP
nsXULElement::GetElementsByTagName(const nsAString& aName,
nsXULElement::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
{
nsresult rv;
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aTagname);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
nsRDFDOMNodeList* elements;
rv = nsRDFDOMNodeList::Create(&elements);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create node list");
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIContentList> list;
NS_GetContentList(mDocument, nameAtom, kNameSpaceID_Unknown, this,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIDOMNode> domElement;
rv = QueryInterface(NS_GET_IID(nsIDOMNode), getter_AddRefs(domElement));
if (NS_SUCCEEDED(rv)) {
GetElementsByTagName(domElement, aName, elements);
}
// transfer ownership to caller
*aReturn = elements;
return NS_OK;
return CallQueryInterface(list, aReturn);
}
NS_IMETHODIMP
@ -1504,40 +1497,32 @@ nsXULElement::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
nsIDOMNodeList** aReturn)
{
NS_ENSURE_ARG_POINTER(aReturn);
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLocalName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
PRInt32 nameSpaceId = kNameSpaceID_Unknown;
nsRDFDOMNodeList* elements;
nsresult rv = nsRDFDOMNodeList::Create(&elements);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMNodeList> kungFuGrip;
kungFuGrip = dont_AddRef(NS_STATIC_CAST(nsIDOMNodeList *, elements));
nsCOMPtr<nsIContentList> list;
if (!aNamespaceURI.Equals(NS_LITERAL_STRING("*"))) {
nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceID(aNamespaceURI,
nameSpaceId);
if (nameSpaceId == kNameSpaceID_Unknown) {
// Unkonwn namespace means no matches, we return an empty list...
*aReturn = elements;
NS_ADDREF(*aReturn);
return NS_OK;
// Unknown namespace means no matches, we create an empty list...
NS_GetContentList(mDocument, nsnull, kNameSpaceID_None, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
}
}
rv = nsXULDocument::GetElementsByTagName(NS_STATIC_CAST(nsIStyledContent *,
this), aLocalName,
nameSpaceId, elements);
NS_ENSURE_SUCCESS(rv, rv);
if (!list) {
NS_GetContentList(mDocument, nameAtom, nameSpaceId, this,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
}
*aReturn = elements;
NS_ADDREF(*aReturn);
return NS_OK;
return CallQueryInterface(list, aReturn);
}
NS_IMETHODIMP
@ -1586,6 +1571,9 @@ nsXULElement::GetElementsByAttribute(const nsAString& aAttribute,
const nsAString& aValue,
nsIDOMNodeList** aReturn)
{
// XXX This should use nsContentList, but that does not support
// _two_ strings being passed to the match func. Ah, the ability
// to create real closures, where art thou?
nsresult rv;
nsRDFDOMNodeList* elements;
rv = nsRDFDOMNodeList::Create(&elements);
@ -3568,72 +3556,6 @@ nsXULElement::EnsureContentsGenerated(void) const
return NS_OK;
}
nsresult
nsXULElement::GetElementsByTagName(nsIDOMNode* aNode,
const nsAString& aTagName,
nsRDFDOMNodeList* aElements)
{
nsresult rv;
nsCOMPtr<nsIDOMNodeList> children;
if (NS_FAILED(rv = aNode->GetChildNodes( getter_AddRefs(children) ))) {
NS_ERROR("unable to get node's children");
return rv;
}
// no kids: terminate the recursion
if (! children)
return NS_OK;
PRUint32 length;
if (NS_FAILED(children->GetLength(&length))) {
NS_ERROR("unable to get node list's length");
return rv;
}
for (PRUint32 i = 0; i < length; ++i) {
nsCOMPtr<nsIDOMNode> child;
if (NS_FAILED(rv = children->Item(i, getter_AddRefs(child) ))) {
NS_ERROR("unable to get child from list");
return rv;
}
nsCOMPtr<nsIDOMElement> element;
element = do_QueryInterface(child);
if (!element)
continue;
if (aTagName.Equals(NS_LITERAL_STRING("*"))) {
if (NS_FAILED(rv = aElements->AppendNode(child))) {
NS_ERROR("unable to append element to node list");
return rv;
}
}
else {
nsAutoString name;
if (NS_FAILED(rv = child->GetNodeName(name))) {
NS_ERROR("unable to get node name");
return rv;
}
if (aTagName.Equals(name)) {
if (NS_FAILED(rv = aElements->AppendNode(child))) {
NS_ERROR("unable to append element to node list");
return rv;
}
}
}
// Now recursively look for children
if (NS_FAILED(rv = GetElementsByTagName(child, aTagName, aElements))) {
NS_ERROR("unable to recursively get elements by tag name");
return rv;
}
}
return NS_OK;
}
nsresult
nsXULElement::GetElementsByAttribute(nsIDOMNode* aNode,
const nsAString& aAttribute,

Просмотреть файл

@ -524,11 +524,6 @@ protected:
ExecuteJSCode(nsIDOMElement* anElement, nsEvent* aEvent);
// Static helpers
static nsresult
GetElementsByTagName(nsIDOMNode* aNode,
const nsAString& aTagName,
nsRDFDOMNodeList* aElements);
static nsresult
GetElementsByAttribute(nsIDOMNode* aNode,
const nsAString& aAttributeName,

Просмотреть файл

@ -160,7 +160,7 @@
#include "nsIObjectOutputStream.h"
#include "nsIPref.h"
#include "nsIFocusController.h"
#include "nsContentList.h"
//----------------------------------------------------------------------
//
@ -2954,29 +2954,18 @@ nsXULDocument::CreateEntityReference(const nsAString& aName,
NS_IMETHODIMP
nsXULDocument::GetElementsByTagName(const nsAString& aTagName,
nsXULDocument::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
{
nsresult rv;
nsRDFDOMNodeList* elements;
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
NS_ERROR("unable to create node list");
return rv;
}
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aTagname);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
nsIContent* root = nsnull;
GetRootContent(&root);
NS_ASSERTION(root != nsnull, "no doc root");
nsCOMPtr<nsIContentList> list;
NS_GetContentList(this, nameAtom, kNameSpaceID_Unknown, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
if (root != nsnull) {
rv = GetElementsByTagName(root, aTagName, kNameSpaceID_Unknown,
elements);
NS_RELEASE(root);
}
*aReturn = elements;
return NS_OK;
return CallQueryInterface(list, aReturn);
}
NS_IMETHODIMP
@ -2984,6 +2973,9 @@ nsXULDocument::GetElementsByAttribute(const nsAString& aAttribute,
const nsAString& aValue,
nsIDOMNodeList** aReturn)
{
// XXX This should use nsContentList, but that does not support
// _two_ strings being passed to the match func. Ah, the ability
// to create real closures, where art thou?
nsresult rv;
nsRDFDOMNodeList* elements;
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
@ -3712,38 +3704,32 @@ nsXULDocument::GetElementsByTagNameNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
nsIDOMNodeList** aReturn)
{
nsresult rv;
PRInt32 nameSpaceId = kNameSpaceID_Unknown;
nsRDFDOMNodeList* elements;
if (NS_FAILED(rv = nsRDFDOMNodeList::Create(&elements))) {
NS_ERROR("unable to create node list");
return rv;
}
nsCOMPtr<nsIContentList> list;
*aReturn = elements;
if (!aNamespaceURI.Equals(NS_LITERAL_STRING("*"))) {
nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceID(aNamespaceURI,
nameSpaceId);
nsCOMPtr<nsIContent> root;
GetRootContent(getter_AddRefs(root));
NS_ASSERTION(root, "no doc root");
if (root) {
PRInt32 nsid = kNameSpaceID_Unknown;
if (!aNamespaceURI.Equals(NS_LITERAL_STRING("*"))) {
rv = nsContentUtils::GetNSManagerWeakRef()->GetNameSpaceID(aNamespaceURI, nsid);
NS_ENSURE_SUCCESS(rv, rv);
if (nsid == kNameSpaceID_Unknown) {
// Namespace not found, then there can't be any elements to
// be found.
return NS_OK;
}
if (nameSpaceId == kNameSpaceID_Unknown) {
// Unknown namespace means no matches, we create an empty list...
NS_GetContentList(this, nsnull, kNameSpaceID_None, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
}
rv = GetElementsByTagName(root, aLocalName, nsid,
elements);
}
return NS_OK;
if (!list) {
nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aLocalName);
NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY);
NS_GetContentList(this, nameAtom, nameSpaceId, nsnull,
getter_AddRefs(list));
NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY);
}
return CallQueryInterface(list, aReturn);
}
nsresult
@ -4519,68 +4505,6 @@ nsXULDocument::StartLayout(void)
}
nsresult
nsXULDocument::GetElementsByTagName(nsIContent *aContent,
const nsAString& aName,
PRInt32 aNamespaceID,
nsRDFDOMNodeList* aElements)
{
NS_ENSURE_ARG_POINTER(aContent);
NS_ENSURE_ARG_POINTER(aElements);
nsresult rv = NS_OK;
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(aContent));
if (!element)
return NS_OK;
nsCOMPtr<nsINodeInfo> ni;
aContent->GetNodeInfo(*getter_AddRefs(ni));
NS_ENSURE_TRUE(ni, NS_OK);
if (aName.Equals(NS_LITERAL_STRING("*"))) {
if (aNamespaceID == kNameSpaceID_Unknown ||
ni->NamespaceEquals(aNamespaceID)) {
if (NS_FAILED(rv = aElements->AppendNode(element))) {
NS_ERROR("unable to append element to node list");
return rv;
}
}
}
else {
if (ni->Equals(aName) &&
(aNamespaceID == kNameSpaceID_Unknown ||
ni->NamespaceEquals(aNamespaceID))) {
if (NS_FAILED(rv = aElements->AppendNode(element))) {
NS_ERROR("unable to append element to node list");
return rv;
}
}
}
PRInt32 length;
if (NS_FAILED(rv = aContent->ChildCount(length))) {
NS_ERROR("unable to get childcount");
return rv;
}
for (PRInt32 i = 0; i < length; ++i) {
nsCOMPtr<nsIContent> child;
if (NS_FAILED(rv = aContent->ChildAt(i, *getter_AddRefs(child) ))) {
NS_ERROR("unable to get child from content");
return rv;
}
if (NS_FAILED(rv = GetElementsByTagName(child, aName, aNamespaceID,
aElements))) {
NS_ERROR("unable to recursively get elements by tag name");
return rv;
}
}
return NS_OK;
}
nsresult
nsXULDocument::GetElementsByAttribute(nsIDOMNode* aNode,
const nsAString& aAttribute,

Просмотреть файл

@ -433,12 +433,6 @@ public:
NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult);
NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult);
static nsresult
GetElementsByTagName(nsIContent* aContent,
const nsAString& aTagName,
PRInt32 aNamespaceID,
nsRDFDOMNodeList* aElements);
protected:
// Implementation methods
friend nsresult

Просмотреть файл

@ -230,8 +230,8 @@ function GetCurrentEditorElement()
var editorList = tmpWindow.document.getElementsByTagName("editor");
// This will change if we support > 1 editor element
if (editorList && editorList.length > 0)
return editorList[0];
if (editorList.item(0))
return editorList.item(0);
tmpWindow = tmpWindow.opener;
}