Use nsINode in nsEventListenerManager::CompileEventHandlerInternal. Bug

329192, r+sr=sicking.
This commit is contained in:
bzbarsky%mit.edu 2006-05-05 22:45:56 +00:00
Родитель 19eac0bfdf
Коммит dc6c7fda01
1 изменённых файлов: 14 добавлений и 20 удалений

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

@ -699,10 +699,9 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
// Go from our target to the nearest enclosing DOM window. // Go from our target to the nearest enclosing DOM window.
nsCOMPtr<nsPIDOMWindow> window; nsCOMPtr<nsPIDOMWindow> window;
nsCOMPtr<nsIDocument> document; nsCOMPtr<nsIDocument> document;
nsCOMPtr<nsIContent> content(do_QueryInterface(mTarget)); nsCOMPtr<nsINode> node(do_QueryInterface(mTarget));
if (content) if (node)
document = content->GetOwnerDoc(); document = node->GetOwnerDoc();
else document = do_QueryInterface(mTarget);
if (document) if (document)
window = document->GetInnerWindow(); window = document->GetInnerWindow();
else window = do_QueryInterface(mTarget); else window = do_QueryInterface(mTarget);
@ -1205,7 +1204,7 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
nsIScriptContext *context = nsnull; nsIScriptContext *context = nsnull;
JSContext* cx = nsnull; JSContext* cx = nsnull;
nsCOMPtr<nsIContent> content(do_QueryInterface(aObject)); nsCOMPtr<nsINode> node(do_QueryInterface(aObject));
nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIDocument> doc;
@ -1213,9 +1212,9 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
JSObject *scope = nsnull; JSObject *scope = nsnull;
if (content) { if (node) {
// Try to get context from doc // Try to get context from doc
doc = content->GetOwnerDoc(); doc = node->GetOwnerDoc();
nsIScriptGlobalObject *global; nsIScriptGlobalObject *global;
if (doc && (global = doc->GetScriptGlobalObject())) { if (doc && (global = doc->GetScriptGlobalObject())) {
@ -1234,13 +1233,7 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
doc = do_QueryInterface(domdoc); doc = do_QueryInterface(domdoc);
global = do_QueryInterface(win); global = do_QueryInterface(win);
} else { } else {
doc = do_QueryInterface(aObject); global = do_QueryInterface(aObject);
if (doc) {
global = doc->GetScriptGlobalObject();
} else {
global = do_QueryInterface(aObject);
}
} }
if (global) { if (global) {
context = global->GetContext(); context = global->GetContext();
@ -1331,8 +1324,10 @@ nsEventListenerManager::AddScriptEventListener(nsISupports *aObject,
} }
else { else {
PRInt32 nameSpace = kNameSpaceID_Unknown; PRInt32 nameSpace = kNameSpaceID_Unknown;
if (content) if (node && node->IsNodeOfType(nsINode::eCONTENT)) {
nsIContent* content = NS_STATIC_CAST(nsIContent*, node.get());
nameSpace = content->GetNameSpaceID(); nameSpace = content->GetNameSpaceID();
}
else if (doc) { else if (doc) {
nsCOMPtr<nsIContent> root = doc->GetRootContent(); nsCOMPtr<nsIContent> root = doc->GetRootContent();
if (root) if (root)
@ -1553,11 +1548,10 @@ nsEventListenerManager::CompileEventHandlerInternal(nsIScriptContext *aContext,
PRUint32 lineNo = 0; PRUint32 lineNo = 0;
nsCAutoString url (NS_LITERAL_CSTRING("javascript:alert('TODO: FIXME')")); nsCAutoString url (NS_LITERAL_CSTRING("javascript:alert('TODO: FIXME')"));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aCurrentTarget); nsIDocument* doc = nsnull;
if (!doc) { nsCOMPtr<nsINode> node = do_QueryInterface(aCurrentTarget);
nsCOMPtr<nsIContent> content = do_QueryInterface(aCurrentTarget); if (node) {
if (content) doc = node->GetOwnerDoc();
doc = content->GetOwnerDoc();
} }
if (doc) { if (doc) {
nsIURI *uri = doc->GetDocumentURI(); nsIURI *uri = doc->GetDocumentURI();