More IsNodeOfType. Bug 336822, r+sr=sicking

This commit is contained in:
bzbarsky%mit.edu 2006-05-06 03:25:58 +00:00
Родитель 9a8e044731
Коммит 990f4ef359
1 изменённых файлов: 36 добавлений и 42 удалений

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

@ -6416,65 +6416,59 @@ NS_IMETHODIMP
nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj, nsNodeSH::PreCreate(nsISupports *nativeObj, JSContext *cx, JSObject *globalObj,
JSObject **parentObj) JSObject **parentObj)
{ {
nsCOMPtr<nsIContent> content(do_QueryInterface(nativeObj)); nsCOMPtr<nsINode> node(do_QueryInterface(nativeObj));
nsCOMPtr<nsIDocument> doc; NS_ENSURE_TRUE(node, NS_ERROR_UNEXPECTED);
if (content) { // Make sure that we get the owner document of the content node, in case
// Make sure that we get the owner document of the content node, in case // we're in document teardown. If we are, it's important to *not* use
// we're in document teardown. If we are, it's important to *not* use // globalObj as the nodes parent since that would give the node the
// globalObj as the nodes parent since that would give the node the // principal of globalObj (i.e. the principal of the document that's being
// principal of globalObj (i.e. the principal of the document that's being // loaded) and not the principal of the document that's being unloaded.
// loaded) and not the principal of the document that's being unloaded. // See http://bugzilla.mozilla.org/show_bug.cgi?id=227417
// See http://bugzilla.mozilla.org/show_bug.cgi?id=227417 nsIDocument* doc = node->GetOwnerDoc();
doc = content->GetOwnerDoc();
}
if (!doc) { if (!doc) {
doc = do_QueryInterface(nativeObj); // No document reachable from nativeObj, use the global object
// that was passed to this method.
if (!doc) { *parentObj = globalObj;
// No document reachable from nativeObj, use the global object
// that was passed to this method.
*parentObj = globalObj; return NS_OK;
return NS_OK;
}
} }
nsISupports *native_parent; nsISupports *native_parent;
if (content) { if (node->IsNodeOfType(nsINode::eELEMENT | nsINode::eXUL)) {
if (content->IsNodeOfType(nsINode::eXUL)) { // For XUL elements, use the parent, if any.
// For XUL elements, use the parent, if any. native_parent = node->GetParent();
native_parent = content->GetParent();
if (!native_parent) { if (!native_parent) {
native_parent = doc;
}
} else {
// For non-XUL elements, use the document as scope parent.
native_parent = doc; native_parent = doc;
}
} else if (node->IsNodeOfType(nsINode::eCONTENT)) {
// For non-XUL content, use the document as scope parent.
native_parent = doc;
// But for HTML form controls, use the form as scope parent. // But for HTML form controls, use the form as scope parent.
if (content->IsNodeOfType(nsINode::eELEMENT | if (node->IsNodeOfType(nsINode::eELEMENT |
nsIContent::eHTML | nsIContent::eHTML |
nsIContent::eHTML_FORM_CONTROL)) { nsIContent::eHTML_FORM_CONTROL)) {
nsCOMPtr<nsIFormControl> form_control(do_QueryInterface(content)); nsCOMPtr<nsIFormControl> form_control(do_QueryInterface(node));
if (form_control) { if (form_control) {
nsCOMPtr<nsIDOMHTMLFormElement> form; nsCOMPtr<nsIDOMHTMLFormElement> form;
form_control->GetForm(getter_AddRefs(form)); form_control->GetForm(getter_AddRefs(form));
if (form) { if (form) {
// Found a form, use it. // Found a form, use it.
native_parent = form; native_parent = form;
}
} }
} }
} }
} else { } else {
// We're called for a document object (since content is null), NS_ASSERTION(node->IsNodeOfType(nsINode::eDOCUMENT),
"Unexpected node");
// We're called for a document object (since node is not eCONTENT),
// set the parent to be the document's global object, if there // set the parent to be the document's global object, if there
// is one // is one