mshtml: Bind events directly to document node for documents with no window associated.
Signed-off-by: Jacek Caban <jacek@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
d49d83a18e
commit
b574cd98bd
|
@ -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,15 +421,10 @@ static void detach_nslistener(HTMLDocumentNode *doc, const WCHAR *type, nsEventL
|
|||
nsAString type_str;
|
||||
nsresult nsres;
|
||||
|
||||
if(!doc->basedoc.window)
|
||||
target = get_default_document_target(doc);
|
||||
if(!target)
|
||||
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);
|
||||
nsres = nsIDOMEventTarget_RemoveEventListener(target, &type_str,
|
||||
&listener->nsIDOMEventListener_iface, is_capture);
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue