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 @@
#include "config.h"
#include <stdarg.h>
#include <assert.h>
#define COBJMACROS
......@@ -384,18 +385,29 @@ static void init_listener(nsEventListener *This, nsDocumentEventListener *listen
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)
{
nsIDOMEventTarget *target;
nsresult nsres;
if(nsnode)
if(nsnode) {
nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMEventTarget, (void**)&target);
else
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;
assert(nsres == NS_OK);
}else {
target = get_default_document_target(doc);
if(!target)
return;
}
init_event(target, type, &doc->nsevent_listener->htmlevent_listener.nsIDOMEventListener_iface,
......@@ -409,14 +421,9 @@ static void detach_nslistener(HTMLDocumentNode *doc, const WCHAR *type, nsEventL
nsAString type_str;
nsresult nsres;
if(!doc->basedoc.window)
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);
target = get_default_document_target(doc);
if(!target)
return;
}
nsAString_InitDepend(&type_str, type);
nsres = nsIDOMEventTarget_RemoveEventListener(target, &type_str,
......@@ -455,7 +462,6 @@ void init_nsevents(HTMLDocumentNode *doc)
{
nsDocumentEventListener *listener;
nsIDOMEventTarget *target;
nsresult nsres;
listener = heap_alloc(sizeof(nsDocumentEventListener));
if(!listener)
......@@ -474,11 +480,9 @@ void init_nsevents(HTMLDocumentNode *doc)
doc->nsevent_listener = listener;
nsres = nsIDOMWindow_QueryInterface(doc->basedoc.window->nswindow, &IID_nsIDOMEventTarget, (void**)&target);
if(NS_FAILED(nsres)) {
ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
target = get_default_document_target(doc);
if(!target)
return;
}
init_event(target, blurW, &listener->blur_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