Commit b574cd98 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Bind events directly to document node for documents with no window associated.

parent d49d83a1
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "config.h" #include "config.h"
#include <stdarg.h> #include <stdarg.h>
#include <assert.h>
#define COBJMACROS #define COBJMACROS
...@@ -384,17 +385,28 @@ static void init_listener(nsEventListener *This, nsDocumentEventListener *listen ...@@ -384,17 +385,28 @@ static void init_listener(nsEventListener *This, nsDocumentEventListener *listen
This->This = listener; This->This = listener;
} }
static nsIDOMEventTarget *get_default_document_target(HTMLDocumentNode *doc)
{
nsIDOMEventTarget *target;
nsISupports *target_iface;
nsresult nsres;
target_iface = doc->window ? (nsISupports*)doc->basedoc.window->nswindow : (nsISupports*)doc->nsdoc;
nsres = nsISupports_QueryInterface(target_iface, &IID_nsIDOMEventTarget, (void**)&target);
return NS_SUCCEEDED(nsres) ? target : NULL;
}
void add_nsevent_listener(HTMLDocumentNode *doc, nsIDOMNode *nsnode, LPCWSTR type) void add_nsevent_listener(HTMLDocumentNode *doc, nsIDOMNode *nsnode, LPCWSTR type)
{ {
nsIDOMEventTarget *target; nsIDOMEventTarget *target;
nsresult nsres; nsresult nsres;
if(nsnode) if(nsnode) {
nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMEventTarget, (void**)&target); nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMEventTarget, (void**)&target);
else assert(nsres == NS_OK);
nsres = nsIDOMWindow_QueryInterface(doc->basedoc.window->nswindow, &IID_nsIDOMEventTarget, (void**)&target); }else {
if(NS_FAILED(nsres)) { target = get_default_document_target(doc);
ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres); if(!target)
return; return;
} }
...@@ -409,15 +421,10 @@ static void detach_nslistener(HTMLDocumentNode *doc, const WCHAR *type, nsEventL ...@@ -409,15 +421,10 @@ static void detach_nslistener(HTMLDocumentNode *doc, const WCHAR *type, nsEventL
nsAString type_str; nsAString type_str;
nsresult nsres; nsresult nsres;
if(!doc->basedoc.window) target = get_default_document_target(doc);
if(!target)
return; return;
nsres = nsIDOMWindow_QueryInterface(doc->basedoc.window->nswindow, &IID_nsIDOMEventTarget, (void**)&target);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
return;
}
nsAString_InitDepend(&type_str, type); nsAString_InitDepend(&type_str, type);
nsres = nsIDOMEventTarget_RemoveEventListener(target, &type_str, nsres = nsIDOMEventTarget_RemoveEventListener(target, &type_str,
&listener->nsIDOMEventListener_iface, is_capture); &listener->nsIDOMEventListener_iface, is_capture);
...@@ -455,7 +462,6 @@ void init_nsevents(HTMLDocumentNode *doc) ...@@ -455,7 +462,6 @@ void init_nsevents(HTMLDocumentNode *doc)
{ {
nsDocumentEventListener *listener; nsDocumentEventListener *listener;
nsIDOMEventTarget *target; nsIDOMEventTarget *target;
nsresult nsres;
listener = heap_alloc(sizeof(nsDocumentEventListener)); listener = heap_alloc(sizeof(nsDocumentEventListener));
if(!listener) if(!listener)
...@@ -474,11 +480,9 @@ void init_nsevents(HTMLDocumentNode *doc) ...@@ -474,11 +480,9 @@ void init_nsevents(HTMLDocumentNode *doc)
doc->nsevent_listener = listener; doc->nsevent_listener = listener;
nsres = nsIDOMWindow_QueryInterface(doc->basedoc.window->nswindow, &IID_nsIDOMEventTarget, (void**)&target); target = get_default_document_target(doc);
if(NS_FAILED(nsres)) { if(!target)
ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
return; return;
}
init_event(target, blurW, &listener->blur_listener.nsIDOMEventListener_iface, TRUE); init_event(target, blurW, &listener->blur_listener.nsIDOMEventListener_iface, TRUE);
init_event(target, focusW, &listener->focus_listener.nsIDOMEventListener_iface, TRUE); init_event(target, focusW, &listener->focus_listener.nsIDOMEventListener_iface, TRUE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment